1 /*
2  * Copyright � 2014 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
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *     Wei Lin<wei.w.lin@intel.com>
26  *     Yuting Yang<yuting.yang@intel.com>
27  *     Lina Sun<lina.sun@intel.com>
28  */
29 
30 #pragma once
31 #include "cm_surface.h"
32 #include "cm_surface_2d_base.h"
33 
34 class CmEvent;
35 class CmSurfaceManager;
36 
37 class CmSurface2D_RT: public CmSurface2D, public CmSurface {
38  public:
39 	static INT Create(UINT index, UINT handle, UINT width, UINT height,
40 			  UINT pitch, CM_SURFACE_FORMAT format,
41 			  BOOL isCmCreated, CmSurfaceManager * pSurfaceManager,
42 			  CmSurface2D_RT * &pSurface);
43 
44 	CM_RT_API INT ReadSurface(unsigned char *pSysMem, CmEvent * pEvent,
45 				  UINT64 sysMemSize = 0xFFFFFFFFFFFFFFFFULL);
46 	CM_RT_API INT WriteSurface(const unsigned char *pSysMem,
47 				   CmEvent * pEvent, UINT64 sysMemSize =
48 				   0xFFFFFFFFFFFFFFFFULL);
49 	CM_RT_API INT ReadSurfaceStride(unsigned char *pSysMem,
50 					CmEvent * pEvent, const UINT stride,
51 					UINT64 sysMemSize =
52 					0xFFFFFFFFFFFFFFFFULL);
53 	CM_RT_API INT WriteSurfaceStride(const unsigned char *pSysMem,
54 					 CmEvent * pEvent, const UINT stride,
55 					 UINT64 sysMemSize =
56 					 0xFFFFFFFFFFFFFFFFULL);
57 
58 	CM_RT_API INT GetIndex(SurfaceIndex * &pIndex);
59 	CM_RT_API INT GetSurfaceDesc(UINT & width, UINT & height,
60 				     CM_SURFACE_FORMAT & format,
61 				     UINT & sizeperpixel);
62 	CM_RT_API INT InitSurface(const DWORD initValue, CmEvent * pEvent);
63 	CM_RT_API INT SetSurfaceStateDimensions(UINT iWidth, UINT iHeight,
64 						SurfaceIndex * pSurfIndex =
65 						NULL);
66 	CM_RT_API INT ReadSurfaceFullStride(unsigned char *pSysMem,
67 					    CmEvent * pEvent,
68 					    const UINT iWidthStride,
69 					    const UINT iHeightStride,
70 					    UINT64 sysMemSize);
71 	CM_RT_API INT WriteSurfaceFullStride(const unsigned char *pSysMem,
72 					     CmEvent * pEvent,
73 					     const UINT iWidthStride,
74 					     const UINT iHeightStride,
75 					     UINT64 sysMemSize);
76 
77 	INT GetIndexFor2D(UINT & index);
78 	INT GetHandle(UINT & handle);
79 	INT SetSurfaceProperties(UINT width, UINT height,
80 				 CM_SURFACE_FORMAT format);
Type()81 	CM_ENUM_CLASS_TYPE Type() const {
82 		return CM_ENUM_CLASS_TYPE_CMSURFACE2D;
83 	};
84 	CM_RT_API INT SetMemoryObjectControl(MEMORY_OBJECT_CONTROL mem_ctrl,
85 					     MEMORY_TYPE mem_type, UINT age);
86 
87 	INT GetSubResourceIndex(UINT & nIndex);
88 	INT SetSubResourceIndex(UINT nIndex);
89 	INT SetReadSyncFlag();
90 
91  protected:
92 	 CmSurface2D_RT(UINT handle, UINT width, UINT height, UINT pitch,
93 		     CM_SURFACE_FORMAT format,
94 		     CmSurfaceManager * pSurfaceManager, BOOL isCmCreated);
95 	~CmSurface2D_RT(void);
96 
97 	INT Initialize(UINT index);
98 
99 	UINT m_Width;
100 	UINT m_Height;
101 	UINT m_Handle;
102 	UINT m_Pitch;
103 	CM_SURFACE_FORMAT m_Format;
104 
105 	UINT m_SubResourceIndex;
106 };
107