Title: [219208] trunk
Revision
219208
Author
drou...@apple.com
Date
2017-07-06 11:35:58 -0700 (Thu, 06 Jul 2017)

Log Message

Web Inspector: Support getting the content of WebGL/WebGL2 contexts
https://bugs.webkit.org/show_bug.cgi?id=173569
<rdar://problem/33112420>

Reviewed by Joseph Pecoraro.

Source/WebCore:

Tests: inspector/canvas/requestContent-2d.html
       inspector/canvas/requestContent-webgl.html
       inspector/canvas/requestContent-webgl2.html

* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::clearIfComposited):
* html/canvas/WebGLRenderingContextBase.h:
(WebCore::WebGLRenderingContextBase::preventBufferClearForInspector):
(WebCore::WebGLRenderingContextBase::setPreventBufferClearForInspector):
Add a flag that will prevent the context buffer from being cleared, allowing it to be copied
within a toDataURL call. This is currently only used by InspectorCanvasAgent::requestContent.

* inspector/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::requestContent):
Since toDataURL attempts to force the canvas to redraw, we can preserve the buffer after it
finishes drawing so that it can be copied, instead of it normally being swapped out.

LayoutTests:

* inspector/canvas/requestContent-2d-expected.txt: Added.
* inspector/canvas/requestContent-2d.html: Added.
* inspector/canvas/requestContent-webgl-expected.txt: Added.
* inspector/canvas/requestContent-webgl.html: Added.
* inspector/canvas/requestContent-webgl2-expected.txt: Added.
* inspector/canvas/requestContent-webgl2.html: Added.
* inspector/canvas/requestContent-expected.txt: Removed.
* inspector/canvas/requestContent.html: Removed.
* platform/gtk/TestExpectations:
* platform/win/TestExpectations:
Split the existing canvas content tests into one for each context type. This allows
platforms that don't support certain context types to ignore just those tests (e.g. WebGL2).

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (219207 => 219208)


--- trunk/LayoutTests/ChangeLog	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/LayoutTests/ChangeLog	2017-07-06 18:35:58 UTC (rev 219208)
@@ -1,3 +1,24 @@
+2017-07-06  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: Support getting the content of WebGL/WebGL2 contexts
+        https://bugs.webkit.org/show_bug.cgi?id=173569
+        <rdar://problem/33112420>
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/canvas/requestContent-2d-expected.txt: Added.
+        * inspector/canvas/requestContent-2d.html: Added.
+        * inspector/canvas/requestContent-webgl-expected.txt: Added.
+        * inspector/canvas/requestContent-webgl.html: Added.
+        * inspector/canvas/requestContent-webgl2-expected.txt: Added.
+        * inspector/canvas/requestContent-webgl2.html: Added.
+        * inspector/canvas/requestContent-expected.txt: Removed.
+        * inspector/canvas/requestContent.html: Removed.
+        * platform/gtk/TestExpectations:
+        * platform/win/TestExpectations:
+        Split the existing canvas content tests into one for each context type. This allows
+        platforms that don't support certain context types to ignore just those tests (e.g. WebGL2).
+
 2017-07-06  Carlos Alberto Lopez Perez  <clo...@igalia.com>
 
         [GTK] Layout test gardening.

Added: trunk/LayoutTests/inspector/canvas/requestContent-2d-expected.txt (0 => 219208)


--- trunk/LayoutTests/inspector/canvas/requestContent-2d-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/requestContent-2d-expected.txt	2017-07-06 18:35:58 UTC (rev 219208)
@@ -0,0 +1,11 @@
+Test that CanvasAgent.requestContent can retrieve a dataURL with the current content of the 2D canvas.
+
+
+== Running test suite: Canvas.requestContent2D
+-- Running test case: Canvas.requestContent2D.validCanvasId
+data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAACWCAYAAABkW7XSAAAAAXNSR0IArs4c6QAABGhJREFUeAHt1IEJACAMA8Hq4o6u4BYP1wnCpWTdmTOOAAECAYEdyCgiAQIEvoDB8ggECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcp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gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAg94ygKqdtZNrwAAAABJRU5ErkJggg==
+
+-- Running test case: Canvas.requestContent.invalidCanvasId
+PASS: Should produce an error.
+Error: Invalid canvas identifier
+

