Changeset 220436 in webkit


Ignore:
Timestamp:
Aug 8, 2017 6:55:53 PM (7 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Canvas: support editing WebGL shaders
https://bugs.webkit.org/show_bug.cgi?id=124211
<rdar://problem/15448958>

Reviewed by Matt Baker.

Source/JavaScriptCore:

  • inspector/protocol/Canvas.json:

Add updateShader command that will change the given shader's source to the provided string,
recompile, and relink it to its associated program.
Drive-by: add description to requestShaderSource command.

Source/WebCore:

Test: inspector/canvas/updateShader.html

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

(WebCore::InspectorCanvasAgent::updateShader):

  • html/canvas/WebGLRenderingContextBase.h:
  • html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::linkProgram):
(WebCore::WebGLRenderingContextBase::linkProgramWithoutInvalidatingAttribLocations):
Normally, when a program is linked, it invalidates any WebGLUniformLocation associated with
the program by incrementing its linkCount. In order to allow live editing of shaders, we
need to be able to compile and link a shader without invalidating these locations. This
patch moves the shader linking logic to its own function that is called by linkProgram so
that InspectorCanvasAgent can compile and link without invalidation.

Source/WebInspectorUI:

  • UserInterface/Models/ShaderProgram.js:

(WI.ShaderProgram.prototype.updateVertexShader):
(WI.ShaderProgram.prototype.updateFragmentShader):
(WI.ShaderProgram.prototype._updateShader):

  • UserInterface/Views/ShaderProgramContentView.js:

(WI.ShaderProgramContentView):
(WI.ShaderProgramContentView.prototype._contentDidChange):

LayoutTests:

  • inspector/canvas/updateShader-expected.txt: Added.
  • inspector/canvas/updateShader.html: Added.
  • platform/win/TestExpectations:
