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 #pragma once
30 
31 #include "cm_surface.h"
32 class CmSurface;
33 class CmEvent;
34 
35 class CmBufferUP {
36  public:
37 	CM_RT_API virtual INT GetIndex(SurfaceIndex * &pIndex) = 0;
38 	CM_RT_API virtual CM_ENUM_CLASS_TYPE Type() const = 0;
39 	CM_RT_API virtual INT SetMemoryObjectControl(MEMORY_OBJECT_CONTROL
40 						     mem_ctrl,
41 						     MEMORY_TYPE mem_type,
42 						     UINT age) = 0;
43 
~CmBufferUP()44 	 virtual ~ CmBufferUP() {
45 	};
46 };
47 
48 class CmBuffer {
49  public:
50 
51 	CM_RT_API virtual INT GetIndex(SurfaceIndex * &pIndex) = 0;
52 	CM_RT_API virtual INT ReadSurface(unsigned char *pSysMem,
53 					  CmEvent * pEvent, UINT64 sysMemSize =
54 					  0xFFFFFFFFFFFFFFFFULL) = 0;
55 	CM_RT_API virtual INT WriteSurface(const unsigned char *pSysMem,
56 					   CmEvent * pEvent, UINT64 sysMemSize =
57 					   0xFFFFFFFFFFFFFFFFULL) = 0;
58 
59 	CM_RT_API virtual CM_ENUM_CLASS_TYPE Type() const = 0;
60 
~CmBuffer()61 	 virtual ~ CmBuffer() {
62 	};
63 
64 	CM_RT_API virtual INT InitSurface(const DWORD initValue,
65 					  CmEvent * pEvent) = 0;
66 	CM_RT_API virtual INT SetMemoryObjectControl(MEMORY_OBJECT_CONTROL
67 						     mem_ctrl,
68 						     MEMORY_TYPE mem_type,
69 						     UINT age) = 0;
70 };
71 
72 class CmBuffer_RT:public CmBuffer, public CmBufferUP, public CmSurface {
73  public:
74 	static INT Create(UINT index, UINT handle, UINT size, BOOL bIsCmCreated,
75 			  CmSurfaceManager * pSurfaceManager, UINT uiBufferType,
76 			  void *pSysMem, CmBuffer_RT * &pSurface);
77 	CM_RT_API INT ReadSurface(unsigned char *pSysMem, CmEvent * pEvent,
78 				  UINT64 sysMemSize = 0xFFFFFFFFFFFFFFFFULL);
79 	CM_RT_API INT WriteSurface(const unsigned char *pSysMem,
80 				   CmEvent * pEvent, UINT64 sysMemSize =
81 				   0xFFFFFFFFFFFFFFFFULL);
82 	CM_RT_API INT InitSurface(const DWORD initValue, CmEvent * pEvent);
83 
84 	CM_RT_API INT GetIndex(SurfaceIndex * &pIndex);
85 	INT GetHandle(UINT & handle);
Type()86 	CM_RT_API CM_ENUM_CLASS_TYPE Type() const {
87 		return CM_ENUM_CLASS_TYPE_CMBUFFER_RT;
88 	};
89 	CM_RT_API INT SetMemoryObjectControl(MEMORY_OBJECT_CONTROL mem_ctrl,
90 					     MEMORY_TYPE mem_type, UINT age);
91 	CM_RT_API INT GetAddress(VOID * &pAddr);
92 
93 	INT GetSize(UINT & size);
94 	INT SetSize(UINT size);
95 	BOOL IsUpSurface();
96 
GetBufferType()97 	UINT GetBufferType() {
98 		return m_uiBufferType;
99  } protected:
100 	 CmBuffer_RT(UINT handle, UINT size, BOOL bIsCmCreated,
101 		     CmSurfaceManager * pSurfaceManager, UINT uiBufferType,
102 		     VOID * pSysMem);
103 	~CmBuffer_RT(void);
104 
105 	INT Initialize(UINT index);
106 
107 	UINT m_Handle;
108 	UINT m_Size;
109 	UINT m_uiBufferType;
110 	PVOID m_pSysMem;
111 };
112