1 /*
2 * Copyright (c) 2017, 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 #ifndef CMRTLIB_LINUX_HARDWARE_CM_SURFACE_MANAGER_H_
23 #define CMRTLIB_LINUX_HARDWARE_CM_SURFACE_MANAGER_H_
24 
25 #include "cm_def_os.h"
26 #include "cm_include.h"
27 
28 class CmDevice_RT;
29 class CmSurface2D;
30 class CmSurface2DUP;
31 class CmSurface3D;
32 class CmBuffer;
33 class CmBufferUP;
34 class CmBufferSVM;
35 class CmBufferStateless;
36 
37 class CmSurfaceManager
38 {
39 public:
40     CmSurfaceManager(CmDevice_RT *device);
41 
42     ~CmSurfaceManager();
43 
44     int32_t CreateSurface2D(uint32_t width,
45                         uint32_t height,
46                         CM_SURFACE_FORMAT format,
47                         CmSurface2D* &surface);
48 
49     int32_t CreateSurface2D(VASurfaceID *vaSurface, CmSurface2D *&surface);
50 
51     int32_t CreateSurface2D(VASurfaceID *vaSurface,
52                         uint32_t firstArraySlice,
53                         uint32_t mipSlice,
54                         CmSurface2D *&surface);
55 
56     int32_t DestroySurface(CmSurface2D* &surface);
57 
58     int32_t CreateBuffer(uint32_t size, CmBuffer* &buffer);
59 
60     int32_t CreateBufferUP(uint32_t size,
61                        void *sysMem,
62                        CmBufferUP* &buffer);
63 
64     int32_t DestroyBuffer(CmBuffer *&buffer);
65 
66     int32_t DestroyBufferUP(CmBufferUP *&buffer);
67 
68     int32_t CreateSurface2DUP(uint32_t width,
69                           uint32_t height,
70                           CM_SURFACE_FORMAT format,
71                           void *sysMem,
72                           CmSurface2DUP* &surface);
73 
74     int32_t DestroySurface2DUP(CmSurface2DUP* &surface);
75 
76     int32_t CreateSurface3D(uint32_t width,
77                         uint32_t height,
78                         uint32_t depth,
79                         CM_SURFACE_FORMAT format,
80                         CmSurface3D *&surface);
81 
82     int32_t DestroySurface3D(CmSurface3D *&surface);
83 
84     int32_t CreateBufferSVM(uint32_t size,
85                         void* &sysMem,
86                         uint32_t accessFlag,
87                         CmBufferSVM* &buffer);
88 
89     int32_t DestroyBufferSVM(CmBufferSVM* &buffer);
90 
91     int32_t CreateVaSurface2D(uint32_t width,
92                           uint32_t height,
93                           CM_SURFACE_FORMAT format,
94                           VASurfaceID &vaSurface,
95                           CmSurface2D* &surface);
96 
97     int32_t CreateSurface2D(VASurfaceID vaSurface, CmSurface2D* &surface);
98 
99     int32_t CreateSurface2D(VASurfaceID *vaSurfaceArray,
100                         const uint32_t surfaceCount,
101                         CmSurface2D **surfaceArray);
102 
103     int32_t CreateBufferStateless(size_t size,
104                                   uint32_t option,
105                                   void *sysMem,
106                                   CmBufferStateless *&buffer);
107 
108     int32_t DestroyBufferStateless(CmBufferStateless *&buffer);
109 
110 protected:
111     int32_t CreateSurface2D(VASurfaceID &vaSurface,
112                         bool cmCreated,
113                         bool createdByLibva,
114                         CmSurface2D* &surface);
115 
116     int32_t ConvertToLibvaFormat(int32_t format);
117 
118     int32_t AllocateSurface2DInUmd(uint32_t width,
119                              uint32_t height,
120                              CM_SURFACE_FORMAT format,
121                              bool cmCreated,
122                              bool createdByLibva,
123                              VASurfaceID vaSurface,
124                              CmSurface2D* &surface);
125 
126     int32_t Surface2DSanityCheck(uint32_t width,
127                              uint32_t height,
128                              CM_SURFACE_FORMAT format);
129 
130     int32_t DestroySurface2DInUmd(CmSurface2D* &surface);
131 
132 private:
133     CmDevice_RT *m_device;
134 
135 private:
136     CmSurfaceManager(const CmSurfaceManager &other);
137     CmSurfaceManager &operator=(const CmSurfaceManager &other);
138 
139 };
140 
141 #endif  // #ifndef CMRTLIB_LINUX_HARDWARE_CM_SURFACE_MANAGER_H_
142