Bug 1449271 - Add a pref called gfx.compositor.glcontext.opaque that defaults to false and can be set to true in order to force the use of an opaque OpenGL context for the window on Mac. r?jrmuizel draft
authorMarkus Stange <mstange@themasta.com>
Tue, 27 Mar 2018 14:43:38 -0400
changeset 773264 d736902fb7b45a4016bd2e0ed641a538f1531515
parent 773260 ae9ea5d9b6dca99c1047c6dfa74fb070836a7d17
push id104190
push userbmo:mstange@themasta.com
push dateTue, 27 Mar 2018 18:44:11 +0000
reviewersjrmuizel
bugs1449271
milestone61.0a1
Bug 1449271 - Add a pref called gfx.compositor.glcontext.opaque that defaults to false and can be set to true in order to force the use of an opaque OpenGL context for the window on Mac. r?jrmuizel MozReview-Commit-ID: InOKiLXGL7o
gfx/gl/GLContextProviderCGL.mm
gfx/thebes/gfxPrefs.h
modules/libpref/init/all.js
widget/cocoa/nsChildView.mm
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -277,18 +277,17 @@ GLContextProviderCGL::CreateForWindow(ns
     } else {
         attribs = aForceAccelerated ? kAttribs_singleBuffered_accel : kAttribs_singleBuffered;
     }
     NSOpenGLContext* context = CreateWithFormat(attribs);
     if (!context) {
         return nullptr;
     }
 
-    // make the context transparent
-    GLint opaque = 0;
+    GLint opaque = gfxPrefs::CompositorGLContextOpaque();
     [context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
 
     RefPtr<GLContextCGL> glContext = new GLContextCGL(CreateContextFlags::NONE,
                                                       SurfaceCaps::ForRGBA(), context,
                                                       false);
 
     if (!glContext->Init()) {
         glContext = nullptr;
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -434,16 +434,17 @@ private:
 #endif
 #if defined(RELEASE_OR_BETA)
   // "Skip" means this is locked to the default value in beta and release.
   DECL_GFX_PREF(Skip, "gfx.blocklist.all",                     BlocklistAll, int32_t, 0);
 #else
   DECL_GFX_PREF(Once, "gfx.blocklist.all",                     BlocklistAll, int32_t, 0);
 #endif
   DECL_GFX_PREF(Live, "gfx.compositor.clearstate",             CompositorClearState, bool, false);
+  DECL_GFX_PREF(Live, "gfx.compositor.glcontext.opaque",       CompositorGLContextOpaque, bool, false);
   DECL_GFX_PREF(Live, "gfx.canvas.auto_accelerate.min_calls",  CanvasAutoAccelerateMinCalls, int32_t, 4);
   DECL_GFX_PREF(Live, "gfx.canvas.auto_accelerate.min_frames", CanvasAutoAccelerateMinFrames, int32_t, 30);
   DECL_GFX_PREF(Live, "gfx.canvas.auto_accelerate.min_seconds", CanvasAutoAccelerateMinSeconds, float, 5.0f);
   DECL_GFX_PREF(Live, "gfx.canvas.azure.accelerated",          CanvasAzureAccelerated, bool, false);
   DECL_GFX_PREF(Once, "gfx.canvas.azure.accelerated.limit",    CanvasAzureAcceleratedLimit, int32_t, 0);
   // 0x7fff is the maximum supported xlib surface size and is more than enough for canvases.
   DECL_GFX_PREF(Live, "gfx.canvas.max-size",                   MaxCanvasSize, int32_t, 0x7fff);
   DECL_GFX_PREF(Once, "gfx.canvas.skiagl.cache-items",         CanvasSkiaGLCacheItems, int32_t, 256);
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -917,16 +917,20 @@ pref("gfx.webrender.enabled", true);
 #else
 pref("gfx.webrender.enabled", false);
 #endif
 #ifdef XP_WIN
 pref("gfx.webrender.force-angle", true);
 pref("gfx.webrender.program-binary", true);
 #endif
 
+#ifdef XP_MACOSX
+pref("gfx.compositor.glcontext.opaque", false);
+#endif
+
 pref("gfx.webrender.highlight-painted-layers", false);
 pref("gfx.webrender.blob-images", 1);
 pref("gfx.webrender.hit-test", true);
 
 // WebRender debugging utilities.
 pref("gfx.webrender.debug.texture-cache", false);
 pref("gfx.webrender.debug.render-targets", false);
 pref("gfx.webrender.debug.alpha-primitives", false);
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -3845,18 +3845,19 @@ NSEvent* gLastDragMouseDownEvent = nil;
     return 4.0f;
   return [frameView roundedCornerRadius];
 }
 
 -(void)setGLOpaque:(BOOL)aOpaque
 {
   CGLLockContext((CGLContextObj)[mGLContext CGLContextObj]);
   // Make the context opaque for fullscreen (since it performs better), and transparent
-  // for windowed (since we need it for rounded corners).
-  GLint opaque = aOpaque ? 1 : 0;
+  // for windowed (since we need it for rounded corners), but allow overriding
+  // it to opaque for testing purposes, even if that breaks the rounded corners.
+  GLint opaque = aOpaque || gfxPrefs::CompositorGLContextOpaque();
   [mGLContext setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
   CGLUnlockContext((CGLContextObj)[mGLContext CGLContextObj]);
 }
 
 // Accelerated windows have two NSSurfaces:
 //  (1) The window's pixel buffer in the back and
 //  (2) the OpenGL view in the front.
 // These two surfaces are composited by the window manager. Drawing into the