Web Inspector: replace HTMLCanvasElement with CanvasRenderingContext for instrumentat...
authorwebkit@devinrousso.com <webkit@devinrousso.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Dec 2017 00:02:18 +0000 (00:02 +0000)
committerwebkit@devinrousso.com <webkit@devinrousso.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Dec 2017 00:02:18 +0000 (00:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180770

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

* inspector/protocol/Canvas.json:

Source/WebCore:

No change in functionality.

* html/canvas/CanvasRenderingContext.h:
* html/canvas/CanvasRenderingContext.cpp:
(WebCore::CanvasRenderingContext::~CanvasRenderingContext):
Instead of waiting on the HTMLCanvasElement to destruct to call willDestroyCanvasRenderingContext
we can call out in the destructor and know that the CanvasRenderingContext will be destroyed
immediately thereafter.

* html/canvas/CanvasRenderingContext2D.h:
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::create):
* html/canvas/ImageBitmapRenderingContext.h:
* html/canvas/ImageBitmapRenderingContext.cpp:
(WebCore::ImageBitmapRenderingContext::create):
* html/canvas/WebGL2RenderingContext.h:
* html/canvas/WebGL2RenderingContext.cpp:
(WebCore::WebGL2RenderingContext::create):
* html/canvas/WebGLRenderingContext.h:
* html/canvas/WebGLRenderingContext.cpp:
(WebCore::WebGLRenderingContext::create):
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::create):
* html/canvas/WebGPURenderingContext.cpp:
(WebCore::WebGPURenderingContext::create):
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::createContext2d):
(WebCore::HTMLCanvasElement::createContextWebGL):
(WebCore::HTMLCanvasElement::createContextWebGPU):
(WebCore::HTMLCanvasElement::createContextBitmapRenderer):
(WebCore::HTMLCanvasElement::paint):
(WebCore::HTMLCanvasElement::setImageBuffer const):
Instead of adding didCreateCanvasRenderingContext calls at the construction sites of each
context, we can make the constructors private and force the usage of static `create` functions.
This way, we have access to the fully constructed object and have a guaranteed path for creation.

* inspector/InspectorCanvas.h:
* inspector/InspectorCanvas.cpp:
(WebCore::InspectorCanvas::create):
(WebCore::InspectorCanvas::InspectorCanvas):
(WebCore::InspectorCanvas::canvasElement):
(WebCore::InspectorCanvas::resetRecordingData):
(WebCore::InspectorCanvas::recordAction):
(WebCore::InspectorCanvas::buildObjectForCanvas):
(WebCore::InspectorCanvas::getCanvasContentAsDataURL):
(WebCore::InspectorCanvas::buildInitialState):

* inspector/InspectorShaderProgram.h:
* inspector/InspectorShaderProgram.cpp:
(WebCore::InspectorShaderProgram::context const):

* inspector/agents/InspectorCanvasAgent.h:
* inspector/agents/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::InspectorCanvasAgent):
(WebCore::InspectorCanvasAgent::enable):
(WebCore::InspectorCanvasAgent::disable):
(WebCore::InspectorCanvasAgent::requestNode):
(WebCore::InspectorCanvasAgent::requestContent):
(WebCore::InspectorCanvasAgent::requestCSSCanvasClientNodes):
(WebCore::contextAsScriptValue):
(WebCore::InspectorCanvasAgent::resolveCanvasContext):
(WebCore::InspectorCanvasAgent::startRecording):
(WebCore::InspectorCanvasAgent::stopRecording):
(WebCore::InspectorCanvasAgent::updateShader):
(WebCore::InspectorCanvasAgent::frameNavigated):
(WebCore::InspectorCanvasAgent::didChangeCSSCanvasClientNodes):
(WebCore::InspectorCanvasAgent::didCreateCanvasRenderingContext):
(WebCore::InspectorCanvasAgent::willDestroyCanvasRenderingContext):
(WebCore::InspectorCanvasAgent::didChangeCanvasMemory):
(WebCore::InspectorCanvasAgent::recordCanvasAction):
(WebCore::InspectorCanvasAgent::didFinishRecordingCanvasFrame):
(WebCore::InspectorCanvasAgent::consoleStartRecordingCanvas):
(WebCore::InspectorCanvasAgent::didEnableExtension):
(WebCore::InspectorCanvasAgent::didCreateProgram):
(WebCore::InspectorCanvasAgent::canvasDestroyedTimerFired):
(WebCore::InspectorCanvasAgent::canvasRecordingTimerFired):
(WebCore::InspectorCanvasAgent::clearCanvasData):
(WebCore::InspectorCanvasAgent::unbindCanvas):
(WebCore::InspectorCanvasAgent::findInspectorCanvas):
(WebCore::InspectorCanvasAgent::unbindProgram):
(WebCore::InspectorCanvasAgent::didCreateCSSCanvas): Deleted.
(WebCore::InspectorCanvasAgent::canvasDestroyed): Deleted.

* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::didCreateCanvasRenderingContext):
(WebCore::InspectorInstrumentation::willDestroyCanvasRenderingContext):
(WebCore::InspectorInstrumentation::didChangeCanvasMemory):
(WebCore::InspectorInstrumentation::recordCanvasAction):
(WebCore::InspectorInstrumentation::didFinishRecordingCanvasFrame):
(WebCore::InspectorInstrumentation::didEnableExtension):
(WebCore::InspectorInstrumentation::didCreateProgram):
(WebCore::InspectorInstrumentation::willDeleteProgram):
(WebCore::InspectorInstrumentation::isShaderProgramDisabled):
(WebCore::InspectorInstrumentation::consoleStartRecordingCanvas):
(WebCore::InspectorInstrumentation::didCreateCSSCanvas): Deleted.
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::consoleStartRecordingCanvasImpl):
(WebCore::InspectorInstrumentation::didChangeCSSCanvasClientNodesImpl):
(WebCore::InspectorInstrumentation::didCreateCanvasRenderingContextImpl):
(WebCore::InspectorInstrumentation::willDestroyCanvasRenderingContextImpl):
(WebCore::InspectorInstrumentation::didChangeCanvasMemoryImpl):
(WebCore::InspectorInstrumentation::didFinishRecordingCanvasFrameImpl):
(WebCore::InspectorInstrumentation::didEnableExtensionImpl):
(WebCore::InspectorInstrumentation::didCreateProgramImpl):
(WebCore::InspectorInstrumentation::didCreateCSSCanvasImpl): Deleted.

* page/PageConsoleClient.cpp:
(WebCore::PageConsoleClient::record):
(WebCore::PageConsoleClient::recordEnd):

* dom/Document.h:
* dom/Document.cpp:
(WebCore::Document::getCSSCanvasElement):
(WebCore::Document::nameForCSSCanvasElement const):
We have no reason to save the CSS canvas name for each InspectorCanvas object, so instead we
can just query for the name based on the CanvasRenderingContext's HTMLCanvasElement (assuming
it is not an OffscreenCanvas) when we need it.

Source/WebInspectorUI:

* UserInterface/Models/Canvas.js:
(WI.Canvas.fromPayload):
(WI.Canvas.prototype.get contextType):
(WI.Canvas.prototype.saveIdentityToCookie):
(WI.Canvas.prototype.get frame): Deleted.

Tools:

* Scripts/webkitpy/common/config/watchlist:

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

31 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/protocol/Canvas.json
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/canvas/CanvasRenderingContext.cpp
Source/WebCore/html/canvas/CanvasRenderingContext.h
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.h
Source/WebCore/html/canvas/ImageBitmapRenderingContext.cpp
Source/WebCore/html/canvas/ImageBitmapRenderingContext.h
Source/WebCore/html/canvas/WebGL2RenderingContext.cpp
Source/WebCore/html/canvas/WebGL2RenderingContext.h
Source/WebCore/html/canvas/WebGLRenderingContext.cpp
Source/WebCore/html/canvas/WebGLRenderingContext.h
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/html/canvas/WebGPURenderingContext.cpp
Source/WebCore/inspector/InspectorCanvas.cpp
Source/WebCore/inspector/InspectorCanvas.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/InspectorShaderProgram.cpp
Source/WebCore/inspector/InspectorShaderProgram.h
Source/WebCore/inspector/agents/InspectorCanvasAgent.cpp
Source/WebCore/inspector/agents/InspectorCanvasAgent.h
Source/WebCore/page/PageConsoleClient.cpp
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Models/Canvas.js
Tools/ChangeLog
Tools/Scripts/webkitpy/common/config/watchlist

index d1e1d5e..4441f73 100644 (file)
@@ -1,3 +1,12 @@
+2017-12-14  Devin Rousso  <webkit@devinrousso.com>
+
+        Web Inspector: replace HTMLCanvasElement with CanvasRenderingContext for instrumentation logic
+        https://bugs.webkit.org/show_bug.cgi?id=180770
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/protocol/Canvas.json:
+
 2017-12-14  Keith Miller  <keith_miller@apple.com>
 
         Fix assertion in JSObject's structure setting methods
index 73f472d..8bab3b5 100644 (file)
@@ -46,7 +46,6 @@
             "properties": [
                 { "name": "canvasId", "$ref": "CanvasId", "description": "Canvas identifier." },
                 { "name": "contextType", "$ref": "ContextType", "description": "The type of rendering context backing the canvas." },
-                { "name": "frameId", "$ref": "Network.FrameId", "description": "Parent frame identifier." },
                 { "name": "nodeId", "$ref": "DOM.NodeId", "optional": true, "description": "The corresponding DOM node id." },
                 { "name": "cssCanvasName", "type": "string", "optional": true, "description": "The CSS canvas identifier, for canvases created with <code>document.getCSSCanvasContext</code>." },
                 { "name": "contextAttributes", "$ref": "ContextAttributes", "optional": true, "description": "Context attributes for rendering contexts." },
index 76630a0..a71e6ae 100644 (file)
@@ -1,3 +1,128 @@
+2017-12-14  Devin Rousso  <webkit@devinrousso.com>
+
+        Web Inspector: replace HTMLCanvasElement with CanvasRenderingContext for instrumentation logic
+        https://bugs.webkit.org/show_bug.cgi?id=180770
+
+        Reviewed by Joseph Pecoraro.
+
+        No change in functionality.
+
+        * html/canvas/CanvasRenderingContext.h:
+        * html/canvas/CanvasRenderingContext.cpp:
+        (WebCore::CanvasRenderingContext::~CanvasRenderingContext):
+        Instead of waiting on the HTMLCanvasElement to destruct to call willDestroyCanvasRenderingContext
+        we can call out in the destructor and know that the CanvasRenderingContext will be destroyed
+        immediately thereafter.
+
+        * html/canvas/CanvasRenderingContext2D.h:
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::create):
+        * html/canvas/ImageBitmapRenderingContext.h:
+        * html/canvas/ImageBitmapRenderingContext.cpp:
+        (WebCore::ImageBitmapRenderingContext::create):
+        * html/canvas/WebGL2RenderingContext.h:
+        * html/canvas/WebGL2RenderingContext.cpp:
+        (WebCore::WebGL2RenderingContext::create):
+        * html/canvas/WebGLRenderingContext.h:
+        * html/canvas/WebGLRenderingContext.cpp:
+        (WebCore::WebGLRenderingContext::create):
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::create):
+        * html/canvas/WebGPURenderingContext.cpp:
+        (WebCore::WebGPURenderingContext::create):
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::createContext2d):
+        (WebCore::HTMLCanvasElement::createContextWebGL):
+        (WebCore::HTMLCanvasElement::createContextWebGPU):
+        (WebCore::HTMLCanvasElement::createContextBitmapRenderer):
+        (WebCore::HTMLCanvasElement::paint):
+        (WebCore::HTMLCanvasElement::setImageBuffer const):
+        Instead of adding didCreateCanvasRenderingContext calls at the construction sites of each
+        context, we can make the constructors private and force the usage of static `create` functions.
+        This way, we have access to the fully constructed object and have a guaranteed path for creation.
+
+        * inspector/InspectorCanvas.h:
+        * inspector/InspectorCanvas.cpp:
+        (WebCore::InspectorCanvas::create):
+        (WebCore::InspectorCanvas::InspectorCanvas):
+        (WebCore::InspectorCanvas::canvasElement):
+        (WebCore::InspectorCanvas::resetRecordingData):
+        (WebCore::InspectorCanvas::recordAction):
+        (WebCore::InspectorCanvas::buildObjectForCanvas):
+        (WebCore::InspectorCanvas::getCanvasContentAsDataURL):
+        (WebCore::InspectorCanvas::buildInitialState):
+        
+        * inspector/InspectorShaderProgram.h:
+        * inspector/InspectorShaderProgram.cpp:
+        (WebCore::InspectorShaderProgram::context const):
+
+        * inspector/agents/InspectorCanvasAgent.h:
+        * inspector/agents/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::InspectorCanvasAgent):
+        (WebCore::InspectorCanvasAgent::enable):
+        (WebCore::InspectorCanvasAgent::disable):
+        (WebCore::InspectorCanvasAgent::requestNode):
+        (WebCore::InspectorCanvasAgent::requestContent):
+        (WebCore::InspectorCanvasAgent::requestCSSCanvasClientNodes):
+        (WebCore::contextAsScriptValue):
+        (WebCore::InspectorCanvasAgent::resolveCanvasContext):
+        (WebCore::InspectorCanvasAgent::startRecording):
+        (WebCore::InspectorCanvasAgent::stopRecording):
+        (WebCore::InspectorCanvasAgent::updateShader):
+        (WebCore::InspectorCanvasAgent::frameNavigated):
+        (WebCore::InspectorCanvasAgent::didChangeCSSCanvasClientNodes):
+        (WebCore::InspectorCanvasAgent::didCreateCanvasRenderingContext):
+        (WebCore::InspectorCanvasAgent::willDestroyCanvasRenderingContext):
+        (WebCore::InspectorCanvasAgent::didChangeCanvasMemory):
+        (WebCore::InspectorCanvasAgent::recordCanvasAction):
+        (WebCore::InspectorCanvasAgent::didFinishRecordingCanvasFrame):
+        (WebCore::InspectorCanvasAgent::consoleStartRecordingCanvas):
+        (WebCore::InspectorCanvasAgent::didEnableExtension):
+        (WebCore::InspectorCanvasAgent::didCreateProgram):
+        (WebCore::InspectorCanvasAgent::canvasDestroyedTimerFired):
+        (WebCore::InspectorCanvasAgent::canvasRecordingTimerFired):
+        (WebCore::InspectorCanvasAgent::clearCanvasData):
+        (WebCore::InspectorCanvasAgent::unbindCanvas):
+        (WebCore::InspectorCanvasAgent::findInspectorCanvas):
+        (WebCore::InspectorCanvasAgent::unbindProgram):
+        (WebCore::InspectorCanvasAgent::didCreateCSSCanvas): Deleted.
+        (WebCore::InspectorCanvasAgent::canvasDestroyed): Deleted.
+
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::didCreateCanvasRenderingContext):
+        (WebCore::InspectorInstrumentation::willDestroyCanvasRenderingContext):
+        (WebCore::InspectorInstrumentation::didChangeCanvasMemory):
+        (WebCore::InspectorInstrumentation::recordCanvasAction):
+        (WebCore::InspectorInstrumentation::didFinishRecordingCanvasFrame):
+        (WebCore::InspectorInstrumentation::didEnableExtension):
+        (WebCore::InspectorInstrumentation::didCreateProgram):
+        (WebCore::InspectorInstrumentation::willDeleteProgram):
+        (WebCore::InspectorInstrumentation::isShaderProgramDisabled):
+        (WebCore::InspectorInstrumentation::consoleStartRecordingCanvas):
+        (WebCore::InspectorInstrumentation::didCreateCSSCanvas): Deleted.
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::consoleStartRecordingCanvasImpl):
+        (WebCore::InspectorInstrumentation::didChangeCSSCanvasClientNodesImpl):
+        (WebCore::InspectorInstrumentation::didCreateCanvasRenderingContextImpl):
+        (WebCore::InspectorInstrumentation::willDestroyCanvasRenderingContextImpl):
+        (WebCore::InspectorInstrumentation::didChangeCanvasMemoryImpl):
+        (WebCore::InspectorInstrumentation::didFinishRecordingCanvasFrameImpl):
+        (WebCore::InspectorInstrumentation::didEnableExtensionImpl):
+        (WebCore::InspectorInstrumentation::didCreateProgramImpl):
+        (WebCore::InspectorInstrumentation::didCreateCSSCanvasImpl): Deleted.
+
+        * page/PageConsoleClient.cpp:
+        (WebCore::PageConsoleClient::record):
+        (WebCore::PageConsoleClient::recordEnd):
+
+        * dom/Document.h:
+        * dom/Document.cpp:
+        (WebCore::Document::getCSSCanvasElement):
+        (WebCore::Document::nameForCSSCanvasElement const):
+        We have no reason to save the CSS canvas name for each InspectorCanvas object, so instead we
+        can just query for the name based on the CanvasRenderingContext's HTMLCanvasElement (assuming
+        it is not an OffscreenCanvas) when we need it.
+
 2017-12-14  Chris Dumez  <cdumez@apple.com>
 
         self.importScripts() should obey updateViaCache inside service workers
