Bug 1427668 - Require frag_color_float for color_buffer_*float extensions. - r=daoshengmu draft
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 22 Dec 2017 13:21:26 -0800
changeset 716065 e2e2f523f22141be0fde1309268ce96746fc5575
parent 716064 d7443e50c66b1530d9d6997b9c4b75fee10187a2
child 716066 b137e187bfcdab2af07ad531200226d1b4830dfc
push id94316
push userbmo:jgilbert@mozilla.com
push dateFri, 05 Jan 2018 03:14:09 +0000
reviewersdaoshengmu
bugs1427668
milestone59.0a1
Bug 1427668 - Require frag_color_float for color_buffer_*float extensions. - r=daoshengmu Add probe for faulty frag_color_float implementations. MozReview-Commit-ID: E2I0mrDuicV
dom/canvas/WebGLExtensionColorBufferFloat.cpp
dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp
dom/canvas/test/webgl-conf/generated-mochitest.ini
dom/canvas/test/webgl-conf/mochitest-errata.ini
dom/canvas/test/webgl-mochitest/mochitest.ini
gfx/gl/GLContext.cpp
--- a/dom/canvas/WebGLExtensionColorBufferFloat.cpp
+++ b/dom/canvas/WebGLExtensionColorBufferFloat.cpp
@@ -29,29 +29,54 @@ WebGLExtensionColorBufferFloat::WebGLExt
     };
 
 #define FOO(x) fnUpdateUsage(LOCAL_GL_ ## x, webgl::EffectiveFormat::x)
 
     // The extension doesn't actually add RGB32F; only RGBA32F.
     FOO(RGBA32F);
 
 #undef FOO
+
+#ifdef DEBUG
+    const auto gl = webgl->gl;
+    float was[4] = {};
+    gl->fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, was);
+
+    const float test[4] = {-1.0, 0, 2.0, 255.0};
+    gl->fClearColor(test[0], test[1], test[2], test[3]);
+
+    float now[4] = {};
+    gl->fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, now);
+    const bool ok = now[0] == test[0] && now[1] == test[1] &&
+                    now[2] == test[2] && now[3] == test[3];
+    if (!ok) {
+        printf_stderr("COLOR_CLEAR_VALUE: now{%f,%f,%f,%f} != test{%f,%f,%f,%f}\n",
+                      test[0], test[1], test[2], test[3],
+                      now[0], now[1], now[2], now[3]);
+        MOZ_ASSERT(false);
+    }
+    gl->fClearColor(was[0], was[1], was[2], was[3]);
+#endif
 }
 
 WebGLExtensionColorBufferFloat::~WebGLExtensionColorBufferFloat()
 {
 }
 
 bool
 WebGLExtensionColorBufferFloat::IsSupported(const WebGLContext* webgl)
 {
-    gl::GLContext* gl = webgl->GL();
+    const auto& gl = webgl->gl;
+    if (gl->IsANGLE()) {
+        // ANGLE supports this, but doesn't have a way to advertize its support,
+        // since it's compliant with WEBGL_color_buffer_float's clamping, but not
+        // EXT_color_buffer_float.
+        // TODO: This probably isn't necessary anymore.
+        return true;
+    }
 
-    // ANGLE supports this, but doesn't have a way to advertize its support,
-    // since it's compliant with WEBGL_color_buffer_float's clamping, but not
-    // EXT_color_buffer_float.
-    return gl->IsSupported(gl::GLFeature::renderbuffer_color_float) ||
-           gl->IsANGLE();
+    return gl->IsSupported(gl::GLFeature::renderbuffer_color_float) &&
+           gl->IsSupported(gl::GLFeature::frag_color_float);
 }
 
 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionColorBufferFloat, WEBGL_color_buffer_float)
 
 } // namespace mozilla
