Bug 1535808 - Expose and implicitly enable EXT_float_blend. r=lsalzman a=pascalc
authorJeff Gilbert <jgilbert@mozilla.com>
Mon, 18 Mar 2019 10:13:01 +0000
changeset 525642 13ad686075c4e0d91943606db2306d16be4fdb5e
parent 525641 46698f87307d4a5cc08175acaa62e62768710bcd
child 525643 8e2c346fa3e4408226f3ef85cf74637e9c6b487a
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman, pascalc
bugs1535808
milestone67.0
Bug 1535808 - Expose and implicitly enable EXT_float_blend. r=lsalzman a=pascalc Chrome team reports that some content is broken being strict about this validation. Implicitly enable it to preserve functionality. Differential Revision: https://phabricator.services.mozilla.com/D23769
dom/canvas/WebGLContextExtensions.cpp
dom/canvas/WebGLExtensions.cpp
dom/canvas/test/webgl-mochitest/ensure-exts/test_EXT_float_blend.html
dom/canvas/test/webgl-mochitest/ensure-exts/test_common.html
dom/canvas/test/webgl-mochitest/ensure-exts/test_implicit.html
dom/canvas/test/webgl-mochitest/mochi-to-testcase.py
dom/canvas/test/webgl-mochitest/mochitest.ini
--- a/dom/canvas/WebGLContextExtensions.cpp
+++ b/dom/canvas/WebGLContextExtensions.cpp
@@ -278,26 +278,38 @@ void WebGLContext::GetExtension(JSContex
 
   // step 3: if the extension hadn't been previously been created, create it
   // now, thus enabling it
   WebGLExtensionBase* extObj = EnableSupportedExtension(callerType, ext);
   if (!extObj) return;
 
   // Step 4: Enable any implied extensions.
   switch (ext) {
+    case WebGLExtensionID::EXT_color_buffer_float:
+      EnableSupportedExtension(callerType,
+                               WebGLExtensionID::EXT_float_blend);
+      break;
+
     case WebGLExtensionID::OES_texture_float:
       EnableSupportedExtension(callerType,
                                WebGLExtensionID::WEBGL_color_buffer_float);
+      EnableSupportedExtension(callerType,
+                               WebGLExtensionID::EXT_float_blend);
       break;
 
     case WebGLExtensionID::OES_texture_half_float:
       EnableSupportedExtension(callerType,
                                WebGLExtensionID::EXT_color_buffer_half_float);
       break;
 
+    case WebGLExtensionID::WEBGL_color_buffer_float:
+      EnableSupportedExtension(callerType,
+                               WebGLExtensionID::EXT_float_blend);
+      break;
+
     default:
       break;
   }
 
   retval.set(WebGLObjectAsJSObject(cx, extObj, rv));
 }
 
 void WebGLContext::EnableExtension(WebGLExtensionID ext) {
--- a/dom/canvas/WebGLExtensions.cpp
+++ b/dom/canvas/WebGLExtensions.cpp
@@ -33,17 +33,16 @@ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(W
 WebGLExtensionFloatBlend::WebGLExtensionFloatBlend(WebGLContext* const webgl)
     : WebGLExtensionBase(webgl) {
   MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
 }
 
 WebGLExtensionFloatBlend::~WebGLExtensionFloatBlend() = default;
 
 bool WebGLExtensionFloatBlend::IsSupported(const WebGLContext* const webgl) {
-  if (!gfxPrefs::WebGLDraftExtensionsEnabled()) return false;
   if (!WebGLExtensionColorBufferFloat::IsSupported(webgl) &&
       !WebGLExtensionEXTColorBufferFloat::IsSupported(webgl))
     return false;
 
   const auto& gl = webgl->gl;
   return !gl->IsGLES() || gl->IsANGLE() ||
          gl->IsExtensionSupported(gl::GLContext::EXT_float_blend);
 }
--- a/dom/canvas/test/webgl-mochitest/ensure-exts/test_EXT_float_blend.html
+++ b/dom/canvas/test/webgl-mochitest/ensure-exts/test_EXT_float_blend.html
@@ -6,15 +6,13 @@
     <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
     <script src='ensure-ext.js'></script>
   </head>
   <body>
     <script>
 
 'use strict';
 
-Lastly_WithDraftExtsEnabled(function() {
-  EnsureExt('EXT_float_blend');
-});
+EnsureExt('EXT_float_blend');
 
     </script>
   </body>
 </html>
--- a/dom/canvas/test/webgl-mochitest/ensure-exts/test_common.html
+++ b/dom/canvas/test/webgl-mochitest/ensure-exts/test_common.html
@@ -35,30 +35,30 @@ var defaultExts = [
     ['WEBGL_depth_texture'           , [MACHINE_SPECIFIC, FORBID          ]],
     ['WEBGL_draw_buffers'            , [MACHINE_SPECIFIC, FORBID          ]],
     ['WEBGL_lose_context'            , [ENSURE          , ENSURE          ]],
 
     // Community Approved
     ['EXT_color_buffer_float'            , [FORBID          , ENSURE          ]],
     ['EXT_color_buffer_half_float'       , [MACHINE_SPECIFIC, FORBID          ]],
     ['EXT_disjoint_timer_query'          , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
+    ['EXT_float_blend'                   , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['EXT_sRGB'                          , [MACHINE_SPECIFIC, FORBID          ]],
     ['EXT_texture_compression_bptc'      , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['EXT_texture_compression_rgtc'      , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['WEBGL_color_buffer_float'          , [MACHINE_SPECIFIC, FORBID          ]],
     ['WEBGL_compressed_texture_astc'     , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['WEBGL_compressed_texture_atc'      , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['WEBGL_compressed_texture_etc'      , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['WEBGL_compressed_texture_etc1'     , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['WEBGL_compressed_texture_pvrtc'    , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['WEBGL_compressed_texture_s3tc_srgb', [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
 ];
 
 var draftExts = [
-    ['EXT_float_blend'      , [MACHINE_SPECIFIC, MACHINE_SPECIFIC]],
     ['OES_fbo_render_mipmap', [MACHINE_SPECIFIC, FORBID          ]],
 ];
 
 ////////////////////
 // Ensure that we never see any extensions that we haven't listed above!
 
 (function() {
     const expectedExts = (defaultExts.concat(draftExts)).map(x => x[0]);
new file mode 100644
--- /dev/null
+++ b/dom/canvas/test/webgl-mochitest/ensure-exts/test_implicit.html
@@ -0,0 +1,130 @@
+<!DOCTYPE HTML>
+<html>
+  <head>
+    <meta charset='utf-8'/>
+    <script src='/tests/SimpleTest/SimpleTest.js'></script>
+    <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
+    <script src='ensure-ext.js'></script>
+  </head>
+  <body>
+    <script id='g_vs' type='text/plain'>
+
+void main() {
+    gl_PointSize = 1.0;
+}
+
+    </script>
+    <script id='g_fs' type='text/plain'>
+
+void main() {
+    gl_FragColor = vec4(0);
+}
+
+    </script>
+    <script>
+
+'use strict';
+
+let gl = null;
+
+function CheckTexFloatRenderable(rgbaInternal, type) {
+    const tex = gl.createTexture();
+    gl.bindTexture(gl.TEXTURE_2D, tex);
+    gl.texImage2D(gl.TEXTURE_2D, 0, rgbaInternal, 1, 1, 0, gl.RGBA, type, null);
+
+    const fb = gl.createFramebuffer();
+    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
+    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
+    return gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
+}
+
+function CheckRbFloatRenderable(format) {
+    const rb = gl.createRenderbuffer();
+    gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
+    gl.renderbufferStorage(gl.RENDERBUFFER, format, 1, 1);
+
+    const fb = gl.createFramebuffer();
+    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
+    gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
+    return gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
+}
+
+function CheckBlending() {
+    function CompileShader(type, elem) {
+        const text = elem.innerHTML.trim();
+        const s = gl.createShader(type);
+        gl.shaderSource(s, text);
+        gl.compileShader(s);
+        return s;
+    }
+
+    const vs = CompileShader(gl.VERTEX_SHADER, g_vs);
+    const fs = CompileShader(gl.FRAGMENT_SHADER, g_fs);
+    const p = gl.createProgram();
+    gl.attachShader(p, vs);
+    gl.attachShader(p, fs);
+    gl.linkProgram(p);
+    gl.useProgram(p);
+
+    gl.drawArrays(gl.POINTS, 0, 1);
+    if (gl.getError()) throw new Error('Unexpected GL error,');
+
+    gl.enable(gl.BLEND);
+    gl.drawArrays(gl.POINTS, 0, 1);
+    return gl.getError() == 0;
+}
+
+function ResetGl(type) {
+    if (gl) {
+        const ext = gl.getExtension('WEBGL_lose_context');
+        ext.loseContext();
+        gl = null;
+    }
+    const c = document.createElement('canvas');
+    gl = c.getContext(type);
+    return !!gl;
+}
+
+function HasExt(name) {
+    return gl.getSupportedExtensions().indexOf(name) != -1;
+}
+
+ResetGl('webgl');
+if (HasExt('EXT_color_buffer_half_float')) {
+    const ext = gl.getExtension('OES_texture_half_float');
+    const implicitEnabled = CheckTexFloatRenderable(gl.RGBA, ext.HALF_FLOAT_OES);
+    ok(implicitEnabled, 'OES_texture_half_float should implicitly enable EXT_color_buffer_half_float.');
+}
+
+ResetGl('webgl');
+if (HasExt('WEBGL_color_buffer_float')) {
+    const ext = gl.getExtension('OES_texture_float');
+    const implicitEnabled = CheckTexFloatRenderable(gl.RGBA, gl.FLOAT);
+    ok(implicitEnabled, 'OES_texture_float should implicitly enable WEBGL_color_buffer_float.');
+
+    if (HasExt('EXT_float_blend')) {
+        const implicitEnabled = CheckBlending();
+        ok(implicitEnabled, 'OES_texture_float should implicitly enable EXT_float_blend.');
+    }
+}
+
+ResetGl('webgl');
+if (HasExt('EXT_float_blend')) {
+    const ext = gl.getExtension('WEBGL_color_buffer_float');
+    CheckRbFloatRenderable(ext.RGBA32F_EXT);
+    const implicitEnabled = CheckBlending();
+    ok(implicitEnabled, 'WEBGL_color_buffer_float should implicitly enable EXT_float_blend.');
+}
+
+if (ResetGl('webgl2')) {
+    if (HasExt('EXT_float_blend')) {
+        const ext = gl.getExtension('EXT_color_buffer_float');
+        CheckTexFloatRenderable(gl.RGBA32F, gl.FLOAT);
+        const implicitEnabled = CheckBlending();
+        ok(implicitEnabled, 'EXT_color_buffer_float should implicitly enable EXT_float_blend.');
+    }
+}
+
+    </script>
+  </body>
+</html>
--- a/dom/canvas/test/webgl-mochitest/mochi-to-testcase.py
+++ b/dom/canvas/test/webgl-mochitest/mochi-to-testcase.py
@@ -1,9 +1,9 @@
-#!python2
+#! /usr/bin/env python2
 import sys
 import os.path
 import re
 
 assert len(sys.argv) == 2
 mochiPath = sys.argv[1]
 
 extDotPos = mochiPath.find('.html')
--- a/dom/canvas/test/webgl-mochitest/mochitest.ini
+++ b/dom/canvas/test/webgl-mochitest/mochitest.ini
@@ -50,16 +50,17 @@ fail-if = (os == 'linux') || (os == 'mac
 fail-if = (os == 'android') || (os == 'linux') || (os == 'mac') || (os == 'win')
 [ensure-exts/test_WEBGL_compressed_texture_s3tc.html]
 fail-if = (os == 'android')
 [ensure-exts/test_WEBGL_depth_texture.html]
 [ensure-exts/test_WEBGL_draw_buffers.html]
 fail-if = (os == 'android')
 
 [ensure-exts/test_common.html]
+[ensure-exts/test_implicit.html]
 
 
 [regress/test_bug_1268096.html]
 
 
 [test_backends.html]
 [test_backbuffer_channels.html]
 [test_depth_readpixels.html]