Bug 1644606 - Add a pref to select between GLES and desktop GL contexts on EGL, r=gfx-reviewers,nical
authorRobert Mader <robert.mader@posteo.de>
Tue, 19 Oct 2021 11:11:47 +0000
changeset 596341 07e60ed33cc0c4b90775eab2daac7526f63755e9
parent 596340 7eafd0a7d79a5cdf73723bb39243ddb89fdf3918
child 596342 10d29c75b2357d3151048ecb7053a7e552869f93
push id151753
push userrobert.mader@posteo.de
push dateTue, 19 Oct 2021 11:14:11 +0000
treeherderautoland@07e60ed33cc0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfx-reviewers, nical
bugs1644606
milestone95.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 1644606 - Add a pref to select between GLES and desktop GL contexts on EGL, r=gfx-reviewers,nical This preference was requested by driver developers, simplifying debugging processes. It is especially useful on Linux, but may be handy on other platforms as well. As a side effect it also ensures the two places with fallback paths behave the same again on Android. Depends on D128411 Differential Revision: https://phabricator.services.mozilla.com/D128592
gfx/gl/GLContextProviderEGL.cpp
modules/libpref/init/StaticPrefList.yaml
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -317,24 +317,30 @@ already_AddRefed<GLContext> GLContextEGL
     MOZ_ASSERT(doubleBuffered);
     egl->fSwapInterval(0);
   }
   return gl.forget();
 }
 
 already_AddRefed<GLContext> GLContextEGLFactory::Create(
     EGLNativeWindowType aWindow, bool aHardwareWebRender) {
-  RefPtr<GLContext> glContext;
+  bool preferGles;
+#if defined(MOZ_WIDGET_ANDROID)
+  preferGles = true;
+#else
+  preferGles = StaticPrefs::gfx_egl_prefer_gles_enabled_AtStartup();
+#endif  // defined(MOZ_WIDGET_ANDROID)
+
+  RefPtr<GLContext> glContext =
+      CreateImpl(aWindow, aHardwareWebRender, preferGles);
 #if !defined(MOZ_WIDGET_ANDROID)
-  glContext = CreateImpl(aWindow, aHardwareWebRender, /* aUseGles */ false);
+  if (!glContext) {
+    glContext = CreateImpl(aWindow, aHardwareWebRender, !preferGles);
+  }
 #endif  // !defined(MOZ_WIDGET_ANDROID)
-
-  if (!glContext) {
-    glContext = CreateImpl(aWindow, aHardwareWebRender, /* aUseGles */ true);
-  }
   return glContext.forget();
 }
 
 /* static */
 EGLSurface GLContextEGL::CreateEGLSurfaceForCompositorWidget(
     widget::CompositorWidget* aCompositorWidget, const EGLConfig aConfig) {
   nsCString discardFailureId;
   const auto egl = DefaultEglDisplay(&discardFailureId);
@@ -1174,22 +1180,31 @@ RefPtr<GLContextEGL> GLContextEGL::Creat
 
   return gl;
 }
 
 /*static*/
 RefPtr<GLContextEGL> GLContextEGL::CreateEGLPBufferOffscreenContext(
     const std::shared_ptr<EglDisplay> display, const GLContextCreateDesc& desc,
     const mozilla::gfx::IntSize& size, nsACString* const out_failureId) {
+  bool preferGles;
+#if defined(MOZ_WIDGET_ANDROID)
+  preferGles = true;
+#else
+  preferGles = StaticPrefs::gfx_egl_prefer_gles_enabled_AtStartup();
+#endif  // defined(MOZ_WIDGET_ANDROID)
+
   RefPtr<GLContextEGL> gl = CreateEGLPBufferOffscreenContextImpl(
-      display, desc, size, /* useGles */ false, out_failureId);
+      display, desc, size, preferGles, out_failureId);
+#if !defined(MOZ_WIDGET_ANDROID)
   if (!gl) {
-    gl = CreateEGLPBufferOffscreenContextImpl(
-        display, desc, size, /* useGles */ true, out_failureId);
+    gl = CreateEGLPBufferOffscreenContextImpl(display, desc, size, !preferGles,
+                                              out_failureId);
   }
+#endif  // !defined(MOZ_WIDGET_ANDROID)
   return gl;
 }
 
 /*static*/
 already_AddRefed<GLContext> GLContextProviderEGL::CreateHeadless(
     const GLContextCreateDesc& desc, nsACString* const out_failureId) {
   const auto display = DefaultEglDisplay(out_failureId);
   if (!display) {
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -4930,16 +4930,23 @@
   value: true
   mirror: once
 
 - name: gfx.e10s.font-list.shared
   type: bool
   value: true
   mirror: once
 
+#if !defined(MOZ_WIDGET_ANDROID)
+- name: gfx.egl.prefer-gles.enabled
+  type: bool
+  value: false
+  mirror: once
+#endif
+
 # [Windows] Whether registry FontSubstitutes entries are used unconditionally,
 # or only if the original font is not available.
 #if defined(XP_WIN)
 - name: gfx.windows-font-substitutes.always
   type: bool
   value: false
   mirror: once
 #endif