Bug 1326421 - Update GL context creation code to use compositor-specific WebRender flag instead of a global pref. r?dvander
MozReview-Commit-ID: FzlPa6QcezB
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -8,16 +8,17 @@
#include "nsDebug.h"
#include "nsIWidget.h"
#include <OpenGL/gl.h>
#include "gfxFailure.h"
#include "gfxPrefs.h"
#include "prenv.h"
#include "GeckoProfiler.h"
#include "mozilla/gfx/MacIOSurface.h"
+#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/widget/CompositorWidget.h"
#include <OpenGL/OpenGL.h>
// When running inside a VM, creating an accelerated OpenGL context usually
// fails. Uncomment this line to emulate that behavior.
// #define EMULATE_VM
@@ -242,35 +243,39 @@ CreateWithFormat(const NSOpenGLPixelForm
[format release];
return context;
}
already_AddRefed<GLContext>
GLContextProviderCGL::CreateForCompositorWidget(CompositorWidget* aCompositorWidget, bool aForceAccelerated)
{
- return CreateForWindow(aCompositorWidget->RealWidget(), aForceAccelerated);
+ return CreateForWindow(aCompositorWidget->RealWidget(),
+ aCompositorWidget->GetCompositorOptions().UseWebRender(),
+ aForceAccelerated);
}
already_AddRefed<GLContext>
-GLContextProviderCGL::CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated)
+GLContextProviderCGL::CreateForWindow(nsIWidget* aWidget,
+ bool aWebRender,
+ bool aForceAccelerated)
{
if (!sCGLLibrary.EnsureInitialized()) {
return nullptr;
}
#ifdef EMULATE_VM
if (aForceAccelerated) {
return nullptr;
}
#endif
const NSOpenGLPixelFormatAttribute* attribs;
if (sCGLLibrary.UseDoubleBufferedWindows()) {
- if (gfxPrefs::WebRenderEnabled()) {
+ if (aWebRender) {
attribs = aForceAccelerated ? kAttribs_doubleBuffered_accel_webrender : kAttribs_doubleBuffered;
} else {
attribs = aForceAccelerated ? kAttribs_doubleBuffered_accel : kAttribs_doubleBuffered;
}
} else {
attribs = aForceAccelerated ? kAttribs_singleBuffered_accel : kAttribs_singleBuffered;
}
NSOpenGLContext* context = CreateWithFormat(attribs);
--- a/gfx/gl/GLContextProviderEAGL.mm
+++ b/gfx/gl/GLContextProviderEAGL.mm
@@ -6,16 +6,17 @@
#include "GLContextProvider.h"
#include "GLContextEAGL.h"
#include "nsDebug.h"
#include "nsIWidget.h"
#include "gfxPrefs.h"
#include "gfxFailure.h"
#include "prenv.h"
#include "mozilla/Preferences.h"
+#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/widget/CompositorWidget.h"
#include "GeckoProfiler.h"
#import <UIKit/UIKit.h>
namespace mozilla {
namespace gl {
@@ -205,21 +206,25 @@ CreateEAGLContext(CreateContextFlags fla
}
return glContext.forget();
}
already_AddRefed<GLContext>
GLContextProviderEAGL::CreateForCompositorWidget(CompositorWidget* aCompositorWidget, bool aForceAccelerated)
{
- return CreateForWindow(aCompositorWidget->RealWidget(), aForceAccelerated);
+ return CreateForWindow(aCompositorWidget->RealWidget(),
+ aCompositorWidget->GetCompositorOptions().UseWebRender(),
+ aForceAccelerated);
}
already_AddRefed<GLContext>
-GLContextProviderEAGL::CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated)
+GLContextProviderEAGL::CreateForWindow(nsIWidget* aWidget,
+ bool aWebRender,
+ bool aForceAccelerated)
{
RefPtr<GLContext> glContext = CreateEAGLContext(CreateContextFlags::NONE, false,
GetGlobalContextEAGL());
if (!glContext) {
return nullptr;
}
if (!GLContextEAGL::Cast(glContext)->AttachToWindow(aWidget)) {
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -84,16 +84,17 @@
#include "gfxPlatform.h"
#include "gfxUtils.h"
#include "GLBlitHelper.h"
#include "GLContextEGL.h"
#include "GLContextProvider.h"
#include "GLLibraryEGL.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Preferences.h"
+#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/widget/CompositorWidget.h"
#include "nsDebug.h"
#include "nsIWidget.h"
#include "nsThreadUtils.h"
#include "ScopedGLHelpers.h"
#include "TextureImageEGL.h"
using namespace mozilla::gfx;
@@ -705,21 +706,25 @@ GLContextProviderEGL::CreateWrappingExis
gl->mOwnsContext = false;
return gl.forget();
}
already_AddRefed<GLContext>
GLContextProviderEGL::CreateForCompositorWidget(CompositorWidget* aCompositorWidget, bool aForceAccelerated)
{
- return CreateForWindow(aCompositorWidget->RealWidget(), aForceAccelerated);
+ return CreateForWindow(aCompositorWidget->RealWidget(),
+ aCompositorWidget->GetCompositorOptions().UseWebRender(),
+ aForceAccelerated);
}
already_AddRefed<GLContext>
-GLContextProviderEGL::CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated)
+GLContextProviderEGL::CreateForWindow(nsIWidget* aWidget,
+ bool aWebRender,
+ bool aForceAccelerated)
{
nsCString discardFailureId;
if (!sEGLLibrary.EnsureInitialized(false, &discardFailureId)) {
MOZ_CRASH("GFX: Failed to load EGL library 3!\n");
return nullptr;
}
bool doubleBuffered = true;
@@ -732,17 +737,17 @@ GLContextProviderEGL::CreateForWindow(ns
EGLSurface surface = mozilla::gl::CreateSurfaceForWindow(aWidget, config);
if (!surface) {
MOZ_CRASH("GFX: Failed to create EGLSurface!\n");
return nullptr;
}
CreateContextFlags flags = CreateContextFlags::NONE;
- if (gfxPrefs::WebRenderEnabled()) {
+ if (aWebRender) {
flags |= CreateContextFlags::PREFER_ES3;
}
SurfaceCaps caps = SurfaceCaps::Any();
RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(flags,
caps, nullptr, false, config,
surface, &discardFailureId);
if (!gl) {
MOZ_CRASH("GFX: Failed to create EGLContext!\n");
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -10,16 +10,17 @@
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "X11UndefineNone.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/StaticPtr.h"
+#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/widget/CompositorWidget.h"
#include "mozilla/widget/X11CompositorWidget.h"
#include "mozilla/Unused.h"
#include "prenv.h"
#include "GLContextProvider.h"
#include "GLLibraryLoader.h"
#include "nsDebug.h"
@@ -1094,17 +1095,19 @@ GLContextProviderGLX::CreateWrappingExis
return glContext.forget();
}
return nullptr;
}
already_AddRefed<GLContext>
-CreateForWidget(Display* aXDisplay, Window aXWindow, bool aForceAccelerated)
+CreateForWidget(Display* aXDisplay, Window aXWindow,
+ bool aWebRender,
+ bool aForceAccelerated)
{
if (!sGLXLibrary.EnsureInitialized()) {
return nullptr;
}
// Currently, we take whatever Visual the window already has, and
// try to create an fbconfig for that visual. This isn't
// necessarily what we want in the long run; an fbconfig may not
@@ -1126,17 +1129,17 @@ CreateForWidget(Display* aXDisplay, Wind
&config, &visid))
{
return nullptr;
}
SurfaceCaps caps = SurfaceCaps::Any();
GLContextGLX* shareContext = GetGlobalContextGLX();
RefPtr<GLContextGLX> gl;
- if (gfxPrefs::WebRenderEnabled()) {
+ if (aWebRender) {
gl = GLContextGLX::CreateGLContext(CreateContextFlags::NONE,
caps, shareContext, false,
aXDisplay, aXWindow, config,
//TODO: we might want to pass an additional bool to select GL core/compat
false, nullptr, ContextProfile::OpenGLCore); //WR: required GL 3.2+
} else {
gl = GLContextGLX::CreateGLContext(CreateContextFlags::NONE,
caps, shareContext, false,
@@ -1150,27 +1153,31 @@ CreateForWidget(Display* aXDisplay, Wind
already_AddRefed<GLContext>
GLContextProviderGLX::CreateForCompositorWidget(CompositorWidget* aCompositorWidget, bool aForceAccelerated)
{
X11CompositorWidget* compWidget = aCompositorWidget->AsX11();
MOZ_ASSERT(compWidget);
return CreateForWidget(compWidget->XDisplay(),
compWidget->XWindow(),
+ compWidget->GetCompositorOptions().UseWebRender(),
aForceAccelerated);
}
already_AddRefed<GLContext>
-GLContextProviderGLX::CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated)
+GLContextProviderGLX::CreateForWindow(nsIWidget* aWidget,
+ bool aWebRender,
+ bool aForceAccelerated)
{
Display* display = (Display*)aWidget->GetNativeData(NS_NATIVE_COMPOSITOR_DISPLAY);
Window window = GET_NATIVE_WINDOW(aWidget);
return CreateForWidget(display,
window,
+ aWebRender,
aForceAccelerated);
}
static bool
ChooseConfig(GLXLibrary* glx, Display* display, int screen, const SurfaceCaps& minCaps,
ScopedXFree<GLXFBConfig>* const out_scopedConfigArr,
GLXFBConfig* const out_config, int* const out_visid)
{
--- a/gfx/gl/GLContextProviderImpl.h
+++ b/gfx/gl/GLContextProviderImpl.h
@@ -56,22 +56,23 @@ public:
* The GetSharedContext() method will return non-null if sharing
* was successful.
*
* Note: a context created for a widget /must not/ hold a strong
* reference to the widget; otherwise a cycle can be created through
* a GL layer manager.
*
* @param aWidget Widget whose surface to create a context for
+ * @param aWebRender If the compositor is a WebRender compositor
* @param aForceAccelerated true if only accelerated contexts are allowed
*
* @return Context to use for the window
*/
static already_AddRefed<GLContext>
- CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated);
+ CreateForWindow(nsIWidget* aWidget, bool aWebRender, bool aForceAccelerated);
/**
* Create a context for offscreen rendering. The target of this
* context should be treated as opaque -- it might be a FBO, or a
* pbuffer, or some other construct. Users of this GLContext
* should bind framebuffer 0 directly to use this offscreen buffer.
*
* The offscreen context returned by this method will always have
--- a/gfx/gl/GLContextProviderNull.cpp
+++ b/gfx/gl/GLContextProviderNull.cpp
@@ -12,17 +12,19 @@ using namespace mozilla::widget;
already_AddRefed<GLContext>
GLContextProviderNull::CreateForCompositorWidget(CompositorWidget* aCompositorWidget, bool aForceAccelerated)
{
return nullptr;
}
already_AddRefed<GLContext>
-GLContextProviderNull::CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated)
+GLContextProviderNull::CreateForWindow(nsIWidget* aWidget,
+ bool aWebRender,
+ bool aForceAccelerated)
{
return nullptr;
}
already_AddRefed<GLContext>
GLContextProviderNull::CreateWrappingExisting(void*, void*)
{
return nullptr;
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -13,16 +13,17 @@
#include "gfxCrashReporterUtils.h"
#include "prenv.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPtr.h"
+#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/widget/CompositorWidget.h"
namespace mozilla {
namespace gl {
using namespace mozilla::gfx;
using namespace mozilla::widget;
@@ -431,21 +432,25 @@ already_AddRefed<GLContext>
GLContextProviderWGL::CreateWrappingExisting(void*, void*)
{
return nullptr;
}
already_AddRefed<GLContext>
GLContextProviderWGL::CreateForCompositorWidget(CompositorWidget* aCompositorWidget, bool aForceAccelerated)
{
- return CreateForWindow(aCompositorWidget->RealWidget(), aForceAccelerated);
+ return CreateForWindow(aCompositorWidget->RealWidget(),
+ aCompositorWidget->GetCompositorOptions().UseWebRender(),
+ aForceAccelerated);
}
already_AddRefed<GLContext>
-GLContextProviderWGL::CreateForWindow(nsIWidget* aWidget, bool aForceAccelerated)
+GLContextProviderWGL::CreateForWindow(nsIWidget* aWidget,
+ bool aWebRender,
+ bool aForceAccelerated)
{
if (!sWGLLib.EnsureInitialized()) {
return nullptr;
}
/**
* We need to make sure we call SetPixelFormat -after- calling
* EnsureInitialized, otherwise it can load/unload the dll and
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -145,17 +145,21 @@ GetAndInitWARPDisplay(GLLibraryEGL& egl,
return display;
}
static bool
IsAccelAngleSupported(const nsCOMPtr<nsIGfxInfo>& gfxInfo,
nsACString* const out_failureId)
{
if (CompositorThreadHolder::IsInCompositorThread()) {
- MOZ_ASSERT(gfxPrefs::WebRenderEnabled());
+ // We can only enter here with WebRender, so assert that this is a
+ // WebRender-enabled build.
+#ifndef MOZ_ENABLE_WEBRENDER
+ MOZ_ASSERT(false);
+#endif
return true;
}
int32_t angleSupport;
nsCString failureId;
gfxUtils::ThreadSafeGetFeatureStatus(gfxInfo,
nsIGfxInfo::FEATURE_WEBGL_ANGLE,
failureId,
&angleSupport);
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -274,17 +274,17 @@ namespace {
// deadlocks in our setup. See bug 882523.
class GLPresenter : public GLManager
{
public:
static mozilla::UniquePtr<GLPresenter> CreateForWindow(nsIWidget* aWindow)
{
// Contrary to CompositorOGL, we allow unaccelerated OpenGL contexts to be
// used. BasicCompositor only requires very basic GL functionality.
- RefPtr<GLContext> context = gl::GLContextProvider::CreateForWindow(aWindow, false);
+ RefPtr<GLContext> context = gl::GLContextProvider::CreateForWindow(aWindow, false, false);
return context ? MakeUnique<GLPresenter>(context) : nullptr;
}
explicit GLPresenter(GLContext* aContext);
virtual ~GLPresenter();
virtual GLContext* gl() const override { return mGLContext; }
virtual ShaderProgramOGL* GetProgram(GLenum aTarget, gfx::SurfaceFormat aFormat) override