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
This commit is contained in:
stransky
2025-04-09 19:34:19 +00:00
parent b952710ea7
commit 5c7669bace
5 changed files with 43 additions and 11 deletions

View File

@@ -106,7 +106,9 @@ class gfxVarReceiver;
_(WebRenderOverlayVpAutoHDR, bool, false) \ _(WebRenderOverlayVpAutoHDR, bool, false) \
_(WebRenderOverlayVpSuperResolution, bool, false) \ _(WebRenderOverlayVpSuperResolution, bool, false) \
_(AllowWebGPUPresentWithoutReadback, bool, false) \ _(AllowWebGPUPresentWithoutReadback, bool, false) \
_(GPUProcessEnabled, bool, false) _(GPUProcessEnabled, bool, false) \
_(DMABufModifiersP010, ArrayOfuint64_t, nsTArray<uint64_t>()) \
_(DMABufModifiersNV12, ArrayOfuint64_t, nsTArray<uint64_t>())
/* Add new entries above this line. */ /* Add new entries above this line. */

View File

@@ -57,6 +57,9 @@ class DRMFormat final {
aModifiersNum = mModifiers.Length(); aModifiersNum = mModifiers.Length();
return mModifiers.Elements(); return mModifiers.Elements();
} }
uint64_t GetModifier() {
return mModifiers.Length() ? mModifiers[0] : DRM_FORMAT_MOD_INVALID;
}
nsTArray<uint64_t>* GetModifiers() { return &mModifiers; } nsTArray<uint64_t>* GetModifiers() { return &mModifiers; }
private: private:

View File

