Bug 1535893 - Use SharedGL in RenderCompositorEGL on wayland, r=sotaro
authorMartin Stransky <stransky@redhat.com>
Fri, 12 Apr 2019 08:08:03 +0000
changeset 469232 659c30eda4f10747540e72a9d41ed459b9234db3
parent 469231 6fa8c4b075bc639bc2bf38c66665da7190aa4f33
child 469233 7bd34721fb35f036eb119d42593fa22c9ad09d91
push id35859
push usershindli@mozilla.com
push dateFri, 12 Apr 2019 15:46:45 +0000
treeherdermozilla-central@c261aea0226a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1535893
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1535893 - Use SharedGL in RenderCompositorEGL on wayland, r=sotaro Differential Revision: https://phabricator.services.mozilla.com/D26800
gfx/webrender_bindings/RenderCompositorEGL.cpp
gfx/webrender_bindings/RenderCompositorEGL.h
gfx/webrender_bindings/RenderThread.cpp
--- a/gfx/webrender_bindings/RenderCompositorEGL.cpp
+++ b/gfx/webrender_bindings/RenderCompositorEGL.cpp
@@ -24,96 +24,59 @@
 #endif
 
 namespace mozilla {
 namespace wr {
 
 /* static */
 UniquePtr<RenderCompositor> RenderCompositorEGL::Create(
     RefPtr<widget::CompositorWidget> aWidget) {
-#ifdef MOZ_WIDGET_ANDROID
+#ifdef MOZ_WAYLAND
+  if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
+    return nullptr;
+  }
+#endif
   if (!RenderThread::Get()->SharedGL()) {
     gfxCriticalNote << "Failed to get shared GL context";
     return nullptr;
   }
   return MakeUnique<RenderCompositorEGL>(aWidget);
-#elif defined(MOZ_WAYLAND)
-  // Disabled SharedGL() usage on wayland. Its usage caused flicker when
-  // multiple windows were opened. See Bug 1535893.
-  if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
-    return nullptr;
-  }
-  RefPtr<gl::GLContext> gl;
-  gl = CreateGLContext();
-  if (!gl) {
-    return nullptr;
-  }
-  return MakeUnique<RenderCompositorEGL>(gl, aWidget);
-#endif
 }
 
-#ifdef MOZ_WAYLAND
-/* static */ already_AddRefed<gl::GLContext>
-RenderCompositorEGL::CreateGLContext() {
-  // Create GLContext with dummy EGLSurface.
-  RefPtr<gl::GLContext> gl =
-      gl::GLContextProviderEGL::CreateForCompositorWidget(
-          nullptr, /* aWebRender */ true, /* aForceAccelerated */ true);
-  if (!gl || !gl->MakeCurrent()) {
-    gfxCriticalNote << "Failed GL context creation for WebRender: "
-                    << gfx::hexa(gl.get());
-    return nullptr;
-  }
-
-  return gl.forget();
-}
-#endif
-
 EGLSurface RenderCompositorEGL::CreateEGLSurface() {
   EGLSurface surface = EGL_NO_SURFACE;
   surface = gl::GLContextEGL::CreateEGLSurfaceForCompositorWidget(
       mWidget, gl::GLContextEGL::Cast(gl())->mConfig);
   if (surface == EGL_NO_SURFACE) {
     gfxCriticalNote << "Failed to create EGLSurface";
   }
   return surface;
 }
 
-#ifdef MOZ_WIDGET_ANDROID
 RenderCompositorEGL::RenderCompositorEGL(
     RefPtr<widget::CompositorWidget> aWidget)
     : RenderCompositor(std::move(aWidget)), mEGLSurface(EGL_NO_SURFACE) {}
