Bug 1532949 - Bug 1532024 - Explicityly create headless context for webrender in RenderCompositorEGL r=jgilbert
authorsotaro <sotaro.ikeda.g@gmail.com>
Wed, 13 Mar 2019 00:17:01 +0000
changeset 521652 a0767cb93359
parent 521651 7cbe3fbc4b7f
child 521653 123ecc5c9586
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1532949, 1532024
milestone67.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 1532949 - Bug 1532024 - Explicityly create headless context for webrender in RenderCompositorEGL r=jgilbert On Wayland with WebRender, RenderCompositorEGL creates headless context by using GLContextProviderEGL::CreateForCompositorWidget(), since GetNativeData(NS_NATIVE_EGL_WINDOW) returns nullptr. But we want to make hadless explicitly. But GLContextProviderEGL::CreateHeadless() and GLContextEGL::CreateEGLPBufferOffscreenContext() could not be used for it. They creates incompatible EGLConfig to egl window. Then we extends GLContextProviderEAGL::CreateForCompositorWidget() to handle this case. When CreateForCompositorWidget() receives null widget, it creates GLContext without surface of egl window. Differential Revision: https://phabricator.services.mozilla.com/D22454
gfx/gl/GLContextProviderCGL.mm
gfx/gl/GLContextProviderEAGL.mm
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/gl/GLContextProviderImpl.h
gfx/gl/GLContextProviderNull.cpp
gfx/gl/GLContextProviderWGL.cpp
gfx/gl/GLContextProviderWayland.cpp
gfx/layers/opengl/CompositorOGL.cpp
gfx/webrender_bindings/RenderCompositorEGL.cpp
gfx/webrender_bindings/RenderCompositorEGL.h
gfx/webrender_bindings/RenderCompositorOGL.cpp
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -161,20 +161,22 @@ static NSOpenGLContext* CreateWithFormat
   NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nullptr];
 
   [format release];
 
   return context;
 }
 
 already_AddRefed<GLContext> GLContextProviderCGL::CreateForCompositorWidget(
-    CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
-  return CreateForWindow(aCompositorWidget->RealWidget(),
-                         aCompositorWidget->GetCompositorOptions().UseWebRender(),
-                         aForceAccelerated);
+    CompositorWidget* aCompositorWidget, bool aWebRender, bool aForceAccelerated) {
+  if (!aCompositorWidget) {
+    MOZ_ASSERT(false);
+    return nullptr;
+  }
+  return CreateForWindow(aCompositorWidget->RealWidget(), aWebRender, aForceAccelerated);
 }
 
 already_AddRefed<GLContext> GLContextProviderCGL::CreateForWindow(nsIWidget* aWidget,
                                                                   bool aWebRender,
                                                                   bool aForceAccelerated) {
   if (!sCGLLibrary.EnsureInitialized()) {
     return nullptr;
   }
--- a/gfx/gl/GLContextProviderEAGL.mm
+++ b/gfx/gl/GLContextProviderEAGL.mm
@@ -161,20 +161,22 @@ static already_AddRefed<GLContext> Creat
     glContext = nullptr;
     return nullptr;
   }
 
   return glContext.forget();
 }
 
 already_AddRefed<GLContext> GLContextProviderEAGL::CreateForCompositorWidget(
-    CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
-  return CreateForWindow(aCompositorWidget->RealWidget(),
-                         aCompositorWidget->GetCompositorOptions().UseWebRender(),
-                         aForceAccelerated);
+    CompositorWidget* aCompositorWidget, bool aWebRender, bool aForceAccelerated) {
+  if (!aCompositorWidget) {
+    MOZ_ASSERT(false);
+    return nullptr;
+  }
+  return CreateForWindow(aCompositorWidget->RealWidget(), aWebRender, aForceAccelerated);
 }
 
 already_AddRefed<GLContext> GLContextProviderEAGL::CreateForWindow(nsIWidget* aWidget,
                                                                    bool aWebRender,
                                                                    bool aForceAccelerated) {
   RefPtr<GLContext> glContext =
       CreateEAGLContext(CreateContextFlags::NONE, false, GetGlobalContextEAGL());
   if (!glContext) {
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -863,21 +863,23 @@ already_AddRefed<GLContext> GLContextPro
                        (EGLSurface)aSurface, (EGLContext)aContext);
   gl->SetIsDoubleBuffered(true);
   gl->mOwnsContext = false;
 
   return gl.forget();
 }
 
 already_AddRefed<GLContext> GLContextProviderEGL::CreateForCompositorWidget(
-    CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
-  MOZ_ASSERT(aCompositorWidget);
-  return GLContextEGLFactory::Create(
-      GET_NATIVE_WINDOW_FROM_COMPOSITOR_WIDGET(aCompositorWidget),
-      aCompositorWidget->GetCompositorOptions().UseWebRender());
+    CompositorWidget* aCompositorWidget, bool aWebRender,
+    bool aForceAccelerated) {
+  EGLNativeWindowType window = nullptr;
+  if (aCompositorWidget) {
+    window = GET_NATIVE_WINDOW_FROM_COMPOSITOR_WIDGET(aCompositorWidget);
+  }
+  return GLContextEGLFactory::Create(window, aWebRender);
 }
 
 already_AddRefed<GLContext> GLContextProviderEGL::CreateForWindow(
     nsIWidget* aWidget, bool aWebRender, bool aForceAccelerated) {
   MOZ_ASSERT(aWidget);
   return GLContextEGLFactory::Create(
       GET_NATIVE_WINDOW_FROM_REAL_WIDGET(aWidget), aWebRender);
 }
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -740,23 +740,27 @@ already_AddRefed<GLContext> CreateForWid
     flags = CreateContextFlags::REQUIRE_COMPAT_PROFILE;
   }
   return GLContextGLX::CreateGLContext(flags, SurfaceCaps::Any(), false,
                                        aXDisplay, aXWindow, config, false,
                                        nullptr);
 }
 
 already_AddRefed<GLContext> GLContextProviderGLX::CreateForCompositorWidget(
-    CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
+    CompositorWidget* aCompositorWidget, bool aWebRender,
+    bool aForceAccelerated) {
+  if (!aCompositorWidget) {
+    MOZ_ASSERT(false);
+    return nullptr;
+  }
   GtkCompositorWidget* compWidget = aCompositorWidget->AsX11();
   MOZ_ASSERT(compWidget);
 
   return CreateForWidget(compWidget->XDisplay(), compWidget->XWindow(),
-                         compWidget->GetCompositorOptions().UseWebRender(),
-                         aForceAccelerated);
+                         aWebRender, aForceAccelerated);
 }
 
 already_AddRefed<GLContext> GLContextProviderGLX::CreateForWindow(
     nsIWidget* aWidget, bool aWebRender, bool aForceAccelerated) {
   Display* display =
       (Display*)aWidget->GetNativeData(NS_NATIVE_COMPOSITOR_DISPLAY);
   Window window = GET_NATIVE_WINDOW(aWidget);
 
--- a/gfx/gl/GLContextProviderImpl.h
+++ b/gfx/gl/GLContextProviderImpl.h
@@ -35,17 +35,17 @@ class GL_CONTEXT_PROVIDER_NAME {
    * a GL layer manager.
    *
    * @param aCompositorWidget Widget whose surface to create a context for
    * @param aForceAccelerated true if only accelerated contexts are allowed
    *
    * @return Context to use for the window
    */
   static already_AddRefed<GLContext> CreateForCompositorWidget(
-      mozilla::widget::CompositorWidget* aCompositorWidget,
+      mozilla::widget::CompositorWidget* aCompositorWidget, bool aWebRender,
       bool aForceAccelerated);
 
   /**
    * Create a context that renders to the surface of the widget that is
    * passed in.  The context is always created with an RGB pixel format,
    * with no alpha, depth or stencil.  If any of those features are needed,
    * either use a framebuffer, or use CreateOffscreen.
    *
--- a/gfx/gl/GLContextProviderNull.cpp
+++ b/gfx/gl/GLContextProviderNull.cpp
@@ -6,17 +6,18 @@
 #include "GLContextProvider.h"
 
 namespace mozilla {
 namespace gl {
 
 using namespace mozilla::widget;
 
 already_AddRefed<GLContext> GLContextProviderNull::CreateForCompositorWidget(
-    CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
+    CompositorWidget* aCompositorWidget, bool aWebRender,
+    bool aForceAccelerated) {
   return nullptr;
 }
 
 already_AddRefed<GLContext> GLContextProviderNull::CreateForWindow(
     nsIWidget* aWidget, bool aWebRender, bool aForceAccelerated) {
   return nullptr;
 }
 
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -447,21 +447,24 @@ static RefPtr<GLContext> CreateForWidget
   cleanupDc.release();
   gl->mIsDoubleBuffered = true;
   if (!gl->Init()) return nullptr;
 
   return gl;
 }
 
 already_AddRefed<GLContext> GLContextProviderWGL::CreateForCompositorWidget(
-    CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
-  return CreateForWidget(
-             aCompositorWidget->AsWindows()->GetHwnd(),
-             aCompositorWidget->GetCompositorOptions().UseWebRender(),
-             aForceAccelerated)
+    CompositorWidget* aCompositorWidget, bool aWebRender,
+    bool aForceAccelerated) {
+  if (!aCompositorWidget) {
+    MOZ_ASSERT(false);
+    return nullptr;
+  }
+  return CreateForWidget(aCompositorWidget->AsWindows()->GetHwnd(), aWebRender,
+                         aForceAccelerated)
       .forget();
 }
 
 already_AddRefed<GLContext> GLContextProviderWGL::CreateForWindow(
     nsIWidget* aWidget, bool aWebRender, bool aForceAccelerated) {
   return CreateForWidget((HWND)aWidget->GetNativeData(NS_NATIVE_WINDOW),
                          aWebRender, aForceAccelerated)
       .forget();
--- a/gfx/gl/GLContextProviderWayland.cpp
+++ b/gfx/gl/GLContextProviderWayland.cpp
@@ -24,23 +24,24 @@ already_AddRefed<GLContext> GLContextPro
   if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
     return sGLContextProviderGLX.CreateWrappingExisting(aContext, aSurface);
   } else {
     return sGLContextProviderEGL.CreateWrappingExisting(aContext, aSurface);
   }
 }
 
 already_AddRefed<GLContext> GLContextProviderWayland::CreateForCompositorWidget(
-    CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
+    CompositorWidget* aCompositorWidget, bool aWebRender,
+    bool aForceAccelerated) {
   if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
-    return sGLContextProviderGLX.CreateForCompositorWidget(aCompositorWidget,
-                                                           aForceAccelerated);
+    return sGLContextProviderGLX.CreateForCompositorWidget(
+        aCompositorWidget, aWebRender, aForceAccelerated);
   } else {
-    return sGLContextProviderEGL.CreateForCompositorWidget(aCompositorWidget,
-                                                           aForceAccelerated);
+    return sGLContextProviderEGL.CreateForCompositorWidget(
+        aCompositorWidget, aWebRender, aForceAccelerated);
   }
 }
 
 already_AddRefed<GLContext> GLContextProviderWayland::CreateForWindow(
     nsIWidget* aWidget, bool aWebRender, bool aForceAccelerated) {
   if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
     return sGLContextProviderGLX.CreateForWindow(aWidget, aWebRender,
                                                  aForceAccelerated);
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -222,18 +222,18 @@ already_AddRefed<mozilla::gl::GLContext>
   if (widgetOpenGLContext) {
     GLContext* alreadyRefed = reinterpret_cast<GLContext*>(widgetOpenGLContext);
     return already_AddRefed<GLContext>(alreadyRefed);
   }
 
 #ifdef XP_WIN
   if (gfxEnv::LayersPreferEGL()) {
     printf_stderr("Trying GL layers...\n");
-    context =
-        gl::GLContextProviderEGL::CreateForCompositorWidget(mWidget, false);
+    context = gl::GLContextProviderEGL::CreateForCompositorWidget(
+        mWidget, /* aWebRender */ false, /* aForceAccelerated */ false);
   }
 #endif
 
   // Allow to create offscreen GL context for main Layer Manager
   if (!context && gfxEnv::LayersPreferOffscreen()) {
     SurfaceCaps caps = SurfaceCaps::ForRGB();
     caps.preserve = false;
     caps.bpp16 = gfxVars::OffscreenFormat() == SurfaceFormat::R5G6B5_UINT16;
@@ -241,17 +241,19 @@ already_AddRefed<mozilla::gl::GLContext>
     nsCString discardFailureId;
     context = GLContextProvider::CreateOffscreen(
         mSurfaceSize, caps, CreateContextFlags::REQUIRE_COMPAT_PROFILE,
         &discardFailureId);
   }
 
   if (!context) {
     context = gl::GLContextProvider::CreateForCompositorWidget(
-        mWidget, gfxVars::RequiresAcceleratedGLContextForCompositorOGL());
+        mWidget,
+        /* aWebRender */ false,
+        gfxVars::RequiresAcceleratedGLContextForCompositorOGL());
   }
 
   if (!context) {
     NS_WARNING("Failed to create CompositorOGL context");
   }
 
   return context.forget();
 }