Added: trunk/LayoutTests/inspector/canvas/requestContent-2d.html (0 => 219208)


--- trunk/LayoutTests/inspector/canvas/requestContent-2d.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/requestContent-2d.html	2017-07-06 18:35:58 UTC (rev 219208)
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+function load() {
+    window.context2d = document.createElement("canvas").getContext("2d");
+    window.context2d.fillStyle = "rgba(255, 0, 0, 0.5)"; // Half-transparent red
+    window.context2d.fillRect(0, 0, 300, 150);
+
+    runTest();
+}
+
+function test() {
+    let suite = InspectorTest.createAsyncSuite("Canvas.requestContent2D");
+
+    suite.addTestCase({
+        name: "Canvas.requestContent2D.validCanvasId",
+        description: "Get the base64 encoded data for the canvas on the page with the given type.",
+        test(resolve, reject) {
+            let canvas = WebInspector.canvasManager.canvases.find((canvas) => canvas.contextType === WebInspector.Canvas.ContextType.Canvas2D);
+            if (!canvas) {
+                reject(`Missing Canvas.`);
+                return;
+            }
+
+            CanvasAgent.requestContent(canvas.identifier)
+            .then(({content}) => InspectorTest.log(content))
+            .then(resolve, reject);
+        }
+    });
+
+    // ------
+
+    suite.addTestCase({
+        name: "Canvas.requestContent.invalidCanvasId",
+        description: "Invalid canvas identifiers should cause an error.",
+        test(resolve, reject) {
+            const canvasId = "DOES_NOT_EXIST";
+            CanvasAgent.requestContent(canvasId, (error) => {
+                InspectorTest.expectThat(error, "Should produce an error.");
+                InspectorTest.log("Error: " + error);
+                resolve();
+            });
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="load()">
+    <p>Test that CanvasAgent.requestContent can retrieve a dataURL with the current content of the 2D canvas.</p>
+</body>
+</html>

Deleted: trunk/LayoutTests/inspector/canvas/requestContent-expected.txt (219207 => 219208)


--- trunk/LayoutTests/inspector/canvas/requestContent-expected.txt	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/LayoutTests/inspector/canvas/requestContent-expected.txt	2017-07-06 18:35:58 UTC (rev 219208)
@@ -1,19 +0,0 @@
-Test that CanvasAgent.requestContent can properly resolve the owner canvas node.
-
-
-== Running test suite: Canvas.requestContent
--- Running test case: Canvas.requestContent.validCanvasId
-Canvas "CSS canvas “css”" has content:
-data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAAXNSR0IArs4c6QAAACJJREFUGBljYKA2YEQy8D8SG5kJVsOELIKPPRQU4nM/eXIARtsBDD0MXU8AAAAASUVORK5CYII=
-
-Canvas "Canvas 1" has content:
-data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAACWCAYAAABkW7XSAAAAAXNSR0IArs4c6QAABE9JREFUeAHt1LENACEQA0Ge/nvmIwoguGQ1JBAheSx5LYcAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQIECBAgQIAAAQLDAt/w//f7cx9uAgSyAuN7srN0ghEgkBMwWLlKBSLQFTBY3W4lI5ATMFi5SgUi0BUwWN1uJSOQEzBYuUoFItAVMFjdbiUjkBMwWLlKBSLQFTBY3W4lI5ATMFi5SgUi0BUwWN1uJSOQEzBYuUoFItAVMFjdbiUjkBMwWLlKBSLQFTBY3W4lI5ATMFi5SgUi0BUw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MFjdbiUjkBMwWLlKBSLQFTBY3W4lI5ATMFi5SgUi0BUwWN1uJSOQEzBYuUoFItAVMFjdbiUjkBMwWLlKBSLQFTBY3W4lI5ATMFi5SgUi0BUwWN1uJSOQEzBYuUoFItAVMFjdbiUjkBMwWLlKBSLQFTBY3W4lI5ATMFi5SgUi0BUwWN1uJSOQEzBYuUoFItAVMFjdbiUjkBMwWLlKBSLQFTBY3W4lI5ATMFi5SgUi0BUwWN1uJSOQEzBYuUoFItAVMFjdbiUjkBMwWLlKBSLQFTBY3W4lI5ATMFi5SgUi0BUwWN1uJSOQEzBYuUoFItAVMFjdbiUjkBMwWLlKBSLQFTBY3W4lI0CAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBF4FfmEuAchmzh6GAAAAAElFTkSuQmCC
-
-
--- Running test case: Canvas.requestContent.invalidCanvasId
-PASS: Should produce an error.
-Error: Invalid canvas identifier
-

Added: trunk/LayoutTests/inspector/canvas/requestContent-webgl-expected.txt (0 => 219208)


--- trunk/LayoutTests/inspector/canvas/requestContent-webgl-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/requestContent-webgl-expected.txt	2017-07-06 18:35:58 UTC (rev 219208)
@@ -0,0 +1,7 @@
+Test that CanvasAgent.requestContent can retrieve a dataURL with the current content of the WebGL canvas.
+
+
+== Running test suite: Canvas.requestContentWebGL
+-- Running test case: Canvas.requestContentWebGL.validCanvasId
+data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAACWCAYAAABkW7XSAAAAAXNSR0IArs4c6QAABGhJREFUeAHt1IEJACAMA8Hq5G6u4BYP1wnCpWTNnTOOAAECAYEdyCgiAQIEvoDB8ggECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqB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YyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAg83qgKrddkJzwAAAABJRU5ErkJggg==
+

Added: trunk/LayoutTests/inspector/canvas/requestContent-webgl.html (0 => 219208)


--- trunk/LayoutTests/inspector/canvas/requestContent-webgl.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/requestContent-webgl.html	2017-07-06 18:35:58 UTC (rev 219208)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+function load() {
+    window.contextWebGL = document.createElement("canvas").getContext("webgl");
+    window.contextWebGL.clearColor(0, 1, 0, 0.5); // Half-transparent green
+    window.contextWebGL.clear(window.contextWebGL.COLOR_BUFFER_BIT);
+
+    runTest();
+}
+
+function test() {
+    let suite = InspectorTest.createAsyncSuite("Canvas.requestContentWebGL");
+
+    suite.addTestCase({
+        name: "Canvas.requestContentWebGL.validCanvasId",
+        description: "Get the base64 encoded data for the WebGL canvas on the page.",
+        test(resolve, reject) {
+            let canvas = WebInspector.canvasManager.canvases.find((canvas) => canvas.contextType === WebInspector.Canvas.ContextType.WebGL);
+            if (!canvas) {
+                reject(`Missing Canvas.`);
+                return;
+            }
+
+            CanvasAgent.requestContent(canvas.identifier)
+            .then(({content}) => InspectorTest.log(content))
+            .then(resolve, reject);
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="load()">
+    <p>Test that CanvasAgent.requestContent can retrieve a dataURL with the current content of the WebGL canvas.</p>
+</body>
+</html>

Added: trunk/LayoutTests/inspector/canvas/requestContent-webgl2-expected.txt (0 => 219208)


--- trunk/LayoutTests/inspector/canvas/requestContent-webgl2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/requestContent-webgl2-expected.txt	2017-07-06 18:35:58 UTC (rev 219208)
@@ -0,0 +1,7 @@
+Test that CanvasAgent.requestContent can retrieve a dataURL with the current content of the WebGL2 canvas.
+
+
+== Running test suite: Canvas.requestContentWebGL2
+-- Running test case: Canvas.requestContentWebGL2.validCanvasId
+data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAACWCAYAAABkW7XSAAAAAXNSR0IArs4c6QAABGhJREFUeAHt1IEJACAMA8Hq5G6u4BYP1wnCpWTN3DOOAAECAYEdyCgiAQIEvoDB8ggECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgI
 GK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAgbLDxAgkBEwWJmqBCVAwGD5AQIEMgIGK1OVoAQIGCw/QIBARsBgZaoSlAABg+UHCBDICBisTFWCEiBgsPwAAQIZAYOVqUpQAgQMlh8gQCAjYLAyVQlKgIDB8gMECGQEDFamKkEJEDBYfoAAgYyAwcpUJSgBAg82qwKrwT9MJgAAAABJRU5ErkJggg==
+

Added: trunk/LayoutTests/inspector/canvas/requestContent-webgl2.html (0 => 219208)


--- trunk/LayoutTests/inspector/canvas/requestContent-webgl2.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/requestContent-webgl2.html	2017-07-06 18:35:58 UTC (rev 219208)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+if (window.internals)
+    window.internals.settings.setWebGL2Enabled(true);
+
+function load() {
+    window.contextWebGL2 = document.createElement("canvas").getContext("webgl2");
+    window.contextWebGL2.clearColor(0, 0, 1, 0.5); // Half-transparent blue
+    window.contextWebGL2.clear(window.contextWebGL2.COLOR_BUFFER_BIT);
+
+    runTest();
+}
+
+function test() {
+    let suite = InspectorTest.createAsyncSuite("Canvas.requestContentWebGL2");
+
+    suite.addTestCase({
+        name: "Canvas.requestContentWebGL2.validCanvasId",
+        description: "Get the base64 encoded data for the WebGL2 canvas on the page.",
+        test(resolve, reject) {
+            let canvas = WebInspector.canvasManager.canvases.find((canvas) => canvas.contextType === WebInspector.Canvas.ContextType.WebGL2);
+            if (!canvas) {
+                reject(`Missing Canvas.`);
+                return;
+            }
+
+            CanvasAgent.requestContent(canvas.identifier)
+            .then(({content}) => InspectorTest.log(content))
+            .then(resolve, reject);
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="load()">
+    <p>Test that CanvasAgent.requestContent can retrieve a dataURL with the current content of the WebGL2 canvas.</p>
+</body>
+</html>

Deleted: trunk/LayoutTests/inspector/canvas/requestContent.html (219207 => 219208)


--- trunk/LayoutTests/inspector/canvas/requestContent.html	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/LayoutTests/inspector/canvas/requestContent.html	2017-07-06 18:35:58 UTC (rev 219208)
@@ -1,93 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<script src=""
-<script>
-function load() {
-    window.contextOnscreen = document.getElementById("onscreen").getContext("2d");
-    window.contextOnscreen.fillRect(25, 25, 250, 100);
-
-    window.contextOffscreen = document.createElement("canvas").getContext("2d");
-    window.contextOffscreen.fillRect(25, 25, 250, 100);
-
-    window.contextCSS = document.getCSSCanvasContext("2d", "css", 10, 10);
-    window.contextCSS.fillRect(2, 2, 6, 6);
-
-    runTest();
-}
-
-function test() {
-    let suite = InspectorTest.createAsyncSuite("Canvas.requestContent");
-
-    suite.addTestCase({
-        name: "Canvas.requestContent.validCanvasId",
-        description: "Get the base64 encoded data for each canvas on the page.",
-        test(resolve, reject) {
-            let canvases = WebInspector.canvasManager.canvases;
-            let expectedLength = canvases.length;
-            InspectorTest.assert(expectedLength === 3, "The page has 3 canvases.");
-
-            let contentsMap = new Map;
-
-            function finish() {
-                let results = {};
-                for (let [canvas, content] of contentsMap)
-                    results[canvas.displayName] = content;
-
-                let keys = Object.keys(results);
-                InspectorTest.assert(keys.length === contentsMap.size, "No display name collisions");
-
-                // Ensure that the test runs properly even if the canvas
-                // events are sent in a different order than the above.
-                keys.sort();
-                for (let displayName of keys) {
-                    InspectorTest.log(`Canvas "${displayName}" has content:`);
-                    InspectorTest.log(results[displayName]);
-                    InspectorTest.log("");
-                }
-
-                resolve();
-            }
-
-            canvases.forEach((canvas) => {
-                CanvasAgent.requestContent(canvas.identifier, (error, content) => {
-                    if (error) {
-                        reject(error);
-                        return;
-                    }
-
-                    contentsMap.set(canvas, content);
-                    if (contentsMap.size === expectedLength)
-                        finish();
-                });
-            });
-        }
-    });
-
-    // ------
-
-    suite.addTestCase({
-        name: "Canvas.requestContent.invalidCanvasId",
-        description: "Invalid canvas identifiers should cause an error.",
-        test(resolve, reject) {
-            const canvasId = "DOES_NOT_EXIST";
-            CanvasAgent.requestContent(canvasId, (error) => {
-                InspectorTest.expectThat(error, "Should produce an error.");
-                InspectorTest.log("Error: " + error);
-                resolve();
-            });
-        }
-    });
-
-    suite.runTestCasesAndFinish();
-}
-</script>
-<style>
-    .css { background-image: -webkit-canvas(css); }
-</style>
-</head>
-<body _onload_="load()">
-<p>Test that CanvasAgent.requestContent can properly resolve the owner canvas node.</p>
-<canvas id="onscreen"></canvas>
-</body>
-</html>

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (219207 => 219208)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2017-07-06 18:35:58 UTC (rev 219208)
@@ -595,6 +595,7 @@
 webkit.org/b/166536 fast/canvas/webgl/webgl2-texStorage.html [ Skip ]
 webkit.org/b/166536 fast/canvas/webgl/webgl2-texture-upload-enums.html [ Skip ]
 webkit.org/b/166536 inspector/canvas/create-context-webgl2.html [ Skip ]
+webkit.org/b/166536 inspector/canvas/requestContent-webgl2.html [ Skip ]
 webkit.org/b/166536 inspector/canvas/resolveCanvasContext-webgl2.html [ Skip ]
 
 # These tests reference specific fonts on Mac port.

Modified: trunk/LayoutTests/platform/win/TestExpectations (219207 => 219208)


--- trunk/LayoutTests/platform/win/TestExpectations	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/LayoutTests/platform/win/TestExpectations	2017-07-06 18:35:58 UTC (rev 219208)
@@ -1913,6 +1913,8 @@
 http/tests/security/webgl-remote-read-remote-image-blocked-no-crossorigin.html [ Skip ]
 inspector/canvas/create-context-webgl.html [ Skip ]
 inspector/canvas/create-context-webgl2.html [ Skip ]
+inspector/canvas/requestContent-webgl.html [ Skip ]
+inspector/canvas/requestContent-webgl2.html [ Skip ]
 inspector/canvas/resolveCanvasContext-webgl.html [ Skip ]
 inspector/canvas/resolveCanvasContext-webgl2.html [ Skip ]
 ################################################################################

Modified: trunk/Source/WebCore/ChangeLog (219207 => 219208)


--- trunk/Source/WebCore/ChangeLog	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/Source/WebCore/ChangeLog	2017-07-06 18:35:58 UTC (rev 219208)
@@ -1,3 +1,28 @@
+2017-07-06  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: Support getting the content of WebGL/WebGL2 contexts
+        https://bugs.webkit.org/show_bug.cgi?id=173569
+        <rdar://problem/33112420>
+
+        Reviewed by Joseph Pecoraro.
+
+        Tests: inspector/canvas/requestContent-2d.html
+               inspector/canvas/requestContent-webgl.html
+               inspector/canvas/requestContent-webgl2.html
+
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::clearIfComposited):
+        * html/canvas/WebGLRenderingContextBase.h:
+        (WebCore::WebGLRenderingContextBase::preventBufferClearForInspector):
+        (WebCore::WebGLRenderingContextBase::setPreventBufferClearForInspector):
+        Add a flag that will prevent the context buffer from being cleared, allowing it to be copied
+        within a toDataURL call. This is currently only used by InspectorCanvasAgent::requestContent.
+
+        * inspector/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::requestContent):
+        Since toDataURL attempts to force the canvas to redraw, we can preserve the buffer after it
+        finishes drawing so that it can be copied, instead of it normally being swapped out.
+
 2017-07-06  Chris Dumez  <cdu...@apple.com>
 
         Move ResourceLoadObserver notification throttling logic from WebProcess class to ResourceLoadObserver

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (219207 => 219208)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2017-07-06 18:35:58 UTC (rev 219208)
@@ -731,7 +731,8 @@
         return false;
 
     if (!m_context->layerComposited() || m_layerCleared
-        || m_attributes.preserveDrawingBuffer || (mask && m_framebufferBinding))
+        || m_attributes.preserveDrawingBuffer || (mask && m_framebufferBinding)
+        || m_preventBufferClearForInspector)
         return false;
 
     auto contextAttributes = getContextAttributes();

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (219207 => 219208)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2017-07-06 18:35:58 UTC (rev 219208)
@@ -210,6 +210,9 @@
     bool isPreservingDrawingBuffer() const { return m_attributes.preserveDrawingBuffer; }
     void setPreserveDrawingBuffer(bool value) { m_attributes.preserveDrawingBuffer = value; }
 
+    bool preventBufferClearForInspector() const { return m_preventBufferClearForInspector; }
+    void setPreventBufferClearForInspector(bool value) { m_preventBufferClearForInspector = value; }
+
     virtual void hint(GC3Denum target, GC3Denum mode) = 0;
     GC3Dboolean isBuffer(WebGLBuffer*);
     bool isContextLost() const;
@@ -570,6 +573,8 @@
     bool m_synthesizedErrorsToConsole { true };
     int m_numGLErrorsToConsoleAllowed;
 
+    bool m_preventBufferClearForInspector { false };
+
     // A WebGLRenderingContext can be created in a state where it appears as
     // a valid and active context, but will not execute any important operations
     // until its load policy is completely resolved.

Modified: trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp (219207 => 219208)


--- trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp	2017-07-06 18:28:40 UTC (rev 219207)
+++ trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp	2017-07-06 18:35:58 UTC (rev 219208)
@@ -149,10 +149,25 @@
             return;
         }
         *content = result.releaseReturnValue();
-    } else {
-        // FIXME: <https://webkit.org/b/173569> Web Inspector: Support getting the content of WebGL/WebGL2/WebGPU contexts
+    }
+#if ENABLE(WEBGL)
+    else if (is<WebGLRenderingContextBase>(context)) {
+        WebGLRenderingContextBase* gl = downcast<WebGLRenderingContextBase>(context);
+
+        gl->setPreventBufferClearForInspector(true);
+        ExceptionOr<String> result = canvasEntry->element->toDataURL(ASCIILiteral("image/png"));
+        gl->setPreventBufferClearForInspector(false);
+
+        if (result.hasException()) {
+            errorString = result.releaseException().releaseMessage();
+            return;
+        }
+        *content = result.releaseReturnValue();
+    }
+#endif
+    // FIXME: <https://webkit.org/b/173621> Web Inspector: Support getting the content of WebGPU contexts
+    else
         errorString = ASCIILiteral("Unsupported canvas context type");
-    }
 }
 
 static JSC::JSValue contextAsScriptValue(JSC::ExecState& state, CanvasRenderingContext* context)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to