-#elif defined(MOZ_WAYLAND)
-RenderCompositorEGL::RenderCompositorEGL(
-    RefPtr<gl::GLContext> aGL, RefPtr<widget::CompositorWidget> aWidget)
-    : RenderCompositor(std::move(aWidget)),
-      mGL(aGL),
-      mEGLSurface(EGL_NO_SURFACE) {
-  MOZ_ASSERT(mGL);
-}
-#endif
 
 RenderCompositorEGL::~RenderCompositorEGL() { DestroyEGLSurface(); }
 
 bool RenderCompositorEGL::BeginFrame() {
 #ifdef MOZ_WAYLAND
   if (mWidget->AsX11() &&
       mWidget->AsX11()->WaylandRequestsUpdatingEGLSurface()) {
     // Destroy EGLSurface if it exists.
     DestroyEGLSurface();
     mEGLSurface = CreateEGLSurface();
-    gl::GLContextEGL::Cast(gl())->SetEGLSurfaceOverride(mEGLSurface);
     if (mEGLSurface) {
       const auto* egl = gl::GLLibraryEGL::Get();
       // Make eglSwapBuffers() non-blocking on wayland
       egl->fSwapInterval(gl::EGL_DISPLAY(), 0);
     }
   }
 #endif
-  if (!gl()->MakeCurrent()) {
+  if (!MakeCurrent()) {
     gfxCriticalNote << "Failed to make render context current, can't draw.";
     return false;
   }
 
 #ifdef MOZ_WIDGET_ANDROID
   java::GeckoSurfaceTexture::DestroyUnused((int64_t)gl());
 #endif
 
@@ -142,22 +105,17 @@ bool RenderCompositorEGL::Resume() {
   DestroyEGLSurface();
   mEGLSurface = CreateEGLSurface();
   gl::GLContextEGL::Cast(gl())->SetEGLSurfaceOverride(mEGLSurface);
 #endif
   return true;
 }
 
 gl::GLContext* RenderCompositorEGL::gl() const {
-#ifdef MOZ_WIDGET_ANDROID
   return RenderThread::Get()->SharedGL();
-#elif defined(MOZ_WAYLAND)
-  MOZ_ASSERT(mGL);
-  return mGL;
-#endif
 }
 
 bool RenderCompositorEGL::MakeCurrent() {
   gl::GLContextEGL::Cast(gl())->SetEGLSurfaceOverride(mEGLSurface);
   return gl()->MakeCurrent();
 }
 
 void RenderCompositorEGL::DestroyEGLSurface() {
--- a/gfx/webrender_bindings/RenderCompositorEGL.h
+++ b/gfx/webrender_bindings/RenderCompositorEGL.h
@@ -14,22 +14,17 @@ namespace mozilla {
 
 namespace wr {
 
 class RenderCompositorEGL : public RenderCompositor {
  public:
   static UniquePtr<RenderCompositor> Create(
       RefPtr<widget::CompositorWidget> aWidget);
 
-#ifdef MOZ_WIDGET_ANDROID
   explicit RenderCompositorEGL(RefPtr<widget::CompositorWidget> aWidget);
-#elif defined(MOZ_WAYLAND)
-  RenderCompositorEGL(RefPtr<gl::GLContext> aGL,
-                      RefPtr<widget::CompositorWidget> aWidget);
-#endif
   virtual ~RenderCompositorEGL();
 
   bool BeginFrame() override;
   void EndFrame() override;
   void WaitForGPU() override;
   void Pause() override;
   bool Resume() override;
 
@@ -37,25 +32,19 @@ class RenderCompositorEGL : public Rende
 
   bool MakeCurrent() override;
 
   bool UseANGLE() const override { return false; }
 
   LayoutDeviceIntSize GetBufferSize() override;
 
  protected:
-#ifdef MOZ_WAYLAND
-  static already_AddRefed<gl::GLContext> CreateGLContext();
-#endif
   EGLSurface CreateEGLSurface();
 
   void DestroyEGLSurface();
 
-#ifdef MOZ_WAYLAND
-  const RefPtr<gl::GLContext> mGL;
-#endif
   EGLSurface mEGLSurface;
 };
 
 }  // namespace wr
 }  // namespace mozilla
 
 #endif  // MOZILLA_GFX_RENDERCOMPOSITOR_EGL_H
--- a/gfx/webrender_bindings/RenderThread.cpp
+++ b/gfx/webrender_bindings/RenderThread.cpp
@@ -864,17 +864,17 @@ static already_AddRefed<gl::GLContext> C
                     << gfx::hexa(gl.get());
     return nullptr;
   }
 
   return gl.forget();
 }
 #endif
 
-#ifdef MOZ_WIDGET_ANDROID
+#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WAYLAND)
 static already_AddRefed<gl::GLContext> CreateGLContextEGL() {
   nsCString discardFailureId;
   if (!gl::GLLibraryEGL::EnsureInitialized(/* forceAccel */ true,
                                            &discardFailureId)) {
     gfxCriticalNote << "Failed to load EGL library: " << discardFailureId.get();
     return nullptr;
   }
   // Create GLContext with dummy EGLSurface.
@@ -892,18 +892,22 @@ static already_AddRefed<gl::GLContext> C
 
 static already_AddRefed<gl::GLContext> CreateGLContext() {
 #ifdef XP_WIN
   if (gfx::gfxVars::UseWebRenderANGLE()) {
     return CreateGLContextANGLE();
   }
 #endif
 
-#ifdef MOZ_WIDGET_ANDROID
-  return CreateGLContextEGL();
+#if defined(MOZ_WIDGET_ANDROID)
+    return CreateGLContextEGL();
+#elif defined(MOZ_WAYLAND)
+  if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
+    return CreateGLContextEGL();
+  }
 #endif
   // We currently only support a shared GLContext
   // with ANGLE.
   return nullptr;
 }
 
 extern "C" {