1 /* 2 * Copyright (c) 2018, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file encode_allocator.h 24 //! \brief Defines the interface for encode resource allocate 25 //! \details encode allocator will allocate and destory buffers, the caller 26 //! can use directly 27 //! 28 29 #ifndef __ENCODE_ALLOCATOR_H__ 30 #define __ENCODE_ALLOCATOR_H__ 31 32 #include "media_class_trace.h" 33 #include "mos_defs.h" 34 #include "mos_os.h" 35 #include "mos_os_hw.h" 36 #include "mos_os_specific.h" 37 class Allocator; 38 39 namespace encode { 40 41 class EncodeAllocator 42 { 43 public: 44 //! 45 //! \brief Constructor 46 //! \param [in] osInterface 47 //! Pointer to MOS_INTERFACE 48 //! 49 EncodeAllocator(PMOS_INTERFACE osInterface); 50 51 //! 52 //! \brief EncodeAllocator Destructor 53 //! 54 virtual ~EncodeAllocator(); 55 56 //! 57 //! \brief Allocate Resource 58 //! \param [in] component 59 //! component type to track the buffer 60 //! \param [in] param 61 //! reference to MOS_ALLOC_GFXRES_PARAMS 62 //! \param [in] zeroOnAllocate 63 //! zero the memory if true 64 //! \param [in] resUsageType 65 //! resource usage for cache policy 66 //! \return MOS_RESOURCE* 67 //! return the pointer to MOS_RESOURCE 68 //! 69 MOS_RESOURCE* AllocateResource( 70 MOS_ALLOC_GFXRES_PARAMS ¶m, 71 bool zeroOnAllocate, 72 MOS_HW_RESOURCE_DEF resUsageType = MOS_HW_RESOURCE_DEF_MAX); 73 74 //! 75 //! \brief Allocate Surface 76 //! \param [in] component 77 //! component type to track the buffer 78 //! \param [in] param 79 //! reference to MOS_ALLOC_GFXRES_PARAMS 80 //! \param [in] zeroOnAllocate 81 //! zero the memory if true 82 //! \param [in] resUsageType 83 //! resource usage for cache policy 84 //! \return MOS_SURFACE* 85 //! return the pointer to MOS_SURFACE 86 //! 87 virtual MOS_SURFACE* AllocateSurface( 88 MOS_ALLOC_GFXRES_PARAMS ¶m, 89 bool zeroOnAllocate, 90 MOS_HW_RESOURCE_DEF resUsageType = MOS_HW_RESOURCE_DEF_MAX); 91 92 //! 93 //! \brief Destroy Resource 94 //! \param [in] resource 95 //! Pointer to MOS_RESOURCE 96 //! \return MOS_STATUS 97 //! MOS_STATUS_SUCCESS if success, else fail reason 98 //! 99 MOS_STATUS DestroyResource(MOS_RESOURCE* resource); 100 101 MOS_STATUS DestroyAllResources(); 102 103 //! 104 //! \brief Destroy Surface 105 //! \param [in] surface 106 //! Pointer to MOS_SURFACE 107 //! \return MOS_STATUS 108 //! MOS_STATUS_SUCCESS if success, else fail reason 109 //! 110 MOS_STATUS DestroySurface(MOS_SURFACE* surface); 111 112 //! 113 //! \brief Lock resource 114 //! \param [in] resource 115 //! Pointer to MOS_RESOURCE 116 //! \param [in] lockFlag 117 //! Pointer to MOS_LOCK_PARAMS 118 //! \return void* 119 //! a poniter to data 120 //! 121 void* Lock(MOS_RESOURCE* resource, MOS_LOCK_PARAMS* lockFlag); 122 123 //! 124 //! \brief Lock resource only for writing 125 //! \param [in] resource 126 //! Pointer to MOS_RESOURCE 127 //! \return void* 128 //! a poniter to data 129 //! 130 virtual void* LockResourceForWrite(MOS_RESOURCE *resource); 131 132 //! 133 //! \brief Lock resource with no overwrite flag 134 //! \param [in] resource 135 //! Pointer to MOS_RESOURCE 136 //! \return void* 137 //! a poniter to data 138 //! 139 void* LockResourceWithNoOverwrite(MOS_RESOURCE *resource); 140 141 //! 142 //! \brief Lock resource only for reading 143 //! \param [in] resource 144 //! Pointer to MOS_RESOURCE 145 //! \return void* 146 //! a poniter to data 147 //! 148 virtual void* LockResourceForRead(MOS_RESOURCE *resource); 149 150 //! 151 //! \brief UnLock resource 152 //! \param [in] resource 153 //! Pointer to MOS_RESOURCE 154 //! \return MOS_STATUS 155 //! MOS_STATUS_SUCCESS if success, else fail reason 156 //! 157 virtual MOS_STATUS UnLock(MOS_RESOURCE* resource); 158 159 //! 160 //! \brief Skip sync resource 161 //! \param [in] resource 162 //! Pointer to MOS_RESOURCE 163 //! \return MOS_STATUS 164 //! MOS_STATUS_SUCCESS if success, else fail reason 165 //! 166 MOS_STATUS SkipResourceSync(MOS_RESOURCE* resource); 167 168 //! 169 //! \brief get surface info from resource 170 //! \param [in, out] surface 171 //! Pointer to MOS_RESOURCE 172 //! \return MOS_STATUS 173 //! MOS_STATUS_SUCCESS if success, else fail reason 174 //! 175 virtual MOS_STATUS GetSurfaceInfo(PMOS_SURFACE surface); 176 177 //! 178 //! \brief Update the GMM usage type of resource for cache policy 179 //! \details Update the GMM usage type of resource for cache policy 180 //! \param PMOS_RESOURCE OsResource 181 //! [in] OS resource sturcture 182 //! \param MOS_HW_RESOURCE_DEF resUsageType 183 //! [in] MOS_HW_RESOURCE_DEF to be set 184 //! \return VOID 185 //! 186 MOS_STATUS UpdateResourceUsageType( 187 PMOS_RESOURCE osResource, 188 MOS_HW_RESOURCE_DEF resUsageType); 189 190 //! 191 //! \brief Tag based synchronization at the resource level 192 //! \details Tag based synchronization at the resource level 193 //! \param PMOS_RESOURCE OsResource 194 //! [in] OS resource sturcture 195 //! \param BOOL bWriteOperation 196 //! [in] Indicate if it is a write operation 197 //! \return VOID 198 //! 199 MOS_STATUS SyncOnResource( 200 PMOS_RESOURCE osResource, 201 bool bWriteOperation); 202 203 protected: 204 PMOS_INTERFACE m_osInterface = nullptr; //!< PMOS_INTERFACE 205 Allocator *m_allocator = nullptr; 206 207 MEDIA_CLASS_DEFINE_END(encode__EncodeAllocator) 208 }; 209 } 210 #endif // !__ENCODE_ALLOCATOR_H__ 211