1 /*
2 * Copyright (c) 2020-2021, 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_cgc_filter.cpp
24 //! \brief Defines the common interface for Color Gamut Compression and Expansion
25 //! this file is for the base interface which is shared by all CGC in driver.
26 //!
27 #include "vp_cgc_filter.h"
28 #include "vp_vebox_cmd_packet.h"
29 #include "hw_filter.h"
30 #include "sw_filter_pipe.h"
31
32 namespace vp {
VpCgcFilter(PVP_MHWINTERFACE vpMhwInterface)33 VpCgcFilter::VpCgcFilter(PVP_MHWINTERFACE vpMhwInterface) :
34 VpFilter(vpMhwInterface)
35 {
36
37 }
38
Init()39 MOS_STATUS VpCgcFilter::Init()
40 {
41 VP_FUNC_CALL();
42
43 return MOS_STATUS_SUCCESS;
44 }
45
Prepare()46 MOS_STATUS VpCgcFilter::Prepare()
47 {
48 VP_FUNC_CALL();
49
50 return MOS_STATUS_SUCCESS;
51 }
52
Destroy()53 MOS_STATUS VpCgcFilter::Destroy()
54 {
55 VP_FUNC_CALL();
56
57 if (m_pVeboxCgcParams)
58 {
59 MOS_FreeMemAndSetNull(m_pVeboxCgcParams);
60 }
61
62 return MOS_STATUS_SUCCESS;
63 }
64
SetExecuteEngineCaps(FeatureParamCgc & cgcParams,VP_EXECUTE_CAPS vpExecuteCaps)65 MOS_STATUS VpCgcFilter::SetExecuteEngineCaps(
66 FeatureParamCgc &cgcParams,
67 VP_EXECUTE_CAPS vpExecuteCaps)
68 {
69 VP_FUNC_CALL();
70
71 m_cgcParams = cgcParams;
72 m_executeCaps = vpExecuteCaps;
73
74 return MOS_STATUS_SUCCESS;
75 }
76
CalculateEngineParams()77 MOS_STATUS VpCgcFilter::CalculateEngineParams()
78 {
79 VP_FUNC_CALL();
80 if (m_executeCaps.bVebox)
81 {
82 // create a filter Param buffer
83 if (!m_pVeboxCgcParams)
84 {
85 m_pVeboxCgcParams = (PVEBOX_CGC_PARAMS)MOS_AllocAndZeroMemory(sizeof(VEBOX_CGC_PARAMS));
86
87 if (m_pVeboxCgcParams == nullptr)
88 {
89 VP_PUBLIC_ASSERTMESSAGE("Vebox CGC Pamas buffer allocate failed, return nullpointer");
90 return MOS_STATUS_NO_SPACE;
91 }
92 }
93 else
94 {
95 MOS_ZeroMemory(m_pVeboxCgcParams, sizeof(VEBOX_CGC_PARAMS));
96 }
97
98 m_pVeboxCgcParams->bEnableCGC = m_cgcParams.GCompMode != GAMUT_MODE_NONE ? true : false;
99 m_pVeboxCgcParams->GCompMode = m_cgcParams.GCompMode;
100 m_pVeboxCgcParams->bBt2020ToRGB = m_cgcParams.bBt2020ToRGB;
101 m_pVeboxCgcParams->inputColorSpace = m_cgcParams.colorSpace;
102 m_pVeboxCgcParams->outputColorSpace = m_cgcParams.dstColorSpace;
103 m_pVeboxCgcParams->bExtendedSrcGamut = m_cgcParams.bExtendedSrcGamut;
104 m_pVeboxCgcParams->bExtendedDstGamut = m_cgcParams.bExtendedDstGamut;
105 m_pVeboxCgcParams->dwAttenuation = m_cgcParams.dwAttenuation;
106 m_pVeboxCgcParams->displayRGBW_x[0] = m_cgcParams.displayRGBW_x[0];
107 m_pVeboxCgcParams->displayRGBW_x[1] = m_cgcParams.displayRGBW_x[1];
108 m_pVeboxCgcParams->displayRGBW_x[2] = m_cgcParams.displayRGBW_x[2];
109 m_pVeboxCgcParams->displayRGBW_x[3] = m_cgcParams.displayRGBW_x[3];
110 m_pVeboxCgcParams->displayRGBW_y[0] = m_cgcParams.displayRGBW_y[0];
111 m_pVeboxCgcParams->displayRGBW_y[1] = m_cgcParams.displayRGBW_y[1];
112 m_pVeboxCgcParams->displayRGBW_y[2] = m_cgcParams.displayRGBW_y[2];
113 m_pVeboxCgcParams->displayRGBW_y[3] = m_cgcParams.displayRGBW_y[3];
114 }
115 else
116 {
117 VP_PUBLIC_ASSERTMESSAGE("Wrong engine caps! Vebox should be used for CGC");
118 return MOS_STATUS_INVALID_PARAMETER;
119 }
120
121 return MOS_STATUS_SUCCESS;
122 }
123
124
125 /****************************************************************************************************/
126 /* HwFilter Tcc Parameter */
127 /****************************************************************************************************/
Create(HW_FILTER_CGC_PARAM & param,FeatureType featureType)128 HwFilterParameter *HwFilterCgcParameter::Create(HW_FILTER_CGC_PARAM ¶m, FeatureType featureType)
129 {
130 VP_FUNC_CALL();
131
132 HwFilterCgcParameter *p = MOS_New(HwFilterCgcParameter, featureType);
133 if (p)
134 {
135 if (MOS_FAILED(p->Initialize(param)))
136 {
137 MOS_Delete(p);
138 return nullptr;
139 }
140 }
141 return p;
142 }
143
HwFilterCgcParameter(FeatureType featureType)144 HwFilterCgcParameter::HwFilterCgcParameter(FeatureType featureType) : HwFilterParameter(featureType)
145 {
146 }
147
~HwFilterCgcParameter()148 HwFilterCgcParameter::~HwFilterCgcParameter()
149 {
150 }
151
ConfigParams(HwFilter & hwFilter)152 MOS_STATUS HwFilterCgcParameter::ConfigParams(HwFilter &hwFilter)
153 {
154 VP_FUNC_CALL();
155
156 return hwFilter.ConfigParam(m_Params);
157 }
158
Initialize(HW_FILTER_CGC_PARAM & param)159 MOS_STATUS HwFilterCgcParameter::Initialize(HW_FILTER_CGC_PARAM ¶m)
160 {
161 VP_FUNC_CALL();
162
163 m_Params = param;
164 return MOS_STATUS_SUCCESS;
165 }
166
167 /****************************************************************************************************/
168 /* Packet Vebox Tcc Parameter */
169 /****************************************************************************************************/
Create(HW_FILTER_CGC_PARAM & param)170 VpPacketParameter *VpVeboxCgcParameter::Create(HW_FILTER_CGC_PARAM ¶m)
171 {
172 VP_FUNC_CALL();
173
174 if (nullptr == param.pPacketParamFactory)
175 {
176 return nullptr;
177 }
178 VpVeboxCgcParameter *p = dynamic_cast<VpVeboxCgcParameter *>(param.pPacketParamFactory->GetPacketParameter(param.pHwInterface));
179 if (p)
180 {
181 if (MOS_FAILED(p->Initialize(param)))
182 {
183 VpPacketParameter *pParam = p;
184 param.pPacketParamFactory->ReturnPacketParameter(pParam);
185 return nullptr;
186 }
187 }
188 return p;
189 }
190
VpVeboxCgcParameter(PVP_MHWINTERFACE pHwInterface,PacketParamFactoryBase * packetParamFactory)191 VpVeboxCgcParameter::VpVeboxCgcParameter(PVP_MHWINTERFACE pHwInterface, PacketParamFactoryBase *packetParamFactory) :
192 VpPacketParameter(packetParamFactory), m_cgcFilter(pHwInterface)
193 {
194 }
~VpVeboxCgcParameter()195 VpVeboxCgcParameter::~VpVeboxCgcParameter() {}
196
SetPacketParam(VpCmdPacket * _packet)197 bool VpVeboxCgcParameter::SetPacketParam(VpCmdPacket *_packet)
198 {
199 VP_FUNC_CALL();
200
201 VEBOX_CGC_PARAMS *params = m_cgcFilter.GetVeboxParams();
202 if (nullptr == params)
203 {
204 VP_PUBLIC_ASSERTMESSAGE("Failed to get Vebox cgc params");
205 return false;
206 }
207
208 VpVeboxCmdPacketBase *packet = dynamic_cast<VpVeboxCmdPacketBase *>(_packet);
209 if (packet)
210 {
211 return MOS_SUCCEEDED(packet->SetCgcParams(params));
212 }
213
214 VP_PUBLIC_ASSERTMESSAGE("Invalid packet for Vebox cgc");
215 return false;
216 }
217
Initialize(HW_FILTER_CGC_PARAM & params)218 MOS_STATUS VpVeboxCgcParameter::Initialize(HW_FILTER_CGC_PARAM ¶ms)
219 {
220 VP_FUNC_CALL();
221
222 VP_PUBLIC_CHK_STATUS_RETURN(m_cgcFilter.Init());
223 VP_PUBLIC_CHK_STATUS_RETURN(m_cgcFilter.SetExecuteEngineCaps(params.cgcParams, params.vpExecuteCaps));
224 VP_PUBLIC_CHK_STATUS_RETURN(m_cgcFilter.CalculateEngineParams());
225 return MOS_STATUS_SUCCESS;
226 }
227
228 /****************************************************************************************************/
229 /* Policy Vebox Tcc Handler */
230 /****************************************************************************************************/
PolicyVeboxCgcHandler(VP_HW_CAPS & hwCaps)231 PolicyVeboxCgcHandler::PolicyVeboxCgcHandler(VP_HW_CAPS &hwCaps) : PolicyFeatureHandler(hwCaps)
232 {
233 m_Type = FeatureTypeCgcOnVebox;
234 }
~PolicyVeboxCgcHandler()235 PolicyVeboxCgcHandler::~PolicyVeboxCgcHandler()
236 {
237 }
238
IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)239 bool PolicyVeboxCgcHandler::IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)
240 {
241 VP_FUNC_CALL();
242
243 return vpExecuteCaps.bCGC;
244 }
245
CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps,SwFilterPipe & swFilterPipe,PVP_MHWINTERFACE pHwInterface)246 HwFilterParameter* PolicyVeboxCgcHandler::CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe& swFilterPipe, PVP_MHWINTERFACE pHwInterface)
247 {
248 VP_FUNC_CALL();
249
250 if (IsFeatureEnabled(vpExecuteCaps))
251 {
252 if (SwFilterPipeType1To1 != swFilterPipe.GetSwFilterPipeType())
253 {
254 VP_PUBLIC_ASSERTMESSAGE("Invalid parameter! Sfc only support 1To1 swFilterPipe!");
255 return nullptr;
256 }
257
258 SwFilterCgc *swFilter = dynamic_cast<SwFilterCgc *>(swFilterPipe.GetSwFilter(true, 0, FeatureTypeCgcOnVebox));
259
260 if (nullptr == swFilter)
261 {
262 VP_PUBLIC_ASSERTMESSAGE("Invalid parameter! Feature enabled in vpExecuteCaps but no swFilter exists!");
263 return nullptr;
264 }
265
266 FeatureParamCgc ¶m = swFilter->GetSwFilterParams();
267
268 HW_FILTER_CGC_PARAM paramCgc = {};
269 paramCgc.type = m_Type;
270 paramCgc.pHwInterface = pHwInterface;
271 paramCgc.vpExecuteCaps = vpExecuteCaps;
272 paramCgc.pPacketParamFactory = &m_PacketParamFactory;
273 paramCgc.cgcParams = param;
274 paramCgc.pfnCreatePacketParam = PolicyVeboxCgcHandler::CreatePacketParam;
275
276 HwFilterParameter *pHwFilterParam = GetHwFeatureParameterFromPool();
277
278 if (pHwFilterParam)
279 {
280 if (MOS_FAILED(((HwFilterCgcParameter*)pHwFilterParam)->Initialize(paramCgc)))
281 {
282 ReleaseHwFeatureParameter(pHwFilterParam);
283 }
284 }
285 else
286 {
287 pHwFilterParam = HwFilterCgcParameter::Create(paramCgc, m_Type);
288 }
289
290 return pHwFilterParam;
291 }
292 else
293 {
294 return nullptr;
295 }
296 }
297 }
298