
# HG changeset patch
# User Martin Stransky <stransky@redhat.com>
# Date 1656309292 0
# Node ID 6dce488087f13c4ffe6ba0c758362968a8e60704
# Parent  00ef31a00437f25556606342668f1125e86c55b4
Bug 1774271 [Linux] Use DMABUF_SURFACE_EXPORT feature to control dmabuf surface export from EGLImage and disable that on Mesa/Intel and Mesa/AMD r=jgilbert

Differential Revision: https://phabricator.services.mozilla.com/D149984

diff --git a/gfx/config/gfxFeature.h b/gfx/config/gfxFeature.h
--- a/gfx/config/gfxFeature.h
+++ b/gfx/config/gfxFeature.h
@@ -38,17 +38,18 @@ namespace gfx {
   _(WEBGPU, Feature, "WebGPU")                                               \
   _(X11_EGL, Feature, "X11 EGL")                                             \
   _(DMABUF, Feature, "DMABUF")                                               \
   _(WINDOW_OCCLUSION, Feature, "WINDOW_OCCLUSION")                           \
   _(VAAPI, Feature, "VA-API video decoding")                                 \
   _(VIDEO_OVERLAY, Feature, "video overlay")                                 \
   _(HW_DECODED_VIDEO_ZERO_COPY, Feature, "Hardware decoded video zero copy") \
   _(VP8_HW_DECODE, Feature, "VP8 hardware decoding")                         \
-  _(VP9_HW_DECODE, Feature, "VP9 hardware decoding")
+  _(VP9_HW_DECODE, Feature, "VP9 hardware decoding")                         \
+  _(DMABUF_SURFACE_EXPORT, Feature, "WebGL DMABuf surface export")
 /* Add new entries above this comment */
 
 enum class Feature : uint32_t {
 #define MAKE_ENUM(name, type, desc) name,
   GFX_FEATURE_MAP(MAKE_ENUM)
 #undef MAKE_ENUM
       NumValues
 };
diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -2806,23 +2806,29 @@ void gfxPlatform::InitWebGLConfig() {
     nsAutoString renderer;
     gfxInfo->GetAdapterDeviceID(renderer);
     if (renderer.Find("Adreno (TM) 630") != -1) {
       gfxVars::SetAllowEglRbab(false);
     }
   }
 
   if (kIsWayland || kIsX11) {
-    // Disable EGL_MESA_image_dma_buf_export on mesa/radeonsi due to
-    // https://gitlab.freedesktop.org/mesa/mesa/-/issues/6666
-    nsString adapterDriverVendor;
-    gfxInfo->GetAdapterDriverVendor(adapterDriverVendor);
-    if (adapterDriverVendor.Find("mesa") != -1 &&
-        adapterDriverVendor.Find("radeonsi") != -1) {
+    nsCString discardFailureId;
+    int32_t status;
+    FeatureState& feature =
+        gfxConfig::GetFeature(Feature::DMABUF_SURFACE_EXPORT);
+    if (NS_FAILED(
+            gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT,
+                                      discardFailureId, &status)) ||
+        status != nsIGfxInfo::FEATURE_STATUS_OK) {
+      feature.DisableByDefault(FeatureStatus::Blocked, "Blocklisted by gfxInfo",
+                               discardFailureId);
       gfxVars::SetUseDMABufSurfaceExport(false);
+    } else {
+      feature.EnableByDefault();
     }
   }
 }
 
 void gfxPlatform::InitWebGPUConfig() {
   if (!XRE_IsParentProcess()) {
     return;
   }
diff --git a/widget/GfxInfoBase.cpp b/widget/GfxInfoBase.cpp
--- a/widget/GfxInfoBase.cpp
+++ b/widget/GfxInfoBase.cpp
@@ -249,16 +249,19 @@ static const char* GetPrefNameForFeature
       name = BLOCKLIST_PREF_BRANCH "hw-video-zero-copy";
       break;
     case nsIGfxInfo::FEATURE_WEBRENDER_SHADER_CACHE:
       name = BLOCKLIST_PREF_BRANCH "webrender.program-binary-disk";
       break;
     case nsIGfxInfo::FEATURE_WEBRENDER_PARTIAL_PRESENT:
       name = BLOCKLIST_PREF_BRANCH "webrender.partial-present";
       break;
+    case nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT:
+      name = BLOCKLIST_PREF_BRANCH "dmabuf.surface-export";
+      break;
     default:
       MOZ_ASSERT_UNREACHABLE("Unexpected nsIGfxInfo feature?!");
       break;
   }
 
   return name;
 }
 
