| 1 |
/*===================== begin_copyright_notice ================================== |
| 2 |
/* |
| 3 |
* Copyright (c) 2019, Intel Corporation |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice shall be included |
| 13 |
* in all copies or substantial portions of the Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 19 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 20 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 21 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 22 |
*/ |
| 23 |
//! |
| 24 |
//! \file cm_surface_2d_rt_base.h |
| 25 |
//! \brief Contains CmSurface2DRTBase declaration. |
| 26 |
//! |
| 27 |
|
| 28 |
#ifndef MEDIADRIVER_COMMON_CM_CMSURFACE2DRT_BASE_H_ |
| 29 |
#define MEDIADRIVER_COMMON_CM_CMSURFACE2DRT_BASE_H_ |
| 30 |
|
| 31 |
#include "cm_surface.h" |
| 32 |
#include "cm_surface_2d.h" |
| 33 |
|
| 34 |
#include "cm_hal.h" |
| 35 |
|
| 36 |
namespace CMRT_UMD |
| 37 |
{ |
| 38 |
//! |
| 39 |
//! \brief Abstraction of 2D surfaces in graphics memory. |
| 40 |
//! |
| 41 |
class CmSurface2DRTBase: public CmSurface, public CmSurface2D |
| 42 |
{ |
| 43 |
public: |
| 44 |
CM_RT_API int32_t ReadSurface(unsigned char *pSysMem, |
| 45 |
CmEvent *pEvent, |
| 46 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL); |
| 47 |
|
| 48 |
CM_RT_API int32_t WriteSurface(const unsigned char *pSysMem, |
| 49 |
CmEvent *pEvent, |
| 50 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL); |
| 51 |
|
| 52 |
CM_RT_API int32_t |
| 53 |
ReadSurfaceStride(unsigned char *pSysMem, |
| 54 |
CmEvent *pEvent, |
| 55 |
const unsigned int stride, |
| 56 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL); |
| 57 |
|
| 58 |
CM_RT_API int32_t |
| 59 |
WriteSurfaceStride(const unsigned char *pSysMem, |
| 60 |
CmEvent *pEvent, |
| 61 |
const unsigned int stride, |
| 62 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL); |
| 63 |
|
| 64 |
CM_RT_API int32_t |
| 65 |
ReadSurfaceHybridStrides(unsigned char *pSysMem, |
| 66 |
CmEvent *pEvent, |
| 67 |
const unsigned int iWidthStride, |
| 68 |
const unsigned int iHeightStride, |
| 69 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL, |
| 70 |
unsigned int uiOption = 0); |
| 71 |
|
| 72 |
CM_RT_API int32_t |
| 73 |
WriteSurfaceHybridStrides(const unsigned char *pSysMem, |
| 74 |
CmEvent *pEvent, |
| 75 |
const unsigned int iWidthStride, |
| 76 |
const unsigned int iHeightStride, |
| 77 |
uint64_t sysMemSize = 0xFFFFFFFFFFFFFFFFULL, |
| 78 |
unsigned int uiOption = 0); |
| 79 |
|
| 80 |
CM_RT_API int32_t GetIndex(SurfaceIndex *&pIndex); |
| 81 |
|
| 82 |
virtual CM_RT_API int32_t GetSurfaceDesc(unsigned int &width, |
| 83 |
unsigned int &height, |
| 84 |
CM_SURFACE_FORMAT &format, |
| 85 |
unsigned int &sizeperpixel); |
| 86 |
|
| 87 |
CM_RT_API int32_t InitSurface(const unsigned int initValue, |
| 88 |
CmEvent *pEvent, |
| 89 |
unsigned int useGPU = 0); |
| 90 |
|
| 91 |
CM_RT_API int32_t |
| 92 |
SetSurfaceStateParam(SurfaceIndex *pSurfIndex, |
| 93 |
const CM_SURFACE2D_STATE_PARAM *pSSParam); |
| 94 |
|
| 95 |
CM_RT_API int32_t ReadSurfaceFullStride(unsigned char *pSysMem, |
| 96 |
CmEvent *pEvent, |
| 97 |
const unsigned int iWidthStride, |
| 98 |
const unsigned int iHeightStride, |
| 99 |
uint64_t sysMemSize); |
| 100 |
|
| 101 |
CM_RT_API int32_t WriteSurfaceFullStride(const unsigned char *pSysMem, |
| 102 |
CmEvent *pEvent, |
| 103 |
const unsigned int iWidthStride, |
| 104 |
const unsigned int iHeightStride, |
| 105 |
uint64_t sysMemSize); |
| 106 |
|
| 107 |
int32_t SetMemoryObjectControl(MEMORY_OBJECT_CONTROL mem_ctrl, |
| 108 |
MEMORY_TYPE mem_type, |
| 109 |
unsigned int age); |
| 110 |
|
| 111 |
CM_RT_API int32_t SelectMemoryObjectControlSetting(MEMORY_OBJECT_CONTROL mem_ctrl); |
| 112 |
|
| 113 |
CMRT_UMD_API int32_t SetResourceUsage(const MOS_HW_RESOURCE_DEF mosUsage); |
| 114 |
|
| 115 |
CM_RT_API int32_t SetCompressionMode(MEMCOMP_STATE MmcMode); |
| 116 |
|
| 117 |
CM_RT_API int32_t SetProperty(CM_FRAME_TYPE frameType); |
| 118 |
|
| 119 |
virtual int32_t GetIndexFor2D(unsigned int &index); |
| 120 |
|
| 121 |
virtual int32_t GetHandle(unsigned int &handle); |
| 122 |
|
| 123 |
int32_t SetSurfaceProperties(unsigned int width, |
| 124 |
unsigned int height, |
| 125 |
CM_SURFACE_FORMAT format); |
| 126 |
|
| 127 |
//NOT depend on RTTI::dynamic_cast |
| 128 |
CM_ENUM_CLASS_TYPE Type() const { return CM_ENUM_CLASS_TYPE_CMSURFACE2D; } |
| 129 |
|
| 130 |
bool IsGPUCopy(void *pSysMem, |
| 131 |
uint32_t iWidth, |
| 132 |
uint32_t iHeight, |
| 133 |
uint32_t iWidthStride); |
| 134 |
|
| 135 |
bool IsUnalignedGPUCopy(uint32_t iWidthInBytes, uint32_t iHeight); |
| 136 |
|
| 137 |
CMRT_UMD_API int SetReadSyncFlag(bool bReadSync, CmQueue *pCmQueue); |
| 138 |
|
| 139 |
|
| 140 |
CMRT_UMD_API int |
| 141 |
NotifyUmdResourceChanged(void *umdResource, |
| 142 |
int updateMosResource = 0, |
| 143 |
PMOS_RESOURCE pMosResource = nullptr); |
| 144 |
|
| 145 |
virtual int32_t UpdateResource(MOS_RESOURCE *resource); |
| 146 |
|
| 147 |
virtual int32_t Create2DAlias(SurfaceIndex *&pAliasSurfIndex); |
| 148 |
|
| 149 |
virtual int32_t GetNumAliases(unsigned int &numAliases); |
| 150 |
|
| 151 |
void Log(std::ostringstream &oss); |
| 152 |
|
| 153 |
void DumpContent(uint32_t kernelNumber, |
| 154 |
char *kernelName, |
| 155 |
int32_t taskId, |
| 156 |
uint32_t argIndex, |
| 157 |
uint32_t vectorIndex); |
| 158 |
|
| 159 |
void DumpContentToFile(const char *filename); |
| 160 |
|
| 161 |
virtual int32_t UpdateSurfaceProperty(uint32_t width, uint32_t height, uint32_t pitch, CM_SURFACE_FORMAT format); |
| 162 |
|
| 163 |
protected: |
| 164 |
CmSurface2DRTBase(unsigned int handle, |
| 165 |
unsigned int width, |
| 166 |
unsigned int height, |
| 167 |
unsigned int pitch, |
| 168 |
CM_SURFACE_FORMAT format, |
| 169 |
CmSurfaceManager *pSurfaceManager, |
| 170 |
bool isCmCreated); |
| 171 |
|
| 172 |
virtual ~CmSurface2DRTBase(); |
| 173 |
|
| 174 |
int32_t Initialize(unsigned int index); |
| 175 |
|
| 176 |
unsigned int m_width; |
| 177 |
|
| 178 |
unsigned int m_height; |
| 179 |
|
| 180 |
unsigned int m_handle; |
| 181 |
|
| 182 |
unsigned int m_pitch; |
| 183 |
|
| 184 |
CM_SURFACE_FORMAT m_format; |
| 185 |
|
| 186 |
// a pointer to UMD resource, set to nullptr if no UMD resource related to |
| 187 |
void *m_umdResource; |
| 188 |
|
| 189 |
// number of surfaces created as an alias |
| 190 |
unsigned int m_numAliases; |
| 191 |
|
| 192 |
SurfaceIndex *m_aliasIndexes[CM_HAL_MAX_NUM_2D_ALIASES]; |
| 193 |
|
| 194 |
CM_FRAME_TYPE m_frameType; |
| 195 |
}; |
| 196 |
}; //namespace |
| 197 |
|
| 198 |
#endif // #ifndef MEDIADRIVER_COMMON_CM_CMSURFACE2DRT_BASE_H_ |