Support passing preferLowPowerToHighPerformance and failIfMajorPerformanceCaveat
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Aug 2016 00:50:36 +0000 (00:50 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Aug 2016 00:50:36 +0000 (00:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160982
<rdar://problem/27915946>

Reviewed by Simon Fraser.

Source/WebCore:

Update WebGLContextAttributes to be compliant with the specification,
by adding preferLowPowerToHighPerformance and failIfMajorPerformanceCaveat.
They are not implemented yet, so asking the created context what
values it used should give the default.

Test: fast/canvas/webgl/context-creation-attributes.html

* html/canvas/WebGLContextAttributes.cpp:
(WebCore::WebGLContextAttributes::preferLowPowerToHighPerformance):
(WebCore::WebGLContextAttributes::setPreferLowPowerToHighPerformance):
(WebCore::WebGLContextAttributes::failIfMajorPerformanceCaveat):
(WebCore::WebGLContextAttributes::setFailIfMajorPerformanceCaveat):
* html/canvas/WebGLContextAttributes.h:
* html/canvas/WebGLContextAttributes.idl:
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::create): Deleted.
* platform/graphics/GraphicsContext3D.h:
(WebCore::GraphicsContext3D::Attributes::Attributes): Deleted.

LayoutTests:

Very simple test that creates some WebGL contexts with various
creation attributes and outputs the result.

* fast/canvas/webgl/context-creation-attributes-expected.txt: Added.
* fast/canvas/webgl/context-creation-attributes.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/canvas/webgl/context-creation-attributes-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/webgl/context-creation-attributes.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/WebGLContextAttributes.cpp
Source/WebCore/html/canvas/WebGLContextAttributes.h
Source/WebCore/html/canvas/WebGLContextAttributes.idl
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/platform/graphics/GraphicsContext3D.h

index 9c0b912..811a13a 100644 (file)
@@ -1,3 +1,17 @@
+2016-08-18  Dean Jackson  <dino@apple.com>
+
+        Support passing preferLowPowerToHighPerformance and failIfMajorPerformanceCaveat
+        https://bugs.webkit.org/show_bug.cgi?id=160982
+        <rdar://problem/27915946>
+
+        Reviewed by Simon Fraser.
+
+        Very simple test that creates some WebGL contexts with various
+        creation attributes and outputs the result.
+
+        * fast/canvas/webgl/context-creation-attributes-expected.txt: Added.
+        * fast/canvas/webgl/context-creation-attributes.html: Added.
+
 2016-08-17  Ryosuke Niwa  <rniwa@webkit.org>
 
         Add basic support for connected and disconnected callbacks
diff --git a/LayoutTests/fast/canvas/webgl/context-creation-attributes-expected.txt b/LayoutTests/fast/canvas/webgl/context-creation-attributes-expected.txt
new file mode 100644 (file)
index 0000000..d02b2b2
--- /dev/null
@@ -0,0 +1,6 @@
+Note that some of the values tested here might not be supported, and thus should return the default values.
+
+{"alpha":true,"depth":true,"stencil":false,"antialias":true,"premultipliedAlpha":true,"preserveDrawingBuffer":false,"preferLowPowerToHighPerformance":false,"failIfMajorPerformanceCaveat":false}
+{"alpha":true,"depth":true,"stencil":true,"antialias":true,"premultipliedAlpha":true,"preserveDrawingBuffer":false,"preferLowPowerToHighPerformance":false,"failIfMajorPerformanceCaveat":false}
+{"alpha":true,"depth":true,"stencil":false,"antialias":true,"premultipliedAlpha":true,"preserveDrawingBuffer":false,"preferLowPowerToHighPerformance":false,"failIfMajorPerformanceCaveat":false}
+{"alpha":true,"depth":true,"stencil":false,"antialias":true,"premultipliedAlpha":true,"preserveDrawingBuffer":false,"preferLowPowerToHighPerformance":false,"failIfMajorPerformanceCaveat":false}
diff --git a/LayoutTests/fast/canvas/webgl/context-creation-attributes.html b/LayoutTests/fast/canvas/webgl/context-creation-attributes.html
new file mode 100644 (file)
index 0000000..9b878e6
--- /dev/null
@@ -0,0 +1,38 @@
+<script>
+if (window.testRunner)
+    window.testRunner.dumpAsText();
+
+function describe(object) {
+    result = {};
+    if (typeof object === "function")
+        object = object.prototype;
+    for (let o = object; o; o = o.__proto__) {
+        for (let name of Object.getOwnPropertyNames(o)) {
+            result[name] = object[name];
+        }
+    }
+    return result;
+}
+
+function testContextCreation(parameters)
+{
+    var canvas = document.createElement("canvas");
+    var gl = canvas.getContext("webgl", parameters || {});
+    var attributes = gl.getContextAttributes();
+    var result = document.createElement("pre");
+    result.textContent = JSON.stringify(describe(attributes));
+    document.body.appendChild(result);
+}
+
+function run() {
+    testContextCreation({});
+    testContextCreation({stencil: true});
+    testContextCreation({preferLowPowerToHighPerformance: true});
+    testContextCreation({failIfMajorPerformanceCaveat: true});
+}
+
+window.addEventListener("load", run, false);
+</script>
+<p>
+    Note that some of the values tested here might not be supported, and thus should return the default values.
+</p>
\ No newline at end of file
index 9452229..ebed889 100644 (file)
@@ -1,3 +1,30 @@
+2016-08-18  Dean Jackson  <dino@apple.com>
+
+        Support passing preferLowPowerToHighPerformance and failIfMajorPerformanceCaveat
+        https://bugs.webkit.org/show_bug.cgi?id=160982
+        <rdar://problem/27915946>
+
+        Reviewed by Simon Fraser.
+
+        Update WebGLContextAttributes to be compliant with the specification,
+        by adding preferLowPowerToHighPerformance and failIfMajorPerformanceCaveat.
+        They are not implemented yet, so asking the created context what
+        values it used should give the default.
+
+        Test: fast/canvas/webgl/context-creation-attributes.html
+
+        * html/canvas/WebGLContextAttributes.cpp:
+        (WebCore::WebGLContextAttributes::preferLowPowerToHighPerformance):
+        (WebCore::WebGLContextAttributes::setPreferLowPowerToHighPerformance):
+        (WebCore::WebGLContextAttributes::failIfMajorPerformanceCaveat):
+        (WebCore::WebGLContextAttributes::setFailIfMajorPerformanceCaveat):
+        * html/canvas/WebGLContextAttributes.h:
+        * html/canvas/WebGLContextAttributes.idl:
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::create): Deleted.
+        * platform/graphics/GraphicsContext3D.h:
+        (WebCore::GraphicsContext3D::Attributes::Attributes): Deleted.
+
 2016-08-18  Anders Carlsson  <andersca@apple.com>
 
         Move an NPAPI-only function from WebCore to WebKit
