xref: /aosp_15_r20/external/intel-media-driver/media_driver/linux/common/cm/hal/cm_surface_2d_rt.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2007-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 //!
23 //! \file      cm_surface_2d_rt_os.cpp
24 //! \brief     Contains Linux-dependent CmSurface2DRT member functions.
25 //!
26 
27 #include "cm_surface_2d_rt.h"
28 
29 #include "cm_surface_manager.h"
30 #include "cm_device_rt.h"
31 #include "cm_mem.h"
32 
33 #define COPY_OPTION(option)    (option & 0x1)
34 
35 namespace CMRT_UMD
36 {
37 //*-----------------------------------------------------------------------------
38 //| Purpose:    Constructor of CmSurface2D
39 //| Returns:    None.
40 //*-----------------------------------------------------------------------------
CmSurface2DRT(uint32_t handle,uint32_t width,uint32_t height,uint32_t pitch,CM_SURFACE_FORMAT format,CmSurfaceManager * surfaceManager,bool isCmCreated)41 CmSurface2DRT::CmSurface2DRT(
42     uint32_t handle,
43     uint32_t width,
44     uint32_t height,
45     uint32_t pitch,
46     CM_SURFACE_FORMAT format,
47     CmSurfaceManager* surfaceManager ,
48     bool isCmCreated):
49     CmSurface2DRTBase(handle, width, height, pitch, format, surfaceManager, isCmCreated),
50     m_vaSurfaceID(0),
51     m_vaCreated(0),
52     m_vaDisplay(nullptr)
53 {
54 }
55 
56 //*-----------------------------------------------------------------------------
57 //| Purpose:    Destructor of CmSurface2D
58 //| Returns:    None.
59 //*-----------------------------------------------------------------------------
~CmSurface2DRT(void)60 CmSurface2DRT::~CmSurface2DRT( void )
61 {
62     for( uint32_t i = 0; i < CM_HAL_MAX_NUM_2D_ALIASES; ++i )
63     {
64         MosSafeDelete(m_aliasIndexes[i]);
65     }
66     if(m_vaCreated && IsCmCreated())
67    // if(m_vaCreated )
68     {
69         // Release VA Surface created in thin layer via call back
70         CmDeviceRT *device;
71         m_surfaceMgr->GetCmDevice(device);
72         device->ReleaseVASurface(m_vaDisplay, &m_vaSurfaceID);
73     }
74 }
75 
76 //*-----------------------------------------------------------------------------
77 //| Purpose:    Create Surface 2D
78 //| Arguments :
79 //|               index             [in]     index in runtime Surface2D table
80 //|               handle            [in]     index in driver's surface2D table
81 //|               width             [in]     width of the  CmSurface2D
82 //|               height            [in]     height of the CmSurface2D
83 //|               pitch             [in]     pitch of the CmSurface2D
84 //|               format            [out]    format of CmSurface2D
85 //|               isCmCreated       [out]    ture,if the surface created by CM;
86 //|                                          false,if the surface created externally
87 //|               surfaceManager   [out]    Pointer to CmSurfaceManager
88 //|               surface          [out]    Reference to the Pointer to CmSurface2D
89 
90 //| Returns:    Result of the operation.
91 //*-----------------------------------------------------------------------------
Create(uint32_t index,uint32_t handle,uint32_t width,uint32_t height,uint32_t pitch,CM_SURFACE_FORMAT format,bool isCmCreated,CmSurfaceManager * surfaceManager,CmSurface2DRT * & surface)92 int32_t CmSurface2DRT::Create(
93                            uint32_t index,
94                            uint32_t handle,
95                            uint32_t width,
96                            uint32_t height,
97                            uint32_t pitch,
98                            CM_SURFACE_FORMAT format,
99                            bool isCmCreated,
100                            CmSurfaceManager* surfaceManager,
101                            CmSurface2DRT* &surface )
102 {
103     int32_t result = CM_SUCCESS;
104 
105     surface = new (std::nothrow) CmSurface2DRT( handle,width,height, pitch,format,surfaceManager, isCmCreated);
106     if( surface )
107     {
108         result = surface->Initialize( index );
109         if( result != CM_SUCCESS )
110         {
111             CmSurface* baseSurface = surface;
112             CmSurface::Destroy( baseSurface );
113         }
114     }
115     else
116     {
117         CM_ASSERTMESSAGE("Error: Failed to CmSurface2DRTBase due to out of system memory.")
118         result = CM_OUT_OF_HOST_MEMORY;
119     }
120 
121     return result;
122 }
123 
SetVaSurfaceID(VASurfaceID vaSurface,void * vaDisplay)124 int32_t CmSurface2DRT::SetVaSurfaceID( VASurfaceID  vaSurface, void  *vaDisplay)
125 {
126     m_vaSurfaceID = vaSurface;
127     m_vaCreated  = true;
128     m_vaDisplay      = vaDisplay;
129 
130     return CM_SUCCESS;
131 }
GetVaSurfaceID(VASurfaceID & vaSurface)132 CM_RT_API int32_t CmSurface2DRT::GetVaSurfaceID( VASurfaceID  &vaSurface)
133 {
134    vaSurface = m_vaSurfaceID;
135    return CM_SUCCESS;
136 }
137 }  // namespace
138