Web Inspector: add 2D/WebGL canvas instrumentation infrastructure
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2015 17:23:12 +0000 (17:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2015 17:23:12 +0000 (17:23 +0000)
commit2dd8fdac3122017018fa7dd79bbeadba1f2cb57c
tree756636e73739ff90a1a2891f1dd6eda7e21e2478
parent00d55b283b937a7e7393245d10c52de5b2cd8cf2
Web Inspector: add 2D/WebGL canvas instrumentation infrastructure
https://bugs.webkit.org/show_bug.cgi?id=137278

Patch by Matt Baker <mattbaker@apple.com> on 2015-03-31
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

Added Canvas protocol which defines types used by InspectorCanvasAgent.

* CMakeLists.txt:
* DerivedSources.make:
* inspector/protocol/Canvas.json: Added.

* inspector/scripts/codegen/generator.py:
(Generator.stylized_name_for_enum_value):
Added special handling for 2D (always uppercase) and WebGL (rename mapping) enum strings.

Source/WebCore:

Added backend agent for canvas inspection. A canvas is instrumented once its CanvasRenderingContext has been
created. WebGLRenderingContext is instrumented to track the lifetime of shader program objects.

To instrument off-screen rendering contexts (CSS canvases and detached canvas elements), the canvas agent must
track all CanvasRenderingContexts as they are created, even in the absense of the frontend. As far as I know,
there is no practical way to identify rendering contexts belonging to a frame that are not in the DOM. In the
absence of the inspector frontend the agent does only the minimum required to track the lifetime of rendering
contexts and their resources, to avoid creating a negative performance impact.

Tests: inspector/canvas/canvas-add-remove-events.html
       inspector/canvas/canvas-context-attributes.html
       inspector/canvas/canvas-css-name.html

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:

* dom/Document.cpp:
(WebCore::Document::getCSSCanvasElement):
Instrumentation for CSS canvases.

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext):
Instrumentation for context creation.

* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::attachShader):
(WebCore::WebGLRenderingContextBase::createProgram):
(WebCore::WebGLRenderingContextBase::deleteProgram):
(WebCore::WebGLRenderingContextBase::detachShader):
Instrumentation for programs and shaders.

* inspector/InspectorAllInOne.cpp:

* inspector/InspectorCanvasAgent.cpp: Added.
(WebCore::InspectorCanvasAgent::InspectorCanvasAgent):
(WebCore::InspectorCanvasAgent::didCreateFrontendAndBackend):
(WebCore::InspectorCanvasAgent::willDestroyFrontendAndBackend):
(WebCore::InspectorCanvasAgent::frameNavigated):
(WebCore::InspectorCanvasAgent::didCreateCSSCanvas):
(WebCore::InspectorCanvasAgent::didCreateCanvasRenderingContext):
(WebCore::InspectorCanvasAgent::didAttachShader):
(WebCore::InspectorCanvasAgent::didDetachShader):
(WebCore::InspectorCanvasAgent::didCreateProgram):
(WebCore::InspectorCanvasAgent::didDeleteProgram):
(WebCore::InspectorCanvasAgent::getCanvases):
(WebCore::InspectorCanvasAgent::canvasDestroyed):
(WebCore::InspectorCanvasAgent::canvasDestroyedTimerFired):
(WebCore::InspectorCanvasAgent::reset):
(WebCore::InspectorCanvasAgent::getCanvasEntry):
(WebCore::InspectorCanvasAgent::getProgramEntry):
(WebCore::InspectorCanvasAgent::removeShaderFromShaderMap):
(WebCore::InspectorCanvasAgent::contextTypeJson):
(WebCore::InspectorCanvasAgent::buildObjectForCanvas):
* inspector/InspectorCanvasAgent.h: Added.
New backend agent.

* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
Support for new backend agent.

* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::didCommitLoadImpl):
(WebCore::InspectorInstrumentation::didCreateCSSCanvasImpl):
(WebCore::InspectorInstrumentation::didCreateCanvasRenderingContextImpl):
(WebCore::InspectorInstrumentation::didAttachShaderImpl):
(WebCore::InspectorInstrumentation::didDetachShaderImpl):
(WebCore::InspectorInstrumentation::didCreateProgramImpl):
(WebCore::InspectorInstrumentation::didDeleteProgramImpl):
(WebCore::InspectorInstrumentation::instrumentingAgentsForRenderingContext):
Plumbing for canvas instrumentation.

* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::didCreateCSSCanvas):
(WebCore::InspectorInstrumentation::didCreateCanvasRenderingContext):
(WebCore::InspectorInstrumentation::didAttachShader):
(WebCore::InspectorInstrumentation::didDetachShader):
(WebCore::InspectorInstrumentation::didCreateProgram):
(WebCore::InspectorInstrumentation::didDeleteProgram):

* inspector/InstrumentingAgents.cpp:
(WebCore::InstrumentingAgents::InstrumentingAgents):
(WebCore::InstrumentingAgents::reset):
* inspector/InstrumentingAgents.h:
(WebCore::InstrumentingAgents::inspectorCanvasAgent):
(WebCore::InstrumentingAgents::setInspectorCanvasAgent):
Support for new backend agent.

Source/WebInspectorUI:

Added models, views, and controller classes for 2D and WebGL canvas inspection. Each canvas is shown in the
Resources navigation sidebar under its parent frame. Shader programs are displayed as child nodes of
their respective canvas. Canvases will get an associated content view and details sidebar in a later patch
(see https://bugs.webkit.org/show_bug.cgi?id=138941).

Shader programs will get an associated content view for editing shader source in a later patch (see
https://bugs.webkit.org/show_bug.cgi?id=138593). Individual shaders are not shown in the Resource navigation
sidebar, and at this time there are no plans to instrument shaders that aren't attached to a program.

* Localizations/en.lproj/localizedStrings.js:
* UserInterface/Base/Main.js:
(WebInspector.loaded):
(WebInspector.sidebarPanelForRepresentedObject):
* UserInterface/Base/Test.js:
(WebInspector.loaded):
* UserInterface/Main.html:
* UserInterface/Test.html:
Updated for new canvas/shader program types.

* UserInterface/Controllers/CanvasManager.js: Added.
(WebInspector.CanvasManager):
(WebInspector.CanvasManager.prototype.canvasesForFrame):
(WebInspector.CanvasManager.prototype.canvasAdded.set this):
(WebInspector.CanvasManager.prototype.canvasAdded):
(WebInspector.CanvasManager.prototype.canvasRemoved):
(WebInspector.CanvasManager.programDeleted.get console):
(WebInspector.CanvasManager.prototype.programCreated.get console):
(WebInspector.CanvasManager.prototype.programCreated):
(WebInspector.CanvasManager.prototype._mainResourceDidChange):
Frontend controller for canvases and their shader programs.

* UserInterface/Images/Canvas.svg: Added.
* UserInterface/Images/DocumentGL.png: Added.
* UserInterface/Images/DocumentGL@2x.png: Added.
New art for canvas and shader program tree elements.

* UserInterface/Models/Canvas.js: Added.
(WebInspector.Canvas):
(WebInspector.Canvas.prototype.set fromPayload):
(WebInspector.Canvas.displayNameForContextType):
(WebInspector.Canvas.resetUniqueDisplayNameNumbers):
(WebInspector.Canvas.prototype.get id):
(WebInspector.Canvas.prototype.get parentFrame):
(WebInspector.Canvas.prototype.get name):
(WebInspector.Canvas.prototype.get cssCanvas):
(WebInspector.Canvas.prototype.get contextType):
(WebInspector.Canvas.prototype.get contextAttributes):
(WebInspector.Canvas.prototype.get programs):
(WebInspector.Canvas.prototype.get displayName):
(WebInspector.Canvas.programForId):
(WebInspector.Canvas.get programWasCreated.set this):
(WebInspector.Canvas.prototype.get programWasCreated):
(WebInspector.Canvas.prototype.programWasDeleted):
(WebInspector.Canvas.prototype.saveIdentityToCookie):
Model for DOM or CSS canvas (2D or WebGL).

* UserInterface/Models/ShaderProgram.js: Added.
(WebInspector.ShaderProgram):
(WebInspector.ShaderProgram.prototype.get id):
(WebInspector.ShaderProgram.prototype.get canvas):
(WebInspector.ShaderProgram.prototype.get displayName):
(WebInspector.ShaderProgram.prototype.saveIdentityToCookie):
(WebInspector.ShaderProgram.prototype.updateCanvas):
* UserInterface/Models/WebGLContextAttributes.js: Added.
(WebInspector.WebGLContextAttributes):
(WebInspector.WebGLContextAttributes.fromPayload):
(WebInspector.WebGLContextAttributes.prototype.get alpha):
(WebInspector.WebGLContextAttributes.prototype.get depth):
(WebInspector.WebGLContextAttributes.prototype.get stencil):
(WebInspector.WebGLContextAttributes.prototype.get antialias):
(WebInspector.WebGLContextAttributes.prototype.get premultipliedAlpha):
(WebInspector.WebGLContextAttributes.prototype.get preserveDrawingBuffer):
Model for WebGL canvas context attributes.

* UserInterface/Protocol/CanvasObserver.js: Added.
(WebInspector.CanvasObserver.prototype.canvasAdded):
(WebInspector.CanvasObserver.prototype.canvasRemoved):
(WebInspector.CanvasObserver.prototype.programCreated):
(WebInspector.CanvasObserver.prototype.programDeleted):
(WebInspector.CanvasObserver):
Model for WebGL canvas shader program.

* UserInterface/Views/CanvasTreeElement.js: Added.
(WebInspector.CanvasTreeElement.validateRepresentedObject):
(WebInspector.CanvasTreeElement.countChildren):
(WebInspector.CanvasTreeElement):
(WebInspector.CanvasTreeElement.prototype.onexpand):
(WebInspector.CanvasTreeElement.prototype.oncollapse):
(WebInspector.CanvasTreeElement.prototype.onpopulate):
(WebInspector.CanvasTreeElement.prototype._programWasCreated):
(WebInspector.CanvasTreeElement.prototype._programWasDeleted):
Folderized tree element for canvases and their child objects (shader programs).

* UserInterface/Views/FrameTreeElement.js:
(WebInspector.FrameTreeElement.prototype.onattach):
(WebInspector.FrameTreeElement.prototype.ondetach):
(WebInspector.FrameTreeElement.prototype.onpopulate):
(WebInspector.FrameTreeElement.prototype._canvasesAvailable):
(WebInspector.FrameTreeElement.prototype._canvasWasAdded):
(WebInspector.FrameTreeElement.prototype._canvasWasRemoved):
Updated to support canvas tree elements.

* UserInterface/Views/ResourceIcons.css:
(.canvas-icon .icon):
(.shader-program-icon .icon):
Styles for new canvas and shader program icons.

* UserInterface/Views/ResourceSidebarPanel.js:
(WebInspector.ResourceSidebarPanel.prototype._treeElementSelected):
Updated for new tree element types.

* UserInterface/Views/ShaderProgramTreeElement.js: Added.
(WebInspector.ShaderProgramTreeElement):
Tree element for shader programs. Shown as children of CanvasTreeElement.

* WebInspectorUI.vcxproj/WebInspectorUI.vcxproj:
* WebInspectorUI.vcxproj/WebInspectorUI.vcxproj.filters:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182186 268f45cc-cd09-0410-ab3c-d52691b4dbfc
40 files changed:
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/DerivedSources.make
Source/JavaScriptCore/inspector/protocol/Canvas.json [new file with mode: 0644]
Source/JavaScriptCore/inspector/scripts/codegen/generator.py
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/Document.cpp
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp
Source/WebCore/inspector/InspectorAllInOne.cpp
Source/WebCore/inspector/InspectorCanvasAgent.cpp [new file with mode: 0644]
Source/WebCore/inspector/InspectorCanvasAgent.h [new file with mode: 0644]
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/InstrumentingAgents.cpp
Source/WebCore/inspector/InstrumentingAgents.h
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Base/Test.js
Source/WebInspectorUI/UserInterface/Controllers/CanvasManager.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Images/Canvas.svg [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Images/DocumentGL.png [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Images/DocumentGL@2x.png [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Main.html
Source/WebInspectorUI/UserInterface/Models/Canvas.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Models/ShaderProgram.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Models/WebGLContextAttributes.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Protocol/CanvasObserver.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Test.html
Source/WebInspectorUI/UserInterface/Views/CanvasTreeElement.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Views/FrameTreeElement.js
Source/WebInspectorUI/UserInterface/Views/ResourceIcons.css
Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/ShaderProgramTreeElement.js [new file with mode: 0644]
Source/WebInspectorUI/WebInspectorUI.vcxproj/WebInspectorUI.vcxproj
Source/WebInspectorUI/WebInspectorUI.vcxproj/WebInspectorUI.vcxproj.filters