1 /* 2 * Copyright (c) 2019-2022, 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 mos_graphicsresource_specific_next.h 24 //! \brief Container class for the linux/Android specfic graphic resource 25 //! 26 27 #ifndef __GRAPHICS_RESOURCE_SPECIFIC_NEXT_H__ 28 #define __GRAPHICS_RESOURCE_SPECIFIC_NEXT_H__ 29 30 #include "mos_graphicsresource_next.h" 31 32 class GraphicsResourceSpecificNext : public GraphicsResourceNext 33 { 34 public: 35 //! 36 //! \brief Constructor 37 //! 38 GraphicsResourceSpecificNext(); 39 40 //! 41 //! \brief Destructor 42 //! 43 ~GraphicsResourceSpecificNext(); 44 45 //! 46 //! \brief to sync render target for multi-threading decoding mode 47 //! 48 struct HybridSem 49 { 50 public: 51 //! 52 //! \brief Semaphore queue for hybrid decoding multi-threading case 53 //! 54 PMOS_SEMAPHORE* m_pCurrentFrameSemaphore = nullptr; 55 56 //! 57 //! \brief Semaphore queue for hybrid decoding multi-threading case; post when a 58 //! surface is not used as reference frame 59 //! 60 PMOS_SEMAPHORE* m_pReferenceFrameSemaphore = nullptr; 61 62 //! 63 //! \brief Flag to mark whether the semaphore has been initialized 64 //! 65 bool m_semInitialized = false; 66 67 }; 68 69 //! 70 //! \brief Check whether the resource is nullptr 71 //! \return ture if the resource is nullptr, false on other cases 72 //! 73 bool ResourceIsNull(); 74 75 //! 76 //! \brief Allocate the graphic memory to back up the graphic resource 77 //! \param [in] osContextPtr 78 //! Pointer to the osContext handle 79 //! \param [in] params 80 //! Resource creation Params 81 //! \return MOS_STATUS_SUCCESS on success case, MOS error status on fail cases 82 //! 83 MOS_STATUS Allocate(OsContextNext* osContextPtr, CreateParams& params); 84 85 //! 86 //! \brief Frees the specified resource with flag, if locked, unlocks it. 87 //! \param [in] osContextPtr 88 //! Pointer to the osContext handle 89 //! \param [in] freeFlag 90 //! flags for the free operation 91 //! 92 void Free(OsContextNext* osContextPtr, uint32_t freeFlag = 0); 93 94 //! 95 //! \brief Check whether the specific graphic resources is equal to the current one 96 //! \param [in] toCompare 97 //! ptr to the graphics resource to be compared with 98 //! \return Returns true if the two resources are equal and false otherwise. 99 //! 100 bool IsEqual(GraphicsResourceNext* toCompare); 101 102 //! 103 //! \brief Check whether the current graphic resource is valid 104 //! \return Returns true if a resource is valid and false otherwise. 105 //! 106 bool IsValid(); 107 108 //! 109 //! \brief Locks a resource and returns a mapped system memory pointer. 110 //! \param [in] osContextPtr 111 //! Pointer to the osContext handle 112 //! \param [in] params 113 //! Resource lock Params 114 //! \return CPU side lock address in success case, nullptr in fail cases 115 //! 116 void* Lock(OsContextNext* osContextPtr, LockParams& params); 117 118 //! 119 //! \brief Unlocks a resource that has already been locked, if no lock has 120 //! occurred, this function does nothing 121 //! \param [in] osContextPtr 122 //! Pointer to the osContext handle 123 //! \return MOS_SUCCESS in success case, MOS error status in fail cases 124 //! 125 MOS_STATUS Unlock(OsContextNext* osContextPtr); 126 127 //! 128 //! \brief Converts an OS specific resource to a MOS resource. 129 //! \param [in] mosResourcePtr 130 //! ptr to the MosResource to be filled w/ the conversion result 131 //! \return MOS_SUCCESS on success case 132 //! 133 MOS_STATUS ConvertToMosResource(MOS_RESOURCE* mosResourcePtr); 134 GetBufferObject()135 MOS_LINUX_BO* GetBufferObject(){return m_bo;}; 136 137 //! 138 //! \brief Allocate External Resource 139 //! \details Derive the MOS_RESOURCE_HANDLE to indicate external resource. 140 //! It could be user provided resource with no GraphicResource info firstly 141 //! and get the info later; Or the resource converted from DDI. 142 //! 143 //! \param [in] streamState 144 //! Handle of Os Stream State 145 //! \param [in] params 146 //! Pointer to the parameters for allocating resource 147 //! \param [out] resource 148 //! MOS Resource handle of the allocated resource. 149 //! 150 //! \return MOS_STATUS 151 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 152 //! 153 static MOS_STATUS AllocateExternalResource( 154 MOS_STREAM_HANDLE streamState, 155 PMOS_ALLOC_GFXRES_PARAMS params, 156 MOS_RESOURCE_HANDLE & resource); 157 158 //! 159 //! \brief Free External Resource 160 //! \details Free the MOS_RESOURCE_HANDLE of external resource. 161 //! Undefined behavior if using to free internal resource. 162 //! 163 //! \param [in] streamState 164 //! Handle of Os Stream State 165 //! \param [in] resource 166 //! MOS Resource handle of the allocated resource. 167 //! \param [in] flag 168 //! User defined free flag of the resource. 169 //! 170 //! \return MOS_STATUS 171 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 172 //! 173 static MOS_STATUS FreeExternalResource( 174 MOS_STREAM_HANDLE streamState, 175 MOS_RESOURCE_HANDLE resource, 176 uint32_t flag); 177 178 //! 179 //! \brief Lock External Resource 180 //! 181 //! \param [in] streamState 182 //! Handle of Os Stream State 183 //! \param [in] resource 184 //! MOS Resource handle of the resource to lock. 185 //! \param [in] flags 186 //! Control flags of locking resource. 187 //! 188 //! \return void * 189 //! Locked memory data pointer, nullptr if lock failed. 190 //! 191 static void *LockExternalResource( 192 MOS_STREAM_HANDLE streamState, 193 MOS_RESOURCE_HANDLE resource, 194 PMOS_LOCK_PARAMS flags); 195 196 //! 197 //! \brief Unlock External Resource 198 //! 199 //! \param [in] streamState 200 //! Handle of Os Stream State 201 //! \param [in] resource 202 //! MOS Resource handle of the allocated resource. 203 //! 204 //! \return MOS_STATUS 205 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 206 //! 207 static MOS_STATUS UnlockExternalResource( 208 MOS_STREAM_HANDLE streamState, 209 MOS_RESOURCE_HANDLE resource); 210 211 protected: 212 //! 213 //! \brief Set tilemode by force to GMM info flag. 214 //! \return MOS_SUCCESS on success case. 215 //! 216 MOS_STATUS SetTileModebyForce(GMM_RESCREATE_PARAMS &gmmParams, MOS_TILE_MODE_GMM tileMode); 217 218 private: 219 220 //! 221 //! \brief Pointer to the GMM info structure 222 //! 223 GMM_RESOURCE_INFO* m_gmmResInfo = nullptr; 224 225 //! 226 //! \brief Whether the graphic resource is mapped at CPU side 227 //! 228 bool m_mapped = false; 229 230 //! 231 //! \brief The map operation type we use 232 //! 233 MOS_MMAP_OPERATION m_mmapOperation = MOS_MMAP_OPERATION_NONE; 234 235 //! 236 //! \brief the ptr to the buffer object of the graphic buffer 237 //! 238 MOS_LINUX_BO* m_bo = nullptr; 239 240 //! 241 //! \brief the semaphore used in hybrid decoder corresponding to the graphic buffer 242 //! 243 HybridSem m_hybridSem = {}; 244 245 uint8_t* m_systemShadow = nullptr; //!< System shadow surface for s/w untiling 246 MEDIA_CLASS_DEFINE_END(GraphicsResourceSpecificNext) 247 }; 248 #endif // #ifndef __GRAPHICS_RESOURCE_SPECIFIC_NEXT_H__ 249 250