Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: Source/devtools/front_end/layers/PaintProfilerView.js

Issue 319603007: DevTools: Add snapshot command log on the frontend. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Small fix. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/devtools/front_end/layersPanel.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @param {!WebInspector.LayerTreeModel} model 33 * @param {!WebInspector.LayerTreeModel} model
34 * @param {!WebInspector.Layers3DView} layers3DView 34 * @param {!WebInspector.Layers3DView} layers3DView
35 * @extends {WebInspector.VBox} 35 * @extends {WebInspector.SplitView}
36 */ 36 */
37 WebInspector.PaintProfilerView = function(model, layers3DView) 37 WebInspector.PaintProfilerView = function(model, layers3DView)
38 { 38 {
39 WebInspector.VBox.call(this); 39 WebInspector.SplitView.call(this, true, false);
40 this.element.classList.add("paint-profiler-view"); 40 this.element.classList.add("paint-profiler-view");
41 this._logTreeView = new WebInspector.PaintProfilerCommandLogView();
42 this._logTreeView.show(this.sidebarElement());
43 this.addEventListener(WebInspector.SplitView.Events.SidebarSizeChanged, this .onResize, this);
41 44
42 this._model = model; 45 this._model = model;
43 this._layers3DView = layers3DView; 46 this._layers3DView = layers3DView;
44 47
45 this._canvas = this.element.createChild("canvas", "fill"); 48 this._canvas = this.mainElement().createChild("canvas", "fill");
46 this._context = this._canvas.getContext("2d"); 49 this._context = this._canvas.getContext("2d");
47 this._selectionWindow = new WebInspector.OverviewGrid.Window(this.element, t his.element); 50 this._selectionWindow = new WebInspector.OverviewGrid.Window(this.mainElemen t(), this.mainElement());
48 this._selectionWindow.addEventListener(WebInspector.OverviewGrid.Events.Wind owChanged, this._onWindowChanged, this); 51 this._selectionWindow.addEventListener(WebInspector.OverviewGrid.Events.Wind owChanged, this._onWindowChanged, this);
49 52
50 this._innerBarWidth = 4 * window.devicePixelRatio; 53 this._innerBarWidth = 4 * window.devicePixelRatio;
51 this._minBarHeight = 4 * window.devicePixelRatio; 54 this._minBarHeight = 4 * window.devicePixelRatio;
52 this._barPaddingWidth = 2 * window.devicePixelRatio; 55 this._barPaddingWidth = 2 * window.devicePixelRatio;
53 this._outerBarWidth = this._innerBarWidth + this._barPaddingWidth; 56 this._outerBarWidth = this._innerBarWidth + this._barPaddingWidth;
54 57
55 this._reset(); 58 this._reset();
56 } 59 }
57 60
58 WebInspector.PaintProfilerView.prototype = { 61 WebInspector.PaintProfilerView.prototype = {
59 onResize: function() 62 onResize: function()
60 { 63 {
61 this._update(); 64 this._update();
62 }, 65 },
63 66
64 _update: function() 67 _update: function()
65 { 68 {
66 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; 69 this._canvas.width = this.mainElement().clientWidth * window.devicePixel Ratio;
67 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; 70 this._canvas.height = this.mainElement().clientHeight * window.devicePix elRatio;
68 this._samplesPerBar = 0; 71 this._samplesPerBar = 0;
69 if (!this._profiles || !this._profiles.length) 72 if (!this._profiles || !this._profiles.length)
70 return; 73 return;
71 74
72 var maxBars = Math.floor((this._canvas.width - 2 * this._barPaddingWidth ) / this._outerBarWidth); 75 var maxBars = Math.floor((this._canvas.width - 2 * this._barPaddingWidth ) / this._outerBarWidth);
73 var sampleCount = this._profiles[0].length; 76 var sampleCount = this._profiles[0].length;
74 this._samplesPerBar = Math.ceil(sampleCount / maxBars); 77 this._samplesPerBar = Math.ceil(sampleCount / maxBars);
75 var barCount = Math.floor(sampleCount / this._samplesPerBar); 78 var barCount = Math.floor(sampleCount / this._samplesPerBar);
76 79
77 var maxBarTime = 0; 80 var maxBarTime = 0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 126
124 var screenLeft = this._selectionWindow.windowLeft * this._canvas.width; 127 var screenLeft = this._selectionWindow.windowLeft * this._canvas.width;
125 var screenRight = this._selectionWindow.windowRight * this._canvas.width ; 128 var screenRight = this._selectionWindow.windowRight * this._canvas.width ;
126 129
127 var barLeft = Math.floor((screenLeft - this._barPaddingWidth) / this._ou terBarWidth); 130 var barLeft = Math.floor((screenLeft - this._barPaddingWidth) / this._ou terBarWidth);
128 var barRight = Math.floor((screenRight - this._barPaddingWidth + this._i nnerBarWidth)/ this._outerBarWidth); 131 var barRight = Math.floor((screenRight - this._barPaddingWidth + this._i nnerBarWidth)/ this._outerBarWidth);
129 132
130 var stepLeft = Math.max(0, barLeft * this._samplesPerBar); 133 var stepLeft = Math.max(0, barLeft * this._samplesPerBar);
131 var stepRight = Math.min(barRight * this._samplesPerBar, this._profiles[ 0].length); 134 var stepRight = Math.min(barRight * this._samplesPerBar, this._profiles[ 0].length);
132 this._snapshot.requestImage(stepLeft, stepRight, this._layers3DView.show ImageForLayer.bind(this._layers3DView, this._layer)); 135 this._snapshot.requestImage(stepLeft, stepRight, this._layers3DView.show ImageForLayer.bind(this._layers3DView, this._layer));
136 this._logTreeView.updateLog(stepLeft, stepRight);
133 }, 137 },
134 138
135 _reset: function() 139 _reset: function()
136 { 140 {
137 this._snapshot = null; 141 this._snapshot = null;
138 this._profiles = null; 142 this._profiles = null;
139 this._selectionWindow.reset(); 143 this._selectionWindow.reset();
140 }, 144 },
141 145
142 /** 146 /**
(...skipping 11 matching lines...) Expand all
154 */ 158 */
155 function onSnapshotDone(snapshot) 159 function onSnapshotDone(snapshot)
156 { 160 {
157 this._snapshot = snapshot; 161 this._snapshot = snapshot;
158 if (!snapshot) { 162 if (!snapshot) {
159 this._profiles = null; 163 this._profiles = null;
160 this._update(); 164 this._update();
161 return; 165 return;
162 } 166 }
163 snapshot.requestImage(null, null, this._layers3DView.showImageForLay er.bind(this._layers3DView, this._layer)); 167 snapshot.requestImage(null, null, this._layers3DView.showImageForLay er.bind(this._layers3DView, this._layer));
164 snapshot.profile(onProfileDone.bind(this)); 168 var barrier = new CallbackBarrier();
169 snapshot.profile(barrier.createCallback(onProfileDone.bind(this)));
170 snapshot.commandLog(barrier.createCallback(onCommandLogDone.bind(thi s)));
171 barrier.callWhenDone(this._update.bind(this));
165 } 172 }
166 173
167 /** 174 /**
168 * @param {!Array.<!LayerTreeAgent.PaintProfile>=} profiles 175 * @param {!Array.<!LayerTreeAgent.PaintProfile>=} profiles
169 * @this {WebInspector.PaintProfilerView} 176 * @this {WebInspector.PaintProfilerView}
170 */ 177 */
171 function onProfileDone(profiles) 178 function onProfileDone(profiles)
172 { 179 {
173 this._profiles = profiles; 180 this._profiles = profiles;
174 this._update(); 181 }
182
183 /**
184 * @param {!Array.<!Object>=} log
185 * @this {WebInspector.PaintProfilerView}
186 */
187 function onCommandLogDone(log)
188 {
189 this._logTreeView.setLog(log);
190 this._logTreeView.updateLog();
191 }
192 },
193
194 __proto__: WebInspector.SplitView.prototype
195 };
196
197 /**
198 * @constructor
199 * @extends {WebInspector.VBox}
200 */
201 WebInspector.PaintProfilerCommandLogView = function()
202 {
203 WebInspector.VBox.call(this);
204 this.setMinimumSize(100, 25);
205 this.element.classList.add("outline-disclosure");
206 var sidebarTreeElement = this.element.createChild("ol", "sidebar-tree");
207 this.sidebarTree = new TreeOutline(sidebarTreeElement);
208
209 this._log = [];
210 }
211
212 WebInspector.PaintProfilerCommandLogView.prototype = {
213 setLog: function(log)
214 {
215 this._log = log;
216 },
217
218 /**
219 * @param {number=} stepLeft
220 * @param {number=} stepRight
221 */
222 updateLog: function(stepLeft, stepRight)
223 {
224 var log = this._log;
225 stepLeft = stepLeft || 0;
226 stepRight = stepRight || log.length - 1;
227 this.sidebarTree.removeChildren();
228 for (var i = stepLeft; i <= stepRight; ++i) {
229 var node = new WebInspector.LogTreeElement(log[i]);
230 this.sidebarTree.appendChild(node);
175 } 231 }
176 }, 232 },
177 233
178 __proto__: WebInspector.VBox.prototype 234 __proto__: WebInspector.VBox.prototype
179 }; 235 };
236
237 /**
238 * @constructor
239 * @param {!Object} logItem
240 * @extends {TreeElement}
241 */
242 WebInspector.LogTreeElement = function(logItem)
243 {
244 TreeElement.call(this, "", logItem);
245 this._update();
246 }
247
248 WebInspector.LogTreeElement.prototype = {
249 /**
250 * @param {!Object} param
251 * @param {string} name
252 * @return {string}
253 */
254 _paramToString: function(param, name)
255 {
256 if (typeof param !== "object")
257 return typeof param === "string" && param.length > 100 ? name : JSON .stringify(param);
258 var str = "";
259 var keyCount = 0;
260 for (var key in param) {
261 if (++keyCount > 4 || typeof param[key] === "object" || (typeof para m[key] === "string" && param[key].length > 100))
262 return name;
263 if (str)
264 str += ", ";
265 str += param[key];
266 }
267 return str;
268 },
269
270 /**
271 * @param {!Object} params
272 * @return {string}
273 */
274 _paramsToString: function(params)
275 {
276 var str = "";
277 for (var key in params) {
278 if (str)
279 str += ", ";
280 str += this._paramToString(params[key], key);
281 }
282 return str;
283 },
284
285 _update: function()
286 {
287 var logItem = this.representedObject;
288 var title = document.createDocumentFragment();
289 title.createChild("div", "selection");
290 var textContent = logItem.method;
291 if (logItem.params)
292 textContent += "(" + this._paramsToString(logItem.params) + ")";
293 title.appendChild(document.createTextNode(textContent));
294 this.title = title;
295 },
296
297 /**
298 * @param {boolean} hovered
299 */
300 setHovered: function(hovered)
301 {
302 this.listItemElement.classList.toggle("hovered", hovered);
303 },
304
305 __proto__: TreeElement.prototype
306 };
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/layersPanel.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698