xref: /aosp_15_r20/external/intel-media-driver/media_softlet/linux/common/vp/ddi/ddi_vp_functions.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2021-2023, 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     ddi_vp_functions.cpp
24 //! \brief    ddi vp functions implementaion.
25 //!
26 #include "ddi_vp_functions.h"
27 #include "media_libva_util_next.h"
28 #include "media_libva_common_next.h"
29 #include "media_libva_caps_next.h"
30 #include "ddi_vp_tools.h"
31 #include "mos_solo_generic.h"
32 #include "media_libva_interface_next.h"
33 #include "ddi_cp_interface_next.h"
34 #include "vp_utils.h"
35 #if !defined(ANDROID) && defined(X11_FOUND)
36 #include <X11/Xutil.h>
37 #include "media_libva_putsurface_linux.h"
38 #endif
39 
40 #define VP_SETTING_MAX_PHASES               1
41 #define VP_SETTING_MEDIA_STATES             32
42 #define VP_SETTING_SAME_SAMPLE_THRESHOLD    1000
43 
44 #define VP_MAX_PIC_WIDTH                    16384
45 #define VP_MAX_PIC_HEIGHT                   16384
46 #define VP_MIN_PIC_WIDTH                    16
47 #define VP_MIN_PIC_HEIGHT                   16
48 #define QUERY_CAPS_ATTRIBUTE                1                     /* query the actual filter caps attribute in vp module */
49 
50 // ITU-T H.265 Table E.3: Colour Primaries
51 #define COLOUR_PRIMARY_BT2020                  9
52 #define COLOUR_PRIMARY_BT709                   1
53 #define COLOUR_PRIMARY_BT601                   5
54 // ITU-T H.265 Table E.4 Transfer characteristics
55 #define TRANSFER_CHARACTERISTICS_BT709         1
56 #define TRANSFER_CHARACTERISTICS_GMAMA2P2      4
57 #define TRANSFER_CHARACTERISTICS_LINEAR        8
58 #define TRANSFER_CHARACTERISTICS_BT2020        14
59 #define TRANSFER_CHARACTERISTICS_ST2084        16
60 
61 const VAProcFilterCapColorBalance DdiVpFunctions::m_vpColorBalCap[] = {
62     /** \brief Hue. */
63     {VAProcColorBalanceHue,
64         { PROCAMP_HUE_MIN,
65           PROCAMP_HUE_MAX,
66           PROCAMP_HUE_DEFAULT,
67           PROCAMP_HUE_STEP }
68     },
69     /** \brief Saturation. */
70     {VAProcColorBalanceSaturation,
71         { PROCAMP_SATURATION_MIN,
72           PROCAMP_SATURATION_MAX,
73           PROCAMP_SATURATION_DEFAULT,
74           PROCAMP_SATURATION_STEP }
75     },
76     /** \brief Brightness. */
77     {VAProcColorBalanceBrightness,
78         { PROCAMP_BRIGHTNESS_MIN,
79           PROCAMP_BRIGHTNESS_MAX,
80           PROCAMP_BRIGHTNESS_DEFAULT,
81           PROCAMP_BRIGHTNESS_STEP }
82     },
83     /** \brief Contrast. */
84     {VAProcColorBalanceContrast,
85         { PROCAMP_CONTRAST_MIN,
86           PROCAMP_CONTRAST_MAX,
87           PROCAMP_CONTRAST_DEFAULT,
88           PROCAMP_CONTRAST_STEP }
89     },
90     /** \brief Automatically adjusted contrast. */
91     {VAProcColorBalanceAutoContrast,
92         { 0.0F, 0.0F, 0.0F, 0.0F }
93     }
94 };
95 
96 const VAProcFilterType DdiVpFunctions::m_vpSupportedFilters[DDI_VP_MAX_NUM_FILTERS] = {
97     VAProcFilterNoiseReduction,
98     VAProcFilterDeinterlacing,
99     VAProcFilterSharpening,
100     VAProcFilterColorBalance,
101     VAProcFilterSkinToneEnhancement,
102     VAProcFilterTotalColorCorrection,
103     VAProcFilterHVSNoiseReduction,
104     VAProcFilterHighDynamicRangeToneMapping,
105 #if VA_CHECK_VERSION(1, 12, 0)
106     VAProcFilter3DLUT
107 #endif
108 };
109 
CreateContext(VADriverContextP ctx,VAConfigID configId,int32_t pictureWidth,int32_t pictureHeight,int32_t flag,VASurfaceID * renderTargets,int32_t renderTargetsNum,VAContextID * ctxID)110 VAStatus DdiVpFunctions::CreateContext (
111     VADriverContextP  ctx,
112     VAConfigID        configId,
113     int32_t           pictureWidth,
114     int32_t           pictureHeight,
115     int32_t           flag,
116     VASurfaceID       *renderTargets,
117     int32_t           renderTargetsNum,
118     VAContextID       *ctxID)
119 {
120     PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
121 
122     VAStatus                          status        = VA_STATUS_SUCCESS;
123     PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT vaCtxHeapElmt = nullptr;
124     PDDI_MEDIA_CONTEXT                mediaCtx      = nullptr;
125     PDDI_VP_CONTEXT                   vpCtx         = nullptr;
126     DDI_VP_FUNC_ENTER;
127 
128     DDI_UNUSED(configId);
129     DDI_UNUSED(pictureWidth);
130     DDI_UNUSED(pictureHeight);
131     DDI_UNUSED(flag);
132     DDI_UNUSED(renderTargets);
133     DDI_UNUSED(renderTargetsNum);
134 
135     DDI_VP_CHK_NULL(ctx, "nullptr ctx.", VA_STATUS_ERROR_INVALID_CONTEXT);
136 
137     *ctxID = VA_INVALID_ID;
138 
139     mediaCtx = GetMediaContext(ctx);
140     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
141 
142     // allocate vpCtx
143     vpCtx = MOS_New(DDI_VP_CONTEXT);
144     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_ALLOCATION_FAILED);
145 
146     // init vpCtx
147     status = DdiInitCtx(ctx, vpCtx);
148     DDI_CHK_RET(status, "VA_STATUS_ERROR_OPERATION_FAILED");
149 
150     MosUtilities::MosLockMutex(&mediaCtx->VpMutex);
151 
152     // get Free VP context index
153     vaCtxHeapElmt = MediaLibvaUtilNext::DdiAllocPVAContextFromHeap(mediaCtx->pVpCtxHeap);
154     if (nullptr == vaCtxHeapElmt)
155     {
156         MOS_Delete(vpCtx);
157         MosUtilities::MosUnlockMutex(&mediaCtx->VpMutex);
158         DDI_VP_ASSERTMESSAGE("VP Context number exceeds maximum.");
159         return VA_STATUS_ERROR_INVALID_CONTEXT;
160     }
161 
162     // store vpCtx in pMedia
163     vaCtxHeapElmt->pVaContext = (void *)vpCtx;
164     *ctxID = (VAContextID)(vaCtxHeapElmt->uiVaContextID + DDI_MEDIA_SOFTLET_VACONTEXTID_VP_OFFSET);
165 
166     // increate VP context number
167     mediaCtx->uiNumVPs++;
168 
169     MosUtilities::MosUnlockMutex(&mediaCtx->VpMutex);
170 
171     return VA_STATUS_SUCCESS;
172 }
173 
DestroyContext(VADriverContextP ctx,VAContextID ctxID)174 VAStatus DdiVpFunctions::DestroyContext (
175     VADriverContextP  ctx,
176     VAContextID       ctxID)
177 {
178     PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
179     VAStatus                 vaStatus  = VA_STATUS_SUCCESS;
180     PDDI_MEDIA_CONTEXT       mediaCtx  = nullptr;
181     PDDI_VP_CONTEXT          vpCtx     = nullptr;
182     uint32_t                 vpIndex   = 0;
183     uint32_t                 ctxType   = DDI_MEDIA_CONTEXT_TYPE_NONE;
184 
185     DDI_VP_FUNC_ENTER;
186     DDI_VP_CHK_NULL(ctx, "nullptr ctx.", VA_STATUS_ERROR_INVALID_CONTEXT);
187 
188     // initialize
189     mediaCtx = GetMediaContext(ctx);
190     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
191     vpCtx    = (PDDI_VP_CONTEXT)MediaLibvaCommonNext::GetContextFromContextID(ctx, ctxID, &ctxType);
192     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
193 
194     MOS_FreeMemory(vpCtx->MosDrvCtx.pPerfData);
195     vpCtx->MosDrvCtx.pPerfData = nullptr;
196 
197     if (vpCtx->pCpDdiInterfaceNext)
198     {
199         MOS_Delete(vpCtx->pCpDdiInterfaceNext);
200     }
201 
202     // destroy vphal
203     vaStatus  = DdiDestroyVpHal(vpCtx);
204 
205     // Get VP context index
206     vpIndex = ctxID & DDI_MEDIA_MASK_VACONTEXTID;
207 
208     // remove from context array
209     MosUtilities::MosLockMutex(&mediaCtx->VpMutex);
210     // destroy vp context
211     MOS_Delete(vpCtx);
212     MediaLibvaUtilNext::DdiReleasePVAContextFromHeap(mediaCtx->pVpCtxHeap, vpIndex);
213 
214     mediaCtx->uiNumVPs--;
215     MosUtilities::MosUnlockMutex(&mediaCtx->VpMutex);
216 
217     return vaStatus;
218 }
219 
CreateBuffer(VADriverContextP ctx,VAContextID context,VABufferType type,uint32_t size,uint32_t elementsNum,void * data,VABufferID * bufId)220 VAStatus DdiVpFunctions::CreateBuffer (
221     VADriverContextP  ctx,
222     VAContextID       context,
223     VABufferType      type,
224     uint32_t          size,
225     uint32_t          elementsNum,
226     void              *data,
227     VABufferID        *bufId)
228 {
229     VAStatus                       vaStatus          = VA_STATUS_SUCCESS;
230     PDDI_MEDIA_CONTEXT             mediaCtx          = nullptr;
231     PDDI_MEDIA_BUFFER              buf               = nullptr;
232     PDDI_MEDIA_BUFFER_HEAP_ELEMENT bufferHeapElement = nullptr;
233     MOS_STATUS                     eStatus           = MOS_STATUS_SUCCESS;
234     PDDI_VP_CONTEXT                vpContext         = nullptr;
235     uint32_t                       ctxType           = DDI_MEDIA_CONTEXT_TYPE_NONE;
236     void                           *ctxPtr           = nullptr;
237 
238     DDI_VP_FUNC_ENTER;
239     DDI_VP_CHK_NULL(ctx,  "nullptr ctx.", VA_STATUS_ERROR_INVALID_CONTEXT);
240     *bufId = VA_INVALID_ID;
241 
242     mediaCtx = GetMediaContext(ctx);
243     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
244 
245     ctxPtr  = MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
246     DDI_VP_CHK_NULL(ctxPtr, "nullptr ctxPtr", VA_STATUS_ERROR_INVALID_CONTEXT);
247 
248     vpContext = (PDDI_VP_CONTEXT)ctxPtr;
249 
250     // only for VAProcFilterParameterBufferType and VAProcPipelineParameterBufferType
251     if (type != VAProcFilterParameterBufferType && type != VAProcPipelineParameterBufferType
252 #if VA_CHECK_VERSION(1, 10, 0)
253         && type != VAContextParameterUpdateBufferType
254 #endif
255     )
256     {
257         DDI_VP_ASSERTMESSAGE("Unsupported Va Buffer Type.");
258         return VA_STATUS_ERROR_INVALID_PARAMETER;
259     }
260 
261     // allocate new buf and init
262     buf = MOS_New(DDI_MEDIA_BUFFER);
263     DDI_VP_CHK_NULL(buf, "nullptr buf.", VA_STATUS_ERROR_ALLOCATION_FAILED);
264     buf->pMediaCtx      = mediaCtx;
265     buf->iSize          = size * elementsNum;
266     buf->uiNumElements  = elementsNum;
267     buf->uiType         = type;
268     buf->format         = Media_Format_Buffer;
269     buf->uiOffset       = 0;
270     buf->pData          = MOS_NewArray(uint8_t, size * elementsNum);
271     if (nullptr == buf->pData)
272     {
273         MOS_Delete(buf);
274         return VA_STATUS_ERROR_ALLOCATION_FAILED;
275     }
276     buf->format = Media_Format_CPU;
277 
278     bufferHeapElement = MediaLibvaUtilNext::AllocPMediaBufferFromHeap(mediaCtx->pBufferHeap);
279     if (nullptr == bufferHeapElement)
280     {
281         MOS_DeleteArray(buf->pData);
282         MOS_Delete(buf);
283         DDI_VP_ASSERTMESSAGE("Invalid buffer index.");
284         return VA_STATUS_ERROR_INVALID_BUFFER;
285     }
286     bufferHeapElement->pBuffer   = buf;
287     bufferHeapElement->pCtx      = (void *)vpContext;
288     bufferHeapElement->uiCtxType = DDI_MEDIA_CONTEXT_TYPE_VP;
289     *bufId                       = bufferHeapElement->uiVaBufferID;
290     mediaCtx->uiNumBufs++;
291 
292     // if there is data from client, then dont need to copy data from client
293     if (data)
294     {
295         // copy client data to new buf
296         eStatus = MOS_SecureMemcpy(buf->pData, size * elementsNum, data, size * elementsNum);
297         DDI_VP_CHK_CONDITION((eStatus != MOS_STATUS_SUCCESS), "DDI: Failed to copy client data!", VA_STATUS_ERROR_MAX_NUM_EXCEEDED);
298     }
299     else
300     {
301         // do nothing if there is no data from client
302         vaStatus = VA_STATUS_SUCCESS;
303     }
304 
305     return vaStatus;
306 }
307 
MapBufferInternal(PDDI_MEDIA_CONTEXT mediaCtx,VABufferID bufId,void ** buf,uint32_t flag)308 VAStatus DdiVpFunctions::MapBufferInternal(
309     PDDI_MEDIA_CONTEXT  mediaCtx,
310     VABufferID          bufId,
311     void                **buf,
312     uint32_t            flag)
313 {
314     DDI_VP_FUNC_ENTER;
315 
316     return DdiMediaFunctions::MapBufferInternal(mediaCtx, bufId, buf, flag);
317 }
318 
UnmapBuffer(PDDI_MEDIA_CONTEXT mediaCtx,VABufferID bufId)319 VAStatus DdiVpFunctions::UnmapBuffer (
320     PDDI_MEDIA_CONTEXT mediaCtx,
321     VABufferID         bufId)
322 {
323     DDI_VP_FUNC_ENTER;
324 
325     return DdiMediaFunctions::UnmapBuffer(mediaCtx, bufId);
326 }
327 
DestroyBuffer(DDI_MEDIA_CONTEXT * mediaCtx,VABufferID bufId)328 VAStatus DdiVpFunctions::DestroyBuffer(
329     DDI_MEDIA_CONTEXT  *mediaCtx,
330     VABufferID         bufId)
331 {
332     VAStatus         vaStatus  = VA_STATUS_SUCCESS;
333     DDI_MEDIA_BUFFER *mediaBuf = nullptr;
334     DDI_VP_FUNC_ENTER;
335 
336     mediaBuf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, bufId);
337     DDI_VP_CHK_NULL(mediaBuf, "nullptr mediaBuf", VA_STATUS_ERROR_INVALID_BUFFER);
338 
339     switch ((int32_t)mediaBuf->uiType)
340     {
341         case VAProcPipelineParameterBufferType:
342         case VAProcFilterParameterBufferType:
343 #if VA_CHECK_VERSION(1, 10, 0)
344         case VAContextParameterUpdateBufferType:
345 #endif
346             MOS_DeleteArray(mediaBuf->pData);
347             break;
348         default:
349             DDI_VP_ASSERTMESSAGE("Unsupported Va Buffer Type.");
350     }
351     MOS_Delete(mediaBuf);
352 
353     MediaLibvaInterfaceNext::DestroyBufFromVABufferID(mediaCtx, bufId);
354     return vaStatus;
355 }
356 
BeginPicture(VADriverContextP ctx,VAContextID context,VASurfaceID renderTarget)357 VAStatus DdiVpFunctions::BeginPicture (
358     VADriverContextP  ctx,
359     VAContextID       context,
360     VASurfaceID       renderTarget)
361 {
362     PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
363 
364     VAStatus             vaStatus          = VA_STATUS_SUCCESS;
365     PDDI_MEDIA_CONTEXT   mediaDrvCtx       = nullptr;
366     PDDI_VP_CONTEXT      vpCtx             = nullptr;
367     uint32_t             ctxType           = DDI_MEDIA_CONTEXT_TYPE_NONE;
368     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
369     PVPHAL_SURFACE       vpHalTgtSurf      = nullptr;
370     PDDI_MEDIA_SURFACE   mediaTgtSurf      = nullptr;
371 
372     DDI_VP_FUNC_ENTER;
373     DDI_VP_CHK_NULL(ctx, "nullptr ctx.", VA_STATUS_ERROR_INVALID_CONTEXT);
374 
375     // initialize
376     mediaDrvCtx = GetMediaContext(ctx);
377     DDI_VP_CHK_NULL(mediaDrvCtx, "nullptr mediaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
378 
379     vpCtx = (PDDI_VP_CONTEXT)MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
380     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
381 
382     vpCtx->TargetSurfID = renderTarget;
383     vpHalRenderParams   = VpGetRenderParams(vpCtx);
384     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
385 
386     // uDstCount == 0 means no render target is set yet.
387     // uDstCount == 1 means 1 render target has been set already.
388     // uDstCount == 2 means 2 render targets have been set already.
389     DDI_VP_CHK_LESS(vpHalRenderParams->uDstCount, VPHAL_MAX_TARGETS, "Too many render targets for VP.", VA_STATUS_ERROR_INVALID_PARAMETER);
390 
391     vpHalTgtSurf = vpHalRenderParams->pTarget[vpHalRenderParams->uDstCount];
392     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
393 
394     mediaTgtSurf = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaDrvCtx, renderTarget);
395     DDI_VP_CHK_NULL(mediaTgtSurf, "nullptr mediaTgtSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
396     mediaTgtSurf->pVpCtx = vpCtx;
397 
398     // Setup Target VpHal Surface
399     vpHalTgtSurf->SurfType       = SURF_OUT_RENDERTARGET;
400     vpHalTgtSurf->rcSrc.top      = 0;
401     vpHalTgtSurf->rcSrc.left     = 0;
402     vpHalTgtSurf->rcSrc.right    = mediaTgtSurf->iWidth;
403     vpHalTgtSurf->rcSrc.bottom   = mediaTgtSurf->iRealHeight;
404     vpHalTgtSurf->rcDst.top      = 0;
405     vpHalTgtSurf->rcDst.left     = 0;
406     vpHalTgtSurf->rcDst.right    = mediaTgtSurf->iWidth;
407     vpHalTgtSurf->rcDst.bottom   = mediaTgtSurf->iRealHeight;
408     vpHalTgtSurf->ExtendedGamut  = false;
409 
410     // Set os resource for VPHal render
411     vaStatus = VpSetOsResource(vpCtx, mediaTgtSurf, vpHalRenderParams->uDstCount);
412     DDI_CHK_RET(vaStatus, "Call VpSetOsResource failed");
413 
414     vpHalTgtSurf->Format   = vpHalTgtSurf->OsResource.Format;
415     vpHalTgtSurf->TileType = vpHalTgtSurf->OsResource.TileType;
416 
417     VpSetRenderParams(mediaTgtSurf, vpHalRenderParams, renderTarget);
418 
419     return VA_STATUS_SUCCESS;
420 }
421 
RenderPicture(VADriverContextP ctx,VAContextID context,VABufferID * buffers,int32_t buffersNum)422 VAStatus DdiVpFunctions::RenderPicture (
423     VADriverContextP  ctx,
424     VAContextID       context,
425     VABufferID        *buffers,
426     int32_t           buffersNum)
427 {
428     PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
429 
430     VAStatus           vaStatus               = VA_STATUS_SUCCESS;
431     PDDI_MEDIA_CONTEXT mediaCtx               = nullptr;
432     PDDI_VP_CONTEXT    vpCtx                  = nullptr;
433     PDDI_MEDIA_BUFFER  buf                    = nullptr;
434     void               *data                  = nullptr;
435     uint32_t           ctxType                = DDI_MEDIA_CONTEXT_TYPE_NONE;
436     int32_t            numOfBuffers           = buffersNum;
437     int32_t            priority               = 0;
438     int32_t            priorityIndexInBuffers = -1;
439     bool               updatePriority         = false;
440 
441     DDI_VP_FUNC_ENTER;
442     DDI_VP_CHK_NULL(ctx, "nullptr ctx.", VA_STATUS_ERROR_INVALID_CONTEXT);
443 
444     mediaCtx = GetMediaContext(ctx);
445     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_OPERATION_FAILED);
446 
447     vpCtx = (PDDI_VP_CONTEXT)MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
448     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
449 
450     //buffersNum check
451     DDI_VP_CHK_CONDITION(((numOfBuffers > VPHAL_MAX_SOURCES) || (numOfBuffers <= 0)),
452         "numOfBuffers is Invalid.",
453         VA_STATUS_ERROR_INVALID_PARAMETER);
454 
455     priorityIndexInBuffers = MediaLibvaCommonNext::GetGpuPriority(ctx, buffers, numOfBuffers, &updatePriority, &priority);
456     if (priorityIndexInBuffers != -1)
457     {
458         if (updatePriority)
459         {
460             if ((vaStatus = DdiSetGpuPriority(vpCtx, priority)) != VA_STATUS_SUCCESS)
461             {
462                 return vaStatus;
463             }
464         }
465         MediaLibvaCommonNext::MovePriorityBufferIdToEnd(buffers, priorityIndexInBuffers, numOfBuffers);
466         numOfBuffers--;
467     }
468     if (numOfBuffers == 0)
469     {
470         return vaStatus;
471     }
472 
473     for (int32_t i = 0; i < numOfBuffers; i++)
474     {
475         buf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, buffers[i]);
476         DDI_VP_CHK_NULL(buf, "nullptr buf.", VA_STATUS_ERROR_INVALID_BUFFER);
477 
478         MediaLibvaInterfaceNext::MapBuffer(ctx, buffers[i], &data);
479         DDI_VP_CHK_NULL(data, "nullptr data.", VA_STATUS_ERROR_INVALID_BUFFER);
480 
481         switch ((int32_t)buf->uiType)
482         {
483         // VP Buffer Types
484         case VAProcPipelineParameterBufferType:
485             if (VpIsRenderTarget(ctx, vpCtx, (VAProcPipelineParameterBuffer *)data))
486             {
487                 vaStatus = VpSetRenderTargetParams(ctx, vpCtx, (VAProcPipelineParameterBuffer *)data);
488             }
489             else
490             {
491                 vaStatus = DdiSetProcPipelineParams(ctx, vpCtx, (VAProcPipelineParameterBuffer *)data);
492                 DDI_CHK_RET(vaStatus, "Unable to set pipeline parameters");
493             }
494             break;
495         case VAProcFilterParameterBufferType:
496             // User is not supposed to pass this buffer type:Refer va_vpp.h
497             DDI_VP_ASSERTMESSAGE("Invalid buffer type.");
498             vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
499             break;
500 
501         default:
502             DDI_CHK_RET(vaStatus, "Unsupported buffer type!");
503             break;
504         }
505         MediaLibvaInterfaceNext::UnmapBuffer(ctx, buffers[i]);
506     }
507     return vaStatus;
508 }
509 
EndPicture(VADriverContextP ctx,VAContextID context)510 VAStatus DdiVpFunctions::EndPicture (
511     VADriverContextP  ctx,
512     VAContextID       context)
513 {
514     PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
515 
516     MOS_STATUS      eStatus = MOS_STATUS_SUCCESS;
517     PDDI_VP_CONTEXT vpCtx   = nullptr;
518     uint32_t        ctxType = DDI_MEDIA_CONTEXT_TYPE_NONE;
519     VpBase          *vpHal  = nullptr;
520 
521     DDI_VP_FUNC_ENTER;
522     DDI_VP_CHK_NULL(ctx, "nullptr ctx.", VA_STATUS_ERROR_INVALID_CONTEXT);
523 
524     //get VP Context
525     vpCtx = (PDDI_VP_CONTEXT)MediaLibvaCommonNext::GetContextFromContextID(ctx, context, &ctxType);
526     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
527 
528     //Add component tag for VP
529     DDI_VP_CHK_NULL(vpCtx->pVpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
530     vpCtx->pVpHalRenderParams->Component = COMPONENT_VPCommon;
531 
532     vpHal = vpCtx->pVpHal;
533     DDI_VP_CHK_NULL(vpHal, "nullptr vpHal.", VA_STATUS_ERROR_INVALID_PARAMETER);
534     eStatus = vpHal->Render(vpCtx->pVpHalRenderParams);
535 
536 #if (_DEBUG || _RELEASE_INTERNAL)
537     DdiVpTools::VpDumpProcPipelineParams(ctx, vpCtx);
538 #endif  //(_DEBUG || _RELEASE_INTERNAL)
539 
540     VpReportFeatureMode(vpCtx);
541 
542     // Reset primary surface count for next render call
543     vpCtx->iPriSurfs = 0;
544     // Reset render target count for next render call
545     vpCtx->pVpHalRenderParams->uDstCount = 0;
546 
547     if (MOS_FAILED(eStatus))
548     {
549         DDI_VP_ASSERTMESSAGE("Failed to call render function.");
550         return VA_STATUS_ERROR_OPERATION_FAILED;
551     }
552 
553     return VA_STATUS_SUCCESS;
554 }
555 
CreateConfig(VADriverContextP ctx,VAProfile profile,VAEntrypoint entrypoint,VAConfigAttrib * attribList,int32_t attribsNum,VAConfigID * configId)556 VAStatus DdiVpFunctions::CreateConfig (
557     VADriverContextP  ctx,
558     VAProfile         profile,
559     VAEntrypoint      entrypoint,
560     VAConfigAttrib    *attribList,
561     int32_t           attribsNum,
562     VAConfigID        *configId)
563 {
564     VAStatus status = VA_STATUS_SUCCESS;
565 
566     DDI_VP_FUNC_ENTER;
567     // attribList and numAttribs are for future usage.
568     DDI_UNUSED(attribList);
569     DDI_UNUSED(attribsNum);
570     DDI_VP_CHK_NULL(ctx, "nullptr ctx", VA_STATUS_ERROR_INVALID_CONTEXT);
571     DDI_VP_CHK_NULL(configId, "nullptr configId", VA_STATUS_ERROR_INVALID_PARAMETER);
572 
573     PDDI_MEDIA_CONTEXT mediaCtx = GetMediaContext(ctx);
574     DDI_VP_CHK_NULL(mediaCtx,             "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
575     DDI_VP_CHK_NULL(mediaCtx->m_capsNext, "nullptr m_caps",   VA_STATUS_ERROR_INVALID_PARAMETER);
576     DDI_VP_CHK_NULL(mediaCtx->m_capsNext->m_capsTable, "nullptr m_capsTable",   VA_STATUS_ERROR_INVALID_PARAMETER);
577 
578     status = mediaCtx->m_capsNext->CreateConfig(profile, entrypoint, attribList, attribsNum, configId);
579     DDI_CHK_RET(status, "Create common config failed");
580 
581     auto configList = mediaCtx->m_capsNext->GetConfigList();
582     DDI_VP_CHK_NULL(configList, "Get configList failed", VA_STATUS_ERROR_INVALID_PARAMETER);
583 
584     for(int i = 0; i < configList->size(); i++)
585     {
586         if((configList->at(i).profile == profile) && (configList->at(i).entrypoint == entrypoint))
587         {
588             uint32_t curConfigID = ADD_CONFIG_ID_VP_OFFSET(i);
589             if(!mediaCtx->m_capsNext->m_capsTable->IsVpConfigId(curConfigID))
590             {
591                  DDI_VP_ASSERTMESSAGE("DDI: Invalid configID.");
592                  return VA_STATUS_ERROR_INVALID_CONFIG;
593             }
594 
595             *configId = curConfigID;
596             return VA_STATUS_SUCCESS;
597         }
598     }
599 
600     return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
601 }
602 
QueryVideoProcFilters(VADriverContextP ctx,VAContextID context,VAProcFilterType * filters,uint32_t * filtersNum)603 VAStatus DdiVpFunctions::QueryVideoProcFilters(
604     VADriverContextP  ctx,
605     VAContextID       context,
606     VAProcFilterType  *filters,
607     uint32_t          *filtersNum)
608 {
609     uint32_t maxNumFilters       = DDI_VP_MAX_NUM_FILTERS;
610     uint32_t i                   = 0;
611     uint32_t supportedFiltersNum = 0;
612     VAStatus vaStatus            = VA_STATUS_SUCCESS;
613 
614     DDI_VP_FUNC_ENTER;
615     DDI_UNUSED(ctx);
616     DDI_UNUSED(context);
617     DDI_VP_CHK_NULL(filters,    "nullptr filters",    VA_STATUS_ERROR_INVALID_PARAMETER);
618     DDI_VP_CHK_NULL(filtersNum, "nullptr filtersNum", VA_STATUS_ERROR_INVALID_PARAMETER);
619 
620     // check if array size is less than VP_MAX_NUM_FILTERS
621     if(*filtersNum < maxNumFilters)
622     {
623         DDI_VP_NORMALMESSAGE("filtersNum %d < maxNumFilters %d. Probably caused by Libva version upgrade!", *filtersNum, maxNumFilters);
624     }
625 
626     // Set the filters
627     while(supportedFiltersNum < *filtersNum && i < DDI_VP_MAX_NUM_FILTERS)
628     {
629         uint32_t filterCapsNum = 0;
630         vaStatus = QueryVideoProcFilterCaps(ctx, context, m_vpSupportedFilters[i], nullptr, &filterCapsNum);
631         if(vaStatus == VA_STATUS_SUCCESS && filterCapsNum != 0)
632         {
633             filters[supportedFiltersNum] = m_vpSupportedFilters[i];
634             supportedFiltersNum++;
635         }
636         i++;
637     }
638 
639     // Tell the app how many valid filters are filled in the array
640     *filtersNum = supportedFiltersNum;
641 
642     return VA_STATUS_SUCCESS;
643 }
644 
QueryVideoProcFilterCaps(VADriverContextP ctx,VAContextID context,VAProcFilterType type,void * filterCaps,uint32_t * filterCapsNum)645 VAStatus DdiVpFunctions::QueryVideoProcFilterCaps(
646     VADriverContextP  ctx,
647     VAContextID       context,
648     VAProcFilterType  type,
649     void              *filterCaps,
650     uint32_t          *filterCapsNum)
651 {
652     uint32_t                            queryCapsNum   = 0;   /* the filter caps number queried by app layer */
653     uint32_t                            existCapsNum   = 0;   /* the actual number of filters in vp module */
654     uint32_t                            queryFlag      = 0;   /* QUERY_CAPS_ATTRIBUTE: search caps attribute */
655     PDDI_MEDIA_CONTEXT                  mediaDrvCtx    = nullptr;
656 
657     DDI_VP_FUNC_ENTER;
658     DDI_VP_CHK_NULL (ctx,           "nullptr ctx.",           VA_STATUS_ERROR_INVALID_PARAMETER);
659     DDI_VP_CHK_NULL (filterCapsNum, "nullptr filterCapsNum.", VA_STATUS_ERROR_INVALID_PARAMETER);
660 
661     mediaDrvCtx = GetMediaContext(ctx);
662     DDI_VP_CHK_NULL (mediaDrvCtx,   "nullptr mediaDrvCtx.", VA_STATUS_ERROR_INVALID_PARAMETER);
663 
664     if (*filterCapsNum != 0)
665     {
666         /* return filter caps attribute  */
667         queryFlag = QUERY_CAPS_ATTRIBUTE;
668         /* check filter_caps pointer to fill in the filter_caps */
669         DDI_VP_CHK_NULL (filterCaps, "nullptr filterCaps.", VA_STATUS_ERROR_INVALID_PARAMETER);
670     }
671 
672     queryCapsNum = *filterCapsNum;
673 
674     switch (type)
675     {
676         /* Noise reduction filter */
677         case VAProcFilterNoiseReduction:
678         {
679             existCapsNum   = 1;
680             /* set input filter caps number to the actual number of filters in vp module */
681             *filterCapsNum = existCapsNum;
682             /* set the actual filter caps attribute in vp module */
683             DDI_CHK_RET(QueryNoiseReductionCapsAttrib(queryFlag, queryCapsNum, existCapsNum, filterCaps), "Query Noise Reduction Caps Attribute Failed.")
684             break;
685         }
686         /* HVS Noise reduction filter */
687         case VAProcFilterHVSNoiseReduction:
688         {
689             existCapsNum   = 0;
690             *filterCapsNum = existCapsNum;
691             if (MEDIA_IS_SKU(&mediaDrvCtx->SkuTable, FtrHVSDenoise))
692             {
693                 existCapsNum   = 4;
694                 *filterCapsNum = existCapsNum;
695             }
696             break;
697         }
698         /* Deinterlacing filter */
699         case VAProcFilterDeinterlacing:
700         {
701             existCapsNum   = 3;
702             /* set input filter caps number to the actual number of filters in vp module */
703             *filterCapsNum = existCapsNum;
704             /* set the actual filter caps attribute in vp module */
705             DDI_CHK_RET(QueryDeinterlacingCapsAttrib(queryFlag, queryCapsNum, existCapsNum, filterCaps), "Query Deinterlacing filter Caps Attribute Failed.");
706             break;
707         }
708         /* Sharpening filter. */
709         case VAProcFilterSharpening:
710         {
711             existCapsNum   = 1;
712             /* set input filter caps number to the actual number of filters in vp module */
713             *filterCapsNum = existCapsNum;
714             /* set the actual filter caps attribute in vp module */
715             DDI_CHK_RET(QuerySharpeningCapsAttrib(queryFlag, queryCapsNum, existCapsNum, filterCaps), "Query Sharpening filter Cpas Attribute Failed.");
716             break;
717         }
718         /* Color balance parameters. */
719         case VAProcFilterColorBalance:
720         {
721             existCapsNum   = sizeof(m_vpColorBalCap)/sizeof(VAProcFilterCapColorBalance);
722             /* set input filter caps number to the actual number of filters in vp module */
723             *filterCapsNum = existCapsNum;
724             /* set the actual filter caps attribute in vp module */
725             DDI_CHK_RET(QueryColorBalanceCapsAttrib(queryFlag, queryCapsNum, existCapsNum, filterCaps), "Query Color Balance Caps Attribute Failed.");
726             break;
727         }
728         case VAProcFilterSkinToneEnhancement:
729         {
730             existCapsNum   = 1;
731             *filterCapsNum = existCapsNum;
732             DDI_CHK_RET(QuerySkinToneEnhancementCapsAttrib(queryFlag, queryCapsNum, existCapsNum, filterCaps), "Query SkinTone Enhancement Caps Attribute Failed.");
733             break;
734         }
735         case VAProcFilterTotalColorCorrection:
736         {
737             existCapsNum   = 6;
738             *filterCapsNum = existCapsNum;
739             DDI_CHK_RET(QueryTotalColorCorrectionCapsAttrib(queryFlag, queryCapsNum, existCapsNum, filterCaps), "Query Total Color Correction Caps Attribute Failed.");
740             break;
741         }
742         case VAProcFilterHighDynamicRangeToneMapping:
743         {
744             existCapsNum   = 0;
745             *filterCapsNum = existCapsNum;
746             if (MEDIA_IS_SKU(&mediaDrvCtx->SkuTable, FtrHDR))
747             {
748                 existCapsNum   = 1;
749                 *filterCapsNum = existCapsNum;
750                 DDI_CHK_RET(QueryHDRToneMappingCapsAttrib(queryFlag, queryCapsNum, existCapsNum, filterCaps), "Query High Dynamic Range ToneMapping Caps Attribute Failed.");
751             }
752             break;
753         }
754 #if VA_CHECK_VERSION(1, 12, 0)
755         case VAProcFilter3DLUT:
756         {
757             existCapsNum   = 0;
758             *filterCapsNum = existCapsNum;
759             /* 3DLUT is supported in VEBOX on Gen11+*/
760             if (!MEDIA_IS_SKU(&mediaDrvCtx->SkuTable, FtrDisableVEBoxFeatures))
761             {
762                 existCapsNum   = 3;
763                 *filterCapsNum = existCapsNum;
764                 DDI_CHK_RET(QueryLut3DCapsAttrib(queryFlag, queryCapsNum, existCapsNum, filterCaps), "Query 3Dlut Caps Attribute Failed.");
765             }
766 
767             break;
768         }
769 #endif
770 
771         case VAProcFilterCount:
772         case VAProcFilterNone:
773             return VA_STATUS_ERROR_INVALID_VALUE;
774 
775         default:
776             return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
777     }
778 
779     return VA_STATUS_SUCCESS;
780 }
781 
QueryVideoProcPipelineCaps(VADriverContextP ctx,VAContextID context,VABufferID * filters,uint32_t filtersNum,VAProcPipelineCaps * pipelineCaps)782 VAStatus DdiVpFunctions::QueryVideoProcPipelineCaps(
783     VADriverContextP    ctx,
784     VAContextID         context,
785     VABufferID          *filters,
786     uint32_t            filtersNum,
787     VAProcPipelineCaps  *pipelineCaps)
788 {
789     PDDI_MEDIA_CONTEXT mediaCtx = nullptr;
790 
791     DDI_VP_FUNC_ENTER;
792     DDI_VP_CHK_NULL(ctx,          "nullptr ctx",          VA_STATUS_ERROR_INVALID_CONTEXT);
793     DDI_VP_CHK_NULL(pipelineCaps, "nullptr pipelineCaps", VA_STATUS_ERROR_INVALID_PARAMETER);
794 
795     if (filtersNum > 0)
796     {
797         DDI_VP_CHK_NULL(filters,   "nullptr filters",     VA_STATUS_ERROR_INVALID_PARAMETER);
798     }
799     mediaCtx   = GetMediaContext(ctx);
800     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
801 
802     pipelineCaps->pipeline_flags             = VA_PROC_PIPELINE_FAST;
803     pipelineCaps->filter_flags               = 0;
804     pipelineCaps->rotation_flags             = (1 << VA_ROTATION_NONE) | (1 << VA_ROTATION_90) | (1 << VA_ROTATION_180) | (1 << VA_ROTATION_270);
805     pipelineCaps->mirror_flags               = VA_MIRROR_HORIZONTAL  | VA_MIRROR_VERTICAL;
806     pipelineCaps->blend_flags                = VA_BLEND_GLOBAL_ALPHA | VA_BLEND_PREMULTIPLIED_ALPHA | VA_BLEND_LUMA_KEY;
807     pipelineCaps->num_forward_references     = DDI_CODEC_NUM_FWD_REF;
808     pipelineCaps->num_backward_references    = DDI_CODEC_NUM_BK_REF;
809     pipelineCaps->input_color_standards      = const_cast<VAProcColorStandardType*>(m_vpInputColorStd);
810     pipelineCaps->num_input_color_standards  = DDI_VP_NUM_INPUT_COLOR_STD;
811     pipelineCaps->output_color_standards     = const_cast<VAProcColorStandardType*>(m_vpOutputColorStd);
812     pipelineCaps->num_output_color_standards = DDI_VP_NUM_OUT_COLOR_STD;
813 
814     //Capability of Gen9+ platform
815     pipelineCaps->max_input_width            = VP_MAX_PIC_WIDTH;
816     pipelineCaps->max_input_height           = VP_MAX_PIC_HEIGHT;
817     pipelineCaps->max_output_width           = VP_MAX_PIC_WIDTH;
818     pipelineCaps->max_output_height          = VP_MAX_PIC_HEIGHT;
819 
820     pipelineCaps->min_input_width            = VP_MIN_PIC_WIDTH;
821     pipelineCaps->min_input_height           = VP_MIN_PIC_HEIGHT;
822     pipelineCaps->min_output_width           = VP_MIN_PIC_WIDTH;
823     pipelineCaps->min_output_height          = VP_MIN_PIC_WIDTH;
824 
825 
826     for (int i = 0; i < filtersNum; i++) {
827         void *pData;
828         DdiMedia_MapBuffer(ctx, filters[i], &pData);
829         DDI_CHK_NULL(pData, "nullptr pData", VA_STATUS_ERROR_INVALID_PARAMETER);
830         VAProcFilterParameterBufferBase* base_param = (VAProcFilterParameterBufferBase*) pData;
831         if (base_param->type == VAProcFilterDeinterlacing)
832         {
833             VAProcFilterParameterBufferDeinterlacing *di_param = (VAProcFilterParameterBufferDeinterlacing *)base_param;
834             if (di_param->algorithm == VAProcDeinterlacingMotionAdaptive ||
835                 di_param->algorithm == VAProcDeinterlacingMotionCompensated)
836             {
837                 pipelineCaps->num_forward_references = 1;
838             }
839         }
840     }
841 
842     return VA_STATUS_SUCCESS;
843 }
844 
DdiInitCtx(VADriverContextP vaDrvCtx,PDDI_VP_CONTEXT vpCtx)845 VAStatus DdiVpFunctions::DdiInitCtx(
846     VADriverContextP vaDrvCtx,
847     PDDI_VP_CONTEXT  vpCtx)
848 {
849     PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
850     VAStatus                 vaStatus          = VA_STATUS_SUCCESS;
851     PDDI_MEDIA_CONTEXT       mediaCtx          = nullptr;
852     PVPHAL_RENDER_PARAMS     vpHalRenderParams = nullptr;
853 
854     DDI_VP_FUNC_ENTER;
855     DDI_VP_CHK_NULL(vaDrvCtx, "nullptr vaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
856     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
857 
858     mediaCtx = GetMediaContext(vaDrvCtx);
859     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
860 
861     // initialize VPHAL
862     vpCtx->MosDrvCtx.bufmgr                = mediaCtx->pDrmBufMgr;
863     vpCtx->MosDrvCtx.fd                    = mediaCtx->fd;
864     vpCtx->MosDrvCtx.iDeviceId             = mediaCtx->iDeviceId;
865     vpCtx->MosDrvCtx.m_skuTable            = mediaCtx->SkuTable;
866     vpCtx->MosDrvCtx.m_waTable             = mediaCtx->WaTable;
867     vpCtx->MosDrvCtx.m_gtSystemInfo        = *mediaCtx->pGtSystemInfo;
868     vpCtx->MosDrvCtx.m_platform            = mediaCtx->platform;
869     vpCtx->MosDrvCtx.m_auxTableMgr         = mediaCtx->m_auxTableMgr;
870     vpCtx->MosDrvCtx.pGmmClientContext     = mediaCtx->pGmmClientContext;
871     vpCtx->MosDrvCtx.ppMediaMemDecompState = &mediaCtx->pMediaMemDecompState;
872     vpCtx->MosDrvCtx.pfnMediaMemoryCopy    = mediaCtx->pfnMediaMemoryCopy;
873     vpCtx->MosDrvCtx.pfnMediaMemoryCopy2D  = mediaCtx->pfnMediaMemoryCopy2D;
874     vpCtx->MosDrvCtx.pfnMemoryDecompress   = mediaCtx->pfnMemoryDecompress;
875     vpCtx->MosDrvCtx.ppMediaCopyState      = &mediaCtx->pMediaCopyState;
876 
877     vpCtx->MosDrvCtx.m_osDeviceContext     = mediaCtx->m_osDeviceContext;
878     vpCtx->MosDrvCtx.m_apoMosEnabled       = true;
879     vpCtx->MosDrvCtx.m_userSettingPtr      = mediaCtx->m_userSettingPtr;
880 
881     vpCtx->MosDrvCtx.pPerfData = (PERF_DATA *)MOS_AllocAndZeroMemory(sizeof(PERF_DATA));
882     DDI_VP_CHK_NULL(vpCtx->MosDrvCtx.pPerfData, "nullptr vpCtx->MosDrvCtx.pPerfData", VA_STATUS_ERROR_ALLOCATION_FAILED);
883 
884     // initialize DDI level cp interface
885     vpCtx->pCpDdiInterfaceNext = CreateDdiCpNext(&vpCtx->MosDrvCtx);
886     if (nullptr == vpCtx->pCpDdiInterfaceNext)
887     {
888         FreeVpHalRenderParams(vpCtx, vpHalRenderParams);
889         return VA_STATUS_ERROR_ALLOCATION_FAILED;
890     }
891 
892     DDI_CHK_RET(DdiInitVpHal(vpCtx), "Call DdiInitVpHal failed");
893 
894     // allocate vphal render param
895     vpHalRenderParams = MOS_New(VPHAL_RENDER_PARAMS);
896     if( nullptr == vpHalRenderParams)
897     {
898         FreeVpHalRenderParams(vpCtx, vpHalRenderParams);
899         return VA_STATUS_ERROR_ALLOCATION_FAILED;
900     }
901 
902     // initialize vphal render params
903     for (int32_t surfIndex = 0; surfIndex < VPHAL_MAX_SOURCES; surfIndex++)
904     {
905         vpHalRenderParams->pSrc[surfIndex] = MOS_New(VPHAL_SURFACE);
906         if( nullptr == vpHalRenderParams->pSrc[surfIndex])
907         {
908             FreeVpHalRenderParams(vpCtx, vpHalRenderParams);
909             return VA_STATUS_ERROR_ALLOCATION_FAILED;
910         }
911     }
912 
913     for (int32_t surfIndex = 0; surfIndex < VPHAL_MAX_TARGETS; surfIndex++)
914     {
915         vpHalRenderParams->pTarget[surfIndex] = MOS_New(VPHAL_SURFACE);
916         if( nullptr == vpHalRenderParams->pTarget[surfIndex])
917         {
918             FreeVpHalRenderParams(vpCtx, vpHalRenderParams);
919             return VA_STATUS_ERROR_ALLOCATION_FAILED;
920         }
921     }
922 
923     // background Colorfill
924     vpHalRenderParams->pColorFillParams = MOS_New(VPHAL_COLORFILL_PARAMS);
925     if( nullptr == vpHalRenderParams->pColorFillParams)
926     {
927         FreeVpHalRenderParams(vpCtx, vpHalRenderParams);
928         return VA_STATUS_ERROR_ALLOCATION_FAILED;
929     }
930 
931     // reset source surface count
932     vpHalRenderParams->uSrcCount = 0;
933     vpCtx->MosDrvCtx.wRevision   = 0;
934     vpCtx->iPriSurfs             = 0;
935 
936     // Add the render param for calculating alpha value.
937     // Because can not pass the alpha calculate flag from iVP,
938     // need to hardcode here for both Android and Linux.
939     vpHalRenderParams->bCalculatingAlpha = true;
940 
941     // put the render param in vp context
942     vpCtx->pVpHalRenderParams    = vpHalRenderParams;
943 
944 #if (_DEBUG || _RELEASE_INTERNAL)
945     vaStatus = DdiVpTools::InitDumpConfig(vpCtx);
946     DDI_CHK_RET(vaStatus, "Init Dump Config failed");
947 #endif //(_DEBUG || _RELEASE_INTERNAL)
948 
949     return VA_STATUS_SUCCESS;
950 }
951 
FreeVpHalRenderParams(PDDI_VP_CONTEXT vpCtx,PVPHAL_RENDER_PARAMS vpHalRenderParams)952 void DdiVpFunctions::FreeVpHalRenderParams(
953     PDDI_VP_CONTEXT      vpCtx,
954     PVPHAL_RENDER_PARAMS vpHalRenderParams)
955 {
956     DDI_VP_FUNC_ENTER;
957     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx", );
958 
959     if(vpHalRenderParams)
960     {
961         for (int32_t surfIndex = 0; surfIndex < VPHAL_MAX_SOURCES; surfIndex++)
962         {
963             MOS_Delete(vpHalRenderParams->pSrc[surfIndex]);
964         }
965         for (int32_t surfIndex = 0; surfIndex < VPHAL_MAX_TARGETS; surfIndex++)
966         {
967             MOS_Delete(vpHalRenderParams->pTarget[surfIndex]);
968         }
969 
970         MOS_Delete(vpHalRenderParams->pColorFillParams);
971         MOS_Delete(vpHalRenderParams);
972     }
973 
974     if (vpCtx->pCpDdiInterfaceNext)
975     {
976         MOS_Delete(vpCtx->pCpDdiInterfaceNext);
977     }
978 
979 #if (_DEBUG || _RELEASE_INTERNAL)
980     DdiVpTools::DestoryDumpConfig(vpCtx);
981 #endif //(_DEBUG || _RELEASE_INTERNAL)
982     return;
983 }
984 
DdiInitVpHal(PDDI_VP_CONTEXT vpCtx)985 VAStatus DdiVpFunctions::DdiInitVpHal(
986     PDDI_VP_CONTEXT   vpCtx)
987 {
988     PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
989 
990     VpBase           *vpHal        = nullptr;
991     VpSettings       vpHalSettings = {};
992     VAStatus         vaStatus      = VA_STATUS_ERROR_UNKNOWN;
993 
994     DDI_VP_FUNC_ENTER;
995     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
996 
997     // Create VpHal state
998     MOS_STATUS status = MOS_STATUS_UNKNOWN;
999     vpHal = VpBase::VphalStateFactory( nullptr, &(vpCtx->MosDrvCtx), &status);
1000     if (vpHal && MOS_FAILED(status))
1001     {
1002         MOS_Delete(vpHal);
1003         vpHal = nullptr;
1004     }
1005     if (!vpHal)
1006     {
1007         DDI_VP_ASSERTMESSAGE("Failed to create vphal.");
1008         MOS_Delete(vpCtx);
1009         return VA_STATUS_ERROR_ALLOCATION_FAILED;
1010     }
1011 
1012     vpHalSettings.maxPhases                = VP_SETTING_MAX_PHASES;
1013     vpHalSettings.mediaStates              = VP_SETTING_MEDIA_STATES;
1014     vpHalSettings.sameSampleThreshold      = VP_SETTING_SAME_SAMPLE_THRESHOLD;
1015     vpHalSettings.disableDnDi              = false;
1016 
1017     // Allocate resources (state heaps, resources, KDLL)
1018     if (MOS_FAILED(vpHal->Allocate(&vpHalSettings)))
1019     {
1020         DDI_VP_ASSERTMESSAGE("Failed to allocate resources for vphal.");
1021         MOS_Delete(vpHal);
1022         vpHal = nullptr;
1023         return vaStatus;
1024     }
1025 
1026     vpCtx->pVpHal  = vpHal;
1027     return VA_STATUS_SUCCESS;
1028 }
1029 
DdiDestroyVpHal(PDDI_VP_CONTEXT vpCtx)1030 VAStatus DdiVpFunctions::DdiDestroyVpHal(PDDI_VP_CONTEXT vpCtx)
1031 {
1032     DDI_VP_FUNC_ENTER;
1033     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1034 
1035     DdiDestroyRenderParams(vpCtx);
1036 
1037     // Destroy VPHAL context
1038     if (vpCtx)
1039     {
1040         vpCtx->MosDrvCtx.m_skuTable.reset();
1041         vpCtx->MosDrvCtx.m_waTable.reset();
1042         if (vpCtx->pVpHal)
1043         {
1044             MOS_Delete(vpCtx->pVpHal);
1045             vpCtx->pVpHal = nullptr;
1046         }
1047 
1048 #if (_DEBUG || _RELEASE_INTERNAL)
1049         DdiVpTools::DestoryDumpConfig(vpCtx);
1050 #endif //(_DEBUG || _RELEASE_INTERNAL)
1051     }
1052 
1053     return VA_STATUS_SUCCESS;
1054 }
1055 
DdiDestroyRenderParams(PDDI_VP_CONTEXT vpCtx)1056 VAStatus DdiVpFunctions::DdiDestroyRenderParams(PDDI_VP_CONTEXT vpCtx)
1057 {
1058     DDI_VP_FUNC_ENTER;
1059     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1060 
1061     DdiDestroySrcParams(vpCtx);
1062     DdiDestroyTargetParams(vpCtx);
1063 
1064     if (vpCtx->pVpHalRenderParams)
1065     {
1066         MOS_Delete(vpCtx->pVpHalRenderParams->pSplitScreenDemoModeParams);
1067         MOS_Delete(vpCtx->pVpHalRenderParams->pCompAlpha);
1068         if (vpCtx->pVpHalRenderParams->pColorFillParams)
1069         {
1070             MOS_Delete(vpCtx->pVpHalRenderParams->pColorFillParams);
1071         }
1072         MOS_Delete(vpCtx->pVpHalRenderParams);
1073     }
1074 
1075     return VA_STATUS_SUCCESS;
1076 }
1077 
DdiDestroySrcParams(PDDI_VP_CONTEXT vpCtx)1078 VAStatus DdiVpFunctions::DdiDestroySrcParams(PDDI_VP_CONTEXT vpCtx)
1079 {
1080     DDI_VP_FUNC_ENTER;
1081     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1082     DDI_VP_CHK_NULL(vpCtx->pVpHalRenderParams, "nullptr vpCtx->pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
1083 
1084     for (uint32_t surfIndex = 0; surfIndex < VPHAL_MAX_SOURCES; surfIndex++)
1085     {
1086         if (nullptr != vpCtx->pVpHalRenderParams->pSrc[surfIndex])
1087         {
1088             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pProcampParams);
1089             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pDeinterlaceParams);
1090             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pDenoiseParams);
1091             if (vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pIEFParams)
1092             {
1093                 if (!vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pIEFParams->pExtParam)
1094                 {
1095                     DDI_VP_ASSERTMESSAGE("vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pIEFParams->pExtParam is nullptr.");
1096                 }
1097                 MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pIEFParams);
1098             }
1099             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pBlendingParams);
1100             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pLumaKeyParams);
1101             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pColorPipeParams);
1102             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pHDRParams);
1103             if (vpCtx->pVpHalRenderParams->pSrc[surfIndex]->p3DLutParams)
1104             {
1105                 MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->p3DLutParams->pExt3DLutSurface);
1106             }
1107             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->p3DLutParams);
1108             DdiDestroyVpHalSurface(vpCtx->pVpHalRenderParams->pSrc[surfIndex]);
1109             vpCtx->pVpHalRenderParams->pSrc[surfIndex] = nullptr;
1110         }
1111     }
1112 
1113     return VA_STATUS_SUCCESS;
1114 }
1115 
DdiDestroyVpHalSurface(PVPHAL_SURFACE surf)1116 VAStatus DdiVpFunctions::DdiDestroyVpHalSurface(PVPHAL_SURFACE surf)
1117 {
1118     DDI_VP_FUNC_ENTER;
1119     DDI_VP_CHK_NULL(surf, "nullptr surf.", VA_STATUS_ERROR_INVALID_PARAMETER);
1120 
1121     if (surf->pFwdRef)
1122     {
1123         DdiDestroyVpHalSurface(surf->pFwdRef);
1124     }
1125     if (surf->pBwdRef)
1126     {
1127         DdiDestroyVpHalSurface(surf->pBwdRef);
1128     }
1129 
1130     MOS_Delete(surf);
1131     return VA_STATUS_SUCCESS;
1132 }
1133 
DdiDestroyTargetParams(PDDI_VP_CONTEXT vpCtx)1134 VAStatus DdiVpFunctions::DdiDestroyTargetParams(PDDI_VP_CONTEXT vpCtx)
1135 {
1136     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
1137     PVPHAL_SURFACE       targetSurface     = nullptr;
1138 
1139     DDI_VP_FUNC_ENTER;
1140     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1141     DDI_VP_CHK_NULL(vpCtx->pVpHalRenderParams, "nullptr vpCtx->pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
1142 
1143     vpHalRenderParams = vpCtx->pVpHalRenderParams;
1144     for (uint32_t targetIndex = 0; targetIndex < VPHAL_MAX_TARGETS; targetIndex++)
1145     {
1146         targetSurface = vpHalRenderParams->pTarget[targetIndex];
1147         if (targetSurface)
1148         {
1149             if (targetSurface->OsResource.bo)
1150             {
1151                 targetSurface->OsResource.bo = nullptr;
1152             }
1153             if (targetSurface->pProcampParams)
1154             {
1155                 MOS_Delete(targetSurface->pProcampParams);
1156             }
1157             if (targetSurface->pDeinterlaceParams)
1158             {
1159                 MOS_Delete(targetSurface->pDeinterlaceParams);
1160             }
1161             if (targetSurface->pDenoiseParams)
1162             {
1163                 MOS_Delete(targetSurface->pDenoiseParams);
1164             }
1165             if (targetSurface->pHDRParams)
1166             {
1167                 MOS_Delete(targetSurface->pHDRParams);
1168             }
1169 
1170             MOS_Delete(vpHalRenderParams->pTarget[targetIndex]);
1171         }
1172     }
1173     // reset render target count
1174     vpHalRenderParams->uDstCount = 0;
1175 
1176     return VA_STATUS_SUCCESS;
1177 }
1178 
QueryNoiseReductionCapsAttrib(uint32_t queryFlag,uint32_t queryCapsNum,uint32_t existCapsNum,void * filterCaps)1179 VAStatus DdiVpFunctions::QueryNoiseReductionCapsAttrib(
1180     uint32_t queryFlag,
1181     uint32_t queryCapsNum,
1182     uint32_t existCapsNum,
1183     void     *filterCaps)
1184 {
1185     VAProcFilterCap *dnCap = nullptr;
1186     DDI_VP_FUNC_ENTER;
1187 
1188     if (queryFlag == QUERY_CAPS_ATTRIBUTE)
1189     {
1190         DDI_VP_CHK_NULL(filterCaps, "nullptr filterCaps", VA_STATUS_ERROR_INVALID_PARAMETER);
1191         if (queryCapsNum < existCapsNum)
1192         {
1193             return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1194         }
1195         dnCap                      = (VAProcFilterCap *)filterCaps;
1196         dnCap->range.min_value     = NOISEREDUCTION_MIN;
1197         dnCap->range.max_value     = NOISEREDUCTION_MAX;
1198         dnCap->range.default_value = NOISEREDUCTION_DEFAULT;
1199         dnCap->range.step          = NOISEREDUCTION_STEP;
1200     }
1201     return VA_STATUS_SUCCESS;
1202 }
1203 
QueryDeinterlacingCapsAttrib(uint32_t queryFlag,uint32_t queryCapsNum,uint32_t existCapsNum,void * filterCaps)1204 VAStatus DdiVpFunctions::QueryDeinterlacingCapsAttrib(
1205     uint32_t queryFlag,
1206     uint32_t queryCapsNum,
1207     uint32_t existCapsNum,
1208     void     *filterCaps)
1209 {
1210     VAProcFilterCapDeinterlacing *diCap = nullptr;
1211     DDI_VP_FUNC_ENTER;
1212 
1213     if (queryFlag == QUERY_CAPS_ATTRIBUTE)
1214     {
1215         DDI_VP_CHK_NULL(filterCaps, "nullptr filterCaps", VA_STATUS_ERROR_INVALID_PARAMETER);
1216         if (queryCapsNum < existCapsNum)
1217         {
1218             return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1219         }
1220         diCap         = (VAProcFilterCapDeinterlacing*)filterCaps;
1221         diCap[0].type = VAProcDeinterlacingBob;
1222         diCap[1].type = VAProcDeinterlacingMotionAdaptive;
1223         diCap[2].type = VAProcDeinterlacingMotionCompensated;
1224     }
1225     return VA_STATUS_SUCCESS;
1226 }
1227 
QuerySharpeningCapsAttrib(uint32_t queryFlag,uint32_t queryCapsNum,uint32_t existCapsNum,void * filterCaps)1228 VAStatus DdiVpFunctions::QuerySharpeningCapsAttrib(
1229     uint32_t queryFlag,
1230     uint32_t queryCapsNum,
1231     uint32_t existCapsNum,
1232     void     *filterCaps)
1233 {
1234     VAProcFilterCap *sharpeningCap = nullptr;
1235     DDI_VP_FUNC_ENTER;
1236 
1237     if (queryFlag == QUERY_CAPS_ATTRIBUTE)
1238     {
1239         DDI_VP_CHK_NULL(filterCaps, "nullptr filterCaps", VA_STATUS_ERROR_INVALID_PARAMETER);
1240         if (queryCapsNum < existCapsNum)
1241         {
1242             return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1243         }
1244 
1245         sharpeningCap                      = (VAProcFilterCap*)filterCaps;
1246         sharpeningCap->range.min_value     = EDGEENHANCEMENT_MIN;
1247         sharpeningCap->range.max_value     = EDGEENHANCEMENT_MAX;
1248         sharpeningCap->range.default_value = EDGEENHANCEMENT_DEFAULT;
1249         sharpeningCap->range.step          = EDGEENHANCEMENT_STEP;
1250     }
1251     return VA_STATUS_SUCCESS;
1252 }
1253 
QueryColorBalanceCapsAttrib(uint32_t queryFlag,uint32_t queryCapsNum,uint32_t existCapsNum,void * filterCaps)1254 VAStatus DdiVpFunctions::QueryColorBalanceCapsAttrib(
1255     uint32_t queryFlag,
1256     uint32_t queryCapsNum,
1257     uint32_t existCapsNum,
1258     void     *filterCaps)
1259 {
1260     VAProcFilterCapColorBalance *colorBalCap = nullptr;
1261     DDI_VP_FUNC_ENTER;
1262 
1263     if (queryFlag == QUERY_CAPS_ATTRIBUTE)
1264     {
1265         DDI_VP_CHK_NULL(filterCaps, "nullptr filterCaps", VA_STATUS_ERROR_INVALID_PARAMETER);
1266         if (queryCapsNum < existCapsNum)
1267         {
1268             return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1269         }
1270 
1271         for (uint32_t cnt = 0; cnt < queryCapsNum; cnt++)
1272         {
1273             colorBalCap                         = (VAProcFilterCapColorBalance*)filterCaps + cnt;
1274             colorBalCap->type                   = m_vpColorBalCap[cnt].type;
1275             colorBalCap->range.default_value    = m_vpColorBalCap[cnt].range.default_value;
1276             colorBalCap->range.max_value        = m_vpColorBalCap[cnt].range.max_value;
1277             colorBalCap->range.min_value        = m_vpColorBalCap[cnt].range.min_value;
1278             colorBalCap->range.step             = m_vpColorBalCap[cnt].range.step;
1279         }
1280     }
1281     return VA_STATUS_SUCCESS;
1282 }
1283 
QuerySkinToneEnhancementCapsAttrib(uint32_t queryFlag,uint32_t queryCapsNum,uint32_t existCapsNum,void * filterCaps)1284 VAStatus DdiVpFunctions::QuerySkinToneEnhancementCapsAttrib(
1285     uint32_t queryFlag,
1286     uint32_t queryCapsNum,
1287     uint32_t existCapsNum,
1288     void     *filterCaps)
1289 {
1290     VAProcFilterCap *steCap = nullptr;
1291     DDI_VP_FUNC_ENTER;
1292 
1293     if (queryFlag == QUERY_CAPS_ATTRIBUTE)
1294     {
1295         DDI_VP_CHK_NULL(filterCaps, "nullptr filterCaps", VA_STATUS_ERROR_INVALID_PARAMETER);
1296         if (queryCapsNum < existCapsNum)
1297         {
1298             return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1299         }
1300         steCap                      = (VAProcFilterCap *)filterCaps;
1301         steCap->range.min_value     = STE_MIN;
1302         steCap->range.max_value     = STE_MAX;
1303         steCap->range.default_value = STE_DEFAULT;
1304         steCap->range.step          = STE_STEP;
1305     }
1306     return VA_STATUS_SUCCESS;
1307 }
1308 
QueryTotalColorCorrectionCapsAttrib(uint32_t queryFlag,uint32_t queryCapsNum,uint32_t existCapsNum,void * filterCaps)1309 VAStatus DdiVpFunctions::QueryTotalColorCorrectionCapsAttrib(
1310     uint32_t queryFlag,
1311     uint32_t queryCapsNum,
1312     uint32_t existCapsNum,
1313     void     *filterCaps)
1314 {
1315     VAProcFilterCapTotalColorCorrection *tccCap = nullptr;
1316     DDI_VP_FUNC_ENTER;
1317 
1318     if (queryFlag == QUERY_CAPS_ATTRIBUTE)
1319     {
1320         DDI_VP_CHK_NULL(filterCaps, "nullptr filterCaps", VA_STATUS_ERROR_INVALID_PARAMETER);
1321         if (queryCapsNum < existCapsNum)
1322         {
1323             return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1324         }
1325 
1326         for (uint32_t cnt = 0; cnt < queryCapsNum; cnt++)
1327         {
1328             tccCap                      = (VAProcFilterCapTotalColorCorrection *)filterCaps + cnt;
1329             tccCap->type                = (VAProcTotalColorCorrectionType)((uint32_t)VAProcTotalColorCorrectionRed + cnt);
1330             tccCap->range.min_value     = TCC_MIN;
1331             tccCap->range.max_value     = TCC_MAX;
1332             tccCap->range.default_value = TCC_DEFAULT;
1333             tccCap->range.step          = TCC_STEP;
1334         }
1335     }
1336     return VA_STATUS_SUCCESS;
1337 }
1338 
QueryHDRToneMappingCapsAttrib(uint32_t queryFlag,uint32_t queryCapsNum,uint32_t existCapsNum,void * filterCaps)1339 VAStatus DdiVpFunctions::QueryHDRToneMappingCapsAttrib(
1340     uint32_t            queryFlag,
1341     uint32_t            queryCapsNum,
1342     uint32_t            existCapsNum,
1343     void                *filterCaps)
1344 {
1345     VAProcFilterCapHighDynamicRange *hdrTmCap    = nullptr;
1346     DDI_VP_FUNC_ENTER;
1347 
1348     if (queryFlag == QUERY_CAPS_ATTRIBUTE)
1349     {
1350         DDI_VP_CHK_NULL(filterCaps,    "nullptr filterCaps",    VA_STATUS_ERROR_INVALID_PARAMETER);
1351         if (queryCapsNum < existCapsNum)
1352         {
1353             return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1354         }
1355         hdrTmCap                = (VAProcFilterCapHighDynamicRange *)filterCaps;
1356         hdrTmCap->metadata_type = VAProcHighDynamicRangeMetadataHDR10;
1357         hdrTmCap->caps_flag     = VA_TONE_MAPPING_HDR_TO_HDR | VA_TONE_MAPPING_HDR_TO_SDR | VA_TONE_MAPPING_HDR_TO_EDR;
1358 
1359     }
1360     return VA_STATUS_SUCCESS;
1361 }
1362 
QueryLut3DCapsAttrib(uint32_t queryFlag,uint32_t queryCapsNum,uint32_t existCapsNum,void * filterCaps)1363 VAStatus DdiVpFunctions::QueryLut3DCapsAttrib(
1364     uint32_t            queryFlag,
1365     uint32_t            queryCapsNum,
1366     uint32_t            existCapsNum,
1367     void                *filterCaps)
1368 {
1369     uint32_t             channelMapping = 0;
1370     VAProcFilterCap3DLUT *lut3DCap      = nullptr;
1371     DDI_VP_FUNC_ENTER;
1372 
1373     /* set the actual filter caps attribute in vp module */
1374     if (queryFlag == QUERY_CAPS_ATTRIBUTE)
1375     {
1376         DDI_VP_CHK_NULL(filterCaps,    "nullptr filterCaps",    VA_STATUS_ERROR_INVALID_PARAMETER);
1377         if (queryCapsNum < existCapsNum)
1378         {
1379             return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
1380         }
1381 
1382         channelMapping = VA_3DLUT_CHANNEL_RGB_RGB | VA_3DLUT_CHANNEL_YUV_RGB | VA_3DLUT_CHANNEL_VUY_RGB;
1383         /* 17^3 */
1384         lut3DCap                      = (VAProcFilterCap3DLUT *)filterCaps + 0;
1385         lut3DCap->lut_size            = 17;
1386         lut3DCap->lut_stride[0]       = 17;
1387         lut3DCap->lut_stride[1]       = 17;
1388         lut3DCap->lut_stride[2]       = 32;
1389         lut3DCap->bit_depth           = 16;
1390         lut3DCap->num_channel         = 4;
1391         lut3DCap->channel_mapping     = channelMapping;
1392         /* 33^3 */
1393         lut3DCap                      = (VAProcFilterCap3DLUT *)filterCaps + 1;
1394         lut3DCap->lut_size            = 33;
1395         lut3DCap->lut_stride[0]       = 33;
1396         lut3DCap->lut_stride[1]       = 33;
1397         lut3DCap->lut_stride[2]       = 64;
1398         lut3DCap->bit_depth           = 16;
1399         lut3DCap->num_channel         = 4;
1400         lut3DCap->channel_mapping     = channelMapping;
1401         /* 65^3 */
1402         lut3DCap                      = (VAProcFilterCap3DLUT *)filterCaps + 2;
1403         lut3DCap->lut_size            = 65;
1404         lut3DCap->lut_stride[0]       = 65;
1405         lut3DCap->lut_stride[1]       = 65;
1406         lut3DCap->lut_stride[2]       = 128;
1407         lut3DCap->bit_depth           = 16;
1408         lut3DCap->num_channel         = 4;
1409         lut3DCap->channel_mapping     = channelMapping;
1410     }
1411     return VA_STATUS_SUCCESS;
1412 }
1413 
VpGetRenderParams(PDDI_VP_CONTEXT vpCtx)1414 PVPHAL_RENDER_PARAMS DdiVpFunctions::VpGetRenderParams(PDDI_VP_CONTEXT vpCtx)
1415 {
1416     DDI_VP_FUNC_ENTER;
1417     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", nullptr);
1418     return vpCtx->pVpHalRenderParams;
1419 }
1420 
VpSetOsResource(PDDI_VP_CONTEXT vpCtx,PDDI_MEDIA_SURFACE boRt,uint32_t targetIndex)1421 VAStatus DdiVpFunctions::VpSetOsResource(
1422     PDDI_VP_CONTEXT     vpCtx,
1423     PDDI_MEDIA_SURFACE  boRt,
1424     uint32_t            targetIndex)
1425 {
1426     PMOS_RESOURCE           osResource        = nullptr;
1427     PVPHAL_RENDER_PARAMS    vpHalRenderParams = nullptr;
1428 
1429     DDI_VP_FUNC_ENTER;
1430     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1431     DDI_VP_CHK_NULL(boRt, "nullptr boRt.", VA_STATUS_ERROR_INVALID_SURFACE);
1432 
1433     // get vphal render parameters
1434     vpHalRenderParams = VpGetRenderParams(vpCtx);
1435     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
1436 
1437     // set render target os resource information according to target surface
1438     osResource              = &vpHalRenderParams->pTarget[targetIndex]->OsResource;
1439     DDI_VP_CHK_NULL(osResource, "nullptr osResource.", VA_STATUS_ERROR_INVALID_PARAMETER);
1440 
1441     osResource->bo          = boRt->bo;
1442     osResource->bMapped     = boRt->bMapped;
1443     osResource->Format      = MediaLibvaUtilNext::GetFormatFromMediaFormat(boRt->format);
1444     osResource->iWidth      = boRt->iWidth;
1445     osResource->iHeight     = boRt->iHeight;
1446     osResource->iPitch      = boRt->iPitch;
1447     osResource->iCount      = boRt->iRefCount;
1448     osResource->TileType    = MediaLibvaUtilNext::GetTileTypeFromMediaTileType(boRt->TileType);
1449     osResource->pGmmResInfo = boRt->pGmmResourceInfo;
1450 
1451     Mos_Solo_SetOsResource(boRt->pGmmResourceInfo, osResource);
1452 
1453     return VA_STATUS_SUCCESS;
1454 }
1455 
VpSetRenderParams(PDDI_MEDIA_SURFACE mediaSurf,PVPHAL_RENDER_PARAMS vpHalRenderParams,VASurfaceID renderTarget)1456 void DdiVpFunctions::VpSetRenderParams(
1457     PDDI_MEDIA_SURFACE    mediaSurf,
1458     PVPHAL_RENDER_PARAMS  vpHalRenderParams,
1459     VASurfaceID           renderTarget)
1460 {
1461     DDI_VP_FUNC_ENTER;
1462     DDI_VP_CHK_NULL(mediaSurf, "nullptr mediaSurf", );
1463     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams", );
1464 
1465     // reset source surface count
1466     vpHalRenderParams->uSrcCount = 0;
1467 
1468     vpHalRenderParams->bReportStatus    = true;
1469     vpHalRenderParams->StatusFeedBackID = renderTarget;
1470 
1471     if (mediaSurf->pSurfDesc && (mediaSurf->pSurfDesc->uiVaMemType == VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR))
1472     {
1473         vpHalRenderParams->pTarget[vpHalRenderParams->uDstCount]->b16UsrPtr = VpIs16UsrPtrPitch(mediaSurf->iPitch, mediaSurf->format);
1474     }
1475     else
1476     {
1477         vpHalRenderParams->pTarget[vpHalRenderParams->uDstCount]->b16UsrPtr = false;
1478     }
1479 
1480     // increase render target count
1481     vpHalRenderParams->uDstCount++;
1482     return;
1483 }
1484 
VpIs16UsrPtrPitch(uint32_t pitch,DDI_MEDIA_FORMAT format)1485 bool DdiVpFunctions::VpIs16UsrPtrPitch(uint32_t pitch, DDI_MEDIA_FORMAT format)
1486 {
1487     uint32_t pitchAligned = 64;
1488     bool     status       = false;
1489     DDI_VP_FUNC_ENTER;
1490 
1491     if (Media_Format_YV12 == format)
1492     {
1493         pitchAligned = 128;
1494     }
1495 
1496     if (!(pitch % 16) && (pitch % pitchAligned))
1497     {
1498         status = true;
1499     }
1500     else
1501     {
1502         status = false;
1503     }
1504 
1505     DDI_VP_NORMALMESSAGE("[VP] 16Usrptr check, surface pitch is %d, go to %s path.", pitch, status?"16Usrptr":"legacy");
1506     return status;
1507 }
1508 
VpReportFeatureMode(PDDI_VP_CONTEXT vpCtx)1509 VAStatus DdiVpFunctions::VpReportFeatureMode(PDDI_VP_CONTEXT vpCtx)
1510 {
1511     VP_CONFIG configValues = {};
1512     DDI_VP_FUNC_ENTER;
1513 
1514     DDI_VP_CHK_NULL(vpCtx,         "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1515     DDI_VP_CHK_NULL(vpCtx->pVpHal, "nullptr vpHal.", VA_STATUS_ERROR_INVALID_PARAMETER);
1516 
1517     VpConfigValuesInit(&configValues);
1518     VpHalDdiReportFeatureMode(vpCtx->pVpHal, &configValues);
1519     VpFeatureReport(&configValues, vpCtx);
1520 
1521     return VA_STATUS_SUCCESS;
1522 }
1523 
VpConfigValuesInit(PVP_CONFIG configValues)1524 void DdiVpFunctions::VpConfigValuesInit(
1525     PVP_CONFIG  configValues)
1526 {
1527     DDI_VP_FUNC_ENTER;
1528     DDI_VP_CHK_NULL(configValues, "nullptr configValues.",);
1529 
1530     configValues->dwVpPath                   = 0;
1531     configValues->dwVpComponent              = 0;
1532     configValues->dwReportedDeinterlaceMode  = LIBVA_VP_CONFIG_NOT_REPORTED;
1533     configValues->dwReportedScalingMode      = LIBVA_VP_CONFIG_NOT_REPORTED;
1534     configValues->dwReportedOutputPipeMode   = LIBVA_VP_CONFIG_NOT_REPORTED;
1535     configValues->dwReportedVEFeatureInUse   = LIBVA_VP_CONFIG_NOT_REPORTED;
1536     configValues->dwVPMMCInUseReported       = LIBVA_VP_CONFIG_NOT_REPORTED;
1537     configValues->dwRTCompressibleReported   = LIBVA_VP_CONFIG_NOT_REPORTED;
1538     configValues->dwRTCompressModeReported   = LIBVA_VP_CONFIG_NOT_REPORTED;
1539     configValues->dwCapturePipeInUseReported = LIBVA_VP_CONFIG_NOT_REPORTED;
1540     configValues->dwReportedCompositionMode  = LIBVA_VP_CONFIG_NOT_REPORTED;
1541     configValues->dwReportedHdrMode          = LIBVA_VP_CONFIG_NOT_REPORTED;
1542 
1543     configValues->dwFFDICompressibleReported    = LIBVA_VP_CONFIG_NOT_REPORTED;
1544     configValues->dwFFDICompressModeReported    = LIBVA_VP_CONFIG_NOT_REPORTED;
1545     configValues->dwFFDNCompressibleReported    = LIBVA_VP_CONFIG_NOT_REPORTED;
1546     configValues->dwFFDNCompressModeReported    = LIBVA_VP_CONFIG_NOT_REPORTED;
1547     configValues->dwSTMMCompressibleReported    = LIBVA_VP_CONFIG_NOT_REPORTED;
1548     configValues->dwSTMMCompressModeReported    = LIBVA_VP_CONFIG_NOT_REPORTED;
1549     configValues->dwScalerCompressibleReported  = LIBVA_VP_CONFIG_NOT_REPORTED;
1550     configValues->dwScalerCompressModeReported  = LIBVA_VP_CONFIG_NOT_REPORTED;
1551     configValues->dwPrimaryCompressibleReported = LIBVA_VP_CONFIG_NOT_REPORTED;
1552     configValues->dwPrimaryCompressModeReported = LIBVA_VP_CONFIG_NOT_REPORTED;
1553 
1554     configValues->dwReportedVeboxScalability    = LIBVA_VP_CONFIG_NOT_REPORTED;
1555     configValues->dwReportedVPApogeios          = LIBVA_VP_CONFIG_NOT_REPORTED;
1556     return;
1557 }
1558 
VpHalDdiReportFeatureMode(VpBase * vpHalState,PVP_CONFIG configValues)1559 void DdiVpFunctions::VpHalDdiReportFeatureMode(
1560     VpBase         *vpHalState,
1561     PVP_CONFIG     configValues)
1562 {
1563     VphalFeatureReport *report = nullptr;
1564     DDI_VP_FUNC_ENTER;
1565     DDI_VP_CHK_NULL(vpHalState, "nullptr vpHalState.", );
1566 
1567     // Get VPHAL feature reporting
1568     report = vpHalState->GetRenderFeatureReport();
1569     DDI_VP_CHK_NULL(report, "nullptr report", );
1570 
1571     report->SetConfigValues(configValues);
1572     return;
1573 }
1574 
VpFeatureReport(PVP_CONFIG config,PDDI_VP_CONTEXT vpCtx)1575 void DdiVpFunctions::VpFeatureReport(PVP_CONFIG config, PDDI_VP_CONTEXT vpCtx)
1576 {
1577     DDI_VP_FUNC_ENTER;
1578     DDI_VP_CHK_NULL(config, "nullptr config.", );
1579 
1580     MediaUserSettingSharedPtr userSettingPtr = vpCtx ? vpCtx->MosDrvCtx.m_userSettingPtr : nullptr;
1581 
1582     ReportUserSetting(
1583         userSettingPtr,
1584         __VPHAL_VEBOX_OUTPUTPIPE_MODE,
1585         config->dwCurrentOutputPipeMode,
1586         MediaUserSetting::Group::Sequence);
1587 
1588     ReportUserSetting(
1589         userSettingPtr,
1590         __VPHAL_VEBOX_FEATURE_INUSE,
1591         config->dwCurrentVEFeatureInUse,
1592         MediaUserSetting::Group::Sequence);
1593 
1594 #ifdef _MMC_SUPPORTED
1595     //VP Primary Surface Compress Mode Report
1596     ReportUserSetting(
1597         userSettingPtr,
1598         __VPHAL_PRIMARY_MMC_COMPRESSMODE,
1599         config->dwPrimaryCompressMode,
1600         MediaUserSetting::Group::Sequence);
1601     //VP RT Compress Mode
1602     ReportUserSetting(
1603         userSettingPtr,
1604         __VPHAL_RT_MMC_COMPRESSMODE,
1605         config->dwRTCompressMode,
1606         MediaUserSetting::Group::Sequence);
1607 #endif
1608     //VP RT Cache Usage
1609     ReportUserSetting(
1610         userSettingPtr,
1611         __VPHAL_RT_Cache_Setting,
1612         config->dwRTCacheSetting,
1613         MediaUserSetting::Group::Sequence);
1614 
1615 #if (_DEBUG || _RELEASE_INTERNAL)
1616     //VP RT Old Cache Usage
1617     ReportUserSetting(
1618         userSettingPtr,
1619         __VPHAL_RT_Old_Cache_Setting,
1620         config->dwRTOldCacheSetting,
1621         MediaUserSetting::Group::Sequence);
1622 
1623     ReportUserSettingForDebug(
1624         userSettingPtr,
1625         __VPHAL_VEBOX_HDR_MODE,
1626         config->dwCurrentHdrMode,
1627         MediaUserSetting::Group::Sequence);
1628 
1629 #ifdef _MMC_SUPPORTED
1630     //VP MMC In Use
1631     ReportUserSettingForDebug(
1632         userSettingPtr,
1633         __VPHAL_MMC_ENABLE,
1634         config->dwVPMMCInUse,
1635         MediaUserSetting::Group::Sequence);
1636 
1637     //VP Primary Surface Compressible
1638     ReportUserSettingForDebug(
1639         userSettingPtr,
1640         __VPHAL_PRIMARY_MMC_COMPRESSIBLE,
1641         config->dwPrimaryCompressible,
1642         MediaUserSetting::Group::Sequence);
1643 
1644     //VP RT Compressible
1645     ReportUserSettingForDebug(
1646         userSettingPtr,
1647         __VPHAL_RT_MMC_COMPRESSIBLE,
1648         config->dwRTCompressible,
1649         MediaUserSetting::Group::Sequence);
1650 
1651 #endif
1652 #endif //(_DEBUG || _RELEASE_INTERNAL)
1653 
1654     if (config->dwCurrentVeboxScalability != config->dwReportedVeboxScalability)
1655     {
1656         ReportUserSetting(
1657             userSettingPtr,
1658             __MEDIA_USER_FEATURE_VALUE_ENABLE_VEBOX_SCALABILITY_MODE,
1659             config->dwCurrentVeboxScalability,
1660             MediaUserSetting::Group::Device);
1661 
1662         config->dwReportedVeboxScalability = config->dwCurrentVeboxScalability;
1663     }
1664 
1665     if (config->dwCurrentVPApogeios != config->dwReportedVPApogeios)
1666     {
1667         ReportUserSetting(
1668             userSettingPtr,
1669             __MEDIA_USER_FEATURE_VALUE_VPP_APOGEIOS_ENABLE,
1670             config->dwCurrentVPApogeios,
1671             MediaUserSetting::Group::Sequence);
1672 
1673         config->dwReportedVPApogeios = config->dwCurrentVPApogeios;
1674     }
1675 
1676     return;
1677 }
1678 
DdiSetGpuPriority(PDDI_VP_CONTEXT vpCtx,int32_t priority)1679 VAStatus DdiVpFunctions::DdiSetGpuPriority(
1680     PDDI_VP_CONTEXT     vpCtx,
1681     int32_t             priority)
1682 {
1683     PMOS_INTERFACE osInterface = nullptr;
1684     DDI_VP_FUNC_ENTER;
1685     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
1686 
1687     //Set the priority for Gpu
1688     if(vpCtx->pVpHal)
1689     {
1690         osInterface = vpCtx->pVpHal->GetOsInterface();
1691         DDI_VP_CHK_NULL(osInterface, "nullptr osInterface.", VA_STATUS_ERROR_ALLOCATION_FAILED);
1692         osInterface->pfnSetGpuPriority(osInterface, priority);
1693     }
1694     return VA_STATUS_SUCCESS;
1695 }
1696 
VpSetColorStandardExplictly(PVPHAL_SURFACE vpHalSurf,VAProcColorStandardType colorStandard,VAProcColorProperties colorProperties)1697 VAStatus DdiVpFunctions::VpSetColorStandardExplictly(
1698     PVPHAL_SURFACE          vpHalSurf,
1699     VAProcColorStandardType colorStandard,
1700     VAProcColorProperties   colorProperties)
1701 {
1702     DDI_VP_FUNC_ENTER;
1703     DDI_VP_CHK_NULL(vpHalSurf, "nullptr vpHalSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
1704     DDI_VP_CHK_CONDITION((colorStandard != VAProcColorStandardExplicit), "Not Explict color standard, Exit!", VA_STATUS_ERROR_INVALID_PARAMETER);
1705 
1706     if (IS_RGB_FORMAT(vpHalSurf->Format))
1707     {
1708         switch (colorProperties.colour_primaries)
1709         {
1710             case COLOUR_PRIMARY_BT2020:
1711                 vpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_REDUCED) ? CSpace_BT2020_stRGB : CSpace_BT2020_RGB;
1712                 break;
1713             case COLOUR_PRIMARY_BT709:
1714             case COLOUR_PRIMARY_BT601:
1715                 vpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_REDUCED) ? CSpace_stRGB : CSpace_sRGB;
1716                 break;
1717             default:
1718                 vpHalSurf->ColorSpace = CSpace_sRGB;
1719                 DDI_VP_ASSERTMESSAGE("unknown Color Standard for RGB format.");
1720                 break;
1721         }
1722     }
1723 
1724     if (IS_YUV_FORMAT(vpHalSurf->Format) || IS_ALPHA_YUV_FORMAT(vpHalSurf->Format))
1725     {
1726         switch (colorProperties.colour_primaries)
1727         {
1728             case COLOUR_PRIMARY_BT2020:
1729                 vpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_FULL) ? CSpace_BT2020_FullRange : CSpace_BT2020;
1730                 break;
1731             case COLOUR_PRIMARY_BT709:
1732                 vpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_FULL) ? CSpace_BT709_FullRange : CSpace_BT709;
1733                 break;
1734             case COLOUR_PRIMARY_BT601:
1735                 vpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_FULL) ? CSpace_BT601_FullRange : CSpace_BT601;
1736                 break;
1737             default:
1738                 vpHalSurf->ColorSpace = CSpace_BT601;
1739                 DDI_VP_ASSERTMESSAGE("unknown Color Standard for YUV format.");
1740                 break;
1741         }
1742     }
1743 
1744     switch (colorProperties.transfer_characteristics)
1745     {
1746         case TRANSFER_CHARACTERISTICS_ST2084:
1747             vpHalSurf->GammaType = VPHAL_GAMMA_SMPTE_ST2084;
1748             break;
1749         default:
1750             vpHalSurf->GammaType = VPHAL_GAMMA_TRADITIONAL_GAMMA;
1751             break;
1752     }
1753 
1754     return VA_STATUS_SUCCESS;
1755 }
1756 
VpIsRenderTarget(VADriverContextP vaDrvCtx,PDDI_VP_CONTEXT vpCtx,VAProcPipelineParameterBuffer * pipelineParam)1757 bool DdiVpFunctions::VpIsRenderTarget(
1758     VADriverContextP              vaDrvCtx,
1759     PDDI_VP_CONTEXT               vpCtx,
1760     VAProcPipelineParameterBuffer *pipelineParam)
1761 {
1762     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
1763     PDDI_MEDIA_CONTEXT   mediaCtx          = nullptr;
1764     PDDI_MEDIA_SURFACE   mediaSrcSurf      = nullptr;
1765     PVPHAL_SURFACE       vpHalTgtSurf      = nullptr;
1766     bool                 isTarget          = false;
1767 
1768     DDI_VP_FUNC_ENTER;
1769     DDI_VP_CHK_NULL(vaDrvCtx,      "nullptr vaDrvCtx.",      VA_STATUS_ERROR_INVALID_CONTEXT);
1770     DDI_VP_CHK_NULL(vpCtx,         "nullptr vpCtx.",         VA_STATUS_ERROR_INVALID_CONTEXT);
1771     DDI_VP_CHK_NULL(pipelineParam, "nullptr pipelineParam.", VA_STATUS_ERROR_INVALID_BUFFER);
1772 
1773     mediaCtx = GetMediaContext(vaDrvCtx);
1774     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1775     mediaSrcSurf = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, pipelineParam->surface);
1776     DDI_VP_CHK_NULL(mediaSrcSurf, "nullptr mediaSrcSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
1777     vpHalRenderParams = vpCtx->pVpHalRenderParams;
1778     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
1779 
1780     if (pipelineParam->pipeline_flags == 0 && vpHalRenderParams->uDstCount >= 1)
1781     {
1782         vpHalTgtSurf = vpHalRenderParams->pTarget[vpHalRenderParams->uDstCount - 1];
1783 
1784         isTarget = ((vpHalTgtSurf->OsResource.bo != nullptr) && (vpHalTgtSurf->OsResource.bo == mediaSrcSurf->bo));
1785     }
1786 
1787     return isTarget;
1788 }
1789 
VpSetRenderTargetParams(VADriverContextP vaDrvCtx,PDDI_VP_CONTEXT vpCtx,VAProcPipelineParameterBuffer * pipelineParam)1790 VAStatus DdiVpFunctions::VpSetRenderTargetParams(
1791     VADriverContextP              vaDrvCtx,
1792     PDDI_VP_CONTEXT               vpCtx,
1793     VAProcPipelineParameterBuffer *pipelineParam)
1794 {
1795     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
1796     PDDI_MEDIA_CONTEXT   mediaCtx          = nullptr;
1797     PDDI_MEDIA_SURFACE   mediaSrcSurf      = nullptr;
1798     PVPHAL_SURFACE       vpHalTgtSurf      = nullptr;
1799 
1800     DDI_VP_FUNC_ENTER;
1801     DDI_VP_CHK_NULL(vaDrvCtx,      "nullptr vaDrvCtx.",      VA_STATUS_ERROR_INVALID_CONTEXT);
1802     DDI_VP_CHK_NULL(vpCtx,         "nullptr vpCtx.",         VA_STATUS_ERROR_INVALID_CONTEXT);
1803     DDI_VP_CHK_NULL(pipelineParam, "nullptr pipelineParam.", VA_STATUS_ERROR_INVALID_BUFFER);
1804 
1805     mediaCtx = GetMediaContext(vaDrvCtx);
1806     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1807 
1808     mediaSrcSurf = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, pipelineParam->surface);
1809     DDI_VP_CHK_NULL(mediaSrcSurf, "nullptr mediaSrcSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
1810     vpHalRenderParams = vpCtx->pVpHalRenderParams;
1811     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
1812 
1813     if(vpHalRenderParams->uDstCount < 1)
1814     {
1815         DDI_VP_ASSERTMESSAGE("vpHalRenderParams->uDstCount is lower than 1");
1816         return VA_STATUS_ERROR_INVALID_PARAMETER;
1817     }
1818     DDI_VP_CHK_NULL(vpHalRenderParams->pTarget, "nullptr vpHalRenderParams->pTarget.", VA_STATUS_ERROR_INVALID_BUFFER);
1819     vpHalTgtSurf = vpHalRenderParams->pTarget[vpHalRenderParams->uDstCount - 1];
1820     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
1821 
1822     // Set src rect
1823     SetSrcRect(pipelineParam->surface_region, vpHalTgtSurf, mediaSrcSurf);
1824     // Set dest rect
1825     SetDestRect(pipelineParam->output_region, vpHalTgtSurf, mediaSrcSurf);
1826 
1827     if (IsProcmpEnable(vpHalTgtSurf))
1828     {
1829         // correct the ChromaSitting location if Procamp is enabled.
1830 #if (VA_MAJOR_VERSION < 1)
1831         pipelineParam->output_surface_flag = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
1832 #else
1833         pipelineParam->output_color_properties.chroma_sample_location = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
1834 #endif
1835     }
1836 
1837 #if (VA_MAJOR_VERSION < 1)
1838     VpUpdateProcChromaSittingState(vpHalTgtSurf, (uint8_t)(pipelineParam->output_surface_flag & 0xff));
1839 #else
1840     VpUpdateProcChromaSittingState(vpHalTgtSurf, pipelineParam->output_color_properties.chroma_sample_location);
1841 #endif
1842     return VA_STATUS_SUCCESS;
1843 }
1844 
SetSrcRect(const VARectangle * surfaceRegion,PVPHAL_SURFACE vpHalTgtSurf,PDDI_MEDIA_SURFACE mediaSrcSurf)1845 void DdiVpFunctions::SetSrcRect(
1846     const VARectangle  *surfaceRegion,
1847     PVPHAL_SURFACE     vpHalTgtSurf,
1848     PDDI_MEDIA_SURFACE mediaSrcSurf)
1849 {
1850     DDI_VP_FUNC_ENTER;
1851     DDI_VP_CHK_NULL(surfaceRegion, "nullptr surfaceRegion", );
1852     DDI_VP_CHK_NULL(vpHalTgtSurf,  "nullptr vpHalTgtSurf", );
1853     DDI_VP_CHK_NULL(mediaSrcSurf,  "nullptr mediaSrcSurf", );
1854 
1855     vpHalTgtSurf->rcSrc.left    = surfaceRegion->x;
1856     vpHalTgtSurf->rcSrc.top     = surfaceRegion->y;
1857     vpHalTgtSurf->rcSrc.right   = surfaceRegion->x + surfaceRegion->width;
1858     vpHalTgtSurf->rcSrc.bottom  = surfaceRegion->y + surfaceRegion->height;
1859 
1860     if (vpHalTgtSurf->rcSrc.top < 0)
1861     {
1862         vpHalTgtSurf->rcSrc.top = 0;
1863     }
1864 
1865     if (vpHalTgtSurf->rcSrc.left < 0)
1866     {
1867         vpHalTgtSurf->rcSrc.left = 0;
1868     }
1869 
1870     if (vpHalTgtSurf->rcSrc.right > mediaSrcSurf->iWidth)
1871     {
1872         vpHalTgtSurf->rcSrc.right = mediaSrcSurf->iWidth;
1873     }
1874 
1875     if (vpHalTgtSurf->rcSrc.bottom > mediaSrcSurf->iHeight)
1876     {
1877         vpHalTgtSurf->rcSrc.bottom = mediaSrcSurf->iHeight;
1878     }
1879 
1880     return;
1881 }
1882 
SetDestRect(const VARectangle * outputRegion,PVPHAL_SURFACE vpHalTgtSurf,PDDI_MEDIA_SURFACE mediaSrcSurf)1883 void DdiVpFunctions::SetDestRect(
1884     const VARectangle  *outputRegion,
1885     PVPHAL_SURFACE     vpHalTgtSurf,
1886     PDDI_MEDIA_SURFACE mediaSrcSurf)
1887 {
1888     DDI_VP_FUNC_ENTER;
1889     DDI_VP_CHK_NULL(outputRegion, "nullptr outputRegion", );
1890     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf", );
1891     DDI_VP_CHK_NULL(mediaSrcSurf, "nullptr mediaSrcSurf", );
1892 
1893     vpHalTgtSurf->rcDst.left    = outputRegion->x;
1894     vpHalTgtSurf->rcDst.top     = outputRegion->y;
1895     vpHalTgtSurf->rcDst.right   = outputRegion->x + outputRegion->width;
1896     vpHalTgtSurf->rcDst.bottom  = outputRegion->y + outputRegion->height;
1897     if (vpHalTgtSurf->rcDst.top < 0)
1898     {
1899         vpHalTgtSurf->rcDst.top = 0;
1900     }
1901 
1902     if (vpHalTgtSurf->rcDst.left < 0)
1903     {
1904         vpHalTgtSurf->rcDst.left = 0;
1905     }
1906 
1907     if (vpHalTgtSurf->rcDst.right > mediaSrcSurf->iWidth)
1908     {
1909         vpHalTgtSurf->rcDst.right = mediaSrcSurf->iWidth;
1910     }
1911 
1912     if (vpHalTgtSurf->rcDst.bottom > mediaSrcSurf->iHeight)
1913     {
1914         vpHalTgtSurf->rcDst.bottom = mediaSrcSurf->iHeight;
1915     }
1916 
1917     return;
1918 }
1919 
IsProcmpEnable(PVPHAL_SURFACE vpHalSrcSurf)1920 bool DdiVpFunctions::IsProcmpEnable(PVPHAL_SURFACE vpHalSrcSurf)
1921 {
1922     DDI_VP_FUNC_ENTER;
1923     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
1924 
1925     if ((vpHalSrcSurf->pProcampParams && vpHalSrcSurf->pProcampParams->bEnabled) &&
1926         (vpHalSrcSurf->pProcampParams->fContrast == 1 && vpHalSrcSurf->pProcampParams->fHue == 0 && vpHalSrcSurf->pProcampParams->fSaturation == 1) &&
1927         !vpHalSrcSurf->pBlendingParams && !vpHalSrcSurf->pLumaKeyParams && (!vpHalSrcSurf->pIEFParams || !vpHalSrcSurf->pIEFParams->bEnabled) &&
1928         !vpHalSrcSurf->pDeinterlaceParams && (!vpHalSrcSurf->pDenoiseParams || (!vpHalSrcSurf->pDenoiseParams->bEnableChroma && !vpHalSrcSurf->pDenoiseParams->bEnableLuma)) &&
1929         (!vpHalSrcSurf->pColorPipeParams || (!vpHalSrcSurf->pColorPipeParams->bEnableACE && !vpHalSrcSurf->pColorPipeParams->bEnableSTE && !vpHalSrcSurf->pColorPipeParams->bEnableTCC)) &&
1930         !vpHalSrcSurf->pHDRParams)
1931     {
1932         return true;
1933     }
1934 
1935     return false;
1936 }
1937 
VpUpdateProcChromaSittingState(PVPHAL_SURFACE vpHalSurf,uint8_t chromasitingState)1938 VAStatus DdiVpFunctions::VpUpdateProcChromaSittingState(
1939     PVPHAL_SURFACE vpHalSurf,
1940     uint8_t        chromasitingState)
1941 {
1942     uint32_t chromaSitingFlags = 0;
1943 
1944     DDI_VP_FUNC_ENTER;
1945     DDI_VP_CHK_NULL(vpHalSurf, "nullptr vpHalSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
1946 
1947     // Chroma siting
1948     // The lower 4 bits are still used as chroma-siting flag for output/input_surface_flag
1949     // Set the vertical chroma siting info at bit 1:0
1950     chromaSitingFlags = chromasitingState & 0x3;
1951 
1952     switch (chromaSitingFlags)
1953     {
1954     case VA_CHROMA_SITING_VERTICAL_TOP:
1955         vpHalSurf->ChromaSiting = CHROMA_SITING_VERT_TOP;
1956         break;
1957     case VA_CHROMA_SITING_VERTICAL_CENTER:
1958         vpHalSurf->ChromaSiting = CHROMA_SITING_VERT_CENTER;
1959         break;
1960     case VA_CHROMA_SITING_VERTICAL_BOTTOM:
1961         vpHalSurf->ChromaSiting = CHROMA_SITING_VERT_BOTTOM;
1962         break;
1963     default:
1964         vpHalSurf->ChromaSiting = CHROMA_SITING_NONE;
1965         break;
1966     }
1967 
1968     if (vpHalSurf->ChromaSiting != CHROMA_SITING_NONE)
1969     {
1970         // Set the horizontal chroma siting info at bit 3:2
1971         chromaSitingFlags = chromasitingState & 0xc;
1972 
1973         switch (chromaSitingFlags)
1974         {
1975         case VA_CHROMA_SITING_HORIZONTAL_LEFT:
1976             vpHalSurf->ChromaSiting = vpHalSurf->ChromaSiting | CHROMA_SITING_HORZ_LEFT;
1977             break;
1978         case VA_CHROMA_SITING_HORIZONTAL_CENTER:
1979             vpHalSurf->ChromaSiting = vpHalSurf->ChromaSiting | CHROMA_SITING_HORZ_CENTER;
1980             break;
1981         default:
1982             vpHalSurf->ChromaSiting = CHROMA_SITING_NONE;
1983             break;
1984         }
1985     }
1986 
1987     return VA_STATUS_SUCCESS;
1988 }
1989 
SetSrcSurfaceRect(const VARectangle * surfRegion,PVPHAL_SURFACE vpHalSrcSurf,PDDI_MEDIA_SURFACE mediaSrcSurf)1990 void DdiVpFunctions::SetSrcSurfaceRect(
1991     const VARectangle        *surfRegion,
1992     PVPHAL_SURFACE           vpHalSrcSurf,
1993     PDDI_MEDIA_SURFACE       mediaSrcSurf)
1994 {
1995     DDI_VP_FUNC_ENTER;
1996     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf", );
1997     DDI_VP_CHK_NULL(mediaSrcSurf, "nullptr mediaSrcSurf", );
1998 
1999     if (surfRegion != nullptr)
2000     {
2001         vpHalSrcSurf->rcSrc.top    = surfRegion->y;
2002         vpHalSrcSurf->rcSrc.left   = surfRegion->x;
2003         vpHalSrcSurf->rcSrc.right  = surfRegion->x + surfRegion->width;
2004         vpHalSrcSurf->rcSrc.bottom = surfRegion->y + surfRegion->height;
2005 
2006         if (vpHalSrcSurf->rcSrc.top < 0)
2007         {
2008             vpHalSrcSurf->rcSrc.top = 0;
2009         }
2010 
2011         if (vpHalSrcSurf->rcSrc.left < 0)
2012         {
2013             vpHalSrcSurf->rcSrc.left = 0;
2014         }
2015 
2016         if (vpHalSrcSurf->rcSrc.right > mediaSrcSurf->iWidth)
2017         {
2018             vpHalSrcSurf->rcSrc.right = mediaSrcSurf->iWidth;
2019         }
2020 
2021         if (vpHalSrcSurf->rcSrc.bottom > mediaSrcSurf->iRealHeight)
2022         {
2023             vpHalSrcSurf->rcSrc.bottom = mediaSrcSurf->iRealHeight;
2024         }
2025     }
2026     else
2027     {
2028         // nullptr surface_region implies the whole surface
2029         vpHalSrcSurf->rcSrc.top    = 0;
2030         vpHalSrcSurf->rcSrc.left   = 0;
2031         vpHalSrcSurf->rcSrc.right  = mediaSrcSurf->iWidth;
2032         vpHalSrcSurf->rcSrc.bottom = mediaSrcSurf->iRealHeight;
2033     }
2034     return;
2035 }
2036 
SetDestSurfaceRect(const VARectangle * outputRegion,PVPHAL_SURFACE vpHalSrcSurf,PVPHAL_SURFACE vpHalTgtSurf)2037 VAStatus DdiVpFunctions::SetDestSurfaceRect(
2038     const VARectangle    *outputRegion,
2039     PVPHAL_SURFACE       vpHalSrcSurf,
2040     PVPHAL_SURFACE       vpHalTgtSurf)
2041 {
2042     DDI_VP_FUNC_ENTER;
2043     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
2044     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
2045     if (outputRegion != nullptr)
2046     {
2047         vpHalSrcSurf->rcDst.top    = outputRegion->y;
2048         vpHalSrcSurf->rcDst.left   = outputRegion->x;
2049         vpHalSrcSurf->rcDst.right  = outputRegion->x + outputRegion->width;
2050         vpHalSrcSurf->rcDst.bottom = outputRegion->y + outputRegion->height;
2051     }
2052     else
2053     {
2054         vpHalSrcSurf->rcDst.top    = 0;
2055         vpHalSrcSurf->rcDst.left   = 0;
2056         vpHalSrcSurf->rcDst.right  = vpHalTgtSurf->rcDst.right;
2057         vpHalSrcSurf->rcDst.bottom = vpHalTgtSurf->rcDst.bottom;
2058     }
2059 
2060     if ((vpHalTgtSurf->rcSrc.right < vpHalSrcSurf->rcDst.right) ||
2061         (vpHalTgtSurf->rcSrc.bottom < vpHalSrcSurf->rcDst.bottom))
2062     {
2063         DDI_VP_CHK_CONDITION(true, "Invalid color fill parameter!", VA_STATUS_ERROR_INVALID_PARAMETER);
2064     }
2065     return VA_STATUS_SUCCESS;
2066 }
2067 
2068 #if (VA_MAJOR_VERSION < 1)
DdiGetColorSpace(PVPHAL_SURFACE vpHalSurf,VAProcColorStandardType colorStandard,uint32_t flag)2069 VAStatus DdiVpFunctions::DdiGetColorSpace(PVPHAL_SURFACE vpHalSurf, VAProcColorStandardType colorStandard, uint32_t flag)
2070 #else
2071 VAStatus DdiVpFunctions::DdiGetColorSpace(PVPHAL_SURFACE vpHalSurf, VAProcColorStandardType colorStandard, VAProcColorProperties colorProperties)
2072 #endif
2073 {
2074     uint8_t colorRange = colorProperties.color_range;
2075 
2076     DDI_VP_FUNC_ENTER;
2077     DDI_VP_CHK_NULL(vpHalSurf, "nullptr vpHalSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
2078 
2079     vpHalSurf->ColorSpace = CSpace_None;
2080 
2081     // Convert VAProcColorStandardType to VPHAL_CSPACE
2082     if (IS_RGB_FORMAT(vpHalSurf->Format) || (vpHalSurf->Format == Format_P8))
2083     {
2084         switch (colorStandard)
2085         {
2086         case VAProcColorStandardBT2020:
2087 #if (VA_MAJOR_VERSION < 1)
2088             if (flag & VA_SOURCE_RANGE_FULL)
2089 #else
2090             if (colorRange == VA_SOURCE_RANGE_FULL)
2091 #endif
2092             {
2093                 vpHalSurf->ColorSpace = CSpace_BT2020_RGB;
2094             }
2095             else
2096             {
2097                 vpHalSurf->ColorSpace = CSpace_BT2020_stRGB;
2098             }
2099             break;
2100         case VAProcColorStandardSTRGB:
2101             vpHalSurf->ColorSpace = CSpace_stRGB;
2102             break;
2103         case VAProcColorStandardExplicit:
2104             VpSetColorStandardExplictly(vpHalSurf, colorStandard, colorProperties);
2105             break;
2106         case VAProcColorStandardSRGB:
2107         default:
2108             vpHalSurf->ColorSpace = CSpace_sRGB;
2109             break;
2110         }
2111     }
2112     else
2113     {
2114         // Set colorspace by default to avoid application don't set ColorStandard
2115         if (colorStandard == 0)
2116         {
2117             VpSetColorSpaceByDefault(vpHalSurf);
2118         }
2119         else
2120         {
2121             VpSetColorSpaceByColorStandard(vpHalSurf, colorStandard, colorProperties, colorRange);
2122         }
2123     }
2124     DDI_VP_CHK_CONDITION((vpHalSurf->ColorSpace == CSpace_None), "Invalid color standard", VA_STATUS_ERROR_INVALID_PARAMETER);
2125 
2126     return VA_STATUS_SUCCESS;
2127 }
2128 
SetBackgroundColorfill(PVPHAL_RENDER_PARAMS vpHalRenderParams,uint32_t outBackGroundcolor)2129 VAStatus DdiVpFunctions::SetBackgroundColorfill(
2130     PVPHAL_RENDER_PARAMS vpHalRenderParams,
2131     uint32_t             outBackGroundcolor)
2132 {
2133     DDI_VP_FUNC_ENTER;
2134     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2135 
2136     if ((outBackGroundcolor >> 24) != 0)
2137     {
2138         if (vpHalRenderParams->pColorFillParams == nullptr)
2139         {
2140             vpHalRenderParams->pColorFillParams = MOS_New(VPHAL_COLORFILL_PARAMS);
2141         }
2142 
2143         DDI_VP_CHK_NULL(vpHalRenderParams->pColorFillParams, "nullptr pColorFillParams.", VA_STATUS_ERROR_UNKNOWN);
2144 
2145         // set background colorfill option
2146         vpHalRenderParams->pColorFillParams->Color   = outBackGroundcolor;
2147         vpHalRenderParams->pColorFillParams->bYCbCr  = false;
2148         vpHalRenderParams->pColorFillParams->CSpace  = CSpace_sRGB;
2149 
2150     }
2151     else
2152     {
2153         MOS_Delete(vpHalRenderParams->pColorFillParams);
2154     }
2155     return VA_STATUS_SUCCESS;
2156 }
2157 
VpHalDdiSetupSplitScreenDemoMode(uint32_t splitDemoPosDdi,uint32_t splitDemoParaDdi,PVPHAL_SPLIT_SCREEN_DEMO_MODE_PARAMS * splitScreenDemoModeParams,bool * disableDemoMode,PMOS_INTERFACE osInterface)2158 MOS_STATUS DdiVpFunctions::VpHalDdiSetupSplitScreenDemoMode(
2159     uint32_t                             splitDemoPosDdi,
2160     uint32_t                             splitDemoParaDdi,
2161     PVPHAL_SPLIT_SCREEN_DEMO_MODE_PARAMS *splitScreenDemoModeParams,
2162     bool                                 *disableDemoMode,
2163     PMOS_INTERFACE                       osInterface)
2164 {
2165     MOS_STATUS eStatus                   = MOS_STATUS_SUCCESS;
2166     uint32_t   splitScreenDemoPosition   = splitDemoPosDdi;
2167     uint32_t   splitScreenDemoParameters = splitDemoParaDdi;
2168     uint32_t   ufSplitScreenDemoPosition   = 0;
2169     uint32_t   ufSplitScreenDemoParameters = 0;
2170     MediaUserSettingSharedPtr userSetting  = nullptr;
2171     DDI_VP_FUNC_ENTER;
2172     //--------------------------
2173     // Set Demo Mode Parameters
2174     //--------------------------
2175     if (*splitScreenDemoModeParams == nullptr)
2176     {
2177         *splitScreenDemoModeParams = (PVPHAL_SPLIT_SCREEN_DEMO_MODE_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_SPLIT_SCREEN_DEMO_MODE_PARAMS));
2178         DDI_VP_CHK_NULL(*splitScreenDemoModeParams, "nullptr *splitScreenDemoModeParams!", MOS_STATUS_NULL_POINTER);
2179     }
2180 
2181 #if (_DEBUG || _RELEASE_INTERNAL)
2182     // If it is not enabled from DDI params, check if internal user feature key have settings
2183     if (splitScreenDemoPosition == SPLIT_SCREEN_DEMO_DISABLED && splitScreenDemoParameters == 0)
2184     {
2185         DDI_VP_CHK_NULL(osInterface, "nullptr osInterface", MOS_STATUS_NULL_POINTER);
2186         userSetting = osInterface->pfnGetUserSettingInstance(osInterface);
2187         ReadUserSettingForDebug(
2188             userSetting,
2189             ufSplitScreenDemoPosition,
2190             __MEDIA_USER_FEATURE_VALUE_SPLIT_SCREEN_DEMO_POSITION,
2191             MediaUserSetting::Group::Device);
2192         splitScreenDemoPosition = ufSplitScreenDemoPosition;
2193 
2194         ReadUserSettingForDebug(
2195             userSetting,
2196             ufSplitScreenDemoParameters,
2197             __MEDIA_USER_FEATURE_VALUE_SPLIT_SCREEN_DEMO_PARAMETERS,
2198             MediaUserSetting::Group::Device);
2199         splitScreenDemoParameters = ufSplitScreenDemoParameters;
2200     }
2201 #endif
2202 
2203     if ((splitScreenDemoPosition > SPLIT_SCREEN_DEMO_DISABLED) && (splitScreenDemoPosition < SPLIT_SCREEN_DEMO_END_POS_LIST))
2204     {
2205         (*splitScreenDemoModeParams)->Position        = (VPHAL_SPLIT_SCREEN_DEMO_POSITION)(splitScreenDemoPosition);
2206         (*splitScreenDemoModeParams)->bDisableACE     = (bool)((splitScreenDemoParameters & 0x0001) > 0);
2207         (*splitScreenDemoModeParams)->bDisableAVS     = (bool)((splitScreenDemoParameters & 0x0002) > 0);
2208         (*splitScreenDemoModeParams)->bDisableDN      = (bool)((splitScreenDemoParameters & 0x0004) > 0);
2209         (*splitScreenDemoModeParams)->bDisableFMD     = (bool)((splitScreenDemoParameters & 0x0008) > 0);
2210         (*splitScreenDemoModeParams)->bDisableIEF     = (bool)((splitScreenDemoParameters & 0x0010) > 0);
2211         (*splitScreenDemoModeParams)->bDisableProcamp = (bool)((splitScreenDemoParameters & 0x0020) > 0);
2212         (*splitScreenDemoModeParams)->bDisableSTE     = (bool)((splitScreenDemoParameters & 0x0040) > 0);
2213         (*splitScreenDemoModeParams)->bDisableTCC     = (bool)((splitScreenDemoParameters & 0x0080) > 0);
2214         (*splitScreenDemoModeParams)->bDisableIS      = (bool)((splitScreenDemoParameters & 0x0100) > 0);
2215         (*splitScreenDemoModeParams)->bDisableDrDb    = (bool)((splitScreenDemoParameters & 0x0200) > 0);
2216         (*splitScreenDemoModeParams)->bDisableDNUV    = (bool)((splitScreenDemoParameters & 0x0400) > 0);
2217         (*splitScreenDemoModeParams)->bDisableFRC     = (bool)((splitScreenDemoParameters & 0x0800) > 0);
2218         (*splitScreenDemoModeParams)->bDisableLACE    = (bool)((splitScreenDemoParameters & 0x1000) > 0);
2219         *disableDemoMode                              = false;
2220     }
2221     else
2222     {
2223         *disableDemoMode = true;
2224     }
2225 
2226     return eStatus;
2227 }
2228 
DdiUpdateProcPipelineFutureReferenceFrames(PDDI_VP_CONTEXT vpCtx,VADriverContextP vaDrvCtx,PVPHAL_SURFACE vpHalSrcSurf,VAProcPipelineParameterBuffer * pipelineParam)2229 VAStatus DdiVpFunctions::DdiUpdateProcPipelineFutureReferenceFrames(
2230     PDDI_VP_CONTEXT               vpCtx,
2231     VADriverContextP              vaDrvCtx,
2232     PVPHAL_SURFACE                vpHalSrcSurf,
2233     VAProcPipelineParameterBuffer *pipelineParam)
2234 {
2235     PVPHAL_SURFACE       surface        = nullptr;
2236     PDDI_MEDIA_SURFACE   refSurfBuffObj = nullptr;
2237     PDDI_MEDIA_CONTEXT   mediaCtx       = nullptr;
2238 
2239     DDI_VP_FUNC_ENTER;
2240     DDI_VP_CHK_NULL(vpCtx,         "nullptr vpCtx!",         VA_STATUS_ERROR_INVALID_CONTEXT);
2241     DDI_VP_CHK_NULL(vaDrvCtx,      "nullptr vaDrvCtx!",      VA_STATUS_ERROR_INVALID_CONTEXT);
2242     DDI_VP_CHK_NULL(vpHalSrcSurf,  "nullptr vpHalSrcSurf!",  VA_STATUS_ERROR_INVALID_PARAMETER);
2243     DDI_VP_CHK_NULL(pipelineParam, "nullptr pipelineParam!", VA_STATUS_ERROR_INVALID_PARAMETER);
2244 
2245     // initialize
2246     mediaCtx = GetMediaContext(vaDrvCtx);
2247     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx!", VA_STATUS_ERROR_INVALID_CONTEXT);
2248 
2249     surface = vpHalSrcSurf;
2250     if (!pipelineParam->backward_references)
2251     {
2252         DDI_VP_NORMALMESSAGE("nullptr pipelineParam->forward_references");
2253         return VA_STATUS_SUCCESS;
2254     }
2255 
2256     for (uint32_t i = 0; i < pipelineParam->num_backward_references; i++)
2257     {
2258         if (surface->pFwdRef == nullptr)
2259         {
2260             surface->pFwdRef = MOS_New(VPHAL_SURFACE);
2261             DDI_VP_CHK_NULL(surface->pFwdRef, "nullptr surface->pFwdRef!", VA_STATUS_ERROR_ALLOCATION_FAILED);
2262 
2263             surface->pFwdRef->Format        = vpHalSrcSurf->Format;
2264             surface->pFwdRef->SurfType      = vpHalSrcSurf->SurfType;
2265             surface->pFwdRef->rcSrc         = vpHalSrcSurf->rcSrc;
2266             surface->pFwdRef->rcDst         = vpHalSrcSurf->rcDst;
2267             surface->pFwdRef->ColorSpace    = vpHalSrcSurf->ColorSpace;
2268             surface->pFwdRef->ExtendedGamut = vpHalSrcSurf->ExtendedGamut;
2269             surface->pFwdRef->SampleType    = vpHalSrcSurf->SampleType;
2270             surface->pFwdRef->ScalingMode   = vpHalSrcSurf->ScalingMode;
2271             surface->pFwdRef->OsResource    = vpHalSrcSurf->OsResource;
2272             surface->pFwdRef->dwWidth       = vpHalSrcSurf->dwWidth;
2273             surface->pFwdRef->dwHeight      = vpHalSrcSurf->dwHeight;
2274             surface->pFwdRef->dwPitch       = vpHalSrcSurf->dwPitch;
2275             surface->uFwdRefCount           = pipelineParam->num_backward_references - i;
2276         }
2277         refSurfBuffObj = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, pipelineParam->backward_references[i]);
2278         DDI_VP_CHK_NULL(refSurfBuffObj, "nullptr refSurfBuffObj!", VA_STATUS_ERROR_INVALID_SURFACE);
2279 
2280         surface->pFwdRef->OsResource.bo          = refSurfBuffObj->bo;
2281         surface->pFwdRef->OsResource.Format      = MediaLibvaUtilNext::GetFormatFromMediaFormat(refSurfBuffObj->format);
2282         surface->pFwdRef->OsResource.iWidth      = refSurfBuffObj->iWidth;
2283         surface->pFwdRef->OsResource.iHeight     = refSurfBuffObj->iHeight;
2284         surface->pFwdRef->OsResource.iPitch      = refSurfBuffObj->iPitch;
2285         surface->pFwdRef->OsResource.TileType    = MediaLibvaUtilNext::GetTileTypeFromMediaTileType(refSurfBuffObj->TileType);
2286         surface->pFwdRef->OsResource.pGmmResInfo = refSurfBuffObj->pGmmResourceInfo;
2287 
2288         Mos_Solo_SetOsResource(refSurfBuffObj->pGmmResourceInfo, &surface->OsResource);
2289 
2290         surface->pFwdRef->FrameID = refSurfBuffObj->frame_idx;
2291         surface = surface->pFwdRef;
2292     }
2293 
2294     return VA_STATUS_SUCCESS;
2295 }
2296 
DdiUpdateProcPipelinePastReferenceFrames(PDDI_VP_CONTEXT vpCtx,VADriverContextP vaDrvCtx,PVPHAL_SURFACE vpHalSrcSurf,VAProcPipelineParameterBuffer * pipelineParam)2297 VAStatus DdiVpFunctions::DdiUpdateProcPipelinePastReferenceFrames(
2298     PDDI_VP_CONTEXT               vpCtx,
2299     VADriverContextP              vaDrvCtx,
2300     PVPHAL_SURFACE                vpHalSrcSurf,
2301     VAProcPipelineParameterBuffer *pipelineParam)
2302 {
2303     PVPHAL_SURFACE       surface        = nullptr;
2304     PDDI_MEDIA_SURFACE   refSurfBuffObj = nullptr;
2305     PDDI_MEDIA_CONTEXT   mediaCtx       = nullptr;
2306 
2307     DDI_VP_FUNC_ENTER;
2308     DDI_VP_CHK_NULL(vpCtx,         "nullptr vpCtx!",         VA_STATUS_ERROR_INVALID_CONTEXT);
2309     DDI_VP_CHK_NULL(vaDrvCtx,      "nullptr vaDrvCtx!",      VA_STATUS_ERROR_INVALID_CONTEXT);
2310     DDI_VP_CHK_NULL(vpHalSrcSurf,  "nullptr vpHalSrcSurf!",  VA_STATUS_ERROR_INVALID_PARAMETER);
2311     DDI_VP_CHK_NULL(pipelineParam, "nullptr pipelineParam!", VA_STATUS_ERROR_INVALID_PARAMETER);
2312 
2313     // initialize
2314     mediaCtx = GetMediaContext(vaDrvCtx);
2315     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx!", VA_STATUS_ERROR_INVALID_CONTEXT);
2316 
2317     surface = vpHalSrcSurf;
2318     if(!pipelineParam->forward_references)
2319     {
2320         DDI_VP_NORMALMESSAGE("nullptr pipelineParam->backward_references");
2321         return VA_STATUS_SUCCESS;
2322     }
2323 
2324     for (uint32_t i = 0; i < pipelineParam->num_forward_references; i++)
2325     {
2326         if (surface->pBwdRef == nullptr)
2327         {
2328             surface->pBwdRef = MOS_New(VPHAL_SURFACE);
2329             DDI_VP_CHK_NULL(surface->pBwdRef, "nullptr surface->pBwdRef!", VA_STATUS_ERROR_ALLOCATION_FAILED);
2330 
2331             surface->pBwdRef->Format        = vpHalSrcSurf->Format;
2332             surface->pBwdRef->SurfType      = vpHalSrcSurf->SurfType;
2333             surface->pBwdRef->rcSrc         = vpHalSrcSurf->rcSrc;
2334             surface->pBwdRef->rcDst         = vpHalSrcSurf->rcDst;
2335             surface->pBwdRef->ColorSpace    = vpHalSrcSurf->ColorSpace;
2336             surface->pBwdRef->ExtendedGamut = vpHalSrcSurf->ExtendedGamut;
2337             surface->pBwdRef->SampleType    = vpHalSrcSurf->SampleType;
2338             surface->pBwdRef->ScalingMode   = vpHalSrcSurf->ScalingMode;
2339             surface->pBwdRef->OsResource    = vpHalSrcSurf->OsResource;
2340             surface->pBwdRef->dwWidth       = vpHalSrcSurf->dwWidth;
2341             surface->pBwdRef->dwHeight      = vpHalSrcSurf->dwHeight;
2342             surface->pBwdRef->dwPitch       = vpHalSrcSurf->dwPitch;
2343             surface->uBwdRefCount           = pipelineParam->num_forward_references - i;
2344         }
2345         refSurfBuffObj = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, pipelineParam->forward_references[i]);
2346         DDI_VP_CHK_NULL(refSurfBuffObj, "nullptr refSurfBuffObj!", VA_STATUS_ERROR_INVALID_SURFACE);
2347 
2348         surface->pBwdRef->OsResource.bo          = refSurfBuffObj->bo;
2349         surface->pBwdRef->OsResource.Format      = MediaLibvaUtilNext::GetFormatFromMediaFormat(refSurfBuffObj->format);
2350         surface->pBwdRef->OsResource.iWidth      = refSurfBuffObj->iWidth;
2351         surface->pBwdRef->OsResource.iHeight     = refSurfBuffObj->iHeight;
2352         surface->pBwdRef->OsResource.iPitch      = refSurfBuffObj->iPitch;
2353         surface->pBwdRef->OsResource.TileType    = MediaLibvaUtilNext::GetTileTypeFromMediaTileType(refSurfBuffObj->TileType);
2354         surface->pBwdRef->OsResource.pGmmResInfo = refSurfBuffObj->pGmmResourceInfo;
2355 
2356         Mos_Solo_SetOsResource(refSurfBuffObj->pGmmResourceInfo, &surface->OsResource);
2357 
2358         surface->pBwdRef->FrameID = refSurfBuffObj->frame_idx;
2359         surface = surface->pBwdRef;
2360     }
2361 
2362     return VA_STATUS_SUCCESS;
2363 }
2364 
DdiUpdateFilterParamBuffer(VADriverContextP vaDrvCtx,PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,int32_t filterType,void * data,uint32_t elementNum,DDI_VP_STATE * vpStateFlags)2365 VAStatus DdiVpFunctions::DdiUpdateFilterParamBuffer(
2366     VADriverContextP vaDrvCtx,
2367     PDDI_VP_CONTEXT  vpCtx,
2368     uint32_t         surfIndex,
2369     int32_t          filterType,
2370     void             *data,
2371     uint32_t         elementNum,
2372     DDI_VP_STATE     *vpStateFlags)
2373 {
2374     VAStatus vaStatus = VA_STATUS_SUCCESS;
2375     DDI_VP_FUNC_ENTER;
2376     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2377     DDI_VP_CHK_NULL(vpStateFlags, "nullptr vpStateFlags.", VA_STATUS_ERROR_INVALID_PARAMETER);
2378 
2379     switch (filterType)
2380     {
2381     case VAProcFilterDeinterlacing:
2382         vpStateFlags->bDeinterlaceEnable = true;
2383         vaStatus                         = DdiSetProcFilterDinterlaceParams(vpCtx, surfIndex, (VAProcFilterParameterBufferDeinterlacing *)data);
2384         break;
2385     case VAProcFilterNoiseReduction:
2386         vpStateFlags->bDenoiseEnable = true;
2387         vaStatus                     = DdiSetProcFilterDenoiseParams(vpCtx, surfIndex, (VAProcFilterParameterBuffer *)data);
2388         break;
2389     case VAProcFilterHVSNoiseReduction:
2390         vpStateFlags->bDenoiseEnable = true;
2391         vaStatus                     = DdiSetProcFilterHVSDenoiseParams(vpCtx, surfIndex, (VAProcFilterParameterBufferHVSNoiseReduction *)data);
2392         break;
2393     case VAProcFilterSharpening:
2394         vpStateFlags->bIEFEnable = true;
2395         vaStatus                 = DdiSetProcFilterSharpnessParams(vpCtx, surfIndex, (VAProcFilterParameterBuffer *)data);
2396         break;
2397     case VAProcFilterColorBalance:
2398         vpStateFlags->bProcampEnable = true;
2399         vaStatus                     = DdiSetProcFilterColorBalanceParams(vpCtx, surfIndex, (VAProcFilterParameterBufferColorBalance *)data, elementNum);
2400         break;
2401     case VAProcFilterSkinToneEnhancement:
2402         vaStatus = DdiSetProcFilterSkinToneEnhancementParams(vpCtx, surfIndex, (VAProcFilterParameterBuffer *)data);
2403         break;
2404     case VAProcFilterTotalColorCorrection:
2405         vaStatus = DdiSetProcFilterTotalColorCorrectionParams(vpCtx, surfIndex, (VAProcFilterParameterBufferTotalColorCorrection *)data, elementNum);
2406         break;
2407     case VAProcFilterHighDynamicRangeToneMapping:
2408         vaStatus = DdiSetProcFilterHdrTmParams(vpCtx, surfIndex, (VAProcFilterParameterBufferHDRToneMapping *)data);
2409         break;
2410 #if VA_CHECK_VERSION(1, 12, 0)
2411     case VAProcFilter3DLUT:
2412         vaStatus = DdiSetProcFilter3DLutParams(vaDrvCtx, vpCtx, surfIndex, (VAProcFilterParameterBuffer3DLUT *)data);
2413         break;
2414 #endif
2415     case VAProcFilterNone:
2416         vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
2417         break;
2418     default:
2419         DDI_VP_ASSERTMESSAGE("VAProcFilterType is unknown.");
2420         vaStatus = VA_STATUS_ERROR_UNSUPPORTED_FILTER;
2421         break;
2422     }  // switch (type)
2423 
2424     return vaStatus;
2425 }
2426 
DdiSetProcFilterDinterlaceParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBufferDeinterlacing * diParamBuff)2427 VAStatus DdiVpFunctions::DdiSetProcFilterDinterlaceParams(
2428     PDDI_VP_CONTEXT                          vpCtx,
2429     uint32_t                                 surfIndex,
2430     VAProcFilterParameterBufferDeinterlacing *diParamBuff)
2431 {
2432     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
2433     PVPHAL_SURFACE       targetSurf        = nullptr;
2434     PVPHAL_SURFACE       srcSurf           = nullptr;
2435     VPHAL_DI_MODE        diMode;
2436 
2437     DDI_VP_FUNC_ENTER;
2438     DDI_VP_CHK_NULL(vpCtx,       "nullptr vpCtx.",       VA_STATUS_ERROR_INVALID_CONTEXT);
2439     DDI_VP_CHK_NULL(diParamBuff, "nullptr diParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
2440 
2441     // initialize
2442     vpHalRenderParams = VpGetRenderParams(vpCtx);
2443     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2444 
2445     srcSurf = vpHalRenderParams->pSrc[surfIndex];
2446     DDI_VP_CHK_NULL(srcSurf, "nullptr srcSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
2447     targetSurf = vpHalRenderParams->pTarget[0];
2448     DDI_VP_CHK_NULL(targetSurf, "nullptr targetSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
2449 
2450     switch (diParamBuff->algorithm)
2451     {
2452     case VAProcDeinterlacingBob:
2453         diMode = DI_MODE_BOB;
2454         break;
2455     case VAProcDeinterlacingMotionAdaptive:
2456     case VAProcDeinterlacingMotionCompensated:
2457         diMode = DI_MODE_ADI;
2458         break;
2459     case VAProcDeinterlacingWeave:
2460         srcSurf->bFieldWeaving = true;
2461         return VA_STATUS_SUCCESS;
2462     case VAProcDeinterlacingNone:
2463         return VA_STATUS_SUCCESS;
2464     default:
2465         DDI_VP_ASSERTMESSAGE("Deinterlacing type is unsupported.");
2466         return VA_STATUS_ERROR_UNIMPLEMENTED;
2467     }  // switch (diParamBuff->algorithm)
2468 
2469     if (nullptr == srcSurf->pDeinterlaceParams)
2470     {
2471         srcSurf->pDeinterlaceParams = MOS_New(VPHAL_DI_PARAMS);
2472         DDI_VP_CHK_NULL(srcSurf->pDeinterlaceParams, "srcSurf->pDeinterlaceParams is nullptr", VA_STATUS_ERROR_ALLOCATION_FAILED);
2473     }
2474 
2475     if (nullptr == targetSurf->pDeinterlaceParams)
2476     {
2477         targetSurf->pDeinterlaceParams = MOS_New(VPHAL_DI_PARAMS);
2478         DDI_VP_CHK_NULL(targetSurf->pDeinterlaceParams, "targetSurf->pDeinterlaceParams is nullptr", VA_STATUS_ERROR_ALLOCATION_FAILED);
2479     }
2480     //application detect scene change and then pass parameter to driver.
2481     if (diParamBuff->flags & VA_DEINTERLACING_SCD_ENABLE)
2482     {
2483         diMode                                  = DI_MODE_BOB;
2484         srcSurf->pDeinterlaceParams->bSCDEnable = true;
2485     }
2486     else
2487     {
2488         srcSurf->pDeinterlaceParams->bSCDEnable = false;
2489     }
2490 
2491     srcSurf->pDeinterlaceParams->DIMode       = diMode;
2492     srcSurf->pDeinterlaceParams->bSingleField = (diParamBuff->flags & VA_DEINTERLACING_ONE_FIELD) ? true : false;
2493     srcSurf->pDeinterlaceParams->bEnableFMD   = (diParamBuff->flags & VA_DEINTERLACING_FMD_ENABLE) ? true : false;
2494 
2495     //update sample type
2496     UpdateSampleType(srcSurf, diParamBuff->flags);
2497 
2498     if (srcSurf->pDeinterlaceParams->DIMode != DI_MODE_ADI)
2499     {
2500         return VA_STATUS_SUCCESS;
2501     }
2502 
2503     //When pBwdRef is not nullptr and uBwdRefCount is nonzero, ADI can use Bwd Ref frame.
2504     //Otherwise, ADI shouldn't use Bwd Ref frame.
2505     if (srcSurf->uBwdRefCount && srcSurf->pBwdRef != nullptr)
2506     {
2507         SetFrameID(vpCtx, srcSurf);
2508     }
2509     else
2510     {
2511         //ADI no reference frame driver only care EVEN/ODD
2512         if (diParamBuff->flags & VA_DEINTERLACING_BOTTOM_FIELD)
2513         {
2514             srcSurf->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
2515         }
2516         else
2517         {
2518             srcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
2519         }
2520     }
2521 
2522     //int32_t overflow process
2523     vpCtx->FrameIDTracer.uiFrameIndex = (vpCtx->FrameIDTracer.uiFrameIndex + 1 == INT_MAX) ? 1 : vpCtx->FrameIDTracer.uiFrameIndex + 1;
2524 
2525     return VA_STATUS_SUCCESS;
2526 }
2527 
VpSetColorSpaceByDefault(PVPHAL_SURFACE vpHalSurf)2528 void DdiVpFunctions::VpSetColorSpaceByDefault(PVPHAL_SURFACE  vpHalSurf)
2529 {
2530     DDI_VP_FUNC_ENTER;
2531     DDI_VP_CHK_NULL(vpHalSurf, "nullptr vpHalSurf.", );
2532 
2533     if ((vpHalSurf->rcSrc.right - vpHalSurf->rcSrc.left) <= 1280 && (vpHalSurf->rcSrc.bottom - vpHalSurf->rcSrc.top) <= 720)
2534     {
2535         vpHalSurf->ColorSpace = CSpace_BT601;
2536     }  //720p
2537     else if ((vpHalSurf->rcSrc.right - vpHalSurf->rcSrc.left) <= 1920 && (vpHalSurf->rcSrc.bottom - vpHalSurf->rcSrc.top) <= 1080)
2538     {
2539         vpHalSurf->ColorSpace = CSpace_BT709;
2540     }  //1080p
2541     else
2542     {
2543         if (vpHalSurf->Format == Format_P010 || vpHalSurf->Format == Format_P016)
2544         {
2545             vpHalSurf->ColorSpace = CSpace_BT2020;
2546         }
2547         else
2548         {
2549             vpHalSurf->ColorSpace = CSpace_BT709;
2550         }
2551     }  //4K
2552     return;
2553 }
2554 
VpSetColorSpaceByColorStandard(PVPHAL_SURFACE vpHalSurf,VAProcColorStandardType colorStandard,VAProcColorProperties colorProperties,uint8_t colorRange)2555 void DdiVpFunctions::VpSetColorSpaceByColorStandard(
2556     PVPHAL_SURFACE          vpHalSurf,
2557     VAProcColorStandardType colorStandard,
2558     VAProcColorProperties   colorProperties,
2559     uint8_t                 colorRange)
2560 {
2561     DDI_VP_FUNC_ENTER;
2562     DDI_VP_CHK_NULL(vpHalSurf, "nullptr vpHalSurf.", );
2563 
2564     switch (colorStandard)
2565             {
2566             case VAProcColorStandardBT709:
2567 #if (VA_MAJOR_VERSION < 1)
2568                 if (flag & VA_SOURCE_RANGE_FULL)
2569 #else
2570                 if (colorRange == VA_SOURCE_RANGE_FULL)
2571 #endif
2572                 {
2573                     vpHalSurf->ColorSpace = CSpace_BT709_FullRange;
2574                 }
2575                 else
2576                 {
2577                     vpHalSurf->ColorSpace = CSpace_BT709;
2578                 }
2579                 break;
2580             case VAProcColorStandardBT601:
2581 #if (VA_MAJOR_VERSION < 1)
2582                 if (flag & VA_SOURCE_RANGE_FULL)
2583 #else
2584                 if (colorRange == VA_SOURCE_RANGE_FULL)
2585 #endif
2586                 {
2587                     vpHalSurf->ColorSpace = CSpace_BT601_FullRange;
2588                 }
2589                 else
2590                 {
2591                     vpHalSurf->ColorSpace = CSpace_BT601;
2592                 }
2593                 break;
2594             case VAProcColorStandardBT2020:
2595 #if (VA_MAJOR_VERSION < 1)
2596                 if (flag & VA_SOURCE_RANGE_FULL)
2597 #else
2598                 if (colorRange == VA_SOURCE_RANGE_FULL)
2599 #endif
2600                 {
2601                     vpHalSurf->ColorSpace = CSpace_BT2020_FullRange;
2602                 }
2603                 else
2604                 {
2605                     vpHalSurf->ColorSpace = CSpace_BT2020;
2606                 }
2607                 break;
2608             case VAProcColorStandardBT470M:
2609             case VAProcColorStandardBT470BG:
2610             case VAProcColorStandardSMPTE170M:
2611             case VAProcColorStandardSMPTE240M:
2612             case VAProcColorStandardGenericFilm:
2613             case VAProcColorStandardXVYCC601:
2614             case VAProcColorStandardXVYCC709:
2615                 vpHalSurf->ColorSpace = CSpace_None;
2616                 break;
2617             case VAProcColorStandardExplicit:
2618                 VpSetColorStandardExplictly(vpHalSurf, colorStandard, colorProperties);
2619                 break;
2620             default:
2621                 vpHalSurf->ColorSpace = CSpace_BT601;
2622                 break;
2623             }
2624     return;
2625 }
2626 
UpdateSampleType(PVPHAL_SURFACE srcSurf,uint32_t flags)2627 void DdiVpFunctions::UpdateSampleType(
2628     PVPHAL_SURFACE srcSurf,
2629     uint32_t       flags)
2630 {
2631     DDI_VP_FUNC_ENTER;
2632     DDI_VP_CHK_NULL(srcSurf, "nullptr srcSurf.", );
2633     if (flags & VA_DEINTERLACING_BOTTOM_FIELD_FIRST)
2634     {
2635         if (flags & VA_DEINTERLACING_BOTTOM_FIELD)
2636         {
2637             srcSurf->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
2638         }
2639         else
2640         {
2641             srcSurf->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_TOP_FIELD;
2642         }
2643     }
2644     else
2645     {
2646         if (flags & VA_DEINTERLACING_BOTTOM_FIELD)
2647         {
2648             srcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD;
2649         }
2650         else
2651         {
2652             srcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
2653         }
2654     }
2655     return;
2656 }
2657 
SetFrameID(PDDI_VP_CONTEXT vpCtx,PVPHAL_SURFACE srcSurf)2658 void DdiVpFunctions::SetFrameID(PDDI_VP_CONTEXT vpCtx, PVPHAL_SURFACE srcSurf)
2659 {
2660     DDI_VP_FUNC_ENTER;
2661     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", );
2662     DDI_VP_CHK_NULL(srcSurf, "nullptr srcSurf.", );
2663 
2664     srcSurf->uBwdRefCount = 1;
2665 
2666     //When the bo of the current frame's SRC and reference are same with previous frame's,
2667     //we should set the frame ID same as previous frame's setting.
2668     if (vpCtx->FrameIDTracer.pLastSrcSurfBo == srcSurf->OsResource.bo &&
2669         vpCtx->FrameIDTracer.pLastBwdSurfBo == srcSurf->pBwdRef->OsResource.bo &&
2670         vpCtx->FrameIDTracer.uiLastSampleType != srcSurf->SampleType)
2671     {
2672         srcSurf->FrameID          = vpCtx->FrameIDTracer.uiLastSrcSurfFrameID;
2673         srcSurf->pBwdRef->FrameID = vpCtx->FrameIDTracer.uiLastBwdSurfFrameID;
2674     }
2675     //Otherwise, we should update the values of frame ID and FrameID tracer.
2676     else
2677     {
2678         srcSurf->pBwdRef->FrameID = (VP_SETTING_SAME_SAMPLE_THRESHOLD + 1) * vpCtx->FrameIDTracer.uiFrameIndex;
2679         srcSurf->FrameID          = srcSurf->pBwdRef->FrameID + (VP_SETTING_SAME_SAMPLE_THRESHOLD + 1);
2680 
2681         vpCtx->FrameIDTracer.pLastSrcSurfBo = srcSurf->OsResource.bo;
2682         vpCtx->FrameIDTracer.pLastBwdSurfBo = srcSurf->pBwdRef->OsResource.bo;
2683 
2684         vpCtx->FrameIDTracer.uiLastSrcSurfFrameID = srcSurf->FrameID;
2685         vpCtx->FrameIDTracer.uiLastBwdSurfFrameID = srcSurf->pBwdRef->FrameID;
2686         vpCtx->FrameIDTracer.uiLastSampleType     = srcSurf->SampleType;
2687     }
2688     return;
2689 }
2690 
DdiSetProcFilterDenoiseParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBuffer * dnParamBuff)2691 VAStatus DdiVpFunctions::DdiSetProcFilterDenoiseParams(
2692     PDDI_VP_CONTEXT             vpCtx,
2693     uint32_t                    surfIndex,
2694     VAProcFilterParameterBuffer *dnParamBuff)
2695 {
2696     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
2697     PVPHAL_SURFACE       src               = nullptr;
2698 
2699     DDI_VP_FUNC_ENTER;
2700     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2701 
2702     // initialize
2703     vpHalRenderParams = VpGetRenderParams(vpCtx);
2704     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2705     src = vpHalRenderParams->pSrc[surfIndex];
2706     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
2707 
2708     if (nullptr == src->pDenoiseParams)
2709     {
2710         src->pDenoiseParams = MOS_New(VPHAL_DENOISE_PARAMS);
2711     }
2712     DDI_VP_CHK_NULL(src->pDenoiseParams, "MOS_New pDenoiseParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2713 
2714     // denoise caps range is from 0 to 64, out of range parameter is treated as an error
2715     if (dnParamBuff->value < NOISEREDUCTION_MIN || dnParamBuff->value > NOISEREDUCTION_MAX)
2716     {
2717         return VA_STATUS_ERROR_INVALID_PARAMETER;
2718     }
2719 
2720     src->pDenoiseParams->fDenoiseFactor = dnParamBuff->value;
2721 
2722     // Luma and chroma denoise should be always enabled when noise reduction is needed
2723     src->pDenoiseParams->bEnableLuma   = true;
2724     src->pDenoiseParams->bEnableChroma = true;
2725     src->pDenoiseParams->bAutoDetect   = false;
2726     src->pDenoiseParams->NoiseLevel    = NOISELEVEL_DEFAULT;
2727 
2728     return VA_STATUS_SUCCESS;
2729 }
2730 
DdiSetProcFilterHVSDenoiseParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBufferHVSNoiseReduction * hvsDnParamBuff)2731 VAStatus DdiVpFunctions::DdiSetProcFilterHVSDenoiseParams(
2732     PDDI_VP_CONTEXT                              vpCtx,
2733     uint32_t                                     surfIndex,
2734     VAProcFilterParameterBufferHVSNoiseReduction *hvsDnParamBuff)
2735 {
2736     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
2737     PVPHAL_SURFACE       src              = nullptr;
2738 
2739     DDI_VP_FUNC_ENTER;
2740     DDI_VP_CHK_NULL(vpCtx,          "nullptr vpCtx.",          VA_STATUS_ERROR_INVALID_CONTEXT);
2741     DDI_VP_CHK_NULL(hvsDnParamBuff, "nullptr hvsDnParamBuff.", VA_STATUS_ERROR_INVALID_PARAMETER);
2742 
2743     // initialize
2744     vpHalRenderParams = VpGetRenderParams(vpCtx);
2745     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2746     src = vpHalRenderParams->pSrc[surfIndex];
2747     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
2748 
2749     if (nullptr == src->pDenoiseParams)
2750     {
2751         src->pDenoiseParams = MOS_New(VPHAL_DENOISE_PARAMS);
2752     }
2753     DDI_VP_CHK_NULL(src->pDenoiseParams, "MOS_New pDenoiseParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2754 
2755     // Luma and chroma denoise should be always enabled when noise reduction is needed
2756     src->pDenoiseParams->bEnableLuma        = true;
2757     src->pDenoiseParams->bEnableChroma      = true;
2758     src->pDenoiseParams->bEnableHVSDenoise  = true;
2759 
2760     SetHVSDnParams(hvsDnParamBuff, src->pDenoiseParams);
2761 
2762     DDI_VP_NORMALMESSAGE("HVS Denoise is enabled with qp %d, strength %d, mode %d!", src->pDenoiseParams->HVSDenoise.QP, src->pDenoiseParams->HVSDenoise.Strength, src->pDenoiseParams->HVSDenoise.Mode);
2763 
2764     return VA_STATUS_SUCCESS;
2765 }
2766 
SetHVSDnParams(VAProcFilterParameterBufferHVSNoiseReduction * hvsDnParamBuff,PVPHAL_DENOISE_PARAMS denoiseParams)2767 void DdiVpFunctions::SetHVSDnParams(
2768     VAProcFilterParameterBufferHVSNoiseReduction *hvsDnParamBuff,
2769     PVPHAL_DENOISE_PARAMS                        denoiseParams)
2770 {
2771     DDI_VP_FUNC_ENTER;
2772     DDI_VP_CHK_NULL(hvsDnParamBuff, "nullptr vpCtx.",);
2773     DDI_VP_CHK_NULL(denoiseParams,  "nullptr hvsDnParamBuff.", );
2774 
2775     switch (hvsDnParamBuff->mode)
2776     {
2777     case VA_PROC_HVS_DENOISE_AUTO_SUBJECTIVE:
2778         denoiseParams->HVSDenoise.Mode = HVSDENOISE_AUTO_SUBJECTIVE;
2779         denoiseParams->bAutoDetect     = true;
2780         break;
2781     case VA_PROC_HVS_DENOISE_MANUAL:
2782         denoiseParams->HVSDenoise.Mode = HVSDENOISE_MANUAL;
2783         break;
2784     case VA_PROC_HVS_DENOISE_DEFAULT:
2785     case VA_PROC_HVS_DENOISE_AUTO_BDRATE:
2786     default:
2787         denoiseParams->HVSDenoise.Mode = HVSDENOISE_AUTO_BDRATE;
2788         denoiseParams->bAutoDetect     = true;
2789     }  // switch (hvsDnParamBuff->mode)
2790 
2791     if (denoiseParams->HVSDenoise.Mode == HVSDENOISE_AUTO_BDRATE)
2792     {
2793         denoiseParams->HVSDenoise.QP = hvsDnParamBuff->qp;
2794         if (denoiseParams->HVSDenoise.QP == 0)
2795         {
2796             //If didn't set value, HVS Auto Bdrate Mode default qp 27
2797             denoiseParams->HVSDenoise.QP = 27;
2798         }
2799     }
2800     else if (denoiseParams->HVSDenoise.Mode == HVSDENOISE_AUTO_SUBJECTIVE)
2801     {
2802         //HVS Subjective Mode default qp 32
2803         denoiseParams->HVSDenoise.QP = 32;
2804     }
2805     else
2806     {
2807         denoiseParams->HVSDenoise.QP       = 32;
2808         denoiseParams->HVSDenoise.Strength = hvsDnParamBuff->strength;
2809     }
2810     return;
2811 }
2812 
VpHalDdiInitIEFParams(PVPHAL_IEF_PARAMS iefParams)2813 MOS_STATUS DdiVpFunctions::VpHalDdiInitIEFParams(
2814     PVPHAL_IEF_PARAMS       iefParams)
2815 {
2816     DDI_VP_FUNC_ENTER;
2817     DDI_VP_CHK_NULL(iefParams, "nullptr iefParams", MOS_STATUS_INVALID_PARAMETER);
2818 
2819     // Init default values for flows where user feature key is not available or used
2820     iefParams->bSkintoneTuned        = true;
2821     iefParams->bEmphasizeSkinDetail  = false;
2822     iefParams->bSmoothMode           = false;
2823     iefParams->StrongEdgeWeight      = IEF_STRONG_EDGE_WEIGHT;
2824     iefParams->RegularWeight         = IEF_REGULAR_WEIGHT;
2825     iefParams->StrongEdgeThreshold   = IEF_STRONG_EDGE_THRESHOLD;
2826 
2827     return MOS_STATUS_SUCCESS;
2828 }
2829 
DdiSetProcFilterSharpnessParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBuffer * sharpParamBuff)2830 VAStatus DdiVpFunctions::DdiSetProcFilterSharpnessParams(
2831     PDDI_VP_CONTEXT             vpCtx,
2832     uint32_t                    surfIndex,
2833     VAProcFilterParameterBuffer *sharpParamBuff)
2834 {
2835     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
2836     PVPHAL_SURFACE       src               = nullptr;
2837 
2838     DDI_VP_FUNC_ENTER;
2839     DDI_VP_CHK_NULL(vpCtx,          "nullptr vpCtx.",          VA_STATUS_ERROR_INVALID_CONTEXT);
2840     DDI_VP_CHK_NULL(sharpParamBuff, "nullptr sharpParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
2841 
2842     // initialize
2843     vpHalRenderParams = VpGetRenderParams(vpCtx);
2844     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2845     src = vpHalRenderParams->pSrc[surfIndex];
2846     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
2847 
2848     if (nullptr == src->pIEFParams)
2849     {
2850         src->pIEFParams = MOS_New(VPHAL_IEF_PARAMS);
2851         DDI_VP_CHK_NULL(src->pIEFParams, "MOS_New pIEFParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2852     }
2853 
2854     // out of range parameter is treated as an error
2855     if (sharpParamBuff->value < EDGEENHANCEMENT_MIN || sharpParamBuff->value > EDGEENHANCEMENT_MAX)
2856     {
2857         return VA_STATUS_ERROR_INVALID_PARAMETER;
2858     }
2859 
2860     // sharpness option
2861     // setting with hard code in mplayer side.
2862     // refer to sharpening section of render_picture_vp() defined in vaapi.c.
2863     // change flag and factor for testing.
2864     VpHalDdiInitIEFParams(src->pIEFParams);
2865     src->bIEF                    = true;
2866     src->pIEFParams->bEnabled    = true;
2867     src->pIEFParams->fIEFFactor  = sharpParamBuff->value;
2868 
2869     return VA_STATUS_SUCCESS;
2870 }
2871 
DdiSetProcFilterColorBalanceParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBufferColorBalance * colorBalanceParamBuff,uint32_t elementNum)2872 VAStatus DdiVpFunctions::DdiSetProcFilterColorBalanceParams(
2873     PDDI_VP_CONTEXT                         vpCtx,
2874     uint32_t                                surfIndex,
2875     VAProcFilterParameterBufferColorBalance *colorBalanceParamBuff,
2876     uint32_t                                elementNum)
2877 {
2878     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
2879     PVPHAL_SURFACE       src               = nullptr;
2880     bool                 procamp           = false;
2881 
2882     DDI_VP_FUNC_ENTER;
2883     DDI_VP_CHK_NULL(vpCtx,                 "nullptr vpCtx.",                 VA_STATUS_ERROR_INVALID_CONTEXT);
2884     DDI_VP_CHK_NULL(colorBalanceParamBuff, "nullptr colorBalanceParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
2885 
2886     // initialize
2887     vpHalRenderParams = VpGetRenderParams(vpCtx);
2888     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2889     src = vpHalRenderParams->pSrc[surfIndex];
2890     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
2891 
2892     for (uint32_t i = 0; i < elementNum; i++)
2893     {
2894         if ((VAProcColorBalanceHue == colorBalanceParamBuff[i].attrib) ||
2895             (VAProcColorBalanceSaturation == colorBalanceParamBuff[i].attrib) ||
2896             (VAProcColorBalanceBrightness == colorBalanceParamBuff[i].attrib) ||
2897             (VAProcColorBalanceContrast == colorBalanceParamBuff[i].attrib))
2898         {
2899             procamp = true;
2900             break;
2901         }
2902     }
2903 
2904     if (nullptr == src->pProcampParams && true == procamp)
2905     {
2906         src->pProcampParams = MOS_New(VPHAL_PROCAMP_PARAMS);
2907         DDI_VP_CHK_NULL(src->pProcampParams, "MOS_New Source pProcampParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2908     }
2909 
2910     if (nullptr == vpHalRenderParams->pTarget[0]->pProcampParams)
2911     {
2912         vpHalRenderParams->pTarget[0]->pProcampParams = MOS_New(VPHAL_PROCAMP_PARAMS);
2913         DDI_VP_CHK_NULL(vpHalRenderParams->pTarget[0]->pProcampParams, "MOS_New Target pProcampParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2914     }
2915 
2916     // Needed for ACE
2917     if (nullptr == src->pColorPipeParams && SURF_IN_PRIMARY == src->SurfType)
2918     {
2919         src->pColorPipeParams = MOS_New(VPHAL_COLORPIPE_PARAMS);
2920         DDI_VP_CHK_NULL(src->pColorPipeParams, "MOS_New pColorPipeParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2921     }
2922 
2923     // set default value
2924     if (nullptr != src->pProcampParams)
2925     {
2926         src->pProcampParams->fHue         = PROCAMP_HUE_DEFAULT;
2927         src->pProcampParams->fSaturation  = PROCAMP_SATURATION_DEFAULT;
2928         src->pProcampParams->fBrightness  = PROCAMP_BRIGHTNESS_DEFAULT;
2929         src->pProcampParams->fContrast    = PROCAMP_CONTRAST_DEFAULT;
2930     }
2931 
2932     for (uint32_t i = 0; i < elementNum; i++)
2933     {
2934         DDI_CHK_RET(SetColorBalanceParams(colorBalanceParamBuff, i, src, procamp), "Failed to Set ColorBalanceParams.");
2935     }
2936 
2937     return VA_STATUS_SUCCESS;
2938 }
2939 
SetColorBalanceParams(VAProcFilterParameterBufferColorBalance * colorBalanceParamBuff,uint32_t index,PVPHAL_SURFACE src,bool procamp)2940 VAStatus DdiVpFunctions::SetColorBalanceParams(
2941     VAProcFilterParameterBufferColorBalance *colorBalanceParamBuff,
2942     uint32_t                                index,
2943     PVPHAL_SURFACE                          src,
2944     bool                                    procamp)
2945 {
2946     DDI_VP_FUNC_ENTER;
2947     switch (colorBalanceParamBuff[index].attrib)
2948     {
2949         case VAProcColorBalanceHue:
2950         if (colorBalanceParamBuff[index].value < PROCAMP_HUE_MIN || colorBalanceParamBuff[index].value > PROCAMP_HUE_MAX)
2951         {
2952             DDI_VP_ASSERTMESSAGE("%d: Hue is out of bounds.", index);
2953             return VA_STATUS_ERROR_INVALID_PARAMETER;
2954         }
2955         if (true == procamp)
2956         {
2957             src->pProcampParams->bEnabled = true;
2958             src->pProcampParams->fHue     = colorBalanceParamBuff[index].value;
2959         }
2960         break;
2961         case VAProcColorBalanceSaturation:
2962         if (colorBalanceParamBuff[index].value < PROCAMP_SATURATION_MIN || colorBalanceParamBuff[index].value > PROCAMP_SATURATION_MAX)
2963         {
2964             DDI_VP_ASSERTMESSAGE("%d: Saturation is out of bounds.", index);
2965             return VA_STATUS_ERROR_INVALID_PARAMETER;
2966         }
2967         if (true == procamp)
2968         {
2969             src->pProcampParams->bEnabled     = true;
2970             src->pProcampParams->fSaturation = colorBalanceParamBuff[index].value;
2971         }
2972         break;
2973         case VAProcColorBalanceBrightness:
2974         if (colorBalanceParamBuff[index].value < PROCAMP_BRIGHTNESS_MIN || colorBalanceParamBuff[index].value > PROCAMP_BRIGHTNESS_MAX)
2975         {
2976             DDI_VP_ASSERTMESSAGE("%d: Brightness is out of bounds.", index);
2977             return VA_STATUS_ERROR_INVALID_PARAMETER;
2978         }
2979         if (true == procamp)
2980         {
2981             src->pProcampParams->bEnabled     = true;
2982             src->pProcampParams->fBrightness = colorBalanceParamBuff[index].value;
2983         }
2984         break;
2985         case VAProcColorBalanceContrast:
2986         if (colorBalanceParamBuff[index].value < PROCAMP_CONTRAST_MIN || colorBalanceParamBuff[index].value > PROCAMP_CONTRAST_MAX)
2987         {
2988             DDI_VP_ASSERTMESSAGE("%d: Contrast is out of bounds.", index);
2989             return VA_STATUS_ERROR_INVALID_PARAMETER;
2990         }
2991         if (true == procamp)
2992         {
2993             src->pProcampParams->bEnabled   = true;
2994             src->pProcampParams->fContrast = colorBalanceParamBuff[index].value;
2995         }
2996         break;
2997         case VAProcColorBalanceAutoContrast:
2998         if (SURF_IN_PRIMARY == src->SurfType)
2999         {
3000             src->pColorPipeParams->bEnableACE     = true;
3001             src->pColorPipeParams->dwAceLevel     = ACE_LEVEL_DEFAULT;
3002             src->pColorPipeParams->dwAceStrength  = ACE_STRENGTH_DEFAULT;
3003         }
3004         break;
3005         case VAProcColorBalanceAutoSaturation:
3006         case VAProcColorBalanceAutoBrightness:
3007             return VA_STATUS_ERROR_UNIMPLEMENTED;
3008         case VAProcColorBalanceNone:
3009         case VAProcColorBalanceCount:
3010         default:
3011             DDI_VP_ASSERTMESSAGE("colorBalanceParamBuff[%d].attrib is unknown.", index);
3012             return VA_STATUS_ERROR_INVALID_PARAMETER;
3013     }  // switch (attrib)
3014     return VA_STATUS_SUCCESS;
3015 }
3016 
DdiSetProcFilterSkinToneEnhancementParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBuffer * steParamBuff)3017 VAStatus DdiVpFunctions::DdiSetProcFilterSkinToneEnhancementParams(
3018     PDDI_VP_CONTEXT             vpCtx,
3019     uint32_t                    surfIndex,
3020     VAProcFilterParameterBuffer *steParamBuff)
3021 {
3022     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
3023     PVPHAL_SURFACE       src               = nullptr;
3024 
3025     DDI_VP_FUNC_ENTER;
3026     DDI_VP_CHK_NULL(steParamBuff, "Null steParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
3027 
3028     // initialize
3029     vpHalRenderParams = VpGetRenderParams(vpCtx);
3030     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3031     src = vpHalRenderParams->pSrc[surfIndex];
3032     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
3033 
3034     if (SURF_IN_PRIMARY == src->SurfType)
3035     {
3036         if (nullptr == src->pColorPipeParams)
3037         {
3038             src->pColorPipeParams = MOS_New(VPHAL_COLORPIPE_PARAMS);
3039             DDI_VP_CHK_NULL(src->pColorPipeParams, "MOS_New pColorPipeParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3040         }
3041 
3042         // out of range parameter is treated as an error
3043         if (steParamBuff->value < STE_MIN || steParamBuff->value > STE_MAX)
3044         {
3045             return VA_STATUS_ERROR_INVALID_PARAMETER;
3046         }
3047 
3048         src->pColorPipeParams->bEnableSTE            = true;
3049         src->pColorPipeParams->SteParams.dwSTEFactor = (uint32_t)steParamBuff->value;
3050     }
3051 
3052     return VA_STATUS_SUCCESS;
3053 }
3054 
DdiSetProcFilterTotalColorCorrectionParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBufferTotalColorCorrection * tccParamBuff,uint32_t elementNum)3055 VAStatus DdiVpFunctions::DdiSetProcFilterTotalColorCorrectionParams(
3056     PDDI_VP_CONTEXT                                 vpCtx,
3057     uint32_t                                        surfIndex,
3058     VAProcFilterParameterBufferTotalColorCorrection *tccParamBuff,
3059     uint32_t                                        elementNum)
3060 {
3061     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
3062     PVPHAL_SURFACE       src               = nullptr;
3063 
3064     DDI_VP_FUNC_ENTER;
3065     DDI_VP_CHK_NULL(tccParamBuff, "nullptr tccParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
3066 
3067     // initialize
3068     vpHalRenderParams = VpGetRenderParams(vpCtx);
3069     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3070     src = vpHalRenderParams->pSrc[surfIndex];
3071     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
3072 
3073     if (SURF_IN_PRIMARY == src->SurfType)
3074     {
3075         if (nullptr == src->pColorPipeParams)
3076         {
3077             src->pColorPipeParams = MOS_New(VPHAL_COLORPIPE_PARAMS);
3078             DDI_VP_CHK_NULL(src->pColorPipeParams, "MOS_New pColorPipeParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3079         }
3080 
3081         // set default values
3082         src->pColorPipeParams->TccParams.Red      = (uint8_t)TCC_DEFAULT;
3083         src->pColorPipeParams->TccParams.Green    = (uint8_t)TCC_DEFAULT;
3084         src->pColorPipeParams->TccParams.Blue     = (uint8_t)TCC_DEFAULT;
3085         src->pColorPipeParams->TccParams.Cyan     = (uint8_t)TCC_DEFAULT;
3086         src->pColorPipeParams->TccParams.Magenta  = (uint8_t)TCC_DEFAULT;
3087         src->pColorPipeParams->TccParams.Yellow   = (uint8_t)TCC_DEFAULT;
3088 
3089         for (uint32_t i = 0; i < elementNum; i++)
3090         {
3091             if (tccParamBuff[i].value < TCC_MIN || tccParamBuff[i].value > TCC_MAX)
3092             {
3093                 return VA_STATUS_ERROR_INVALID_PARAMETER;
3094             }
3095 
3096             src->pColorPipeParams->bEnableTCC = true;
3097 
3098             switch (tccParamBuff[i].attrib)
3099             {
3100             case VAProcTotalColorCorrectionRed:
3101                 src->pColorPipeParams->TccParams.Red = (uint8_t)tccParamBuff[i].value;
3102                 break;
3103 
3104             case VAProcTotalColorCorrectionGreen:
3105                 src->pColorPipeParams->TccParams.Green = (uint8_t)tccParamBuff[i].value;
3106                 break;
3107 
3108             case VAProcTotalColorCorrectionBlue:
3109                 src->pColorPipeParams->TccParams.Blue = (uint8_t)tccParamBuff[i].value;
3110                 break;
3111 
3112             case VAProcTotalColorCorrectionCyan:
3113                 src->pColorPipeParams->TccParams.Cyan = (uint8_t)tccParamBuff[i].value;
3114                 break;
3115 
3116             case VAProcTotalColorCorrectionMagenta:
3117                 src->pColorPipeParams->TccParams.Magenta = (uint8_t)tccParamBuff[i].value;
3118                 break;
3119 
3120             case VAProcTotalColorCorrectionYellow:
3121                 src->pColorPipeParams->TccParams.Yellow = (uint8_t)tccParamBuff[i].value;
3122                 break;
3123 
3124             case VAProcTotalColorCorrectionNone:
3125             case VAProcTotalColorCorrectionCount:
3126             default:
3127                 DDI_VP_ASSERTMESSAGE("tccParamBuff[%d].attrib is unknown.", i);
3128                 return VA_STATUS_ERROR_INVALID_PARAMETER;
3129             }
3130         }
3131     }
3132 
3133     return VA_STATUS_SUCCESS;
3134 }
3135 
DdiSetProcFilterHdrTmParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBufferHDRToneMapping * hdrTmParamBuff)3136 VAStatus DdiVpFunctions::DdiSetProcFilterHdrTmParams(
3137     PDDI_VP_CONTEXT                           vpCtx,
3138     uint32_t                                  surfIndex,
3139     VAProcFilterParameterBufferHDRToneMapping *hdrTmParamBuff)
3140 {
3141     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
3142     PVPHAL_SURFACE       src               = nullptr;
3143     VAStatus             eStatus;
3144 
3145     DDI_VP_FUNC_ENTER;
3146     DDI_VP_CHK_NULL(hdrTmParamBuff, "nullptr hdrTmParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
3147 
3148     // initialize
3149     vpHalRenderParams = VpGetRenderParams(vpCtx);
3150     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3151     src = vpHalRenderParams->pSrc[surfIndex];
3152     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
3153 
3154     eStatus = VpUpdateProcHdrState(src, &hdrTmParamBuff->data);
3155 
3156     return eStatus;
3157 }
3158 
VpUpdateProcHdrState(const PVPHAL_SURFACE vpHalSurf,const VAHdrMetaData * hdrMetadata)3159 VAStatus DdiVpFunctions::VpUpdateProcHdrState(
3160     const PVPHAL_SURFACE vpHalSurf,
3161     const VAHdrMetaData *hdrMetadata)
3162 {
3163     VAHdrMetaDataHDR10 *hdr10MetaData = nullptr;
3164     DDI_VP_FUNC_ENTER;
3165     DDI_VP_CHK_NULL(vpHalSurf, "Null vpHalSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
3166 
3167     // pass HDR metadata
3168     if ((hdrMetadata != nullptr) && (hdrMetadata->metadata_size != 0))
3169     {
3170         if (vpHalSurf->pHDRParams == nullptr)
3171         {
3172             vpHalSurf->pHDRParams = MOS_New(VPHAL_HDR_PARAMS);
3173             DDI_VP_CHK_NULL(vpHalSurf->pHDRParams, "MOS_New VPHAL_HDR_PARAMS failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3174         }
3175 
3176         // HDR10 Meta Data
3177         if (hdrMetadata->metadata_type == VAProcHighDynamicRangeMetadataHDR10)
3178         {
3179             DDI_VP_NORMALMESSAGE("VpSetHdrParams HDR10 metadata.");
3180             hdr10MetaData = (VAHdrMetaDataHDR10 *)hdrMetadata->metadata;
3181             if (hdr10MetaData)
3182             {
3183                 vpHalSurf->pHDRParams->white_point_x = hdr10MetaData->white_point_x;
3184                 vpHalSurf->pHDRParams->white_point_y = hdr10MetaData->white_point_y;
3185                 DDI_VP_NORMALMESSAGE("hdr10MetaData white_point_x %d, white_point_y %d.", hdr10MetaData->white_point_x, hdr10MetaData->white_point_y);
3186 
3187                 // From VAAPI defintion which is following video spec, max/min_display_mastering_luminance are in units of 0.0001 candelas per square metre.
3188                 uint32_t max_display_mastering_luminance = (hdr10MetaData->max_display_mastering_luminance > 655350000 ) ? 655350000 : hdr10MetaData->max_display_mastering_luminance;
3189                 uint32_t min_display_mastering_luminance = (hdr10MetaData->min_display_mastering_luminance > 655350000 ) ? 655350000 : hdr10MetaData->min_display_mastering_luminance;
3190 
3191                 vpHalSurf->pHDRParams->max_display_mastering_luminance = (uint16_t)(max_display_mastering_luminance / 10000);;
3192                 vpHalSurf->pHDRParams->min_display_mastering_luminance = (uint16_t)(min_display_mastering_luminance / 10000);
3193                 DDI_VP_NORMALMESSAGE("hdr10MetaData max_display_mastering_luminance %d, min_display_mastering_luminance %d.", hdr10MetaData->max_display_mastering_luminance, hdr10MetaData->min_display_mastering_luminance);
3194 
3195                 vpHalSurf->pHDRParams->MaxCLL  = hdr10MetaData->max_content_light_level;
3196                 vpHalSurf->pHDRParams->MaxFALL = hdr10MetaData->max_pic_average_light_level;
3197                 DDI_VP_NORMALMESSAGE("hdr10MetaData MaxCLL %d, MaxFALL %d.", hdr10MetaData->max_content_light_level, hdr10MetaData->max_pic_average_light_level);
3198 
3199                 vpHalSurf->pHDRParams->bAutoMode = false;
3200                 vpHalSurf->pHDRParams->MaxCLL  = (vpHalSurf->pHDRParams->MaxCLL == 0) ? HDR_DEFAULT_MAXCLL : vpHalSurf->pHDRParams->MaxCLL;
3201                 vpHalSurf->pHDRParams->MaxFALL = (vpHalSurf->pHDRParams->MaxFALL == 0) ? HDR_DEFAULT_MAXFALL : vpHalSurf->pHDRParams->MaxFALL;
3202 
3203                 MOS_SecureMemcpy(vpHalSurf->pHDRParams->display_primaries_x, 3 * sizeof(uint16_t), hdr10MetaData->display_primaries_x, 3 * sizeof(uint16_t));
3204                 MOS_SecureMemcpy(vpHalSurf->pHDRParams->display_primaries_y, 3 * sizeof(uint16_t), hdr10MetaData->display_primaries_y, 3 * sizeof(uint16_t));
3205 
3206                 switch (vpHalSurf->GammaType)
3207                 {
3208                 case VPHAL_GAMMA_SMPTE_ST2084:
3209                     vpHalSurf->pHDRParams->EOTF = VPHAL_HDR_EOTF_SMPTE_ST2084;
3210                     break;
3211                 case VPHAL_GAMMA_BT1886:
3212                     vpHalSurf->pHDRParams->EOTF = VPHAL_HDR_EOTF_BT1886;
3213                     break;
3214                 default:
3215                     vpHalSurf->pHDRParams->EOTF = VPHAL_HDR_EOTF_TRADITIONAL_GAMMA_SDR;
3216                     break;
3217                 }
3218                 DDI_VP_NORMALMESSAGE("max_display_mastering_luminance %d.", vpHalSurf->pHDRParams->max_display_mastering_luminance);
3219                 DDI_VP_NORMALMESSAGE("min_display_mastering_luminance %d.", vpHalSurf->pHDRParams->min_display_mastering_luminance);
3220                 DDI_VP_NORMALMESSAGE("GammaType %d.", vpHalSurf->GammaType);
3221             }
3222         }
3223     }
3224 
3225     return VA_STATUS_SUCCESS;
3226 }
3227 
3228 #if VA_CHECK_VERSION(1, 12, 0)
DdiSetProcFilter3DLutParams(VADriverContextP vaDrvCtx,PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcFilterParameterBuffer3DLUT * lut3DParamBuff)3229 VAStatus DdiVpFunctions::DdiSetProcFilter3DLutParams(
3230     VADriverContextP                 vaDrvCtx,
3231     PDDI_VP_CONTEXT                  vpCtx,
3232     uint32_t                         surfIndex,
3233     VAProcFilterParameterBuffer3DLUT *lut3DParamBuff)
3234 {
3235     VAStatus             eStatus           = VA_STATUS_SUCCESS;
3236     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
3237     PVPHAL_SURFACE       src               = nullptr;
3238     PDDI_MEDIA_SURFACE   media3DLutSurf    = nullptr;
3239     PDDI_MEDIA_CONTEXT   mediaCtx          = nullptr;
3240     PMOS_RESOURCE        osResource        = nullptr;
3241 
3242     DDI_VP_FUNC_ENTER;
3243     DDI_VP_CHK_NULL(lut3DParamBuff, "nullptr lut3DParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
3244     DDI_VP_CHK_NULL(vaDrvCtx,       "nullptr vaDrvCtx.",       VA_STATUS_ERROR_INVALID_BUFFER);
3245 
3246     mediaCtx = GetMediaContext(vaDrvCtx);
3247 
3248     vpHalRenderParams = VpGetRenderParams(vpCtx);
3249     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3250     src = vpHalRenderParams->pSrc[surfIndex];
3251     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
3252 
3253     media3DLutSurf = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, lut3DParamBuff->lut_surface);
3254     DDI_VP_CHK_NULL(media3DLutSurf, "nullptr media3DLutSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
3255 
3256     // only primary surface takes effect if 3DLUT filter
3257     if (SURF_IN_PRIMARY == src->SurfType)
3258     {
3259         if (nullptr == src->p3DLutParams)
3260         {
3261             src->p3DLutParams = MOS_New(VPHAL_3DLUT_PARAMS);
3262             DDI_VP_CHK_NULL(src->p3DLutParams, "MOS_New p3DLutParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3263         }
3264 
3265         src->p3DLutParams->LutSize            = (uint32_t)lut3DParamBuff->lut_size;
3266         src->p3DLutParams->BitDepthPerChannel = (uint16_t)lut3DParamBuff->bit_depth;
3267         src->p3DLutParams->ByteCountPerEntry  = (uint16_t)(lut3DParamBuff->num_channel * (src->p3DLutParams->BitDepthPerChannel / 8));
3268         if (nullptr == src->p3DLutParams->pExt3DLutSurface)
3269         {
3270             src->p3DLutParams->pExt3DLutSurface = MOS_New(VPHAL_SURFACE);
3271             DDI_VP_CHK_NULL(src->p3DLutParams->pExt3DLutSurface, "MOS_New p3DLutParams failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3272         }
3273 
3274         if (src->p3DLutParams->pExt3DLutSurface)
3275         {
3276             osResource               = &(src->p3DLutParams->pExt3DLutSurface->OsResource);
3277             DDI_VP_CHK_NULL(osResource, "nullptr  osResource.", VA_STATUS_ERROR_INVALID_PARAMETER);
3278 
3279             MediaLibvaCommonNext::MediaSurfaceToMosResource(media3DLutSurf, osResource);
3280             Mos_Solo_SetOsResource(media3DLutSurf->pGmmResourceInfo, osResource);
3281         }
3282     }
3283 
3284     return eStatus;
3285 }
3286 #endif
3287 
3288 
DdiClearFilterParamBuffer(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,DDI_VP_STATE vpStateFlags)3289 VAStatus DdiVpFunctions::DdiClearFilterParamBuffer(
3290     PDDI_VP_CONTEXT vpCtx,
3291     uint32_t        surfIndex,
3292     DDI_VP_STATE    vpStateFlags)
3293 {
3294     DDI_VP_FUNC_ENTER;
3295     if (!vpStateFlags.bProcampEnable)
3296     {
3297         MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pProcampParams);
3298     }
3299     if (!vpStateFlags.bDeinterlaceEnable)
3300     {
3301         MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pDeinterlaceParams);
3302     }
3303     if (!vpStateFlags.bDenoiseEnable)
3304     {
3305         MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pDenoiseParams);
3306     }
3307     if (!vpStateFlags.bIEFEnable)
3308     {
3309         if (vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pIEFParams)
3310         {
3311             if (!vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pIEFParams->pExtParam)
3312             {
3313                 DDI_VP_ASSERTMESSAGE("vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pIEFParams->pExtParam is nullptr.");
3314             }
3315             MOS_Delete(vpCtx->pVpHalRenderParams->pSrc[surfIndex]->pIEFParams);
3316         }
3317     }
3318     return VA_STATUS_SUCCESS;
3319 }
3320 
VpSetInterpolationParams(PVPHAL_SURFACE surface,uint32_t interpolationflags)3321 VAStatus DdiVpFunctions::VpSetInterpolationParams(
3322     PVPHAL_SURFACE        surface,
3323     uint32_t              interpolationflags)
3324 {
3325     DDI_VP_CHK_NULL(surface, "nullptr surface.", VA_STATUS_ERROR_INVALID_SURFACE);
3326     switch (interpolationflags)
3327     {
3328 #if VA_CHECK_VERSION(1, 9, 0)
3329     case VA_FILTER_INTERPOLATION_NEAREST_NEIGHBOR:
3330         surface->ScalingMode       = VPHAL_SCALING_NEAREST;
3331         break;
3332     case VA_FILTER_INTERPOLATION_BILINEAR:
3333         surface->ScalingMode       = VPHAL_SCALING_BILINEAR;
3334         break;
3335     case VA_FILTER_INTERPOLATION_ADVANCED:
3336     case VA_FILTER_INTERPOLATION_DEFAULT:
3337 #endif
3338     default:
3339         surface->ScalingMode       = VPHAL_SCALING_AVS;
3340         break;
3341     }
3342 
3343     return VA_STATUS_SUCCESS;
3344 }
3345 
VpUpdateWeaveDI(PVPHAL_SURFACE vpHalSrcSurf,uint32_t filterFlags)3346 void DdiVpFunctions::VpUpdateWeaveDI(PVPHAL_SURFACE vpHalSrcSurf, uint32_t filterFlags)
3347 {
3348     DDI_VP_FUNC_ENTER;
3349     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf", );
3350     if (vpHalSrcSurf->pDeinterlaceParams == nullptr)
3351     {
3352         if ((filterFlags & 0x00000004) || ((filterFlags & VA_TOP_FIELD) && vpHalSrcSurf->bFieldWeaving))
3353         {
3354             vpHalSrcSurf->SampleType = SAMPLE_SINGLE_TOP_FIELD;
3355             if (vpHalSrcSurf->pBwdRef != nullptr)
3356             {
3357                 vpHalSrcSurf->pBwdRef->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
3358             }
3359             vpHalSrcSurf->ScalingMode   = VPHAL_SCALING_BILINEAR;
3360             vpHalSrcSurf->bFieldWeaving = true;
3361         }
3362 
3363         if ((filterFlags & 0x00000008) || ((filterFlags & VA_BOTTOM_FIELD) && vpHalSrcSurf->bFieldWeaving))
3364         {
3365             vpHalSrcSurf->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
3366             if (vpHalSrcSurf->pBwdRef != nullptr)
3367             {
3368                 vpHalSrcSurf->pBwdRef->SampleType = SAMPLE_SINGLE_TOP_FIELD;
3369             }
3370             vpHalSrcSurf->ScalingMode   = VPHAL_SCALING_BILINEAR;
3371             vpHalSrcSurf->bFieldWeaving = true;
3372         }
3373     }
3374     return;
3375 }
3376 
SetSurfaceParamsTopFieldFirst(uint32_t surfaceFlag,PVPHAL_SURFACE vpHalSrcSurf,PVPHAL_SURFACE vpHalTgtSurf)3377 VAStatus DdiVpFunctions::SetSurfaceParamsTopFieldFirst(uint32_t surfaceFlag, PVPHAL_SURFACE vpHalSrcSurf, PVPHAL_SURFACE vpHalTgtSurf)
3378 {
3379     DDI_VP_FUNC_ENTER;
3380     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
3381     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
3382     if (surfaceFlag & VA_TOP_FIELD_FIRST)
3383     {
3384         vpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_INTERLEAVED;
3385         vpHalSrcSurf->SampleType            = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
3386         vpHalSrcSurf->bInterlacedScaling    = true;
3387         vpHalSrcSurf->bFieldWeaving         = false;
3388     }
3389     else if (surfaceFlag & VA_TOP_FIELD)
3390     {
3391         vpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_FIELD;
3392         vpHalSrcSurf->SampleType            = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
3393         vpHalTgtSurf->SampleType            = SAMPLE_SINGLE_TOP_FIELD;
3394         vpHalSrcSurf->bInterlacedScaling    = false;
3395         vpHalSrcSurf->bFieldWeaving         = false;
3396     }
3397     else if (surfaceFlag & VA_BOTTOM_FIELD)
3398     {
3399         vpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_FIELD;
3400         vpHalSrcSurf->SampleType            = SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD;
3401         vpHalTgtSurf->SampleType            = SAMPLE_SINGLE_BOTTOM_FIELD;
3402         vpHalSrcSurf->bInterlacedScaling    = false;
3403         vpHalSrcSurf->bFieldWeaving         = false;
3404     }
3405     else
3406     {
3407         DDI_VP_ASSERTMESSAGE("output_surface_flag need to be set for interlaced scaling.");
3408         vpHalSrcSurf->SampleType            = SAMPLE_PROGRESSIVE;
3409         vpHalSrcSurf->InterlacedScalingType = ISCALING_NONE;
3410         vpHalSrcSurf->bInterlacedScaling    = false;
3411         vpHalSrcSurf->bFieldWeaving         = false;
3412     }
3413     return VA_STATUS_SUCCESS;
3414 }
3415 
SetSurfaceParamsBottomFieldFirst(uint32_t surfaceFlag,PVPHAL_SURFACE vpHalSrcSurf,PVPHAL_SURFACE vpHalTgtSurf)3416 VAStatus DdiVpFunctions::SetSurfaceParamsBottomFieldFirst(uint32_t surfaceFlag, PVPHAL_SURFACE vpHalSrcSurf, PVPHAL_SURFACE vpHalTgtSurf)
3417 {
3418     DDI_VP_FUNC_ENTER;
3419     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
3420     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
3421     if (surfaceFlag & VA_BOTTOM_FIELD_FIRST)
3422     {
3423         vpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_INTERLEAVED;
3424         vpHalSrcSurf->SampleType            = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
3425         vpHalSrcSurf->bInterlacedScaling    = true;
3426         vpHalSrcSurf->bFieldWeaving         = false;
3427     }
3428     else if (surfaceFlag & VA_TOP_FIELD)
3429     {
3430         vpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_FIELD;
3431         vpHalSrcSurf->SampleType            = SAMPLE_INTERLEAVED_ODD_FIRST_TOP_FIELD;
3432         vpHalTgtSurf->SampleType            = SAMPLE_SINGLE_TOP_FIELD;
3433         vpHalSrcSurf->bInterlacedScaling    = false;
3434         vpHalSrcSurf->bFieldWeaving         = false;
3435     }
3436     else if (surfaceFlag & VA_BOTTOM_FIELD)
3437     {
3438         vpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_FIELD;
3439         vpHalSrcSurf->SampleType            = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
3440         vpHalTgtSurf->SampleType            = SAMPLE_SINGLE_BOTTOM_FIELD;
3441         vpHalSrcSurf->bInterlacedScaling    = false;
3442         vpHalSrcSurf->bFieldWeaving         = false;
3443     }
3444     else
3445     {
3446         DDI_VP_ASSERTMESSAGE("output_surface_flag need to be set for interlaced scaling.");
3447         vpHalSrcSurf->SampleType            = SAMPLE_PROGRESSIVE;
3448         vpHalSrcSurf->InterlacedScalingType = ISCALING_NONE;
3449         vpHalSrcSurf->bInterlacedScaling    = false;
3450         vpHalSrcSurf->bFieldWeaving         = false;
3451     }
3452     return VA_STATUS_SUCCESS;
3453 }
3454 
SetSurfaceParamsTopField(uint32_t surfaceFlag,PVPHAL_SURFACE vpHalSrcSurf,PVPHAL_SURFACE vpHalTgtSurf)3455 VAStatus DdiVpFunctions::SetSurfaceParamsTopField(uint32_t surfaceFlag, PVPHAL_SURFACE vpHalSrcSurf, PVPHAL_SURFACE vpHalTgtSurf)
3456 {
3457     DDI_VP_FUNC_ENTER;
3458     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
3459     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
3460     if (surfaceFlag & VA_TOP_FIELD_FIRST)
3461     {
3462         vpHalSrcSurf->InterlacedScalingType = ISCALING_FIELD_TO_INTERLEAVED;
3463         vpHalSrcSurf->SampleType            = SAMPLE_SINGLE_TOP_FIELD;
3464         vpHalTgtSurf->SampleType            = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
3465 
3466         DDI_VP_CHK_NULL(vpHalSrcSurf->pBwdRef, "No Ref Field!", VA_STATUS_ERROR_UNIMPLEMENTED);
3467         vpHalSrcSurf->pBwdRef->InterlacedScalingType = ISCALING_FIELD_TO_INTERLEAVED;
3468         vpHalSrcSurf->pBwdRef->SampleType            = SAMPLE_SINGLE_BOTTOM_FIELD;
3469 
3470         vpHalSrcSurf->bInterlacedScaling = false;
3471         vpHalSrcSurf->bFieldWeaving      = true;
3472     }
3473     else if (surfaceFlag & VA_TOP_FIELD)
3474     {
3475         vpHalSrcSurf->InterlacedScalingType = ISCALING_FIELD_TO_FIELD;
3476         vpHalSrcSurf->SampleType            = SAMPLE_SINGLE_TOP_FIELD;
3477         vpHalSrcSurf->bInterlacedScaling    = false;
3478         vpHalSrcSurf->bFieldWeaving         = false;
3479     }
3480     else
3481     {
3482         vpHalSrcSurf->SampleType         = SAMPLE_PROGRESSIVE;
3483         vpHalSrcSurf->bInterlacedScaling = false;
3484         vpHalSrcSurf->bFieldWeaving      = false;
3485     }
3486     return VA_STATUS_SUCCESS;
3487 }
3488 
SetSurfaceParamsBottomField(uint32_t surfaceFlag,PVPHAL_SURFACE vpHalSrcSurf,PVPHAL_SURFACE vpHalTgtSurf)3489 VAStatus DdiVpFunctions::SetSurfaceParamsBottomField(uint32_t surfaceFlag, PVPHAL_SURFACE vpHalSrcSurf, PVPHAL_SURFACE vpHalTgtSurf)
3490 {
3491     DDI_VP_FUNC_ENTER;
3492     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
3493     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf", VA_STATUS_ERROR_INVALID_PARAMETER);
3494     if (surfaceFlag & VA_BOTTOM_FIELD_FIRST)
3495     {
3496         vpHalSrcSurf->InterlacedScalingType = ISCALING_FIELD_TO_INTERLEAVED;
3497         vpHalSrcSurf->SampleType            = SAMPLE_SINGLE_BOTTOM_FIELD;
3498         vpHalTgtSurf->SampleType            = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
3499 
3500         DDI_VP_CHK_NULL(vpHalSrcSurf->pBwdRef, "No Ref Field!", VA_STATUS_ERROR_UNIMPLEMENTED);
3501         vpHalSrcSurf->pBwdRef->InterlacedScalingType = ISCALING_FIELD_TO_INTERLEAVED;
3502         vpHalSrcSurf->pBwdRef->SampleType            = SAMPLE_SINGLE_TOP_FIELD;
3503 
3504         vpHalSrcSurf->bInterlacedScaling = false;
3505         vpHalSrcSurf->bFieldWeaving      = true;
3506     }
3507     else if (surfaceFlag & VA_BOTTOM_FIELD)
3508     {
3509         vpHalSrcSurf->InterlacedScalingType = ISCALING_FIELD_TO_FIELD;
3510         vpHalSrcSurf->SampleType            = SAMPLE_SINGLE_BOTTOM_FIELD;
3511         vpHalSrcSurf->bInterlacedScaling    = false;
3512         vpHalSrcSurf->bFieldWeaving         = false;
3513     }
3514     else
3515     {
3516         vpHalSrcSurf->SampleType         = SAMPLE_PROGRESSIVE;
3517         vpHalSrcSurf->bInterlacedScaling = false;
3518         vpHalSrcSurf->bFieldWeaving      = false;
3519     }
3520     return VA_STATUS_SUCCESS;
3521 }
3522 
SetLegacyInterlaceScalingParams(PVPHAL_SURFACE vpHalSrcSurf,uint32_t filterFlags)3523 void DdiVpFunctions::SetLegacyInterlaceScalingParams(PVPHAL_SURFACE vpHalSrcSurf, uint32_t filterFlags)
3524 {
3525     DDI_VP_FUNC_ENTER;
3526     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf", );
3527 
3528     if (vpHalSrcSurf->pDeinterlaceParams == nullptr && vpHalSrcSurf->InterlacedScalingType == ISCALING_NONE)
3529     {
3530         if (filterFlags & VA_TOP_FIELD)
3531         {
3532             vpHalSrcSurf->SampleType            = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
3533             vpHalSrcSurf->ScalingMode           = VPHAL_SCALING_AVS;
3534             vpHalSrcSurf->bInterlacedScaling    = true;
3535             vpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_INTERLEAVED;
3536         }
3537         else if (filterFlags & VA_BOTTOM_FIELD)
3538         {
3539             vpHalSrcSurf->SampleType            = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
3540             vpHalSrcSurf->ScalingMode           = VPHAL_SCALING_AVS;
3541             vpHalSrcSurf->bInterlacedScaling    = true;
3542             vpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_INTERLEAVED;
3543         }
3544 
3545         // Kernel does not support 3-plane interlaced AVS, so for 3-plane interlaced scaling, need to use bilinear.
3546         if (vpHalSrcSurf->bInterlacedScaling && IS_PL3_FORMAT(vpHalSrcSurf->Format))
3547         {
3548             vpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
3549         }
3550     }
3551     return;
3552 }
3553 
VpUpdateProcRotateState(PVPHAL_SURFACE vpHalSrcSurf,uint32_t rotationState)3554 VAStatus DdiVpFunctions::VpUpdateProcRotateState(PVPHAL_SURFACE vpHalSrcSurf, uint32_t rotationState)
3555 {
3556     DDI_VP_FUNC_ENTER;
3557     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
3558 
3559     switch (rotationState)
3560     {
3561     case VA_ROTATION_NONE:
3562         vpHalSrcSurf->Rotation = VPHAL_ROTATION_IDENTITY;
3563         break;
3564     case VA_ROTATION_90:
3565         vpHalSrcSurf->Rotation = VPHAL_ROTATION_90;
3566         break;
3567     case VA_ROTATION_180:
3568         vpHalSrcSurf->Rotation = VPHAL_ROTATION_180;
3569         break;
3570     case VA_ROTATION_270:
3571         vpHalSrcSurf->Rotation = VPHAL_ROTATION_270;
3572         break;
3573     default:
3574         DDI_VP_ASSERTMESSAGE("VpUpdateProcRotateState rotationState = %d is out of range.", rotationState);
3575         return VA_STATUS_ERROR_INVALID_PARAMETER;
3576     }
3577 
3578     return VA_STATUS_SUCCESS;
3579 }
3580 
VpUpdateProcMirrorState(PVPHAL_SURFACE vpHalSrcSurf,uint32_t mirrorState)3581 VAStatus DdiVpFunctions::VpUpdateProcMirrorState(PVPHAL_SURFACE vpHalSrcSurf, uint32_t mirrorState)
3582 {
3583     DDI_VP_FUNC_ENTER;
3584     DDI_VP_CHK_NULL(vpHalSrcSurf,  "nullptr vpHalSrcSurf.",  VA_STATUS_ERROR_INVALID_PARAMETER);
3585 
3586     if(mirrorState > VA_MIRROR_VERTICAL)
3587     {
3588         DDI_VP_ASSERTMESSAGE("VpUpdateProcMirrorState mirrorState = %d is out of range.", mirrorState);
3589         DDI_VP_ASSERTMESSAGE("VpUpdateProcMirrorState reset mirrorState to VA_MIRROR_NONE.");
3590         mirrorState = VA_MIRROR_NONE;
3591     }
3592 
3593     // Rotation must be a valid angle
3594     switch(vpHalSrcSurf->Rotation)
3595     {
3596         case VPHAL_ROTATION_IDENTITY:
3597             if(mirrorState == VA_MIRROR_HORIZONTAL)
3598             {
3599                 vpHalSrcSurf->Rotation = VPHAL_MIRROR_HORIZONTAL;
3600             }
3601             else if(mirrorState == VA_MIRROR_VERTICAL)
3602             {
3603                 vpHalSrcSurf->Rotation = VPHAL_MIRROR_VERTICAL;
3604             }
3605             break;
3606         case VPHAL_ROTATION_90:
3607             if(mirrorState == VA_MIRROR_HORIZONTAL)
3608             {
3609                 vpHalSrcSurf->Rotation = VPHAL_ROTATE_90_MIRROR_HORIZONTAL;
3610             }
3611             else if(mirrorState == VA_MIRROR_VERTICAL)
3612             {
3613                 vpHalSrcSurf->Rotation = VPHAL_ROTATE_90_MIRROR_VERTICAL;
3614             }
3615             break;
3616         case VPHAL_ROTATION_180:
3617             if(mirrorState == VA_MIRROR_HORIZONTAL)
3618             {
3619                 vpHalSrcSurf->Rotation =  VPHAL_MIRROR_VERTICAL;
3620             }
3621             else if(mirrorState == VA_MIRROR_VERTICAL)
3622             {
3623                 vpHalSrcSurf->Rotation =  VPHAL_MIRROR_HORIZONTAL;
3624             }
3625             break;
3626         case VPHAL_ROTATION_270:
3627             if(mirrorState == VA_MIRROR_HORIZONTAL)
3628             {
3629                 vpHalSrcSurf->Rotation =  VPHAL_ROTATE_90_MIRROR_VERTICAL;
3630             }
3631             else if(mirrorState == VA_MIRROR_VERTICAL)
3632             {
3633                 vpHalSrcSurf->Rotation =  VPHAL_ROTATE_90_MIRROR_HORIZONTAL;
3634             }
3635             break;
3636         default:
3637             DDI_VP_ASSERTMESSAGE("VpUpdateProcMirrorState Unexpected Invalid Rotation = %d.", vpHalSrcSurf->Rotation);
3638             return VA_STATUS_ERROR_INVALID_PARAMETER;
3639 
3640     }
3641 
3642     return VA_STATUS_SUCCESS;
3643 }
3644 
DdiSetProcPipelineBlendingParams(PDDI_VP_CONTEXT vpCtx,uint32_t surfIndex,VAProcPipelineParameterBuffer * pipelineParam)3645 VAStatus DdiVpFunctions::DdiSetProcPipelineBlendingParams(
3646     PDDI_VP_CONTEXT               vpCtx,
3647     uint32_t                      surfIndex,
3648     VAProcPipelineParameterBuffer *pipelineParam)
3649 {
3650     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
3651     PVPHAL_SURFACE       src               = nullptr;
3652     PVPHAL_SURFACE       target            = nullptr;
3653     bool                 globalAlpha       = false;
3654     bool                 preMultAlpha      = false;
3655     const VABlendState   *blendState       = nullptr;
3656 
3657     DDI_VP_FUNC_ENTER;
3658     DDI_VP_CHK_NULL(vpCtx,         "nullptr vpCtx.",         VA_STATUS_ERROR_INVALID_CONTEXT);
3659     DDI_VP_CHK_NULL(pipelineParam, "nullptr pipelineParam.", VA_STATUS_ERROR_INVALID_BUFFER);
3660 
3661     blendState = pipelineParam->blend_state;
3662     // initialize
3663     vpHalRenderParams = VpGetRenderParams(vpCtx);
3664     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3665 
3666     src = vpHalRenderParams->pSrc[surfIndex];
3667     DDI_VP_CHK_NULL(src, "nullptr src.", VA_STATUS_ERROR_INVALID_SURFACE);
3668 
3669     if (nullptr == vpHalRenderParams->pCompAlpha)
3670     {
3671         vpHalRenderParams->pCompAlpha = MOS_New(VPHAL_ALPHA_PARAMS);
3672         DDI_VP_CHK_NULL(vpHalRenderParams->pCompAlpha, "nullptr pCompAlpha.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3673     }
3674 
3675     // So far vaapi does not have alpha fill mode API.
3676     // And for blending support, we use VPHAL_ALPHA_FILL_MODE_NONE by default.
3677     target = vpHalRenderParams->pTarget[0];
3678     DDI_VP_CHK_NULL(target, "nullptr target.", VA_STATUS_ERROR_INVALID_SURFACE);
3679 
3680     //For surface with alpha, we need to bypass SFC that could change the output alpha.
3681     if (hasAlphaInSurface(src) && hasAlphaInSurface(target))
3682     {
3683         vpHalRenderParams->pCompAlpha->fAlpha    = 0.0f;
3684         vpHalRenderParams->pCompAlpha->AlphaMode = VPHAL_ALPHA_FILL_MODE_SOURCE_STREAM;
3685     }
3686     else
3687     {
3688         vpHalRenderParams->pCompAlpha->fAlpha    = 1.0f;
3689         vpHalRenderParams->pCompAlpha->AlphaMode = VPHAL_ALPHA_FILL_MODE_NONE;
3690     }
3691 
3692     // First, no Blending
3693     if (!blendState)
3694     {
3695         if (src->pBlendingParams)
3696         {
3697             src->pBlendingParams->BlendType = BLEND_NONE;
3698             src->pBlendingParams->fAlpha    = 1.0;
3699         }
3700 
3701         if (src->pLumaKeyParams)
3702         {
3703             src->pLumaKeyParams->LumaLow  = 0;
3704             src->pLumaKeyParams->LumaHigh = 0;
3705         }
3706 
3707         return VA_STATUS_SUCCESS;
3708     }
3709 
3710     // Then, process all blending types
3711 
3712     if (blendState->flags & VA_BLEND_GLOBAL_ALPHA)
3713     {
3714         globalAlpha = true;
3715     }
3716 
3717     if (blendState->flags & VA_BLEND_PREMULTIPLIED_ALPHA)
3718     {
3719         preMultAlpha = true;
3720     }
3721 
3722     if (nullptr == src->pBlendingParams)
3723     {
3724         src->pBlendingParams = MOS_New(VPHAL_BLENDING_PARAMS);
3725         DDI_VP_CHK_NULL(src->pBlendingParams, "nullptr pBlendingParams.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3726     }
3727 
3728     ///////////////////////////////////////////////////////////////////////////////////////////////////
3729     // Surfaces contains alpha value, will be devide into premultiplied and non-premultiplied:
3730     //     For premultiplied surface, will support:
3731     //         a. per-pixel alpha blending;
3732     //         b. per-pixel plus per-plane alpha blending;
3733     //     For non-promultilied surface, will support:
3734     //         a. per-plane alpha blending;
3735     //         b. per-pixel alpha blending;
3736     //         c. NOT support per-pixel plus per-plane alpha blending;
3737     // Surfaces NOT contains alpha value, will not be devided into premultiplied or non-premultiplied:
3738     //     Will only support per-plane alpha blending.
3739     ///////////////////////////////////////////////////////////////////////////////////////////////////
3740     if (hasAlphaInSurface(src))
3741     {
3742         // For premultiplied surface, we just support four blending types until now
3743         SetBlendingTypes(preMultAlpha, globalAlpha, src->pBlendingParams, blendState->global_alpha);
3744     }
3745     else
3746     {
3747         if (globalAlpha)  // Do per-plane alpha blending for surface which not contain alpha value
3748         {
3749             if (blendState->global_alpha < 1.0f)
3750             {
3751                 src->pBlendingParams->BlendType = BLEND_CONSTANT;
3752                 src->pBlendingParams->fAlpha    = blendState->global_alpha;
3753                 DDI_VP_ASSERTMESSAGE("BLEND_CONSTANT do not support alpha calculating.\n");
3754             }
3755             else
3756             {
3757                 src->pBlendingParams->BlendType = BLEND_PARTIAL;
3758                 DDI_VP_NORMALMESSAGE("Because BLEND_CONSTANT do not support alpha calculating, use BLEND_PARTIAL instead.\n");
3759             }
3760 
3761             // preMultAlpha should not be true for surfaces which do not contain alpha value,
3762             // but inorder to make the driver more usable, choose the most reasonable blending mode, but print out a message.
3763             if (preMultAlpha)
3764             {
3765                 DDI_VP_NORMALMESSAGE("Should not set VA_BLEND_PREMULTIPLIED_ALPHA for surface which do not contain alpha value.\n");
3766             }
3767         }
3768         else
3769         {
3770             src->pBlendingParams->BlendType = BLEND_NONE;
3771             src->pBlendingParams->fAlpha    = 1.0;
3772 
3773             // preMultAlpha should not be true for surfaces which do not contain alpha value,
3774             // but inorder to make the driver more usable, choose the most reasonable blending mode, but print out a message.
3775             if (preMultAlpha)
3776             {
3777                 DDI_VP_NORMALMESSAGE("Should not set VA_BLEND_PREMULTIPLIED_ALPHA for surface which do not contain alpha value.\n");
3778             }
3779         }
3780     }
3781 
3782     if (blendState->flags & VA_BLEND_LUMA_KEY)
3783     {
3784         if (nullptr == src->pLumaKeyParams)
3785         {
3786             src->pLumaKeyParams = MOS_New(VPHAL_LUMAKEY_PARAMS);
3787             DDI_VP_CHK_NULL(src->pLumaKeyParams, "nullptr pLumaKeyParams.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3788         }
3789         src->pLumaKeyParams->LumaLow  = (int16_t)(pipelineParam->blend_state->min_luma * 255);
3790         src->pLumaKeyParams->LumaHigh = (int16_t)(pipelineParam->blend_state->max_luma * 255);
3791     }
3792 
3793     return VA_STATUS_SUCCESS;
3794 }
3795 
SetBlendingTypes(bool preMultAlpha,bool globalAlpha,PVPHAL_BLENDING_PARAMS blendingParams,float globalalpha)3796 void DdiVpFunctions::SetBlendingTypes(
3797     bool                   preMultAlpha,
3798     bool                   globalAlpha,
3799     PVPHAL_BLENDING_PARAMS blendingParams,
3800     float                  globalalpha)
3801 {
3802     DDI_VP_FUNC_ENTER;
3803     DDI_VP_CHK_NULL(blendingParams, "nullptr blendingParams.", );
3804     if (preMultAlpha && !globalAlpha)  // Do per-pixel alpha blending for premultiplied surface.
3805         {
3806             blendingParams->BlendType = BLEND_PARTIAL;
3807         }
3808         else if (preMultAlpha && globalAlpha)  // Do per-pixel plus per-plane alpha blending For premultiplied surface.
3809         {
3810             if (globalalpha < 1.0f)
3811             {
3812                 blendingParams->BlendType = BLEND_CONSTANT_PARTIAL;
3813             }
3814             else
3815             {
3816                 // Optimization when per-plane alpha value is 1.0
3817                 blendingParams->BlendType = BLEND_PARTIAL;
3818             }
3819             blendingParams->fAlpha = globalalpha;
3820         }
3821         else if (!preMultAlpha && globalAlpha)  // Do per-plane alpha blending for non-premultiplied surface, not do per-pixel blending
3822         {
3823             blendingParams->BlendType = BLEND_CONSTANT;
3824             blendingParams->fAlpha    = globalalpha;
3825             DDI_VP_ASSERTMESSAGE("BLEND_CONSTANT do not support alpha calculating.\n");
3826         }
3827         else if (!preMultAlpha && !globalAlpha)  // Do per-pixel alpha blending for non-premultiplied surface
3828         {
3829             blendingParams->BlendType = BLEND_SOURCE;
3830             DDI_VP_ASSERTMESSAGE("BLEND_SOURCE do not support alpha calculating.\n");
3831         }
3832         // Not support per-plane plus per-pixel alpha blending for non-premultiplied surface.
3833     return;
3834 }
3835 
hasAlphaInSurface(PVPHAL_SURFACE surface)3836 bool DdiVpFunctions::hasAlphaInSurface(PVPHAL_SURFACE surface)
3837 {
3838     DDI_VP_FUNC_ENTER;
3839     DDI_VP_CHK_NULL(surface, "nullptr surface.No surface handle passed in.\n", false);
3840 
3841     switch (surface->Format)
3842     {
3843     case Format_P8:  //P8_UNORM: An 8-bit color index which is used to lookup a 32-bit ARGB value in the texture palette.
3844     case Format_AI44:
3845     case Format_IA44:
3846     case Format_A8R8G8B8:
3847     case Format_A8B8G8R8:
3848     case Format_A8P8:
3849     case Format_AYUV:
3850     case Format_Y410:
3851     case Format_Y416:
3852     case Format_R10G10B10A2:
3853     case Format_B10G10R10A2:
3854         return true;
3855     default:
3856         return false;
3857     }
3858 
3859     DDI_VP_ASSERTMESSAGE("No surface handle passed in.\n");
3860     return false;
3861 }
3862 
DdiUpdateVphalTargetSurfColorSpace(VADriverContextP vaDrvCtx,PDDI_VP_CONTEXT vpCtx,VAProcPipelineParameterBuffer * pipelineParam,uint32_t targetIndex)3863 VAStatus DdiVpFunctions::DdiUpdateVphalTargetSurfColorSpace(
3864     VADriverContextP              vaDrvCtx,
3865     PDDI_VP_CONTEXT               vpCtx,
3866     VAProcPipelineParameterBuffer *pipelineParam,
3867     uint32_t                      targetIndex)
3868 {
3869     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
3870     PVPHAL_SURFACE       vpHalSrcSurf      = nullptr;
3871     PVPHAL_SURFACE       vpHalTgtSurf      = nullptr;
3872     VAStatus             vaStatus          = VA_STATUS_SUCCESS;
3873     DDI_UNUSED(vaDrvCtx);
3874 
3875     DDI_VP_FUNC_ENTER;
3876     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3877 
3878     // initialize
3879     vpHalRenderParams = VpGetRenderParams(vpCtx);
3880     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3881     vpHalTgtSurf = vpHalRenderParams->pTarget[targetIndex];
3882     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
3883 
3884     // update target surface color space
3885 #if (VA_MAJOR_VERSION < 1)
3886     vaStatus = DdiGetColorSpace(vpHalTgtSurf, pipelineParam->output_color_standard, pipelineParam->output_surface_flag);
3887 #else
3888     vaStatus = DdiGetColorSpace(vpHalTgtSurf, pipelineParam->output_color_standard, pipelineParam->output_color_properties);
3889 #endif
3890 
3891     vpHalSrcSurf = vpHalRenderParams->pSrc[0];
3892     // Not support BT601/BT709 -> BT2020 colorspace conversion, if colorspace is not set, will keep it same with input.
3893     if (vpHalSrcSurf != nullptr &&
3894         pipelineParam->output_color_standard == 0 &&
3895         IS_COLOR_SPACE_BT2020(vpHalTgtSurf->ColorSpace) &&
3896         !IS_COLOR_SPACE_BT2020(vpHalSrcSurf->ColorSpace))
3897     {
3898         vpHalTgtSurf->ColorSpace = vpHalSrcSurf->ColorSpace;
3899     }
3900 
3901     // extended gamut?
3902     vpHalRenderParams->pTarget[0]->ExtendedGamut = false;
3903 
3904     return vaStatus;
3905 }
3906 
DdiBeginPictureInt(VADriverContextP vaDrvCtx,PDDI_VP_CONTEXT vpCtx,VASurfaceID vaSurfID)3907 VAStatus DdiVpFunctions::DdiBeginPictureInt(
3908     VADriverContextP vaDrvCtx,
3909     PDDI_VP_CONTEXT  vpCtx,
3910     VASurfaceID      vaSurfID)
3911 {
3912     PDDI_MEDIA_CONTEXT   mediaDrvCtx       = nullptr;
3913     uint32_t             ctxType           = 0;
3914     VAStatus             vaStatus          = VA_STATUS_SUCCESS;
3915     PVPHAL_RENDER_PARAMS vpHalRenderParams = nullptr;
3916     PVPHAL_SURFACE       vpHalTgtSurf      = nullptr;
3917     PDDI_MEDIA_SURFACE   mediaTgtSurf      = nullptr;
3918 
3919     DDI_VP_FUNC_ENTER;
3920     DDI_VP_CHK_NULL(vaDrvCtx, "nullptr vaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3921 
3922     // initialize
3923     mediaDrvCtx = GetMediaContext(vaDrvCtx);
3924     DDI_VP_CHK_NULL(mediaDrvCtx, "nullptr mediaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3925     DDI_VP_CHK_NULL(vpCtx,       "nullptr vpCtx.",       VA_STATUS_ERROR_INVALID_CONTEXT);
3926     vpCtx->TargetSurfID = vaSurfID;
3927 
3928     vpHalRenderParams   = VpGetRenderParams(vpCtx);
3929     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3930 
3931     // uDstCount == 0 means no render target is set yet.
3932     // uDstCount == 1 means 1 render target has been set already.
3933     // uDstCount == 2 means 2 render targets have been set already.
3934     DDI_VP_CHK_LESS(vpHalRenderParams->uDstCount, VPHAL_MAX_TARGETS, "Too many render targets for VP.", VA_STATUS_ERROR_INVALID_PARAMETER);
3935 
3936     vpHalTgtSurf = vpHalRenderParams->pTarget[vpHalRenderParams->uDstCount];
3937     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf.",  VA_STATUS_ERROR_INVALID_SURFACE);
3938     mediaTgtSurf = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaDrvCtx, vaSurfID);
3939     DDI_VP_CHK_NULL(mediaTgtSurf, "nullptr mediaTgtSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
3940 
3941     mediaTgtSurf->pVpCtx = vpCtx;
3942 
3943     // Setup Target VpHal Surface
3944     vpHalTgtSurf->SurfType       = SURF_OUT_RENDERTARGET;
3945     vpHalTgtSurf->rcSrc.top      = 0;
3946     vpHalTgtSurf->rcSrc.left     = 0;
3947     vpHalTgtSurf->rcSrc.right    = mediaTgtSurf->iWidth;
3948     vpHalTgtSurf->rcSrc.bottom   = mediaTgtSurf->iRealHeight;
3949     vpHalTgtSurf->rcDst.top      = 0;
3950     vpHalTgtSurf->rcDst.left     = 0;
3951     vpHalTgtSurf->rcDst.right    = mediaTgtSurf->iWidth;
3952     vpHalTgtSurf->rcDst.bottom   = mediaTgtSurf->iRealHeight;
3953     vpHalTgtSurf->ExtendedGamut  = false;
3954 
3955     // Set os resource for VPHal render
3956     vaStatus = VpSetOsResource(vpCtx, mediaTgtSurf, vpHalRenderParams->uDstCount);
3957     DDI_CHK_RET(vaStatus, "Call VpSetOsResource failed");
3958 
3959     vpHalTgtSurf->Format = vpHalTgtSurf->OsResource.Format;
3960 
3961     vpHalRenderParams->bReportStatus    = true;
3962     vpHalRenderParams->StatusFeedBackID = vaSurfID;
3963     if (mediaTgtSurf->pSurfDesc && (mediaTgtSurf->pSurfDesc->uiVaMemType == VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR))
3964     {
3965         vpHalRenderParams->pTarget[vpHalRenderParams->uDstCount]->b16UsrPtr = VpIs16UsrPtrPitch(mediaTgtSurf->iPitch, mediaTgtSurf->format);
3966     }
3967     else
3968     {
3969         vpHalRenderParams->pTarget[vpHalRenderParams->uDstCount]->b16UsrPtr = false;
3970     }
3971     // increase render target count
3972     vpHalRenderParams->uDstCount++;
3973 
3974     return VA_STATUS_SUCCESS;
3975 }
3976 
DdiSetProcPipelineParams(VADriverContextP vaDrvCtx,PDDI_VP_CONTEXT vpCtx,VAProcPipelineParameterBuffer * pipelineParam)3977 VAStatus DdiVpFunctions::DdiSetProcPipelineParams(
3978     VADriverContextP              vaDrvCtx,
3979     PDDI_VP_CONTEXT               vpCtx,
3980     VAProcPipelineParameterBuffer *pipelineParam)
3981 {
3982     PVPHAL_RENDER_PARAMS             vpHalRenderParams  = nullptr;
3983     PDDI_MEDIA_CONTEXT               mediaCtx           = nullptr;
3984     PDDI_MEDIA_SURFACE               mediaSrcSurf       = nullptr;
3985     PDDI_MEDIA_BUFFER                filterBuf          = nullptr;
3986     void *                           data               = nullptr;
3987     uint32_t                         i                  = 0;
3988     PVPHAL_SURFACE                   vpHalSrcSurf       = nullptr;
3989     PVPHAL_SURFACE                   vpHalTgtSurf       = nullptr;
3990     uint32_t                         surfIndex          = 0;
3991     uint32_t                         scalingflags       = 0;
3992     uint32_t                         interpolationflags = 0;
3993     VAStatus                         vaStatus           = VA_STATUS_SUCCESS;
3994     MOS_STATUS                       eStatus            = MOS_STATUS_SUCCESS;
3995     DDI_VP_STATE                     vpStateFlags       = {};
3996     PMOS_INTERFACE                   osInterface        = nullptr;
3997     VAProcFilterParameterBufferBase  *filterParam       = nullptr;
3998 
3999     DDI_VP_FUNC_ENTER;
4000     DDI_VP_CHK_NULL(vaDrvCtx, "nullptr vaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
4001     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx.", VA_STATUS_ERROR_INVALID_PARAMETER);
4002     DDI_VP_CHK_NULL(vpCtx->pVpHal, "nullptr vpCtx->pVpHal.", VA_STATUS_ERROR_INVALID_PARAMETER);
4003     DDI_VP_CHK_NULL(pipelineParam, "nullptr pipelineParam.", VA_STATUS_ERROR_INVALID_PARAMETER);
4004 
4005     // initialize
4006     mediaCtx = GetMediaContext(vaDrvCtx);
4007     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
4008 
4009     mediaSrcSurf = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, pipelineParam->surface);
4010     DDI_VP_CHK_NULL(mediaSrcSurf, "nullptr mediaSrcSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
4011 
4012     vpHalRenderParams = vpCtx->pVpHalRenderParams;
4013     DDI_VP_CHK_NULL(vpHalRenderParams, "nullptr vpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
4014 
4015     osInterface = vpCtx->pVpHal->GetOsInterface();
4016     DDI_VP_CHK_NULL(osInterface, "nullptr osInterface.", VA_STATUS_ERROR_INVALID_BUFFER);
4017 
4018     // increment surface count
4019     vpHalRenderParams->uSrcCount++;
4020 
4021     // check if the surface count exceeded maximum VPHAL surfaces
4022     DDI_VP_CHK_CONDITION((vpHalRenderParams->uSrcCount > VPHAL_MAX_SOURCES),
4023         "Surface count exceeds maximum!",
4024         VA_STATUS_ERROR_MAX_NUM_EXCEEDED);
4025 
4026     // update surface surfIndex
4027     surfIndex = vpHalRenderParams->uSrcCount - 1;
4028 
4029     vpHalSrcSurf = vpHalRenderParams->pSrc[surfIndex];
4030     DDI_VP_CHK_NULL(vpHalSrcSurf, "nullptr vpHalSrcSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
4031 
4032     vpHalSrcSurf->Format   = MediaLibvaUtilNext::GetFormatFromMediaFormat(mediaSrcSurf->format);
4033     vpHalSrcSurf->TileType = MediaLibvaUtilNext::GetTileTypeFromMediaTileType(mediaSrcSurf->TileType);
4034 
4035     DDI_VP_CHK_CONDITION((Format_Invalid == vpHalSrcSurf->Format), "Invalid surface media format!", VA_STATUS_ERROR_INVALID_PARAMETER);
4036 
4037 #if (_DEBUG || _RELEASE_INTERNAL)
4038     if (vpCtx->pCurVpDumpDDIParam != nullptr && vpCtx->pCurVpDumpDDIParam->pPipelineParamBuffers[surfIndex] != nullptr)
4039     {
4040         MOS_SecureMemcpy(vpCtx->pCurVpDumpDDIParam->pPipelineParamBuffers[surfIndex], sizeof(VAProcPipelineParameterBuffer), pipelineParam, sizeof(VAProcPipelineParameterBuffer));
4041         vpCtx->pCurVpDumpDDIParam->SrcFormat[surfIndex] = vpHalSrcSurf->Format;
4042     }
4043 #endif  //(_DEBUG || _RELEASE_INTERNAL)
4044 
4045     // Currently we only support 1 primary surface in VP
4046     if (vpCtx->iPriSurfs < VP_MAX_PRIMARY_SURFS)
4047     {
4048         vpHalSrcSurf->SurfType = SURF_IN_PRIMARY;
4049         vpCtx->iPriSurfs++;
4050     }
4051     else
4052     {
4053         vpHalSrcSurf->SurfType = SURF_IN_SUBSTREAM;
4054     }
4055 
4056     // Set workload path using pipeline_flags VA_PROC_PIPELINE_FAST flag
4057     if (pipelineParam->pipeline_flags & VA_PROC_PIPELINE_FAST)
4058     {
4059         vpHalRenderParams->bForceToRender = true;
4060     }
4061 
4062     // Set src rect
4063     SetSrcSurfaceRect(pipelineParam->surface_region, vpHalSrcSurf, mediaSrcSurf);
4064 
4065     vpHalTgtSurf = vpHalRenderParams->pTarget[0];
4066     DDI_VP_CHK_NULL(vpHalTgtSurf, "nullptr vpHalTgtSurf.", VA_STATUS_ERROR_UNKNOWN);
4067     // Set dest rect
4068     vaStatus = SetDestSurfaceRect(pipelineParam->output_region, vpHalSrcSurf, vpHalTgtSurf);
4069     DDI_CHK_RET(vaStatus, "Failed to Set dest rect!");
4070 
4071     //set the frame_id
4072     vpHalSrcSurf->FrameID = mediaSrcSurf->frame_idx;
4073 
4074     //In order to refresh the frame ID in DdiVp_UpdateFilterParamBuffer when run ADI case,
4075     //we need to set the OS resource here.
4076     vpHalSrcSurf->OsResource.bo = mediaSrcSurf->bo;
4077 
4078     // csc option
4079     //---------------------------------------
4080     // Set color space for src
4081 #if (VA_MAJOR_VERSION < 1)
4082     vaStatus = DdiGetColorSpace(vpHalSrcSurf, pipelineParam->surface_color_standard, pipelineParam->input_surface_flag);
4083 #else
4084     vaStatus = DdiGetColorSpace(vpHalSrcSurf, pipelineParam->surface_color_standard, pipelineParam->input_color_properties);
4085 #endif
4086     DDI_CHK_RET(vaStatus, "Unsupport Color space!");
4087 
4088     if (mediaSrcSurf->format == Media_Format_400P)
4089     {
4090         vpHalSrcSurf->ColorSpace = CSpace_BT601Gray;
4091     }
4092 
4093     // extended gamut? RGB can't have extended gamut flag
4094     vpHalSrcSurf->ExtendedGamut = false;
4095 
4096     // Background Colorfill
4097     // According to libva  definition, if alpha in output background color is zero, then colorfill is not needed
4098     DDI_CHK_RET(SetBackgroundColorfill(vpHalRenderParams, pipelineParam->output_background_color), "Failed Set Background Colorfill");
4099 
4100     // Set Demo Mode option
4101     if (vpHalRenderParams->bDisableDemoMode == false)
4102     {
4103         eStatus = VpHalDdiSetupSplitScreenDemoMode(
4104             0,  // No DDI setting on Linux. Set it when Linux DDI supports it
4105             0,  // No DDI setting on Linux. Set it when Linux DDI supports it
4106             &vpHalRenderParams->pSplitScreenDemoModeParams,
4107             &vpHalRenderParams->bDisableDemoMode,
4108             osInterface);
4109         if (MOS_STATUS_SUCCESS != eStatus)
4110         {
4111             DDI_VP_ASSERTMESSAGE("Failed to setup Split-Screen Demo Mode.");
4112             MOS_FreeMemAndSetNull(vpHalRenderParams->pSplitScreenDemoModeParams);
4113         }
4114     }
4115 
4116     // Update fwd and bkward ref frames: Required for Advanced processing - will be supported in the future
4117     vpHalSrcSurf->uFwdRefCount = pipelineParam->num_backward_references;
4118 
4119     vaStatus = DdiUpdateProcPipelineFutureReferenceFrames(vpCtx, vaDrvCtx, vpHalSrcSurf, pipelineParam);
4120     DDI_CHK_RET(vaStatus, "Failed to update future reference frames!");
4121 
4122     vpHalSrcSurf->uBwdRefCount = pipelineParam->num_forward_references;
4123 
4124     vaStatus = DdiUpdateProcPipelinePastReferenceFrames(vpCtx, vaDrvCtx, vpHalSrcSurf, pipelineParam);
4125     DDI_CHK_RET(vaStatus, "Failed to update past reference frames!");
4126 
4127     // Check if filter values changed,if yes, then reset all filters for this surface
4128 
4129     // intialize the filter parameter
4130     // Parameters once set in the surface will be keep till video complete
4131     // so the parameter of rendered surface should be intialized every time
4132     if (vpHalRenderParams->bStereoMode)
4133     {
4134         vpHalSrcSurf->Rotation = VPHAL_ROTATION_IDENTITY;
4135     }
4136 
4137     // Progressive or interlaced - Check filter_flags
4138     // if the deinterlace parameters is not set, manipulate it as a progressive video.
4139     if (pipelineParam->filter_flags & VA_TOP_FIELD)
4140     {
4141         vpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
4142     }
4143     else if (pipelineParam->filter_flags & VA_BOTTOM_FIELD)
4144     {
4145         vpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD;
4146     }
4147     else  // VA_FRAME_PICTURE
4148     {
4149         vpHalSrcSurf->SampleType = SAMPLE_PROGRESSIVE;
4150 
4151         //if the deinterlace parameters is set, clear it.
4152         if (vpHalSrcSurf->pDeinterlaceParams != nullptr)
4153         {
4154             MOS_Delete(vpHalSrcSurf->pDeinterlaceParams);
4155         }
4156     }
4157 
4158     for (i = 0; i < pipelineParam->num_filters; i++)
4159     {
4160         VABufferID filter = pipelineParam->filters[i];
4161 
4162         filterBuf = MediaLibvaCommonNext::GetBufferFromVABufferID(mediaCtx, filter);
4163         DDI_VP_CHK_NULL(filterBuf, "nullptr filterBuf!", VA_STATUS_ERROR_INVALID_BUFFER);
4164 
4165         DDI_VP_CHK_CONDITION((VAProcFilterParameterBufferType != filterBuf->uiType),
4166             "Invalid parameter buffer type!",
4167             VA_STATUS_ERROR_INVALID_PARAMETER);
4168 
4169         // Map Buffer data to virtual addres space
4170         MediaLibvaInterfaceNext::MapBuffer(vaDrvCtx, filter, &data);
4171 
4172         filterParam = (VAProcFilterParameterBufferBase *)data;
4173 
4174         // HSBC can only be applied to the primary layer
4175         if (!((filterParam->type == VAProcFilterColorBalance) && vpHalSrcSurf->SurfType != SURF_IN_PRIMARY))
4176         {
4177             // Pass the filter type
4178             vaStatus = DdiUpdateFilterParamBuffer(vaDrvCtx, vpCtx, surfIndex, filterParam->type, data, filterBuf->uiNumElements, &vpStateFlags);
4179             DDI_CHK_RET(vaStatus, "Failed to update parameter buffer!");
4180         }
4181     }
4182 
4183     DdiClearFilterParamBuffer(vpCtx, surfIndex, vpStateFlags);
4184 
4185     // Use Render to do scaling for resolution larger than 8K
4186     if (MEDIA_IS_WA(&mediaCtx->WaTable, WaDisableVeboxFor8K))
4187     {
4188         vpHalRenderParams->bDisableVeboxFor8K = true;
4189     }
4190 
4191     // Scaling algorithm
4192     scalingflags                    = pipelineParam->filter_flags & VA_FILTER_SCALING_MASK;
4193     vpHalSrcSurf->ScalingPreference = VPHAL_SCALING_PREFER_SFC;  // default
4194     // Interpolation method
4195 #if VA_CHECK_VERSION(1, 9, 0)
4196     interpolationflags = pipelineParam->filter_flags & VA_FILTER_INTERPOLATION_MASK;
4197 #endif
4198     switch (scalingflags)
4199     {
4200     case VA_FILTER_SCALING_FAST:
4201         if (vpHalSrcSurf->SurfType == SURF_IN_PRIMARY)
4202         {
4203             VpSetInterpolationParams(vpHalSrcSurf, interpolationflags);
4204             vpHalSrcSurf->ScalingPreference = VPHAL_SCALING_PREFER_SFC_FOR_VEBOX;
4205         }
4206         else
4207         {
4208             vpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
4209         }
4210         break;
4211     case VA_FILTER_SCALING_HQ:
4212         if (vpHalSrcSurf->SurfType == SURF_IN_PRIMARY)
4213         {
4214             VpSetInterpolationParams(vpHalSrcSurf, interpolationflags);
4215             vpHalSrcSurf->ScalingPreference = VPHAL_SCALING_PREFER_COMP;
4216         }
4217         else
4218         {
4219             vpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
4220         }
4221         break;
4222     case VA_FILTER_SCALING_DEFAULT:
4223     case VA_FILTER_SCALING_NL_ANAMORPHIC:
4224     default:
4225         if (vpHalSrcSurf->SurfType == SURF_IN_PRIMARY)
4226         {
4227             VpSetInterpolationParams(vpHalSrcSurf, interpolationflags);
4228             vpHalSrcSurf->ScalingPreference = VPHAL_SCALING_PREFER_SFC;
4229         }
4230         else
4231         {
4232             vpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
4233         }
4234         break;
4235     }
4236     //init interlace scaling flag
4237     vpHalSrcSurf->bInterlacedScaling = false;
4238     vpHalSrcSurf->bFieldWeaving      = false;
4239 
4240     if (vpHalSrcSurf->pDeinterlaceParams == nullptr)
4241     {
4242         if (pipelineParam->input_surface_flag & VA_TOP_FIELD_FIRST)
4243         {
4244             vaStatus = SetSurfaceParamsTopFieldFirst(pipelineParam->output_surface_flag, vpHalSrcSurf, vpHalTgtSurf);
4245             DDI_CHK_RET(vaStatus, "Failed to set params on TopFieldFirst");
4246         }
4247         else if (pipelineParam->input_surface_flag & VA_BOTTOM_FIELD_FIRST)
4248         {
4249             vaStatus = SetSurfaceParamsBottomFieldFirst(pipelineParam->output_surface_flag, vpHalSrcSurf, vpHalTgtSurf);
4250             DDI_CHK_RET(vaStatus, "Failed to set params on BottomFieldFirst");
4251         }
4252         else if (pipelineParam->input_surface_flag & VA_TOP_FIELD)
4253         {
4254             vaStatus = SetSurfaceParamsTopField(pipelineParam->output_surface_flag, vpHalSrcSurf, vpHalTgtSurf);
4255             DDI_CHK_RET(vaStatus, "Failed to set params on TopField");
4256         }
4257         else if (pipelineParam->input_surface_flag & VA_BOTTOM_FIELD)
4258         {
4259             vaStatus = SetSurfaceParamsBottomField(pipelineParam->output_surface_flag, vpHalSrcSurf, vpHalTgtSurf);
4260             DDI_CHK_RET(vaStatus, "Failed to set params on BottomField");
4261         }
4262         else
4263         {
4264             vpHalSrcSurf->SampleType            = SAMPLE_PROGRESSIVE;
4265             vpHalSrcSurf->InterlacedScalingType = ISCALING_NONE;
4266             vpHalSrcSurf->bInterlacedScaling    = false;
4267             vpHalSrcSurf->bFieldWeaving         = false;
4268         }
4269     }
4270 
4271     // For legacy interlace scaling
4272     SetLegacyInterlaceScalingParams(vpHalSrcSurf, pipelineParam->filter_flags);
4273 
4274     // For weave DI
4275     VpUpdateWeaveDI(vpHalSrcSurf, pipelineParam->filter_flags);
4276 
4277     // Rotation
4278     vaStatus = VpUpdateProcRotateState(vpHalSrcSurf, pipelineParam->rotation_state);
4279     DDI_CHK_RET(vaStatus, "Failed to update rotate state!");
4280 
4281     // Mirror
4282     vaStatus = VpUpdateProcMirrorState(vpHalSrcSurf, pipelineParam->mirror_state);
4283     DDI_CHK_RET(vaStatus, "Failed to update mirror state!");
4284 
4285     // Alpha blending
4286     // Note: the alpha blending region cannot overlay
4287     vaStatus = DdiSetProcPipelineBlendingParams(vpCtx, surfIndex, pipelineParam);
4288     DDI_CHK_RET(vaStatus, "Failed to update Alpha Blending parameter!");
4289 
4290     if (IsProcmpEnable(vpHalSrcSurf))
4291     {
4292         // correct the ChromaSitting location if Procamp is enabled.
4293 #if (VA_MAJOR_VERSION < 1)
4294         pipelineParam->input_surface_flag   = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
4295         pipelineParam->output_surface_flag = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
4296 #else
4297         pipelineParam->input_color_properties.chroma_sample_location = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
4298         pipelineParam->output_color_properties.chroma_sample_location = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
4299 #endif
4300     }
4301 
4302 #if (VA_MAJOR_VERSION < 1)
4303     VpUpdateProcChromaSittingState(vpHalSrcSurf, (uint8_t)(pipelineParam->input_surface_flag & 0xff));
4304     VpUpdateProcChromaSittingState(vpHalTgtSurf, (uint8_t)(pipelineParam->output_surface_flag & 0xff));
4305 #else
4306     VpUpdateProcChromaSittingState(vpHalSrcSurf, pipelineParam->input_color_properties.chroma_sample_location);
4307     VpUpdateProcChromaSittingState(vpHalTgtSurf, pipelineParam->output_color_properties.chroma_sample_location);
4308 #endif
4309     // update OsResource for src surface
4310     vpHalSrcSurf->OsResource.Format      = MediaLibvaUtilNext::GetFormatFromMediaFormat(mediaSrcSurf->format);
4311     vpHalSrcSurf->OsResource.iWidth      = mediaSrcSurf->iWidth;
4312     vpHalSrcSurf->OsResource.iHeight     = mediaSrcSurf->iHeight;
4313     vpHalSrcSurf->OsResource.iPitch      = mediaSrcSurf->iPitch;
4314     vpHalSrcSurf->OsResource.iCount      = mediaSrcSurf->iRefCount;
4315     vpHalSrcSurf->OsResource.bo          = mediaSrcSurf->bo;
4316     vpHalSrcSurf->OsResource.TileType    = MediaLibvaUtilNext::GetTileTypeFromMediaTileType(mediaSrcSurf->TileType);
4317     vpHalSrcSurf->OsResource.pGmmResInfo = mediaSrcSurf->pGmmResourceInfo;
4318 
4319     Mos_Solo_SetOsResource(mediaSrcSurf->pGmmResourceInfo, &vpHalSrcSurf->OsResource);
4320 
4321     //Set encryption bit for input surface
4322     //This setting only used for secure VPP test app which do secure VP and provide secure YUV as input
4323     //Since APP cannot set encryption flag, it will set input_surface_flag to ask driver add encryption bit to input surface
4324     if (osInterface->osCpInterface->IsHMEnabled() && (pipelineParam->input_surface_flag & VPHAL_SURFACE_ENCRYPTION_FLAG))
4325     {
4326         osInterface->osCpInterface->SetResourceEncryption(&(vpHalSrcSurf->OsResource), true);
4327     }
4328 
4329     // Update the Render Target params - this needs to be done once when Render Target is passed via BeginPicture
4330     vaStatus = DdiUpdateVphalTargetSurfColorSpace(vaDrvCtx, vpCtx, pipelineParam, 0);
4331     DDI_CHK_RET(vaStatus, "Failed to update vphal target surface color space!");
4332     // Update the Render Target HDR params - this needs to be done once when Render Target is passed via BeginPicture
4333     vaStatus = VpUpdateProcHdrState(vpHalTgtSurf, pipelineParam->output_hdr_metadata);
4334     DDI_CHK_RET(vaStatus, "Failed to update vphal target surface HDR metadata!");
4335 
4336     // Using additional_outputs processing as 1:N case.
4337     for (i = 0; i < pipelineParam->num_additional_outputs; i++)
4338     {
4339         vaStatus = DdiBeginPictureInt(vaDrvCtx, vpCtx, pipelineParam->additional_outputs[i]);
4340         DDI_CHK_RET(vaStatus, "Failed to update vphal target surface buffers!");
4341         vaStatus = DdiUpdateVphalTargetSurfColorSpace(vaDrvCtx, vpCtx, pipelineParam, i + 1);
4342         DDI_CHK_RET(vaStatus, "Failed to update vphal target surface color space!");
4343     }
4344 
4345     // add 16aligned UsrPtr mode support
4346     if (mediaSrcSurf->pSurfDesc && (mediaSrcSurf->pSurfDesc->uiVaMemType == VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR))
4347     {
4348         vpHalSrcSurf->b16UsrPtr = VpIs16UsrPtrPitch(mediaSrcSurf->iPitch, mediaSrcSurf->format); // VpIs16UsrPtrPitch  define in beginPicture
4349     }
4350     else
4351     {
4352         vpHalSrcSurf->b16UsrPtr = false;
4353     }
4354 
4355     return VA_STATUS_SUCCESS;
4356 }
4357 
StatusCheck(PDDI_MEDIA_CONTEXT mediaCtx,DDI_MEDIA_SURFACE * surface,VASurfaceID surfaceId)4358 VAStatus DdiVpFunctions::StatusCheck(
4359     PDDI_MEDIA_CONTEXT mediaCtx,
4360     DDI_MEDIA_SURFACE  *surface,
4361     VASurfaceID        surfaceId)
4362 {
4363     PDDI_VP_CONTEXT         vpCtx        = nullptr;
4364     QUERY_STATUS_REPORT_APP tempVpReport = {};
4365     DDI_MEDIA_SURFACE       *tempSurface = nullptr;
4366     MOS_STATUS              eStatus      = MOS_STATUS_SUCCESS;
4367     DDI_VP_FUNC_ENTER;
4368 
4369     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
4370     DDI_VP_CHK_NULL(surface,  "nullptr surface",  VA_STATUS_ERROR_INVALID_CONTEXT);
4371 
4372     vpCtx = (PDDI_VP_CONTEXT)surface->pVpCtx;
4373     DDI_VP_CHK_NULL(vpCtx ,        "nullptr vpCtx",         VA_STATUS_ERROR_INVALID_CONTEXT);
4374     DDI_VP_CHK_NULL(vpCtx->pVpHal ,"nullptr vpCtx->pVpHal", VA_STATUS_ERROR_INVALID_CONTEXT);
4375 
4376     MOS_ZeroMemory(&tempVpReport, sizeof(QUERY_STATUS_REPORT_APP));
4377 
4378     // Get reported surfaces' count
4379     uint32_t tableLen = 0;
4380     eStatus = vpCtx->pVpHal->GetStatusReportEntryLength(&tableLen);
4381     if(eStatus != MOS_STATUS_SUCCESS)
4382     {
4383         return VA_STATUS_ERROR_OPERATION_FAILED;
4384     }
4385     if (tableLen > 0 && surface->curStatusReportQueryState == DDI_MEDIA_STATUS_REPORT_QUERY_STATE_PENDING)
4386     {
4387         // Query the status for all of surfaces which have finished
4388         for(uint32_t i = 0; i < tableLen; i++)
4389         {
4390             MOS_ZeroMemory(&tempVpReport, sizeof(QUERY_STATUS_REPORT_APP));
4391             eStatus = vpCtx->pVpHal->GetStatusReport(&tempVpReport, 1);
4392             if(eStatus != MOS_STATUS_SUCCESS)
4393             {
4394                 return VA_STATUS_ERROR_OPERATION_FAILED;
4395             }
4396             // StatusFeedBackID is last time submitted Target Surface ID which is set in BeginPicture,
4397             // So we can know the report is for which surface here.
4398             tempSurface = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, tempVpReport.StatusFeedBackID);
4399             DDI_VP_CHK_NULL(tempSurface,  "nullptr tempSurface",  VA_STATUS_ERROR_OPERATION_FAILED);
4400 
4401             // Update the status of the surface which is reported.
4402             tempSurface->curStatusReport.vpp.status = (uint32_t)tempVpReport.dwStatus;
4403             tempSurface->curStatusReportQueryState  = DDI_MEDIA_STATUS_REPORT_QUERY_STATE_COMPLETED;
4404 
4405             if(tempVpReport.StatusFeedBackID == surfaceId)
4406             {
4407                 break;
4408             }
4409         }
4410     }
4411 
4412     if (surface->curStatusReportQueryState != DDI_MEDIA_STATUS_REPORT_QUERY_STATE_COMPLETED)
4413     {
4414         return VA_STATUS_ERROR_OPERATION_FAILED;
4415     }
4416 
4417     if(surface->curStatusReport.vpp.status == VPREP_OK)
4418     {
4419         return VA_STATUS_SUCCESS;
4420     }
4421     else if(surface->curStatusReport.vpp.status == VPREP_NOTREADY)
4422     {
4423         return mediaCtx->bMediaResetEnable ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_HW_BUSY;
4424     }
4425     else
4426     {
4427         return VA_STATUS_ERROR_OPERATION_FAILED;
4428     }
4429     return VA_STATUS_SUCCESS;
4430 }
4431 
ProcessPipeline(VADriverContextP vaDrvCtx,VAContextID ctxID,VASurfaceID srcSurface,VARectangle * srcRect,VASurfaceID dstSurface,VARectangle * dstRect)4432 VAStatus DdiVpFunctions::ProcessPipeline(
4433     VADriverContextP    vaDrvCtx,
4434     VAContextID         ctxID,
4435     VASurfaceID         srcSurface,
4436     VARectangle         *srcRect,
4437     VASurfaceID         dstSurface,
4438     VARectangle         *dstRect)
4439 {
4440     PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
4441 
4442     VAStatus                      vaStatus            = VA_STATUS_SUCCESS;
4443     uint32_t                      ctxType             = DDI_MEDIA_CONTEXT_TYPE_NONE;
4444     PDDI_VP_CONTEXT               vpCtx               = nullptr;
4445     VAProcPipelineParameterBuffer *inputPipelineParam = nullptr;
4446 
4447     DDI_VP_FUNC_ENTER;
4448     DDI_VP_CHK_NULL(vaDrvCtx, "nullptr vaDrvCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
4449 
4450     vpCtx = (PDDI_VP_CONTEXT)MediaLibvaCommonNext::GetContextFromContextID(vaDrvCtx, ctxID, &ctxType);
4451     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
4452 
4453     vaStatus = BeginPicture(vaDrvCtx, ctxID, dstSurface);
4454     DDI_CHK_RET(vaStatus, "VP BeginPicture failed");
4455 
4456     //Set parameters
4457     inputPipelineParam = (VAProcPipelineParameterBuffer*)MOS_AllocAndZeroMemory(sizeof(VAProcPipelineParameterBuffer));
4458     DDI_VP_CHK_NULL(inputPipelineParam, "nullptr inputPipelineParam", VA_STATUS_ERROR_ALLOCATION_FAILED);
4459 
4460     inputPipelineParam->surface_region = srcRect;
4461     inputPipelineParam->output_region  = dstRect;
4462     inputPipelineParam->surface        = srcSurface;
4463 
4464     vaStatus = DdiSetProcPipelineParams(vaDrvCtx, vpCtx, inputPipelineParam);
4465     if(vaStatus != VA_STATUS_SUCCESS)
4466     {
4467         MOS_FreeMemory(inputPipelineParam);
4468         DDI_VP_ASSERTMESSAGE("VP SetProcPipelineParams failed.");
4469         return vaStatus;
4470     }
4471 
4472     vaStatus = EndPicture(vaDrvCtx, ctxID);
4473     if(vaStatus != VA_STATUS_SUCCESS)
4474     {
4475         MOS_FreeMemory(inputPipelineParam);
4476         DDI_VP_ASSERTMESSAGE("VP EndPicture failed.");
4477         return vaStatus;
4478     }
4479 
4480     MOS_FreeMemory(inputPipelineParam);
4481     return vaStatus;
4482 }
4483 
PutSurface(VADriverContextP ctx,VASurfaceID surface,void * draw,int16_t srcx,int16_t srcy,uint16_t srcw,uint16_t srch,int16_t destx,int16_t desty,uint16_t destw,uint16_t desth,VARectangle * cliprects,uint32_t numberCliprects,uint32_t flags)4484 VAStatus DdiVpFunctions::PutSurface(
4485     VADriverContextP ctx,
4486     VASurfaceID      surface,
4487     void             *draw,
4488     int16_t          srcx,
4489     int16_t          srcy,
4490     uint16_t         srcw,
4491     uint16_t         srch,
4492     int16_t          destx,
4493     int16_t          desty,
4494     uint16_t         destw,
4495     uint16_t         desth,
4496     VARectangle      *cliprects,
4497     uint32_t         numberCliprects,
4498     uint32_t         flags)
4499 {
4500     void               *vpCtx      = nullptr;
4501     PDDI_MEDIA_CONTEXT mediaDrvCtx = nullptr;
4502     uint32_t           ctxType     = DDI_MEDIA_CONTEXT_TYPE_NONE;
4503     DDI_VP_FUNC_ENTER;
4504 
4505     mediaDrvCtx = GetMediaContext(ctx);
4506     DDI_VP_CHK_NULL(mediaDrvCtx,               "nullptr mediaDrvCtx",               VA_STATUS_ERROR_INVALID_CONTEXT);
4507     DDI_VP_CHK_NULL(mediaDrvCtx->pSurfaceHeap, "nullptr mediaDrvCtx->pSurfaceHeap", VA_STATUS_ERROR_INVALID_CONTEXT);
4508     DDI_VP_CHK_NULL(mediaDrvCtx->pVpCtxHeap,   "nullptr mediaDrvCtx->pVpCtxHeap",   VA_STATUS_ERROR_INVALID_CONTEXT);
4509     DDI_CHK_LESS((uint32_t)surface, mediaDrvCtx->pSurfaceHeap->uiAllocatedHeapElements, "Invalid surface", VA_STATUS_ERROR_INVALID_SURFACE);
4510 
4511     if (nullptr != mediaDrvCtx->pVpCtxHeap->pHeapBase)
4512     {
4513         vpCtx = MediaLibvaCommonNext::GetContextFromContextID(ctx, (VAContextID)(DDI_MEDIA_SOFTLET_VACONTEXTID_VP_OFFSET), &ctxType);
4514     }
4515 
4516 #if defined(ANDROID) || !defined(X11_FOUND)
4517     return VA_STATUS_ERROR_UNIMPLEMENTED;
4518 #else
4519     if(nullptr == vpCtx)
4520     {
4521         VAContextID context  = VA_INVALID_ID;
4522         VAStatus    vaStatus = CreateContext(ctx, 0, 0, 0, 0, 0, 0, &context);
4523         DDI_CHK_RET(vaStatus, "Create VP Context failed");
4524     }
4525     return PutSurfaceLinuxHW(ctx, surface, draw, srcx, srcy, srcw, srch, destx, desty, destw, desth, cliprects, numberCliprects, flags);
4526 #endif
4527 
4528     return VA_STATUS_SUCCESS;
4529 }
4530 
4531 #if !defined(ANDROID) && defined(X11_FOUND)
4532 
RectInit(RECT * rect,int16_t destx,int16_t desty,uint16_t destw,uint16_t desth)4533 void DdiVpFunctions::RectInit(
4534     RECT            *rect,
4535     int16_t         destx,
4536     int16_t         desty,
4537     uint16_t        destw,
4538     uint16_t        desth)
4539 {
4540     DDI_VP_FUNC_ENTER;
4541     DDI_VP_CHK_NULL(rect, "nullptr rect", );
4542 
4543     rect->left   = destx;
4544     rect->top    = desty;
4545     rect->right  = destx + destw;
4546     rect->bottom = desty + desth;
4547     return;
4548 }
4549 
PutSurfaceLinuxHW(VADriverContextP ctx,VASurfaceID surface,void * draw,int16_t srcx,int16_t srcy,uint16_t srcw,uint16_t srch,int16_t destx,int16_t desty,uint16_t destw,uint16_t desth,VARectangle * cliprects,uint32_t numberCliprects,uint32_t flags)4550 VAStatus DdiVpFunctions::PutSurfaceLinuxHW(
4551     VADriverContextP ctx,
4552     VASurfaceID      surface,
4553     void             *draw,
4554     int16_t          srcx,
4555     int16_t          srcy,
4556     uint16_t         srcw,
4557     uint16_t         srch,
4558     int16_t          destx,
4559     int16_t          desty,
4560     uint16_t         destw,
4561     uint16_t         desth,
4562     VARectangle      *cliprects,
4563     uint32_t         numberCliprects,
4564     uint32_t         flags)
4565 {
4566     VpBase                 *vpHal        = nullptr;
4567     int32_t                ovRenderIndex = 0;
4568     VPHAL_SURFACE          surf          = {};
4569     VPHAL_SURFACE          target        = {};
4570     VPHAL_RENDER_PARAMS    renderParams  = {};
4571     VPHAL_COLORFILL_PARAMS colorFill     = {};
4572     MOS_STATUS             eStatus       = MOS_STATUS_INVALID_PARAMETER;
4573     RECT                   srcRect       = { 0, 0, 0, 0 };
4574     RECT                   dstRect       = { 0, 0, 0, 0 };
4575     PDDI_MEDIA_CONTEXT     mediaCtx      = nullptr;
4576     PDDI_MEDIA_SURFACE     bufferObject  = nullptr;
4577     uint32_t               width = 0,height = 0,pitch = 0;
4578     uint32_t               drawableTilingMode  = 0;
4579     uint32_t               drawableSwizzleMode = 0;
4580     MOS_TILE_TYPE          tileType            = MOS_TILE_INVALID;
4581     uint32_t               ctxType             = 0;
4582     PDDI_VP_CONTEXT        vpCtx               = nullptr;
4583     struct dri_drawable    *driDrawable        = nullptr;
4584     union dri_buffer       *buffer             = nullptr;
4585     GMM_RESCREATE_PARAMS   gmmParams           = {};
4586 
4587     DDI_VP_FUNC_ENTER;
4588 
4589     mediaCtx = GetMediaContext(ctx);
4590     DDI_VP_CHK_NULL(mediaCtx, "nullptr mediaCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
4591     DDI_VP_CHK_NULL(mediaCtx->dri_output, "nullptr mediaDrvCtx->dri_output", VA_STATUS_ERROR_INVALID_PARAMETER);
4592     DDI_VP_CHK_NULL(mediaCtx->pSurfaceHeap, "nullptr mediaDrvCtx->pSurfaceHeap", VA_STATUS_ERROR_INVALID_PARAMETER);
4593     DDI_VP_CHK_NULL(mediaCtx->pGmmClientContext, "nullptr mediaCtx->pGmmClientContext", VA_STATUS_ERROR_INVALID_PARAMETER);
4594     DDI_VP_CHK_NULL(mediaCtx->pVpCtxHeap, "nullptr mediaCtx->pVpCtxHeap", VA_STATUS_ERROR_INVALID_PARAMETER);
4595     DDI_VP_CHK_NULL(mediaCtx->pVpCtxHeap->pHeapBase, "nullptr mediaCtx->pVpCtxHeap->pHeapBase", VA_STATUS_ERROR_INVALID_CONTEXT);
4596 
4597     DDI_CHK_LESS((uint32_t)surface, mediaCtx->pSurfaceHeap->uiAllocatedHeapElements, "Invalid surfaceId", VA_STATUS_ERROR_INVALID_SURFACE);
4598 
4599     struct dri_vtable *const driVtable = &mediaCtx->dri_output->vtable;
4600     DDI_VP_CHK_NULL(driVtable, "nullptr driVtable", VA_STATUS_ERROR_INVALID_PARAMETER);
4601 
4602     driDrawable = driVtable->get_drawable(ctx, (Drawable)draw);
4603     DDI_VP_CHK_NULL(driDrawable, "nullptr driDrawable", VA_STATUS_ERROR_INVALID_PARAMETER);
4604     buffer = driVtable->get_rendering_buffer(ctx, driDrawable);
4605     DDI_VP_CHK_NULL(buffer, "nullptr buffer", VA_STATUS_ERROR_INVALID_PARAMETER);
4606 
4607     bufferObject = MediaLibvaCommonNext::GetSurfaceFromVASurfaceID(mediaCtx, surface);
4608     DDI_VP_CHK_NULL(bufferObject, "nullptr bufferObject", VA_STATUS_ERROR_INVALID_SURFACE);
4609     MediaLibvaUtilNext::MediaPrintFps();
4610     pitch = bufferObject->iPitch;
4611 
4612     vpCtx = (PDDI_VP_CONTEXT)MediaLibvaCommonNext::GetContextFromContextID(ctx, (VAContextID)(DDI_MEDIA_SOFTLET_VACONTEXTID_VP_OFFSET), &ctxType);
4613     DDI_VP_CHK_NULL(vpCtx, "nullptr vpCtx", VA_STATUS_ERROR_INVALID_PARAMETER);
4614     vpHal = vpCtx->pVpHal;
4615     DDI_VP_CHK_NULL(vpHal, "nullptr vpHal", VA_STATUS_ERROR_INVALID_PARAMETER);
4616 
4617     renderParams.Component = COMPONENT_LibVA;
4618 
4619     //Init source rectangle
4620     RectInit(&srcRect, srcx, srcy, srcw, srch);
4621     RectInit(&dstRect, destx, desty, destw, desth);
4622 
4623     if (destx + destw > driDrawable->x + driDrawable->width)
4624     {
4625         dstRect.right = driDrawable->x + driDrawable->width - destx;
4626         if(dstRect.right <= 0)
4627         {
4628             return VA_STATUS_SUCCESS;
4629         }
4630     }
4631     if (desty + desth > driDrawable->y + driDrawable->height)
4632     {
4633         dstRect.bottom = driDrawable->y + driDrawable->height - desty;
4634         if(dstRect.bottom <= 0)
4635         {
4636             return VA_STATUS_SUCCESS;
4637         }
4638     }
4639     // Source Surface Information
4640     surf.Format                 = MediaLibvaUtilNext::GetFormatFromMediaFormat(bufferObject->format);  // Surface format
4641     surf.SurfType               = SURF_IN_PRIMARY;                                   // Surface type (context)
4642     surf.SampleType             = SAMPLE_PROGRESSIVE;
4643     surf.ScalingMode            = VPHAL_SCALING_AVS;
4644 
4645     surf.OsResource.Format      = MediaLibvaUtilNext::GetFormatFromMediaFormat(bufferObject->format);
4646     surf.OsResource.iWidth      = bufferObject->iWidth;
4647     surf.OsResource.iHeight     = bufferObject->iHeight;
4648     surf.OsResource.iPitch      = bufferObject->iPitch;
4649     surf.OsResource.iCount      = 0;
4650     surf.OsResource.TileType    = MediaLibvaUtilNext::GetTileTypeFromMediaTileType(bufferObject->TileType);
4651     surf.OsResource.bMapped     = bufferObject->bMapped;
4652     surf.OsResource.bo          = bufferObject->bo;
4653     surf.OsResource.pGmmResInfo = bufferObject->pGmmResourceInfo;
4654 
4655     surf.dwWidth                = bufferObject->iWidth;
4656     surf.dwHeight               = bufferObject->iHeight;
4657     surf.dwPitch                = bufferObject->iPitch;
4658     surf.TileType               = MediaLibvaUtilNext::GetTileTypeFromMediaTileType(bufferObject->TileType);
4659     surf.ColorSpace             = MediaLibvaUtilNext::GetColorSpaceFromMediaFormat(bufferObject->format);
4660     surf.ExtendedGamut          = false;
4661     surf.rcSrc                  = srcRect;
4662     surf.rcDst                  = dstRect;
4663 
4664     MOS_LINUX_BO *drawableBo = mos_bo_create_from_name(mediaCtx->pDrmBufMgr, "rendering buffer", buffer->dri2.name);
4665     DDI_VP_CHK_NULL(drawableBo, "nullptr drawableBo", VA_STATUS_ERROR_ALLOCATION_FAILED);
4666 
4667     if (!mos_bo_get_tiling(drawableBo, &drawableTilingMode, &drawableSwizzleMode))
4668     {
4669         switch (drawableTilingMode)
4670         {
4671             case TILING_Y:
4672                 tileType = MOS_TILE_Y;
4673                 break;
4674             case TILING_X:
4675                 tileType = MOS_TILE_X;
4676                 gmmParams.Flags.Info.TiledX    = true;
4677                 break;
4678             case TILING_NONE:
4679                tileType = MOS_TILE_LINEAR;
4680                gmmParams.Flags.Info.Linear    = true;
4681                break;
4682             default:
4683                 drawableTilingMode          = TILING_NONE;
4684                 tileType = MOS_TILE_LINEAR;
4685                 gmmParams.Flags.Info.Linear    = true;
4686                 break;
4687         }
4688         target.OsResource.TileType = (MOS_TILE_TYPE)drawableTilingMode;
4689     }
4690     else
4691     {
4692         target.OsResource.TileType = (MOS_TILE_TYPE)TILING_NONE;
4693         tileType = MOS_TILE_LINEAR;
4694         gmmParams.Flags.Info.Linear    = true;
4695     }
4696     gmmParams.Flags.Info.LocalOnly = MEDIA_IS_SKU(&mediaCtx->SkuTable, FtrLocalMemory);
4697 
4698     target.Format                = Format_A8R8G8B8;
4699     target.SurfType              = SURF_OUT_RENDERTARGET;
4700 
4701     //init target retangle
4702     RectInit(&srcRect, driDrawable->x, driDrawable->y, driDrawable->width, driDrawable->height);
4703     RectInit(&dstRect, driDrawable->x, driDrawable->y, driDrawable->width, driDrawable->height);
4704 
4705     // Create GmmResourceInfo
4706     gmmParams.Flags.Gpu.Video       = true;
4707     gmmParams.BaseWidth             = driDrawable->width;
4708     gmmParams.BaseHeight            = driDrawable->height;
4709     gmmParams.ArraySize             = 1;
4710     gmmParams.Type                  = RESOURCE_2D;
4711     gmmParams.Format                = GMM_FORMAT_R8G8B8A8_UNORM_TYPE;
4712     //gmmParams.Format                = GMM_FORMAT_B8G8R8A8_UNORM_TYPE;
4713     target.OsResource.pGmmResInfo = mediaCtx->pGmmClientContext->CreateResInfoObject(&gmmParams);
4714     if (nullptr == target.OsResource.pGmmResInfo)
4715     {
4716         mos_bo_unreference(drawableBo);
4717         return VA_STATUS_ERROR_ALLOCATION_FAILED;
4718     }
4719 
4720     target.OsResource.iWidth     = driDrawable->width;
4721     target.OsResource.iHeight    = driDrawable->height;
4722     target.OsResource.iPitch     = buffer->dri2.pitch;
4723     target.OsResource.Format     = Format_A8R8G8B8;
4724     target.OsResource.iCount     = 0;
4725     target.OsResource.bo         = drawableBo;
4726     target.OsResource.pData      = (uint8_t *)drawableBo->virt;
4727     target.OsResource.TileType   = tileType;
4728     target.TileType              = tileType;
4729     target.dwWidth               = driDrawable->width;
4730     target.dwHeight              = driDrawable->height;
4731     target.dwPitch               = target.OsResource.iPitch;
4732     target.ColorSpace            = CSpace_sRGB;
4733     target.ExtendedGamut         = false;
4734     target.rcSrc                 = srcRect;
4735     target.rcDst                 = dstRect;
4736 
4737     renderParams.uSrcCount                  = 1;
4738     renderParams.uDstCount                  = 1;
4739     renderParams.pSrc[0]                    = &surf;
4740     renderParams.pTarget[0]                 = &target;
4741     renderParams.pColorFillParams           = &colorFill;
4742     renderParams.pColorFillParams->Color    = 0xFF000000;
4743     renderParams.pColorFillParams->bYCbCr   = false;
4744     renderParams.pColorFillParams->CSpace   = CSpace_sRGB;
4745 
4746     MosUtilities::MosLockMutex(&mediaCtx->PutSurfaceRenderMutex);
4747     eStatus = vpHal->Render(&renderParams);
4748     if (MOS_FAILED(eStatus))
4749     {
4750         MosUtilities::MosUnlockMutex(&mediaCtx->PutSurfaceRenderMutex);
4751         mos_bo_unreference(drawableBo);
4752         return VA_STATUS_ERROR_OPERATION_FAILED;
4753     }
4754 
4755     MosUtilities::MosUnlockMutex(&mediaCtx->PutSurfaceRenderMutex);
4756     mos_bo_unreference(drawableBo);
4757     target.OsResource.bo         = nullptr;
4758     MosUtilities::MosLockMutex(&mediaCtx->PutSurfaceSwapBufferMutex);
4759     driVtable->swap_buffer(ctx, driDrawable);
4760     MosUtilities::MosUnlockMutex(&mediaCtx->PutSurfaceSwapBufferMutex);
4761 
4762     mediaCtx->pGmmClientContext->DestroyResInfoObject(target.OsResource.pGmmResInfo);
4763     target.OsResource.pGmmResInfo = nullptr;
4764 
4765     return VA_STATUS_SUCCESS;
4766 }
4767 #endif // !defined(ANDROID) && defined(X11_FOUND)
4768