@@ -31,6 +31,11 @@
using namespace mozilla::gfx; 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 mozilla {
namespace widget { namespace widget {
@@ -261,6 +266,18 @@ void DMABufDevice::SetModifiersToGfxVars() {
MOZ_DIAGNOSTIC_ASSERT(format, "Missing GBM_FORMAT_ARGB8888 dmabuf format!"); MOZ_DIAGNOSTIC_ASSERT(format, "Missing GBM_FORMAT_ARGB8888 dmabuf format!");
mFormatRGBA = new DRMFormat(*format); mFormatRGBA = new DRMFormat(*format);
gfxVars::SetDMABufModifiersARGB(*format->GetModifiers()); 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() { void DMABufDevice::GetModifiersFromGfxVars() {
@@ -268,6 +285,8 @@ void DMABufDevice::GetModifiersFromGfxVars() {
new DRMFormat(GBM_FORMAT_XRGB8888, gfxVars::DMABufModifiersXRGB()); new DRMFormat(GBM_FORMAT_XRGB8888, gfxVars::DMABufModifiersXRGB());
mFormatRGBA = mFormatRGBA =
new DRMFormat(GBM_FORMAT_ARGB8888, gfxVars::DMABufModifiersARGB()); 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; } void DMABufDevice::DisableDMABufWebGL() { sUseWebGLDmabufBackend = false; }
@@ -280,6 +299,10 @@ RefPtr<DRMFormat> DMABufDevice::GetDRMFormat(int32_t aFOURCCFormat) {
case GBM_FORMAT_ARGB8888: case GBM_FORMAT_ARGB8888:
MOZ_DIAGNOSTIC_ASSERT(mFormatRGBA, "Missing RGBA dmabuf format!"); MOZ_DIAGNOSTIC_ASSERT(mFormatRGBA, "Missing RGBA dmabuf format!");
return mFormatRGBA; return mFormatRGBA;
case GBM_FORMAT_P010:
return mFormatP010;
case GBM_FORMAT_NV12:
return mFormatNV12;
default: default:
gfxCriticalNoteOnce << "DMABufDevice::GetDRMFormat() unknow format: " gfxCriticalNoteOnce << "DMABufDevice::GetDRMFormat() unknow format: "
<< aFOURCCFormat; << aFOURCCFormat;

View File

@@ -222,9 +222,13 @@ class DMABufDevice {
void SetModifiersToGfxVars(); void SetModifiersToGfxVars();
void GetModifiersFromGfxVars(); 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<DRMFormat> mFormatRGBA; RefPtr<DRMFormat> mFormatRGBA;
RefPtr<DRMFormat> mFormatRGBX; RefPtr<DRMFormat> mFormatRGBX;
RefPtr<DRMFormat> mFormatP010;
RefPtr<DRMFormat> mFormatNV12;
int mDRMFd = -1; int mDRMFd = -1;
std::once_flag mFlagGbmDevice; std::once_flag mFlagGbmDevice;

View File

@@ -1542,7 +1542,7 @@ bool DMABufSurfaceYUV::CreateYUVPlaneGBM(int aPlane) {
MOZ_DIAGNOSTIC_ASSERT(mGbmBufferObject[aPlane] == nullptr); MOZ_DIAGNOSTIC_ASSERT(mGbmBufferObject[aPlane] == nullptr);
bool useModifiers = (mBufferModifiers[aPlane] != DRM_FORMAT_MOD_INVALID); bool useModifiers = (mBufferModifiers[aPlane] != DRM_FORMAT_MOD_INVALID);
if (useModifiers) { if (useModifiers) {
LOGDMABUF(" Creating with modifiers"); LOGDMABUF(" Creating with modifier %" PRIx64, mBufferModifiers[aPlane]);
mGbmBufferObject[aPlane] = GbmLib::CreateWithModifiers2( mGbmBufferObject[aPlane] = GbmLib::CreateWithModifiers2(
GetDMABufDevice()->GetGbmDevice(), mWidth[aPlane], mHeight[aPlane], GetDMABufDevice()->GetGbmDevice(), mWidth[aPlane], mHeight[aPlane],
mDrmFormats[aPlane], mBufferModifiers + aPlane, 1, mDrmFormats[aPlane], mBufferModifiers + aPlane, 1,
@@ -1658,7 +1658,7 @@ bool DMABufSurfaceYUV::CreateYUVPlaneExport(GLContext* aGLContext, int aPlane) {
return false; 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, mWidth[aPlane], mHeight[aPlane], mFOURCCFormat, mBufferPlaneCount,
mBufferModifiers[aPlane]); mBufferModifiers[aPlane]);
@@ -1735,10 +1735,6 @@ bool DMABufSurfaceYUV::UpdateYUVData(
ReturnSnapshotGLContext(context); ReturnSnapshotGLContext(context);
}); });
// Use LINEAR modifiers
// TODO: Load modifiers from DMABuf
mBufferModifiers[0] = mBufferModifiers[1] = 0;
gfx::IntSize size = aData.YPictureSize(); gfx::IntSize size = aData.YPictureSize();
mWidthAligned[0] = mWidth[0] = size.width; mWidthAligned[0] = mWidth[0] = size.width;
@@ -1763,6 +1759,10 @@ bool DMABufSurfaceYUV::UpdateYUVData(
return false; return false;
} }
RefPtr<DRMFormat> format = GetDMABufDevice()->GetDRMFormat(mFOURCCFormat);
mBufferModifiers[0] = mBufferModifiers[1] =
format ? format->GetModifier() : DRM_FORMAT_MOD_INVALID;
for (int i = 0; i < mBufferPlaneCount; i++) { for (int i = 0; i < mBufferPlaneCount; i++) {
if (!CreateYUVPlane(context, i)) { if (!CreateYUVPlane(context, i)) {
return false; return false;
@@ -1803,9 +1803,9 @@ bool DMABufSurfaceYUV::ImportSurfaceDescriptor(
mStrides[i] = aDesc.strides()[i]; mStrides[i] = aDesc.strides()[i];
mOffsets[i] = aDesc.offsets()[i]; mOffsets[i] = aDesc.offsets()[i];
mBufferModifiers[i] = aDesc.modifier()[i]; mBufferModifiers[i] = aDesc.modifier()[i];
LOGDMABUF(" plane %d fd %d size %d x %d format %x", i, LOGDMABUF(" plane %d fd %d size %d x %d format %x modifier %" PRIx64, i,
mDmabufFds[i]->GetHandle(), mWidth[i], mHeight[i], mDmabufFds[i]->GetHandle(), mWidth[i], mHeight[i], mDrmFormats[i],
mDrmFormats[i]); mBufferModifiers[i]);
} }
if (aDesc.fence().Length() > 0) { if (aDesc.fence().Length() > 0) {