Web Inspector: Canvas: replace constant numbers with their associated name on WebGL...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Oct 2018 08:00:37 +0000 (08:00 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Oct 2018 08:00:37 +0000 (08:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190026

Reviewed by Joseph Pecoraro.

* UserInterface/Models/RecordingAction.js:
(WI.RecordingAction.constantNameForParameter): Added.
(WI.RecordingAction.prototype.getColorParameters):
(WI.RecordingAction.prototype.getImageParameters):
Drive-by: add additional swatches to color/image arguments for WebGL actions.
* UserInterface/Views/CanvasSidebarPanel.js:
(WI.CanvasSidebarPanel.prototype._treeOutlineSelectionDidChange):
Drive-by: ensure that the `WI.RecordingContentView` is showing before applying the action.
* UserInterface/Views/RecordingActionTreeElement.js:
(WI.RecordingActionTreeElement._generateDOM.createParameterElement):
(WI.RecordingActionTreeElement._generateDOM):
* UserInterface/Views/RecordingActionTreeElement.css:
(.item.action > .titles .parameter.constant): Added.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Models/RecordingAction.js
Source/WebInspectorUI/UserInterface/Views/RecordingActionTreeElement.css
Source/WebInspectorUI/UserInterface/Views/RecordingActionTreeElement.js

index 78d1bd6..fd43d36 100644 (file)
@@ -1,3 +1,26 @@
+2018-10-02  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Canvas: replace constant numbers with their associated name on WebGL contexts
+        https://bugs.webkit.org/show_bug.cgi?id=190026
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Models/RecordingAction.js:
+        (WI.RecordingAction.constantNameForParameter): Added.
+        (WI.RecordingAction.prototype.getColorParameters):
+        (WI.RecordingAction.prototype.getImageParameters):
+        Drive-by: add additional swatches to color/image arguments for WebGL actions.
+
+        * UserInterface/Views/CanvasSidebarPanel.js:
+        (WI.CanvasSidebarPanel.prototype._treeOutlineSelectionDidChange):
+        Drive-by: ensure that the `WI.RecordingContentView` is showing before applying the action.
+
+        * UserInterface/Views/RecordingActionTreeElement.js:
+        (WI.RecordingActionTreeElement._generateDOM.createParameterElement):
+        (WI.RecordingActionTreeElement._generateDOM):
+        * UserInterface/Views/RecordingActionTreeElement.css:
+        (.item.action > .titles .parameter.constant): Added.
+
 2018-10-01  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Fix a typo for execution context identifier
index 263ce2a..1316b1f 100644 (file)
@@ -87,6 +87,49 @@ WI.RecordingAction = class RecordingAction extends WI.Object
         return typeof Object.getOwnPropertyDescriptor(prototype, name).value === "function";
     }
 
+    static constantNameForParameter(type, name, value, index, count)
+    {
+        let indexesForType = WI.RecordingAction._constantIndexes[type];
+        if (!indexesForType)
+            return null;
+
+        let indexesForAction = indexesForType[name];
+        if (!indexesForAction)
+            return null;
+
+        if (Array.isArray(indexesForAction) && !indexesForAction.includes(index))
+            return null;
+
+        if (typeof indexesForAction === "object") {
+            let indexesForActionVariant = indexesForAction[count];
+            if (!indexesForActionVariant)
+                return null;
+
+            if (Array.isArray(indexesForActionVariant) && !indexesForActionVariant.includes(index))
+                return null;
+        }
+
+        if (value === 0 && type === WI.Recording.Type.CanvasWebGL) {
+            if (name === "blendFunc" || name === "blendFuncSeparate")
+                return "ZERO";
+            if (index === 0) {
+                if (name === "drawArrays" || name === "drawElements")
+                    return "POINTS";
+                if (name === "pixelStorei")
+                    return "NONE";
+            }
+        }
+
+        let prototype = WI.RecordingAction._prototypeForType(type);
+        for (let key in prototype) {
+            let descriptor = Object.getOwnPropertyDescriptor(prototype, key);
+            if (descriptor.value === value)
+                return key;
+        }
+
+        return null;
+    }
+
     static _prototypeForType(type)
     {
         if (type === WI.Recording.Type.Canvas2D)
@@ -323,6 +366,7 @@ WI.RecordingAction = class RecordingAction extends WI.Object
         // WebGL
         case "blendColor":
         case "clearColor":
+        case "colorMask":
             return this._parameters;
 
         // 2D (non-standard, legacy)
@@ -348,6 +392,12 @@ WI.RecordingAction = class RecordingAction extends WI.Object
         // BitmapRenderer
         case "transferFromImageBitmap":
             return this._parameters.slice(0, 1);
+
+        // WebGL
+        case "texImage2D":
+        case "texSubImage2D":
+        case "compressedTexImage2D":
+            return [this._parameters.lastValue];
         }
 
         return [];
@@ -366,6 +416,73 @@ WI.RecordingAction.Event = {
     ValidityChanged: "recording-action-marked-invalid",
 };
 
+WI.RecordingAction._constantIndexes = {
+    [WI.Recording.Type.CanvasWebGL]: {
+        "activeTexture": true,
+        "bindBuffer": true,
+        "bindFramebuffer": true,
+        "bindRenderbuffer": true,
+        "bindTexture": true,
+        "blendEquation": true,
+        "blendEquationSeparate": true,
+        "blendFunc": true,
+        "blendFuncSeparate": true,
+        "bufferData": [0, 2],
+        "bufferSubData": [0],
+        "checkFramebufferStatus": true,
+        "compressedTexImage2D": [0, 2],
+        "compressedTexSubImage2D": [0],
+        "copyTexImage2D": [0, 2],
+        "copyTexSubImage2D": [0],
+        "createShader": true,
+        "cullFace": true,
+        "depthFunc": true,
+        "disable": true,
+        "drawArrays": [0],
+        "drawElements": [0, 2],
+        "enable": true,
+        "framebufferRenderbuffer": true,
+        "framebufferTexture2D": [0, 1, 2],
+        "frontFace": true,
+        "generateMipmap": true,
+        "getBufferParameter": true,
+        "getFramebufferAttachmentParameter": true,
+        "getParameter": true,
+        "getProgramParameter": true,
+        "getRenderbufferParameter": true,
+        "getShaderParameter": true,
+        "getShaderPrecisionFormat": true,
+        "getTexParameter": true,
+        "getVertexAttrib": [1],
+        "getVertexAttribOffset": [1],
+        "hint": true,
+        "isEnabled": true,
+        "pixelStorei": [0],
+        "readPixels": [4, 5],
+        "renderbufferStorage": [0, 1],
+        "stencilFunc": [0],
+        "stencilFuncSeparate": [0, 1],
+        "stencilMaskSeparate": [0],
+        "stencilOp": true,
+        "stencilOpSeparate": true,
+        "texImage2D": {
+            5: [0, 2, 3, 4],
+            6: [0, 2, 3, 4],
+            8: [0, 2, 6, 7],
+            9: [0, 2, 6, 7],
+        },
+        "texParameterf": [0, 1],
+        "texParameteri": [0, 1],
+        "texSubImage2D": {
+            6: [0, 4, 5],
+            7: [0, 4, 5],
+            8: [0, 6, 7],
+            9: [0, 6, 7],
+        },
+        "vertexAttribPointer": [2],
+    },
+};
+
 WI.RecordingAction._visualNames = {
     [WI.Recording.Type.Canvas2D]: new Set([
         "clearRect",
index bacea29..33a87a0 100644 (file)
@@ -61,6 +61,12 @@ body[dir=rtl] .item.action::before {
     color: var(--text-color-gray-medium);
 }
 
+.item.action > .titles .parameter.constant {
+    font-size: calc(100% - 1px);
+    font-family: Menlo, monospace;
+    font-style: italic;
+}
+
 body:not(.window-inactive, .window-docked-inactive) .tree-outline:matches(:focus, .force-focus) .item.action.selected > .titles .parameter.swizzled,
 body:not(.window-inactive, .window-docked-inactive) .tree-outline:matches(:focus, .force-focus) .item.action.selected::before {
     color: var(--selected-secondary-text-color);
index 5d31810..88ba84a 100644 (file)
@@ -45,13 +45,20 @@ WI.RecordingActionTreeElement = class RecordingActionTreeElement extends WI.Gene
 
     static _generateDOM(recordingAction, recordingType)
     {
-        function createParameterElement(parameter, swizzleType) {
+        let parameterCount = recordingAction.parameters.length;
+
+        function createParameterElement(parameter, swizzleType, index) {
             let parameterElement = document.createElement("span");
             parameterElement.classList.add("parameter");
 
             switch (swizzleType) {
             case WI.Recording.Swizzle.Number:
-                parameterElement.textContent = parameter.maxDecimals(2);
+                var constantNameForParameter = WI.RecordingAction.constantNameForParameter(recordingType, recordingAction.name, parameter, index, parameterCount);
+                if (constantNameForParameter) {
+                    parameterElement.classList.add("constant");
+                    parameterElement.textContent = "context." + constantNameForParameter;
+                } else
+                    parameterElement.textContent = parameter.maxDecimals(2);
                 break;
 
             case WI.Recording.Swizzle.Boolean:
@@ -102,7 +109,7 @@ WI.RecordingActionTreeElement = class RecordingActionTreeElement extends WI.Gene
         nameContainer.classList.add("name");
         nameContainer.textContent = recordingAction.name;
 
-        if (!recordingAction.parameters.length)
+        if (!parameterCount)
             return {titleFragment, copyText};
 
         let parametersContainer = titleFragment.appendChild(document.createElement("span"));
@@ -113,10 +120,10 @@ WI.RecordingActionTreeElement = class RecordingActionTreeElement extends WI.Gene
         else
             copyText += " = ";
 
-        for (let i = 0; i < recordingAction.parameters.length; ++i) {
+        for (let i = 0; i < parameterCount; ++i) {
             let parameter = recordingAction.parameters[i];
             let swizzleType = recordingAction.swizzleTypes[i];
-            let parameterElement = createParameterElement(parameter, swizzleType);
+            let parameterElement = createParameterElement(parameter, swizzleType, i);
             parametersContainer.appendChild(parameterElement);
 
             if (i)