Disabling WebGL2 should mean no context is created
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 May 2016 22:27:58 +0000 (22:27 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 May 2016 22:27:58 +0000 (22:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157352
<rdar://problem/26096346>

Reviewed by Eric Carlson.

Source/WebCore:

If WebGL2 is disabled by the runtime flag, we should
not create a context.

Test: fast/canvas/webgl/webgl2-runtime-flag.html

* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::create):
* testing/Internals.cpp: Added some helpers to toggle the runtime setting.
(WebCore::Internals::webGL2Enabled):
(WebCore::Internals::setWebGL2Enabled):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

Check that toggling the runtime flag enables/disables WebGL 2.0.

* fast/canvas/webgl/webgl2-runtime-flag-expected.txt: Added.
* fast/canvas/webgl/webgl2-runtime-flag.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200435 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/webgl2-runtime-flag-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/webgl2-runtime-flag.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index f31c055..2bc4e52 100644 (file)
@@ -1,3 +1,16 @@
+2016-05-04  Dean Jackson  <dino@apple.com>
+
+        Disabling WebGL2 should mean no context is created
+        https://bugs.webkit.org/show_bug.cgi?id=157352
+        <rdar://problem/26096346>
+
+        Reviewed by Eric Carlson.
+
+        Check that toggling the runtime flag enables/disables WebGL 2.0.
+
+        * fast/canvas/webgl/webgl2-runtime-flag-expected.txt: Added.
+        * fast/canvas/webgl/webgl2-runtime-flag.html: Added.
+
 2016-05-04  Chris Dumez  <cdumez@apple.com>
 
         Media elements should not be paused right away when removed from the document
diff --git a/LayoutTests/fast/canvas/webgl/webgl2-runtime-flag-expected.txt b/LayoutTests/fast/canvas/webgl/webgl2-runtime-flag-expected.txt
new file mode 100644 (file)
index 0000000..79bacac
--- /dev/null
@@ -0,0 +1,2 @@
+PASS: WebGL 2.0 was available when enabled.
+PASS: WebGL 2.0 was not available when disabled.
diff --git a/LayoutTests/fast/canvas/webgl/webgl2-runtime-flag.html b/LayoutTests/fast/canvas/webgl/webgl2-runtime-flag.html
new file mode 100644 (file)
index 0000000..1b94576
--- /dev/null
@@ -0,0 +1,46 @@
+<script>
+
+if (window.testRunner)
+    window.testRunner.dumpAsText();
+
+function getContext(name) {
+    var c = document.createElement("canvas");
+    return c.getContext(name);
+}
+
+function run() {
+    var output;
+
+    output = document.getElementById("output1");
+
+    if (!window.testRunner) {
+        output.textContent = "This test only runs inside DRT/WKTR.";
+        return;
+    }
+
+    var originalSetting = window.internals.webGL2Enabled();
+
+    window.internals.setWebGL2Enabled(true);
+    var ctx = getContext("webgl2");
+    if (ctx)
+        output.textContent = "PASS: WebGL 2.0 was available when enabled.";
+    else
+        output.textContent = "FAIL: WebGL 2.0 was not available when enabled.";
+
+    output = document.getElementById("output2");
+
+    window.internals.setWebGL2Enabled(false);
+    var ctx = getContext("webgl2");
+    if (ctx)
+        output.textContent = "FAIL: WebGL 2.0 was available when disabled.";
+    else
+        output.textContent = "PASS: WebGL 2.0 was not available when disabled.";
+
+    window.internals.setWebGL2Enabled(originalSetting);
+}
+
+window.addEventListener("load", run, false);
+
+</script>
+<div id="output1"></div>
+<div id="output2"></div>
index 639ff6a..eeb5e2a 100644 (file)
@@ -1,3 +1,24 @@
+2016-05-04  Dean Jackson  <dino@apple.com>
+
+        Disabling WebGL2 should mean no context is created
+        https://bugs.webkit.org/show_bug.cgi?id=157352
+        <rdar://problem/26096346>
+
+        Reviewed by Eric Carlson.
+
+        If WebGL2 is disabled by the runtime flag, we should
+        not create a context.
+
+        Test: fast/canvas/webgl/webgl2-runtime-flag.html
+
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::create):
+        * testing/Internals.cpp: Added some helpers to toggle the runtime setting.
+        (WebCore::Internals::webGL2Enabled):
+        (WebCore::Internals::setWebGL2Enabled):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2016-05-04  Anders Carlsson  <andersca@apple.com>
 
         Add an override point for drawing named images in ThemeCocoa
index 697cc82..a4af07d 100644 (file)
@@ -62,6 +62,7 @@
 #include "OESVertexArrayObject.h"
 #include "Page.h"
 #include "RenderBox.h"
+#include "RuntimeEnabledFeatures.h"
 #include "Settings.h"
 #include "WebGL2RenderingContext.h"
 #include "WebGLActiveInfo.h"
@@ -348,7 +349,10 @@ private:
 
 std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(HTMLCanvasElement* canvas, WebGLContextAttributes* attrs, const String& type)
 {
-#if !ENABLE(WEBGL2)
+#if ENABLE(WEBGL2)
+    if (type == "webgl2" && !RuntimeEnabledFeatures::sharedFeatures().webGL2Enabled())
+        return nullptr;
+#else
     UNUSED_PARAM(type);
 #endif
 
index 56fda69..a4ce7e0 100644 (file)
@@ -3316,6 +3316,18 @@ void Internals::setCSSGridLayoutEnabled(bool enable)
 }
 #endif
 
+#if ENABLE(WEBGL2)
+bool Internals::webGL2Enabled() const
+{
+    return RuntimeEnabledFeatures::sharedFeatures().webGL2Enabled();
+}
+
+void Internals::setWebGL2Enabled(bool enable)
+{
+    RuntimeEnabledFeatures::sharedFeatures().setWebGL2Enabled(enable);
+}
+#endif
+
 void Internals::setResourceTimingSupport(bool enable)
 {
     RuntimeEnabledFeatures::sharedFeatures().setResourceTimingEnabled(enable);
index 11f8c88..5f2abb3 100644 (file)
@@ -478,6 +478,11 @@ public:
     void setCSSGridLayoutEnabled(bool);
 #endif
 
+#if ENABLE(WEBGL2)
+    bool webGL2Enabled() const;
+    void setWebGL2Enabled(bool);
+#endif
+
 private:
     explicit Internals(Document&);
     Document* contextDocument() const;
index b34897c..4dc4031 100644 (file)
@@ -453,5 +453,10 @@ enum AutoFillButtonType {
     void setCSSGridLayoutEnabled(boolean enable);
 #endif
 
+#if defined(ENABLE_WEBGL2) && ENABLE_WEBGL2
+    boolean webGL2Enabled();
+    void setWebGL2Enabled(boolean enable);
+#endif
+
     void setResourceTimingSupport(boolean scalable);
 };