Title: [219078] trunk
Revision
219078
Author
[email protected]
Date
2017-07-03 11:21:24 -0700 (Mon, 03 Jul 2017)

Log Message

Web Inspector: Support listing WebGL2 and WebGPU contexts
https://bugs.webkit.org/show_bug.cgi?id=173396

Reviewed by Joseph Pecoraro.

Source/_javascript_Core:

* inspector/protocol/Canvas.json:
* inspector/scripts/codegen/generator.py:
(Generator.stylized_name_for_enum_value):
Add cases for handling new Canvas.ContextType protocol enumerations:
 - "webgl2" maps to `WebGL2`
 - "webgpu" maps to `WebGPU`

Source/WebCore:

Tests: inspector/canvas/create-context-2d.html
       inspector/canvas/create-context-webgl.html
       inspector/canvas/create-context-webgl2.html
       inspector/canvas/create-context-webgpu.html

Split "inspector/canvas/create-canvas-contexts.html" into a test for each context type.

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContextWebGPU):
* inspector/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::buildObjectForCanvas):

Source/WebInspectorUI:

* UserInterface/Models/Canvas.js:
(WebInspector.Canvas.fromPayload):
(WebInspector.Canvas.displayNameForContextType):

LayoutTests:

* inspector/canvas/create-canvas-contexts-expected.txt: Removed.
* inspector/canvas/create-canvas-contexts.html: Removed.
* inspector/canvas/create-context-2d-expected.txt: Added.
* inspector/canvas/create-context-2d.html: Added.
* inspector/canvas/create-context-webgl-expected.txt: Added.
* inspector/canvas/create-context-webgl.html: Added.
* inspector/canvas/create-context-webgl2-expected.txt: Added.
* inspector/canvas/create-context-webgl2.html: Added.
* inspector/canvas/create-context-webgpu-expected.txt: Added.
* inspector/canvas/create-context-webgpu.html: Added.
* inspector/canvas/resources/create-context-utilities.css: Added.
(.canvas):
* inspector/canvas/resources/create-context-utilities.js: Added.
(createAttachedCanvas):
(createDetachedCanvas):
(createCSSCanvas):
(destroyCanvases):
(TestPage.registerInitializer.awaitCanvasAdded):
(TestPage.registerInitializer.awaitCanvasRemoved):
(TestPage.registerInitializer.window.initializeTestSuite):
(TestPage.registerInitializer.window.addSimpleTestCase):
(TestPage.registerInitializer.window.addCSSCanvasTestCase):
* platform/gtk/TestExpectations:
* platform/ios/TestExpectations:
* platform/mac/TestExpectations:
* platform/win/TestExpectations:
Split the existing canvas lifecycle tests into one for each context type. This allows
platforms that don't support certain context types to ignore just those tests (e.g. WebGPU).

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (219077 => 219078)


--- trunk/LayoutTests/ChangeLog	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/LayoutTests/ChangeLog	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1,3 +1,39 @@
+2017-07-03  Devin Rousso  <[email protected]>
+
+        Web Inspector: Support listing WebGL2 and WebGPU contexts
+        https://bugs.webkit.org/show_bug.cgi?id=173396
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/canvas/create-canvas-contexts-expected.txt: Removed.
+        * inspector/canvas/create-canvas-contexts.html: Removed.
+        * inspector/canvas/create-context-2d-expected.txt: Added.
+        * inspector/canvas/create-context-2d.html: Added.
+        * inspector/canvas/create-context-webgl-expected.txt: Added.
+        * inspector/canvas/create-context-webgl.html: Added.
+        * inspector/canvas/create-context-webgl2-expected.txt: Added.
+        * inspector/canvas/create-context-webgl2.html: Added.
+        * inspector/canvas/create-context-webgpu-expected.txt: Added.
+        * inspector/canvas/create-context-webgpu.html: Added.
+        * inspector/canvas/resources/create-context-utilities.css: Added.
+        (.canvas):
+        * inspector/canvas/resources/create-context-utilities.js: Added.
+        (createAttachedCanvas):
+        (createDetachedCanvas):
+        (createCSSCanvas):
+        (destroyCanvases):
+        (TestPage.registerInitializer.awaitCanvasAdded):
+        (TestPage.registerInitializer.awaitCanvasRemoved):
+        (TestPage.registerInitializer.window.initializeTestSuite):
+        (TestPage.registerInitializer.window.addSimpleTestCase):
+        (TestPage.registerInitializer.window.addCSSCanvasTestCase):
+        * platform/gtk/TestExpectations:
+        * platform/ios/TestExpectations:
+        * platform/mac/TestExpectations:
+        * platform/win/TestExpectations:
+        Split the existing canvas lifecycle tests into one for each context type. This allows
+        platforms that don't support certain context types to ignore just those tests (e.g. WebGPU).
+
 2017-07-03  Chris Fleizach  <[email protected]>
 
         AX: role="none" (or presentation) does not work on iframes

