61879d2
diff -up firefox-101.0/gfx/gl/SharedSurfaceDMABUF.cpp.D147637.diff firefox-101.0/gfx/gl/SharedSurfaceDMABUF.cpp
61879d2
--- firefox-101.0/gfx/gl/SharedSurfaceDMABUF.cpp.D147637.diff	2022-05-27 01:16:54.000000000 +0200
61879d2
+++ firefox-101.0/gfx/gl/SharedSurfaceDMABUF.cpp	2022-06-07 09:37:29.361992695 +0200
61879d2
@@ -12,22 +12,37 @@
61879d2
 
61879d2
 namespace mozilla::gl {
61879d2
 
61879d2
+static bool HasDmaBufExtensions(const GLContextEGL* gl) {
61879d2
+  const auto& egl = *(gl->mEgl);
61879d2
+  return egl.IsExtensionSupported(EGLExtension::EXT_image_dma_buf_import) &&
61879d2
+         egl.IsExtensionSupported(
61879d2
+             EGLExtension::EXT_image_dma_buf_import_modifiers) &&
61879d2
+         egl.IsExtensionSupported(EGLExtension::MESA_image_dma_buf_export);
61879d2
+}
61879d2
+
61879d2
 /*static*/
61879d2
 UniquePtr<SharedSurface_DMABUF> SharedSurface_DMABUF::Create(
61879d2
     const SharedSurfaceDesc& desc) {
61879d2
-  const auto flags = static_cast<DMABufSurfaceFlags>(
61879d2
-      DMABUF_TEXTURE | DMABUF_USE_MODIFIERS | DMABUF_ALPHA);
61879d2
-  const RefPtr<DMABufSurface> surface = DMABufSurfaceRGBA::CreateDMABufSurface(
61879d2
-      desc.size.width, desc.size.height, flags);
61879d2
-  if (!surface || !surface->CreateTexture(desc.gl)) {
61879d2
+  const auto& gle = GLContextEGL::Cast(desc.gl);
61879d2
+  const auto& context = gle->mContext;
61879d2
+  const auto& egl = *(gle->mEgl);
61879d2
+
61879d2
+  if (!HasDmaBufExtensions(gle)) {
61879d2
     return nullptr;
61879d2
   }
61879d2
 
61879d2
-  const auto tex = surface->GetTexture();
61879d2
-  auto fb = MozFramebuffer::CreateForBacking(desc.gl, desc.size, 0, false,
61879d2
-                                             LOCAL_GL_TEXTURE_2D, tex);
61879d2
+  auto fb = MozFramebuffer::Create(desc.gl, desc.size, 0, false);
61879d2
   if (!fb) return nullptr;
61879d2
 
61879d2
+  const auto buffer = reinterpret_cast<EGLClientBuffer>(fb->ColorTex());
61879d2
+  const auto image =
61879d2
+      egl.fCreateImage(context, LOCAL_EGL_GL_TEXTURE_2D, buffer, nullptr);
61879d2
+  if (!image) return nullptr;
61879d2
+
61879d2
+  const RefPtr<DMABufSurface> surface = DMABufSurfaceRGBA::CreateDMABufSurface(
61879d2
+      desc.gl, image, desc.size.width, desc.size.height);
61879d2
+  if (!surface) return nullptr;
61879d2
+
61879d2
   return AsUnique(new SharedSurface_DMABUF(desc, std::move(fb), surface));
61879d2
 }
61879d2
 
61879d2
@@ -61,7 +76,7 @@ UniquePtr<SurfaceFactory_DMABUF> Surface
61879d2
   }
61879d2
 
61879d2
   auto dmabufFactory = MakeUnique<SurfaceFactory_DMABUF>(gl);
61879d2
-  if (dmabufFactory->CanCreateSurface()) {
61879d2
+  if (dmabufFactory->CanCreateSurface(gl)) {
61879d2
     return dmabufFactory;
61879d2
   }
61879d2
 
61879d2
@@ -71,8 +86,38 @@ UniquePtr<SurfaceFactory_DMABUF> Surface
61879d2
   return nullptr;
61879d2
 }
61879d2
 
61879d2
+bool SurfaceFactory_DMABUF::CanCreateSurface(GLContext& gl) {
61879d2
+  UniquePtr<SharedSurface> test =
61879d2
+      CreateShared(gfx::IntSize(1, 1));
61879d2
+  if (!test) {
61879d2
+    LOGDMABUF((
61879d2
+        "SurfaceFactory_DMABUF::CanCreateSurface() failed to create surface."));
61879d2
+    return false;
61879d2
+  }
61879d2
+  auto desc = test->ToSurfaceDescriptor();
61879d2
+  if (!desc) {
61879d2
+    LOGDMABUF(
61879d2
+        ("SurfaceFactory_DMABUF::CanCreateSurface() failed to serialize "
61879d2
+         "surface."));
61879d2
+    return false;
61879d2
+  }
61879d2
+  RefPtr<DMABufSurface> importedSurface =
61879d2
+      DMABufSurface::CreateDMABufSurface(*desc);
61879d2
+  if (!importedSurface) {
61879d2
+    LOGDMABUF((
61879d2
+        "SurfaceFactory_DMABUF::CanCreateSurface() failed to import surface."));
61879d2
+    return false;
61879d2
+  }
61879d2
+  if (!importedSurface->CreateTexture(&gl)) {
61879d2
+    LOGDMABUF(
61879d2
+        ("SurfaceFactory_DMABUF::CanCreateSurface() failed to create texture "
61879d2
+         "over surface."));
61879d2
+    return false;
61879d2
+  }
61879d2
+  return true;
61879d2
+}
61879d2
+
61879d2
 SurfaceFactory_DMABUF::SurfaceFactory_DMABUF(GLContext& gl)
61879d2
     : SurfaceFactory({&gl, SharedSurfaceType::EGLSurfaceDMABUF,
61879d2
                       layers::TextureType::DMABUF, true}) {}
61879d2
-
61879d2
 }  // namespace mozilla::gl
61879d2
diff -up firefox-101.0/gfx/gl/SharedSurfaceDMABUF.h.D147637.diff firefox-101.0/gfx/gl/SharedSurfaceDMABUF.h
61879d2
--- firefox-101.0/gfx/gl/SharedSurfaceDMABUF.h.D147637.diff	2022-06-07 09:31:23.678228010 +0200
61879d2
+++ firefox-101.0/gfx/gl/SharedSurfaceDMABUF.h	2022-06-07 09:36:39.691512555 +0200
61879d2
@@ -59,10 +59,7 @@ class SurfaceFactory_DMABUF : public Sur
61879d2
     return SharedSurface_DMABUF::Create(desc);
61879d2
   }
61879d2
 
61879d2
-  bool CanCreateSurface() {
61879d2
-    UniquePtr<SharedSurface> test = CreateShared(gfx::IntSize(1, 1));
61879d2
-    return test != nullptr;
61879d2
-  }
61879d2
+  bool CanCreateSurface(GLContext& gl);
61879d2
 };
61879d2
 
61879d2
 }  // namespace gl