index a1d0e4d..ac9f535 100644 (file)
@@ -5699,13 +5699,20 @@ std::optional<RenderingContext> Document::getCSSCanvasContext(const String& type
 HTMLCanvasElement* Document::getCSSCanvasElement(const String& name)
 {
     RefPtr<HTMLCanvasElement>& element = m_cssCanvasElements.add(name, nullptr).iterator->value;
-    if (!element) {
+    if (!element)
         element = HTMLCanvasElement::create(*this);
-        InspectorInstrumentation::didCreateCSSCanvas(*element, name);
-    }
     return element.get();
 }
 
+String Document::nameForCSSCanvasElement(const HTMLCanvasElement& canvasElement) const
+{
+    for (const auto& entry : m_cssCanvasElements) {
+        if (entry.value.get() == &canvasElement)
+            return entry.key;
+    }
+    return String();
+}
+
 #if ENABLE(TEXT_AUTOSIZING)
 TextAutoSizing& Document::textAutoSizing()
 {
index bce8c1b..26722cb 100644 (file)
@@ -988,6 +988,7 @@ public:
     // Extension for manipulating canvas drawing contexts for use in CSS
     std::optional<RenderingContext> getCSSCanvasContext(const String& type, const String& name, int width, int height);
     HTMLCanvasElement* getCSSCanvasElement(const String& name);
+    String nameForCSSCanvasElement(const HTMLCanvasElement&) const;
 
     bool isDNSPrefetchEnabled() const { return m_isDNSPrefetchEnabled; }
     void parseDNSPrefetchControlHeader(const String&);
index 9b5e282..e31de83 100644 (file)
@@ -370,13 +370,11 @@ CanvasRenderingContext2D* HTMLCanvasElement::createContext2d(const String& type)
         return nullptr;
     }
 
-    m_context = std::make_unique<CanvasRenderingContext2D>(*this, document().inQuirksMode(), usesDashboardCompatibilityMode);
+    m_context = CanvasRenderingContext2D::create(*this, document().inQuirksMode(), usesDashboardCompatibilityMode);
 
     downcast<CanvasRenderingContext2D>(*m_context).setUsesDisplayListDrawing(m_usesDisplayListDrawing);
     downcast<CanvasRenderingContext2D>(*m_context).setTracksDisplayListReplay(m_tracksDisplayListReplay);
 
-    InspectorInstrumentation::didCreateCanvasRenderingContext(*this);
-
 #if USE(IOSURFACE_CANVAS_BACKING_STORE) || ENABLE(ACCELERATED_2D_CANVAS)
     // Need to make sure a RenderLayer and compositing layer get created for the Canvas.
     invalidateStyleAndLayerComposition();
@@ -441,8 +439,6 @@ WebGLRenderingContextBase* HTMLCanvasElement::createContextWebGL(const String& t
     if (m_context) {
         // Need to make sure a RenderLayer and compositing layer get created for the Canvas.
         invalidateStyleAndLayerComposition();
-
-        InspectorInstrumentation::didCreateCanvasRenderingContext(*this);
     }
 
     return downcast<WebGLRenderingContextBase>(m_context.get());
@@ -484,8 +480,6 @@ WebGPURenderingContext* HTMLCanvasElement::createContextWebGPU(const String& typ
     if (m_context) {
         // Need to make sure a RenderLayer and compositing layer get created for the Canvas.
         invalidateStyleAndLayerComposition();
-
-        InspectorInstrumentation::didCreateCanvasRenderingContext(*this);
     }
 
     return static_cast<WebGPURenderingContext*>(m_context.get());
@@ -517,9 +511,7 @@ ImageBitmapRenderingContext* HTMLCanvasElement::createContextBitmapRenderer(cons
     ASSERT_UNUSED(type, HTMLCanvasElement::isBitmapRendererType(type));
     ASSERT(!m_context);
 
-    m_context = std::make_unique<ImageBitmapRenderingContext>(*this, WTFMove(settings));
-
-    InspectorInstrumentation::didCreateCanvasRenderingContext(*this);
+    m_context = ImageBitmapRenderingContext::create(*this, WTFMove(settings));
 
 #if USE(IOSURFACE_CANVAS_BACKING_STORE) || ENABLE(ACCELERATED_2D_CANVAS)
     // Need to make sure a RenderLayer and compositing layer get created for the Canvas.
@@ -634,7 +626,7 @@ bool HTMLCanvasElement::paintsIntoCanvasBuffer() const
 void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r)
 {
     if (UNLIKELY(m_context && m_context->callTracingActive()))
-        InspectorInstrumentation::didFinishRecordingCanvasFrame(*this);
+        InspectorInstrumentation::didFinishRecordingCanvasFrame(*m_context);
 
     // Clear the dirty rect
     m_dirtyRect = FloatRect();
@@ -989,8 +981,8 @@ void HTMLCanvasElement::setImageBuffer(std::unique_ptr<ImageBuffer>&& buffer) co
     size_t currentMemoryCost = memoryCost();
     activePixelMemory += currentMemoryCost;
 
-    if (m_imageBuffer && previousMemoryCost != currentMemoryCost)
-        InspectorInstrumentation::didChangeCanvasMemory(const_cast<HTMLCanvasElement&>(*this));
+    if (m_context && m_imageBuffer && previousMemoryCost != currentMemoryCost)
+        InspectorInstrumentation::didChangeCanvasMemory(*m_context);
 }
 
 void HTMLCanvasElement::setImageBufferAndMarkDirty(std::unique_ptr<ImageBuffer>&& buffer)
index e76bd2b..17c7b02 100644 (file)
@@ -32,6 +32,7 @@
 #include "HTMLVideoElement.h"
 #include "Image.h"
 #include "ImageBitmap.h"
+#include "InspectorInstrumentation.h"
 #include "OffscreenCanvas.h"
 #include "URL.h"
 #include "SecurityOrigin.h"
@@ -43,6 +44,11 @@ CanvasRenderingContext::CanvasRenderingContext(CanvasBase& canvas)
 {
 }
 
+CanvasRenderingContext::~CanvasRenderingContext()
+{
+    InspectorInstrumentation::willDestroyCanvasRenderingContext(*this);
+}
+
 void CanvasRenderingContext::ref()
 {
     m_canvas.refCanvasBase();
index 80cd95e..113ff38 100644 (file)
@@ -44,7 +44,7 @@ class WebGLObject;
 class CanvasRenderingContext : public ScriptWrappable {
     WTF_MAKE_NONCOPYABLE(CanvasRenderingContext); WTF_MAKE_FAST_ALLOCATED;
 public:
-    virtual ~CanvasRenderingContext() = default;
+    virtual ~CanvasRenderingContext();
 
     void ref();
     void deref();
index aecf56b..9a66da7 100644 (file)
@@ -42,6 +42,7 @@
 #include "ImageBitmap.h"
 #include "ImageBuffer.h"
 #include "ImageData.h"
+#include "InspectorInstrumentation.h"
 #include "Path2D.h"
 #include "RenderElement.h"
 #include "RenderImage.h"
@@ -67,6 +68,15 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
+std::unique_ptr<CanvasRenderingContext2D> CanvasRenderingContext2D::create(CanvasBase& canvas, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode)
+{
+    auto renderingContext = std::unique_ptr<CanvasRenderingContext2D>(new CanvasRenderingContext2D(canvas, usesCSSCompatibilityParseMode, usesDashboardCompatibilityMode));
+
+    InspectorInstrumentation::didCreateCanvasRenderingContext(*renderingContext);
+
+    return renderingContext;
+}
+
 CanvasRenderingContext2D::CanvasRenderingContext2D(CanvasBase& canvas, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode)
     : CanvasRenderingContext2DBase(canvas, usesCSSCompatibilityParseMode, usesDashboardCompatibilityMode)
 {
index dffb5a7..22c46ff 100644 (file)
@@ -30,6 +30,7 @@
 #include "CanvasTextBaseline.h"
 #include "FontCascade.h"
 #include "FontSelectorClient.h"
+#include <memory>
 
 namespace WebCore {
 
@@ -37,7 +38,8 @@ class TextMetrics;
 
 class CanvasRenderingContext2D final : public CanvasRenderingContext2DBase {
 public:
-    CanvasRenderingContext2D(CanvasBase&, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode);
+    static std::unique_ptr<CanvasRenderingContext2D> create(CanvasBase&, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode);
+
     virtual ~CanvasRenderingContext2D();
 
     HTMLCanvasElement& canvas() const { return downcast<HTMLCanvasElement>(canvasBase()); }
@@ -66,6 +68,8 @@ public:
     bool is2d() const override { return true; }
 
 private:
+    CanvasRenderingContext2D(CanvasBase&, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode);
+
     // The relationship between FontCascade and CanvasRenderingContext2D::FontProxy must hold certain invariants.
     // Therefore, all font operations must pass through the State.
     const FontProxy& fontProxy();
index 9b2dd05..84899fa 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "ImageBitmap.h"
 #include "ImageBuffer.h"
+#include "InspectorInstrumentation.h"
 
 namespace WebCore {
 
@@ -37,6 +38,15 @@ static RenderingMode bufferRenderingMode = Accelerated;
 static RenderingMode bufferRenderingMode = Unaccelerated;
 #endif
 
+std::unique_ptr<ImageBitmapRenderingContext> ImageBitmapRenderingContext::create(CanvasBase& canvas, ImageBitmapRenderingContextSettings&& settings)
+{
+    auto renderingContext = std::unique_ptr<ImageBitmapRenderingContext>(new ImageBitmapRenderingContext(canvas, WTFMove(settings)));
+
+    InspectorInstrumentation::didCreateCanvasRenderingContext(*renderingContext);
+
+    return renderingContext;
+}
+
 ImageBitmapRenderingContext::ImageBitmapRenderingContext(CanvasBase& canvas, ImageBitmapRenderingContextSettings&& settings)
     : CanvasRenderingContext(canvas)
     , m_settings(WTFMove(settings))
index 6887bc0..257926b 100644 (file)
@@ -30,6 +30,7 @@
 #include "ExceptionOr.h"
 #include "ImageBitmapRenderingContextSettings.h"
 #include "ImageBufferData.h"
+#include <memory>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
@@ -39,13 +40,13 @@ class ImageBuffer;
 
 class ImageBitmapRenderingContext final : public CanvasRenderingContext {
 public:
+    static std::unique_ptr<ImageBitmapRenderingContext> create(CanvasBase&, ImageBitmapRenderingContextSettings&&);
 
     enum class BitmapMode {
         Valid,
         Blank
     };
 
-    ImageBitmapRenderingContext(CanvasBase&, ImageBitmapRenderingContextSettings&&);
     ~ImageBitmapRenderingContext();
 
     HTMLCanvasElement* canvas() const;
@@ -56,6 +57,8 @@ public:
     bool hasAlpha() { return m_settings.alpha; }
 
 private:
+    ImageBitmapRenderingContext(CanvasBase&, ImageBitmapRenderingContextSettings&&);
+
     bool isBitmapRenderer() const final { return true; }
     bool isAccelerated() const override;
 
index b969325..b24a0fa 100644 (file)
 
 namespace WebCore {
 
+std::unique_ptr<WebGL2RenderingContext> WebGL2RenderingContext::create(CanvasBase& canvas, GraphicsContext3DAttributes attributes)
+{
+    auto renderingContext = std::unique_ptr<WebGL2RenderingContext>(new WebGL2RenderingContext(canvas, attributes));
+
+    InspectorInstrumentation::didCreateCanvasRenderingContext(*renderingContext);
+
+    return renderingContext;
+}
+
+std::unique_ptr<WebGL2RenderingContext> WebGL2RenderingContext::create(CanvasBase& canvas, Ref<GraphicsContext3D>&& context, GraphicsContext3DAttributes attributes)
+{
+    auto renderingContext = std::unique_ptr<WebGL2RenderingContext>(new WebGL2RenderingContext(canvas, WTFMove(context), attributes));
+
+    InspectorInstrumentation::didCreateCanvasRenderingContext(*renderingContext);
+
+    return renderingContext;
+}
+
 WebGL2RenderingContext::WebGL2RenderingContext(CanvasBase& canvas, GraphicsContext3DAttributes attributes)
     : WebGLRenderingContextBase(canvas, attributes)
 {
index d3337da..7ad38f2 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(WEBGL2)
 
 #include "WebGLRenderingContextBase.h"
+#include <memory>
 
 namespace WebCore {
 
@@ -39,8 +40,8 @@ class WebGLVertexArrayObject;
 
 class WebGL2RenderingContext final : public WebGLRenderingContextBase {
 public:
-    WebGL2RenderingContext(CanvasBase&, WebGLContextAttributes);
-    WebGL2RenderingContext(CanvasBase&, Ref<GraphicsContext3D>&&, WebGLContextAttributes);
+    static std::unique_ptr<WebGL2RenderingContext> create(CanvasBase&, GraphicsContext3DAttributes);
+    static std::unique_ptr<WebGL2RenderingContext> create(CanvasBase&, Ref<GraphicsContext3D>&&, GraphicsContext3DAttributes);
 
     // Buffer objects
     using WebGLRenderingContextBase::bufferData;
@@ -199,6 +200,9 @@ public:
     void hint(GC3Denum target, GC3Denum mode) final;
 
 private:
+    WebGL2RenderingContext(CanvasBase&, GraphicsContext3DAttributes);
+    WebGL2RenderingContext(CanvasBase&, Ref<GraphicsContext3D>&&, GraphicsContext3DAttributes);
+
     bool isWebGL2() const final { return true; }
 
     void initializeVertexArrayObjects() final;
index f4f948e..6dcd7d4 100644 (file)
 
 namespace WebCore {
 
+std::unique_ptr<WebGLRenderingContext> WebGLRenderingContext::create(CanvasBase& canvas, GraphicsContext3DAttributes attributes)
+{
+    auto renderingContext = std::unique_ptr<WebGLRenderingContext>(new WebGLRenderingContext(canvas, attributes));
+
+    InspectorInstrumentation::didCreateCanvasRenderingContext(*renderingContext);
+
+    return renderingContext;
+}
+
+std::unique_ptr<WebGLRenderingContext> WebGLRenderingContext::create(CanvasBase& canvas, Ref<GraphicsContext3D>&& context, GraphicsContext3DAttributes attributes)
+{
+    auto renderingContext = std::unique_ptr<WebGLRenderingContext>(new WebGLRenderingContext(canvas, WTFMove(context), attributes));
+
+    InspectorInstrumentation::didCreateCanvasRenderingContext(*renderingContext);
+
+    return renderingContext;
+}
+
 WebGLRenderingContext::WebGLRenderingContext(CanvasBase& canvas, GraphicsContext3DAttributes attributes)
     : WebGLRenderingContextBase(canvas, attributes)
 {
index 240e079..bacf9eb 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "WebGLRenderingContextBase.h"
+#include <memory>
 
 #if ENABLE(WEBGL)
 
@@ -33,8 +34,8 @@ namespace WebCore {
 
 class WebGLRenderingContext final : public WebGLRenderingContextBase {
 public:
-    WebGLRenderingContext(CanvasBase&, GraphicsContext3DAttributes);
-    WebGLRenderingContext(CanvasBase&, Ref<GraphicsContext3D>&&, GraphicsContext3DAttributes);
+    static std::unique_ptr<WebGLRenderingContext> create(CanvasBase&, GraphicsContext3DAttributes);
+    static std::unique_ptr<WebGLRenderingContext> create(CanvasBase&, Ref<GraphicsContext3D>&&, GraphicsContext3DAttributes);
 
     bool isWebGL1() const final { return true; }
 
@@ -54,6 +55,10 @@ public:
     bool validateIndexArrayConservative(GC3Denum type, unsigned& numElementsRequired) final;
     bool validateBlendEquation(const char* functionName, GC3Denum mode) final;
     bool validateCapability(const char* functionName, GC3Denum cap) final;
+
+private:
+    WebGLRenderingContext(CanvasBase&, GraphicsContext3DAttributes);
+    WebGLRenderingContext(CanvasBase&, Ref<GraphicsContext3D>&&, GraphicsContext3DAttributes);
 };
 
 } // namespace WebCore
index 1255c39..70e2b3e 100644 (file)
@@ -438,10 +438,10 @@ std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(Can
         std::unique_ptr<WebGLRenderingContextBase> renderingContext = nullptr;
 #if ENABLE(WEBGL2)
         if (type == "webgl2")
-            renderingContext = std::make_unique<WebGL2RenderingContext>(canvas, attributes);
+            renderingContext = WebGL2RenderingContext::create(canvas, attributes);
         else
 #endif
-            renderingContext = std::make_unique<WebGLRenderingContext>(canvas, attributes);
+            renderingContext = WebGLRenderingContext::create(canvas, attributes);
         renderingContext->suspendIfNeeded();
         return renderingContext;
     }
@@ -467,10 +467,10 @@ std::unique_ptr<WebGLRenderingContextBase> WebGLRenderingContextBase::create(Can
     std::unique_ptr<WebGLRenderingContextBase> renderingContext;
 #if ENABLE(WEBGL2)
     if (type == "webgl2")
-        renderingContext = std::make_unique<WebGL2RenderingContext>(canvas, context.releaseNonNull(), attributes);
+        renderingContext = WebGL2RenderingContext::create(canvas, context.releaseNonNull(), attributes);
     else
 #endif
-        renderingContext = std::make_unique<WebGLRenderingContext>(canvas, context.releaseNonNull(), attributes);
+        renderingContext = WebGLRenderingContext::create(canvas, context.releaseNonNull(), attributes);
     renderingContext->suspendIfNeeded();
 
     return renderingContext;
index 59d8dfc..b4c259e 100644 (file)
@@ -32,6 +32,7 @@
 #include "Document.h"
 #include "FrameView.h"
 #include "GPUDevice.h"
+#include "InspectorInstrumentation.h"
 #include "WebGPUBuffer.h"
 #include "WebGPUCommandQueue.h"
 #include "WebGPUComputePipelineState.h"
@@ -80,10 +81,11 @@ std::unique_ptr<WebGPURenderingContext> WebGPURenderingContext::create(CanvasBas
         return nullptr;
     }
 
-    std::unique_ptr<WebGPURenderingContext> renderingContext = nullptr;
-    renderingContext = std::unique_ptr<WebGPURenderingContext>(new WebGPURenderingContext(canvas, device.releaseNonNull()));
+    auto renderingContext = std::unique_ptr<WebGPURenderingContext>(new WebGPURenderingContext(canvas, device.releaseNonNull()));
     renderingContext->suspendIfNeeded();
 
+    InspectorInstrumentation::didCreateCanvasRenderingContext(*renderingContext);
+
     return renderingContext;
 }
 
index 87a8bd2..ec4a0b7 100644 (file)
 #include "CachedImage.h"
 #include "CanvasGradient.h"
 #include "CanvasPattern.h"
+#include "CanvasRenderingContext.h"
 #include "CanvasRenderingContext2D.h"
 #include "Document.h"
 #include "FloatPoint.h"
-#include "Frame.h"
 #include "Gradient.h"
 #include "HTMLCanvasElement.h"
 #include "HTMLImageElement.h"
@@ -44,7 +44,6 @@
 #include "ImageBuffer.h"
 #include "ImageData.h"
 #include "InspectorDOMAgent.h"
-#include "InspectorPageAgent.h"
 #include "InstrumentingAgents.h"
 #include "JSCanvasDirection.h"
 #include "JSCanvasFillRule.h"
@@ -78,15 +77,14 @@ namespace WebCore {
 
 using namespace Inspector;
 
-Ref<InspectorCanvas> InspectorCanvas::create(HTMLCanvasElement& canvas, const String& cssCanvasName)
+Ref<InspectorCanvas> InspectorCanvas::create(CanvasRenderingContext& context)
 {
-    return adoptRef(*new InspectorCanvas(canvas, cssCanvasName));
+    return adoptRef(*new InspectorCanvas(context));
 }
 
-InspectorCanvas::InspectorCanvas(HTMLCanvasElement& canvas, const String& cssCanvasName)
+InspectorCanvas::InspectorCanvas(CanvasRenderingContext& context)
     : m_identifier("canvas:" + IdentifiersFactory::createIdentifier())
-    , m_canvas(canvas)
-    , m_cssCanvasName(cssCanvasName)
+    , m_context(context)
 {
 }
 
@@ -95,6 +93,13 @@ InspectorCanvas::~InspectorCanvas()
     resetRecordingData();
 }
 
+HTMLCanvasElement* InspectorCanvas::canvasElement()
+{
+    if (is<HTMLCanvasElement>(m_context.canvasBase()))
+        return downcast<HTMLCanvasElement>(&m_context.canvasBase());
+    return nullptr;
+}
+
 void InspectorCanvas::resetRecordingData()
 {
     m_initialState = nullptr;
@@ -108,7 +113,7 @@ void InspectorCanvas::resetRecordingData()
     m_bufferUsed = 0;
     m_singleFrame = true;
 
-    m_canvas.renderingContext()->setCallTracingActive(false);
+    m_context.setCallTracingActive(false);
 }
 
 bool InspectorCanvas::hasRecordingData() const
@@ -157,7 +162,7 @@ void InspectorCanvas::recordAction(const String& name, Vector<RecordCanvasAction
     m_currentActions->addItem(action);
 
 #if ENABLE(WEBGL)
-    if (is<WebGLRenderingContext>(m_canvas.renderingContext()) && shouldSnapshotWebGLAction(name))
+    if (is<WebGLRenderingContext>(m_context) && shouldSnapshotWebGLAction(name))
         m_actionNeedingSnapshot = action;
 #endif
 }
@@ -212,25 +217,21 @@ bool InspectorCanvas::hasBufferSpace() const
 
 Ref<Inspector::Protocol::Canvas::Canvas> InspectorCanvas::buildObjectForCanvas(InstrumentingAgents& instrumentingAgents, bool captureBacktrace)
 {
-    Document& document = m_canvas.document();
-    Frame* frame = document.frame();
-    CanvasRenderingContext* context = m_canvas.renderingContext();
-
     Inspector::Protocol::Canvas::ContextType contextType;
-    if (is<CanvasRenderingContext2D>(context))
+    if (is<CanvasRenderingContext2D>(m_context))
         contextType = Inspector::Protocol::Canvas::ContextType::Canvas2D;
-    else if (is<ImageBitmapRenderingContext>(context))
+    else if (is<ImageBitmapRenderingContext>(m_context))
         contextType = Inspector::Protocol::Canvas::ContextType::BitmapRenderer;
 #if ENABLE(WEBGL)
-    else if (is<WebGLRenderingContext>(context))
+    else if (is<WebGLRenderingContext>(m_context))
         contextType = Inspector::Protocol::Canvas::ContextType::WebGL;
 #endif
 #if ENABLE(WEBGL2)
-    else if (is<WebGL2RenderingContext>(context))
+    else if (is<WebGL2RenderingContext>(m_context))
         contextType = Inspector::Protocol::Canvas::ContextType::WebGL2;
 #endif
 #if ENABLE(WEBGPU)
-    else if (is<WebGPURenderingContext>(context))
+    else if (is<WebGPURenderingContext>(m_context))
         contextType = Inspector::Protocol::Canvas::ContextType::WebGPU;
 #endif
     else {
@@ -240,35 +241,37 @@ Ref<Inspector::Protocol::Canvas::Canvas> InspectorCanvas::buildObjectForCanvas(I
 
     auto canvas = Inspector::Protocol::Canvas::Canvas::create()
         .setCanvasId(m_identifier)
-        .setFrameId(instrumentingAgents.inspectorPageAgent()->frameId(frame))
         .setContextType(contextType)
         .release();
 
-    if (!m_cssCanvasName.isEmpty())
-        canvas->setCssCanvasName(m_cssCanvasName);
-    else {
-        InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent();
-        int nodeId = domAgent->boundNodeId(&m_canvas);
-        if (!nodeId) {
-            if (int documentNodeId = domAgent->boundNodeId(&m_canvas.document())) {
-                ErrorString ignored;
-                nodeId = domAgent->pushNodeToFrontend(ignored, documentNodeId, &m_canvas);
+    if (auto* node = canvasElement()) {
+        String cssCanvasName = node->document().nameForCSSCanvasElement(*node);
+        if (!cssCanvasName.isEmpty())
+            canvas->setCssCanvasName(cssCanvasName);
+        else {
+            InspectorDOMAgent* domAgent = instrumentingAgents.inspectorDOMAgent();
+            int nodeId = domAgent->boundNodeId(node);
+            if (!nodeId) {
+                if (int documentNodeId = domAgent->boundNodeId(&node->document())) {
+                    ErrorString ignored;
+                    nodeId = domAgent->pushNodeToFrontend(ignored, documentNodeId, node);
+                }
             }
-        }
 
-        if (nodeId)
-            canvas->setNodeId(nodeId);
+            if (nodeId)
+                canvas->setNodeId(nodeId);
+        }
     }
 
-    if (is<ImageBitmapRenderingContext>(context)) {
+    if (is<ImageBitmapRenderingContext>(m_context)) {
         auto contextAttributes = Inspector::Protocol::Canvas::ContextAttributes::create()
             .release();
-        contextAttributes->setAlpha(downcast<ImageBitmapRenderingContext>(context)->hasAlpha());
+        contextAttributes->setAlpha(downcast<ImageBitmapRenderingContext>(m_context).hasAlpha());
         canvas->setContextAttributes(WTFMove(contextAttributes));
     }
 #if ENABLE(WEBGL)
-    else if (is<WebGLRenderingContextBase>(context)) {
-        if (std::optional<WebGLContextAttributes> attributes = downcast<WebGLRenderingContextBase>(context)->getContextAttributes()) {
+    else if (is<WebGLRenderingContextBase>(m_context)) {
+        if (std::optional<WebGLContextAttributes> attributes = downcast<WebGLRenderingContextBase>(m_context).getContextAttributes()) {
             auto contextAttributes = Inspector::Protocol::Canvas::ContextAttributes::create()
                 .release();
             contextAttributes->setAlpha(attributes->alpha);
@@ -283,8 +286,12 @@ Ref<Inspector::Protocol::Canvas::Canvas> InspectorCanvas::buildObjectForCanvas(I
     }
 #endif
 
-    if (size_t memoryCost = m_canvas.memoryCost())
-        canvas->setMemoryCost(memoryCost);
+    // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
+
+    if (auto* node = canvasElement()) {
+        if (size_t memoryCost = node->memoryCost())
+            canvas->setMemoryCost(memoryCost);
+    }
 
     if (captureBacktrace) {
         auto stackTrace = Inspector::createScriptCallStack(JSMainThreadExecState::currentState(), Inspector::ScriptCallStack::maxCallStackSizeToCapture);
@@ -305,17 +312,22 @@ void InspectorCanvas::appendActionSnapshotIfNeeded()
 
 String InspectorCanvas::getCanvasContentAsDataURL()
 {
+    // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
+
+    auto* node = canvasElement();
+    if (!node)
+        return String();
+
 #if ENABLE(WEBGL)
-    CanvasRenderingContext* canvasRenderingContext = m_canvas.renderingContext();
-    if (is<WebGLRenderingContextBase>(canvasRenderingContext))
-        downcast<WebGLRenderingContextBase>(canvasRenderingContext)->setPreventBufferClearForInspector(true);
+    if (is<WebGLRenderingContextBase>(m_context))
+        downcast<WebGLRenderingContextBase>(m_context).setPreventBufferClearForInspector(true);
 #endif
 
-    ExceptionOr<UncachedString> result = m_canvas.toDataURL(ASCIILiteral("image/png"));
+    ExceptionOr<UncachedString> result = node->toDataURL(ASCIILiteral("image/png"));
 
 #if ENABLE(WEBGL)
-    if (is<WebGLRenderingContextBase>(canvasRenderingContext))
-        downcast<WebGLRenderingContextBase>(canvasRenderingContext)->setPreventBufferClearForInspector(false);
+    if (is<WebGLRenderingContextBase>(m_context))
+        downcast<WebGLRenderingContextBase>(m_context).setPreventBufferClearForInspector(false);
 #endif
 
     if (result.hasException())
@@ -431,27 +443,26 @@ RefPtr<Inspector::Protocol::Recording::InitialState> InspectorCanvas::buildIniti
         .release();
 
     auto attributes = JSON::Object::create();
-    attributes->setInteger(ASCIILiteral("width"), canvas().width());
-    attributes->setInteger(ASCIILiteral("height"), canvas().height());
+    attributes->setInteger(ASCIILiteral("width"), m_context.canvasBase().width());
+    attributes->setInteger(ASCIILiteral("height"), m_context.canvasBase().height());
 
     auto parameters = JSON::ArrayOf<JSON::Value>::create();
 
-    CanvasRenderingContext* canvasRenderingContext = canvas().renderingContext();
-    if (is<CanvasRenderingContext2D>(canvasRenderingContext)) {
-        const CanvasRenderingContext2D* context2d = downcast<CanvasRenderingContext2D>(canvasRenderingContext);
-        const CanvasRenderingContext2D::State& state = context2d->state();
+    if (is<CanvasRenderingContext2D>(m_context)) {
+        const CanvasRenderingContext2D& context2d = downcast<CanvasRenderingContext2D>(m_context);
+        const CanvasRenderingContext2D::State& state = context2d.state();
 
         attributes->setArray(ASCIILiteral("setTransform"), buildArrayForAffineTransform(state.transform));
-        attributes->setDouble(ASCIILiteral("globalAlpha"), context2d->globalAlpha());
-        attributes->setInteger(ASCIILiteral("globalCompositeOperation"), indexForData(context2d->globalCompositeOperation()));
-        attributes->setDouble(ASCIILiteral("lineWidth"), context2d->lineWidth());
-        attributes->setInteger(ASCIILiteral("lineCap"), indexForData(convertEnumerationToString(context2d->lineCap())));
-        attributes->setInteger(ASCIILiteral("lineJoin"), indexForData(convertEnumerationToString(context2d->lineJoin())));
-        attributes->setDouble(ASCIILiteral("miterLimit"), context2d->miterLimit());
-        attributes->setDouble(ASCIILiteral("shadowOffsetX"), context2d->shadowOffsetX());
-        attributes->setDouble(ASCIILiteral("shadowOffsetY"), context2d->shadowOffsetY());
-        attributes->setDouble(ASCIILiteral("shadowBlur"), context2d->shadowBlur());
-        attributes->setInteger(ASCIILiteral("shadowColor"), indexForData(context2d->shadowColor()));
+        attributes->setDouble(ASCIILiteral("globalAlpha"), context2d.globalAlpha());
+        attributes->setInteger(ASCIILiteral("globalCompositeOperation"), indexForData(context2d.globalCompositeOperation()));
+        attributes->setDouble(ASCIILiteral("lineWidth"), context2d.lineWidth());
+        attributes->setInteger(ASCIILiteral("lineCap"), indexForData(convertEnumerationToString(context2d.lineCap())));
+        attributes->setInteger(ASCIILiteral("lineJoin"), indexForData(convertEnumerationToString(context2d.lineJoin())));
+        attributes->setDouble(ASCIILiteral("miterLimit"), context2d.miterLimit());
+        attributes->setDouble(ASCIILiteral("shadowOffsetX"), context2d.shadowOffsetX());
+        attributes->setDouble(ASCIILiteral("shadowOffsetY"), context2d.shadowOffsetY());
+        attributes->setDouble(ASCIILiteral("shadowBlur"), context2d.shadowBlur());
+        attributes->setInteger(ASCIILiteral("shadowColor"), indexForData(context2d.shadowColor()));
 
         // The parameter to `setLineDash` is itself an array, so we need to wrap the parameters
         // list in an array to allow spreading.
@@ -459,11 +470,11 @@ RefPtr<Inspector::Protocol::Recording::InitialState> InspectorCanvas::buildIniti
         setLineDash->addItem(buildArrayForVector(state.lineDash));
         attributes->setArray(ASCIILiteral("setLineDash"), WTFMove(setLineDash));
 
-        attributes->setDouble(ASCIILiteral("lineDashOffset"), context2d->lineDashOffset());
-        attributes->setInteger(ASCIILiteral("font"), indexForData(context2d->font()));
-        attributes->setInteger(ASCIILiteral("textAlign"), indexForData(convertEnumerationToString(context2d->textAlign())));
-        attributes->setInteger(ASCIILiteral("textBaseline"), indexForData(convertEnumerationToString(context2d->textBaseline())));
-        attributes->setInteger(ASCIILiteral("direction"), indexForData(convertEnumerationToString(context2d->direction())));
+        attributes->setDouble(ASCIILiteral("lineDashOffset"), context2d.lineDashOffset());
+        attributes->setInteger(ASCIILiteral("font"), indexForData(context2d.font()));
+        attributes->setInteger(ASCIILiteral("textAlign"), indexForData(convertEnumerationToString(context2d.textAlign())));
+        attributes->setInteger(ASCIILiteral("textBaseline"), indexForData(convertEnumerationToString(context2d.textBaseline())));
+        attributes->setInteger(ASCIILiteral("direction"), indexForData(convertEnumerationToString(context2d.direction())));
 
         int strokeStyleIndex;
         if (auto canvasGradient = state.strokeStyle.canvasGradient())
@@ -483,17 +494,17 @@ RefPtr<Inspector::Protocol::Recording::InitialState> InspectorCanvas::buildIniti
             fillStyleIndex = indexForData(state.fillStyle.color());
         attributes->setInteger(ASCIILiteral("fillStyle"), fillStyleIndex);
 
-        attributes->setBoolean(ASCIILiteral("imageSmoothingEnabled"), context2d->imageSmoothingEnabled());
-        attributes->setInteger(ASCIILiteral("imageSmoothingQuality"), indexForData(convertEnumerationToString(context2d->imageSmoothingQuality())));
+        attributes->setBoolean(ASCIILiteral("imageSmoothingEnabled"), context2d.imageSmoothingEnabled());
+        attributes->setInteger(ASCIILiteral("imageSmoothingQuality"), indexForData(convertEnumerationToString(context2d.imageSmoothingQuality())));
 
         auto setPath = JSON::ArrayOf<JSON::Value>::create();
-        setPath->addItem(indexForData(buildStringFromPath(context2d->getPath()->path())));
+        setPath->addItem(indexForData(buildStringFromPath(context2d.getPath()->path())));
         attributes->setArray(ASCIILiteral("setPath"), WTFMove(setPath));
     }
 #if ENABLE(WEBGL)
-    else if (is<WebGLRenderingContextBase>(canvasRenderingContext)) {
-        WebGLRenderingContextBase* contextWebGLBase = downcast<WebGLRenderingContextBase>(canvasRenderingContext);
-        if (std::optional<WebGLContextAttributes> attributes = contextWebGLBase->getContextAttributes()) {
+    else if (is<WebGLRenderingContextBase>(m_context)) {
+        WebGLRenderingContextBase& contextWebGLBase = downcast<WebGLRenderingContextBase>(m_context);
+        if (std::optional<WebGLContextAttributes> attributes = contextWebGLBase.getContextAttributes()) {
             RefPtr<JSON::Object> contextAttributes = JSON::Object::create();
             contextAttributes->setBoolean(ASCIILiteral("alpha"), attributes->alpha);
             contextAttributes->setBoolean(ASCIILiteral("depth"), attributes->depth);
index e91547f..7a224cd 100644 (file)
@@ -39,6 +39,7 @@ namespace WebCore {
 
 class CanvasGradient;
 class CanvasPattern;
+class CanvasRenderingContext;
 class HTMLCanvasElement;
 class HTMLImageElement;
 class HTMLVideoElement;
@@ -50,11 +51,12 @@ typedef String ErrorString;
 
 class InspectorCanvas final : public RefCounted<InspectorCanvas> {
 public:
-    static Ref<InspectorCanvas> create(HTMLCanvasElement&, const String& cssCanvasName);
+    static Ref<InspectorCanvas> create(CanvasRenderingContext&);
 
     const String& identifier() { return m_identifier; }
-    HTMLCanvasElement& canvas() { return m_canvas; }
-    const String& cssCanvasName() { return m_cssCanvasName; }
+    CanvasRenderingContext& context() { return m_context; }
+
+    HTMLCanvasElement* canvasElement();
 
     void resetRecordingData();
     bool hasRecordingData() const;
@@ -83,7 +85,7 @@ public:
     ~InspectorCanvas();
 
 private:
-    InspectorCanvas(HTMLCanvasElement&, const String& cssCanvasName);
+    InspectorCanvas(CanvasRenderingContext&);
     void appendActionSnapshotIfNeeded();
     String getCanvasContentAsDataURL();
 
@@ -109,8 +111,7 @@ private:
     RefPtr<JSON::ArrayOf<JSON::Value>> buildArrayForImageData(const ImageData&);
 
     String m_identifier;
-    HTMLCanvasElement& m_canvas;
-    String m_cssCanvasName;
+    CanvasRenderingContext& m_context;
 
     RefPtr<Inspector::Protocol::Recording::InitialState> m_initialState;
     RefPtr<JSON::ArrayOf<Inspector::Protocol::Recording::Frame>> m_frames;
index 82cbe7f..13501d1 100644 (file)
@@ -874,10 +874,10 @@ void InspectorInstrumentation::stopProfilingImpl(InstrumentingAgents& instrument
         timelineAgent->stopFromConsole(exec, title);
 }
 
-void InspectorInstrumentation::consoleStartRecordingCanvasImpl(InstrumentingAgents& instrumentingAgents, HTMLCanvasElement& canvasElement, JSC::ExecState& exec, JSC::JSObject* options)
+void InspectorInstrumentation::consoleStartRecordingCanvasImpl(InstrumentingAgents& instrumentingAgents, CanvasRenderingContext& context, JSC::ExecState& exec, JSC::JSObject* options)
 {
     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
-        canvasAgent->consoleStartRecordingCanvas(canvasElement, exec, options);
+        canvasAgent->consoleStartRecordingCanvas(context, exec, options);
 }
 
 void InspectorInstrumentation::didOpenDatabaseImpl(InstrumentingAgents& instrumentingAgents, RefPtr<Database>&& database, const String& domain, const String& name, const String& version)
@@ -958,28 +958,28 @@ void InspectorInstrumentation::didSendWebSocketFrameImpl(InstrumentingAgents& in
         networkAgent->didSendWebSocketFrame(identifier, frame);
 }
 
-void InspectorInstrumentation::didCreateCSSCanvasImpl(InstrumentingAgents& instrumentingAgents, HTMLCanvasElement& canvasElement, const String& name)
+void InspectorInstrumentation::didChangeCSSCanvasClientNodesImpl(InstrumentingAgents& instrumentingAgents, HTMLCanvasElement& canvasElement)
 {
     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
-        canvasAgent->didCreateCSSCanvas(canvasElement, name);
+        canvasAgent->didChangeCSSCanvasClientNodes(canvasElement);
 }
 
-void InspectorInstrumentation::didChangeCSSCanvasClientNodesImpl(InstrumentingAgents& instrumentingAgents, HTMLCanvasElement& canvasElement)
+void InspectorInstrumentation::didCreateCanvasRenderingContextImpl(InstrumentingAgents& instrumentingAgents, CanvasRenderingContext& context)
 {
     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
-        canvasAgent->didChangeCSSCanvasClientNodes(canvasElement);
+        canvasAgent->didCreateCanvasRenderingContext(context);
 }
 
-void InspectorInstrumentation::didCreateCanvasRenderingContextImpl(InstrumentingAgents& instrumentingAgents, HTMLCanvasElement& canvasElement)
+void InspectorInstrumentation::willDestroyCanvasRenderingContextImpl(InstrumentingAgents& instrumentingAgents, CanvasRenderingContext& context)
 {
     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
-        canvasAgent->didCreateCanvasRenderingContext(canvasElement);
+        canvasAgent->willDestroyCanvasRenderingContext(context);
 }
 
-void InspectorInstrumentation::didChangeCanvasMemoryImpl(InstrumentingAgents& instrumentingAgents, HTMLCanvasElement& canvasElement)
+void InspectorInstrumentation::didChangeCanvasMemoryImpl(InstrumentingAgents& instrumentingAgents, CanvasRenderingContext& context)
 {
     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
-        canvasAgent->didChangeCanvasMemory(canvasElement);
+        canvasAgent->didChangeCanvasMemory(context);
 }
 
 void InspectorInstrumentation::recordCanvasActionImpl(InstrumentingAgents& instrumentingAgents, CanvasRenderingContext& canvasRenderingContext, const String& name, Vector<RecordCanvasActionVariant>&& parameters)
@@ -988,23 +988,23 @@ void InspectorInstrumentation::recordCanvasActionImpl(InstrumentingAgents& instr
         canvasAgent->recordCanvasAction(canvasRenderingContext, name, WTFMove(parameters));
 }
 
-void InspectorInstrumentation::didFinishRecordingCanvasFrameImpl(InstrumentingAgents& instrumentingAgents, HTMLCanvasElement& canvasElement, bool forceDispatch)
+void InspectorInstrumentation::didFinishRecordingCanvasFrameImpl(InstrumentingAgents& instrumentingAgents, CanvasRenderingContext& context, bool forceDispatch)
 {
     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
-        canvasAgent->didFinishRecordingCanvasFrame(canvasElement, forceDispatch);
+        canvasAgent->didFinishRecordingCanvasFrame(context, forceDispatch);
 }
 
 #if ENABLE(WEBGL)
-void InspectorInstrumentation::didEnableExtensionImpl(InstrumentingAgents& instrumentingAgents, WebGLRenderingContextBase& context, const String& extension)
+void InspectorInstrumentation::didEnableExtensionImpl(InstrumentingAgents& instrumentingAgents, WebGLRenderingContextBase& contextWebGLBase, const String& extension)
 {
     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
-        canvasAgent->didEnableExtension(context, extension);
+        canvasAgent->didEnableExtension(contextWebGLBase, extension);
 }
 
-void InspectorInstrumentation::didCreateProgramImpl(InstrumentingAgents& instrumentingAgents, WebGLRenderingContextBase& context, WebGLProgram& program)
+void InspectorInstrumentation::didCreateProgramImpl(InstrumentingAgents& instrumentingAgents, WebGLRenderingContextBase& contextWebGLBase, WebGLProgram& program)
 {
     if (InspectorCanvasAgent* canvasAgent = instrumentingAgents.inspectorCanvasAgent())
-        canvasAgent->didCreateProgram(context, program);
+        canvasAgent->didCreateProgram(contextWebGLBase, program);
 }
 
 void InspectorInstrumentation::willDeleteProgramImpl(InstrumentingAgents& instrumentingAgents, WebGLProgram& program)
index a0ad311..a8b5a61 100644 (file)
@@ -225,7 +225,7 @@ public:
     static void consoleTimeStamp(Frame&, Ref<Inspector::ScriptArguments>&&);
     static void startProfiling(Page&, JSC::ExecState*, const String& title);
     static void stopProfiling(Page&, JSC::ExecState*, const String& title);
-    static void consoleStartRecordingCanvas(HTMLCanvasElement&, JSC::ExecState&, JSC::JSObject* options);
+    static void consoleStartRecordingCanvas(CanvasRenderingContext&, JSC::ExecState&, JSC::JSObject* options);
 
     static void didRequestAnimationFrame(Document&, int callbackId);
     static void didCancelAnimationFrame(Document&, int callbackId);
@@ -252,12 +252,12 @@ public:
     static void didHandleMemoryPressure(Page&, Critical);
 #endif
 
-    static void didCreateCSSCanvas(HTMLCanvasElement&, const String&);
     static void didChangeCSSCanvasClientNodes(HTMLCanvasElement&);
-    static void didCreateCanvasRenderingContext(HTMLCanvasElement&);
-    static void didChangeCanvasMemory(HTMLCanvasElement&);
+    static void didCreateCanvasRenderingContext(CanvasRenderingContext&);
+    static void willDestroyCanvasRenderingContext(CanvasRenderingContext&);
+    static void didChangeCanvasMemory(CanvasRenderingContext&);
     static void recordCanvasAction(CanvasRenderingContext&, const String&, Vector<RecordCanvasActionVariant>&& = { });
-    static void didFinishRecordingCanvasFrame(HTMLCanvasElement&, bool forceDispatch = false);
+    static void didFinishRecordingCanvasFrame(CanvasRenderingContext&, bool forceDispatch = false);
 #if ENABLE(WEBGL)
     static void didEnableExtension(WebGLRenderingContextBase&, const String&);
     static void didCreateProgram(WebGLRenderingContextBase&, WebGLProgram&);
@@ -393,7 +393,7 @@ private:
     static void consoleTimeStampImpl(InstrumentingAgents&, Frame&, Ref<Inspector::ScriptArguments>&&);
     static void startProfilingImpl(InstrumentingAgents&, JSC::ExecState*, const String& title);
     static void stopProfilingImpl(InstrumentingAgents&, JSC::ExecState*, const String& title);
-    static void consoleStartRecordingCanvasImpl(InstrumentingAgents&, HTMLCanvasElement&, JSC::ExecState&, JSC::JSObject* options);
+    static void consoleStartRecordingCanvasImpl(InstrumentingAgents&, CanvasRenderingContext&, JSC::ExecState&, JSC::JSObject* options);
 
     static void didRequestAnimationFrameImpl(InstrumentingAgents&, int callbackId, Document&);
     static void didCancelAnimationFrameImpl(InstrumentingAgents&, int callbackId, Document&);
@@ -423,12 +423,12 @@ private:
     static void networkStateChangedImpl(InstrumentingAgents&);
     static void updateApplicationCacheStatusImpl(InstrumentingAgents&, Frame&);
 
-    static void didCreateCSSCanvasImpl(InstrumentingAgents&, HTMLCanvasElement&, const String&);
     static void didChangeCSSCanvasClientNodesImpl(InstrumentingAgents&, HTMLCanvasElement&);
-    static void didCreateCanvasRenderingContextImpl(InstrumentingAgents&, HTMLCanvasElement&);
-    static void didChangeCanvasMemoryImpl(InstrumentingAgents&, HTMLCanvasElement&);
+    static void didCreateCanvasRenderingContextImpl(InstrumentingAgents&, CanvasRenderingContext&);
+    static void willDestroyCanvasRenderingContextImpl(InstrumentingAgents&, CanvasRenderingContext&);
+    static void didChangeCanvasMemoryImpl(InstrumentingAgents&, CanvasRenderingContext&);
     static void recordCanvasActionImpl(InstrumentingAgents&, CanvasRenderingContext&, const String&, Vector<RecordCanvasActionVariant>&& = { });
-    static void didFinishRecordingCanvasFrameImpl(InstrumentingAgents&, HTMLCanvasElement&, bool forceDispatch = false);
+    static void didFinishRecordingCanvasFrameImpl(InstrumentingAgents&, CanvasRenderingContext&, bool forceDispatch = false);
 #if ENABLE(WEBGL)
     static void didEnableExtensionImpl(InstrumentingAgents&, WebGLRenderingContextBase&, const String&);
     static void didCreateProgramImpl(InstrumentingAgents&, WebGLRenderingContextBase&, WebGLProgram&);
@@ -1201,12 +1201,6 @@ inline void InspectorInstrumentation::didHandleMemoryPressure(Page& page, Critic
 }
 #endif
 
-inline void InspectorInstrumentation::didCreateCSSCanvas(HTMLCanvasElement& canvasElement, const String& name)
-{
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
-        didCreateCSSCanvasImpl(*instrumentingAgents, canvasElement, name);
-}
-
 inline void InspectorInstrumentation::didChangeCSSCanvasClientNodes(HTMLCanvasElement& canvasElement)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
@@ -1214,92 +1208,65 @@ inline void InspectorInstrumentation::didChangeCSSCanvasClientNodes(HTMLCanvasEl
         didChangeCSSCanvasClientNodesImpl(*instrumentingAgents, canvasElement);
 }
 
-inline void InspectorInstrumentation::didCreateCanvasRenderingContext(HTMLCanvasElement& canvasElement)
+inline void InspectorInstrumentation::didCreateCanvasRenderingContext(CanvasRenderingContext& context)
 {
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
-        didCreateCanvasRenderingContextImpl(*instrumentingAgents, canvasElement);
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context.canvasBase().scriptExecutionContext()))
+        didCreateCanvasRenderingContextImpl(*instrumentingAgents, context);
+}
+
+inline void InspectorInstrumentation::willDestroyCanvasRenderingContext(CanvasRenderingContext& context)
+{
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context.canvasBase().scriptExecutionContext()))
+        willDestroyCanvasRenderingContextImpl(*instrumentingAgents, context);
 }
 
-inline void InspectorInstrumentation::didChangeCanvasMemory(HTMLCanvasElement& canvasElement)
+inline void InspectorInstrumentation::didChangeCanvasMemory(CanvasRenderingContext& context)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
-        didChangeCanvasMemoryImpl(*instrumentingAgents, canvasElement);
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context.canvasBase().scriptExecutionContext()))
+        didChangeCanvasMemoryImpl(*instrumentingAgents, context);
 }
 
-inline void InspectorInstrumentation::recordCanvasAction(CanvasRenderingContext& canvasRenderingContext, const String& name, Vector<RecordCanvasActionVariant>&& parameters)
+inline void InspectorInstrumentation::recordCanvasAction(CanvasRenderingContext& context, const String& name, Vector<RecordCanvasActionVariant>&& parameters)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    auto& canvasBase = canvasRenderingContext.canvasBase();
-    auto* canvasElement = is<HTMLCanvasElement>(canvasBase) ? &downcast<HTMLCanvasElement>(canvasBase) : nullptr;
-    if (canvasElement) {
-        if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement->document()))
-            recordCanvasActionImpl(*instrumentingAgents, canvasRenderingContext, name, WTFMove(parameters));
-    }
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context.canvasBase().scriptExecutionContext()))
+        recordCanvasActionImpl(*instrumentingAgents, context, name, WTFMove(parameters));
 }
 
-inline void InspectorInstrumentation::didFinishRecordingCanvasFrame(HTMLCanvasElement& canvasElement, bool forceDispatch)
+inline void InspectorInstrumentation::didFinishRecordingCanvasFrame(CanvasRenderingContext& context, bool forceDispatch)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
-        didFinishRecordingCanvasFrameImpl(*instrumentingAgents, canvasElement, forceDispatch);
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context.canvasBase().scriptExecutionContext()))
+        didFinishRecordingCanvasFrameImpl(*instrumentingAgents, context, forceDispatch);
 }
 
 #if ENABLE(WEBGL)
-inline void InspectorInstrumentation::didEnableExtension(WebGLRenderingContextBase& context, const String& extension)
+inline void InspectorInstrumentation::didEnableExtension(WebGLRenderingContextBase& contextWebGLBase, const String& extension)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    auto canvas = context.canvas();
-    WTF::switchOn(canvas,
-        [&] (const RefPtr<HTMLCanvasElement>& htmlCanvasElement) {
-            if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(htmlCanvasElement->document()))
-                didEnableExtensionImpl(*instrumentingAgents, context, extension);
-        },
-        [&] (const RefPtr<OffscreenCanvas>&) {
-        }
-    );
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(contextWebGLBase.canvasBase().scriptExecutionContext()))
+        didEnableExtensionImpl(*instrumentingAgents, contextWebGLBase, extension);
 }
 
-inline void InspectorInstrumentation::didCreateProgram(WebGLRenderingContextBase& context, WebGLProgram& program)
+inline void InspectorInstrumentation::didCreateProgram(WebGLRenderingContextBase& contextWebGLBase, WebGLProgram& program)
 {
-    auto canvas = context.canvas();
-    WTF::switchOn(canvas,
-        [&] (const RefPtr<HTMLCanvasElement>& htmlCanvasElement) {
-            if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(htmlCanvasElement->document()))
-                didCreateProgramImpl(*instrumentingAgents, context, program);
-        },
-        [&] (const RefPtr<OffscreenCanvas>&) {
-        }
-    );
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(contextWebGLBase.canvasBase().scriptExecutionContext()))
+        didCreateProgramImpl(*instrumentingAgents, contextWebGLBase, program);
 }
 
-inline void InspectorInstrumentation::willDeleteProgram(WebGLRenderingContextBase& context, WebGLProgram& program)
+inline void InspectorInstrumentation::willDeleteProgram(WebGLRenderingContextBase& contextWebGLBase, WebGLProgram& program)
 {
-    auto canvas = context.canvas();
-    WTF::switchOn(canvas,
-        [&] (const RefPtr<HTMLCanvasElement>& htmlCanvasElement) {
-            if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(htmlCanvasElement->document()))
-                willDeleteProgramImpl(*instrumentingAgents, program);
-        },
-        [&] (const RefPtr<OffscreenCanvas>&) {
-        }
-    );
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(contextWebGLBase.canvasBase().scriptExecutionContext()))
+        willDeleteProgramImpl(*instrumentingAgents, program);
 }
 
-inline bool InspectorInstrumentation::isShaderProgramDisabled(WebGLRenderingContextBase& context, WebGLProgram& program)
+inline bool InspectorInstrumentation::isShaderProgramDisabled(WebGLRenderingContextBase& contextWebGLBase, WebGLProgram& program)
 {
     FAST_RETURN_IF_NO_FRONTENDS(false);
-    auto canvas = context.canvas();
-    return WTF::switchOn(canvas,
-        [&] (const RefPtr<HTMLCanvasElement>& htmlCanvasElement) {
-            if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(htmlCanvasElement->document()))
-                return isShaderProgramDisabledImpl(*instrumentingAgents, program);
-            return false;
-        },
-        [&] (const RefPtr<OffscreenCanvas>&) {
-            return false;
-        }
-    );
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(contextWebGLBase.canvasBase().scriptExecutionContext()))
+        return isShaderProgramDisabledImpl(*instrumentingAgents, program);
+    return false;
 }
 #endif
 
@@ -1382,11 +1349,11 @@ inline void InspectorInstrumentation::stopProfiling(Page& page, JSC::ExecState*
     stopProfilingImpl(instrumentingAgentsForPage(page), exec, title);
 }
 
-inline void InspectorInstrumentation::consoleStartRecordingCanvas(HTMLCanvasElement& canvasElement, JSC::ExecState& exec, JSC::JSObject* options)
+inline void InspectorInstrumentation::consoleStartRecordingCanvas(CanvasRenderingContext& context, JSC::ExecState& exec, JSC::JSObject* options)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
-        consoleStartRecordingCanvasImpl(*instrumentingAgents, canvasElement, exec, options);
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context.canvasBase().scriptExecutionContext()))
+        consoleStartRecordingCanvasImpl(*instrumentingAgents, context, exec, options);
 }
 
 inline void InspectorInstrumentation::didRequestAnimationFrame(Document& document, int callbackId)
index 41eba0f..217f131 100644 (file)
@@ -52,11 +52,10 @@ InspectorShaderProgram::InspectorShaderProgram(WebGLProgram& program, InspectorC
 {
 }
 
-WebGLRenderingContextBase* InspectorShaderProgram::context() const
+WebGLRenderingContextBase& InspectorShaderProgram::context() const
 {
-    auto* context = m_canvas.canvas().renderingContext();
-    ASSERT(context && is<WebGLRenderingContextBase>(context));
-    return downcast<WebGLRenderingContextBase>(context);
+    ASSERT(is<WebGLRenderingContextBase>(m_canvas.context()));
+    return downcast<WebGLRenderingContextBase>(m_canvas.context());
 }
 
 WebGLShader* InspectorShaderProgram::shaderForType(const String& protocolType)
index 50256df..c915170 100644 (file)
@@ -42,7 +42,7 @@ public:
 
     const String& identifier() const { return m_identifier; }
     InspectorCanvas& canvas() const { return m_canvas; }
-    WebGLRenderingContextBase* context() const;
+    WebGLRenderingContextBase& context() const;
     WebGLProgram& program() const { return m_program; }
     WebGLShader* shaderForType(const String&);
 
index 612370b..b25f8da 100644 (file)
@@ -103,12 +103,11 @@ void InspectorCanvasAgent::enable(ErrorString&)
         m_frontendDispatcher->canvasAdded(inspectorCanvas->buildObjectForCanvas(m_instrumentingAgents, captureBacktrace));
 
 #if ENABLE(WEBGL)
-        CanvasRenderingContext* context = inspectorCanvas->canvas().renderingContext();
-        if (is<WebGLRenderingContextBase>(context)) {
-            WebGLRenderingContextBase* contextWebGL = downcast<WebGLRenderingContextBase>(context);
-            if (std::optional<Vector<String>> extensions = contextWebGL->getSupportedExtensions()) {
+        if (is<WebGLRenderingContextBase>(inspectorCanvas->context())) {
+            WebGLRenderingContextBase& contextWebGL = downcast<WebGLRenderingContextBase>(inspectorCanvas->context());
+            if (std::optional<Vector<String>> extensions = contextWebGL.getSupportedExtensions()) {
                 for (const String& extension : *extensions) {
-                    if (contextWebGL->extensionIsEnabled(extension))
+                    if (contextWebGL.extensionIsEnabled(extension))
                         m_frontendDispatcher->extensionEnabled(inspectorCanvas->identifier(), extension);
                 }
             }
@@ -149,13 +148,19 @@ void InspectorCanvasAgent::requestNode(ErrorString& errorString, const String& c
     if (!inspectorCanvas)
         return;
 
-    int documentNodeId = m_instrumentingAgents.inspectorDOMAgent()->boundNodeId(&inspectorCanvas->canvas().document());
+    auto* node = inspectorCanvas->canvasElement();
+    if (!node) {
+        errorString = ASCIILiteral("No node for canvas");
+        return;
+    }
+
+    int documentNodeId = m_instrumentingAgents.inspectorDOMAgent()->boundNodeId(&node->document());
     if (!documentNodeId) {
         errorString = ASCIILiteral("Document has not been requested");
         return;
     }
 
-    *nodeId = m_instrumentingAgents.inspectorDOMAgent()->pushNodeToFrontend(errorString, documentNodeId, &inspectorCanvas->canvas());
+    *nodeId = m_instrumentingAgents.inspectorDOMAgent()->pushNodeToFrontend(errorString, documentNodeId, node);
 }
 
 void InspectorCanvasAgent::requestContent(ErrorString& errorString, const String& canvasId, String* content)
@@ -164,33 +169,39 @@ void InspectorCanvasAgent::requestContent(ErrorString& errorString, const String
     if (!inspectorCanvas)
         return;
 
-    CanvasRenderingContext* context = inspectorCanvas->canvas().renderingContext();
-    if (is<CanvasRenderingContext2D>(context) || is<ImageBitmapRenderingContext>(context)) {
-        auto result = inspectorCanvas->canvas().toDataURL(ASCIILiteral("image/png"));
-        if (result.hasException()) {
-            errorString = result.releaseException().releaseMessage();
+    // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
+
+    if (auto* node = inspectorCanvas->canvasElement()) {
+        if (is<CanvasRenderingContext2D>(inspectorCanvas->context()) || is<ImageBitmapRenderingContext>(inspectorCanvas->context())) {
+            auto result = node->toDataURL(ASCIILiteral("image/png"));
+            if (result.hasException()) {
+                errorString = result.releaseException().releaseMessage();
+                return;
+            }
+            *content = result.releaseReturnValue().string;
             return;
         }
-        *content = result.releaseReturnValue().string;
-    }
+
 #if ENABLE(WEBGL)
-    else if (is<WebGLRenderingContextBase>(context)) {
-        WebGLRenderingContextBase* gl = downcast<WebGLRenderingContextBase>(context);
+        if (is<WebGLRenderingContextBase>(inspectorCanvas->context())) {
+            WebGLRenderingContextBase& contextWebGLBase = downcast<WebGLRenderingContextBase>(inspectorCanvas->context());
 
-        gl->setPreventBufferClearForInspector(true);
-        auto result = inspectorCanvas->canvas().toDataURL(ASCIILiteral("image/png"));
-        gl->setPreventBufferClearForInspector(false);
+            contextWebGLBase.setPreventBufferClearForInspector(true);
+            auto result = node->toDataURL(ASCIILiteral("image/png"));
+            contextWebGLBase.setPreventBufferClearForInspector(false);
 
-        if (result.hasException()) {
-            errorString = result.releaseException().releaseMessage();
+            if (result.hasException()) {
+                errorString = result.releaseException().releaseMessage();
+                return;
+            }
+            *content = result.releaseReturnValue().string;
             return;
         }
-        *content = result.releaseReturnValue().string;
-    }
 #endif
-    // FIXME: <https://webkit.org/b/173621> Web Inspector: Support getting the content of WebGPU contexts
-    else
-        errorString = ASCIILiteral("Unsupported canvas context type");
+    }
+
+    // FIXME: <https://webkit.org/b/173621> Web Inspector: Support getting the content of WebGPU context;
+    errorString = ASCIILiteral("Unsupported canvas context type");
 }
 
 void InspectorCanvasAgent::requestCSSCanvasClientNodes(ErrorString& errorString, const String& canvasId, RefPtr<JSON::ArrayOf<int>>& result)
@@ -199,14 +210,20 @@ void InspectorCanvasAgent::requestCSSCanvasClientNodes(ErrorString& errorString,
     if (!inspectorCanvas)
         return;
 
+    auto* node = inspectorCanvas->canvasElement();
+    if (!node) {
+        errorString = ASCIILiteral("CSS canvas does not support OffscreenCanvas");
+        return;
+    }
+
     result = JSON::ArrayOf<int>::create();
-    for (Element* element : inspectorCanvas->canvas().cssCanvasClients()) {
-        if (int documentNodeId = m_instrumentingAgents.inspectorDOMAgent()->boundNodeId(&element->document()))
-            result->addItem(m_instrumentingAgents.inspectorDOMAgent()->pushNodeToFrontend(errorString, documentNodeId, element));
+    for (auto* client : node->cssCanvasClients()) {
+        if (int documentNodeId = m_instrumentingAgents.inspectorDOMAgent()->boundNodeId(&client->document()))
+            result->addItem(m_instrumentingAgents.inspectorDOMAgent()->pushNodeToFrontend(errorString, documentNodeId, client));
     }
 }
 
-static JSC::JSValue contextAsScriptValue(JSC::ExecState& state, CanvasRenderingContext* context)
+static JSC::JSValue contextAsScriptValue(JSC::ExecState& state, CanvasRenderingContext& context)
 {
     JSC::JSLockHolder lock(&state);
 
@@ -236,18 +253,11 @@ void InspectorCanvasAgent::resolveCanvasContext(ErrorString& errorString, const
     if (!inspectorCanvas)
         return;
 
-    Frame* frame = inspectorCanvas->canvas().document().frame();
-    if (!frame) {
-        errorString = ASCIILiteral("Canvas belongs to a document without a frame");
-        return;
-    }
-
-    auto& state = *mainWorldExecState(frame);
+    auto& state = *inspectorCanvas->context().canvasBase().scriptExecutionContext()->execState();
     auto injectedScript = m_injectedScriptManager.injectedScriptFor(&state);
     ASSERT(!injectedScript.hasNoValue());
 
-    CanvasRenderingContext* context = inspectorCanvas->canvas().renderingContext();
-    JSC::JSValue value = contextAsScriptValue(state, context);
+    JSC::JSValue value = contextAsScriptValue(state, inspectorCanvas->context());
     if (!value) {
         ASSERT_NOT_REACHED();
         errorString = ASCIILiteral("Unknown context type");
@@ -264,7 +274,7 @@ void InspectorCanvasAgent::startRecording(ErrorString& errorString, const String
     if (!inspectorCanvas)
         return;
 
-    if (inspectorCanvas->canvas().renderingContext()->callTracingActive()) {
+    if (inspectorCanvas->context().callTracingActive()) {
         errorString = ASCIILiteral("Already recording canvas");
         return;
     }
@@ -275,7 +285,7 @@ void InspectorCanvasAgent::startRecording(ErrorString& errorString, const String
     if (memoryLimit)
         inspectorCanvas->setBufferLimit(*memoryLimit);
 
-    inspectorCanvas->canvas().renderingContext()->setCallTracingActive(true);
+    inspectorCanvas->context().setCallTracingActive(true);
 }
 
 void InspectorCanvasAgent::stopRecording(ErrorString& errorString, const String& canvasId)
@@ -284,12 +294,12 @@ void InspectorCanvasAgent::stopRecording(ErrorString& errorString, const String&
     if (!inspectorCanvas)
         return;
 
-    if (!inspectorCanvas->canvas().renderingContext()->callTracingActive()) {
+    if (!inspectorCanvas->context().callTracingActive()) {
         errorString = ASCIILiteral("No active recording for canvas");
         return;
     }
 
-    didFinishRecordingCanvasFrame(inspectorCanvas->canvas(), true);
+    didFinishRecordingCanvasFrame(inspectorCanvas->context(), true);
 }
 
 void InspectorCanvasAgent::requestShaderSource(ErrorString& errorString, const String& programId, const String& shaderType, String* content)
@@ -327,16 +337,16 @@ void InspectorCanvasAgent::updateShader(ErrorString& errorString, const String&
         return;
     }
 
-    WebGLRenderingContextBase* contextWebGL = inspectorProgram->context();
-    contextWebGL->shaderSource(shader, source);
-    contextWebGL->compileShader(shader);
+    WebGLRenderingContextBase& contextWebGL = inspectorProgram->context();
+    contextWebGL.shaderSource(shader, source);
+    contextWebGL.compileShader(shader);
 
     if (!shader->isValid()) {
         errorString = ASCIILiteral("Shader compilation failed.");
         return;
     }
 
-    contextWebGL->linkProgramWithoutInvalidatingAttribLocations(&inspectorProgram->program());
+    contextWebGL.linkProgramWithoutInvalidatingAttribLocations(&inspectorProgram->program());
 #else
     UNUSED_PARAM(programId);
     UNUSED_PARAM(shaderType);
@@ -362,55 +372,33 @@ void InspectorCanvasAgent::setShaderProgramDisabled(ErrorString& errorString, co
 
 void InspectorCanvasAgent::frameNavigated(Frame& frame)
 {
-    if (frame.isMainFrame()) {
+    if (frame.isMainFrame())
         clearCanvasData();
-        return;
-    }
-
-    Vector<InspectorCanvas*> inspectorCanvases;
-    for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
-        if (inspectorCanvas->canvas().document().frame() == &frame)
-            inspectorCanvases.append(inspectorCanvas.get());
-    }
-
-    for (auto* inspectorCanvas : inspectorCanvases) {
-        String identifier = unbindCanvas(*inspectorCanvas);
-        if (m_enabled)
-            m_frontendDispatcher->canvasRemoved(identifier);
-    }
 }
 
-void InspectorCanvasAgent::didCreateCSSCanvas(HTMLCanvasElement& canvasElement, const String& name)
+void InspectorCanvasAgent::didChangeCSSCanvasClientNodes(HTMLCanvasElement& canvasElement)
 {
-    if (findInspectorCanvas(canvasElement)) {
+    auto* context = canvasElement.renderingContext();
+    if (!context) {
         ASSERT_NOT_REACHED();
         return;
     }
 
-    ASSERT(!m_canvasToCSSCanvasName.contains(&canvasElement));
-    m_canvasToCSSCanvasName.set(&canvasElement, name);
-}
-
-void InspectorCanvasAgent::didChangeCSSCanvasClientNodes(HTMLCanvasElement& canvasElement)
-{
-    auto* inspectorCanvas = findInspectorCanvas(canvasElement);
+    auto* inspectorCanvas = findInspectorCanvas(*context);
     if (!inspectorCanvas)
         return;
 
     m_frontendDispatcher->cssCanvasClientNodesChanged(inspectorCanvas->identifier());
 }
 
-void InspectorCanvasAgent::didCreateCanvasRenderingContext(HTMLCanvasElement& canvasElement)
+void InspectorCanvasAgent::didCreateCanvasRenderingContext(CanvasRenderingContext& context)
 {
-    if (findInspectorCanvas(canvasElement)) {
+    if (findInspectorCanvas(context)) {
         ASSERT_NOT_REACHED();
         return;
     }
 
-    canvasElement.addObserver(*this);
-
-    String cssCanvasName = m_canvasToCSSCanvasName.take(&canvasElement);
-    auto inspectorCanvas = InspectorCanvas::create(canvasElement, cssCanvasName);
+    auto inspectorCanvas = InspectorCanvas::create(context);
 
     if (m_enabled) {
         const bool captureBacktrace = true;
@@ -420,23 +408,40 @@ void InspectorCanvasAgent::didCreateCanvasRenderingContext(HTMLCanvasElement& ca
     m_identifierToInspectorCanvas.set(inspectorCanvas->identifier(), WTFMove(inspectorCanvas));
 }
 
-void InspectorCanvasAgent::didChangeCanvasMemory(HTMLCanvasElement& canvasElement)
+void InspectorCanvasAgent::willDestroyCanvasRenderingContext(CanvasRenderingContext& context)
 {
-    auto* inspectorCanvas = findInspectorCanvas(canvasElement);
+    auto* inspectorCanvas = findInspectorCanvas(context);
     if (!inspectorCanvas)
         return;
 
-    m_frontendDispatcher->canvasMemoryChanged(inspectorCanvas->identifier(), canvasElement.memoryCost());
+    String identifier = unbindCanvas(*inspectorCanvas);
+    if (!m_enabled)
+        return;
+
+    // willDestroyCanvasRenderingContext is called in response to the GC destroying the CanvasRenderingContext.
+    // Due to the single-process model used in WebKit1, the event must be dispatched from a timer to prevent
+    // the frontend from making JS allocations while the GC is still active.
+    m_removedCanvasIdentifiers.append(identifier);
+
+    if (!m_canvasDestroyedTimer.isActive())
+        m_canvasDestroyedTimer.startOneShot(0_s);
 }
 
-void InspectorCanvasAgent::recordCanvasAction(CanvasRenderingContext& canvasRenderingContext, const String& name, Vector<RecordCanvasActionVariant>&& parameters)
+void InspectorCanvasAgent::didChangeCanvasMemory(CanvasRenderingContext& context)
 {
-    auto& canvasBase = canvasRenderingContext.canvasBase();
-    auto* canvasElement = is<HTMLCanvasElement>(canvasBase) ? &downcast<HTMLCanvasElement>(canvasBase) : nullptr;
-    if (!canvasElement)
+    auto* inspectorCanvas = findInspectorCanvas(context);
+    if (!inspectorCanvas)
         return;
 
-    auto* inspectorCanvas = findInspectorCanvas(*canvasElement);
+    // FIXME: <https://webkit.org/b/180833> Web Inspector: support OffscreenCanvas for Canvas related operations
+
+    if (auto* node = inspectorCanvas->canvasElement())
+        m_frontendDispatcher->canvasMemoryChanged(inspectorCanvas->identifier(), node->memoryCost());
+}
+
+void InspectorCanvasAgent::recordCanvasAction(CanvasRenderingContext& canvasRenderingContext, const String& name, Vector<RecordCanvasActionVariant>&& parameters)
+{
+    auto* inspectorCanvas = findInspectorCanvas(canvasRenderingContext);
     ASSERT(inspectorCanvas);
     if (!inspectorCanvas)
         return;
@@ -451,39 +456,18 @@ void InspectorCanvasAgent::recordCanvasAction(CanvasRenderingContext& canvasRend
         m_canvasRecordingTimer.startOneShot(0_s);
 
     if (!inspectorCanvas->hasBufferSpace())
-        didFinishRecordingCanvasFrame(*canvasElement, true);
+        didFinishRecordingCanvasFrame(inspectorCanvas->context(), true);
 }
 
-void InspectorCanvasAgent::canvasDestroyed(HTMLCanvasElement& canvasElement)
+void InspectorCanvasAgent::didFinishRecordingCanvasFrame(CanvasRenderingContext& context, bool forceDispatch)
 {
-    auto* inspectorCanvas = findInspectorCanvas(canvasElement);
+    auto* inspectorCanvas = findInspectorCanvas(context);
     ASSERT(inspectorCanvas);
     if (!inspectorCanvas)
         return;
 
-    String identifier = unbindCanvas(*inspectorCanvas);
-    if (!m_enabled)
-        return;
-
-    // WebCore::CanvasObserver::canvasDestroyed is called in response to the GC destroying the HTMLCanvasElement.
-    // Due to the single-process model used in WebKit1, the event must be dispatched from a timer to prevent
-    // the frontend from making JS allocations while the GC is still active.
-    m_removedCanvasIdentifiers.append(identifier);
-
-    if (!m_canvasDestroyedTimer.isActive())
-        m_canvasDestroyedTimer.startOneShot(0_s);
-}
-
-void InspectorCanvasAgent::didFinishRecordingCanvasFrame(HTMLCanvasElement& canvasElement, bool forceDispatch)
-{
-    auto* inspectorCanvas = findInspectorCanvas(canvasElement);
-    ASSERT(inspectorCanvas);
-    if (!inspectorCanvas)
-        return;
-
-    CanvasRenderingContext* canvasRenderingContext = inspectorCanvas->canvas().renderingContext();
-    ASSERT(canvasRenderingContext->callTracingActive());
-    if (!canvasRenderingContext->callTracingActive())
+    ASSERT(inspectorCanvas->context().callTracingActive());
+    if (!inspectorCanvas->context().callTracingActive())
         return;
 
     if (!inspectorCanvas->hasRecordingData()) {
@@ -508,10 +492,10 @@ void InspectorCanvasAgent::didFinishRecordingCanvasFrame(HTMLCanvasElement& canv
     // FIXME: <https://webkit.org/b/176008> Web Inspector: Record actions performed on WebGL2RenderingContext
 
     Inspector::Protocol::Recording::Type type;
-    if (is<CanvasRenderingContext2D>(canvasRenderingContext))
+    if (is<CanvasRenderingContext2D>(inspectorCanvas->context()))
         type = Inspector::Protocol::Recording::Type::Canvas2D;
 #if ENABLE(WEBGL)
-    else if (is<WebGLRenderingContext>(canvasRenderingContext))
+    else if (is<WebGLRenderingContext>(inspectorCanvas->context()))
         type = Inspector::Protocol::Recording::Type::CanvasWebGL;
 #endif
     else {
@@ -535,13 +519,13 @@ void InspectorCanvasAgent::didFinishRecordingCanvasFrame(HTMLCanvasElement& canv
     inspectorCanvas->resetRecordingData();
 }
 
-void InspectorCanvasAgent::consoleStartRecordingCanvas(HTMLCanvasElement& canvasElement, JSC::ExecState& exec, JSC::JSObject* options)
+void InspectorCanvasAgent::consoleStartRecordingCanvas(CanvasRenderingContext& context, JSC::ExecState& exec, JSC::JSObject* options)
 {
-    auto* inspectorCanvas = findInspectorCanvas(canvasElement);
+    auto* inspectorCanvas = findInspectorCanvas(context);
     if (!inspectorCanvas)
         return;
 
-    if (inspectorCanvas->canvas().renderingContext()->callTracingActive())
+    if (inspectorCanvas->context().callTracingActive())
         return;
 
     inspectorCanvas->resetRecordingData();
@@ -555,38 +539,32 @@ void InspectorCanvasAgent::consoleStartRecordingCanvas(HTMLCanvasElement& canvas
             inspectorCanvas->setBufferLimit(optionMemoryLimit.toNumber(&exec));
     }
 
-    inspectorCanvas->canvas().renderingContext()->setCallTracingActive(true);
+    inspectorCanvas->context().setCallTracingActive(true);
 }
 
 #if ENABLE(WEBGL)
 void InspectorCanvasAgent::didEnableExtension(WebGLRenderingContextBase& context, const String& extension)
 {
-    auto canvas = context.canvas();
-    if (WTF::holds_alternative<RefPtr<HTMLCanvasElement>>(canvas)) {
-        auto* inspectorCanvas = findInspectorCanvas(*WTF::get<RefPtr<HTMLCanvasElement>>(canvas));
-        if (!inspectorCanvas)
-            return;
+    auto* inspectorCanvas = findInspectorCanvas(context);
+    if (!inspectorCanvas)
+        return;
 
-        m_frontendDispatcher->extensionEnabled(inspectorCanvas->identifier(), extension);
-    }
+    m_frontendDispatcher->extensionEnabled(inspectorCanvas->identifier(), extension);
 }
 
 void InspectorCanvasAgent::didCreateProgram(WebGLRenderingContextBase& context, WebGLProgram& program)
 {
-    auto canvas = context.canvas();
-    if (WTF::holds_alternative<RefPtr<HTMLCanvasElement>>(canvas)) {
-        auto* inspectorCanvas = findInspectorCanvas(*WTF::get<RefPtr<HTMLCanvasElement>>(canvas));
-        ASSERT(inspectorCanvas);
-        if (!inspectorCanvas)
-            return;
+    auto* inspectorCanvas = findInspectorCanvas(context);
+    ASSERT(inspectorCanvas);
+    if (!inspectorCanvas)
+        return;
 
-        auto inspectorProgram = InspectorShaderProgram::create(program, *inspectorCanvas);
-        String programIdentifier = inspectorProgram->identifier();
-        m_identifierToInspectorProgram.set(programIdentifier, WTFMove(inspectorProgram));
+    auto inspectorProgram = InspectorShaderProgram::create(program, *inspectorCanvas);
+    String programIdentifier = inspectorProgram->identifier();
+    m_identifierToInspectorProgram.set(programIdentifier, WTFMove(inspectorProgram));
 
-        if (m_enabled)
-            m_frontendDispatcher->programCreated(inspectorCanvas->identifier(), programIdentifier);
-    }
+    if (m_enabled)
+        m_frontendDispatcher->programCreated(inspectorCanvas->identifier(), programIdentifier);
 }
 
 void InspectorCanvasAgent::willDeleteProgram(WebGLProgram& program)
@@ -626,20 +604,16 @@ void InspectorCanvasAgent::canvasDestroyedTimerFired()
 void InspectorCanvasAgent::canvasRecordingTimerFired()
 {
     for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
-        if (!inspectorCanvas->canvas().renderingContext()->callTracingActive())
+        if (!inspectorCanvas->context().callTracingActive())
             continue;
 
-        didFinishRecordingCanvasFrame(inspectorCanvas->canvas());
+        didFinishRecordingCanvasFrame(inspectorCanvas->context());
     }
 }
 
 void InspectorCanvasAgent::clearCanvasData()
 {
-    for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values())
-        inspectorCanvas->canvas().removeObserver(*this);
-
     m_identifierToInspectorCanvas.clear();
-    m_canvasToCSSCanvasName.clear();
     m_removedCanvasIdentifiers.clear();
 #if ENABLE(WEBGL)
     m_identifierToInspectorProgram.clear();
@@ -654,8 +628,6 @@ void InspectorCanvasAgent::clearCanvasData()
 
 String InspectorCanvasAgent::unbindCanvas(InspectorCanvas& inspectorCanvas)
 {
-    ASSERT(!m_canvasToCSSCanvasName.contains(&inspectorCanvas.canvas()));
-
 #if ENABLE(WEBGL)
     Vector<InspectorShaderProgram*> programsToRemove;
     for (auto& inspectorProgram : m_identifierToInspectorProgram.values()) {
@@ -684,10 +656,10 @@ InspectorCanvas* InspectorCanvasAgent::assertInspectorCanvas(ErrorString& errorS
     return inspectorCanvas.get();
 }
 
-InspectorCanvas* InspectorCanvasAgent::findInspectorCanvas(HTMLCanvasElement& canvasElement)
+InspectorCanvas* InspectorCanvasAgent::findInspectorCanvas(CanvasRenderingContext& context)
 {
     for (auto& inspectorCanvas : m_identifierToInspectorCanvas.values()) {
-        if (&inspectorCanvas->canvas() == &canvasElement)
+        if (&inspectorCanvas->context() == &context)
             return inspectorCanvas.get();
     }
 
@@ -697,8 +669,6 @@ InspectorCanvas* InspectorCanvasAgent::findInspectorCanvas(HTMLCanvasElement& ca
 #if ENABLE(WEBGL)
 String InspectorCanvasAgent::unbindProgram(InspectorShaderProgram& inspectorProgram)
 {
-    ASSERT(inspectorProgram.context());
-
     String identifier = inspectorProgram.identifier();
     m_identifierToInspectorProgram.remove(identifier);
 
index cd302f4..653547b 100644 (file)
@@ -55,7 +55,7 @@ class WebGLRenderingContextBase;
 
 typedef String ErrorString;
 
-class InspectorCanvasAgent final : public InspectorAgentBase, public CanvasObserver, public Inspector::CanvasBackendDispatcherHandler {
+class InspectorCanvasAgent final : public InspectorAgentBase, public Inspector::CanvasBackendDispatcherHandler {
     WTF_MAKE_NONCOPYABLE(InspectorCanvasAgent);
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -81,13 +81,13 @@ public:
 
     // InspectorInstrumentation
     void frameNavigated(Frame&);
-    void didCreateCSSCanvas(HTMLCanvasElement&, const String&);
     void didChangeCSSCanvasClientNodes(HTMLCanvasElement&);
-    void didCreateCanvasRenderingContext(HTMLCanvasElement&);
-    void didChangeCanvasMemory(HTMLCanvasElement&);
+    void didCreateCanvasRenderingContext(CanvasRenderingContext&);
+    void willDestroyCanvasRenderingContext(CanvasRenderingContext&);
+    void didChangeCanvasMemory(CanvasRenderingContext&);
     void recordCanvasAction(CanvasRenderingContext&, const String&, Vector<RecordCanvasActionVariant>&& = { });
-    void didFinishRecordingCanvasFrame(HTMLCanvasElement&, bool forceDispatch = false);
-    void consoleStartRecordingCanvas(HTMLCanvasElement&, JSC::ExecState&, JSC::JSObject* options);
+    void didFinishRecordingCanvasFrame(CanvasRenderingContext&, bool forceDispatch = false);
+    void consoleStartRecordingCanvas(CanvasRenderingContext&, JSC::ExecState&, JSC::JSObject* options);
 #if ENABLE(WEBGL)
     void didEnableExtension(WebGLRenderingContextBase&, const String&);
     void didCreateProgram(WebGLRenderingContextBase&, WebGLProgram&);
@@ -95,18 +95,13 @@ public:
     bool isShaderProgramDisabled(WebGLProgram&);
 #endif
 
-    // CanvasObserver
-    void canvasChanged(HTMLCanvasElement&, const FloatRect&) override { }
-    void canvasResized(HTMLCanvasElement&) override { }
-    void canvasDestroyed(HTMLCanvasElement&) override;
-
 private:
     void canvasDestroyedTimerFired();
     void canvasRecordingTimerFired();
     void clearCanvasData();
     String unbindCanvas(InspectorCanvas&);
     InspectorCanvas* assertInspectorCanvas(ErrorString&, const String& identifier);
-    InspectorCanvas* findInspectorCanvas(HTMLCanvasElement&);
+    InspectorCanvas* findInspectorCanvas(CanvasRenderingContext&);
 #if ENABLE(WEBGL)
     String unbindProgram(InspectorShaderProgram&);
     InspectorShaderProgram* assertInspectorProgram(ErrorString&, const String& identifier);
@@ -119,7 +114,6 @@ private:
     RefPtr<Inspector::CanvasBackendDispatcher> m_backendDispatcher;
     Inspector::InjectedScriptManager& m_injectedScriptManager;
     HashMap<String, RefPtr<InspectorCanvas>> m_identifierToInspectorCanvas;
-    HashMap<HTMLCanvasElement*, String> m_canvasToCSSCanvasName;
     Vector<String> m_removedCanvasIdentifiers;
     Timer m_canvasDestroyedTimer;
     Timer m_canvasRecordingTimer;
index 960279e..42068b5 100644 (file)
@@ -231,16 +231,14 @@ void PageConsoleClient::record(JSC::ExecState* exec, Ref<ScriptArguments>&& argu
     if (arguments->argumentCount() >= 2)
         options = arguments->argumentAt(1).jsValue().getObject();
 
-    if (HTMLCanvasElement* canvasElement = JSHTMLCanvasElement::toWrapped(*target->vm(), target))
-        InspectorInstrumentation::consoleStartRecordingCanvas(*canvasElement, *exec, options);
-    else if (CanvasRenderingContext2D* context2d = JSCanvasRenderingContext2D::toWrapped(*target->vm(), target))
-        InspectorInstrumentation::consoleStartRecordingCanvas(context2d->canvas(), *exec, options);
+    if (HTMLCanvasElement* canvasElement = JSHTMLCanvasElement::toWrapped(*target->vm(), target)) {
+        if (CanvasRenderingContext* context = canvasElement->renderingContext())
+            InspectorInstrumentation::consoleStartRecordingCanvas(*context, *exec, options);
+    } else if (CanvasRenderingContext2D* context2d = JSCanvasRenderingContext2D::toWrapped(*target->vm(), target))
+        InspectorInstrumentation::consoleStartRecordingCanvas(*context2d, *exec, options);
 #if ENABLE(WEBGL)
-    else if (WebGLRenderingContext* contextWebGL = JSWebGLRenderingContext::toWrapped(*target->vm(), target)) {
-        auto canvas = contextWebGL->canvas();
-        if (WTF::holds_alternative<RefPtr<HTMLCanvasElement>>(canvas))
-            InspectorInstrumentation::consoleStartRecordingCanvas(*WTF::get<RefPtr<HTMLCanvasElement>>(canvas), *exec, options);
-    }
+    else if (WebGLRenderingContext* contextWebGL = JSWebGLRenderingContext::toWrapped(*target->vm(), target))
+        InspectorInstrumentation::consoleStartRecordingCanvas(*contextWebGL, *exec, options);
 #endif
 }
 
@@ -253,16 +251,14 @@ void PageConsoleClient::recordEnd(JSC::ExecState*, Ref<ScriptArguments>&& argume
     if (!target)
         return;
 
-    if (HTMLCanvasElement* canvasElement = JSHTMLCanvasElement::toWrapped(*target->vm(), target))
-        InspectorInstrumentation::didFinishRecordingCanvasFrame(*canvasElement, true);
-    else if (CanvasRenderingContext2D* context2d = JSCanvasRenderingContext2D::toWrapped(*target->vm(), target))
-        InspectorInstrumentation::didFinishRecordingCanvasFrame(context2d->canvas(), true);
+    if (HTMLCanvasElement* canvasElement = JSHTMLCanvasElement::toWrapped(*target->vm(), target)) {
+        if (CanvasRenderingContext* context = canvasElement->renderingContext())
+            InspectorInstrumentation::didFinishRecordingCanvasFrame(*context, true);
+    } else if (CanvasRenderingContext2D* context2d = JSCanvasRenderingContext2D::toWrapped(*target->vm(), target))
+        InspectorInstrumentation::didFinishRecordingCanvasFrame(*context2d, true);
 #if ENABLE(WEBGL)
-    else if (WebGLRenderingContext* contextWebGL = JSWebGLRenderingContext::toWrapped(*target->vm(), target)) {
-        auto canvas = contextWebGL->canvas();
-        if (WTF::holds_alternative<RefPtr<HTMLCanvasElement>>(canvas))
-            InspectorInstrumentation::didFinishRecordingCanvasFrame(*WTF::get<RefPtr<HTMLCanvasElement>>(canvas), true);
-    }
+    else if (WebGLRenderingContext* contextWebGL = JSWebGLRenderingContext::toWrapped(*target->vm(), target))
+        InspectorInstrumentation::didFinishRecordingCanvasFrame(*contextWebGL, true);
 #endif
 }
 
index 81f7142..575e173 100644 (file)
@@ -1,3 +1,16 @@
+2017-12-14  Devin Rousso  <webkit@devinrousso.com>
+
+        Web Inspector: replace HTMLCanvasElement with CanvasRenderingContext for instrumentation logic
+        https://bugs.webkit.org/show_bug.cgi?id=180770
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Models/Canvas.js:
+        (WI.Canvas.fromPayload):
+        (WI.Canvas.prototype.get contextType):
+        (WI.Canvas.prototype.saveIdentityToCookie):
+        (WI.Canvas.prototype.get frame): Deleted.
+
 2017-12-14  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Network Tab - URL filter should be case-insensitive like filter bars in other tabs
index cd077d9..76a0e0f 100644 (file)
 
 WI.Canvas = class Canvas extends WI.Object
 {
-    constructor(identifier, contextType, frame, {domNode, cssCanvasName, contextAttributes, memoryCost, backtrace} = {})
+    constructor(identifier, contextType, {domNode, cssCanvasName, contextAttributes, memoryCost, backtrace} = {})
     {
         super();
 
         console.assert(identifier);
         console.assert(contextType);
-        console.assert(frame instanceof WI.Frame);
 
         this._identifier = identifier;
         this._contextType = contextType;
-        this._frame = frame;
         this._domNode = domNode || null;
         this._cssCanvasName = cssCanvasName || "";
         this._contextAttributes = contextAttributes || {};
@@ -77,8 +75,7 @@ WI.Canvas = class Canvas extends WI.Object
             console.error("Invalid canvas context type", payload.contextType);
         }
 
-        let frame = WI.frameResourceManager.frameForIdentifier(payload.frameId);
-        return new WI.Canvas(payload.canvasId, contextType, frame, {
+        return new WI.Canvas(payload.canvasId, contextType, {
             domNode: payload.nodeId ? WI.domTreeManager.nodeForId(payload.nodeId) : null,
             cssCanvasName: payload.cssCanvasName,
             contextAttributes: payload.contextAttributes,
@@ -114,7 +111,6 @@ WI.Canvas = class Canvas extends WI.Object
 
     get identifier() { return this._identifier; }
     get contextType() { return this._contextType; }
-    get frame() { return this._frame; }
     get cssCanvasName() { return this._cssCanvasName; }
     get contextAttributes() { return this._contextAttributes; }
     get extensions() { return this._extensions; }
@@ -263,8 +259,6 @@ WI.Canvas = class Canvas extends WI.Object
 
     saveIdentityToCookie(cookie)
     {
-        cookie[WI.Canvas.FrameURLCookieKey] = this._frame.url.hash;
-
         if (this._cssCanvasName)
             cookie[WI.Canvas.CSSCanvasNameCookieKey] = this._cssCanvasName;
         else if (this._domNode)
index 8c64023..342dec9 100644 (file)
@@ -1,3 +1,12 @@
+2017-12-14  Devin Rousso  <webkit@devinrousso.com>
+
+        Web Inspector: replace HTMLCanvasElement with CanvasRenderingContext for instrumentation logic
+        https://bugs.webkit.org/show_bug.cgi?id=180770
+
+        Reviewed by Joseph Pecoraro.
+
+        * Scripts/webkitpy/common/config/watchlist:
+
 2017-12-14  Alexey Proskuryakov  <ap@apple.com>
 
         Improve leaks detector output
index 197f825..e12ff6a 100644 (file)
                         r"|Source/WebInspectorUI/UserInterface/\w*/Recording.*\.js"
                         # Canvas
                         r"|Source/WebCore/inspector/InspectorCanvas.*"
-                        r"|Source/WebCore/html/canvas/Canvas.*\.idl"
-                        r"|Source/WebCore/html/canvas/WebGLRenderingContext\.idl"
-                        r"|Source/WebCore/html/canvas/WebGLRenderingContextBase\.idl",
+                        r"|Source/WebCore/html/canvas/Canvas.*",
         },
         "WebInspectorUIImages": {
             "filename": r"Source/WebInspectorUI/UserInterface/Images",