2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @param {!WebInspector.Target} target
34 * @param {string} snapshotId
36 WebInspector.PaintProfilerSnapshot = function(target, snapshotId)
38 this._target = target;
39 this._id = snapshotId;
43 * @param {!WebInspector.Target} target
44 * @param {string} encodedPicture
45 * @param {function(?WebInspector.PaintProfilerSnapshot)} callback
47 WebInspector.PaintProfilerSnapshot.load = function(target, encodedPicture, callback)
49 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "LayerTreeAgent.loadSnapshot(): ", WebInspector.PaintProfilerSnapshot.bind(null, target));
50 target.layerTreeAgent().loadSnapshot(encodedPicture, wrappedCallback);
54 * @param {!Array.<!WebInspector.RawPaintProfilerLogItem>} log
55 * @return {!Array.<!WebInspector.PaintProfilerLogItem>}
57 WebInspector.PaintProfilerSnapshot._processAnnotations = function(log)
60 /** @type {!Array.<!Object.<string, string>>} */
61 var commentGroupStack = [];
63 for (var i = 0; i < log.length; ++i) {
64 var method = log[i].method;
66 case "beginCommentGroup":
67 commentGroupStack.push({});
70 var group = commentGroupStack.peekLast();
72 console.assert(false, "Stray comment without a group");
75 var key = String(log[i].params["key"]);
76 var value = String(log[i].params["value"]);
77 if (!key || typeof value === "undefined") {
78 console.assert(false, "Missing key or value in addComment() params");
82 console.assert(false, "Duplicate key in comment group");
87 case "endCommentGroup":
88 if (!commentGroupStack.length)
89 console.assert(false, "Unbalanced commentGroupEnd call");
91 commentGroupStack.pop();
94 result.push(new WebInspector.PaintProfilerLogItem(log[i], i, commentGroupStack.peekLast()));
100 WebInspector.PaintProfilerSnapshot.prototype = {
103 this._target.layerTreeAgent().releaseSnapshot(this._id);
107 * @return {!WebInspector.Target}
115 * @param {?number} firstStep
116 * @param {?number} lastStep
117 * @param {?number} scale
118 * @param {function(string=)} callback
120 requestImage: function(firstStep, lastStep, scale, callback)
122 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "LayerTreeAgent.replaySnapshot(): ");
123 this._target.layerTreeAgent().replaySnapshot(this._id, firstStep || undefined, lastStep || undefined, scale || 1.0, wrappedCallback);
127 * @param {function(!Array.<!LayerTreeAgent.PaintProfile>=)} callback
129 profile: function(callback)
131 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "LayerTreeAgent.profileSnapshot(): ");
132 this._target.layerTreeAgent().profileSnapshot(this._id, 5, 1, wrappedCallback);
136 * @param {function(!Array.<!WebInspector.PaintProfilerLogItem>=)} callback
138 commandLog: function(callback)
141 * @param {?string} error
142 * @param {!Array.<!WebInspector.RawPaintProfilerLogItem>} log
144 function callbackWrapper(error, log)
147 console.error("LayerTreeAgent.snapshotCommandLog(): " + error);
151 callback(WebInspector.PaintProfilerSnapshot._processAnnotations(log));
154 this._target.layerTreeAgent().snapshotCommandLog(this._id, callbackWrapper);
159 * @typedef {!{method: string, params: Array.<Object.<string, *>>}}
161 WebInspector.RawPaintProfilerLogItem;
165 * @param {!WebInspector.RawPaintProfilerLogItem} rawEntry
166 * @param {number} commandIndex
167 * @param {!Object.<string, string>=} annotations
169 WebInspector.PaintProfilerLogItem = function(rawEntry, commandIndex, annotations)
171 this.method = rawEntry.method;
172 this.params = rawEntry.params;
173 this.annotations = annotations;
174 this.commandIndex = commandIndex;
177 WebInspector.PaintProfilerLogItem.prototype = {
183 if (!this.annotations)
185 var inspectorId = this.annotations["INSPECTOR_ID"];
186 return Number(inspectorId);