Changeset 249753 in webkit


Ignore:
Timestamp:
Sep 10, 2019 9:34:34 PM (5 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Canvas: instrument WebGPUDevice instead of GPUCanvasContext
https://bugs.webkit.org/show_bug.cgi?id=201650

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

Most of the actual "work" done with Web GPU actually uses a WebGPUDevice.

A GPUCanvasContext is basically just a display "client" of the device, and isn't even
required (e.g. compute pipeline). We should treat the GPUCanvasContext almost like a
-webkit-canvas client of a WebGPUDevice.

  • inspector/protocol/Canvas.json:
    • Add powerPreference key to ContextAttributes type.
    • Rename requestCSSCanvasClientNodes command to requestClientNodes for the above reason.
    • Rename cssCanvasClientNodesChanged event to clientNodesChanged for the above reason.
    • Rename resolveCanvasContext command to resolveContext since a WebGPUDevice isn't really a "canvas".

Source/WebCore:

Most of the actual "work" done with Web GPU actually uses a WebGPUDevice.

A GPUCanvasContext is basically just a display "client" of the device, and isn't even
required (e.g. compute pipeline). We should treat the GPUCanvasContext almost like a
-webkit-canvas client of a WebGPUDevice.

Tests: inspector/canvas/create-context-webgpu.html

inspector/canvas/requestClientNodes-webgpu.html
inspector/canvas/resolveContext-webgpu.html

  • Modules/webgpu/WebGPUAdapter.cpp:

(WebCore::WebGPUAdapter::requestDevice const):
Notify web inspector after a device is created.

  • Modules/webgpu/WebGPUDevice.idl:
  • Modules/webgpu/WebGPUDevice.h:
  • Modules/webgpu/WebGPUDevice.cpp:

(WebCore::WebGPUDevice::instances): Added.
(WebCore::WebGPUDevice::instancesMutex): Added.
(WebCore::WebGPUDevice::~WebGPUDevice): Added.
Notify web inspector when the device is about to be destructed.

  • Modules/webgpu/GPUCanvasContext.h:
  • Modules/webgpu/GPUCanvasContext.cpp:

(WebCore::GPUCanvasContext::create):
(WebCore::GPUCanvasContext::configureSwapChain):

  • inspector/InspectorCanvas.h:
  • inspector/InspectorCanvas.cpp:

(WebCore::canvasIfContextMatchesDevice): Added.
(WebCore::InspectorCanvas::create):
(WebCore::InspectorCanvas::InspectorCanvas):
(WebCore::InspectorCanvas::canvasContext const): Added.
(WebCore::InspectorCanvas::canvasElement const): Added.
(WebCore::InspectorCanvas::isDeviceForCanvasContext const): Added.
(WebCore::InspectorCanvas::deviceContext const): Added.
(WebCore::InspectorCanvas::scriptExecutionContext const): Added.
(WebCore::InspectorCanvas::resolveContext const): Added.
(WebCore::InspectorCanvas::clientNodes const): Added.
(WebCore::InspectorCanvas::canvasChanged):
(WebCore::InspectorCanvas::resetRecordingData):
(WebCore::InspectorCanvas::recordAction):
(WebCore::InspectorCanvas::buildObjectForCanvas):
(WebCore::InspectorCanvas::releaseObjectForRecording):
(WebCore::InspectorCanvas::getCanvasContentAsDataURL):
(WebCore::InspectorCanvas::buildInitialState):
(WebCore::InspectorCanvas::canvasElement): Deleted.

  • inspector/InspectorInstrumentation.cpp:

(WebCore::InspectorInstrumentation::didCreateWebGPUDeviceImpl): Added.
(WebCore::InspectorInstrumentation::willDestroyWebGPUDeviceImpl): Added.
(WebCore::InspectorInstrumentation::willConfigureSwapChainImpl): Added.

  • inspector/InspectorInstrumentation.h:

(WebCore::InspectorInstrumentation::didCreateWebGPUDevice): Added.
(WebCore::InspectorInstrumentation::willDestroyWebGPUDevice): Added.
(WebCore::InspectorInstrumentation::willConfigureSwapChain): Added.

  • inspector/agents/InspectorCanvasAgent.h:
  • inspector/agents/InspectorCanvasAgent.cpp:

(WebCore::InspectorCanvasAgent::enable):
(WebCore::InspectorCanvasAgent::requestClientNodes): Added.
(WebCore::InspectorCanvasAgent::resolveContext): Added.
(WebCore::InspectorCanvasAgent::startRecording):
(WebCore::InspectorCanvasAgent::stopRecording):
(WebCore::InspectorCanvasAgent::frameNavigated):
(WebCore::InspectorCanvasAgent::didChangeCSSCanvasClientNodes):
(WebCore::InspectorCanvasAgent::didChangeCanvasMemory):
(WebCore::InspectorCanvasAgent::canvasDestroyed):
(WebCore::InspectorCanvasAgent::recordCanvasAction):
(WebCore::InspectorCanvasAgent::didFinishRecordingCanvasFrame):
(WebCore::InspectorCanvasAgent::didCreateWebGPUDevice): Added.
(WebCore::InspectorCanvasAgent::willDestroyWebGPUDevice): Added.
(WebCore::InspectorCanvasAgent::willConfigureSwapChain): Added.
(WebCore::InspectorCanvasAgent::clearCanvasData):
(WebCore::InspectorCanvasAgent::bindCanvas):
(WebCore::InspectorCanvasAgent::unbindCanvas):
(WebCore::InspectorCanvasAgent::findInspectorCanvas):
(WebCore::InspectorCanvasAgent::requestCSSCanvasClientNodes): Deleted.
(WebCore::contextAsScriptValue): Deleted.
(WebCore::InspectorCanvasAgent::resolveCanvasContext): Deleted.

  • inspector/InspectorShaderProgram.cpp:

(WebCore::InspectorShaderProgram::context const):

Source/WebInspectorUI:

Most of the actual "work" done with Web GPU actually uses a WebGPUDevice.

A GPUCanvasContext is basically just a display "client" of the device, and isn't even
required (e.g. compute pipeline). We should treat the GPUCanvasContext almost like a
-webkit-canvas client of a WebGPUDevice.

  • UserInterface/Protocol/CanvasObserver.js:

(WI.CanvasObserver.prototype.clientNodesChanged): Added.
(WI.CanvasObserver.prototype.cssCanvasClientNodesChanged):

  • UserInterface/Controllers/CanvasManager.js:

(WI.CanvasManager.prototype.clientNodesChanged): Added.
(WI.CanvasManager.prototype.cssCanvasClientNodesChanged): Deleted.

  • UserInterface/Models/Canvas.js:

(WI.Canvas.resetUniqueDisplayNameNumbers):
(WI.Canvas.prototype.get displayName):
(WI.Canvas.prototype.requestNode):
(WI.Canvas.prototype.requestClientNodes): Added.
(WI.Canvas.prototype.requestSize):
(WI.Canvas.prototype.clientNodesChanged): Added.
(WI.Canvas.prototype.requestCSSCanvasClientNodes): Deleted.
(WI.Canvas.prototype.cssCanvasClientNodesChanged): Deleted.

  • UserInterface/Protocol/RemoteObject.js:

(WI.RemoteObject.resolveCanvasContext):

  • UserInterface/Views/CanvasContentView.js:

(WI.CanvasContentView.prototype.attached):
(WI.CanvasContentView.prototype._refreshPixelSize):

  • UserInterface/Views/CanvasDetailsSidebarPanel.js:

(WI.CanvasDetailsSidebarPanel.prototype.set canvas):
(WI.CanvasDetailsSidebarPanel.prototype.initialLayout):
(WI.CanvasDetailsSidebarPanel.prototype.layout):
(WI.CanvasDetailsSidebarPanel.prototype._refreshSourceSection):
(WI.CanvasDetailsSidebarPanel.prototype._refreshClientsSection): Added.
(WI.CanvasDetailsSidebarPanel.prototype._refreshCSSCanvasSection): Deleted.

  • UserInterface/Views/CanvasOverviewContentView.js:

(WI.CanvasOverviewContentView.prototype._contentViewMouseEnter):

  • UserInterface/Views/CanvasTreeElement.js:

(WI.CanvasTreeElement.prototype._handleMouseOver):

  • Localizations/en.lproj/localizedStrings.js:

LayoutTests:

  • inspector/canvas/create-context-webgpu.html:
  • inspector/canvas/create-context-webgpu-expected.txt:
  • inspector/canvas/resources/create-context-utilities.js:

(createDetachedCanvas):
(createCSSCanvas):
(destroyCanvases):

  • inspector/canvas/requestClientNodes.html: Added.
  • inspector/canvas/requestClientNodes-expected.txt: Added.
  • inspector/canvas/requestClientNodes-css.html: Renamed from LayoutTests/inspector/canvas/css-canvas-clients.html.
  • inspector/canvas/requestClientNodes-css-expected.txt: Renamed from LayoutTests/inspector/canvas/css-canvas-clients-expected.txt.
  • inspector/canvas/requestClientNodes-webgpu.html: Added.
  • inspector/canvas/requestClientNodes-webgpu-expected.txt: Added.
  • inspector/canvas/resolveContext-2d.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-2d.html.
  • inspector/canvas/resolveContext-2d-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-2d-expected.txt.
  • inspector/canvas/resolveContext-bitmaprenderer.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-bitmaprenderer.html.
  • inspector/canvas/resolveContext-bitmaprenderer-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-bitmaprenderer-expected.txt.
  • inspector/canvas/resolveContext-webgl.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgl.html.
  • inspector/canvas/resolveContext-webgl-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgl-expected.txt.
  • inspector/canvas/resolveContext-webgl2.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgl2.html.
  • inspector/canvas/resolveContext-webgl2-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgl2-expected.txt.
  • inspector/canvas/resolveContext-webgpu.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgpu.html.
  • inspector/canvas/resolveContext-webgpu-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgpu-expected.txt.
  • inspector/canvas/context-attributes-expected.txt:
  • platform/gtk/TestExpectations:
  • platform/ios/TestExpectations:
  • platform/mac-wk1/TestExpectations:
  • platform/mac/TestExpectations:
  • platform/win/TestExpectations:
  • platform/wincairo/TestExpectations:
  • platform/wpe/TestExpectations:
Location:
trunk
Files:
12 added
8 deleted
38 edited
4 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r249751 r249753  
     12019-09-10  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Canvas: instrument WebGPUDevice instead of GPUCanvasContext
     4        https://bugs.webkit.org/show_bug.cgi?id=201650
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        * inspector/canvas/create-context-webgpu.html:
     9        * inspector/canvas/create-context-webgpu-expected.txt:
     10        * inspector/canvas/resources/create-context-utilities.js:
     11        (createDetachedCanvas):
     12        (createCSSCanvas):
     13        (destroyCanvases):
     14
     15        * inspector/canvas/requestClientNodes.html: Added.
     16        * inspector/canvas/requestClientNodes-expected.txt: Added.
     17        * inspector/canvas/requestClientNodes-css.html: Renamed from LayoutTests/inspector/canvas/css-canvas-clients.html.
     18        * inspector/canvas/requestClientNodes-css-expected.txt: Renamed from LayoutTests/inspector/canvas/css-canvas-clients-expected.txt.
     19        * inspector/canvas/requestClientNodes-webgpu.html: Added.
     20        * inspector/canvas/requestClientNodes-webgpu-expected.txt: Added.
     21
     22        * inspector/canvas/resolveContext-2d.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-2d.html.
     23        * inspector/canvas/resolveContext-2d-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-2d-expected.txt.
     24        * inspector/canvas/resolveContext-bitmaprenderer.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-bitmaprenderer.html.
     25        * inspector/canvas/resolveContext-bitmaprenderer-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-bitmaprenderer-expected.txt.
     26        * inspector/canvas/resolveContext-webgl.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgl.html.
     27        * inspector/canvas/resolveContext-webgl-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgl-expected.txt.
     28        * inspector/canvas/resolveContext-webgl2.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgl2.html.
     29        * inspector/canvas/resolveContext-webgl2-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgl2-expected.txt.
     30        * inspector/canvas/resolveContext-webgpu.html: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgpu.html.
     31        * inspector/canvas/resolveContext-webgpu-expected.txt: Renamed from LayoutTests/inspector/canvas/resolveCanvasContext-webgpu-expected.txt.
     32
     33        * inspector/canvas/context-attributes-expected.txt:
     34
     35        * platform/gtk/TestExpectations:
     36        * platform/ios/TestExpectations:
     37        * platform/mac-wk1/TestExpectations:
     38        * platform/mac/TestExpectations:
     39        * platform/win/TestExpectations:
     40        * platform/wincairo/TestExpectations:
     41        * platform/wpe/TestExpectations:
     42
    1432019-09-10  Joseph Pecoraro  <pecoraro@apple.com>
    244
  • trunk/LayoutTests/inspector/canvas/context-attributes-expected.txt

    r225884 r249753  
    3333  "premultipliedAlpha": true,
    3434  "preserveDrawingBuffer": false,
     35  "powerPreference": "default",
    3536  "failIfMajorPerformanceCaveat": false
    3637}
     
    4647  "premultipliedAlpha": true,
    4748  "preserveDrawingBuffer": false,
     49  "powerPreference": "default",
    4850  "failIfMajorPerformanceCaveat": false
    4951}
  • trunk/LayoutTests/inspector/canvas/create-context-webgpu-expected.txt

    r243763 r249753  
    66PASS: CanvasManager should have no canvases.
    77
    8 -- Running test case: Canvas.CreateContextWebGPU.Attached
     8-- Running test case: Canvas.CreateContextWebGPU.Device
    99PASS: Canvas context should be Web GPU.
    10   0: getContext - [native code]
    11   1: createAttachedCanvas - inspector/canvas/resources/create-context-utilities.js:4:36
    12   2: Global Code - [program code]
    13   3: evaluateWithScopeExtension - [native code]
    14   4: (anonymous function) - [native code]
    15   5: _wrapCall - [native code]
    1610
    1711PASS: Removed canvas has expected ID.
    1812
    19 -- Running test case: Canvas.CreateContextWebGPU.Detached
    20 PASS: Canvas context should be Web GPU.
    21   0: getContext - [native code]
    22   1: createDetachedCanvas - inspector/canvas/resources/create-context-utilities.js:11:62
    23   2: Global Code - [program code]
    24   3: evaluateWithScopeExtension - [native code]
    25   4: (anonymous function) - [native code]
    26   5: _wrapCall - [native code]
     13-- Running test case: Canvas.CreateContextWebGPU.Canvas.Attached
     14PASS: Inspector canvas should not be created for attached GPUCanvasContext without connected WebGPUDevice.
    2715
    28 PASS: Removed canvas has expected ID.
     16-- Running test case: Canvas.CreateContextWebGPU.Canvas.Detached
     17PASS: Inspector canvas should not be created for detached GPUCanvasContext without connected WebGPUDevice.
    2918
    30 -- Running test case: Canvas.CreateContextWebGPU.CSSCanvas
    31 Create CSS canvas from -webkit-canvas(css-canvas).
    32 PASS: Canvas context should be Web GPU.
    33   0: getCSSCanvasContext - [native code]
    34   1: createCSSCanvas - inspector/canvas/resources/create-context-utilities.js:18:47
    35   2: Global Code - [program code]
    36   3: evaluateWithScopeExtension - [native code]
    37   4: (anonymous function) - [native code]
    38   5: _wrapCall - [native code]
     19-- Running test case: Canvas.CreateContextWebGPU.Canvas.CSS
     20PASS: Inspector canvas should not be created for CSS GPUCanvasContext without connected WebGPUDevice.
    3921
    40 PASS: Canvas name should equal the identifier passed to -webkit-canvas.
    41 
  • trunk/LayoutTests/inspector/canvas/create-context-webgpu.html

    r243763 r249753  
    99    window.internals.settings.setWebGPUEnabled(true);
    1010
     11function createDevice() {
     12    function receivedDevice(device) {
     13        window.contexts.push(device);
     14    }
     15
     16    function receivedAdapter(adapter) {
     17        adapter.requestDevice().then(receivedDevice);
     18    }
     19
     20    navigator.gpu.requestAdapter().then(receivedAdapter);
     21}
     22
    1123function test() {
    12     InspectorTest.debug();
    13 
    1424    let suite = InspectorTest.CreateContextUtilities.initializeTestSuite("Canvas.CreateContextWebGPU");
    1525
    1626    InspectorTest.CreateContextUtilities.addSimpleTestCase({
    17         name: "Attached",
    18         expression: `createAttachedCanvas("gpu")`,
     27        name: "Device",
     28        expression: `createDevice()`,
    1929        contextType: WI.Canvas.ContextType.WebGPU,
    2030    });
    2131
    22     InspectorTest.CreateContextUtilities.addSimpleTestCase({
    23         name: "Detached",
    24         expression: `createDetachedCanvas("gpu")`,
    25         contextType: WI.Canvas.ContextType.WebGPU,
     32    suite.addTestCase({
     33        name: "Canvas.CreateContextWebGPU.Canvas.Attached",
     34        description: "Ensure that attached GPUCanvasContext aren't tracked as a canvas, instead of the WebGPUDevice.",
     35        async test() {
     36            let created = false;
     37            let listener = WI.canvasManager.addEventListener(WI.CanvasManager.Event.CanvasAdded, (event) => {
     38                InspectorTest.assert(event.target.contextType === WI.Canvas.ContextType.WebGPU);
     39                created = true;
     40            });
     41
     42            await InspectorTest.evaluateInPage(`createAttachedCanvas("gpu")`)
     43
     44            WI.canvasManager.removeEventListener(WI.CanvasManager.Event.CanvasAdded, listener);
     45
     46            InspectorTest.expectFalse(created, "Inspector canvas should not be created for attached GPUCanvasContext without connected WebGPUDevice.");
     47        },
    2648    });
    2749
    28     InspectorTest.CreateContextUtilities.addCSSCanvasTestCase(WI.Canvas.ContextType.WebGPU);
     50    suite.addTestCase({
     51        name: "Canvas.CreateContextWebGPU.Canvas.Detached",
     52        description: "Ensure that detached GPUCanvasContext aren't tracked as a canvas, instead of the WebGPUDevice.",
     53        async test() {
     54            let created = false;
     55            let listener = WI.canvasManager.addEventListener(WI.CanvasManager.Event.CanvasAdded, (event) => {
     56                InspectorTest.assert(event.target.contextType === WI.Canvas.ContextType.WebGPU);
     57                created = true;
     58            });
     59
     60            await InspectorTest.evaluateInPage(`createDetachedCanvas("gpu")`)
     61
     62            WI.canvasManager.removeEventListener(WI.CanvasManager.Event.CanvasAdded, listener);
     63
     64            InspectorTest.expectFalse(created, "Inspector canvas should not be created for detached GPUCanvasContext without connected WebGPUDevice.");
     65        },
     66    });
     67
     68    suite.addTestCase({
     69        name: "Canvas.CreateContextWebGPU.Canvas.CSS",
     70        description: "Ensure that CSS GPUCanvasContext aren't tracked as a canvas, instead of the WebGPUDevice.",
     71        async test() {
     72            let created = false;
     73            let listener = WI.canvasManager.addEventListener(WI.CanvasManager.Event.CanvasAdded, (event) => {
     74                InspectorTest.assert(event.target.contextType === WI.Canvas.ContextType.WebGPU);
     75                created = true;
     76            });
     77
     78            await InspectorTest.evaluateInPage(`createCSSCanvas("gpu", "css-canvas")`)
     79
     80            WI.canvasManager.removeEventListener(WI.CanvasManager.Event.CanvasAdded, listener);
     81
     82            InspectorTest.expectFalse(created, "Inspector canvas should not be created for CSS GPUCanvasContext without connected WebGPUDevice.");
     83        },
     84    });
    2985
    3086    suite.runTestCasesAndFinish();
  • trunk/LayoutTests/inspector/canvas/resolveContext-2d.html

    r249752 r249753  
    1212function test()
    1313{
    14     let suite = InspectorTest.createAsyncSuite("Canvas.resolveCanvasContext2D");
     14    let suite = InspectorTest.createAsyncSuite("Canvas.resolveContext2D");
    1515
    1616    suite.addTestCase({
    17         name: `Canvas.resolveCanvasContext2D.validIdentifier`,
     17        name: `Canvas.resolveContext2D.validIdentifier`,
    1818        description: "Should return a valid object for the given canvas identifier.",
    1919        test(resolve, reject) {
     
    2525
    2626            const objectGroup = "test";
    27             CanvasAgent.resolveCanvasContext(canvas.identifier, objectGroup)
     27            CanvasAgent.resolveContext(canvas.identifier, objectGroup)
    2828            .then(({object}) => {
    2929                InspectorTest.expectEqual(object.type, "object", `Payload should have type "object".`);
     
    3737
    3838    suite.addTestCase({
    39         name: "Canvas.resolveCanvasContext.invalidIdentifier",
     39        name: "Canvas.resolveContext.invalidIdentifier",
    4040        description: "Invalid canvas identifiers should cause an error.",
    4141        test(resolve, reject) {
    4242            const identifier = "DOES_NOT_EXIST";
    4343            const objectGroup = "test";
    44             CanvasAgent.resolveCanvasContext(identifier, objectGroup, (error) => {
     44            CanvasAgent.resolveContext(identifier, objectGroup, (error) => {
    4545                InspectorTest.expectThat(error, "Should produce an error.");
    4646                InspectorTest.log("Error: " + error);
     
    5555</head>
    5656<body onload="load()">
    57     <p>Tests for the Canvas.resolveCanvasContext command for 2D contexts.</p>
     57    <p>Tests for the Canvas.resolveContext command for 2D contexts.</p>
    5858</body>
    5959</html>
  • trunk/LayoutTests/inspector/canvas/resolveContext-bitmaprenderer.html

    r249752 r249753  
    1212function test()
    1313{
    14     let suite = InspectorTest.createAsyncSuite("Canvas.resolveCanvasContextBitmapRenderer");
     14    let suite = InspectorTest.createAsyncSuite("Canvas.resolveContextBitmapRenderer");
    1515
    1616    suite.addTestCase({
    17         name: `Canvas.resolveCanvasContextBitmapRenderer.validIdentifier`,
     17        name: `Canvas.resolveContextBitmapRenderer.validIdentifier`,
    1818        description: "Should return a valid object for the given canvas identifier.",
    1919        test(resolve, reject) {
     
    2525
    2626            const objectGroup = "test";
    27             CanvasAgent.resolveCanvasContext(canvas.identifier, objectGroup)
     27            CanvasAgent.resolveContext(canvas.identifier, objectGroup)
    2828            .then(({object}) => {
    2929                InspectorTest.expectEqual(object.type, "object", `Payload should have type "object".`);
     
    3939</head>
    4040<body onload="load()">
    41     <p>Tests for the Canvas.resolveCanvasContext command for BitmapRenderer contexts.</p>
     41    <p>Tests for the Canvas.resolveContext command for BitmapRenderer contexts.</p>
    4242</body>
    4343</html>
  • trunk/LayoutTests/inspector/canvas/resolveContext-webgl.html

    r249752 r249753  
    1212function test()
    1313{
    14     let suite = InspectorTest.createAsyncSuite("Canvas.resolveCanvasContextWebGL");
     14    let suite = InspectorTest.createAsyncSuite("Canvas.resolveContextWebGL");
    1515
    1616    suite.addTestCase({
    17         name: `Canvas.resolveCanvasContextWebGL.validIdentifier`,
     17        name: `Canvas.resolveContextWebGL.validIdentifier`,
    1818        description: "Should return a valid object for the given canvas identifier.",
    1919        test(resolve, reject) {
     
    2525
    2626            const objectGroup = "test";
    27             CanvasAgent.resolveCanvasContext(canvas.identifier, objectGroup)
     27            CanvasAgent.resolveContext(canvas.identifier, objectGroup)
    2828            .then(({object}) => {
    2929                InspectorTest.expectEqual(object.type, "object", `Payload should have type "object".`);
     
    3939</head>
    4040<body onload="load()">
    41     <p>Tests for the Canvas.resolveCanvasContext command for WebGL contexts.</p>
     41    <p>Tests for the Canvas.resolveContext command for WebGL contexts.</p>
    4242</body>
    4343</html>
  • trunk/LayoutTests/inspector/canvas/resolveContext-webgl2.html

    r249752 r249753  
    1515function test()
    1616{
    17     let suite = InspectorTest.createAsyncSuite("Canvas.resolveCanvasContextWebGL2");
     17    let suite = InspectorTest.createAsyncSuite("Canvas.resolveContextWebGL2");
    1818
    1919    suite.addTestCase({
    20         name: `Canvas.resolveCanvasContextWebGL2.validIdentifier`,
     20        name: `Canvas.resolveContextWebGL2.validIdentifier`,
    2121        description: "Should return a valid object for the given canvas identifier.",
    2222        test(resolve, reject) {
     
    2828
    2929            const objectGroup = "test";
    30             CanvasAgent.resolveCanvasContext(canvas.identifier, objectGroup)
     30            CanvasAgent.resolveContext(canvas.identifier, objectGroup)
    3131            .then(({object}) => {
    3232                InspectorTest.expectEqual(object.type, "object", `Payload should have type "object".`);
     
    4242</head>
    4343<body onload="load()">
    44     <p>Tests for the Canvas.resolveCanvasContext command for WebGL2 contexts.</p>
     44    <p>Tests for the Canvas.resolveContext command for WebGL2 contexts.</p>
    4545</body>
    4646</html>
  • trunk/LayoutTests/inspector/canvas/resources/create-context-utilities.js

    r243763 r249753  
    1 let contexts = [];
     1window.contexts = [];
    22
    33function createAttachedCanvas(contextType) {
     
    66    if (!context)
    77        TestPage.addResult("FAIL: missing context for type " + contextType);
    8     contexts.push(context);
     8    window.contexts.push(context);
    99}
    1010
     
    1313    if (!context)
    1414        TestPage.addResult("FAIL: missing context for type " + contextType);
    15     contexts.push(context);
     15    window.contexts.push(context);
    1616}
    1717
     
    2020    if (!context)
    2121        TestPage.addResult("FAIL: missing context for type " + contextType);
    22     contexts.push();
     22    window.contexts.push();
    2323}
    2424
    2525function destroyCanvases() {
    26     for (let context of contexts) {
     26    for (let context of window.contexts) {
    2727        if (!context)
    2828            continue;
     
    3333    }
    3434
    35     contexts = [];
     35    window.contexts = [];
    3636
    3737    // Force GC to make sure the canvas element is destroyed, otherwise the frontend
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r249713 r249753  
    517517webkit.org/b/166536 inspector/canvas/recording-webgl2-snapshots.html [ Skip ]
    518518webkit.org/b/166536 inspector/canvas/requestContent-webgl2.html [ Skip ]
    519 webkit.org/b/166536 inspector/canvas/resolveCanvasContext-webgl2.html [ Skip ]
     519webkit.org/b/166536 inspector/canvas/resolveContext-webgl2.html [ Skip ]
    520520webkit.org/b/166536 inspector/canvas/shaderProgram-add-remove-webgl2.html [ Skip ]
    521521webkit.org/b/166536 webgl/2.0.0/ [ Skip ]
     
    11511151webkit.org/b/191005 webgpu/ [ Skip ]
    11521152webkit.org/b/191005 inspector/canvas/create-context-webgpu.html [ Skip ]
    1153 webkit.org/b/191005 inspector/canvas/resolveCanvasContext-webgpu.html [ Skip ]
     1153webkit.org/b/191005 inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
     1154webkit.org/b/191005 inspector/canvas/resolveContext-webgpu.html [ Skip ]
    11541155
    11551156# No support for resource load statistics yet
  • trunk/LayoutTests/platform/ios/TestExpectations

    r249744 r249753  
    4545webgpu [ Skip ]
    4646inspector/canvas/create-context-webgpu.html [ Skip ]
    47 inspector/canvas/resolveCanvasContext-webgpu.html [ Skip ]
     47inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
     48inspector/canvas/resolveContext-webgpu.html [ Skip ]
    4849
    4950# Encrypted Media Extensions are not enabled
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r249680 r249753  
    4747webgpu [ Skip ]
    4848inspector/canvas/create-context-webgpu.html [ Skip ]
    49 inspector/canvas/resolveCanvasContext-webgpu.html [ Skip ]
     49inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
     50inspector/canvas/resolveContext-webgpu.html [ Skip ]
    5051
    5152# Media Stream API testing is not supported for WK1 yet.
  • trunk/LayoutTests/platform/mac/TestExpectations

    r249586 r249753  
    10331033webkit.org/b/178028 inspector/canvas/create-context-2d.html [ Pass Timeout ]
    10341034webkit.org/b/174066 inspector/canvas/create-context-webgl2.html [ Pass Timeout ]
    1035 webkit.org/b/174272 inspector/canvas/css-canvas-clients.html [ Pass Failure ]
    10361035webkit.org/b/174066 inspector/canvas/recording-webgl2-frameCount.html [ Pass Failure Timeout ]
    10371036webkit.org/b/174066 inspector/canvas/recording-webgl2-full.html [ Pass Failure Timeout ]
    10381037webkit.org/b/174066 inspector/canvas/recording-webgl2-memoryLimit.html [ Pass Failure Timeout ]
    10391038webkit.org/b/174066 inspector/canvas/recording-webgl2-snapshots.html [ Pass Failure Timeout ]
     1039webkit.org/b/174272 inspector/canvas/requestClientNodes-css.html [ Pass Failure ]
    10401040webkit.org/b/174066 inspector/canvas/shaderProgram-add-remove-webgl2.html [ Pass Failure Timeout ]
    10411041webkit.org/b/160048 [ Debug ] inspector/codemirror/prettyprinting-javascript.html [ Pass Timeout ]
     
    17841784webkit.org/b/199275 [ HighSierra ] webgpu [ Skip ]
    17851785webkit.org/b/199275 [ HighSierra ] inspector/canvas/create-context-webgpu.html [ Skip ]
    1786 webkit.org/b/199275 [ HighSierra ] inspector/canvas/resolveCanvasContext-webgpu.html [ Skip ]
     1786webkit.org/b/199275 [ HighSierra ] inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
     1787webkit.org/b/199275 [ HighSierra ] inspector/canvas/resolveContext-webgpu.html [ Skip ]
    17871788
    17881789webkit.org/b/189680 platform/mac/media/audio-session-category-video-paused.html [ Pass Timeout ]
  • trunk/LayoutTests/platform/win/TestExpectations

    r249713 r249753  
    20022002inspector/canvas/requestContent-webgl2.html [ Skip ]
    20032003inspector/canvas/requestShaderSource.html [ Skip ]
    2004 inspector/canvas/resolveCanvasContext-webgl.html [ Skip ]
    2005 inspector/canvas/resolveCanvasContext-webgl2.html [ Skip ]
     2004inspector/canvas/resolveContext-webgl.html [ Skip ]
     2005inspector/canvas/resolveContext-webgl2.html [ Skip ]
    20062006inspector/canvas/shaderProgram-add-remove-webgl.html [ Skip ]
    20072007inspector/canvas/shaderProgram-add-remove-webgl2.html [ Skip ]
     
    42454245webgpu [ Skip ]
    42464246inspector/canvas/create-context-webgpu.html [ Skip ]
    4247 inspector/canvas/resolveCanvasContext-webgpu.html [ Skip ]
     4247inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
     4248inspector/canvas/resolveContext-webgpu.html [ Skip ]
    42484249
    42494250webkit.org/b/191194 fast/block/basic/inline-content-with-floating-image.html [ Failure ]
  • trunk/LayoutTests/platform/wincairo/TestExpectations

    r248268 r249753  
    290290inspector/canvas/recording-webgl2.html [ Skip ]
    291291inspector/canvas/recording-webgl2-snapshots.html [ Skip ]
    292 inspector/canvas/resolveCanvasContext-webgl2.html [ Skip ]
     292inspector/canvas/resolveContext-webgl2.html [ Skip ]
    293293inspector/canvas/shaderProgram-add-remove-webgl2.html [ Skip ]
    294294webgl/webgl2-rendering-context-defined.html [ Skip ]
     
    298298webgpu [ Skip ]
    299299inspector/canvas/create-context-webgpu.html [ Skip ]
    300 inspector/canvas/resolveCanvasContext-webgpu.html [ Skip ]
     300inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
     301inspector/canvas/resolveContext-webgpu.html [ Skip ]
    301302
    302303# WIRELESS_PLAYBACK_TARGET is disabled
  • trunk/LayoutTests/platform/wpe/TestExpectations

    r249416 r249753  
    303303webgpu [ Skip ]
    304304inspector/canvas/create-context-webgpu.html [ Skip ]
    305 inspector/canvas/resolveCanvasContext-webgpu.html [ Skip ]
     305inspector/canvas/requestClientNodes-webgpu.html [ Skip ]
     306inspector/canvas/resolveContext-webgpu.html [ Skip ]
    306307
    307308# Skipped due to untestable DRM key system. ClearKey counterparts are tested instead.
  • trunk/Source/JavaScriptCore/ChangeLog

    r249747 r249753  
     12019-09-10  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Canvas: instrument WebGPUDevice instead of GPUCanvasContext
     4        https://bugs.webkit.org/show_bug.cgi?id=201650
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        Most of the actual "work" done with Web GPU actually uses a `WebGPUDevice`.
     9
     10        A `GPUCanvasContext` is basically just a display "client" of the device, and isn't even
     11        required (e.g. compute pipeline).  We should treat the `GPUCanvasContext` almost like a
     12        `-webkit-canvas` client of a `WebGPUDevice`.
     13
     14        * inspector/protocol/Canvas.json:
     15         - Add `powerPreference` key to `ContextAttributes` type.
     16         - Rename `requestCSSCanvasClientNodes` command to `requestClientNodes` for the above reason.
     17         - Rename `cssCanvasClientNodesChanged` event to `clientNodesChanged` for the above reason.
     18         - Rename `resolveCanvasContext` command to `resolveContext` since a `WebGPUDevice` isn't
     19           really a "canvas".
     20
    1212019-09-10  Yusuke Suzuki  <ysuzuki@apple.com>
    222
  • trunk/Source/JavaScriptCore/inspector/protocol/Canvas.json

    r243666 r249753  
    3131            "description": "Drawing surface attributes.",
    3232            "properties": [
    33                 { "name": "alpha", "type": "boolean", "optional": true },
    34                 { "name": "depth", "type": "boolean", "optional": true },
    35                 { "name": "stencil", "type": "boolean", "optional": true },
    36                 { "name": "antialias", "type": "boolean", "optional": true },
    37                 { "name": "premultipliedAlpha", "type": "boolean", "optional": true },
    38                 { "name": "preserveDrawingBuffer", "type": "boolean", "optional": true },
    39                 { "name": "failIfMajorPerformanceCaveat", "type": "boolean", "optional": true }
     33                { "name": "alpha", "type": "boolean", "optional": true, "description": "WebGL, WebGL2, ImageBitmapRenderingContext" },
     34                { "name": "depth", "type": "boolean", "optional": true, "description": "WebGL, WebGL2" },
     35                { "name": "stencil", "type": "boolean", "optional": true, "description": "WebGL, WebGL2" },
     36                { "name": "antialias", "type": "boolean", "optional": true, "description": "WebGL, WebGL2" },
     37                { "name": "premultipliedAlpha", "type": "boolean", "optional": true, "description": "WebGL, WebGL2" },
     38                { "name": "preserveDrawingBuffer", "type": "boolean", "optional": true, "description": "WebGL, WebGL2" },
     39                { "name": "failIfMajorPerformanceCaveat", "type": "boolean", "optional": true, "description": "WebGL, WebGL2" },
     40                { "name": "powerPreference", "type": "string", "optional": true, "description": "WebGL, WebGL2, WebGPU" }
    4041            ]
    4142        },
     
    8586        },
    8687        {
    87             "name": "requestCSSCanvasClientNodes",
    88             "description": "Gets all the nodes that are using this canvas via -webkit-canvas.",
     88            "name": "requestClientNodes",
     89            "description": "Gets all <code>-webkit-canvas</code> nodes or active <code>HTMLCanvasElement</code> for a <code>WebGPUDevice</code>.",
    8990            "parameters": [
    9091                { "name": "canvasId", "$ref": "CanvasId" }
     
    9596        },
    9697        {
    97             "name": "resolveCanvasContext",
    98             "description": "Resolves JavaScript canvas context object for given canvasId.",
     98            "name": "resolveContext",
     99            "description": "Resolves JavaScript canvas/device context object for given canvasId.",
    99100            "parameters": [
    100101                { "name": "canvasId", "$ref": "CanvasId", "description": "Canvas identifier." },
     
    193194        },
    194195        {
    195             "name": "cssCanvasClientNodesChanged",
     196            "name": "clientNodesChanged",
    196197            "parameters": [
    197198                { "name": "canvasId", "$ref": "CanvasId", "description": "Identifier of canvas that changed." }
  • trunk/Source/WebCore/ChangeLog

    r249748 r249753  
     12019-09-10  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Canvas: instrument WebGPUDevice instead of GPUCanvasContext
     4        https://bugs.webkit.org/show_bug.cgi?id=201650
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        Most of the actual "work" done with Web GPU actually uses a `WebGPUDevice`.
     9
     10        A `GPUCanvasContext` is basically just a display "client" of the device, and isn't even
     11        required (e.g. compute pipeline).  We should treat the `GPUCanvasContext` almost like a
     12        `-webkit-canvas` client of a `WebGPUDevice`.
     13
     14        Tests: inspector/canvas/create-context-webgpu.html
     15               inspector/canvas/requestClientNodes-webgpu.html
     16               inspector/canvas/resolveContext-webgpu.html
     17
     18        * Modules/webgpu/WebGPUAdapter.cpp:
     19        (WebCore::WebGPUAdapter::requestDevice const):
     20        Notify web inspector after a device is created.
     21
     22        * Modules/webgpu/WebGPUDevice.idl:
     23        * Modules/webgpu/WebGPUDevice.h:
     24        * Modules/webgpu/WebGPUDevice.cpp:
     25        (WebCore::WebGPUDevice::instances): Added.
     26        (WebCore::WebGPUDevice::instancesMutex): Added.
     27        (WebCore::WebGPUDevice::~WebGPUDevice): Added.
     28        Notify web inspector when the device is about to be destructed.
     29
     30        * Modules/webgpu/GPUCanvasContext.h:
     31        * Modules/webgpu/GPUCanvasContext.cpp:
     32        (WebCore::GPUCanvasContext::create):
     33        (WebCore::GPUCanvasContext::configureSwapChain):
     34
     35        * inspector/InspectorCanvas.h:
     36        * inspector/InspectorCanvas.cpp:
     37        (WebCore::canvasIfContextMatchesDevice): Added.
     38        (WebCore::InspectorCanvas::create):
     39        (WebCore::InspectorCanvas::InspectorCanvas):
     40        (WebCore::InspectorCanvas::canvasContext const): Added.
     41        (WebCore::InspectorCanvas::canvasElement const): Added.
     42        (WebCore::InspectorCanvas::isDeviceForCanvasContext const): Added.
     43        (WebCore::InspectorCanvas::deviceContext const): Added.
     44        (WebCore::InspectorCanvas::scriptExecutionContext const): Added.
     45        (WebCore::InspectorCanvas::resolveContext const): Added.
     46        (WebCore::InspectorCanvas::clientNodes const): Added.
     47        (WebCore::InspectorCanvas::canvasChanged):
     48        (WebCore::InspectorCanvas::resetRecordingData):
     49        (WebCore::InspectorCanvas::recordAction):
     50        (WebCore::InspectorCanvas::buildObjectForCanvas):
     51        (WebCore::InspectorCanvas::releaseObjectForRecording):
     52        (WebCore::InspectorCanvas::getCanvasContentAsDataURL):
     53        (WebCore::InspectorCanvas::buildInitialState):
     54        (WebCore::InspectorCanvas::canvasElement): Deleted.
     55        * inspector/InspectorInstrumentation.cpp:
     56        (WebCore::InspectorInstrumentation::didCreateWebGPUDeviceImpl): Added.
     57        (WebCore::InspectorInstrumentation::willDestroyWebGPUDeviceImpl): Added.
     58        (WebCore::InspectorInstrumentation::willConfigureSwapChainImpl): Added.
     59        * inspector/InspectorInstrumentation.h:
     60        (WebCore::InspectorInstrumentation::didCreateWebGPUDevice): Added.
     61        (WebCore::InspectorInstrumentation::willDestroyWebGPUDevice): Added.
     62        (WebCore::InspectorInstrumentation::willConfigureSwapChain): Added.
     63
     64        * inspector/agents/InspectorCanvasAgent.h:
     65        * inspector/agents/InspectorCanvasAgent.cpp:
     66        (WebCore::InspectorCanvasAgent::enable):
     67        (WebCore::InspectorCanvasAgent::requestClientNodes): Added.
     68        (WebCore::InspectorCanvasAgent::resolveContext): Added.
     69        (WebCore::InspectorCanvasAgent::startRecording):
     70        (WebCore::InspectorCanvasAgent::stopRecording):
     71        (WebCore::InspectorCanvasAgent::frameNavigated):
     72        (WebCore::InspectorCanvasAgent::didChangeCSSCanvasClientNodes):
     73        (WebCore::InspectorCanvasAgent::didChangeCanvasMemory):
     74        (WebCore::InspectorCanvasAgent::canvasDestroyed):
     75        (WebCore::InspectorCanvasAgent::recordCanvasAction):
     76        (WebCore::InspectorCanvasAgent::didFinishRecordingCanvasFrame):
     77        (WebCore::InspectorCanvasAgent::didCreateWebGPUDevice): Added.
     78        (WebCore::InspectorCanvasAgent::willDestroyWebGPUDevice): Added.
     79        (WebCore::InspectorCanvasAgent::willConfigureSwapChain): Added.
     80        (WebCore::InspectorCanvasAgent::clearCanvasData):
     81        (WebCore::InspectorCanvasAgent::bindCanvas):
     82        (WebCore::InspectorCanvasAgent::unbindCanvas):
     83        (WebCore::InspectorCanvasAgent::findInspectorCanvas):
     84        (WebCore::InspectorCanvasAgent::requestCSSCanvasClientNodes): Deleted.
     85        (WebCore::contextAsScriptValue): Deleted.
     86        (WebCore::InspectorCanvasAgent::resolveCanvasContext): Deleted.
     87
     88        * inspector/InspectorShaderProgram.cpp:
     89        (WebCore::InspectorShaderProgram::context const):
     90
    1912019-09-10  Chris Dumez  <cdumez@apple.com>
    292
  • trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.cpp

    r248879 r249753  
    4242    auto context = std::unique_ptr<GPUCanvasContext>(new GPUCanvasContext(canvas));
    4343    context->suspendIfNeeded();
    44 
    45     InspectorInstrumentation::didCreateCanvasRenderingContext(*context);
    46 
    4744    return context;
    4845}
     
    6865        if (m_swapChain)
    6966            m_swapChain->destroy();
    70        
     67
     68        InspectorInstrumentation::willConfigureSwapChain(*this, newSwapChain.get());
     69
    7170        m_swapChain = newSwapChain.copyRef();
     71
    7272        notifyCanvasContentChanged();
    7373    }
  • trunk/Source/WebCore/Modules/webgpu/GPUCanvasContext.h

    r244507 r249753  
    4444    HTMLCanvasElement& canvas() const { return downcast<HTMLCanvasElement>(canvasBase()); }
    4545
     46    WebGPUSwapChain* swapChain() const { return m_swapChain.get(); }
    4647    Ref<WebGPUSwapChain> configureSwapChain(const WebGPUSwapChainDescriptor&);
    4748
  • trunk/Source/WebCore/Modules/webgpu/WebGPUAdapter.cpp

    r249539 r249753  
    3030
    3131#include "Document.h"
     32#include "InspectorInstrumentation.h"
    3233#include "JSWebGPUDevice.h"
    3334
     
    4748{
    4849    document.postTask([protectedThis = makeRef(*this), promise = WTFMove(promise)] (ScriptExecutionContext& context) mutable {
    49         if (auto device = WebGPUDevice::tryCreate(context, protectedThis.get()))
     50        if (auto device = WebGPUDevice::tryCreate(context, protectedThis.get())) {
     51            InspectorInstrumentation::didCreateWebGPUDevice(*device);
     52
    5053            promise.resolve(device.releaseNonNull());
    51         else
     54        } else
    5255            promise.reject();
    5356    });
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp

    r249601 r249753  
    4848#include "GPUTextureDescriptor.h"
    4949#include "GPUUncapturedErrorEvent.h"
     50#include "InspectorInstrumentation.h"
    5051#include "JSDOMConvertBufferSource.h"
    5152#include "JSGPUOutOfMemoryError.h"
     
    7475#include <JavaScriptCore/ConsoleMessage.h>
    7576#include <memory>
     77#include <wtf/HashSet.h>
    7678#include <wtf/IsoMallocInlines.h>
     79#include <wtf/Lock.h>
    7780#include <wtf/MainThread.h>
     81#include <wtf/NeverDestroyed.h>
    7882#include <wtf/Optional.h>
     83#include <wtf/Ref.h>
     84#include <wtf/RefPtr.h>
    7985#include <wtf/Variant.h>
     86#include <wtf/Vector.h>
    8087#include <wtf/text/WTFString.h>
    8188
     
    8996        return adoptRef(new WebGPUDevice(context, WTFMove(adapter), device.releaseNonNull()));
    9097    return nullptr;
     98}
     99
     100HashSet<WebGPUDevice*>& WebGPUDevice::instances(const LockHolder&)
     101{
     102    static NeverDestroyed<HashSet<WebGPUDevice*>> instances;
     103    return instances;
     104}
     105
     106Lock& WebGPUDevice::instancesMutex()
     107{
     108    static LazyNeverDestroyed<Lock> mutex;
     109    static std::once_flag initializeMutex;
     110    std::call_once(initializeMutex, [] {
     111        mutex.construct();
     112    });
     113    return mutex.get();
    91114}
    92115
     
    101124{
    102125    ASSERT(m_scriptExecutionContext.isDocument());
     126
     127    LockHolder lock(instancesMutex());
     128    instances(lock).add(this);
     129}
     130
     131WebGPUDevice::~WebGPUDevice()
     132{
     133    InspectorInstrumentation::willDestroyWebGPUDevice(*this);
     134
     135    LockHolder lock(instancesMutex());
     136    ASSERT(instances(lock).contains(this));
     137    instances(lock).remove(this);
    103138}
    104139
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h

    r249539 r249753  
    3535#include "WebGPUQueue.h"
    3636#include "WebGPUSwapChainDescriptor.h"
    37 #include <wtf/Ref.h>
     37#include <wtf/Forward.h>
    3838#include <wtf/RefCounted.h>
    39 #include <wtf/RefPtr.h>
    40 #include <wtf/Vector.h>
    4139#include <wtf/WeakPtr.h>
    4240
     
    8179    WTF_MAKE_ISO_ALLOCATED(WebGPUDevice);
    8280public:
     81    virtual ~WebGPUDevice();
     82
    8383    static RefPtr<WebGPUDevice> tryCreate(ScriptExecutionContext&, Ref<const WebGPUAdapter>&&);
     84
     85    static HashSet<WebGPUDevice*>& instances(const LockHolder&);
     86    static Lock& instancesMutex();
    8487
    8588    const WebGPUAdapter& adapter() const { return m_adapter.get(); }
     
    107110    void popErrorScope(ErrorPromise&&);
    108111
     112    ScriptExecutionContext* scriptExecutionContext() const final { return &m_scriptExecutionContext; }
     113
    109114    using RefCounted::ref;
    110115    using RefCounted::deref;
     
    115120    // EventTarget
    116121    EventTargetInterface eventTargetInterface() const final { return WebGPUDeviceEventTargetInterfaceType; }
    117     ScriptExecutionContext* scriptExecutionContext() const final { return &m_scriptExecutionContext; }
    118122    void refEventTarget() final { ref(); }
    119123    void derefEventTarget() final { deref(); }
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl

    r249539 r249753  
    3030    Conditional=WEBGPU,
    3131    EnabledAtRuntime=WebGPU,
    32     InterfaceName=GPUDevice
     32    InterfaceName=GPUDevice,
     33    JSGenerateToJSObject,
    3334] interface WebGPUDevice : EventTarget {
    3435    readonly attribute WebGPUAdapter adapter;
  • trunk/Source/WebCore/inspector/InspectorCanvas.cpp

    r247278 r249753  
    3434#include "CanvasRenderingContext2D.h"
    3535#include "Document.h"
     36#include "Element.h"
    3637#include "FloatPoint.h"
    3738#include "Gradient.h"
     
    4950#include "JSCanvasLineCap.h"
    5051#include "JSCanvasLineJoin.h"
     52#include "JSCanvasRenderingContext2D.h"
    5153#include "JSCanvasTextAlign.h"
    5254#include "JSCanvasTextBaseline.h"
    5355#include "JSExecState.h"
     56#include "JSImageBitmapRenderingContext.h"
    5457#include "JSImageSmoothingQuality.h"
    5558#include "Path2D.h"
     
    5861#include "SVGPathUtilities.h"
    5962#include "StringAdaptors.h"
    60 #if ENABLE(CSS_TYPED_OM)
    61 #include "TypedOMCSSImageValue.h"
    62 #endif
    63 #if ENABLE(WEBGL)
    64 #include "WebGLRenderingContext.h"
    65 #endif
    66 #if ENABLE(WEBGL2)
    67 #include "WebGL2RenderingContext.h"
    68 #endif
    69 #if ENABLE(WEBGPU)
    70 #include "GPUCanvasContext.h"
    71 #endif
    7263#include <JavaScriptCore/IdentifiersFactory.h>
    7364#include <JavaScriptCore/ScriptCallStackFactory.h>
    7465#include <wtf/Function.h>
    7566
     67#if ENABLE(CSS_TYPED_OM)
     68#include "TypedOMCSSImageValue.h"
     69#endif
     70
     71#if ENABLE(WEBGL)
     72#include "JSWebGLRenderingContext.h"
     73#include "WebGLRenderingContext.h"
     74#endif
     75
     76#if ENABLE(WEBGL2)
     77#include "JSWebGL2RenderingContext.h"
     78#include "WebGL2RenderingContext.h"
     79#endif
     80
     81#if ENABLE(WEBGPU)
     82#include "GPUCanvasContext.h"
     83#include "JSWebGPUDevice.h"
     84#include "WebGPUDevice.h"
     85#endif
     86
    7687namespace WebCore {
    7788
    7889using namespace Inspector;
    7990
     91#if ENABLE(WEBGPU)
     92static HTMLCanvasElement* canvasIfContextMatchesDevice(CanvasRenderingContext& context, WebGPUDevice& device)
     93{
     94    if (is<GPUCanvasContext>(context)) {
     95        auto& contextGPU = downcast<GPUCanvasContext>(context);
     96        if (auto* webGPUSwapChain = contextGPU.swapChain()) {
     97            if (auto* gpuSwapChain = webGPUSwapChain->swapChain()) {
     98                if (gpuSwapChain == device.device().swapChain()) {
     99                    if (is<HTMLCanvasElement>(contextGPU.canvasBase()))
     100                        return &downcast<HTMLCanvasElement>(contextGPU.canvasBase());
     101                }
     102            }
     103        }
     104    }
     105    return nullptr;
     106}
     107#endif
     108
    80109Ref<InspectorCanvas> InspectorCanvas::create(CanvasRenderingContext& context)
    81110{
    82111    return adoptRef(*new InspectorCanvas(context));
    83112}
     113
     114#if ENABLE(WEBGPU)
     115Ref<InspectorCanvas> InspectorCanvas::create(WebGPUDevice& device)
     116{
     117    return adoptRef(*new InspectorCanvas(device));
     118}
     119#endif
    84120
    85121InspectorCanvas::InspectorCanvas(CanvasRenderingContext& context)
     
    87123    , m_context(context)
    88124{
    89 }
    90 
    91 HTMLCanvasElement* InspectorCanvas::canvasElement()
    92 {
    93     if (is<HTMLCanvasElement>(m_context.canvasBase()))
    94         return &downcast<HTMLCanvasElement>(m_context.canvasBase());
     125#if ENABLE(WEBGPU)
     126    // The actual "context" for WebGPU is the `WebGPUDevice`, not the <canvas>.
     127    ASSERT(!is<GPUCanvasContext>(context));
     128#endif
     129}
     130
     131#if ENABLE(WEBGPU)
     132InspectorCanvas::InspectorCanvas(WebGPUDevice& device)
     133    : m_identifier("canvas:" + IdentifiersFactory::createIdentifier())
     134    , m_context(device)
     135{
     136}
     137#endif
     138
     139CanvasRenderingContext* InspectorCanvas::canvasContext() const
     140{
     141    if (auto* contextWrapper = WTF::get_if<std::reference_wrapper<CanvasRenderingContext>>(m_context))
     142        return &contextWrapper->get();
    95143    return nullptr;
    96144}
    97145
     146HTMLCanvasElement* InspectorCanvas::canvasElement() const
     147{
     148    return WTF::switchOn(m_context,
     149        [] (std::reference_wrapper<CanvasRenderingContext> contextWrapper) -> HTMLCanvasElement* {
     150            auto& context = contextWrapper.get();
     151            if (is<HTMLCanvasElement>(context.canvasBase()))
     152                return &downcast<HTMLCanvasElement>(context.canvasBase());
     153            return nullptr;
     154        },
     155#if ENABLE(WEBGPU)
     156        [&] (std::reference_wrapper<WebGPUDevice> deviceWrapper) -> HTMLCanvasElement* {
     157            auto& device = deviceWrapper.get();
     158            {
     159                LockHolder lock(CanvasRenderingContext::instancesMutex());
     160                for (auto* canvasRenderingContext : CanvasRenderingContext::instances(lock)) {
     161                    if (auto* canvasElement = canvasIfContextMatchesDevice(*canvasRenderingContext, device))
     162                        return canvasElement;
     163                }
     164            }
     165            return nullptr;
     166        },
     167#endif
     168        [] (Monostate) {
     169            ASSERT_NOT_REACHED();
     170            return nullptr;
     171        }
     172    );
     173    return nullptr;
     174}
     175
     176#if ENABLE(WEBGPU)
     177WebGPUDevice* InspectorCanvas::deviceContext() const
     178{
     179    if (auto* deviceWrapper = WTF::get_if<std::reference_wrapper<WebGPUDevice>>(m_context))
     180        return &deviceWrapper->get();
     181    return nullptr;
     182}
     183
     184bool InspectorCanvas::isDeviceForCanvasContext(CanvasRenderingContext& context) const
     185{
     186    if (auto* device = deviceContext())
     187        return canvasIfContextMatchesDevice(context, *device);
     188    return false;
     189}
     190#endif
     191
     192ScriptExecutionContext* InspectorCanvas::scriptExecutionContext() const
     193{
     194    return WTF::switchOn(m_context,
     195        [] (std::reference_wrapper<CanvasRenderingContext> contextWrapper) {
     196            auto& context = contextWrapper.get();
     197            return context.canvasBase().scriptExecutionContext();
     198        },
     199#if ENABLE(WEBGPU)
     200        [] (std::reference_wrapper<WebGPUDevice> deviceWrapper) {
     201            auto& device = deviceWrapper.get();
     202            return device.scriptExecutionContext();
     203        },
     204#endif
     205        [] (Monostate) {
     206            ASSERT_NOT_REACHED();
     207            return nullptr;
     208        }
     209    );
     210}
     211
     212JSC::JSValue InspectorCanvas::resolveContext(ExecState* exec) const
     213{
     214    JSC::JSLockHolder lock(exec);
     215
     216    auto* globalObject = deprecatedGlobalObjectForPrototype(exec);
     217
     218    return WTF::switchOn(m_context,
     219        [&] (std::reference_wrapper<CanvasRenderingContext> contextWrapper) {
     220            auto& context = contextWrapper.get();
     221            if (is<CanvasRenderingContext2D>(context))
     222                return toJS(exec, globalObject, downcast<CanvasRenderingContext2D>(context));
     223            if (is<ImageBitmapRenderingContext>(context))
     224                return toJS(exec, globalObject, downcast<ImageBitmapRenderingContext>(context));
     225#if ENABLE(WEBGL)
     226            if (is<WebGLRenderingContext>(context))
     227                return toJS(exec, globalObject, downcast<WebGLRenderingContext>(context));
     228#endif
     229#if ENABLE(WEBGL2)
     230            if (is<WebGL2RenderingContext>(context))
     231                return toJS(exec, globalObject, downcast<WebGL2RenderingContext>(context));
     232#endif
     233            return JSC::JSValue();
     234        },
     235#if ENABLE(WEBGPU)
     236        [&] (std::reference_wrapper<WebGPUDevice> deviceWrapper) {
     237            return toJS(exec, globalObject, deviceWrapper.get());
     238        },
     239#endif
     240        [] (Monostate) {
     241            ASSERT_NOT_REACHED();
     242            return JSC::JSValue();
     243        }
     244    );
     245}
     246
     247HashSet<Element*> InspectorCanvas::clientNodes() const
     248{
     249    return WTF::switchOn(m_context,
     250        [] (std::reference_wrapper<CanvasRenderingContext> contextWrapper) {
     251            auto& context = contextWrapper.get();
     252            return context.canvasBase().cssCanvasClients();
     253        },
     254#if ENABLE(WEBGPU)
     255        [&] (std::reference_wrapper<WebGPUDevice> deviceWrapper) {
     256            auto& device = deviceWrapper.get();
     257
     258            HashSet<Element*> canvasElementClients;
     259            {
     260                LockHolder lock(CanvasRenderingContext::instancesMutex());
     261                for (auto* canvasRenderingContext : CanvasRenderingContext::instances(lock)) {
     262                    if (auto* canvasElement = canvasIfContextMatchesDevice(*canvasRenderingContext, device))
     263                        canvasElementClients.add(canvasElement);
     264                }
     265            }
     266            return canvasElementClients;
     267        },
     268#endif
     269        [] (Monostate) {
     270            ASSERT_NOT_REACHED();
     271            return HashSet<Element*>();
     272        }
     273    );
     274}
     275
    98276void InspectorCanvas::canvasChanged()
    99277{
    100     if (!m_context.callTracingActive())
     278    auto* context = canvasContext();
     279    ASSERT(context);
     280
     281    if (!context->callTracingActive())
    101282        return;
    102283
    103284    // Since 2D contexts are able to be fully reproduced in the frontend, we don't need snapshots.
    104     if (is<CanvasRenderingContext2D>(m_context))
     285    if (is<CanvasRenderingContext2D>(context))
    105286        return;
    106287
     
    122303    m_contentChanged = false;
    123304
    124     m_context.setCallTracingActive(false);
     305    auto* context = canvasContext();
     306    ASSERT(context);
     307    // FIXME: <https://webkit.org/b/201651> Web Inspector: Canvas: support canvas recordings for WebGPUDevice
     308
     309    context->setCallTracingActive(false);
    125310}
    126311
     
    192377    m_currentActions->addItem(m_lastRecordedAction.get());
    193378
    194     if (is<ImageBitmapRenderingContext>(m_context) && shouldSnapshotBitmapRendererAction(name))
     379    auto* context = canvasContext();
     380    ASSERT(context);
     381    // FIXME: <https://webkit.org/b/201651> Web Inspector: Canvas: support canvas recordings for WebGPUDevice
     382
     383    if (is<ImageBitmapRenderingContext>(context) && shouldSnapshotBitmapRendererAction(name))
    195384        m_contentChanged = true;
    196385#if ENABLE(WEBGL)
    197     else if (is<WebGLRenderingContext>(m_context) && shouldSnapshotWebGLAction(name))
     386    else if (is<WebGLRenderingContext>(context) && shouldSnapshotWebGLAction(name))
    198387        m_contentChanged = true;
    199388#endif
    200389#if ENABLE(WEBGL2)
    201     else if (is<WebGL2RenderingContext>(m_context) && shouldSnapshotWebGL2Action(name))
     390    else if (is<WebGL2RenderingContext>(context) && shouldSnapshotWebGL2Action(name))
    202391        m_contentChanged = true;
    203392#endif
     
    251440Ref<Inspector::Protocol::Canvas::Canvas> InspectorCanvas::buildObjectForCanvas(bool captureBacktrace)
    252441{
    253     Inspector::Protocol::Canvas::ContextType contextType;
    254     if (is<CanvasRenderingContext2D>(m_context))
    255         contextType = Inspector::Protocol::Canvas::ContextType::Canvas2D;
    256     else if (is<ImageBitmapRenderingContext>(m_context))
    257         contextType = Inspector::Protocol::Canvas::ContextType::BitmapRenderer;
     442    using ContextTypeType = Optional<Inspector::Protocol::Canvas::ContextType>;
     443    auto contextType = WTF::switchOn(m_context,
     444        [] (std::reference_wrapper<CanvasRenderingContext> contextWrapper) -> ContextTypeType {
     445            auto& context = contextWrapper.get();
     446            if (is<CanvasRenderingContext2D>(context))
     447                return Inspector::Protocol::Canvas::ContextType::Canvas2D;
     448            if (is<ImageBitmapRenderingContext>(context))
     449                return Inspector::Protocol::Canvas::ContextType::BitmapRenderer;
    258450#if ENABLE(WEBGL)
    259     else if (is<WebGLRenderingContext>(m_context))
    260         contextType = Inspector::Protocol::Canvas::ContextType::WebGL;
     451            if (is<WebGLRenderingContext>(context))
     452                return Inspector::Protocol::Canvas::ContextType::WebGL;
    261453#endif
    262454#if ENABLE(WEBGL2)
    263     else if (is<WebGL2RenderingContext>(m_context))
    264         contextType = Inspector::Protocol::Canvas::ContextType::WebGL2;
    265 #endif
     455            if (is<WebGL2RenderingContext>(context))
     456                return Inspector::Protocol::Canvas::ContextType::WebGL2;
     457#endif
     458            return WTF::nullopt;
     459        },
    266460#if ENABLE(WEBGPU)
    267     else if (is<GPUCanvasContext>(m_context))
    268         contextType = Inspector::Protocol::Canvas::ContextType::WebGPU;
    269 #endif
    270     else {
     461        [] (std::reference_wrapper<WebGPUDevice>) {
     462            return Inspector::Protocol::Canvas::ContextType::WebGPU;
     463        },
     464#endif
     465        [] (Monostate) {
     466            ASSERT_NOT_REACHED();
     467            return WTF::nullopt;
     468        }
     469    );
     470    if (!contextType) {
    271471        ASSERT_NOT_REACHED();
    272472        contextType = Inspector::Protocol::Canvas::ContextType::Canvas2D;
     
    275475    auto canvas = Inspector::Protocol::Canvas::Canvas::create()
    276476        .setCanvasId(m_identifier)
    277         .setContextType(contextType)
     477        .setContextType(contextType.value())
    278478        .release();
    279479
     
    286486    }
    287487
    288     if (is<ImageBitmapRenderingContext>(m_context)) {
    289         auto contextAttributes = Inspector::Protocol::Canvas::ContextAttributes::create()
    290             .release();
    291         contextAttributes->setAlpha(downcast<ImageBitmapRenderingContext>(m_context).hasAlpha());
     488    using ContextAttributesType = RefPtr<Inspector::Protocol::Canvas::ContextAttributes>;
     489    auto contextAttributes = WTF::switchOn(m_context,
     490        [] (std::reference_wrapper<CanvasRenderingContext> contextWrapper) -> ContextAttributesType {
     491            auto& context = contextWrapper.get();
     492            if (is<ImageBitmapRenderingContext>(context)) {
     493                auto contextAttributesPayload = Inspector::Protocol::Canvas::ContextAttributes::create()
     494                    .release();
     495                contextAttributesPayload->setAlpha(downcast<ImageBitmapRenderingContext>(context).hasAlpha());
     496                return WTFMove(contextAttributesPayload);
     497            }
     498
     499#if ENABLE(WEBGL)
     500            if (is<WebGLRenderingContextBase>(context)) {
     501                if (const auto& attributes = downcast<WebGLRenderingContextBase>(context).getContextAttributes()) {
     502                    auto contextAttributesPayload = Inspector::Protocol::Canvas::ContextAttributes::create()
     503                        .release();
     504                    contextAttributesPayload->setAlpha(attributes->alpha);
     505                    contextAttributesPayload->setDepth(attributes->depth);
     506                    contextAttributesPayload->setStencil(attributes->stencil);
     507                    contextAttributesPayload->setAntialias(attributes->antialias);
     508                    contextAttributesPayload->setPremultipliedAlpha(attributes->premultipliedAlpha);
     509                    contextAttributesPayload->setPreserveDrawingBuffer(attributes->preserveDrawingBuffer);
     510                    switch (attributes->powerPreference) {
     511                    case WebGLPowerPreference::Default:
     512                        contextAttributesPayload->setPowerPreference("default");
     513                        break;
     514                    case WebGLPowerPreference::LowPower:
     515                        contextAttributesPayload->setPowerPreference("low-power");
     516                        break;
     517                    case WebGLPowerPreference::HighPerformance:
     518                        contextAttributesPayload->setPowerPreference("high-performance");
     519                        break;
     520                    }
     521                    contextAttributesPayload->setFailIfMajorPerformanceCaveat(attributes->failIfMajorPerformanceCaveat);
     522                    return WTFMove(contextAttributesPayload);
     523                }
     524            }
     525#endif
     526            return nullptr;
     527        },
     528#if ENABLE(WEBGPU)
     529        [] (std::reference_wrapper<WebGPUDevice> deviceWrapper) -> ContextAttributesType {
     530            auto& device = deviceWrapper.get();
     531            if (const auto& options = device.adapter().options()) {
     532                auto contextAttributesPayload = Inspector::Protocol::Canvas::ContextAttributes::create()
     533                    .release();
     534                if (const auto& powerPreference = options->powerPreference) {
     535                    switch (powerPreference.value()) {
     536                    case GPUPowerPreference::LowPower:
     537                        contextAttributesPayload->setPowerPreference("low-power");
     538                        break;
     539
     540                    case GPUPowerPreference::HighPerformance:
     541                        contextAttributesPayload->setPowerPreference("high-performance");
     542                        break;
     543                    }
     544                }
     545                return WTFMove(contextAttributesPayload);
     546            }
     547            return nullptr;
     548        },
     549#endif
     550        [] (Monostate) {
     551            ASSERT_NOT_REACHED();
     552            return nullptr;
     553        }
     554    );
     555    if (contextAttributes)
    292556        canvas->setContextAttributes(WTFMove(contextAttributes));
    293     }
    294 #if ENABLE(WEBGL)
    295     else if (is<WebGLRenderingContextBase>(m_context)) {
    296         if (Optional<WebGLContextAttributes> attributes = downcast<WebGLRenderingContextBase>(m_context).getContextAttributes()) {
    297             auto contextAttributes = Inspector::Protocol::Canvas::ContextAttributes::create()
    298                 .release();
    299             contextAttributes->setAlpha(attributes->alpha);
    300             contextAttributes->setDepth(attributes->depth);
    301             contextAttributes->setStencil(attributes->stencil);
    302             contextAttributes->setAntialias(attributes->antialias);
    303             contextAttributes->setPremultipliedAlpha(attributes->premultipliedAlpha);
    304             contextAttributes->setPreserveDrawingBuffer(attributes->preserveDrawingBuffer);
    305             contextAttributes->setFailIfMajorPerformanceCaveat(attributes->failIfMajorPerformanceCaveat);
    306             canvas->setContextAttributes(WTFMove(contextAttributes));
    307         }
    308     }
    309 #endif
    310557
    311558    // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
     
    330577    ASSERT(!m_frames);
    331578
     579    auto* context = canvasContext();
     580    ASSERT(context);
     581    // FIXME: <https://webkit.org/b/201651> Web Inspector: Canvas: support canvas recordings for WebGPUDevice
     582
    332583    Inspector::Protocol::Recording::Type type;
    333     if (is<CanvasRenderingContext2D>(m_context))
     584    if (is<CanvasRenderingContext2D>(context))
    334585        type = Inspector::Protocol::Recording::Type::Canvas2D;
    335     else if (is<ImageBitmapRenderingContext>(m_context))
     586    else if (is<ImageBitmapRenderingContext>(context))
    336587        type = Inspector::Protocol::Recording::Type::CanvasBitmapRenderer;
    337588#if ENABLE(WEBGL)
    338     else if (is<WebGLRenderingContext>(m_context))
     589    else if (is<WebGLRenderingContext>(context))
    339590        type = Inspector::Protocol::Recording::Type::CanvasWebGL;
    340591#endif
    341592#if ENABLE(WEBGL2)
    342     else if (is<WebGL2RenderingContext>(m_context))
     593    else if (is<WebGL2RenderingContext>(context))
    343594        type = Inspector::Protocol::Recording::Type::CanvasWebGL2;
    344595#endif
     
    365616String InspectorCanvas::getCanvasContentAsDataURL(ErrorString& errorString)
    366617{
    367     // FIXME: <https://webkit.org/b/173621> Web Inspector: Support getting the content of WebMetal context;
    368     if (!is<CanvasRenderingContext2D>(m_context)
    369 #if ENABLE(WEBGL)
    370         && !is<WebGLRenderingContextBase>(m_context)
    371 #endif
    372         && !is<ImageBitmapRenderingContext>(m_context)) {
    373         errorString = "Unsupported canvas context type"_s;
    374         return emptyString();
    375     }
    376 
    377     // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
    378618    auto* node = canvasElement();
    379619    if (!node) {
    380         errorString = "Context isn't related to an HTMLCanvasElement"_s;
     620        errorString = "Missing HTMLCanvasElement of canvas for given canvasId"_s;
    381621        return emptyString();
    382622    }
    383623
    384624#if ENABLE(WEBGL)
    385     if (is<WebGLRenderingContextBase>(m_context))
    386         downcast<WebGLRenderingContextBase>(m_context).setPreventBufferClearForInspector(true);
     625    auto* context = node->renderingContext();
     626    if (is<WebGLRenderingContextBase>(context))
     627        downcast<WebGLRenderingContextBase>(*context).setPreventBufferClearForInspector(true);
    387628#endif
    388629
     
    390631
    391632#if ENABLE(WEBGL)
    392     if (is<WebGLRenderingContextBase>(m_context))
    393         downcast<WebGLRenderingContextBase>(m_context).setPreventBufferClearForInspector(false);
     633    if (is<WebGLRenderingContextBase>(context))
     634        downcast<WebGLRenderingContextBase>(*context).setPreventBufferClearForInspector(false);
    394635#endif
    395636
     
    559800Ref<Inspector::Protocol::Recording::InitialState> InspectorCanvas::buildInitialState()
    560801{
     802    auto* context = canvasContext();
     803    ASSERT(context);
     804    // FIXME: <https://webkit.org/b/201651> Web Inspector: Canvas: support canvas recordings for WebGPUDevice
     805
    561806    auto initialStatePayload = Inspector::Protocol::Recording::InitialState::create().release();
    562807
    563808    auto attributesPayload = JSON::Object::create();
    564     attributesPayload->setInteger("width"_s, m_context.canvasBase().width());
    565     attributesPayload->setInteger("height"_s, m_context.canvasBase().height());
     809    attributesPayload->setInteger("width"_s, context->canvasBase().width());
     810    attributesPayload->setInteger("height"_s, context->canvasBase().height());
    566811
    567812    auto statesPayload = JSON::ArrayOf<JSON::Object>::create();
     
    569814    auto parametersPayload = JSON::ArrayOf<JSON::Value>::create();
    570815
    571     if (is<CanvasRenderingContext2D>(m_context)) {
    572         auto& context2d = downcast<CanvasRenderingContext2D>(m_context);
     816    if (is<CanvasRenderingContext2D>(context)) {
     817        auto& context2d = downcast<CanvasRenderingContext2D>(*context);
    573818        for (auto& state : context2d.stateStack()) {
    574819            auto statePayload = JSON::Object::create();
     
    627872    }
    628873#if ENABLE(WEBGL)
    629     else if (is<WebGLRenderingContextBase>(m_context)) {
    630         WebGLRenderingContextBase& contextWebGLBase = downcast<WebGLRenderingContextBase>(m_context);
     874    else if (is<WebGLRenderingContextBase>(context)) {
     875        auto& contextWebGLBase = downcast<WebGLRenderingContextBase>(*context);
    631876        if (Optional<WebGLContextAttributes> webGLContextAttributes = contextWebGLBase.getContextAttributes()) {
    632877            auto webGLContextAttributesPayload = JSON::Object::create();
  • trunk/Source/WebCore/inspector/InspectorCanvas.h

    r247278 r249753  
    2727
    2828#include "CallTracerTypes.h"
     29#include "CanvasRenderingContext.h"
    2930#include <JavaScriptCore/InspectorProtocolObjects.h>
     31#include <JavaScriptCore/JSCInlines.h>
    3032#include <JavaScriptCore/ScriptCallFrame.h>
    3133#include <JavaScriptCore/ScriptCallStack.h>
    3234#include <initializer_list>
     35#include <wtf/HashSet.h>
    3336#include <wtf/Variant.h>
    3437#include <wtf/Vector.h>
    3538#include <wtf/text/WTFString.h>
     39
     40#if ENABLE(WEBGPU)
     41#include "WebGPUDevice.h"
     42#endif
    3643
    3744namespace WebCore {
     
    3946class CanvasGradient;
    4047class CanvasPattern;
    41 class CanvasRenderingContext;
     48class Element;
    4249class HTMLCanvasElement;
    4350class HTMLImageElement;
     
    5461public:
    5562    static Ref<InspectorCanvas> create(CanvasRenderingContext&);
     63#if ENABLE(WEBGPU)
     64    static Ref<InspectorCanvas> create(WebGPUDevice&);
     65#endif
    5666
    57     const String& identifier() { return m_identifier; }
    58     CanvasRenderingContext& context() { return m_context; }
     67    const String& identifier() const { return m_identifier; }
    5968
    60     HTMLCanvasElement* canvasElement();
     69    CanvasRenderingContext* canvasContext() const;
     70    HTMLCanvasElement* canvasElement() const;
     71
     72#if ENABLE(WEBGPU)
     73    WebGPUDevice* deviceContext() const;
     74    bool isDeviceForCanvasContext(CanvasRenderingContext&) const;
     75#endif
     76
     77    ScriptExecutionContext* scriptExecutionContext() const;
     78
     79    JSC::JSValue resolveContext(JSC::ExecState*) const;
     80
     81    HashSet<Element*> clientNodes() const;
    6182
    6283    void canvasChanged();
     
    88109private:
    89110    InspectorCanvas(CanvasRenderingContext&);
     111#if ENABLE(WEBGPU)
     112    InspectorCanvas(WebGPUDevice&);
     113#endif
     114
    90115    void appendActionSnapshotIfNeeded();
    91116
     
    117142
    118143    String m_identifier;
    119     CanvasRenderingContext& m_context;
     144
     145    Variant<
     146        std::reference_wrapper<CanvasRenderingContext>,
     147#if ENABLE(WEBGPU)
     148        std::reference_wrapper<WebGPUDevice>,
     149#endif
     150        Monostate
     151    > m_context;
    120152
    121153    RefPtr<Inspector::Protocol::Recording::InitialState> m_initialState;
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r249714 r249753  
    7575#include <wtf/StdLibExtras.h>
    7676
     77#if ENABLE(WEBGPU)
     78#include "WebGPUSwapChain.h"
     79#endif
     80
    7781namespace WebCore {
    7882
     
    11031107#endif
    11041108
     1109#if ENABLE(WEBGPU)
     1110void InspectorInstrumentation::didCreateWebGPUDeviceImpl(InstrumentingAgents& instrumentingAgents, WebGPUDevice& device)
     1111{
     1112    if (auto* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
     1113        canvasAgent->didCreateWebGPUDevice(device);
     1114}
     1115
     1116void InspectorInstrumentation::willDestroyWebGPUDeviceImpl(InstrumentingAgents& instrumentingAgents, WebGPUDevice& device)
     1117{
     1118    if (auto* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
     1119        canvasAgent->willDestroyWebGPUDevice(device);
     1120}
     1121
     1122void InspectorInstrumentation::willConfigureSwapChainImpl(InstrumentingAgents& instrumentingAgents, GPUCanvasContext& contextGPU, WebGPUSwapChain& newSwapChain)
     1123{
     1124    if (auto* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
     1125        canvasAgent->willConfigureSwapChain(contextGPU, newSwapChain);
     1126}
     1127#endif
     1128
    11051129#if ENABLE(RESOURCE_USAGE)
    11061130void InspectorInstrumentation::didHandleMemoryPressureImpl(InstrumentingAgents& instrumentingAgents, Critical critical)
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r249504 r249753  
    6161#endif
    6262
     63#if ENABLE(WEBGPU)
     64#include "GPUCanvasContext.h"
     65#include "WebGPUDevice.h"
     66#endif
     67
    6368namespace Inspector {
    6469class ConsoleMessage;
     
    9398class SharedBuffer;
    9499class TimerBase;
     100class WebKitNamedFlow;
     101class WorkerInspectorProxy;
     102
    95103#if ENABLE(WEBGL)
    96104class WebGLProgram;
    97105#endif
    98 class WebKitNamedFlow;
    99 class WorkerInspectorProxy;
     106
     107#if ENABLE(WEBGPU)
     108class WebGPUSwapChain;
     109#endif
    100110
    101111enum class StorageType;
     
    285295    static bool isShaderProgramHighlighted(WebGLRenderingContextBase&, WebGLProgram&);
    286296#endif
     297#if ENABLE(WEBGPU)
     298    static void didCreateWebGPUDevice(WebGPUDevice&);
     299    static void willDestroyWebGPUDevice(WebGPUDevice&);
     300    static void willConfigureSwapChain(GPUCanvasContext&, WebGPUSwapChain&);
     301#endif
    287302
    288303    static void networkStateChanged(Page&);
     
    472487    static bool isShaderProgramHighlightedImpl(InstrumentingAgents&, WebGLProgram&);
    473488#endif
     489#if ENABLE(WEBGPU)
     490    static void didCreateWebGPUDeviceImpl(InstrumentingAgents&, WebGPUDevice&);
     491    static void willDestroyWebGPUDeviceImpl(InstrumentingAgents&, WebGPUDevice&);
     492    static void willConfigureSwapChainImpl(InstrumentingAgents&, GPUCanvasContext&, WebGPUSwapChain&);
     493#endif
    474494
    475495    static void layerTreeDidChangeImpl(InstrumentingAgents&);
     
    13961416#endif
    13971417
     1418#if ENABLE(WEBGPU)
     1419inline void InspectorInstrumentation::didCreateWebGPUDevice(WebGPUDevice& device)
     1420{
     1421    FAST_RETURN_IF_NO_FRONTENDS(void());
     1422    if (auto* instrumentingAgents = instrumentingAgentsForContext(device.scriptExecutionContext()))
     1423        didCreateWebGPUDeviceImpl(*instrumentingAgents, device);
     1424}
     1425
     1426inline void InspectorInstrumentation::willDestroyWebGPUDevice(WebGPUDevice& device)
     1427{
     1428    FAST_RETURN_IF_NO_FRONTENDS(void());
     1429    if (auto* instrumentingAgents = instrumentingAgentsForContext(device.scriptExecutionContext()))
     1430        willDestroyWebGPUDeviceImpl(*instrumentingAgents, device);
     1431}
     1432
     1433inline void InspectorInstrumentation::willConfigureSwapChain(GPUCanvasContext& contextGPU, WebGPUSwapChain& newSwapChain)
     1434{
     1435    FAST_RETURN_IF_NO_FRONTENDS(void());
     1436    if (auto* instrumentingAgents = instrumentingAgentsForContext(contextGPU.canvasBase().scriptExecutionContext()))
     1437        willConfigureSwapChainImpl(*instrumentingAgents, contextGPU, newSwapChain);
     1438}
     1439#endif
     1440
    13981441inline void InspectorInstrumentation::networkStateChanged(Page& page)
    13991442{
  • trunk/Source/WebCore/inspector/InspectorShaderProgram.cpp

    r228218 r249753  
    5656WebGLRenderingContextBase& InspectorShaderProgram::context() const
    5757{
    58     ASSERT(is<WebGLRenderingContextBase>(m_canvas.context()));
    59     return downcast<WebGLRenderingContextBase>(m_canvas.context());
     58    ASSERT(m_canvas.canvasContext());
     59    ASSERT(is<WebGLRenderingContextBase>(*m_canvas.canvasContext()));
     60    return downcast<WebGLRenderingContextBase>(*m_canvas.canvasContext());
    6061}
    6162
  • trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp

    r249175 r249753  
    3737#include "InspectorDOMAgent.h"
    3838#include "InstrumentingAgents.h"
    39 #include "JSCanvasRenderingContext2D.h"
    4039#include "JSExecState.h"
    41 #include "JSImageBitmapRenderingContext.h"
    4240#include "Microtasks.h"
    4341#include "OffscreenCanvas.h"
     
    5351
    5452#if ENABLE(WEBGL)
    55 #include "JSWebGLRenderingContext.h"
    5653#include "WebGLProgram.h"
     54#include "WebGLRenderingContext.h"
     55#include "WebGLRenderingContextBase.h"
    5756#include "WebGLShader.h"
    5857#endif
    5958
    6059#if ENABLE(WEBGL2)
    61 #include "JSWebGL2RenderingContext.h"
     60#include "WebGL2RenderingContext.h"
    6261#endif
    6362
    6463#if ENABLE(WEBGPU)
    65 #include "JSGPUCanvasContext.h"
     64#include "GPUCanvasContext.h"
     65#include "WebGPUDevice.h"
    6666#endif
    6767
     
    104104    m_instrumentingAgents.setInspectorCanvasAgent(this);
    105105
    106     const auto canvasExistsInCurrentPage = [&] (CanvasRenderingContext* canvasRenderingContext) {
    107         if (!canvasRenderingContext)
    108             return false;
    109 
    110         auto* scriptExecutionContext = canvasRenderingContext->canvasBase().scriptExecutionContext();
     106    const auto existsInCurrentPage = [&] (ScriptExecutionContext* scriptExecutionContext) {
    111107        if (!is<Document>(scriptExecutionContext))
    112108            return false;
     
    119115    {
    120116        LockHolder lock(CanvasRenderingContext::instancesMutex());
    121         for (auto* canvasRenderingContext : CanvasRenderingContext::instances(lock)) {
    122             if (canvasExistsInCurrentPage(canvasRenderingContext))
    123                 bindCanvas(*canvasRenderingContext, false);
     117        for (auto* context : CanvasRenderingContext::instances(lock)) {
     118#if ENABLE(WEBGPU)
     119            // The actual "context" for WebGPU is the `WebGPUDevice`, not the <canvas>.
     120            if (is<GPUCanvasContext>(context))
     121                continue;
     122#endif
     123
     124            if (existsInCurrentPage(context->canvasBase().scriptExecutionContext()))
     125                bindCanvas(*context, false);
    124126        }
    125127    }
     128
     129#if ENABLE(WEBGPU)
     130    {
     131        LockHolder lock(WebGPUDevice::instancesMutex());
     132        for (auto* device : WebGPUDevice::instances(lock)) {
     133            if (existsInCurrentPage(device->scriptExecutionContext()))
     134                bindCanvas(*device, false);
     135        }
     136    }
     137#endif
    126138
    127139#if ENABLE(WEBGL)
    128140    {
    129141        LockHolder lock(WebGLProgram::instancesMutex());
    130         for (auto& entry : WebGLProgram::instances(lock)) {
    131             if (canvasExistsInCurrentPage(entry.value))
    132                 didCreateProgram(*entry.value, *entry.key);
     142        for (auto& [program, contextWebGLBase] : WebGLProgram::instances(lock)) {
     143            if (existsInCurrentPage(contextWebGLBase->canvasBase().scriptExecutionContext()))
     144                didCreateProgram(*contextWebGLBase, *program);
    133145        }
    134146    }
     
    175187}
    176188
    177 void InspectorCanvasAgent::requestCSSCanvasClientNodes(ErrorString& errorString, const String& canvasId, RefPtr<JSON::ArrayOf<int>>& result)
    178 {
     189void InspectorCanvasAgent::requestClientNodes(ErrorString& errorString, const String& canvasId, RefPtr<JSON::ArrayOf<int>>& clientNodeIds)
     190{
     191    auto* domAgent = m_instrumentingAgents.inspectorDOMAgent();
     192    if (!domAgent) {
     193        errorString = "DOM domain must be enabled"_s;
     194        return;
     195    }
     196
    179197    auto inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
    180198    if (!inspectorCanvas)
    181199        return;
    182200
    183     result = JSON::ArrayOf<int>::create();
    184     for (auto* client : inspectorCanvas->context().canvasBase().cssCanvasClients()) {
    185         if (int documentNodeId = m_instrumentingAgents.inspectorDOMAgent()->boundNodeId(&client->document()))
    186             result->addItem(m_instrumentingAgents.inspectorDOMAgent()->pushNodeToFrontend(errorString, documentNodeId, client));
    187     }
    188 }
    189 
    190 static JSC::JSValue contextAsScriptValue(JSC::ExecState& state, CanvasRenderingContext& context)
    191 {
    192     JSC::JSLockHolder lock(&state);
    193 
    194     if (is<CanvasRenderingContext2D>(context))
    195         return toJS(&state, deprecatedGlobalObjectForPrototype(&state), downcast<CanvasRenderingContext2D>(context));
    196 #if ENABLE(WEBGL)
    197     if (is<WebGLRenderingContext>(context))
    198         return toJS(&state, deprecatedGlobalObjectForPrototype(&state), downcast<WebGLRenderingContext>(context));
    199 #endif
    200 #if ENABLE(WEBGL2)
    201     if (is<WebGL2RenderingContext>(context))
    202         return toJS(&state, deprecatedGlobalObjectForPrototype(&state), downcast<WebGL2RenderingContext>(context));
    203 #endif
    204 #if ENABLE(WEBGPU)
    205     if (is<GPUCanvasContext>(context))
    206         return toJS(&state, deprecatedGlobalObjectForPrototype(&state), downcast<GPUCanvasContext>(context));
    207 #endif
    208     if (is<ImageBitmapRenderingContext>(context))
    209         return toJS(&state, deprecatedGlobalObjectForPrototype(&state), downcast<ImageBitmapRenderingContext>(context));
    210 
    211     return { };
    212 }
    213 
    214 void InspectorCanvasAgent::resolveCanvasContext(ErrorString& errorString, const String& canvasId, const String* objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result)
     201    clientNodeIds = JSON::ArrayOf<int>::create();
     202    for (auto& clientNode : inspectorCanvas->clientNodes()) {
     203        if (auto documentNodeId = domAgent->boundNodeId(&clientNode->document()))
     204            clientNodeIds->addItem(domAgent->pushNodeToFrontend(errorString, documentNodeId, clientNode));
     205    }
     206}
     207
     208void InspectorCanvasAgent::resolveContext(ErrorString& errorString, const String& canvasId, const String* objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result)
    215209{
    216210    auto inspectorCanvas = assertInspectorCanvas(errorString, canvasId);
     
    218212        return;
    219213
    220     auto& state = *inspectorCanvas->context().canvasBase().scriptExecutionContext()->execState();
    221     auto injectedScript = m_injectedScriptManager.injectedScriptFor(&state);
     214    auto* state = inspectorCanvas->scriptExecutionContext()->execState();
     215    auto injectedScript = m_injectedScriptManager.injectedScriptFor(state);
    222216    ASSERT(!injectedScript.hasNoValue());
    223217
    224     JSC::JSValue value = contextAsScriptValue(state, inspectorCanvas->context());
     218    JSC::JSValue value = inspectorCanvas->resolveContext(state);
     219
    225220    if (!value) {
    226221        ASSERT_NOT_REACHED();
     
    247242        return;
    248243
    249     if (inspectorCanvas->context().callTracingActive()) {
     244    // FIXME: <https://webkit.org/b/201651> Web Inspector: Canvas: support canvas recordings for WebGPUDevice
     245
     246    auto* context = inspectorCanvas->canvasContext();
     247    if (!context)
     248        return;
     249
     250    if (context->callTracingActive()) {
    250251        errorString = "Already recording canvas"_s;
    251252        return;
     
    266267        return;
    267268
    268     if (!inspectorCanvas->context().callTracingActive()) {
     269    // FIXME: <https://webkit.org/b/201651> Web Inspector: Canvas: support canvas recordings for WebGPUDevice
     270
     271    auto* context = inspectorCanvas->canvasContext();
     272    if (!context)
     273        return;
     274
     275    if (!context->callTracingActive()) {
    269276        errorString = "Not recording canvas"_s;
    270277        return;
    271278    }
    272279
    273     didFinishRecordingCanvasFrame(inspectorCanvas->context(), true);
     280    didFinishRecordingCanvasFrame(*context, true);
    274281}
    275282
     
    372379    }
    373380
    374     for (auto* inspectorCanvas : inspectorCanvases) {
    375         String identifier = unbindCanvas(*inspectorCanvas);
    376         m_frontendDispatcher->canvasRemoved(identifier);
    377     }
     381    for (auto* inspectorCanvas : inspectorCanvases)
     382        unbindCanvas(*inspectorCanvas);
    378383}
    379384
     
    391396        return;
    392397
    393     m_frontendDispatcher->cssCanvasClientNodesChanged(inspectorCanvas->identifier());
     398    m_frontendDispatcher->clientNodesChanged(inspectorCanvas->identifier());
    394399}
    395400
     
    412417void InspectorCanvasAgent::didChangeCanvasMemory(CanvasRenderingContext& context)
    413418{
    414     auto inspectorCanvas = findInspectorCanvas(context);
     419    RefPtr<InspectorCanvas> inspectorCanvas;
     420
     421#if ENABLE(WEBGPU)
     422    if (is<GPUCanvasContext>(context)) {
     423        for (auto& item : m_identifierToInspectorCanvas.values()) {
     424            if (item->isDeviceForCanvasContext(context)) {
     425                inspectorCanvas = item;
     426                break;
     427            }
     428        }
     429    }
     430#endif
     431
     432    if (!inspectorCanvas)
     433        inspectorCanvas = findInspectorCanvas(context);
     434
    415435    ASSERT(inspectorCanvas);
    416436    if (!inspectorCanvas)
     
    437457    // covered by the initial microtask until the next frame.
    438458    if (!inspectorCanvas->currentFrameHasData()) {
    439         if (auto* scriptExecutionContext = inspectorCanvas->context().canvasBase().scriptExecutionContext()) {
     459        if (auto* scriptExecutionContext = inspectorCanvas->scriptExecutionContext()) {
    440460            auto& queue = MicrotaskQueue::mainThreadQueue();
    441461            queue.append(makeUnique<ActiveDOMCallbackMicrotask>(queue, *scriptExecutionContext, [&, protectedInspectorCanvas = inspectorCanvas.copyRef()] {
     
    445465                }
    446466
    447                 if (protectedInspectorCanvas->context().callTracingActive())
    448                     didFinishRecordingCanvasFrame(protectedInspectorCanvas->context());
     467                if (canvasRenderingContext.callTracingActive())
     468                    didFinishRecordingCanvasFrame(canvasRenderingContext);
    449469            }));
    450470        }
     
    454474
    455475    if (!inspectorCanvas->hasBufferSpace())
    456         didFinishRecordingCanvasFrame(inspectorCanvas->context(), true);
     476        didFinishRecordingCanvasFrame(canvasRenderingContext, true);
    457477}
    458478
     
    482502        return;
    483503
    484     String identifier = unbindCanvas(*inspectorCanvas);
    485 
    486     // WebCore::CanvasObserver::canvasDestroyed is called in response to the GC destroying the CanvasBase.
    487     // Due to the single-process model used in WebKit1, the event must be dispatched from a timer to prevent
    488     // the frontend from making JS allocations while the GC is still active.
    489     m_removedCanvasIdentifiers.append(identifier);
    490 
    491     if (!m_canvasDestroyedTimer.isActive())
    492         m_canvasDestroyedTimer.startOneShot(0_s);
     504    unbindCanvas(*inspectorCanvas);
    493505}
    494506
    495507void InspectorCanvasAgent::didFinishRecordingCanvasFrame(CanvasRenderingContext& context, bool forceDispatch)
    496508{
     509    if (!context.callTracingActive())
     510        return;
     511
    497512    auto inspectorCanvas = findInspectorCanvas(context);
    498513    ASSERT(inspectorCanvas);
    499514    if (!inspectorCanvas)
    500         return;
    501 
    502     if (!inspectorCanvas->context().callTracingActive())
    503515        return;
    504516
     
    601613#endif
    602614
     615#if ENABLE(WEBGPU)
     616void InspectorCanvasAgent::didCreateWebGPUDevice(WebGPUDevice& device)
     617{
     618    if (findInspectorCanvas(device)) {
     619        ASSERT_NOT_REACHED();
     620        return;
     621    }
     622
     623    bindCanvas(device, true);
     624}
     625
     626void InspectorCanvasAgent::willDestroyWebGPUDevice(WebGPUDevice& device)
     627{
     628    auto inspectorCanvas = findInspectorCanvas(device);
     629    ASSERT(inspectorCanvas);
     630    if (!inspectorCanvas)
     631        return;
     632
     633    unbindCanvas(*inspectorCanvas);
     634}
     635
     636void InspectorCanvasAgent::willConfigureSwapChain(GPUCanvasContext& contextGPU, WebGPUSwapChain& newSwapChain)
     637{
     638    auto notifyDeviceForSwapChain = [&] (WebGPUSwapChain& webGPUSwapChain) {
     639        for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
     640            if (auto* device = inspectorCanvas->deviceContext()) {
     641                if (device->device().swapChain() == webGPUSwapChain.swapChain())
     642                    m_frontendDispatcher->clientNodesChanged(inspectorCanvas->identifier());
     643            }
     644        }
     645    };
     646
     647    if (auto* existingSwapChain = contextGPU.swapChain())
     648        notifyDeviceForSwapChain(*existingSwapChain);
     649
     650    notifyDeviceForSwapChain(newSwapChain);
     651}
     652#endif
     653
    603654void InspectorCanvasAgent::startRecording(InspectorCanvas& inspectorCanvas, Inspector::Protocol::Recording::Initiator initiator, RecordingOptions&& recordingOptions)
    604655{
    605     auto& canvasRenderingContext = inspectorCanvas.context();
    606 
    607     if (!is<CanvasRenderingContext2D>(canvasRenderingContext)
    608 #if ENABLE(WEBGL)
    609         && !is<WebGLRenderingContext>(canvasRenderingContext)
     656    auto* context = inspectorCanvas.canvasContext();
     657    ASSERT(context);
     658    // FIXME: <https://webkit.org/b/201651> Web Inspector: Canvas: support canvas recordings for WebGPUDevice
     659
     660    if (!is<CanvasRenderingContext2D>(context)
     661        && !is<ImageBitmapRenderingContext>(context)
     662#if ENABLE(WEBGL)
     663        && !is<WebGLRenderingContext>(context)
    610664#endif
    611665#if ENABLE(WEBGL2)
    612         && !is<WebGL2RenderingContext>(canvasRenderingContext)
    613 #endif
    614         && !is<ImageBitmapRenderingContext>(canvasRenderingContext))
    615         return;
    616 
    617     if (canvasRenderingContext.callTracingActive())
     666        && !is<WebGL2RenderingContext>(context)
     667#endif
     668    )
     669        return;
     670
     671    if (context->callTracingActive())
    618672        return;
    619673
     
    625679    if (recordingOptions.name)
    626680        inspectorCanvas.setRecordingName(recordingOptions.name.value());
    627     canvasRenderingContext.setCallTracingActive(true);
     681    context->setCallTracingActive(true);
    628682
    629683    m_frontendDispatcher->recordingStarted(inspectorCanvas.identifier(), initiator);
     
    643697void InspectorCanvasAgent::clearCanvasData()
    644698{
    645     for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values())
    646         inspectorCanvas->context().canvasBase().removeObserver(*this);
     699    for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
     700        if (auto* context = inspectorCanvas->canvasContext())
     701            context->canvasBase().removeObserver(*this);
     702    }
    647703
    648704    m_identifierToInspectorCanvas.clear();
     
    661717    m_identifierToInspectorCanvas.set(inspectorCanvas->identifier(), inspectorCanvas.copyRef());
    662718
    663     inspectorCanvas->context().canvasBase().addObserver(*this);
     719    context.canvasBase().addObserver(*this);
    664720
    665721    m_frontendDispatcher->canvasAdded(inspectorCanvas->buildObjectForCanvas(captureBacktrace));
    666722
    667723#if ENABLE(WEBGL)
    668     if (is<WebGLRenderingContextBase>(inspectorCanvas->context())) {
    669         WebGLRenderingContextBase& contextWebGL = downcast<WebGLRenderingContextBase>(inspectorCanvas->context());
     724    if (is<WebGLRenderingContextBase>(context)) {
     725        auto& contextWebGL = downcast<WebGLRenderingContextBase>(context);
    670726        if (Optional<Vector<String>> extensions = contextWebGL.getSupportedExtensions()) {
    671727            for (const String& extension : *extensions) {
     
    680736}
    681737
    682 String InspectorCanvasAgent::unbindCanvas(InspectorCanvas& inspectorCanvas)
     738#if ENABLE(WEBGPU)
     739InspectorCanvas& InspectorCanvasAgent::bindCanvas(WebGPUDevice& device, bool captureBacktrace)
     740{
     741    auto inspectorCanvas = InspectorCanvas::create(device);
     742    m_identifierToInspectorCanvas.set(inspectorCanvas->identifier(), inspectorCanvas.copyRef());
     743
     744    m_frontendDispatcher->canvasAdded(inspectorCanvas->buildObjectForCanvas(captureBacktrace));
     745
     746    return inspectorCanvas;
     747}
     748#endif
     749
     750void InspectorCanvasAgent::unbindCanvas(InspectorCanvas& inspectorCanvas)
    683751{
    684752#if ENABLE(WEBGL)
     
    693761#endif
    694762
    695     inspectorCanvas.context().canvasBase().removeObserver(*this);
     763    if (auto* context = inspectorCanvas.canvasContext())
     764        context->canvasBase().removeObserver(*this);
    696765
    697766    String identifier = inspectorCanvas.identifier();
    698767    m_identifierToInspectorCanvas.remove(identifier);
    699768
    700     return identifier;
     769    // This can be called in response to GC. Due to the single-process model used in WebKit1, the
     770    // event must be dispatched from a timer to prevent the frontend from making JS allocations
     771    // while the GC is still active.
     772    m_removedCanvasIdentifiers.append(identifier);
     773
     774    if (!m_canvasDestroyedTimer.isActive())
     775        m_canvasDestroyedTimer.startOneShot(0_s);
    701776}
    702777
     
    714789{
    715790    for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
    716         if (&inspectorCanvas->context() == &context)
     791        if (inspectorCanvas->canvasContext() == &context)
    717792            return inspectorCanvas;
    718793    }
    719794    return nullptr;
    720795}
     796
     797#if ENABLE(WEBGPU)
     798RefPtr<InspectorCanvas> InspectorCanvasAgent::findInspectorCanvas(WebGPUDevice& device)
     799{
     800    for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
     801        if (inspectorCanvas->deviceContext() == &device)
     802            return inspectorCanvas;
     803    }
     804    return nullptr;
     805}
     806#endif
    721807
    722808#if ENABLE(WEBGL)
  • trunk/Source/WebCore/inspector/agents/InspectorCanvasAgent.h

    r249132 r249753  
    5454class WebGLRenderingContextBase;
    5555#endif
     56#if ENABLE(WEBGPU)
     57class GPUCanvasContext;
     58class WebGPUDevice;
     59class WebGPUSwapChain;
     60#endif
    5661
    5762typedef String ErrorString;
     
    7479    void requestNode(ErrorString&, const String& canvasId, int* nodeId);
    7580    void requestContent(ErrorString&, const String& canvasId, String* content);
    76     void requestCSSCanvasClientNodes(ErrorString&, const String& canvasId, RefPtr<JSON::ArrayOf<int>>&);
    77     void resolveCanvasContext(ErrorString&, const String& canvasId, const String* objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>&);
     81    void requestClientNodes(ErrorString&, const String& canvasId, RefPtr<JSON::ArrayOf<int>>&);
     82    void resolveContext(ErrorString&, const String& canvasId, const String* objectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>&);
    7883    void setRecordingAutoCaptureFrameCount(ErrorString&, int count);
    7984    void startRecording(ErrorString&, const String& canvasId, const int* frameCount, const int* memoryLimit);
     
    9398    void didChangeCSSCanvasClientNodes(CanvasBase&);
    9499    void didCreateCanvasRenderingContext(CanvasRenderingContext&);
    95     void willDestroyCanvasRenderingContext(CanvasRenderingContext&);
    96100    void didChangeCanvasMemory(CanvasRenderingContext&);
    97101    void recordCanvasAction(CanvasRenderingContext&, const String&, std::initializer_list<RecordCanvasActionVariant>&& = { });
     
    104108    bool isShaderProgramDisabled(WebGLProgram&);
    105109    bool isShaderProgramHighlighted(WebGLProgram&);
     110#endif
     111#if ENABLE(WEBGPU)
     112    void didCreateWebGPUDevice(WebGPUDevice&);
     113    void willDestroyWebGPUDevice(WebGPUDevice&);
     114    void willConfigureSwapChain(GPUCanvasContext&, WebGPUSwapChain&);
    106115#endif
    107116
     
    117126    void clearCanvasData();
    118127    InspectorCanvas& bindCanvas(CanvasRenderingContext&, bool captureBacktrace);
    119     String unbindCanvas(InspectorCanvas&);
     128#if ENABLE(WEBGPU)
     129    InspectorCanvas& bindCanvas(WebGPUDevice&, bool captureBacktrace);
     130#endif
     131    void unbindCanvas(InspectorCanvas&);
    120132    RefPtr<InspectorCanvas> assertInspectorCanvas(ErrorString&, const String& canvasId);
    121133    RefPtr<InspectorCanvas> findInspectorCanvas(CanvasRenderingContext&);
     134#if ENABLE(WEBGPU)
     135    RefPtr<InspectorCanvas> findInspectorCanvas(WebGPUDevice&);
     136#endif
     137
    122138#if ENABLE(WEBGL)
    123139    String unbindProgram(InspectorShaderProgram&);
  • trunk/Source/WebInspectorUI/ChangeLog

    r249751 r249753  
     12019-09-10  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Canvas: instrument WebGPUDevice instead of GPUCanvasContext
     4        https://bugs.webkit.org/show_bug.cgi?id=201650
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        Most of the actual "work" done with Web GPU actually uses a `WebGPUDevice`.
     9
     10        A `GPUCanvasContext` is basically just a display "client" of the device, and isn't even
     11        required (e.g. compute pipeline).  We should treat the `GPUCanvasContext` almost like a
     12        `-webkit-canvas` client of a `WebGPUDevice`.
     13
     14        * UserInterface/Protocol/CanvasObserver.js:
     15        (WI.CanvasObserver.prototype.clientNodesChanged): Added.
     16        (WI.CanvasObserver.prototype.cssCanvasClientNodesChanged):
     17        * UserInterface/Controllers/CanvasManager.js:
     18        (WI.CanvasManager.prototype.clientNodesChanged): Added.
     19        (WI.CanvasManager.prototype.cssCanvasClientNodesChanged): Deleted.
     20        * UserInterface/Models/Canvas.js:
     21        (WI.Canvas.resetUniqueDisplayNameNumbers):
     22        (WI.Canvas.prototype.get displayName):
     23        (WI.Canvas.prototype.requestNode):
     24        (WI.Canvas.prototype.requestClientNodes): Added.
     25        (WI.Canvas.prototype.requestSize):
     26        (WI.Canvas.prototype.clientNodesChanged): Added.
     27        (WI.Canvas.prototype.requestCSSCanvasClientNodes): Deleted.
     28        (WI.Canvas.prototype.cssCanvasClientNodesChanged): Deleted.
     29
     30        * UserInterface/Protocol/RemoteObject.js:
     31        (WI.RemoteObject.resolveCanvasContext):
     32
     33        * UserInterface/Views/CanvasContentView.js:
     34        (WI.CanvasContentView.prototype.attached):
     35        (WI.CanvasContentView.prototype._refreshPixelSize):
     36        * UserInterface/Views/CanvasDetailsSidebarPanel.js:
     37        (WI.CanvasDetailsSidebarPanel.prototype.set canvas):
     38        (WI.CanvasDetailsSidebarPanel.prototype.initialLayout):
     39        (WI.CanvasDetailsSidebarPanel.prototype.layout):
     40        (WI.CanvasDetailsSidebarPanel.prototype._refreshSourceSection):
     41        (WI.CanvasDetailsSidebarPanel.prototype._refreshClientsSection): Added.
     42        (WI.CanvasDetailsSidebarPanel.prototype._refreshCSSCanvasSection): Deleted.
     43        * UserInterface/Views/CanvasOverviewContentView.js:
     44        (WI.CanvasOverviewContentView.prototype._contentViewMouseEnter):
     45        * UserInterface/Views/CanvasTreeElement.js:
     46        (WI.CanvasTreeElement.prototype._handleMouseOver):
     47
     48        * Localizations/en.lproj/localizedStrings.js:
     49
    1502019-09-10  Joseph Pecoraro  <pecoraro@apple.com>
    251
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r249504 r249753  
    195195localizedStrings["CPU Usage"] = "CPU Usage";
    196196localizedStrings["CSP Hash"] = "CSP Hash";
    197 localizedStrings["CSS"] = "CSS";
    198197localizedStrings["CSS Canvas"] = "CSS Canvas";
    199198localizedStrings["CSS Changes:"] = "CSS Changes:";
     
    247246localizedStrings["Click to view variable value\nShift-click to replace variable with value"] = "Click to view variable value\nShift-click to replace variable with value";
    248247localizedStrings["Clickable"] = "Clickable";
     248localizedStrings["Clients"] = "Clients";
    249249localizedStrings["Close"] = "Close";
    250250localizedStrings["Close %s timeline view"] = "Close %s timeline view";
     
    346346localizedStrings["Detached"] = "Detached";
    347347localizedStrings["Details"] = "Details";
     348localizedStrings["Device %d"] = "Device %d";
    348349localizedStrings["Device Settings"] = "Device Settings";
    349350localizedStrings["Diagnoses common accessibility problems affecting screen readers and other assistive technology."] = "Diagnoses common accessibility problems affecting screen readers and other assistive technology.";
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/CanvasManager.js

    r248536 r249753  
    185185    }
    186186
    187     cssCanvasClientNodesChanged(canvasIdentifier)
    188     {
    189         let canvas = this._canvasIdentifierMap.get(canvasIdentifier);
    190         console.assert(canvas);
    191         if (!canvas)
    192             return;
    193 
    194         canvas.cssCanvasClientNodesChanged();
     187    clientNodesChanged(canvasIdentifier)
     188    {
     189        let canvas = this._canvasIdentifierMap.get(canvasIdentifier);
     190        console.assert(canvas);
     191        if (!canvas)
     192            return;
     193
     194        canvas.clientNodesChanged();
    195195    }
    196196
  • trunk/Source/WebInspectorUI/UserInterface/Models/Canvas.js

    r249301 r249753  
    4242        this._backtrace = backtrace || [];
    4343
    44         this._cssCanvasClientNodes = null;
     44        this._clientNodes = null;
    4545        this._shaderProgramCollection = new WI.ShaderProgramCollection;
    4646        this._recordingCollection = new WI.RecordingCollection;
     
    114114    static resetUniqueDisplayNameNumbers()
    115115    {
    116         WI.Canvas._nextUniqueDisplayNameNumber = 1;
     116        Canvas._nextContextUniqueDisplayNameNumber = 1;
     117        Canvas._nextDeviceUniqueDisplayNameNumber = 1;
    117118    }
    118119
     
    161162        }
    162163
     164        if (this._contextType === Canvas.ContextType.WebGPU) {
     165            if (!this._uniqueDisplayNameNumber)
     166                this._uniqueDisplayNameNumber = Canvas._nextDeviceUniqueDisplayNameNumber++;
     167            return WI.UIString("Device %d").format(this._uniqueDisplayNameNumber);
     168        }
     169
    163170        if (!this._uniqueDisplayNameNumber)
    164             this._uniqueDisplayNameNumber = this.constructor._nextUniqueDisplayNameNumber++;
     171            this._uniqueDisplayNameNumber = Canvas._nextContextUniqueDisplayNameNumber++;
    165172        return WI.UIString("Canvas %d").format(this._uniqueDisplayNameNumber);
    166173    }
     
    172179                WI.domManager.ensureDocument();
    173180
    174                 CanvasAgent.requestNode(this._identifier).then((result) => {
    175                     this._domNode = WI.domManager.nodeForId(result.nodeId);
    176                     if (!this._domNode) {
    177                         reject(`No DOM node for identifier: ${result.nodeId}.`);
     181                CanvasAgent.requestNode(this._identifier, (error, nodeId) => {
     182                    if (error) {
     183                        resolve(null);
    178184                        return;
    179185                    }
     186
     187                    this._domNode = WI.domManager.nodeForId(nodeId);
     188                    if (!this._domNode) {
     189                        resolve(null);
     190                        return;
     191                    }
     192
    180193                    resolve(this._domNode);
    181                 }).catch(reject);
     194                });
    182195            });
    183196        }
    184 
    185197        return this._requestNodePromise;
    186198    }
     
    191203    }
    192204
    193     requestCSSCanvasClientNodes(callback)
    194     {
    195         if (!this._cssCanvasName) {
    196             callback([]);
     205    requestClientNodes(callback)
     206    {
     207        if (this._clientNodes) {
     208            callback(this._clientNodes);
    197209            return;
    198210        }
    199211
    200         if (this._cssCanvasClientNodes) {
    201             callback(this._cssCanvasClientNodes);
    202             return;
    203         }
    204 
    205212        WI.domManager.ensureDocument();
    206213
    207         CanvasAgent.requestCSSCanvasClientNodes(this._identifier, (error, clientNodeIds) => {
     214        let wrappedCallback = (error, clientNodeIds) => {
    208215            if (error) {
    209216                callback([]);
     
    212219
    213220            clientNodeIds = Array.isArray(clientNodeIds) ? clientNodeIds : [];
    214             this._cssCanvasClientNodes = clientNodeIds.map((clientNodeId) => WI.domManager.nodeForId(clientNodeId));
    215             callback(this._cssCanvasClientNodes);
    216         });
     221            this._clientNodes = clientNodeIds.map((clientNodeId) => WI.domManager.nodeForId(clientNodeId));
     222            callback(this._clientNodes);
     223        };
     224
     225        // COMPATIBILITY (iOS 13): Canvas.requestCSSCanvasClientNodes was renamed to Canvas.requestClientNodes.
     226        if (!CanvasAgent.requestClientNodes) {
     227            CanvasAgent.requestCSSCanvasClientNodes(this._identifier, wrappedCallback);
     228            return;
     229        }
     230
     231        CanvasAgent.requestClientNodes(this._identifier, wrappedCallback);
    217232    }
    218233
     
    246261
    247262        return this.requestNode().then((domNode) => {
     263            if (!domNode)
     264                return null;
     265
    248266            let size = calculateSize(domNode);
    249267            if (!isNaN(size.width) && !isNaN(size.height))
     
    328346    }
    329347
    330     cssCanvasClientNodesChanged()
     348    clientNodesChanged()
    331349    {
    332350        // Called from WI.CanvasManager.
    333351
    334         if (!this._cssCanvasName)
    335             return;
    336 
    337         this._cssCanvasClientNodes = null;
    338 
    339         this.dispatchEventToListeners(WI.Canvas.Event.CSSCanvasClientNodesChanged);
     352        this._clientNodes = null;
     353
     354        this.dispatchEventToListeners(Canvas.Event.ClientNodesChanged);
    340355    }
    341356
     
    403418};
    404419
    405 WI.Canvas._nextUniqueDisplayNameNumber = 1;
     420WI.Canvas._nextContextUniqueDisplayNameNumber = 1;
     421WI.Canvas._nextDeviceUniqueDisplayNameNumber = 1;
    406422
    407423WI.Canvas.FrameURLCookieKey = "canvas-frame-url";
     
    427443    MemoryChanged: "canvas-memory-changed",
    428444    ExtensionEnabled: "canvas-extension-enabled",
    429     CSSCanvasClientNodesChanged: "canvas-css-canvas-client-nodes-changed",
     445    ClientNodesChanged: "canvas-client-nodes-changed",
    430446    RecordingStarted: "canvas-recording-started",
    431447    RecordingProgress: "canvas-recording-progress",
  • trunk/Source/WebInspectorUI/UserInterface/Protocol/CanvasObserver.js

    r237010 r249753  
    4343    }
    4444
    45     cssCanvasClientNodesChanged(canvasId)
     45    clientNodesChanged(canvasId)
    4646    {
    47         WI.canvasManager.cssCanvasClientNodesChanged(canvasId);
     47        WI.canvasManager.clientNodesChanged(canvasId);
    4848    }
    4949
     
    7777        WI.canvasManager.programDeleted(programId);
    7878    }
     79
     80    // COMPATIBILITY (iOS 13): Canvas.events.cssCanvasClientNodesChanged was renamed to Canvas.events.clientNodesChanged.
     81    cssCanvasClientNodesChanged(canvasId)
     82    {
     83        WI.canvasManager.clientNodesChanged(canvasId);
     84    }
    7985};
  • trunk/Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js

    r249301 r249753  
    164164        console.assert(typeof callback === "function");
    165165
    166         CanvasAgent.resolveCanvasContext(canvas.identifier, objectGroup, (error, object) => {
     166        function wrapCallback(error, object) {
    167167            if (error || !object)
    168168                callback(null);
    169169            else
    170170                callback(WI.RemoteObject.fromPayload(object, WI.mainTarget));
    171         });
     171        }
     172
     173        // COMPATIBILITY (iOS 13): Canvas.resolveCanvasContext was renamed to Canvas.resolveContext.
     174        if (!CanvasAgent.resolveContext) {
     175            CanvasAgent.resolveCanvasContext(canvas.identifier, objectGroup, wrapCallback);
     176            return;
     177        }
     178
     179        CanvasAgent.resolveContext(canvas.identifier, objectGroup, wrapCallback);
    172180    }
    173181
  • trunk/Source/WebInspectorUI/UserInterface/Views/CanvasContentView.js

    r247803 r249753  
    211211
    212212        this.representedObject.requestNode().then((node) => {
     213            if (!node)
     214                return;
     215
    213216            console.assert(!this._canvasNode || this._canvasNode === node);
    214217            if (this._canvasNode === node)
     
    282285        };
    283286
    284         this.representedObject.requestSize()
    285         .then((size) => {
     287        this.representedObject.requestSize().then((size) => {
    286288            updatePixelSize(size);
    287         })
    288         .catch((error) => {
    289             updatePixelSize(null);
    290289        });
    291290    }
  • trunk/Source/WebInspectorUI/UserInterface/Views/CanvasDetailsSidebarPanel.js

    r238626 r249753  
    7979            this._canvas.removeEventListener(WI.Canvas.Event.MemoryChanged, this._canvasMemoryChanged, this);
    8080            this._canvas.removeEventListener(WI.Canvas.Event.ExtensionEnabled, this._refreshExtensionsSection, this);
    81             this._canvas.removeEventListener(WI.Canvas.Event.CSSCanvasClientNodesChanged, this._refreshCSSCanvasSection, this);
     81            this._canvas.removeEventListener(WI.Canvas.Event.ClientNodesChanged, this._refreshClientsSection, this);
    8282        }
    8383
     
    8787            this._canvas.addEventListener(WI.Canvas.Event.MemoryChanged, this._canvasMemoryChanged, this);
    8888            this._canvas.addEventListener(WI.Canvas.Event.ExtensionEnabled, this._refreshExtensionsSection, this);
    89             this._canvas.addEventListener(WI.Canvas.Event.CSSCanvasClientNodesChanged, this._refreshCSSCanvasSection, this);
     89            this._canvas.addEventListener(WI.Canvas.Event.ClientNodesChanged, this._refreshClientsSection, this);
    9090        }
    9191
     
    112112        this._widthRow = new WI.DetailsSectionSimpleRow(WI.UIString("Width"));
    113113        this._heightRow = new WI.DetailsSectionSimpleRow(WI.UIString("Height"));
    114         this._datachedRow = new WI.DetailsSectionSimpleRow(WI.UIString("Detached"));
     114        this._detachedRow = new WI.DetailsSectionSimpleRow(WI.UIString("Detached"));
    115115
    116116        let sourceSection = new WI.DetailsSection("canvas-source", WI.UIString("Source"));
    117         sourceSection.groups = [new WI.DetailsSectionGroup([this._nodeRow, this._cssCanvasRow, this._widthRow, this._heightRow, this._datachedRow])];
     117        sourceSection.groups = [new WI.DetailsSectionGroup([this._nodeRow, this._cssCanvasRow, this._widthRow, this._heightRow, this._detachedRow])];
    118118        this._sections.push(sourceSection);
    119119
     
    129129        this._sections.push(this._extensionsSection);
    130130
    131         this._cssCanvasClientsRow = new WI.DetailsSectionSimpleRow(WI.UIString("Nodes"));
    132 
    133         this._cssCanvasSection = new WI.DetailsSection("canvas-css", WI.UIString("CSS"));
    134         this._cssCanvasSection.groups = [new WI.DetailsSectionGroup([this._cssCanvasClientsRow])];
    135         this._cssCanvasSection.element.hidden = true;
    136         this._sections.push(this._cssCanvasSection);
     131        this._clientNodesRow = new WI.DetailsSectionSimpleRow(WI.UIString("Nodes"));
     132
     133        this._clientsSection = new WI.DetailsSection("canvas-clients", WI.UIString("Clients"));
     134        this._clientsSection.groups = [new WI.DetailsSectionGroup([this._clientNodesRow])];
     135        this._clientsSection.element.hidden = true;
     136        this._sections.push(this._clientsSection);
    137137
    138138        const selectable = false;
     
    169169        this._refreshAttributesSection();
    170170        this._refreshExtensionsSection();
    171         this._refreshCSSCanvasSection();
     171        this._refreshClientsSection();
    172172        this._refreshBacktraceSection();
    173173    }
     
    195195            return;
    196196
    197         this._nodeRow.value = this._canvas.cssCanvasName ? null : emDash;
     197        let hideNode = this._canvas.cssCanvasName || this._canvas.contextType === WI.Canvas.ContextType.WebGPU;
     198
     199        this._nodeRow.value = hideNode ? null : emDash;
    198200        this._cssCanvasRow.value = this._canvas.cssCanvasName || null;
    199201        this._widthRow.value = emDash;
    200202        this._heightRow.value = emDash;
    201         this._datachedRow.value = null;
     203        this._detachedRow.value = null;
    202204
    203205        this._canvas.requestNode().then((node) => {
     206            if (!node) {
     207                this._nodeRow.value = null;
     208                return;
     209            }
     210
    204211            if (node !== this._node) {
    205212                if (this._node) {
     
    216223            }
    217224
    218             if (!this._canvas.cssCanvasName)
     225            if (!hideNode) {
    219226                this._nodeRow.value = WI.linkifyNodeReference(this._node);
     227
     228                if (!this._node.parentNode)
     229                    this._detachedRow.value = WI.UIString("Yes");
     230            }
    220231
    221232            let setRowValueIfValidAttributeValue = (row, attribute) => {
     
    249260                });
    250261            }
    251 
    252             if (!this._canvas.cssCanvasName && !this._node.parentNode)
    253                 this._datachedRow.value = WI.UIString("Yes");
    254262        });
    255263    }
     
    296304    }
    297305
    298     _refreshCSSCanvasSection()
     306    _refreshClientsSection()
    299307    {
    300308        if (!this.didInitialLayout)
    301309            return;
    302310
    303         if (!this._canvas.cssCanvasName) {
    304             this._cssCanvasSection.element.hidden = true;
    305             return;
    306         }
    307 
    308         this._cssCanvasClientsRow.value = emDash;
    309 
    310         this._cssCanvasSection.element.hidden = false;
    311 
    312         this._canvas.requestCSSCanvasClientNodes((cssCanvasClientNodes) => {
    313             if (!cssCanvasClientNodes.length)
     311        if (!this._canvas.cssCanvasName && this._canvas.contextType !== WI.Canvas.ContextType.WebGPU) {
     312            this._clientsSection.element.hidden = true;
     313            return;
     314        }
     315
     316        this._clientNodesRow.value = emDash;
     317
     318        this._clientsSection.element.hidden = false;
     319
     320        this._canvas.requestClientNodes((clientNodes) => {
     321            if (!clientNodes.length)
    314322                return;
    315323
    316324            let fragment = document.createDocumentFragment();
    317             for (let clientNode of cssCanvasClientNodes)
     325            for (let clientNode of clientNodes)
    318326                fragment.appendChild(WI.linkifyNodeReference(clientNode));
    319             this._cssCanvasClientsRow.value = fragment;
     327            this._clientNodesRow.value = fragment;
    320328        });
    321329    }
  • trunk/Source/WebInspectorUI/UserInterface/Views/CanvasOverviewContentView.js

    r246555 r249753  
    192192
    193193        let canvas = contentView.representedObject;
    194         if (canvas.cssCanvasName) {
    195             canvas.requestCSSCanvasClientNodes((cssCanvasClientNodes) => {
    196                 WI.domManager.highlightDOMNodeList(cssCanvasClientNodes.map((node) => node.id));
     194        if (canvas.cssCanvasName || canvas.contextType === WI.Canvas.ContextType.WebGPU) {
     195            canvas.requestClientNodes((clientNodes) => {
     196                WI.domManager.highlightDOMNodeList(clientNodes.map((node) => node.id));
    197197            });
    198198            return;
  • trunk/Source/WebInspectorUI/UserInterface/Views/CanvasTreeElement.js

    r236952 r249753  
    116116    _handleMouseOver(event)
    117117    {
    118         if (this.representedObject.cssCanvasName) {
    119             this.representedObject.requestCSSCanvasClientNodes((cssCanvasClientNodes) => {
    120                 WI.domManager.highlightDOMNodeList(cssCanvasClientNodes.map((node) => node.id), "all");
     118        if (this.representedObject.cssCanvasName || this.representedObject.contextType === WI.Canvas.ContextType.WebGPU) {
     119            this.representedObject.requestClientNodes((clientNodes) => {
     120                WI.domManager.highlightDOMNodeList(clientNodes.map((node) => node.id));
    121121            });
    122122        } else {
     
    125125                    return;
    126126
    127                 WI.domManager.highlightDOMNode(node.id, "all");
     127                WI.domManager.highlightDOMNode(node.id);
    128128            });
    129129        }
Note: See TracChangeset for help on using the changeset viewer.