--- a/dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp
+++ b/dom/canvas/WebGLExtensionColorBufferHalfFloat.cpp
@@ -38,14 +38,16 @@ WebGLExtensionColorBufferHalfFloat::WebG
 
 WebGLExtensionColorBufferHalfFloat::~WebGLExtensionColorBufferHalfFloat()
 {
 }
 
 bool
 WebGLExtensionColorBufferHalfFloat::IsSupported(const WebGLContext* webgl)
 {
-    return webgl->GL()->IsSupported(gl::GLFeature::renderbuffer_color_half_float);
+    const auto& gl = webgl->gl;
+    return gl->IsSupported(gl::GLFeature::renderbuffer_color_half_float) &&
+           gl->IsSupported(gl::GLFeature::frag_color_float);
 }
 
 IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionColorBufferHalfFloat, EXT_color_buffer_half_float)
 
 } // namespace mozilla
--- a/dom/canvas/test/webgl-conf/generated-mochitest.ini
+++ b/dom/canvas/test/webgl-conf/generated-mochitest.ini
@@ -7591,17 +7591,17 @@ fail-if = (os == 'android')
 [generated/test_conformance__extensions__oes-texture-half-float-with-image-data.html]
 skip-if = (os == 'win' && os_version == '6.1')
 fail-if = (os == 'android')
 [generated/test_conformance__extensions__oes-texture-half-float-with-image.html]
 fail-if = (os == 'android')
 [generated/test_conformance__extensions__oes-texture-half-float-with-video.html]
 fail-if = (os == 'mac') || (os == 'android') || (os == 'linux') || (os == 'win')
 [generated/test_conformance__extensions__oes-texture-half-float.html]
-fail-if = (os == 'mac') || (os == 'win') || (os == 'android') || (os == 'linux')
+fail-if = (os == 'mac') || (os == 'win') || (os == 'android')
 [generated/test_conformance__extensions__oes-vertex-array-object-bufferData.html]
 [generated/test_conformance__extensions__oes-vertex-array-object.html]
 skip-if = (os == 'mac' && os_version == '10.6')
 fail-if = (os == 'mac') || (os == 'linux') || (os == 'win')
 [generated/test_conformance__extensions__webgl-compressed-texture-atc.html]
 [generated/test_conformance__extensions__webgl-compressed-texture-etc.html]
 [generated/test_conformance__extensions__webgl-compressed-texture-pvrtc.html]
 [generated/test_conformance__extensions__webgl-compressed-texture-s3tc-srgb.html]
