1 /*
2 * Copyright (c) 2020-2022, 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     media_blt_copy.h
24 //! \brief    Common interface and structure used in Blitter Engine
25 //! \details  Common interface and structure used in Blitter Engine which are platform independent
26 //!
27 #ifndef __MEDIA_BLT_COPY_H__
28 #define __MEDIA_BLT_COPY_H__
29 
30 #include <stdint.h>
31 #include "mos_defs.h"
32 #include "mos_os_specific.h"
33 #include "mos_resource_defs.h"
34 #include "mos_util_debug.h"
35 #include "media_interfaces_mhw.h"
36 #include "mhw_blt_legacy.h"
37 #include "mos_os.h"
38 #include "media_class_trace.h"
39 #include "media_copy_common.h"
40 class MhwCpInterface;
41 class MhwMiInterface;
42 
43 #define BLT_CHK_STATUS(_stmt)               MOS_CHK_STATUS(MOS_COMPONENT_MCPY, MOS_MCPY_SUBCOMP_BLT, _stmt)
44 #define BLT_CHK_STATUS_RETURN(_stmt)        MOS_CHK_STATUS_RETURN(MOS_COMPONENT_MCPY, MOS_MCPY_SUBCOMP_BLT, _stmt)
45 #define BLT_CHK_NULL(_ptr)                  MOS_CHK_NULL(MOS_COMPONENT_MCPY, MOS_MCPY_SUBCOMP_BLT, _ptr)
46 #define BLT_CHK_NULL_RETURN(_ptr)           MOS_CHK_NULL_RETURN(MOS_COMPONENT_MCPY, MOS_MCPY_SUBCOMP_BLT, _ptr)
47 #define BLT_ASSERTMESSAGE(_message, ...)    MOS_ASSERTMESSAGE(MOS_COMPONENT_MCPY, MOS_MCPY_SUBCOMP_BLT, _message, ##__VA_ARGS__)
48 
49 class BltState
50 {
51 public:
52     //!
53     //! \brief    BltState constructor
54     //! \details  Initialize the BltState members.
55     //! \param    osInterface
56     //!           [in] Pointer to MOS_INTERFACE.
57     //!
58     BltState(PMOS_INTERFACE     osInterface);
59     BltState(PMOS_INTERFACE    osInterface, MhwInterfaces* mhwInterfaces);
60 
61     virtual ~BltState();
62 
63     //!
64     //! \brief    BltState initialize
65     //! \details  Initialize the BltState, create BLT context.
66     //! \return   MOS_STATUS
67     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
68     //!
69     virtual MOS_STATUS Initialize();
70 
71     //!
72     //! \brief    Copy main surface
73     //! \details  BLT engine will copy source surface to destination surface
74     //! \param    src
75     //!           [in] Pointer to source surface
76     //! \param    dst
77     //!           [in] Pointer to destination surface
78     //! \return   MOS_STATUS
79     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
80     //!
81     virtual MOS_STATUS CopyMainSurface(
82         PMOS_SURFACE src,
83         PMOS_SURFACE dst);
84 
85     //!
86     //! \brief    Copy main surface
87     //! \details  BLT engine will copy source surface to destination surface
88     //! \param    src
89     //!           [in] Pointer to source resource
90     //! \param    dst
91     //!           [in] Pointer to destination resource
92     //! \return   MOS_STATUS
93     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
94     //!
95     virtual MOS_STATUS CopyMainSurface(
96         PMOS_RESOURCE src,
97         PMOS_RESOURCE dst);
98     //!
99     //! \brief    Setup blt copy parameters
100     //! \details  Setup blt copy parameters for BLT Engine
101     //! \param    mhwParams
102     //!           [in/out] Pointer to MHW_FAST_COPY_BLT_PARAM
103     //! \param    inputSurface
104     //!           [in] Pointer to input surface
105     //! \param    outputSurface
106     //!           [in] Pointer to output surface
107     //! \param    planeIndex
108     //!           [in] Pointer to YUV(RGB) plane index
109     //! \return   MOS_STATUS
110     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
111     //!
112     virtual MOS_STATUS SetupBltCopyParam(
113       PMHW_FAST_COPY_BLT_PARAM mhwParams,
114       PMOS_RESOURCE            inputSurface,
115       PMOS_RESOURCE            outputSurface,
116       int                      planeIndex);
117 
118     //!
119     //! \brief    Submit command
120     //! \details  Submit BLT command
121     //! \param    pBltStateParam
122     //!           [in] Pointer to BLT_STATE_PARAM
123     //! \return   MOS_STATUS
124     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
125     //!
126     virtual MOS_STATUS SubmitCMD(
127         PBLT_STATE_PARAM pBltStateParam);
128 
129     //!
130     //! \brief    Get control surface
131     //! \details  BLT engine will copy aux data of source surface to destination
132     //! \param    src
133     //!           [in] Pointer to source surface
134     //! \param    dst
135     //!           [in] Pointer to destination buffer which is created for aux data
136     //! \return   MOS_STATUS
137     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
138     //!
GetCCS(PMOS_SURFACE src,PMOS_SURFACE dst)139     virtual MOS_STATUS GetCCS(
140         PMOS_SURFACE src,
141         PMOS_SURFACE dst)
142     {
143         return MOS_STATUS_SUCCESS;
144     }
145 
146     //!
147     //! \brief    Get Block copy color depth.
148     //! \details  get different format's color depth.
149     //! \param    Gmm format and bits per Pixel
150     //!           [in] Gmm format, Bits per Pixel;
151     //! \return   color depth
152     //!           Return color depth
153     //!
154     uint32_t GetBlkCopyColorDepth(
155         GMM_RESOURCE_FORMAT dstFormat,
156         uint32_t            BitsPerPixel);
157 
158     //!
159     //! \brief    Get Fast copy color depth.
160     //! \details  get different format's color depth.
161     //! \param    Gmm format and bits per Pixel
162     //!           [in] Gmm format, Bits per Pixel;
163     //! \return   MOS_STATUS
164     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
165     //!
166     uint32_t GetFastCopyColorDepth(
167         GMM_RESOURCE_FORMAT dstFormat,
168         uint32_t            BitsPerPixel);
169     //!
170     //! \brief    Get plane's byte per texel
171     //! \details  Get plane's byte per texel
172     //! \param    MOS_FORMAT format
173     //!           [in] GMM resource format
174     //! \return   int
175     //!           return the scaling ratio;
176     //!
177     int GetBytesPerTexelScaling(MOS_FORMAT format);
178 
179     //!
180     //! \brief    Get plane number
181     //! \details  Get plane number
182     //! \param    MOS_FORMAT format
183     //!           [in] GMM resource format
184     //! \return   int
185     //!           return the plane number
186     //!
187     int GetPlaneNum(MOS_FORMAT format);
188 
189     //!
190     //! \brief    SetPrologParamsforCmdbuffer
191     //! \details  Set PrologParams for Cmdbuffer
192     //! \param    PMOS_COMMAND_BUFFER
193     //!           [in] Pointer to PMOS_COMMAND_BUFFER
194     //! \return   MOS_STATUS
195     //!           Return MOS_STATUS_SUCCESS if successful, otherwise failed
196     //!
197     MOS_STATUS SetPrologParamsforCmdbuffer(PMOS_COMMAND_BUFFER cmdBuffer);
198 
199 public:
200     bool           m_blokCopyon       = false;
201     PMOS_INTERFACE m_osInterface      = nullptr;
202     MhwInterfaces *m_mhwInterfaces    = nullptr;
203     MhwMiInterface *m_miInterface     = nullptr;
204     PMHW_BLT_INTERFACE m_bltInterface = nullptr;
205     MhwCpInterface *m_cpInterface     = nullptr;
206     MhwInterfaces::CreateParams params;
207 MEDIA_CLASS_DEFINE_END(BltState)
208 };
209 
210 #endif // __MEDIA_BLT_COPY_H__
211