Bug 1473169 - Support KHR_create_context_no_error in EGL. - r=kvark draft
authorjgilbert@mozilla.com <jdashg@gmail.com>
Tue, 03 Jul 2018 15:40:58 -0700
changeset 813844 a37996ac2858018125e7cb25f685bcaf1558a1d3
parent 813062 9c02d2ecf22050bfee5d70c04a359d8aaff6eb91
push id115017
push userbmo:jgilbert@mozilla.com
push dateTue, 03 Jul 2018 22:50:15 +0000
reviewerskvark
bugs1473169
milestone63.0a1
Bug 1473169 - Support KHR_create_context_no_error in EGL. - r=kvark MozReview-Commit-ID: 3hOIgDuvRNd
dom/canvas/WebGLContextDraw.cpp
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLLibraryEGL.cpp
gfx/gl/GLLibraryEGL.h
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -746,18 +746,21 @@ WebGLContext::DrawElementsInstanced(GLen
     const ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
     if (error)
         return;
 
     {
         ScopedDrawCallWrapper wrapper(*this);
         {
             UniquePtr<gl::GLContext::LocalErrorScope> errorScope;
-
-            if (gl->IsANGLE()) {
+            if (MOZ_UNLIKELY( gl->IsANGLE() &&
+                              gl->mDebugFlags & gl::GLContext::DebugFlagAbortOnError ))
+            {
+                // ANGLE does range validation even when it doesn't need to.
+                // With MOZ_GL_ABORT_ON_ERROR, we need to catch it or hit assertions.
                 errorScope.reset(new gl::GLContext::LocalErrorScope(*gl));
             }
 
             if (indexCount && instanceCount) {
                 AUTO_PROFILER_LABEL("glDrawElementsInstanced", GRAPHICS);
                 if (HasInstancedDrawing(*this)) {
                     gl->fDrawElementsInstanced(mode, indexCount, type,
                                                reinterpret_cast<GLvoid*>(byteOffset),
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -215,18 +215,18 @@ ParseVersion(const std::string& versionS
 
     const auto& majorStr = match.str(1);
     const auto& minorStr = match.str(2);
     *out_major = atoi(majorStr.c_str());
     *out_minor = atoi(minorStr.c_str());
     return true;
 }
 
-static uint8_t
-ChooseDebugFlags(CreateContextFlags createFlags)
+/*static*/ uint8_t
+GLContext::ChooseDebugFlags(const CreateContextFlags createFlags)
 {
     uint8_t debugFlags = 0;
 
 #ifdef MOZ_GL_DEBUG
     if (gfxEnv::GlDebug()) {
         debugFlags |= GLContext::DebugFlagEnabled;
     }
 
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -3468,16 +3468,17 @@ public:
 
     enum {
         DebugFlagEnabled = 1 << 0,
         DebugFlagTrace = 1 << 1,
         DebugFlagAbortOnError = 1 << 2
     };
 
     const uint8_t mDebugFlags;
+    static uint8_t ChooseDebugFlags(CreateContextFlags createFlags);
 
 protected:
     RefPtr<GLContext> mSharedContext;
 
     // The thread id which this context was created.
     PlatformThreadId mOwningThreadId;
 
     GLContextSymbols mSymbols;
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -555,16 +555,25 @@ GLContextEGL::CreateGLContext(CreateCont
     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);
     }
 
+    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);
+    }
+
     std::vector<EGLint> robustness_attribs;
     std::vector<EGLint> rbab_attribs; // RBAB: Robust Buffer Access Behavior
     if (flags & CreateContextFlags::PREFER_ROBUSTNESS) {
         if (egl->IsExtensionSupported(GLLibraryEGL::EXT_create_context_robustness)) {
             robustness_attribs = required_attribs;
             robustness_attribs.push_back(LOCAL_EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT);
             robustness_attribs.push_back(LOCAL_EGL_LOSE_CONTEXT_ON_RESET_EXT);
             // Skip EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, since it doesn't help us.
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -63,17 +63,18 @@ static const char* sEGLExtensionNames[] 
     "EGL_KHR_create_context",
     "EGL_KHR_stream",
     "EGL_KHR_stream_consumer_gltexture",
     "EGL_EXT_device_query",
     "EGL_NV_stream_consumer_gltexture_yuv",
     "EGL_ANGLE_stream_producer_d3d_texture",
     "EGL_ANGLE_device_creation",
     "EGL_ANGLE_device_creation_d3d11",
-    "EGL_KHR_surfaceless_context"
+    "EGL_KHR_surfaceless_context",
+    "EGL_KHR_create_context_no_error"
 };
 
 #if defined(ANDROID)
 
 static PRLibrary* LoadApitraceLibrary()
 {
     // Initialization of gfx prefs here is only needed during the unit tests...
     gfxPrefs::GetSingleton();
--- a/gfx/gl/GLLibraryEGL.h
+++ b/gfx/gl/GLLibraryEGL.h
@@ -100,16 +100,17 @@ public:
         KHR_stream,
         KHR_stream_consumer_gltexture,
         EXT_device_query,
         NV_stream_consumer_gltexture_yuv,
         ANGLE_stream_producer_d3d_texture,
         ANGLE_device_creation,
         ANGLE_device_creation_d3d11,
         KHR_surfaceless_context,
+        KHR_create_context_no_error,
         Extensions_Max
     };
 
     bool IsExtensionSupported(EGLExtensions aKnownExtension) const {
         return mAvailableExtensions[aKnownExtension];
     }
 
     void MarkExtensionUnsupported(EGLExtensions aKnownExtension) {