Deleted: trunk/LayoutTests/inspector/canvas/create-canvas-contexts-expected.txt (219077 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-canvas-contexts-expected.txt	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/LayoutTests/inspector/canvas/create-canvas-contexts-expected.txt	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1,43 +0,0 @@
-Test that CanvasManager tracks creation and destruction of 2D and WebGL canvases.
-
-
-== Running test suite: Canvas.canvasContexts
--- Running test case: CheckNoCanvases
-PASS: CanvasManager should have no canvases.
-
--- Running test case: Create2DCanvasContext
-Added canvas.
-PASS: Canvas context should be 2D.
-Removed canvas.
-PASS: Removed canvas has expected ID.
-
--- Running test case: CreateWebGLCanvasContext
-Added canvas.
-PASS: Canvas context should be WebGL.
-Removed canvas.
-PASS: Removed canvas has expected ID.
-
--- Running test case: Create2DCanvasContextOffscreen
-Added canvas.
-PASS: Canvas context should be 2D.
-Removed canvas.
-PASS: Removed canvas has expected ID.
-
--- Running test case: CreateWebGLCanvasContextOffscreen
-Added canvas.
-PASS: Canvas context should be WebGL.
-Removed canvas.
-PASS: Removed canvas has expected ID.
-
--- Running test case: CreateCSSCanvas2D
-Create CSS canvas from -webkit-canvas(css-canvas-2d).
-Added canvas.
-PASS: Canvas context should be 2D.
-PASS: Canvas name should equal the identifier passed to -webkit-canvas.
-
--- Running test case: CreateCSSCanvasWebGL
-Create CSS canvas from -webkit-canvas(css-canvas-webgl).
-Added canvas.
-PASS: Canvas context should be WebGL.
-PASS: Canvas name should equal the identifier passed to -webkit-canvas.
-

Deleted: trunk/LayoutTests/inspector/canvas/create-canvas-contexts.html (219077 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-canvas-contexts.html	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/LayoutTests/inspector/canvas/create-canvas-contexts.html	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1,150 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<script src=""
-<script>
-let contexts = [];
-
-function createCanvas(contextType) {
-    let canvas = document.body.appendChild(document.createElement("canvas"));
-    contexts.push(canvas.getContext(contextType));
-}
-
-function createCSSCanvas(contextType, canvasName) {
-    contexts.push(document.getCSSCanvasContext(contextType, canvasName, 10, 10));
-}
-
-function createOffscreenCanvas(contextType) {
-    contexts.push(document.createElement("canvas").getContext(contextType));
-}
-
-function destroyCanvases() {
-    for (let context of contexts) {
-        let canvasElement = context.canvas;
-        if (canvasElement && canvasElement.parentNode)
-            canvasElement.remove();
-    }
-
-    contexts = [];
-
-    // Force GC to make sure the canvas element is destroyed, otherwise the frontend
-    // does not receive WebInspector.CanvasManager.Event.CanvasWasRemoved events.
-    setTimeout(() => { GCController.collect(); }, 0);
-}
-
-function test() {
-    let suite = InspectorTest.createAsyncSuite("Canvas.canvasContexts");
-
-    function awaitCanvasAdded(contextType) {
-        return WebInspector.canvasManager.awaitEvent(WebInspector.CanvasManager.Event.CanvasWasAdded)
-        .then((event) => {
-            let canvas = event.data.canvas;
-            InspectorTest.log("Added canvas.");
-
-            let contextDisplayName = WebInspector.Canvas.displayNameForContextType(contextType);
-            InspectorTest.expectEqual(canvas.contextType, contextType, `Canvas context should be ${contextDisplayName}.`);
-
-            return canvas;
-        });
-    }
-
-    function awaitCanvasRemoved(canvasIdentifier) {
-        return WebInspector.canvasManager.awaitEvent(WebInspector.CanvasManager.Event.CanvasWasRemoved)
-        .then((event) => {
-            let canvas = event.data.canvas;
-            InspectorTest.log("Removed canvas.");
-            InspectorTest.expectEqual(canvas.identifier, canvasIdentifier, "Removed canvas has expected ID.");
-        });
-    }
-
-    suite.addTestCase({
-        name: "CheckNoCanvases",
-        description: "Check that the CanvasManager has no canvases initially.",
-        test(resolve, reject) {
-            InspectorTest.expectEqual(WebInspector.canvasManager.canvases.length, 0, "CanvasManager should have no canvases.");
-            resolve();
-        }
-    });
-
-    function addSimpleTestCase({name, description, _expression_, contextType}) {
-        suite.addTestCase({
-            name,
-            description,
-            test(resolve, reject) {
-                awaitCanvasAdded(contextType)
-                .then((canvas) => {
-                    if (canvas.cssCanvasName) {
-                        InspectorTest.log("CSS canvas will not be destroyed");
-                        resolve();
-                        return;
-                    }
-
-                    let promise = awaitCanvasRemoved(canvas.identifier);
-                    InspectorTest.evaluateInPage(`destroyCanvases()`);
-                    return promise;
-                })
-                .then(resolve, reject);
-
-                InspectorTest.evaluateInPage(_expression_);
-            }
-        });
-    }
-
-    let simpleTestCases = [
-        {
-            name: "Create2DCanvasContext",
-            _expression_: `createCanvas("2d")`,
-            contextType: WebInspector.Canvas.ContextType.Canvas2D,
-        },
-        {
-            name: "CreateWebGLCanvasContext",
-            _expression_: `createCanvas("webgl")`,
-            contextType: WebInspector.Canvas.ContextType.WebGL,
-        },
-        {
-            name: "Create2DCanvasContextOffscreen",
-            _expression_: `createOffscreenCanvas("2d")`,
-            contextType: WebInspector.Canvas.ContextType.Canvas2D,
-        },
-        {
-            name: "CreateWebGLCanvasContextOffscreen",
-            _expression_: `createOffscreenCanvas("webgl")`,
-            contextType: WebInspector.Canvas.ContextType.WebGL,
-        }
-    ];
-
-    simpleTestCases.forEach(addSimpleTestCase);
-
-    function addCSSCanvasTest(contextType, cssCanvasIdentifier) {
-        let displayContextType = WebInspector.Canvas.displayNameForContextType(contextType);
-
-        suite.addTestCase({
-            name: `CreateCSSCanvas${displayContextType}`,
-            description: "Check that CSS canvases have the correct name and type.",
-            test(resolve, reject) {
-                awaitCanvasAdded(contextType, !!cssCanvasIdentifier)
-                .then((canvas) => { InspectorTest.expectEqual(canvas.cssCanvasName, cssCanvasIdentifier, "Canvas name should equal the identifier passed to -webkit-canvas."); })
-                .then(resolve, reject);
-
-                let contextId = contextType === WebInspector.Canvas.ContextType.Canvas2D ? "2d" : "webgl";
-                InspectorTest.log(`Create CSS canvas from -webkit-canvas(${cssCanvasIdentifier}).`);
-                InspectorTest.evaluateInPage(`createCSSCanvas("${contextId}", "${cssCanvasIdentifier}")`);
-            }
-        });
-    }
-
-    addCSSCanvasTest(WebInspector.Canvas.ContextType.Canvas2D, "css-canvas-2d");
-    addCSSCanvasTest(WebInspector.Canvas.ContextType.WebGL, "css-canvas-webgl");
-
-    suite.runTestCasesAndFinish();
-}
-</script>
-<style>
-    .canvas1 { background-image: -webkit-canvas(css-canvas-2d); }
-    .canvas2 { background-image: -webkit-canvas(css-canvas-webgl); }
-</style>
-</head>
-<body _onload_="runTest()">
-    <p>Test that CanvasManager tracks creation and destruction of 2D and WebGL canvases.</p>
-</body>
-</html>

Added: trunk/LayoutTests/inspector/canvas/create-context-2d-expected.txt (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-context-2d-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/create-context-2d-expected.txt	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,20 @@
+Test that CanvasManager tracks creation and destruction of 2D canvases.
+
+
+== Running test suite: Canvas.CreateContext2D
+-- Running test case: Canvas.CreateContext2D.NoCanvases
+PASS: CanvasManager should have no canvases.
+
+-- Running test case: Canvas.CreateContext2D.Attached
+PASS: Canvas context should be 2D.
+PASS: Removed canvas has expected ID.
+
+-- Running test case: Canvas.CreateContext2D.Detached
+PASS: Canvas context should be 2D.
+PASS: Removed canvas has expected ID.
+
+-- Running test case: Canvas.CreateContext2D.CSSCanvas
+Create CSS canvas from -webkit-canvas(css-canvas).
+PASS: Canvas context should be 2D.
+PASS: Canvas name should equal the identifier passed to -webkit-canvas.
+

Added: trunk/LayoutTests/inspector/canvas/create-context-2d.html (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-context-2d.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/create-context-2d.html	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+<script src=""
+<script>
+function test() {
+    let suite = initializeTestSuite("Canvas.CreateContext2D");
+
+    addSimpleTestCase({
+        name: "Attached",
+        _expression_: `createAttachedCanvas("2d")`,
+        contextType: WebInspector.Canvas.ContextType.Canvas2D,
+    });
+
+    addSimpleTestCase({
+        name: "Detached",
+        _expression_: `createDetachedCanvas("2d")`,
+        contextType: WebInspector.Canvas.ContextType.Canvas2D,
+    });
+
+    addCSSCanvasTestCase(WebInspector.Canvas.ContextType.Canvas2D);
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+    <p>Test that CanvasManager tracks creation and destruction of 2D canvases.</p>
+</body>
+</html>

Added: trunk/LayoutTests/inspector/canvas/create-context-webgl-expected.txt (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-context-webgl-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/create-context-webgl-expected.txt	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,20 @@
+Test that CanvasManager tracks creation and destruction of WebGL canvases.
+
+
+== Running test suite: Canvas.CreateContextWebGL
+-- Running test case: Canvas.CreateContextWebGL.NoCanvases
+PASS: CanvasManager should have no canvases.
+
+-- Running test case: Canvas.CreateContextWebGL.Attached
+PASS: Canvas context should be WebGL.
+PASS: Removed canvas has expected ID.
+
+-- Running test case: Canvas.CreateContextWebGL.Detached
+PASS: Canvas context should be WebGL.
+PASS: Removed canvas has expected ID.
+
+-- Running test case: Canvas.CreateContextWebGL.CSSCanvas
+Create CSS canvas from -webkit-canvas(css-canvas).
+PASS: Canvas context should be WebGL.
+PASS: Canvas name should equal the identifier passed to -webkit-canvas.
+

Added: trunk/LayoutTests/inspector/canvas/create-context-webgl.html (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-context-webgl.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/create-context-webgl.html	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+<script src=""
+<script>
+function test() {
+    let suite = initializeTestSuite("Canvas.CreateContextWebGL");
+
+    addSimpleTestCase({
+        name: "Attached",
+        _expression_: `createAttachedCanvas("webgl")`,
+        contextType: WebInspector.Canvas.ContextType.WebGL,
+    });
+
+    addSimpleTestCase({
+        name: "Detached",
+        _expression_: `createDetachedCanvas("webgl")`,
+        contextType: WebInspector.Canvas.ContextType.WebGL,
+    });
+
+    addCSSCanvasTestCase(WebInspector.Canvas.ContextType.WebGL);
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+    <p>Test that CanvasManager tracks creation and destruction of WebGL canvases.</p>
+</body>
+</html>

Added: trunk/LayoutTests/inspector/canvas/create-context-webgl2-expected.txt (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-context-webgl2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/create-context-webgl2-expected.txt	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,20 @@
+Test that CanvasManager tracks creation and destruction of WebGL2 canvases.
+
+
+== Running test suite: Canvas.CreateContextWebGL2
+-- Running test case: Canvas.CreateContextWebGL2.NoCanvases
+PASS: CanvasManager should have no canvases.
+
+-- Running test case: Canvas.CreateContextWebGL2.Attached
+PASS: Canvas context should be WebGL2.
+PASS: Removed canvas has expected ID.
+
+-- Running test case: Canvas.CreateContextWebGL2.Detached
+PASS: Canvas context should be WebGL2.
+PASS: Removed canvas has expected ID.
+
+-- Running test case: Canvas.CreateContextWebGL2.CSSCanvas
+Create CSS canvas from -webkit-canvas(css-canvas).
+PASS: Canvas context should be WebGL2.
+PASS: Canvas name should equal the identifier passed to -webkit-canvas.
+

Added: trunk/LayoutTests/inspector/canvas/create-context-webgl2.html (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-context-webgl2.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/create-context-webgl2.html	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+<script src=""
+<script>
+if (window.internals)
+    window.internals.settings.setWebGL2Enabled(true);
+
+function test() {
+    let suite = initializeTestSuite("Canvas.CreateContextWebGL2");
+
+    addSimpleTestCase({
+        name: "Attached",
+        _expression_: `createAttachedCanvas("webgl2")`,
+        contextType: WebInspector.Canvas.ContextType.WebGL2,
+    });
+
+    addSimpleTestCase({
+        name: "Detached",
+        _expression_: `createDetachedCanvas("webgl2")`,
+        contextType: WebInspector.Canvas.ContextType.WebGL2,
+    });
+
+    addCSSCanvasTestCase(WebInspector.Canvas.ContextType.WebGL2);
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+    <p>Test that CanvasManager tracks creation and destruction of WebGL2 canvases.</p>
+</body>
+</html>

Added: trunk/LayoutTests/inspector/canvas/create-context-webgpu-expected.txt (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-context-webgpu-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/create-context-webgpu-expected.txt	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,20 @@
+Test that CanvasManager tracks creation and destruction of WebGPU canvases.
+
+
+== Running test suite: Canvas.CreateContextWebGPU
+-- Running test case: Canvas.CreateContextWebGPU.NoCanvases
+PASS: CanvasManager should have no canvases.
+
+-- Running test case: Canvas.CreateContextWebGPU.Attached
+PASS: Canvas context should be WebGPU.
+PASS: Removed canvas has expected ID.
+
+-- Running test case: Canvas.CreateContextWebGPU.Detached
+PASS: Canvas context should be WebGPU.
+PASS: Removed canvas has expected ID.
+
+-- Running test case: Canvas.CreateContextWebGPU.CSSCanvas
+Create CSS canvas from -webkit-canvas(css-canvas).
+PASS: Canvas context should be WebGPU.
+PASS: Canvas name should equal the identifier passed to -webkit-canvas.
+

Added: trunk/LayoutTests/inspector/canvas/create-context-webgpu.html (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/create-context-webgpu.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/create-context-webgpu.html	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href=""
+<script src=""
+<script src=""
+<script>
+if (window.internals)
+    window.internals.settings.setWebGPUEnabled(true);
+
+function test() {
+    let suite = initializeTestSuite("Canvas.CreateContextWebGPU");
+
+    addSimpleTestCase({
+        name: "Attached",
+        _expression_: `createAttachedCanvas("webgpu")`,
+        contextType: WebInspector.Canvas.ContextType.WebGPU,
+    });
+
+    addSimpleTestCase({
+        name: "Detached",
+        _expression_: `createDetachedCanvas("webgpu")`,
+        contextType: WebInspector.Canvas.ContextType.WebGPU,
+    });
+
+    addCSSCanvasTestCase(WebInspector.Canvas.ContextType.WebGPU);
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+    <p>Test that CanvasManager tracks creation and destruction of WebGPU canvases.</p>
+</body>
+</html>

Added: trunk/LayoutTests/inspector/canvas/resources/create-context-utilities.css (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/resources/create-context-utilities.css	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/resources/create-context-utilities.css	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,3 @@
+.canvas {
+    background-image: -webkit-canvas(css-canvas);
+}

Added: trunk/LayoutTests/inspector/canvas/resources/create-context-utilities.js (0 => 219078)


--- trunk/LayoutTests/inspector/canvas/resources/create-context-utilities.js	                        (rev 0)
+++ trunk/LayoutTests/inspector/canvas/resources/create-context-utilities.js	2017-07-03 18:21:24 UTC (rev 219078)
@@ -0,0 +1,113 @@
+let contexts = [];
+
+function createAttachedCanvas(contextType) {
+    let canvas = document.body.appendChild(document.createElement("canvas"));
+    contexts.push(canvas.getContext(contextType));
+}
+
+function createDetachedCanvas(contextType) {
+    contexts.push(document.createElement("canvas").getContext(contextType));
+}
+
+function createCSSCanvas(contextType, canvasName) {
+    contexts.push(document.getCSSCanvasContext(contextType, canvasName, 10, 10));
+}
+
+function destroyCanvases() {
+    for (let context of contexts) {
+        let canvasElement = context.canvas;
+        if (canvasElement && canvasElement.parentNode)
+            canvasElement.remove();
+    }
+
+    contexts = [];
+
+    // Force GC to make sure the canvas element is destroyed, otherwise the frontend
+    // does not receive WebInspector.CanvasManager.Event.CanvasWasRemoved events.
+    setTimeout(() => { GCController.collect(); }, 0);
+}
+
+TestPage.registerInitializer(() => {
+    let suite = null;
+
+    function awaitCanvasAdded(contextType) {
+        return WebInspector.canvasManager.awaitEvent(WebInspector.CanvasManager.Event.CanvasWasAdded)
+        .then((event) => {
+            let canvas = event.data.canvas;
+            let contextDisplayName = WebInspector.Canvas.displayNameForContextType(contextType);
+            InspectorTest.expectEqual(canvas.contextType, contextType, `Canvas context should be ${contextDisplayName}.`);
+
+            return canvas;
+        });
+    }
+
+    function awaitCanvasRemoved(canvasIdentifier) {
+        return WebInspector.canvasManager.awaitEvent(WebInspector.CanvasManager.Event.CanvasWasRemoved)
+        .then((event) => {
+            let canvas = event.data.canvas;
+            InspectorTest.expectEqual(canvas.identifier, canvasIdentifier, "Removed canvas has expected ID.");
+        });
+    }
+
+    window.initializeTestSuite = function(name) {
+        suite = InspectorTest.createAsyncSuite(name);
+
+        suite.addTestCase({
+            name: `${suite.name}.NoCanvases`,
+            description: "Check that the CanvasManager has no canvases initially.",
+            test(resolve, reject) {
+                InspectorTest.expectEqual(WebInspector.canvasManager.canvases.length, 0, "CanvasManager should have no canvases.");
+                resolve();
+            }
+        });
+
+        return suite;
+    };
+
+    window.addSimpleTestCase = function({name, description, _expression_, contextType}) {
+        suite.addTestCase({
+            name: suite.name + "." + name,
+            description,
+            test(resolve, reject) {
+                awaitCanvasAdded(contextType)
+                .then((canvas) => {
+                    if (canvas.cssCanvasName) {
+                        InspectorTest.log("CSS canvas will not be destroyed");
+                        resolve();
+                        return;
+                    }
+
+                    let promise = awaitCanvasRemoved(canvas.identifier);
+                    InspectorTest.evaluateInPage(`destroyCanvases()`);
+                    return promise;
+                })
+                .then(resolve, reject);
+
+                InspectorTest.evaluateInPage(_expression_);
+            },
+        });
+    };
+
+    let previousCSSCanvasContextType = null;
+    window.addCSSCanvasTestCase = function(contextType) {
+        InspectorTest.assert(!previousCSSCanvasContextType || previousCSSCanvasContextType === contextType, "addCSSCanvasTestCase cannot be called more than once with different context types.");
+        if (!previousCSSCanvasContextType)
+            previousCSSCanvasContextType = contextType;
+
+        suite.addTestCase({
+            name: `${suite.name}.CSSCanvas`,
+            description: "Check that CSS canvases have the correct name and type.",
+            test(resolve, reject) {
+                awaitCanvasAdded(contextType)
+                .then((canvas) => {
+                    InspectorTest.expectEqual(canvas.cssCanvasName, "css-canvas", "Canvas name should equal the identifier passed to -webkit-canvas.");
+                })
+                .then(resolve, reject);
+
+                let contextId = contextType === WebInspector.Canvas.ContextType.Canvas2D ? "2d" : contextType;
+                InspectorTest.log(`Create CSS canvas from -webkit-canvas(css-canvas).`);
+                InspectorTest.evaluateInPage(`createCSSCanvas("${contextId}", "css-canvas")`);
+            },
+        });
+    };
+});

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (219077 => 219078)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2017-07-03 18:21:24 UTC (rev 219078)
@@ -594,6 +594,7 @@
 webkit.org/b/166536 fast/canvas/webgl/webgl2-runtime-flag.html [ Skip ]
 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 ]
 
 # These tests reference specific fonts on Mac port.
 Bug(GTK) fast/text/font-weights.html [ WontFix ]
@@ -1251,6 +1252,7 @@
 
 # WebGPU is not enabled on GTK+.
 fast/canvas/webgpu [ Skip ]
+inspector/canvas/create-context-webgpu.html [ Skip ]
 
 # We don't support APPLE_PAY.
 http/tests/ssl/applepay [ Skip ]

Modified: trunk/LayoutTests/platform/ios/TestExpectations (219077 => 219078)


--- trunk/LayoutTests/platform/ios/TestExpectations	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2017-07-03 18:21:24 UTC (rev 219078)
@@ -35,6 +35,7 @@
 
 # WebGPU is not enabled on iOS Simulator.
 fast/canvas/webgpu
+inspector/canvas/create-context-webgpu.html [ Skip ]
 
 # Encrypted Media Extensions are not enabled
 media/encrypted-media/

Modified: trunk/LayoutTests/platform/mac/TestExpectations (219077 => 219078)


--- trunk/LayoutTests/platform/mac/TestExpectations	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1139,6 +1139,8 @@
 # This test tests a particular system font, which is only on iOS and El Capitan.
 webkit.org/b/148119 [ Yosemite ] fast/text/trak-optimizeLegibility.html [ Failure ]
 
+webkit.org/b/174066 inspector/canvas/create-context-webgl2.html [ Pass Timeout ]
+webkit.org/b/174066 inspector/canvas/create-context-webgpu.html [ Pass Timeout ]
 webkit.org/b/170615 inspector/codemirror/prettyprinting-css.html [ Pass Timeout ]
 webkit.org/b/153460 inspector/codemirror/prettyprinting-css-rules.html [ Pass Timeout ]
 webkit.org/b/160048 [ Debug ] inspector/codemirror/prettyprinting-_javascript_.html [ Pass Timeout ]

Modified: trunk/LayoutTests/platform/win/TestExpectations (219077 => 219078)


--- trunk/LayoutTests/platform/win/TestExpectations	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/LayoutTests/platform/win/TestExpectations	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1912,6 +1912,8 @@
 http/tests/security/webgl-remote-read-remote-image-allowed.html [ Skip ]
 http/tests/security/webgl-remote-read-remote-image-allowed-with-credentials.html [ Skip ]
 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 ]
 ################################################################################
 #################          End WebGL Issues              #######################
 ################################################################################
@@ -2380,6 +2382,8 @@
 # inspector/debugger/removeBreakpoint.html [ Skip ] # Crashing
 # inspector/debugger/searchInContent-linebreaks.html [ Pass Crash ] # Flaky
 
+inspector/canvas/create-context-webgpu.html [ Skip ]
+
 ################################################################################
 #################        End Inspector Issues               ####################
 ################################################################################

Modified: trunk/Source/_javascript_Core/ChangeLog (219077 => 219078)


--- trunk/Source/_javascript_Core/ChangeLog	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1,3 +1,17 @@
+2017-07-03  Devin Rousso  <[email protected]>
+
+        Web Inspector: Support listing WebGL2 and WebGPU contexts
+        https://bugs.webkit.org/show_bug.cgi?id=173396
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/protocol/Canvas.json:
+        * inspector/scripts/codegen/generator.py:
+        (Generator.stylized_name_for_enum_value):
+        Add cases for handling new Canvas.ContextType protocol enumerations:
+         - "webgl2" maps to `WebGL2`
+         - "webgpu" maps to `WebGPU`
+
 2017-07-02  Yusuke Suzuki  <[email protected]>
 
         WTF::Thread should have the threads stack bounds.

Modified: trunk/Source/_javascript_Core/inspector/protocol/Canvas.json (219077 => 219078)


--- trunk/Source/_javascript_Core/inspector/protocol/Canvas.json	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/Source/_javascript_Core/inspector/protocol/Canvas.json	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1,7 +1,7 @@
 {
     "domain": "Canvas",
     "availability": "web",
-    "description": "Canvas domain allows tracking of 2D and WebGL canvases that have an associated graphics context. Tracks canvases in the DOM and CSS canvases created with -webkit-canvas.",
+    "description": "Canvas domain allows tracking of canvases that have an associated graphics context. Tracks canvases in the DOM and CSS canvases created with -webkit-canvas.",
     "types": [
         {
             "id": "CanvasId",
@@ -11,7 +11,7 @@
         {
             "id": "ContextType",
             "type": "string",
-            "enum": ["canvas-2d", "webgl"],
+            "enum": ["canvas-2d", "webgl", "webgl2", "webgpu"],
             "description": "The type of rendering context backing the canvas element."
         },
         {
@@ -31,7 +31,7 @@
         {
             "id": "Canvas",
             "type": "object",
-            "description": "Information about a 2D/WebGL canvas for which a rendering context has been created.",
+            "description": "Information about a canvas for which a rendering context has been created.",
             "properties": [
                 { "name": "canvasId", "$ref": "CanvasId", "description": "Canvas identifier." },
                 { "name": "contextType", "$ref": "ContextType", "description": "The type of rendering context backing the canvas." },

Modified: trunk/Source/_javascript_Core/inspector/scripts/codegen/generator.py (219077 => 219078)


--- trunk/Source/_javascript_Core/inspector/scripts/codegen/generator.py	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/Source/_javascript_Core/inspector/scripts/codegen/generator.py	2017-07-03 18:21:24 UTC (rev 219078)
@@ -43,6 +43,8 @@
 
 _ENUM_IDENTIFIER_RENAME_MAP = {
     'webgl': 'WebGL',  # Canvas.ContextType.webgl
+    'webgl2': 'WebGL2',  # Canvas.ContextType.webgl2
+    'webgpu': 'WebGPU',  # Canvas.ContextType.webgpu
 }
 
 # These objects are built manually by creating and setting InspectorValues.

Modified: trunk/Source/WebCore/ChangeLog (219077 => 219078)


--- trunk/Source/WebCore/ChangeLog	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/Source/WebCore/ChangeLog	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1,3 +1,22 @@
+2017-07-03  Devin Rousso  <[email protected]>
+
+        Web Inspector: Support listing WebGL2 and WebGPU contexts
+        https://bugs.webkit.org/show_bug.cgi?id=173396
+
+        Reviewed by Joseph Pecoraro.
+
+        Tests: inspector/canvas/create-context-2d.html
+               inspector/canvas/create-context-webgl.html
+               inspector/canvas/create-context-webgl2.html
+               inspector/canvas/create-context-webgpu.html
+
+        Split "inspector/canvas/create-canvas-contexts.html" into a test for each context type.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::getContextWebGPU):
+        * inspector/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::buildObjectForCanvas):
+
 2017-07-03  Alex Christensen  <[email protected]>
 
         REGRESSION(r215096) Queries of URLs with non-special schemes should not percent-encode single quotes

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (219077 => 219078)


--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2017-07-03 18:21:24 UTC (rev 219078)
@@ -333,6 +333,8 @@
         if (m_context) {
             // Need to make sure a RenderLayer and compositing layer get created for the Canvas
             invalidateStyleAndLayerComposition();
+
+            InspectorInstrumentation::didCreateCanvasRenderingContext(*this);
         }
     }
 

Modified: trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp (219077 => 219078)


--- trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp	2017-07-03 18:21:24 UTC (rev 219078)
@@ -34,11 +34,23 @@
 #include "InspectorPageAgent.h"
 #include "InstrumentingAgents.h"
 #include "MainFrame.h"
-#include "WebGLContextAttributes.h"
-#include "WebGLRenderingContextBase.h"
 #include <inspector/IdentifiersFactory.h>
 #include <inspector/InspectorProtocolObjects.h>
 
+#if ENABLE(WEBGL)
+#include "WebGLContextAttributes.h"
+#include "WebGLRenderingContext.h"
+#include "WebGLRenderingContextBase.h"
+#endif
+
+#if ENABLE(WEBGL2)
+#include "WebGL2RenderingContext.h"
+#endif
+
+#if ENABLE(WEBGPU)
+#include "WebGPURenderingContext.h"
+#endif
+
 using namespace Inspector;
 
 namespace WebCore {
@@ -259,11 +271,23 @@
     CanvasRenderingContext* context = canvasElement.renderingContext();
 
     Inspector::Protocol::Canvas::ContextType contextType;
-    if (context->is2d())
+    if (is<CanvasRenderingContext2D>(context))
         contextType = Inspector::Protocol::Canvas::ContextType::Canvas2D;
+#if ENABLE(WEBGL)
+    else if (is<WebGLRenderingContext>(context))
+        contextType = Inspector::Protocol::Canvas::ContextType::WebGL;
+#endif
+#if ENABLE(WEBGL2)
+    else if (is<WebGL2RenderingContext>(context))
+        contextType = Inspector::Protocol::Canvas::ContextType::WebGL2;
+#endif
+#if ENABLE(WEBGPU)
+    else if (is<WebGPURenderingContext>(context))
+        contextType = Inspector::Protocol::Canvas::ContextType::WebGPU;
+#endif
     else {
-        ASSERT(context->isWebGL());
-        contextType = Inspector::Protocol::Canvas::ContextType::WebGL;
+        ASSERT_NOT_REACHED();
+        contextType = Inspector::Protocol::Canvas::ContextType::Canvas2D;
     }
 
     auto canvas = Inspector::Protocol::Canvas::Canvas::create()

Modified: trunk/Source/WebInspectorUI/ChangeLog (219077 => 219078)


--- trunk/Source/WebInspectorUI/ChangeLog	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/Source/WebInspectorUI/ChangeLog	2017-07-03 18:21:24 UTC (rev 219078)
@@ -1,3 +1,14 @@
+2017-07-03  Devin Rousso  <[email protected]>
+
+        Web Inspector: Support listing WebGL2 and WebGPU contexts
+        https://bugs.webkit.org/show_bug.cgi?id=173396
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Models/Canvas.js:
+        (WebInspector.Canvas.fromPayload):
+        (WebInspector.Canvas.displayNameForContextType):
+
 2017-07-01  Dan Bernstein  <[email protected]>
 
         [macOS] Remove code only needed when building for OS X Yosemite

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Canvas.js (219077 => 219078)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Canvas.js	2017-07-03 17:22:11 UTC (rev 219077)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Canvas.js	2017-07-03 18:21:24 UTC (rev 219078)
@@ -54,6 +54,12 @@
         case CanvasAgent.ContextType.WebGL:
             contextType = WebInspector.Canvas.ContextType.WebGL;
             break;
+        case CanvasAgent.ContextType.WebGL2:
+            contextType = WebInspector.Canvas.ContextType.WebGL2;
+            break;
+        case CanvasAgent.ContextType.WebGPU:
+            contextType = WebInspector.Canvas.ContextType.WebGPU;
+            break;
         default:
             console.error("Invalid canvas context type", payload.contextType);
         }
@@ -74,6 +80,10 @@
             return WebInspector.UIString("2D");
         case WebInspector.Canvas.ContextType.WebGL:
             return WebInspector.unlocalizedString("WebGL");
+        case WebInspector.Canvas.ContextType.WebGL2:
+            return WebInspector.unlocalizedString("WebGL2");
+        case WebInspector.Canvas.ContextType.WebGPU:
+            return WebInspector.unlocalizedString("WebGPU");
         default:
             console.error("Invalid canvas context type", contextType);
         }
@@ -175,6 +185,8 @@
 WebInspector.Canvas.ContextType = {
     Canvas2D: "canvas-2d",
     WebGL: "webgl",
+    WebGL2: "webgl2",
+    WebGPU: "webgpu",
 };
 
 WebInspector.Canvas.ResourceSidebarType = "resource-type-canvas";
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to