From 5c7669bace2b0e0dea8ee08e5ad235df6d340cad Mon Sep 17 00:00:00 2001 From: stransky Date: Wed, 9 Apr 2025 19:34:19 +0000 Subject: [PATCH] Bug 1950039 [Linux] Get P010/NV12 DMABuf modifiers and propagate them to RDD process to create YUV surfaces with modifiers r=emilio Differential Revision: https://phabricator.services.mozilla.com/D244901 --- gfx/config/gfxVars.h | 4 +++- widget/gtk/DMABufFormats.h | 3 +++ widget/gtk/DMABufLibWrapper.cpp | 23 +++++++++++++++++++++++ widget/gtk/DMABufLibWrapper.h | 6 +++++- widget/gtk/DMABufSurface.cpp | 18 +++++++++--------- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/gfx/config/gfxVars.h b/gfx/config/gfxVars.h index 63e03dbac7c2..5c107cc081fc 100644 --- a/gfx/config/gfxVars.h +++ b/gfx/config/gfxVars.h @@ -106,7 +106,9 @@ class gfxVarReceiver; _(WebRenderOverlayVpAutoHDR, bool, false) \ _(WebRenderOverlayVpSuperResolution, bool, false) \ _(AllowWebGPUPresentWithoutReadback, bool, false) \ - _(GPUProcessEnabled, bool, false) + _(GPUProcessEnabled, bool, false) \ + _(DMABufModifiersP010, ArrayOfuint64_t, nsTArray()) \ + _(DMABufModifiersNV12, ArrayOfuint64_t, nsTArray()) /* Add new entries above this line. */ diff --git a/widget/gtk/DMABufFormats.h b/widget/gtk/DMABufFormats.h index 0cb6748a982c..6622219638ff 100644 --- a/widget/gtk/DMABufFormats.h +++ b/widget/gtk/DMABufFormats.h @@ -57,6 +57,9 @@ class DRMFormat final { aModifiersNum = mModifiers.Length(); return mModifiers.Elements(); } + uint64_t GetModifier() { + return mModifiers.Length() ? mModifiers[0] : DRM_FORMAT_MOD_INVALID; + } nsTArray* GetModifiers() { return &mModifiers; } private: diff --git a/widget/gtk/DMABufLibWrapper.cpp b/widget/gtk/DMABufLibWrapper.cpp index 8e76ce1aacc6..c2c23705b6da 100644 --- a/widget/gtk/DMABufLibWrapper.cpp +++ b/widget/gtk/DMABufLibWrapper.cpp @@ -31,6 +31,11 @@ using namespace mozilla::gfx; +#ifndef GBM_FORMAT_P010 +# define GBM_FORMAT_P010 \ + __gbm_fourcc_code('P', '0', '1', '0') /* 2x2 subsampled Cr:Cb plane */ +#endif + namespace mozilla { namespace widget { @@ -261,6 +266,18 @@ void DMABufDevice::SetModifiersToGfxVars() { MOZ_DIAGNOSTIC_ASSERT(format, "Missing GBM_FORMAT_ARGB8888 dmabuf format!"); mFormatRGBA = new DRMFormat(*format); gfxVars::SetDMABufModifiersARGB(*format->GetModifiers()); + + format = formats->GetFormat(GBM_FORMAT_P010); + if (format) { + mFormatP010 = new DRMFormat(*format); + gfxVars::SetDMABufModifiersP010(*format->GetModifiers()); + } + + format = formats->GetFormat(GBM_FORMAT_NV12); + if (format) { + mFormatNV12 = new DRMFormat(*format); + gfxVars::SetDMABufModifiersNV12(*format->GetModifiers()); + } } void DMABufDevice::GetModifiersFromGfxVars() { @@ -268,6 +285,8 @@ void DMABufDevice::GetModifiersFromGfxVars() { new DRMFormat(GBM_FORMAT_XRGB8888, gfxVars::DMABufModifiersXRGB()); mFormatRGBA = new DRMFormat(GBM_FORMAT_ARGB8888, gfxVars::DMABufModifiersARGB()); + mFormatP010 = new DRMFormat(GBM_FORMAT_P010, gfxVars::DMABufModifiersP010()); + mFormatNV12 = new DRMFormat(GBM_FORMAT_NV12, gfxVars::DMABufModifiersNV12()); } void DMABufDevice::DisableDMABufWebGL() { sUseWebGLDmabufBackend = false; } @@ -280,6 +299,10 @@ RefPtr DMABufDevice::GetDRMFormat(int32_t aFOURCCFormat) { case GBM_FORMAT_ARGB8888: MOZ_DIAGNOSTIC_ASSERT(mFormatRGBA, "Missing RGBA dmabuf format!"); return mFormatRGBA; + case GBM_FORMAT_P010: + return mFormatP010; + case GBM_FORMAT_NV12: + return mFormatNV12; default: gfxCriticalNoteOnce << "DMABufDevice::GetDRMFormat() unknow format: " << aFOURCCFormat; diff --git a/widget/gtk/DMABufLibWrapper.h b/widget/gtk/DMABufLibWrapper.h index d4848221be44..6c8befdfae55 100644 --- a/widget/gtk/DMABufLibWrapper.h +++ b/widget/gtk/DMABufLibWrapper.h @@ -222,9 +222,13 @@ class DMABufDevice { void SetModifiersToGfxVars(); void GetModifiersFromGfxVars(); - // Two basic formats, always present. + // Formats passed to RDD process to WebGL process + // where we can't get formats/modifiers from Wayland display. + // RGBA formats are mandatory, YUV ones are optional. RefPtr mFormatRGBA; RefPtr mFormatRGBX; + RefPtr mFormatP010; + RefPtr mFormatNV12; int mDRMFd = -1; std::once_flag mFlagGbmDevice; diff --git a/widget/gtk/DMABufSurface.cpp b/widget/gtk/DMABufSurface.cpp index eab2e4a9288a..44c6ee94a948 100644 --- a/widget/gtk/DMABufSurface.cpp +++ b/widget/gtk/DMABufSurface.cpp @@ -1542,7 +1542,7 @@ bool DMABufSurfaceYUV::CreateYUVPlaneGBM(int aPlane) { MOZ_DIAGNOSTIC_ASSERT(mGbmBufferObject[aPlane] == nullptr); bool useModifiers = (mBufferModifiers[aPlane] != DRM_FORMAT_MOD_INVALID); if (useModifiers) { - LOGDMABUF(" Creating with modifiers"); + LOGDMABUF(" Creating with modifier %" PRIx64, mBufferModifiers[aPlane]); mGbmBufferObject[aPlane] = GbmLib::CreateWithModifiers2( GetDMABufDevice()->GetGbmDevice(), mWidth[aPlane], mHeight[aPlane], mDrmFormats[aPlane], mBufferModifiers + aPlane, 1, @@ -1658,7 +1658,7 @@ bool DMABufSurfaceYUV::CreateYUVPlaneExport(GLContext* aGLContext, int aPlane) { return false; } - LOGDMABUF(" imported size %d x %d format %x planes %d modifiers %" PRIx64, + LOGDMABUF(" imported size %d x %d format %x planes %d modifier %" PRIx64, mWidth[aPlane], mHeight[aPlane], mFOURCCFormat, mBufferPlaneCount, mBufferModifiers[aPlane]); @@ -1735,10 +1735,6 @@ bool DMABufSurfaceYUV::UpdateYUVData( ReturnSnapshotGLContext(context); }); - // Use LINEAR modifiers - // TODO: Load modifiers from DMABuf - mBufferModifiers[0] = mBufferModifiers[1] = 0; - gfx::IntSize size = aData.YPictureSize(); mWidthAligned[0] = mWidth[0] = size.width; @@ -1763,6 +1759,10 @@ bool DMABufSurfaceYUV::UpdateYUVData( return false; } + RefPtr format = GetDMABufDevice()->GetDRMFormat(mFOURCCFormat); + mBufferModifiers[0] = mBufferModifiers[1] = + format ? format->GetModifier() : DRM_FORMAT_MOD_INVALID; + for (int i = 0; i < mBufferPlaneCount; i++) { if (!CreateYUVPlane(context, i)) { return false; @@ -1803,9 +1803,9 @@ bool DMABufSurfaceYUV::ImportSurfaceDescriptor( mStrides[i] = aDesc.strides()[i]; mOffsets[i] = aDesc.offsets()[i]; mBufferModifiers[i] = aDesc.modifier()[i]; - LOGDMABUF(" plane %d fd %d size %d x %d format %x", i, - mDmabufFds[i]->GetHandle(), mWidth[i], mHeight[i], - mDrmFormats[i]); + LOGDMABUF(" plane %d fd %d size %d x %d format %x modifier %" PRIx64, i, + mDmabufFds[i]->GetHandle(), mWidth[i], mHeight[i], mDrmFormats[i], + mBufferModifiers[i]); } if (aDesc.fence().Length() > 0) {