Changeset 218908 in webkit


Ignore:
Timestamp:
Jun 28, 2017 6:34:51 PM (7 years ago)
Author:
Devin Rousso
Message:

Web Inspector: Instrument active pixel memory used by canvases
https://bugs.webkit.org/show_bug.cgi?id=173087
<rdar://problem/32719261>

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

  • inspector/protocol/Canvas.json:
    • Add optional memoryCost attribute to the Canvas type.
    • Add canvasMemoryChanged event that is dispatched when the memoryCost of a canvas changes.

Source/WebCore:

Test: inspector/canvas/memory.html

  • html/HTMLCanvasElement.cpp:

(WebCore::HTMLCanvasElement::setImageBuffer):

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

(WebCore::InspectorCanvasAgent::didChangeCanvasMemory):
(WebCore::InspectorCanvasAgent::buildObjectForCanvas):

  • inspector/InspectorInstrumentation.h:
  • inspector/InspectorInstrumentation.cpp:

(WebCore::InspectorInstrumentation::didChangeCanvasMemory):
(WebCore::InspectorInstrumentation::didChangeCanvasMemoryImpl):

Source/WebInspectorUI:

  • .eslintrc:
  • UserInterface/Controllers/CanvasManager.js:

(WebInspector.CanvasManager.prototype.canvasMemoryChanged):

  • UserInterface/Models/Canvas.js:

(WebInspector.Canvas.fromPayload):
(WebInspector.Canvas.prototype.get memoryCost):
(WebInspector.Canvas.prototype.set memoryCost):

  • UserInterface/Protocol/CanvasObserver.js:

(WebInspector.CanvasObserver.prototype.canvasMemoryChanged):

  • UserInterface/Views/CanvasDetailsSidebarPanel.js:

(WebInspector.CanvasDetailsSidebarPanel.prototype.initialLayout):
(WebInspector.CanvasDetailsSidebarPanel.prototype._refreshIdentitySection):
(WebInspector.CanvasDetailsSidebarPanel.prototype._formatMemoryRow):
(WebInspector.CanvasDetailsSidebarPanel.prototype._canvasMemoryChanged):

  • Localizations/en.lproj/localizedStrings.js:
  • UserInterface/Base/Utilities.js:

(Number.bytesToString.value):
Add support for gigabyte numbers.

LayoutTests:

  • inspector/canvas/memory-expected.txt: Added.
  • inspector/canvas/memory.html: Added.