Location:
trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r220428 r220436  
     12017-08-08  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Canvas: support editing WebGL shaders
     4        https://bugs.webkit.org/show_bug.cgi?id=124211
     5        <rdar://problem/15448958>
     6
     7        Reviewed by Matt Baker.
     8
     9        * inspector/canvas/updateShader-expected.txt: Added.
     10        * inspector/canvas/updateShader.html: Added.
     11
     12        * platform/win/TestExpectations:
     13
    1142017-08-08  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/LayoutTests/platform/win/TestExpectations

    r220294 r220436  
    19171917inspector/canvas/shaderProgram-add-remove-webgl.html [ Skip ]
    19181918inspector/canvas/shaderProgram-add-remove-webgl2.html [ Skip ]
     1919inspector/canvas/updateShader.html [ Skip ]
    19191920################################################################################
    19201921#################          End WebGL Issues              #######################
  • trunk/Source/JavaScriptCore/ChangeLog

    r220432 r220436  
     12017-08-08  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Canvas: support editing WebGL shaders
     4        https://bugs.webkit.org/show_bug.cgi?id=124211
     5        <rdar://problem/15448958>
     6
     7        Reviewed by Matt Baker.
     8
     9        * inspector/protocol/Canvas.json:
     10        Add `updateShader` command that will change the given shader's source to the provided string,
     11        recompile, and relink it to its associated program.
     12        Drive-by: add description to `requestShaderSource` command.
     13
    1142017-08-08  Robin Morisset  <rmorisset@apple.com>
    215
  • trunk/Source/JavaScriptCore/inspector/protocol/Canvas.json

    r220294 r220436  
    123123        {
    124124            "name": "requestShaderSource",
    125             "description": "",
     125            "description": "Requests the source of the shader of the given type from the program with the given id.",
    126126            "parameters": [
    127127                { "name": "programId", "$ref": "ProgramId" },
     
    130130            "returns": [
    131131                { "name": "content", "type": "string" }
     132            ]
     133        },
     134        {
     135            "name": "updateShader",
     136            "description": "Compiles and links the shader with identifier and type with the given source code.",
     137            "parameters": [
     138                { "name": "programId", "$ref": "ProgramId" },
     139                { "name": "shaderType", "$ref": "ShaderType" },
     140                { "name": "source", "type": "string" }
    132141            ]
    133142        }
  • trunk/Source/WebCore/ChangeLog

    r220433 r220436  
     12017-08-08  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Canvas: support editing WebGL shaders
     4        https://bugs.webkit.org/show_bug.cgi?id=124211
     5        <rdar://problem/15448958>
     6
     7        Reviewed by Matt Baker.
     8
     9        Test: inspector/canvas/updateShader.html
     10
     11        * inspector/InspectorCanvasAgent.h:
     12        * inspector/InspectorCanvasAgent.cpp:
     13        (WebCore::InspectorCanvasAgent::updateShader):
     14
     15        * html/canvas/WebGLRenderingContextBase.h:
     16        * html/canvas/WebGLRenderingContextBase.cpp:
     17        (WebCore::WebGLRenderingContextBase::linkProgram):
     18        (WebCore::WebGLRenderingContextBase::linkProgramWithoutInvalidatingAttribLocations):
     19        Normally, when a program is linked, it invalidates any WebGLUniformLocation associated with
     20        the program by incrementing its `linkCount`. In order to allow live editing of shaders, we
     21        need to be able to compile and link a shader without invalidating these locations. This
     22        patch moves the shader linking logic to its own function that is called by `linkProgram` so
     23        that InspectorCanvasAgent can compile and link without invalidation.
     24
    1252017-08-08  Sam Weinig  <sam@webkit.org>
    226
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

    r220281 r220436  
    28372837void WebGLRenderingContextBase::linkProgram(WebGLProgram* program)
    28382838{
     2839    if (!linkProgramWithoutInvalidatingAttribLocations(program))
     2840        return;
     2841
     2842    program->increaseLinkCount();
     2843}
     2844
     2845bool WebGLRenderingContextBase::linkProgramWithoutInvalidatingAttribLocations(WebGLProgram* program)
     2846{
    28392847    if (isContextLostOrPending() || !validateWebGLObject("linkProgram", program))
    2840         return;
     2848        return false;
     2849
    28412850    WebGLShader* vertexShader = program->getAttachedShader(GraphicsContext3D::VERTEX_SHADER);
    28422851    WebGLShader* fragmentShader = program->getAttachedShader(GraphicsContext3D::FRAGMENT_SHADER);
    28432852    if (!vertexShader || !vertexShader->isValid() || !fragmentShader || !fragmentShader->isValid() || !m_context->precisionsMatch(objectOrZero(vertexShader), objectOrZero(fragmentShader)) || !m_context->checkVaryingsPacking(objectOrZero(vertexShader), objectOrZero(fragmentShader))) {
    28442853        program->setLinkStatus(false);
    2845         return;
     2854        return false;
    28462855    }
    28472856
    28482857    m_context->linkProgram(objectOrZero(program));
    2849     program->increaseLinkCount();
     2858    return true;
    28502859}
    28512860
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h

    r219831 r220436  
    229229    void lineWidth(GC3Dfloat);
    230230    void linkProgram(WebGLProgram*);
     231    bool linkProgramWithoutInvalidatingAttribLocations(WebGLProgram*);
    231232    void pixelStorei(GC3Denum pname, GC3Dint param);
    232233    void polygonOffset(GC3Dfloat factor, GC3Dfloat units);
  • trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp

    r220294 r220436  
    294294}
    295295
     296void InspectorCanvasAgent::updateShader(ErrorString& errorString, const String& programId, const String& shaderType, const String& source)
     297{
     298#if ENABLE(WEBGL)
     299    auto* inspectorProgram = assertInspectorProgram(errorString, programId);
     300    if (!inspectorProgram)
     301        return;
     302
     303    auto* shader = inspectorProgram->shaderForType(shaderType);
     304    if (!shader) {
     305        errorString = ASCIILiteral("No shader for given type.");
     306        return;
     307    }
     308
     309    WebGLRenderingContextBase* contextWebGL = inspectorProgram->context();
     310    contextWebGL->shaderSource(shader, source);
     311    contextWebGL->compileShader(shader);
     312
     313    if (!shader->isValid()) {
     314        errorString = ASCIILiteral("Shader compilation failed.");
     315        return;
     316    }
     317
     318    contextWebGL->linkProgramWithoutInvalidatingAttribLocations(&inspectorProgram->program());
     319#else
     320    UNUSED_PARAM(programId);
     321    UNUSED_PARAM(shaderType);
     322    UNUSED_PARAM(source);
     323    errorString = ASCIILiteral("WebGL is not supported.");
     324#endif
     325}
     326
    296327void InspectorCanvasAgent::frameNavigated(Frame& frame)
    297328{
  • trunk/Source/WebCore/inspector/InspectorCanvasAgent.h

    r220294 r220436  
    7777    void cancelRecording(ErrorString&, const String& canvasId) override;
    7878    void requestShaderSource(ErrorString&, const String& programId, const String& shaderType, String*) override;
     79    void updateShader(ErrorString&, const String& programId, const String& shaderType, const String& source) override;
    7980
    8081    // InspectorInstrumentation
  • trunk/Source/WebInspectorUI/ChangeLog

    r220370 r220436  
     12017-08-08  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Canvas: support editing WebGL shaders
     4        https://bugs.webkit.org/show_bug.cgi?id=124211
     5        <rdar://problem/15448958>
     6
     7        Reviewed by Matt Baker.
     8
     9        * UserInterface/Models/ShaderProgram.js:
     10        (WI.ShaderProgram.prototype.updateVertexShader):
     11        (WI.ShaderProgram.prototype.updateFragmentShader):
     12        (WI.ShaderProgram.prototype._updateShader):
     13
     14        * UserInterface/Views/ShaderProgramContentView.js:
     15        (WI.ShaderProgramContentView):
     16        (WI.ShaderProgramContentView.prototype._contentDidChange):
     17
    1182017-08-07  Devin Rousso  <drousso@apple.com>
    219
  • trunk/Source/WebInspectorUI/UserInterface/Models/ShaderProgram.js

    r220294 r220436  
    5858    }
    5959
     60    updateVertexShader(source)
     61    {
     62        this._updateShader(CanvasAgent.ShaderType.Vertex, source);
     63    }
     64
     65    updateFragmentShader(source)
     66    {
     67        this._updateShader(CanvasAgent.ShaderType.Fragment, source);
     68    }
     69
    6070    // Private
    6171
     
    7181        });
    7282    }
     83
     84    _updateShader(shaderType, source)
     85    {
     86        CanvasAgent.updateShader(this._identifier, shaderType, source, (error) => {
     87            console.assert(!error, error);
     88        });
     89    }
    7390};
    7491
  • trunk/Source/WebInspectorUI/UserInterface/Views/ShaderProgramContentView.js

    r220294 r220436  
    3636        let createEditor = (shaderType) => {
    3737            let textEditor = new WI.TextEditor;
     38            textEditor.readOnly = false;
    3839            textEditor.addEventListener(WI.TextEditor.Event.Focused, this._editorFocused, this);
    3940            textEditor.addEventListener(WI.TextEditor.Event.NumberOfSearchResultsDidChange, this._numberOfSearchResultsDidChange, this);
     41            textEditor.addEventListener(WI.TextEditor.Event.ContentDidChange, this.debounce(250)._contentDidChange, this);
    4042            textEditor.element.classList.add("shader");
    4143
     
    195197        this.dispatchEventToListeners(WI.ContentView.Event.NumberOfSearchResultsDidChange);
    196198    }
     199
     200    _contentDidChange(event)
     201    {
     202        if (event.target === this._vertexEditor)
     203            this.representedObject.updateVertexShader(this._vertexEditor.string);
     204        else if (event.target === this._fragmentEditor)
     205            this.representedObject.updateFragmentShader(this._fragmentEditor.string);
     206    }
    197207};
Note: See TracChangeset for help on using the changeset viewer.