From 2c65d7229cf6415d274077cc4b58db826653422a Mon Sep 17 00:00:00 2001 From: sotaro Date: Wed, 13 Mar 2019 00:17:01 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- gfx/gl/GLContextProviderCGL.mm | 10 ++++++---- gfx/gl/GLContextProviderEAGL.mm | 10 ++++++---- gfx/gl/GLContextProviderEGL.cpp | 12 +++++++----- gfx/gl/GLContextProviderGLX.cpp | 10 +++++++--- gfx/gl/GLContextProviderImpl.h | 2 +- gfx/gl/GLContextProviderNull.cpp | 3 ++- gfx/gl/GLContextProviderWGL.cpp | 13 ++++++++----- gfx/gl/GLContextProviderWayland.cpp | 11 ++++++----- gfx/layers/opengl/CompositorOGL.cpp | 8 +++++--- gfx/webrender_bindings/RenderCompositorEGL.cpp | 18 +++++------------- gfx/webrender_bindings/RenderCompositorEGL.h | 3 +-- gfx/webrender_bindings/RenderCompositorOGL.cpp | 3 ++- 12 files changed, 56 insertions(+), 47 deletions(-) diff --git a/gfx/gl/GLContextProviderCGL.mm b/gfx/gl/GLContextProviderCGL.mm index a7829c73d037..0e771ed436e6 100644 --- a/gfx/gl/GLContextProviderCGL.mm +++ b/gfx/gl/GLContextProviderCGL.mm @@ -166,10 +166,12 @@ static NSOpenGLContext* CreateWithFormat(const NSOpenGLPixelFormatAttribute* att } already_AddRefed 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 GLContextProviderCGL::CreateForWindow(nsIWidget* aWidget, diff --git a/gfx/gl/GLContextProviderEAGL.mm b/gfx/gl/GLContextProviderEAGL.mm index d5a6a204ea11..2af1ffa61fd8 100644 --- a/gfx/gl/GLContextProviderEAGL.mm +++ b/gfx/gl/GLContextProviderEAGL.mm @@ -166,10 +166,12 @@ static already_AddRefed CreateEAGLContext(CreateContextFlags flags, b } already_AddRefed 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 GLContextProviderEAGL::CreateForWindow(nsIWidget* aWidget, diff --git a/gfx/gl/GLContextProviderEGL.cpp b/gfx/gl/GLContextProviderEGL.cpp index 02e8bfc0ce78..66a03abf46ce 100644 --- a/gfx/gl/GLContextProviderEGL.cpp +++ b/gfx/gl/GLContextProviderEGL.cpp @@ -868,11 +868,13 @@ already_AddRefed GLContextProviderEGL::CreateWrappingExisting( } already_AddRefed 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 GLContextProviderEGL::CreateForWindow( diff --git a/gfx/gl/GLContextProviderGLX.cpp b/gfx/gl/GLContextProviderGLX.cpp index 252869ea1b26..682e8a893d96 100644 --- a/gfx/gl/GLContextProviderGLX.cpp +++ b/gfx/gl/GLContextProviderGLX.cpp @@ -745,13 +745,17 @@ already_AddRefed CreateForWidget(Display* aXDisplay, Window aXWindow, } already_AddRefed 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 GLContextProviderGLX::CreateForWindow( diff --git a/gfx/gl/GLContextProviderImpl.h b/gfx/gl/GLContextProviderImpl.h index 4cca0999c52d..a3712a51f832 100644 --- a/gfx/gl/GLContextProviderImpl.h +++ b/gfx/gl/GLContextProviderImpl.h @@ -40,7 +40,7 @@ class GL_CONTEXT_PROVIDER_NAME { * @return Context to use for the window */ static already_AddRefed CreateForCompositorWidget( - mozilla::widget::CompositorWidget* aCompositorWidget, + mozilla::widget::CompositorWidget* aCompositorWidget, bool aWebRender, bool aForceAccelerated); /** diff --git a/gfx/gl/GLContextProviderNull.cpp b/gfx/gl/GLContextProviderNull.cpp index 85409be76cc7..991b809ff464 100644 --- a/gfx/gl/GLContextProviderNull.cpp +++ b/gfx/gl/GLContextProviderNull.cpp @@ -11,7 +11,8 @@ namespace gl { using namespace mozilla::widget; already_AddRefed GLContextProviderNull::CreateForCompositorWidget( - CompositorWidget* aCompositorWidget, bool aForceAccelerated) { + CompositorWidget* aCompositorWidget, bool aWebRender, + bool aForceAccelerated) { return nullptr; } diff --git a/gfx/gl/GLContextProviderWGL.cpp b/gfx/gl/GLContextProviderWGL.cpp index ad2e34b8636e..517e77cc034d 100644 --- a/gfx/gl/GLContextProviderWGL.cpp +++ b/gfx/gl/GLContextProviderWGL.cpp @@ -452,11 +452,14 @@ static RefPtr CreateForWidget(const HWND window, } already_AddRefed 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(); } diff --git a/gfx/gl/GLContextProviderWayland.cpp b/gfx/gl/GLContextProviderWayland.cpp index 8b79457e5e83..072c691d7738 100644 --- a/gfx/gl/GLContextProviderWayland.cpp +++ b/gfx/gl/GLContextProviderWayland.cpp @@ -29,13 +29,14 @@ already_AddRefed GLContextProviderWayland::CreateWrappingExisting( } already_AddRefed 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); } } diff --git a/gfx/layers/opengl/CompositorOGL.cpp b/gfx/layers/opengl/CompositorOGL.cpp index 5191400ee959..ba99f37cc897 100644 --- a/gfx/layers/opengl/CompositorOGL.cpp +++ b/gfx/layers/opengl/CompositorOGL.cpp @@ -227,8 +227,8 @@ already_AddRefed CompositorOGL::CreateContext() { #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 @@ -246,7 +246,9 @@ already_AddRefed CompositorOGL::CreateContext() { if (!context) { context = gl::GLContextProvider::CreateForCompositorWidget( - mWidget, gfxVars::RequiresAcceleratedGLContextForCompositorOGL()); + mWidget, + /* aWebRender */ false, + gfxVars::RequiresAcceleratedGLContextForCompositorOGL()); } if (!context) { diff --git a/gfx/webrender_bindings/RenderCompositorEGL.cpp b/gfx/webrender_bindings/RenderCompositorEGL.cpp index f273c8aa89be..d05ee46102f3 100644 --- a/gfx/webrender_bindings/RenderCompositorEGL.cpp +++ b/gfx/webrender_bindings/RenderCompositorEGL.cpp @@ -27,7 +27,7 @@ UniquePtr RenderCompositorEGL::Create( } RefPtr gl; - gl = CreateGLContext(aWidget); + gl = CreateGLContext(); if (!gl) { return nullptr; } @@ -35,20 +35,12 @@ UniquePtr RenderCompositorEGL::Create( } /* static */ already_AddRefed -RenderCompositorEGL::CreateGLContext(RefPtr aWidget) { - nsCString discardFailureId; - +RenderCompositorEGL::CreateGLContext() { // Create GLContext with dummy EGLSurface. RefPtr 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; diff --git a/gfx/webrender_bindings/RenderCompositorEGL.h b/gfx/webrender_bindings/RenderCompositorEGL.h index bf054fe119d3..05d844856260 100644 --- a/gfx/webrender_bindings/RenderCompositorEGL.h +++ b/gfx/webrender_bindings/RenderCompositorEGL.h @@ -38,8 +38,7 @@ class RenderCompositorEGL : public RenderCompositor { LayoutDeviceIntSize GetBufferSize() override; protected: - static already_AddRefed CreateGLContext( - RefPtr aWidget); + static already_AddRefed CreateGLContext(); EGLSurface CreateEGLSurface(); void DestroyEGLSurface(); diff --git a/gfx/webrender_bindings/RenderCompositorOGL.cpp b/gfx/webrender_bindings/RenderCompositorOGL.cpp index e8c5250f9958..1e70412daab4 100644 --- a/gfx/webrender_bindings/RenderCompositorOGL.cpp +++ b/gfx/webrender_bindings/RenderCompositorOGL.cpp @@ -17,7 +17,8 @@ namespace wr { UniquePtr RenderCompositorOGL::Create( RefPtr&& aWidget) { RefPtr 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());