Location:
trunk
Files:
2 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r218893 r218908  
     12017-06-28  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Instrument active pixel memory used by canvases
     4        https://bugs.webkit.org/show_bug.cgi?id=173087
     5        <rdar://problem/32719261>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * inspector/canvas/memory-expected.txt: Added.
     10        * inspector/canvas/memory.html: Added.
     11
    1122017-06-28  Ryan Haddad  <ryanhaddad@apple.com>
    213
  • trunk/Source/JavaScriptCore/ChangeLog

    r218898 r218908  
     12017-06-28  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Instrument active pixel memory used by canvases
     4        https://bugs.webkit.org/show_bug.cgi?id=173087
     5        <rdar://problem/32719261>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * inspector/protocol/Canvas.json:
     10         - Add optional `memoryCost` attribute to the `Canvas` type.
     11         - Add `canvasMemoryChanged` event that is dispatched when the `memoryCost` of a canvas changes.
     12
    1132017-06-28  Joseph Pecoraro  <pecoraro@apple.com>
    214
  • trunk/Source/JavaScriptCore/inspector/protocol/Canvas.json

    r218618 r218908  
    3939                { "name": "nodeId", "$ref": "DOM.NodeId", "optional": true, "description": "The corresponding DOM node id." },
    4040                { "name": "cssCanvasName", "type": "string", "optional": true, "description": "The CSS canvas identifier, for canvases created with <code>document.getCSSCanvasContext</code>." },
    41                 { "name": "contextAttributes", "$ref": "ContextAttributes", "optional": true, "description": "Context attributes for WebGL rendering contexts." }
     41                { "name": "contextAttributes", "$ref": "ContextAttributes", "optional": true, "description": "Context attributes for WebGL rendering contexts." },
     42                { "name": "memoryCost", "type": "number", "optional": true, "description": "Memory usage of the canvas in bytes." }
    4243            ]
    4344        }
     
    8586                { "name": "canvasId", "$ref": "CanvasId", "description": "Removed canvas identifier." }
    8687            ]
     88        },
     89        {
     90            "name": "canvasMemoryChanged",
     91            "parameters": [
     92                { "name": "canvasId", "$ref": "CanvasId", "description": "Identifier of canvas that changed." },
     93                { "name": "memoryCost", "type": "number", "description": "New memory cost value for the canvas in bytes." }
     94            ]
    8795        }
    8896    ]
  • trunk/Source/WebCore/ChangeLog

    r218907 r218908  
     12017-06-28  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Instrument active pixel memory used by canvases
     4        https://bugs.webkit.org/show_bug.cgi?id=173087
     5        <rdar://problem/32719261>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        Test: inspector/canvas/memory.html
     10
     11        * html/HTMLCanvasElement.cpp:
     12        (WebCore::HTMLCanvasElement::setImageBuffer):
     13        * inspector/InspectorCanvasAgent.h:
     14        * inspector/InspectorCanvasAgent.cpp:
     15        (WebCore::InspectorCanvasAgent::didChangeCanvasMemory):
     16        (WebCore::InspectorCanvasAgent::buildObjectForCanvas):
     17        * inspector/InspectorInstrumentation.h:
     18        * inspector/InspectorInstrumentation.cpp:
     19        (WebCore::InspectorInstrumentation::didChangeCanvasMemory):
     20        (WebCore::InspectorInstrumentation::didChangeCanvasMemoryImpl):
     21
    1222017-06-28  Alex Christensen  <achristensen@webkit.org>
    223
  • trunk/Source/WebCore/html/HTMLCanvasElement.cpp

    r218440 r218908  
    757757void HTMLCanvasElement::setImageBuffer(std::unique_ptr<ImageBuffer> buffer) const
    758758{
    759     removeFromActivePixelMemory(memoryCost());
     759    size_t previousMemoryCost = memoryCost();
     760    removeFromActivePixelMemory(previousMemoryCost);
    760761
    761762    m_imageBuffer = WTFMove(buffer);
    762763
    763     activePixelMemory += memoryCost();
     764    size_t currentMemoryCost = memoryCost();
     765    activePixelMemory += currentMemoryCost;
     766
     767    if (m_imageBuffer && previousMemoryCost != currentMemoryCost)
     768        InspectorInstrumentation::didChangeCanvasMemory(const_cast<HTMLCanvasElement&>(*this));
    764769}
    765770
  • trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp

    r218618 r218908  
    181181}
    182182
     183void InspectorCanvasAgent::didChangeCanvasMemory(HTMLCanvasElement& canvasElement)
     184{
     185    CanvasEntry* canvasEntry = getCanvasEntry(canvasElement);
     186    if (!canvasEntry)
     187        return;
     188
     189    m_frontendDispatcher->canvasMemoryChanged(canvasEntry->identifier, canvasElement.memoryCost());
     190}
     191
    183192void InspectorCanvasAgent::canvasDestroyed(HTMLCanvasElement& canvasElement)
    184193{
     
    296305#endif
    297306
     307    if (size_t memoryCost = canvasElement.memoryCost())
     308        canvas->setMemoryCost(memoryCost);
     309
    298310    return canvas;
    299311}
  • trunk/Source/WebCore/inspector/InspectorCanvasAgent.h

    r218544 r218908  
    6565    void didCreateCSSCanvas(HTMLCanvasElement&, const String&);
    6666    void didCreateCanvasRenderingContext(HTMLCanvasElement&);
     67    void didChangeCanvasMemory(HTMLCanvasElement&);
    6768
    6869    // CanvasObserver
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r218440 r218908  
    10061006}
    10071007
     1008void InspectorInstrumentation::didChangeCanvasMemoryImpl(InstrumentingAgents* instrumentingAgents, HTMLCanvasElement& canvasElement)
     1009{
     1010    if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
     1011        canvasAgent->didChangeCanvasMemory(canvasElement);
     1012}
     1013
    10081014#if ENABLE(WEB_REPLAY)
    10091015void InspectorInstrumentation::sessionCreatedImpl(InstrumentingAgents& instrumentingAgents, RefPtr<ReplaySession>&& session)
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r218440 r218908  
    248248    static void didCreateCSSCanvas(HTMLCanvasElement&, const String&);
    249249    static void didCreateCanvasRenderingContext(HTMLCanvasElement&);
     250    static void didChangeCanvasMemory(HTMLCanvasElement&);
    250251
    251252    static void networkStateChanged(Page&);
     
    423424    static void didCreateCSSCanvasImpl(InstrumentingAgents*, HTMLCanvasElement&, const String&);
    424425    static void didCreateCanvasRenderingContextImpl(InstrumentingAgents*, HTMLCanvasElement&);
     426    static void didChangeCanvasMemoryImpl(InstrumentingAgents*, HTMLCanvasElement&);
    425427
    426428    static void layerTreeDidChangeImpl(InstrumentingAgents&);
     
    11941196}
    11951197
     1198inline void InspectorInstrumentation::didChangeCanvasMemory(HTMLCanvasElement& canvasElement)
     1199{
     1200    FAST_RETURN_IF_NO_FRONTENDS(void());
     1201    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(&canvasElement.document()))
     1202        didChangeCanvasMemoryImpl(instrumentingAgents, canvasElement);
     1203}
     1204
    11961205inline void InspectorInstrumentation::networkStateChanged(Page& page)
    11971206{
  • trunk/Source/WebInspectorUI/.eslintrc

    r205426 r218908  
    3535        "ApplicationCacheAgent": true,
    3636        "CSSAgent": true,
     37        "CanvasAgent": true,
    3738        "ConsoleAgent": true,
    3839        "DOMAgent": true,
  • trunk/Source/WebInspectorUI/ChangeLog

    r218897 r218908  
     12017-06-28  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Instrument active pixel memory used by canvases
     4        https://bugs.webkit.org/show_bug.cgi?id=173087
     5        <rdar://problem/32719261>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * .eslintrc:
     10        * UserInterface/Controllers/CanvasManager.js:
     11        (WebInspector.CanvasManager.prototype.canvasMemoryChanged):
     12        * UserInterface/Models/Canvas.js:
     13        (WebInspector.Canvas.fromPayload):
     14        (WebInspector.Canvas.prototype.get memoryCost):
     15        (WebInspector.Canvas.prototype.set memoryCost):
     16        * UserInterface/Protocol/CanvasObserver.js:
     17        (WebInspector.CanvasObserver.prototype.canvasMemoryChanged):
     18        * UserInterface/Views/CanvasDetailsSidebarPanel.js:
     19        (WebInspector.CanvasDetailsSidebarPanel.prototype.initialLayout):
     20        (WebInspector.CanvasDetailsSidebarPanel.prototype._refreshIdentitySection):
     21        (WebInspector.CanvasDetailsSidebarPanel.prototype._formatMemoryRow):
     22        (WebInspector.CanvasDetailsSidebarPanel.prototype._canvasMemoryChanged):
     23
     24        * Localizations/en.lproj/localizedStrings.js:
     25        * UserInterface/Base/Utilities.js:
     26        (Number.bytesToString.value):
     27        Add support for gigabyte numbers.
     28
    1292017-06-27  Joseph Pecoraro  <pecoraro@apple.com>
    230
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r218839 r218908  
    66localizedStrings["%.0f B"] = "%.0f B";
    77localizedStrings["%.0fms"] = "%.0fms";
     8localizedStrings["%.1f GB"] = "%.1f GB";
    89localizedStrings["%.1f KB"] = "%.1f KB";
    910localizedStrings["%.1f MB"] = "%.1f MB";
     
    1516localizedStrings["%.1fmin"] = "%.1fmin";
    1617localizedStrings["%.1fms"] = "%.1fms";
     18localizedStrings["%.2f GB"] = "%.2f GB";
    1719localizedStrings["%.2f KB"] = "%.2f KB";
    1820localizedStrings["%.2f MB"] = "%.2f MB";
     
    543545localizedStrings["Medium"] = "Medium";
    544546localizedStrings["Memory"] = "Memory";
     547localizedStrings["Memory usage of this canvas"] = "Memory usage of this canvas";
    545548localizedStrings["Memory: %s"] = "Memory: %s";
    546549localizedStrings["Message"] = "Message";
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r214405 r218908  
    10821082
    10831083        let megabytes = kilobytes / 1024;
    1084         if (higherResolution || Math.abs(megabytes) < 10)
    1085             return WebInspector.UIString("%.2f MB").format(megabytes);
    1086         return WebInspector.UIString("%.1f MB").format(megabytes);
     1084        if (Math.abs(megabytes) < 1024) {
     1085            if (higherResolution || Math.abs(megabytes) < 10)
     1086                return WebInspector.UIString("%.2f MB").format(megabytes);
     1087            return WebInspector.UIString("%.1f MB").format(megabytes);
     1088        }
     1089
     1090        let gigabytes = megabytes / 1024;
     1091        if (higherResolution || Math.abs(gigabytes) < 10)
     1092            return WebInspector.UIString("%.2f GB").format(gigabytes);
     1093        return WebInspector.UIString("%.1f GB").format(gigabytes);
    10871094    }
    10881095});
  • trunk/Source/WebInspectorUI/UserInterface/Controllers/CanvasManager.js

    r218544 r218908  
    7373    }
    7474
     75    canvasMemoryChanged(canvasIdentifier, memoryCost)
     76    {
     77        // Called from WebInspector.CanvasObserver.
     78
     79        let canvas = this._canvasIdentifierMap.get(canvasIdentifier);
     80        console.assert(canvas);
     81        if (!canvas)
     82            return;
     83
     84        canvas.memoryCost = memoryCost;
     85    }
     86
    7587    // Private
    7688
  • trunk/Source/WebInspectorUI/UserInterface/Models/Canvas.js

    r218618 r218908  
    2626WebInspector.Canvas = class Canvas extends WebInspector.Object
    2727{
    28     constructor(identifier, contextType, frame, {domNode, cssCanvasName, contextAttributes} = {})
     28    constructor(identifier, contextType, frame, {domNode, cssCanvasName, contextAttributes, memoryCost} = {})
    2929    {
    3030        super();
     
    4040        this._cssCanvasName = cssCanvasName || "";
    4141        this._contextAttributes = contextAttributes || {};
     42        this._memoryCost = memoryCost || NaN;
    4243    }
    4344
     
    6364            cssCanvasName: payload.cssCanvasName,
    6465            contextAttributes: payload.contextAttributes,
     66            memoryCost: payload.memoryCost,
    6567        });
    6668    }
     
    9092    get cssCanvasName() { return this._cssCanvasName; }
    9193    get contextAttributes() { return this._contextAttributes; }
     94
     95    get memoryCost()
     96    {
     97        return this._memoryCost;
     98    }
     99
     100    set memoryCost(memoryCost)
     101    {
     102        if (memoryCost === this._memoryCost)
     103            return;
     104
     105        this._memoryCost = memoryCost;
     106
     107        this.dispatchEventToListeners(WebInspector.Canvas.Event.MemoryChanged);
     108    }
    92109
    93110    get displayName()
     
    162179
    163180WebInspector.Canvas.ResourceSidebarType = "resource-type-canvas";
     181
     182WebInspector.Canvas.Event = {
     183    MemoryChanged: "canvas-memory-changed",
     184};
  • trunk/Source/WebInspectorUI/UserInterface/Protocol/CanvasObserver.js

    r218440 r218908  
    3737        WebInspector.canvasManager.canvasRemoved(canvasId);
    3838    }
     39
     40    canvasMemoryChanged(canvasId, memoryCost)
     41    {
     42        WebInspector.canvasManager.canvasMemoryChanged(canvasId, memoryCost);
     43    }
    3944};
  • trunk/Source/WebInspectorUI/UserInterface/Views/CanvasDetailsSidebarPanel.js

    r218618 r218908  
    5858            return;
    5959
    60         this._canvas = canvas || null;
    61 
    6260        if (this._node) {
    6361            this._node.removeEventListener(WebInspector.DOMNode.Event.AttributeModified, this._refreshSourceSection, this);
     
    6765        }
    6866
     67        if (this._canvas)
     68            this._canvas.removeEventListener(WebInspector.Canvas.Event.MemoryChanged, this._canvasMemoryChanged, this);
     69
     70        this._canvas = canvas || null;
     71
     72        if (this._canvas)
     73            this._canvas.addEventListener(WebInspector.Canvas.Event.MemoryChanged, this._canvasMemoryChanged, this);
     74
    6975        this.needsLayout();
    7076    }
     
    7884        this._nameRow = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Name"));
    7985        this._typeRow = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Type"));
     86        this._memoryRow = new WebInspector.DetailsSectionSimpleRow(WebInspector.UIString("Memory"));
    8087
    8188        let identitySection = new WebInspector.DetailsSection("canvas-details", WebInspector.UIString("Identity"));
    82         identitySection.groups = [new WebInspector.DetailsSectionGroup([this._nameRow, this._typeRow])];
     89        identitySection.groups = [new WebInspector.DetailsSectionGroup([this._nameRow, this._typeRow, this._memoryRow])];
    8390        this.contentView.element.appendChild(identitySection.element);
    8491
     
    129136        this._nameRow.value = this._canvas.displayName;
    130137        this._typeRow.value = WebInspector.Canvas.displayNameForContextType(this._canvas.contextType);
     138        this._formatMemoryRow();
    131139    }
    132140
     
    231239        dataGrid.updateLayoutIfNeeded();
    232240    }
     241
     242    _formatMemoryRow()
     243    {
     244        if (!this._canvas.memoryCost || isNaN(this._canvas.memoryCost)) {
     245            this._memoryRow.value = emDash;
     246            return;
     247        }
     248
     249        let canvasMemory = Number.bytesToString(this._canvas.memoryCost);
     250        this._memoryRow.value = canvasMemory;
     251        this._memoryRow.tooltip = WebInspector.UIString("Memory usage of this canvas");
     252    }
     253
     254    _canvasMemoryChanged(event)
     255    {
     256        this._formatMemoryRow();
     257    }
    233258};
Note: See TracChangeset for help on using the changeset viewer.