diff --git a/media_driver/linux/common/ddi/media_libva.cpp b/media_driver/linux/common/ddi/media_libva.cpp index 8250bd0c98d..e03a2928d04 100755 --- a/media_driver/linux/common/ddi/media_libva.cpp +++ b/media_driver/linux/common/ddi/media_libva.cpp @@ -1829,6 +1829,7 @@ VAStatus DdiMedia__Initialize ( // return VA_STATUS_ERROR_UNIMPLEMENTED directly. ctx->vtable->vaPutSurface = NULL; } + mediaCtx->PutSurfaceContext = VA_INVALID_ID; output_dri_init(ctx); #endif @@ -3961,21 +3962,9 @@ static VAStatus DdiMedia_PutSurface( DDI_CHK_LESS((uint32_t)surface, mediaDrvCtx->pSurfaceHeap->uiAllocatedHeapElements, "Invalid surface", VA_STATUS_ERROR_INVALID_SURFACE); - if (nullptr != mediaDrvCtx->pVpCtxHeap->pHeapBase) - { - uint32_t ctxType = DDI_MEDIA_CONTEXT_TYPE_NONE; - vpCtx = DdiMedia_GetContextFromContextID(ctx, (VAContextID)(0 + DDI_MEDIA_VACONTEXTID_OFFSET_VP), &ctxType); - } - #if defined(ANDROID) || !defined(X11_FOUND) return VA_STATUS_ERROR_UNIMPLEMENTED; #else - if(nullptr == vpCtx) - { - VAContextID context = VA_INVALID_ID; - VAStatus vaStatus = DdiVp_CreateContext(ctx, 0, 0, 0, 0, 0, 0, &context); - DDI_CHK_RET(vaStatus, "Create VP Context failed"); - } return DdiCodec_PutSurfaceLinuxHW(ctx, surface, draw, srcx, srcy, srcw, srch, destx, desty, destw, desth, cliprects, number_cliprects, flags); #endif diff --git a/media_driver/linux/common/ddi/media_libva_common.h b/media_driver/linux/common/ddi/media_libva_common.h index e2a2601ce0a..9754feb8199 100644 --- a/media_driver/linux/common/ddi/media_libva_common.h +++ b/media_driver/linux/common/ddi/media_libva_common.h @@ -509,6 +509,7 @@ struct DDI_MEDIA_CONTEXT //vpgPutSurfaceLinuxHW acceleration hack MEDIA_MUTEX_T PutSurfaceRenderMutex; MEDIA_MUTEX_T PutSurfaceSwapBufferMutex; + VAContextID PutSurfaceContext; #endif bool apoMosEnabled; }; diff --git a/media_driver/linux/common/ddi/media_libva_putsurface_linux.cpp b/media_driver/linux/common/ddi/media_libva_putsurface_linux.cpp index 1cb2a6762df..9956c88e898 100644 --- a/media_driver/linux/common/ddi/media_libva_putsurface_linux.cpp +++ b/media_driver/linux/common/ddi/media_libva_putsurface_linux.cpp @@ -399,18 +399,19 @@ VAStatus DdiCodec_PutSurfaceLinuxHW( DdiMediaUtil_MediaPrintFps(); pitch = bufferObject->iPitch; - vpCtx = nullptr; - if (nullptr != mediaCtx->pVpCtxHeap->pHeapBase) - { - vpCtx = (PDDI_VP_CONTEXT)DdiMedia_GetContextFromContextID(ctx, (VAContextID)(0 + DDI_MEDIA_VACONTEXTID_OFFSET_VP), &ctxType); - DDI_CHK_NULL(vpCtx, "Null vpCtx", VA_STATUS_ERROR_INVALID_PARAMETER); - vpHal = vpCtx->pVpHal; - DDI_CHK_NULL(vpHal, "Null vpHal", VA_STATUS_ERROR_INVALID_PARAMETER); - } - else + DdiMediaUtil_LockMutex(&mediaCtx->PutSurfaceRenderMutex); + if (mediaCtx->PutSurfaceContext == VA_INVALID_ID) { - return VA_STATUS_ERROR_INVALID_CONTEXT; + VAStatus vaStatus = DdiVp_CreateContext(ctx, 0, 0, 0, 0, 0, 0, &mediaCtx->PutSurfaceContext); + DdiMediaUtil_UnLockMutex(&mediaCtx->PutSurfaceRenderMutex); + DDI_CHK_RET(vaStatus, "Create VP Context failed"); + } else { + DdiMediaUtil_UnLockMutex(&mediaCtx->PutSurfaceRenderMutex); } + vpCtx = (PDDI_VP_CONTEXT)DdiMedia_GetContextFromContextID(ctx, mediaCtx->PutSurfaceContext, &ctxType); + DDI_CHK_NULL(vpCtx, "Null vpCtx", VA_STATUS_ERROR_INVALID_PARAMETER); + vpHal = vpCtx->pVpHal; + DDI_CHK_NULL(vpHal, "Null vpHal", VA_STATUS_ERROR_INVALID_PARAMETER); // Zero memory MOS_ZeroMemory(&Surf, sizeof(Surf));