1 /*
2 * Copyright (c) 2018-2024, 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     vp_scaling_filter.h
24 //! \brief    Defines the common interface for scaling
25 //!           this file is for the base interface which is shared by all scaling in driver.
26 //!
27 #ifndef __VP_SCALING_FILTER_H__
28 #define __VP_SCALING_FILTER_H__
29 
30 #include "vp_filter.h"
31 #include "sw_filter.h"
32 
33 namespace vp {
34 class VpScalingFilter : public VpFilter
35 {
36 public:
37 
38     VpScalingFilter(
39         PVP_MHWINTERFACE vpMhwInterface);
40 
~VpScalingFilter()41     virtual ~VpScalingFilter()
42     {
43         Destroy();
44     };
45 
46     virtual MOS_STATUS Init() override;
47 
48     virtual MOS_STATUS Init(
49         CODECHAL_STANDARD           codecStandard,
50         CodecDecodeJpegChromaType   jpegChromaType);
51 
52     virtual MOS_STATUS Prepare() override;
53 
54     virtual MOS_STATUS Destroy() override;
55 
56     virtual MOS_STATUS SetExecuteEngineCaps(
57         FeatureParamScaling     &scalingParams,
58         VP_EXECUTE_CAPS         vpExecuteCaps);
59 
60     MOS_STATUS CalculateEngineParams();
GetSfcParams()61     SFC_SCALING_PARAMS *GetSfcParams()
62     {
63         return m_sfcScalingParams;
64     }
65 
66 protected:
67     //!
68     //! \brief      Gen specific function for SFC adjust boundary
69     //! \details    Adjust the width and height of the input surface for SFC
70     //! \param      [out] pdwSurfaceWidth
71     //!             Pointer to adjusted surface width
72     //! \param      [out] pdwSurfaceHeight
73     //!             Pointer to adjusted surface height
74     //! \return     MOS_STATUS
75     //!             MOS_STATUS_SUCCESS if success, else fail reason
76     //!
77     MOS_STATUS SfcAdjustBoundary(
78         uint32_t                   *pdwSurfaceWidth,
79         uint32_t                   *pdwSurfaceHeight);
80 
81     MOS_STATUS SetTargetRectangle(
82         uint16_t iWidthAlignUnit,
83         uint16_t iHeightAlignUnit,
84         uint16_t oWidthAlignUnit,
85         uint16_t oHeightAlignUnit,
86         float    scaleX,
87         float    scaleY);
88 
89     //!
90     //! \brief    Get width and height align unit of input format
91     //! \param    [in] format
92     //!           format
93     //! \param    [in] bOutput
94     //!           is Output or not
95     //! \param    [in] bRotateNeeded
96     //!           is rotated or not
97     //! \param    [out] widthAlignUnit
98     //!           width align unit
99     //! \param    [out] heightAlignUnit
100     //!           height align unit
101     //! \return   void
102     //!
103     virtual void GetFormatWidthHeightAlignUnit(
104         MOS_FORMAT              format,
105         bool                    bOutput,
106         bool                    bRotateNeeded,
107         uint16_t                &widthAlignUnit,
108         uint16_t                &heightAlignUnit,
109         bool                    isInterlacedScaling);
110 
111     //!
112     //! \brief    check whether colorfill enable or not
113     //! \return   MOS_STATUS
114     //!  MOS_STATUS_SUCCESS if success, else fail reason
115     //!
116     MOS_STATUS IsColorfillEnable();
117 
118     //!
119     //! \brief    set colorfill Params
120     //! \return   MOS_STATUS
121     //!  MOS_STATUS_SUCCESS if success, else fail reason
122     //!
123     MOS_STATUS SetColorFillParams();
124 
125     //!
126     //! \brief    set colorfill YUV/RGB Pixel values
127     //! \return   MOS_STATUS
128     //!  MOS_STATUS_SUCCESS if success, else fail reason
129     //!
130     MOS_STATUS SetYUVRGBPixel();
131 
132     //!
133     //! \brief    set Alpha values
134     //! \return   MOS_STATUS
135     //!  MOS_STATUS_SUCCESS if success, else fail reason
136     //!
137     MOS_STATUS SetAlphaPixelParams();
138 
139     //!
140     //! \brief    set Src/Dst rect values
141     //! \return   MOS_STATUS
142     //!  MOS_STATUS_SUCCESS if success, else fail reason
143     //!
144     MOS_STATUS SetRectSurfaceAlignment(bool isOutputSurf, uint32_t &width, uint32_t &height, RECT &rcSrc, RECT &rcDst);
145 
146 protected:
147     FeatureParamScaling          m_scalingParams     = {};
148     SFC_SCALING_PARAMS          *m_sfcScalingParams  = nullptr;
149     float                        fScaleX             = 0.0f;
150     float                        fScaleY             = 0.0f;
151 
152     // colorfill params
153     bool                         m_bColorfillEnable  = false;
154     VPHAL_COLOR_SAMPLE_8         m_colorFillColorSrc = {};                 //!< ColorFill Sample from DDI
155     VPHAL_COLOR_SAMPLE_8         m_colorFillColorDst = {};                 //!< ColorFill Sample programmed in Sfc State
156     VPHAL_CSPACE                 m_colorFillSrcCspace = {};                //!< Cspace of the source ColorFill Color
157     VPHAL_CSPACE                 m_colorFillRTCspace = {};                 //!< Cspace of the Render Target
158 
159     bool                         m_bVdbox            = false;
160     CODECHAL_STANDARD            m_codecStandard     = CODECHAL_STANDARD_MAX;
161     CodecDecodeJpegChromaType    m_jpegChromaType    = jpegYUV400;
162 
163 MEDIA_CLASS_DEFINE_END(vp__VpScalingFilter)
164 };
165 
166 struct HW_FILTER_SCALING_PARAM : public HW_FILTER_PARAM
167 {
168     FeatureParamScaling     scalingParams;
169 };
170 
171 class HwFilterScalingParameter : public HwFilterParameter
172 {
173 public:
174     static HwFilterParameter *Create(HW_FILTER_SCALING_PARAM &param, FeatureType featureType);
175     HwFilterScalingParameter(FeatureType featureType);
176     virtual ~HwFilterScalingParameter();
177     virtual MOS_STATUS ConfigParams(HwFilter &hwFilter);
178     MOS_STATUS Initialize(HW_FILTER_SCALING_PARAM &param);
179 
180 private:
181 
182     HW_FILTER_SCALING_PARAM         m_Params = {};
183 
184 MEDIA_CLASS_DEFINE_END(vp__HwFilterScalingParameter)
185 };
186 
187 class VpSfcScalingParameter : public VpPacketParameter
188 {
189 public:
190     static VpPacketParameter *Create(HW_FILTER_SCALING_PARAM &param);
191     VpSfcScalingParameter(PVP_MHWINTERFACE pHwInterface, PacketParamFactoryBase *packetParamFactory);
192     virtual ~VpSfcScalingParameter();
193     virtual bool SetPacketParam(VpCmdPacket *pPacket);
194 
195 private:
196     MOS_STATUS Initialize(HW_FILTER_SCALING_PARAM &params);
197 
198     VpScalingFilter m_ScalingFilter;
199 
200 MEDIA_CLASS_DEFINE_END(vp__VpSfcScalingParameter)
201 };
202 
203 class PolicySfcScalingHandler : public PolicyFeatureHandler
204 {
205 public:
206     PolicySfcScalingHandler(VP_HW_CAPS &hwCaps);
207     virtual ~PolicySfcScalingHandler();
208     virtual bool IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps);
209     virtual HwFilterParameter *CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface);
210     virtual MOS_STATUS UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
CreatePacketParam(HW_FILTER_PARAM & param)211     static VpPacketParameter* CreatePacketParam(HW_FILTER_PARAM& param)
212     {
213         if (param.type != FeatureTypeScalingOnSfc)
214         {
215             VP_PUBLIC_ASSERTMESSAGE("Invalid parameter for SFC Scaling!");
216             return nullptr;
217         }
218 
219         HW_FILTER_SCALING_PARAM* scalingParam = (HW_FILTER_SCALING_PARAM*)(&param);
220         return VpSfcScalingParameter::Create(*scalingParam);
221     }
222 
223     virtual MOS_STATUS UpdateUnusedFeature(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
224 
225 
226 private:
227     uint32_t Get1stPassScaledSize(uint32_t input, uint32_t output, bool is2PassNeeded, uint32_t alignUnit);
228 
229     PacketParamFactory<VpSfcScalingParameter> m_PacketParamFactory;
230 
231 MEDIA_CLASS_DEFINE_END(vp__PolicySfcScalingHandler)
232 };
233 
234 class PolicySfcColorFillHandler : public PolicyFeatureHandler
235 {
236 public:
PolicySfcColorFillHandler(VP_HW_CAPS & hwCaps)237     PolicySfcColorFillHandler(VP_HW_CAPS &hwCaps) : PolicyFeatureHandler(hwCaps)
238     {
239         m_Type = FeatureTypeColorFillOnSfc;
240     }
~PolicySfcColorFillHandler()241     virtual ~PolicySfcColorFillHandler()
242     {
243     }
IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)244     virtual bool IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)
245     {
246         // Not create hwFilters for single ColorFill features. It will combined with scaling filter for sfc or involved in FC.
247         return false;
248     }
CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps,SwFilterPipe & swFilterPipe,PVP_MHWINTERFACE pHwInterface)249     virtual HwFilterParameter *CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface)
250     {
251         return nullptr;
252     }
253     virtual MOS_STATUS UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
254     virtual MOS_STATUS UpdateUnusedFeature(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
CreatePacketParam(HW_FILTER_PARAM & param)255     static VpPacketParameter* CreatePacketParam(HW_FILTER_PARAM& param)
256     {
257         return nullptr;
258     }
259 
260 MEDIA_CLASS_DEFINE_END(vp__PolicySfcColorFillHandler)
261 };
262 
263 class PolicySfcAlphaHandler : public PolicyFeatureHandler
264 {
265 public:
PolicySfcAlphaHandler(VP_HW_CAPS & hwCaps)266     PolicySfcAlphaHandler(VP_HW_CAPS &hwCaps) : PolicyFeatureHandler(hwCaps)
267     {
268         m_Type = FeatureTypeAlphaOnSfc;
269     }
~PolicySfcAlphaHandler()270     virtual ~PolicySfcAlphaHandler()
271     {
272     }
IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)273     virtual bool IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)
274     {
275         // Not create hwFilters for single ColorFill features. It will combined with scaling filter for sfc or involved in FC.
276         return false;
277     }
CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps,SwFilterPipe & swFilterPipe,PVP_MHWINTERFACE pHwInterface)278     virtual HwFilterParameter *CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface)
279     {
280         return nullptr;
281     }
282     virtual MOS_STATUS UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
283     virtual MOS_STATUS UpdateUnusedFeature(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
CreatePacketParam(HW_FILTER_PARAM & param)284     static VpPacketParameter* CreatePacketParam(HW_FILTER_PARAM& param)
285     {
286         return nullptr;
287     }
288 
289 MEDIA_CLASS_DEFINE_END(vp__PolicySfcAlphaHandler)
290 };
291 }
292 #endif // !__VP_SCALING_FILTER_H__