index 2abfeb8..455aabf 100644 (file)
@@ -117,6 +117,26 @@ void WebGLContextAttributes::setPreserveDrawingBuffer(bool preserveDrawingBuffer
     m_attrs.preserveDrawingBuffer = preserveDrawingBuffer;
 }
 
+bool WebGLContextAttributes::preferLowPowerToHighPerformance() const
+{
+    return m_attrs.preferLowPowerToHighPerformance;
+}
+
+void WebGLContextAttributes::setPreferLowPowerToHighPerformance(bool preferLowPower)
+{
+    m_attrs.preferLowPowerToHighPerformance = preferLowPower;
+}
+
+bool WebGLContextAttributes::failIfMajorPerformanceCaveat() const
+{
+    return m_attrs.failIfMajorPerformanceCaveat;
+}
+
+void WebGLContextAttributes::setFailIfMajorPerformanceCaveat(bool fail)
+{
+    m_attrs.failIfMajorPerformanceCaveat = fail;
+}
+
 GraphicsContext3D::Attributes WebGLContextAttributes::attributes() const
 {
     return m_attrs;
index ac00d05..97a9cab 100644 (file)
@@ -42,33 +42,43 @@ class WebGLContextAttributes final : public CanvasContextAttributes {
     // Create a new attributes object initialized with preexisting attributes
     static Ref<WebGLContextAttributes> create(GraphicsContext3D::Attributes);
 
-    // Whether or not the drawing buffer has an alpha channel; default=true
+    // Whether or not the drawing buffer has an alpha channel. Default is true.
     bool alpha() const;
     void setAlpha(bool alpha);
 
-    // Whether or not the drawing buffer has a depth buffer; default=true
+    // Whether or not the drawing buffer has a depth buffer. Default is true.
     bool depth() const;
     void setDepth(bool depth);
 
-    // Whether or not the drawing buffer has a stencil buffer; default=true
+    // Whether or not the drawing buffer has a stencil buffer. Default is true.
     bool stencil() const;
     void setStencil(bool stencil);
 
-    // Whether or not the drawing buffer is antialiased; default=true
+    // Whether or not the drawing buffer is antialiased. Default is true.
     bool antialias() const;
     void setAntialias(bool antialias);
 
     // Whether or not to treat the values in the drawing buffer as
     // though their alpha channel has already been multiplied into the
-    // color channels; default=true
+    // color channels. Default is true.
     bool premultipliedAlpha() const;
     void setPremultipliedAlpha(bool premultipliedAlpha);
 
     // Whether or not to preserve the drawing buffer after presentation to the
-    // screen; default=false
+    // screen. Default is false.
     bool preserveDrawingBuffer() const;
     void setPreserveDrawingBuffer(bool);
 
+    // Whether or not to attempt to use a lower-power GPU if it is available.
+    // Default is false.
+    bool preferLowPowerToHighPerformance() const;
+    void setPreferLowPowerToHighPerformance(bool);
+
+    // Whether or not to immediately fail if a performant GPU is not available.
+    // Default is false.
+    bool failIfMajorPerformanceCaveat() const;
+    void setFailIfMajorPerformanceCaveat(bool);
+
     // Fetches a copy of the attributes stored in this object in a
     // form that can be used to initialize a GraphicsContext3D.
     GraphicsContext3D::Attributes attributes() const;
index 41bf102..2d443c3 100644 (file)
@@ -34,4 +34,6 @@
     attribute boolean antialias;
     attribute boolean premultipliedAlpha;
     attribute boolean preserveDrawingBuffer;
+    attribute boolean preferLowPowerToHighPerformance;
+    attribute boolean failIfMajorPerformanceCaveat;
 };
index 6f88531..e63d561 100644 (file)
@@ -397,7 +397,6 @@ std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(HTM
 
     attributes.noExtensions = true;
     attributes.shareResources = false;
-    attributes.preferDiscreteGPU = true;
 
     if (frame->settings().forceSoftwareWebGLRendering())
         attributes.forceSoftwareRenderer = true;
index 83330b6..4afedfb 100644 (file)
@@ -717,34 +717,19 @@ public:
 
     // Context creation attributes.
     struct Attributes {
-        Attributes()
-            : alpha(true)
-            , depth(true)
-            , stencil(false)
-            , antialias(true)
-            , premultipliedAlpha(true)
-            , preserveDrawingBuffer(false)
-            , noExtensions(false)
-            , shareResources(true)
-            , preferDiscreteGPU(false)
-            , forceSoftwareRenderer(false)
-            , useGLES3(false)
-            , devicePixelRatio(1)
-        {
-        }
-
-        bool alpha;
-        bool depth;
-        bool stencil;
-        bool antialias;
-        bool premultipliedAlpha;
-        bool preserveDrawingBuffer;
-        bool noExtensions;
-        bool shareResources;
-        bool preferDiscreteGPU;
-        bool forceSoftwareRenderer;
-        bool useGLES3;
-        float devicePixelRatio;
+        bool alpha { true };
+        bool depth { true };
+        bool stencil { false };
+        bool antialias { true };
+        bool premultipliedAlpha { true };
+        bool preserveDrawingBuffer { false };
+        bool noExtensions { false };
+        bool shareResources { true };
+        bool preferLowPowerToHighPerformance { false };
+        bool forceSoftwareRenderer { false };
+        bool failIfMajorPerformanceCaveat { false };
+        bool useGLES3 { false };
+        float devicePixelRatio { 1 };
     };
 
     enum RenderStyle {