Bug 1578576 - Part 3: Prefer ES2 for WebGL1 r=jgilbert
authorMiko Mynttinen <mikokm@gmail.com>
Mon, 11 Nov 2019 13:09:32 +0000
changeset 501464 3a527c210483a17418269c37b4fece790c80cd61
parent 501463 3a91885d47e0ef7fba9749562d52300eea67c651
child 501465 3e32f97460b0077a37eb5bfc40b30c0031c7e36f
push id114170
push usermalexandru@mozilla.com
push dateTue, 12 Nov 2019 21:58:32 +0000
treeherdermozilla-inbound@9e3f44e87a1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1578576
milestone72.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 1578576 - Part 3: Prefer ES2 for WebGL1 r=jgilbert Depends on D44579 Differential Revision: https://phabricator.services.mozilla.com/D44581
dom/canvas/WebGLContext.cpp
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextTypes.h
gfx/gl/GLDefs.h
--- a/dom/canvas/WebGLContext.cpp
+++ b/dom/canvas/WebGLContext.cpp
@@ -477,18 +477,23 @@ bool WebGLContext::CreateAndInitGL(
   bool tryANGLE = false;
 
   if (forceEnabled) {
     flags |= gl::CreateContextFlags::FORCE_ENABLE_HARDWARE;
   }
 
   if (IsWebGL2()) {
     flags |= gl::CreateContextFlags::PREFER_ES3;
-  } else if (!StaticPrefs::webgl_1_allow_core_profiles()) {
-    flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
+  } else {
+    // Request and prefer ES2 context for WebGL1.
+    flags |= gl::CreateContextFlags::PREFER_EXACT_VERSION;
+
+    if (!StaticPrefs::webgl_1_allow_core_profiles()) {
+      flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
+    }
   }
 
   {
     auto powerPref = mOptions.powerPreference;
 
     // If "Use hardware acceleration when available" option is disabled:
     if (!gfxConfig::IsEnabled(gfx::Feature::HW_COMPOSITING)) {
       powerPref = dom::WebGLPowerPreference::Low_power;
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -551,16 +551,22 @@ already_AddRefed<GLContextEGL> GLContext
   std::vector<EGLint> required_attribs;
   required_attribs.push_back(LOCAL_EGL_CONTEXT_CLIENT_VERSION);
   if (flags & CreateContextFlags::PREFER_ES3) {
     required_attribs.push_back(3);
   } else {
     required_attribs.push_back(2);
   }
 
+  if ((flags & CreateContextFlags::PREFER_EXACT_VERSION) && egl->IsANGLE()) {
+    required_attribs.push_back(
+        LOCAL_EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE);
+    required_attribs.push_back(LOCAL_EGL_FALSE);
+  }
+
   const auto debugFlags = GLContext::ChooseDebugFlags(flags);
   if (!debugFlags && flags & CreateContextFlags::NO_VALIDATION &&
       egl->IsExtensionSupported(GLLibraryEGL::KHR_create_context_no_error)) {
     required_attribs.push_back(LOCAL_EGL_CONTEXT_OPENGL_NO_ERROR_KHR);
     required_attribs.push_back(LOCAL_EGL_TRUE);
   }
 
   if (flags & CreateContextFlags::PROVOKING_VERTEX_DONT_CARE &&
--- a/gfx/gl/GLContextTypes.h
+++ b/gfx/gl/GLContextTypes.h
@@ -24,31 +24,30 @@ struct GLFormats {
   GLenum color_texType = 0;
   GLenum color_rbFormat = 0;
 
   GLenum depthStencil = 0;
   GLenum depth = 0;
   GLenum stencil = 0;
 };
 
-enum class CreateContextFlags : uint8_t {
+enum class CreateContextFlags : uint16_t {
   NONE = 0,
   REQUIRE_COMPAT_PROFILE = 1 << 0,
   // Force the use of hardware backed GL, don't allow software implementations.
   FORCE_ENABLE_HARDWARE = 1 << 1,
   /* Don't force discrete GPU to be used (if applicable) */
   ALLOW_OFFLINE_RENDERER = 1 << 2,
   // Ask for ES3 if possible
   PREFER_ES3 = 1 << 3,
 
   NO_VALIDATION = 1 << 4,
   PREFER_ROBUSTNESS = 1 << 5,
-
   HIGH_POWER = 1 << 6,
-
   PROVOKING_VERTEX_DONT_CARE = 1 << 7,
+  PREFER_EXACT_VERSION = 1 << 8,
 };
 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CreateContextFlags)
 
 } /* namespace gl */
 } /* namespace mozilla */
 
 #endif /* GLCONTEXT_TYPES_H_ */
--- a/gfx/gl/GLDefs.h
+++ b/gfx/gl/GLDefs.h
@@ -90,11 +90,14 @@ bool CheckContextLost(const GLContext* g
 // Others
 #define LOCAL_EGL_PRESERVED_RESOURCES                   0x3030
 #define LOCAL_EGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_EXT 0x3138
 #define LOCAL_GL_CONTEXT_FLAGS_ARB                      0x2094
 #define LOCAL_GL_CONTEXT_CORE_PROFILE_BIT_ARB           0x00000001
 #define LOCAL_GL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB  0x00000002
 #define LOCAL_GL_CONTEXT_ROBUST_ACCESS_BIT_ARB          0x00000004
 
+// EGL_ANGLE_create_context_backwards_compatible
+#define LOCAL_EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE 0x3483
+
 // clang-format on
 
 #endif