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 #include "cm_surface_2d_up.h"
31 #include "cm_device.h"
32 #include "cm_surface_manager.h"
33
Create(UINT index,UINT handle,UINT width,UINT height,CM_SURFACE_FORMAT format,CmSurfaceManager * pSurfaceManager,CmSurface2DUP_RT * & pSurface)34 INT CmSurface2DUP_RT::Create(UINT index, UINT handle, UINT width, UINT height,
35 CM_SURFACE_FORMAT format,
36 CmSurfaceManager * pSurfaceManager,
37 CmSurface2DUP_RT * &pSurface)
38 {
39 INT result = CM_SUCCESS;
40
41 pSurface =
42 new(std::nothrow) CmSurface2DUP_RT(handle, width, height, format,
43 pSurfaceManager);
44 if (pSurface) {
45 result = pSurface->Initialize(index);
46 if (result != CM_SUCCESS) {
47 CmSurface *pBaseSurface = pSurface;
48 CmSurface::Destroy(pBaseSurface);
49 }
50
51 } else {
52 CM_ASSERT(0);
53 result = CM_OUT_OF_HOST_MEMORY;
54 }
55
56 return result;
57
58 }
59
CmSurface2DUP_RT(UINT handle,UINT width,UINT height,CM_SURFACE_FORMAT format,CmSurfaceManager * pSurfaceManager)60 CmSurface2DUP_RT::CmSurface2DUP_RT(UINT handle, UINT width, UINT height, CM_SURFACE_FORMAT format, CmSurfaceManager * pSurfaceManager):
61 CmSurface(pSurfaceManager, TRUE),
62 m_Handle(handle), m_Width(width), m_Height(height), m_Format(format)
63 {
64 CmSurface::SetMemoryObjectControl(MEMORY_OBJECT_CONTROL_UNKNOW,
65 CM_USE_PTE, 0);
66 }
67
~CmSurface2DUP_RT(void)68 CmSurface2DUP_RT::~CmSurface2DUP_RT(void)
69 {
70
71 }
72
Initialize(UINT index)73 INT CmSurface2DUP_RT::Initialize(UINT index)
74 {
75 return CmSurface::Initialize(index);
76
77 }
78
GetHandle(UINT & handle)79 INT CmSurface2DUP_RT::GetHandle(UINT & handle)
80 {
81 handle = m_Handle;
82 return CM_SUCCESS;
83 }
84
GetIndex(SurfaceIndex * & pIndex)85 CM_RT_API INT CmSurface2DUP_RT::GetIndex(SurfaceIndex * &pIndex)
86 {
87 pIndex = m_pIndex;
88 return CM_SUCCESS;
89 }
90
91 CM_RT_API INT
SetMemoryObjectControl(MEMORY_OBJECT_CONTROL mem_ctrl,MEMORY_TYPE mem_type,UINT age)92 CmSurface2DUP_RT::SetMemoryObjectControl(MEMORY_OBJECT_CONTROL mem_ctrl,
93 MEMORY_TYPE mem_type, UINT age)
94 {
95 CmSurface::SetMemoryObjectControl(mem_ctrl, mem_type, age);
96
97 return CM_SUCCESS;
98 }
99
100 CM_RT_API INT
GetSurfaceDesc(UINT & width,UINT & height,CM_SURFACE_FORMAT & format,UINT & sizeperpixel)101 CmSurface2DUP_RT::GetSurfaceDesc(UINT & width, UINT & height,
102 CM_SURFACE_FORMAT & format,
103 UINT & sizeperpixel)
104 {
105 int ret = CM_SUCCESS;
106 UINT updatedHeight = 0;
107
108 width = m_Width;
109 height = m_Height;
110 format = m_Format;
111
112 ret =
113 m_SurfaceMgr->GetPixelBytesAndHeight(width, height, format,
114 sizeperpixel, updatedHeight);
115
116 return ret;
117 }
118