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
This commit is contained in:
sotaro 2019-03-13 00:17:01 +00:00
parent d2f8c37768
commit 2c65d7229c
12 changed files with 56 additions and 47 deletions

View File

@ -166,10 +166,12 @@ static NSOpenGLContext* CreateWithFormat(const NSOpenGLPixelFormatAttribute* att
}
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,

View File

@ -166,10 +166,12 @@ static already_AddRefed<GLContext> CreateEAGLContext(CreateContextFlags flags, b
}
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,

View File

@ -868,11 +868,13 @@ already_AddRefed<GLContext> GLContextProviderEGL::CreateWrappingExisting(
}
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(

View File

@ -745,13 +745,17 @@ already_AddRefed<GLContext> CreateForWidget(Display* aXDisplay, Window aXWindow,
}
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(

View File

@ -40,7 +40,7 @@ class GL_CONTEXT_PROVIDER_NAME {
* @return Context to use for the window
*/
static already_AddRefed<GLContext> CreateForCompositorWidget(
mozilla::widget::CompositorWidget* aCompositorWidget,
mozilla::widget::CompositorWidget* aCompositorWidget, bool aWebRender,
bool aForceAccelerated);
/**

View File

@ -11,7 +11,8 @@ namespace gl {
using namespace mozilla::widget;
already_AddRefed<GLContext> GLContextProviderNull::CreateForCompositorWidget(
CompositorWidget* aCompositorWidget, bool aForceAccelerated) {
CompositorWidget* aCompositorWidget, bool aWebRender,
bool aForceAccelerated) {
return nullptr;
}

View File

@ -452,11 +452,14 @@ static RefPtr<GLContext> CreateForWidget(const HWND window,
}
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();
}

View File

@ -29,13 +29,14 @@ already_AddRefed<GLContext> GLContextProviderWayland::CreateWrappingExisting(
}
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);
}
}

View File

@ -227,8 +227,8 @@ already_AddRefed<mozilla::gl::GLContext> 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<mozilla::gl::GLContext> CompositorOGL::CreateContext() {
if (!context) {
context = gl::GLContextProvider::CreateForCompositorWidget(
mWidget, gfxVars::RequiresAcceleratedGLContextForCompositorOGL());
mWidget,
/* aWebRender */ false,
gfxVars::RequiresAcceleratedGLContextForCompositorOGL());
}
if (!context) {

View File

@ -27,7 +27,7 @@ UniquePtr<RenderCompositor> RenderCompositorEGL::Create(
}
RefPtr<gl::GLContext> gl;
gl = CreateGLContext(aWidget);
gl = CreateGLContext();
if (!gl) {
return nullptr;
}
@ -35,20 +35,12 @@ UniquePtr<RenderCompositor> RenderCompositorEGL::Create(
}
/* 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;

View File

@ -38,8 +38,7 @@ class RenderCompositorEGL : public RenderCompositor {
LayoutDeviceIntSize GetBufferSize() override;
protected:
static already_AddRefed<gl::GLContext> CreateGLContext(
RefPtr<widget::CompositorWidget> aWidget);
static already_AddRefed<gl::GLContext> CreateGLContext();
EGLSurface CreateEGLSurface();
void DestroyEGLSurface();

View File

@ -17,7 +17,8 @@ namespace wr {
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());