Bug 1514156 - Add GLContextEGL::CreateEGLSurfaceForCompositorWidget() for Wayland r=jgilbert
authorsotaro <sotaro.ikeda.g@gmail.com>
Tue, 12 Feb 2019 16:32:51 +0900
changeset 458691 d97a89ada9e6
parent 458690 1c7af47c1ba4
child 458692 19ccde31eaaa
push id35544
push userccoroiu@mozilla.com
push dateTue, 12 Feb 2019 16:29:08 +0000
treeherdermozilla-central@c849fb69e2e7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1514156
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 1514156 - Add GLContextEGL::CreateEGLSurfaceForCompositorWidget() for Wayland r=jgilbert When GDK_BACKEND is wayland, widget is not fully mapped during creating CompositorSession. During CompositorSession creation, GLContextProviderEGL::CreateForCompositorWidget() creates GLContextEGL, but we could not create valid EGLSurface. We could create valid EGLSurface when widget is fully mapped. CreateEGLSurfaceForCompositorWidget() is used for creating valid EGLSurface after widget is fully mapped. Differential Revision: https://phabricator.services.mozilla.com/D18654
gfx/gl/GLContextEGL.h
gfx/gl/GLContextProviderEGL.cpp
--- a/gfx/gl/GLContextEGL.h
+++ b/gfx/gl/GLContextEGL.h
@@ -86,16 +86,20 @@ class GLContextEGL : public GLContext {
   void BindOffscreenFramebuffer();
 
   void Destroy();
 
   static already_AddRefed<GLContextEGL> CreateEGLPBufferOffscreenContext(
       CreateContextFlags flags, const gfx::IntSize& size,
       const SurfaceCaps& minCaps, nsACString* const out_FailureId);
 
+#if defined(MOZ_WAYLAND)
+  static EGLSurface CreateEGLSurfaceForCompositorWidget(
+      widget::CompositorWidget* aCompositorWidget, bool aForceAccelerated);
+#endif
  protected:
   friend class GLContextProviderEGL;
   friend class GLContextEGLFactory;
 
   virtual void OnMarkDestroyed() override;
 
  public:
   const EGLConfig mConfig;
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -291,16 +291,43 @@ already_AddRefed<GLContext> GLContextEGL
   gl->SetIsDoubleBuffered(doubleBuffered);
   if (aWebRender && egl->IsANGLE()) {
     MOZ_ASSERT(doubleBuffered);
     egl->fSwapInterval(EGL_DISPLAY(), 0);
   }
   return gl.forget();
 }
 
+#if defined(MOZ_WAYLAND)
+/* static */ EGLSurface GLContextEGL::CreateEGLSurfaceForCompositorWidget(
+    widget::CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
+  nsCString discardFailureId;
+  if (!GLLibraryEGL::EnsureInitialized(false, &discardFailureId)) {
+    gfxCriticalNote << "Failed to load EGL library 6!";
+    return EGL_NO_SURFACE;
+  }
+
+  MOZ_ASSERT(aCompositorWidget);
+  EGLNativeWindowType window = GET_NATIVE_WINDOW_FROM_COMPOSITOR_WIDGET(aCompositorWidget);
+  if (!window) {
+    gfxCriticalNote << "window is null";
+    return EGL_NO_SURFACE;
+  }
+  const bool useWebRender = aCompositorWidget->GetCompositorOptions().UseWebRender();
+
+  EGLConfig config;
+  if (!CreateConfig(&config, useWebRender)) {
+    gfxCriticalNote << "Failed to create EGLConfig!";
+    return EGL_NO_SURFACE;
+  }
+
+  return mozilla::gl::CreateSurfaceFromNativeWindow(window, config);
+}
+#endif
+
 GLContextEGL::GLContextEGL(CreateContextFlags flags, const SurfaceCaps& caps,
                            bool isOffscreen, EGLConfig config,
                            EGLSurface surface, EGLContext context)
     : GLContext(flags, caps, nullptr, isOffscreen, false),
       mConfig(config),
       mEgl(gl::GLLibraryEGL::Get()),
       mSurface(surface),
       mFallbackSurface(CreateFallbackSurface(config)),