diff --git a/widget/gtk/GfxInfo.cpp b/widget/gtk/GfxInfo.cpp
--- a/widget/gtk/GfxInfo.cpp
+++ b/widget/gtk/GfxInfo.cpp
@@ -822,16 +822,32 @@ const nsTArray<GfxDriverInfo>& GfxInfo::
     APPEND_TO_DRIVER_BLOCKLIST_EXT(
         OperatingSystem::Linux, ScreenSizeStatus::All, BatteryStatus::All,
         DesktopEnvironment::All, WindowProtocol::All, DriverVendor::NonMesaAll,
         DeviceFamily::NvidiaAll, nsIGfxInfo::FEATURE_DMABUF,
         nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION, DRIVER_LESS_THAN,
         V(495, 44, 0, 0), "FEATURE_FAILURE_NO_GBM", "495.44.0");
 
     ////////////////////////////////////
+    // FEATURE_DMABUF_SURFACE_EXPORT
+    APPEND_TO_DRIVER_BLOCKLIST_EXT(
+        OperatingSystem::Linux, ScreenSizeStatus::All, BatteryStatus::All,
+        DesktopEnvironment::All, WindowProtocol::All, DriverVendor::MesaAll,
+        DeviceFamily::AtiAll, nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT,
+        nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION, DRIVER_LESS_THAN,
+        V(21, 1, 2, 0), "FEATURE_FAILURE_BROKEN_MESA", "22.1.2");
+
+    APPEND_TO_DRIVER_BLOCKLIST_EXT(
+        OperatingSystem::Linux, ScreenSizeStatus::All, BatteryStatus::All,
+        DesktopEnvironment::All, WindowProtocol::All, DriverVendor::MesaAll,
+        DeviceFamily::IntelAll, nsIGfxInfo::FEATURE_DMABUF_SURFACE_EXPORT,
+        nsIGfxInfo::FEATURE_BLOCKED_DEVICE, DRIVER_COMPARISON_IGNORED,
+        V(0, 0, 0, 0), "FEATURE_FAILURE_BROKEN_DRIVER", "");
+
+    ////////////////////////////////////
     // FEATURE_VAAPI
     APPEND_TO_DRIVER_BLOCKLIST_EXT(
         OperatingSystem::Linux, ScreenSizeStatus::All, BatteryStatus::All,
         DesktopEnvironment::All, WindowProtocol::All, DriverVendor::MesaAll,
         DeviceFamily::All, nsIGfxInfo::FEATURE_VAAPI,
         nsIGfxInfo::FEATURE_BLOCKED_DRIVER_VERSION, DRIVER_LESS_THAN,
         V(21, 0, 0, 0), "FEATURE_ROLLOUT_VAAPI_MESA", "Mesa 21.0.0.0");
 
diff --git a/widget/nsIGfxInfo.idl b/widget/nsIGfxInfo.idl
--- a/widget/nsIGfxInfo.idl
+++ b/widget/nsIGfxInfo.idl
@@ -171,16 +171,18 @@ interface nsIGfxInfo : nsISupports
   /* Whether VA-API is supported, starting in 96. */
   const long FEATURE_VAAPI = 37;
   /* Whether WebGPU is supported, starting in 100. */
   const long FEATURE_WEBGPU = 38;
   /* Whether video overlay is supported, starting in 100. */
   const long FEATURE_VIDEO_OVERLAY = 39;
   /* Whether hardware decoded video zero copy is supported, starting in 101. */
   const long FEATURE_HW_DECODED_VIDEO_ZERO_COPY = 40;
+  /* Whether DMABUF export is supported, starting in 103. */
+  const long FEATURE_DMABUF_SURFACE_EXPORT = 41;
   /* the maximum feature value. */
   const long FEATURE_MAX_VALUE = FEATURE_HW_DECODED_VIDEO_ZERO_COPY;
 
   /*
    * A set of return values from GetFeatureStatus
    */
 
   /* The driver is safe to the best of our knowledge */

