Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 05a8bb1

Browse files
committed
Bug 1944490 [Linux] Ensure DMABufFormats provides basic dmabuf formats r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D236688
1 parent 379437c commit 05a8bb1

File tree

7 files changed

+52
-16
lines changed

7 files changed

+52
-16
lines changed

widget/gtk/DMABufFormats.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ class DMABufFeedback final {
151151
}
152152
}
153153
DRMFormat* GetFormat(uint32_t aFormat, bool aRequestScanoutFormat) {
154-
MOZ_ASSERT(!mPendingTranche);
155154
for (const auto& tranche : mTranches) {
156155
if (aRequestScanoutFormat && !tranche->IsScanout()) {
157156
continue;
@@ -306,9 +305,8 @@ static const struct zwp_linux_dmabuf_v1_listener dmabuf_v3_listener = {
306305

307306
DRMFormat* DMABufFormats::GetFormat(uint32_t aFormat,
308307
bool aRequestScanoutFormat) {
309-
return mDMABufFeedback
310-
? mDMABufFeedback->GetFormat(aFormat, aRequestScanoutFormat)
311-
: nullptr;
308+
MOZ_DIAGNOSTIC_ASSERT(mDMABufFeedback);
309+
return mDMABufFeedback->GetFormat(aFormat, aRequestScanoutFormat);
312310
}
313311

314312
void DMABufFormats::InitFeedback(zwp_linux_dmabuf_v1* aDMABuf,
@@ -337,6 +335,29 @@ void DMABufFormats::InitV3Done() {
337335
PendingDMABufFeedbackDone();
338336
}
339337

338+
void DMABufFormats::EnsureBasicFormats() {
339+
MOZ_DIAGNOSTIC_ASSERT(!mPendingDMABufFeedback,
340+
"Can't add extra formats during init!");
341+
if (!mDMABufFeedback) {
342+
mDMABufFeedback = MakeUnique<DMABufFeedback>();
343+
}
344+
if (!GetFormat(GBM_FORMAT_XRGB8888)) {
345+
LOGDMABUF(
346+
("DMABufFormats::EnsureBasicFormats(): GBM_FORMAT_XRGB8888 is missing, "
347+
"adding."));
348+
mDMABufFeedback->PendingTranche()->AddFormat(GBM_FORMAT_XRGB8888,
349+
DRM_FORMAT_MOD_INVALID);
350+
}
351+
if (!GetFormat(GBM_FORMAT_ARGB8888)) {
352+
LOGDMABUF(
353+
("DMABufFormats::EnsureBasicFormats(): GBM_FORMAT_ARGB8888 is missing, "
354+
"adding."));
355+
mDMABufFeedback->PendingTranche()->AddFormat(GBM_FORMAT_ARGB8888,
356+
DRM_FORMAT_MOD_INVALID);
357+
}
358+
mDMABufFeedback->PendingTrancheDone();
359+
}
360+
340361
DMABufFormats::DMABufFormats() {}
341362

342363
DMABufFormats::~DMABufFormats() {

widget/gtk/DMABufFormats.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ namespace mozilla::widget {
2121
class DMABufFormatTable;
2222
class DMABufFeedback;
2323

24+
#ifndef DRM_FORMAT_MOD_INVALID
25+
# define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
26+
#endif
27+
2428
// DRMFormat (fourcc) and available modifiers for it.
2529
// Modifiers are sorted from the most preffered one.
2630
class DRMFormat final {
@@ -44,7 +48,11 @@ class DRMFormat final {
4448
MOZ_ASSERT(!IsFormatModifierSupported(aModifier), "Added modifier twice?");
4549
mModifiers.AppendElement(aModifier);
4650
}
47-
bool UseModifiers() const { return !mModifiers.IsEmpty(); }
51+
bool UseModifiers() const {
52+
// Don't use modifiers if we don't have any or we have an invalid one.
53+
return !(mModifiers.IsEmpty() || (mModifiers.Length() == 1 ||
54+
mModifiers[0] == DRM_FORMAT_MOD_INVALID));
55+
}
4856
const uint64_t* GetModifiers(uint32_t& aModifiersNum) {
4957
aModifiersNum = mModifiers.Length();
5058
return mModifiers.Elements();
@@ -79,6 +87,8 @@ class DMABufFormats final {
7987
DRMFormat* GetFormat(uint32_t aFormat, bool aRequestScanoutFormat = false);
8088
DMABufFormats();
8189

90+
void EnsureBasicFormats();
91+
8292
private:
8393
~DMABufFormats();
8494

widget/gtk/DMABufLibWrapper.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,8 @@ bool DMABufDevice::IsDMABufWebGLEnabled() {
246246
#ifdef MOZ_WAYLAND
247247
void DMABufDevice::SetModifiersToGfxVars() {
248248
RefPtr<DMABufFormats> formats = WaylandDisplayGet()->GetDMABufFormats();
249-
if (!formats) {
250-
return;
251-
}
249+
MOZ_RELEASE_ASSERT(formats, "Missing dmabuf formats!");
250+
252251
if (DRMFormat* format = formats->GetFormat(GBM_FORMAT_XRGB8888)) {
253252
mFormatRGBX = new DRMFormat(*format);
254253
gfxVars::SetDMABufModifiersXRGB(*format->GetModifiers());
@@ -272,8 +271,10 @@ void DMABufDevice::DisableDMABufWebGL() { sUseWebGLDmabufBackend = false; }
272271
RefPtr<DRMFormat> DMABufDevice::GetDRMFormat(int32_t aFOURCCFormat) {
273272
switch (aFOURCCFormat) {
274273
case GBM_FORMAT_XRGB8888:
274+
MOZ_DIAGNOSTIC_ASSERT(mFormatRGBX, "Missing RGBX dmabuf format!");
275275
return mFormatRGBX;
276276
case GBM_FORMAT_ARGB8888:
277+
MOZ_DIAGNOSTIC_ASSERT(mFormatRGBA, "Missing RGBA dmabuf format!");
277278
return mFormatRGBA;
278279
default:
279280
gfxCriticalNoteOnce << "DMABufDevice::GetDRMFormat() unknow format: "

widget/gtk/DMABufLibWrapper.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ extern mozilla::LazyLogModule gDmabufLog;
2323
# define LOGDMABUF(args)
2424
#endif /* MOZ_LOGGING */
2525

26-
#ifndef DRM_FORMAT_MOD_INVALID
27-
# define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
28-
#endif
29-
3026
namespace mozilla {
3127
namespace widget {
3228

widget/gtk/DMABufSurface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ bool DMABufSurfaceRGBA::Create(int aWidth, int aHeight,
557557
: GBM_FORMAT_XRGB8888;
558558
RefPtr<DRMFormat> format = GetDMABufDevice()->GetDRMFormat(mFOURCCFormat);
559559
if (!format) {
560+
LOGDMABUF(("DMABufSurfaceRGBA::Create(): Missing drm format 0x%x!",
561+
mFOURCCFormat));
560562
return false;
561563
}
562564
return Create(aWidth, aHeight, format, aDMABufSurfaceFlags);

widget/gtk/nsWaylandDisplay.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ void nsWaylandDisplay::SetDmabuf(zwp_linux_dmabuf_v1* aDmabuf, int aVersion) {
413413
return;
414414
}
415415
mDmabuf = aDmabuf;
416-
mFormats = new DMABufFormats();
417416
mDmabufIsFeedback =
418417
(aVersion >= ZWP_LINUX_DMABUF_V1_GET_DEFAULT_FEEDBACK_SINCE_VERSION);
419418
if (mDmabufIsFeedback) {
@@ -423,6 +422,13 @@ void nsWaylandDisplay::SetDmabuf(zwp_linux_dmabuf_v1* aDmabuf, int aVersion) {
423422
}
424423
}
425424

425+
void nsWaylandDisplay::EnsureDMABufFormats() {
426+
if (mDmabuf && !mDmabufIsFeedback) {
427+
mFormats->InitV3Done();
428+
}
429+
mFormats->EnsureBasicFormats();
430+
}
431+
426432
void nsWaylandDisplay::SetXdgActivation(xdg_activation_v1* aXdgActivation) {
427433
mXdgActivation = aXdgActivation;
428434
}
@@ -646,13 +652,12 @@ nsWaylandDisplay::nsWaylandDisplay(wl_display* aDisplay)
646652
// in a similar fashion
647653
wl_log_set_handler_client(WlLogHandler);
648654

655+
mFormats = new DMABufFormats();
649656
mRegistry = wl_display_get_registry(mDisplay);
650657
wl_registry_add_listener(mRegistry, &registry_listener, this);
651658
wl_display_roundtrip(mDisplay);
652659
wl_display_roundtrip(mDisplay);
653-
if (mDmabuf && !mDmabufIsFeedback) {
654-
mFormats->InitV3Done();
655-
}
660+
EnsureDMABufFormats();
656661

657662
for (auto& e : mSupportedTransfer) {
658663
e = -1;

widget/gtk/nsWaylandDisplay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class nsWaylandDisplay {
108108
}
109109
RefPtr<DMABufFormats> GetDMABufFormats() const { return mFormats; }
110110
bool HasDMABufFeedback() const { return mDmabufIsFeedback; }
111+
void EnsureDMABufFormats();
111112

112113
~nsWaylandDisplay();
113114

0 commit comments

Comments
 (0)