--- a/dom/canvas/test/webgl-conf/mochitest-errata.ini
+++ b/dom/canvas/test/webgl-conf/mochitest-errata.ini
@@ -127,17 +127,17 @@ fail-if = (os == 'mac') || (os == 'linux
 skip-if = (os == 'mac' && os_version == '10.6')
 [generated/test_conformance__textures__misc__texture-size.html]
 # application crashed [@ mozilla::gl::GLContext::AfterGLCall]
 skip-if = (os == 'android') || (os == 'win')
 
 [generated/test_2_conformance2__vertex_arrays__vertex-array-object.html]
 fail-if = (os == 'mac') || (os == 'win')
 [generated/test_conformance__extensions__oes-texture-half-float.html]
-fail-if = (os == 'mac') || (os == 'win') || (os == 'android') || (os == 'linux')
+fail-if = (os == 'mac') || (os == 'win') || (os == 'android')
 [generated/test_conformance__attribs__gl-vertexattribpointer.html]
 fail-if = (os == 'android')
 [generated/test_conformance__ogles__GL__biuDepthRange__biuDepthRange_001_to_002.html]
 fail-if = (os == 'android')
 [generated/test_conformance__ogles__GL__gl_FragCoord__gl_FragCoord_001_to_003.html]
 fail-if = (os == 'android')
 
 [generated/test_conformance__textures__misc__texture-size-limit.html]
--- a/dom/canvas/test/webgl-mochitest/mochitest.ini
+++ b/dom/canvas/test/webgl-mochitest/mochitest.ini
@@ -12,31 +12,31 @@ support-files =
   red-green.webmvp8.webm
   red-green.webmvp9.webm
 
 [ensure-exts/test_ANGLE_instanced_arrays.html]
 fail-if = (os == 'android') || (os == 'mac' && os_version == '10.6')
 [ensure-exts/test_EXT_blend_minmax.html]
 fail-if = (os == 'android')
 [ensure-exts/test_EXT_color_buffer_half_float.html]
-fail-if = (os == 'android')
+fail-if = (os == 'android') || (os == 'linux')
 [ensure-exts/test_EXT_disjoint_timer_query.html]
 fail-if = (os == 'android') || (os == 'win' && os_version == '5.1')
 [ensure-exts/test_EXT_frag_depth.html]
 fail-if = (os == 'android')
 [ensure-exts/test_EXT_sRGB.html]
 fail-if = (os == 'android') || (os == 'mac' && os_version == '10.6')
 [ensure-exts/test_EXT_shader_texture_lod.html]
 fail-if = (os == 'android')
 [ensure-exts/test_EXT_texture_filter_anisotropic.html]
 fail-if = (os == 'android') || (os == 'linux')
 [ensure-exts/test_OES_standard_derivatives.html]
 fail-if = (os == 'android')
 [ensure-exts/test_WEBGL_color_buffer_float.html]
-fail-if = (os == 'android')
+fail-if = (os == 'android') || (os == 'linux')
 [ensure-exts/test_WEBGL_compressed_texture_atc.html]
 fail-if = (os == 'android') || (os == 'linux') || (os == 'mac') || (os == 'win')
 [ensure-exts/test_WEBGL_compressed_texture_es3.html]
 fail-if = (os == 'android') || (os == 'mac') || (os == 'win')
 [ensure-exts/test_WEBGL_compressed_texture_etc1.html]
 fail-if = (os == 'linux') || (os == 'mac') || (os == 'win')
 [ensure-exts/test_WEBGL_compressed_texture_pvrtc.html]
 fail-if = (os == 'android') || (os == 'linux') || (os == 'mac') || (os == 'win')
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -749,16 +749,40 @@ GLContext::InitWithPrefixImpl(const char
         // this has been fixed in Mac OS X 10.9. See 907946
         // and it also works in 10.8.3 and higher.  See 1094338.
         if (Vendor() == gl::GLVendor::NVIDIA &&
             !nsCocoaFeatures::IsAtLeastVersion(10,8,3))
         {
             MarkUnsupported(GLFeature::depth_texture);
         }
 #endif
+        if (IsSupported(GLFeature::frag_color_float)) {
+            float was[4] = {};
+            fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, was);
+
+            const float test[4] = {-1.0, 0, 2.0, 255.0};
+            fClearColor(test[0], test[1], test[2], test[3]);
+
+            float now[4] = {};
+            fGetFloatv(LOCAL_GL_COLOR_CLEAR_VALUE, now);
+
+            fClearColor(was[0], was[1], was[2], was[3]);
+
+            const bool unclamped = now[0] == test[0] && now[1] == test[1] &&
+                                   now[2] == test[2] && now[3] == test[3];
+            if (!unclamped) {
+                printf_stderr("COLOR_CLEAR_VALUE: now{%f,%f,%f,%f} != test{%f,%f,%f,%f}\n",
+                              test[0], test[1], test[2], test[3],
+                              now[0], now[1], now[2], now[3]);
+                gfxCriticalNote << "GLFeature::frag_color_float failed support probe,"
+                                << " disabling. (RENDERER: "
+                                << (const char*)fGetString(LOCAL_GL_RENDERER) << ")";
+                MarkUnsupported(GLFeature::frag_color_float);
+            }
+        }
     }
 
     if (IsExtensionSupported(GLContext::ARB_pixel_buffer_object)) {
         MOZ_ASSERT((mSymbols.fMapBuffer && mSymbols.fUnmapBuffer),
                    "ARB_pixel_buffer_object supported without glMapBuffer/UnmapBuffer"
                    " being available!");
     }