--- a/gfx/webrender_bindings/RenderCompositorEGL.cpp
+++ b/gfx/webrender_bindings/RenderCompositorEGL.cpp
@@ -22,38 +22,30 @@ namespace wr {
 /* static */
 UniquePtr<RenderCompositor> RenderCompositorEGL::Create(
     RefPtr<widget::CompositorWidget> aWidget) {
   if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
     return nullptr;
   }
 
   RefPtr<gl::GLContext> gl;
-  gl = CreateGLContext(aWidget);
+  gl = CreateGLContext();
   if (!gl) {
     return nullptr;
   }
   return MakeUnique<RenderCompositorEGL>(gl, aWidget);
 }
 
 /* static */ already_AddRefed<gl::GLContext>
-RenderCompositorEGL::CreateGLContext(RefPtr<widget::CompositorWidget> aWidget) {
-  nsCString discardFailureId;
-
+RenderCompositorEGL::CreateGLContext() {
   // Create GLContext with dummy EGLSurface.
   RefPtr<gl::GLContext> gl =
-      // XXX headless context did not work.
-      gl::GLContextProviderEGL::CreateForCompositorWidget(aWidget, true);
-  if (!gl) {
-    gfxCriticalNote << "Failed GL context creation for WebRender: "
-                    << gfx::hexa(gl.get());
-    return nullptr;
-  }
-
-  if (!gl->MakeCurrent()) {
+      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();
 }
 
--- a/gfx/webrender_bindings/RenderCompositorEGL.h
+++ b/gfx/webrender_bindings/RenderCompositorEGL.h
@@ -33,18 +33,17 @@ class RenderCompositorEGL : public Rende
 
   bool MakeCurrent() override;
 
   bool UseANGLE() const override { return false; }
 
   LayoutDeviceIntSize GetBufferSize() override;
 
  protected:
-  static already_AddRefed<gl::GLContext> CreateGLContext(
-      RefPtr<widget::CompositorWidget> aWidget);
+  static already_AddRefed<gl::GLContext> CreateGLContext();
   EGLSurface CreateEGLSurface();
 
   void DestroyEGLSurface();
 
   const RefPtr<gl::GLContext> mGL;
   EGLSurface mEGLSurface;
 };
 
--- a/gfx/webrender_bindings/RenderCompositorOGL.cpp
+++ b/gfx/webrender_bindings/RenderCompositorOGL.cpp
@@ -12,17 +12,18 @@
 
 namespace mozilla {
 namespace wr {
 
 /* static */
 UniquePtr<RenderCompositor> RenderCompositorOGL::Create(
     RefPtr<widget::CompositorWidget>&& aWidget) {
   RefPtr<gl::GLContext> gl;
-  gl = gl::GLContextProvider::CreateForCompositorWidget(aWidget, true);
+  gl = gl::GLContextProvider::CreateForCompositorWidget(
+      aWidget, /* aWebRender */ true, /* aForceAccelerated */ true);
   if (!gl || !gl->MakeCurrent()) {
     gfxCriticalNote << "Failed GL context creation for WebRender: "
                     << gfx::hexa(gl.get());
     return nullptr;
   }
   return MakeUnique<RenderCompositorOGL>(std::move(gl), std::move(aWidget));
 }