OLD | NEW |
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 Loading... |
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.PanelWithSidebarTree} |
36 */ | 36 */ |
37 WebInspector.PaintProfilerView = function(model, layers3DView) | 37 WebInspector.PaintProfilerView = function(model, layers3DView) |
38 { | 38 { |
39 WebInspector.VBox.call(this); | 39 WebInspector.PanelWithSidebarTree.call(this, "paint-profiler-view", 225); |
40 this.element.classList.add("paint-profiler-view"); | 40 this.sidebarElement().classList.add("outline-disclosure"); |
| 41 this._panelSplitView.addEventListener(WebInspector.SplitView.Events.SidebarS
izeChanged, this.onResize, this); |
41 | 42 |
42 this._model = model; | 43 this._model = model; |
43 this._layers3DView = layers3DView; | 44 this._layers3DView = layers3DView; |
44 | 45 |
45 this._canvas = this.element.createChild("canvas", "fill"); | 46 this._canvas = this.mainElement().createChild("canvas", "fill"); |
46 this._context = this._canvas.getContext("2d"); | 47 this._context = this._canvas.getContext("2d"); |
47 this._selectionWindow = new WebInspector.OverviewGrid.Window(this.element, t
his.element); | 48 this._selectionWindow = new WebInspector.OverviewGrid.Window(this.mainElemen
t(), this.mainElement()); |
48 this._selectionWindow.addEventListener(WebInspector.OverviewGrid.Events.Wind
owChanged, this._onWindowChanged, this); | 49 this._selectionWindow.addEventListener(WebInspector.OverviewGrid.Events.Wind
owChanged, this._onWindowChanged, this); |
49 | 50 |
50 this._innerBarWidth = 4 * window.devicePixelRatio; | 51 this._innerBarWidth = 4 * window.devicePixelRatio; |
51 this._minBarHeight = 4 * window.devicePixelRatio; | 52 this._minBarHeight = 4 * window.devicePixelRatio; |
52 this._barPaddingWidth = 2 * window.devicePixelRatio; | 53 this._barPaddingWidth = 2 * window.devicePixelRatio; |
53 this._outerBarWidth = this._innerBarWidth + this._barPaddingWidth; | 54 this._outerBarWidth = this._innerBarWidth + this._barPaddingWidth; |
54 | 55 |
55 this._reset(); | 56 this._reset(); |
56 } | 57 } |
57 | 58 |
58 WebInspector.PaintProfilerView.prototype = { | 59 WebInspector.PaintProfilerView.prototype = { |
59 onResize: function() | 60 onResize: function() |
60 { | 61 { |
61 this._update(); | 62 this._update(); |
62 }, | 63 }, |
63 | 64 |
64 _update: function() | 65 _update: function() |
65 { | 66 { |
66 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; | 67 this._canvas.width = this.mainElement().clientWidth * window.devicePixel
Ratio; |
67 this._canvas.height = this.element.clientHeight * window.devicePixelRati
o; | 68 this._canvas.height = this.mainElement().clientHeight * window.devicePix
elRatio; |
68 this._samplesPerBar = 0; | 69 this._samplesPerBar = 0; |
69 if (!this._profiles || !this._profiles.length) | 70 if (!this._profiles || !this._profiles.length) |
70 return; | 71 return; |
71 | 72 |
72 var maxBars = Math.floor((this._canvas.width - 2 * this._barPaddingWidth
) / this._outerBarWidth); | 73 var maxBars = Math.floor((this._canvas.width - 2 * this._barPaddingWidth
) / this._outerBarWidth); |
73 var sampleCount = this._profiles[0].length; | 74 var sampleCount = this._profiles[0].length; |
74 this._samplesPerBar = Math.ceil(sampleCount / maxBars); | 75 this._samplesPerBar = Math.ceil(sampleCount / maxBars); |
75 var barCount = Math.floor(sampleCount / this._samplesPerBar); | 76 var barCount = Math.floor(sampleCount / this._samplesPerBar); |
76 | 77 |
77 var maxBarTime = 0; | 78 var maxBarTime = 0; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 124 |
124 var screenLeft = this._selectionWindow.windowLeft * this._canvas.width; | 125 var screenLeft = this._selectionWindow.windowLeft * this._canvas.width; |
125 var screenRight = this._selectionWindow.windowRight * this._canvas.width
; | 126 var screenRight = this._selectionWindow.windowRight * this._canvas.width
; |
126 | 127 |
127 var barLeft = Math.floor((screenLeft - this._barPaddingWidth) / this._ou
terBarWidth); | 128 var barLeft = Math.floor((screenLeft - this._barPaddingWidth) / this._ou
terBarWidth); |
128 var barRight = Math.floor((screenRight - this._barPaddingWidth + this._i
nnerBarWidth)/ this._outerBarWidth); | 129 var barRight = Math.floor((screenRight - this._barPaddingWidth + this._i
nnerBarWidth)/ this._outerBarWidth); |
129 | 130 |
130 var stepLeft = Math.max(0, barLeft * this._samplesPerBar); | 131 var stepLeft = Math.max(0, barLeft * this._samplesPerBar); |
131 var stepRight = Math.min(barRight * this._samplesPerBar, this._profiles[
0].length); | 132 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)); | 133 this._snapshot.requestImage(stepLeft, stepRight, this._layers3DView.show
ImageForLayer.bind(this._layers3DView, this._layer)); |
| 134 this._snapshot.commandLog(stepLeft, stepRight, this._updateLog.bind(this
)); |
| 135 }, |
| 136 |
| 137 _updateLog: function(log) |
| 138 { |
| 139 this.sidebarTree.removeChildren(); |
| 140 for (var i = 0; i < log.length; ++i) { |
| 141 var node = new WebInspector.LogTreeElement(log[i]); |
| 142 this.sidebarTree.appendChild(node); |
| 143 } |
133 }, | 144 }, |
134 | 145 |
135 _reset: function() | 146 _reset: function() |
136 { | 147 { |
137 this._snapshot = null; | 148 this._snapshot = null; |
138 this._profiles = null; | 149 this._profiles = null; |
139 this._selectionWindow.reset(); | 150 this._selectionWindow.reset(); |
140 }, | 151 }, |
141 | 152 |
142 /** | 153 /** |
(...skipping 11 matching lines...) Expand all Loading... |
154 */ | 165 */ |
155 function onSnapshotDone(snapshot) | 166 function onSnapshotDone(snapshot) |
156 { | 167 { |
157 this._snapshot = snapshot; | 168 this._snapshot = snapshot; |
158 if (!snapshot) { | 169 if (!snapshot) { |
159 this._profiles = null; | 170 this._profiles = null; |
160 this._update(); | 171 this._update(); |
161 return; | 172 return; |
162 } | 173 } |
163 snapshot.requestImage(null, null, this._layers3DView.showImageForLay
er.bind(this._layers3DView, this._layer)); | 174 snapshot.requestImage(null, null, this._layers3DView.showImageForLay
er.bind(this._layers3DView, this._layer)); |
164 snapshot.profile(onProfileDone.bind(this)); | 175 snapshot.profile(onProfileDone.bind(this, snapshot)); |
165 } | 176 } |
166 | 177 |
167 /** | 178 /** |
| 179 * @param {!WebInspector.PaintProfilerSnapshot=} snapshot |
168 * @param {!Array.<!LayerTreeAgent.PaintProfile>=} profiles | 180 * @param {!Array.<!LayerTreeAgent.PaintProfile>=} profiles |
169 * @this {WebInspector.PaintProfilerView} | 181 * @this {WebInspector.PaintProfilerView} |
170 */ | 182 */ |
171 function onProfileDone(profiles) | 183 function onProfileDone(snapshot, profiles) |
172 { | 184 { |
173 this._profiles = profiles; | 185 this._profiles = profiles; |
| 186 snapshot.commandLog(null, null, onCommandLogDone.bind(this)); |
| 187 } |
| 188 |
| 189 /** |
| 190 * @param {!Array.<!Object>=} log |
| 191 * @this {WebInspector.PaintProfilerView} |
| 192 */ |
| 193 function onCommandLogDone(log) |
| 194 { |
| 195 this._updateLog(log); |
174 this._update(); | 196 this._update(); |
175 } | 197 } |
176 }, | 198 }, |
177 | 199 |
178 __proto__: WebInspector.VBox.prototype | 200 __proto__: WebInspector.PanelWithSidebarTree.prototype |
179 }; | 201 }; |
| 202 |
| 203 /** |
| 204 * @constructor |
| 205 * @param {!Object} logItem |
| 206 * @extends {TreeElement} |
| 207 */ |
| 208 WebInspector.LogTreeElement = function(logItem) |
| 209 { |
| 210 TreeElement.call(this, "", logItem); |
| 211 this._update(); |
| 212 } |
| 213 |
| 214 WebInspector.LogTreeElement.prototype = { |
| 215 /** |
| 216 * @param {!Object} param |
| 217 * @param {string} name |
| 218 * @return {string} |
| 219 */ |
| 220 _paramToString: function(param, name) |
| 221 { |
| 222 if (typeof param !== "object") |
| 223 return typeof param === "string" && param.length > 100 ? name : JSON
.stringify(param); |
| 224 var str = ""; |
| 225 var keyCount = 0; |
| 226 for (var key in param) { |
| 227 if (++keyCount > 4 || typeof param[key] === "object" || (typeof para
m[key] === "string" && param[key].length > 100)) |
| 228 return name; |
| 229 if (str) |
| 230 str += ", "; |
| 231 str += param[key]; |
| 232 } |
| 233 return str; |
| 234 }, |
| 235 |
| 236 /** |
| 237 * @param {!Object} params |
| 238 * @return {string} |
| 239 */ |
| 240 _paramsToString: function(params) |
| 241 { |
| 242 var str = ""; |
| 243 for (var key in params) { |
| 244 if (str) |
| 245 str += ", "; |
| 246 str += this._paramToString(params[key], key); |
| 247 } |
| 248 return str; |
| 249 }, |
| 250 |
| 251 _update: function() |
| 252 { |
| 253 var logItem = (this.representedObject); |
| 254 var title = document.createDocumentFragment(); |
| 255 title.textContent = logItem.method; |
| 256 if (logItem.params) |
| 257 title.textContent += "(" + this._paramsToString(logItem.params) + ")
"; |
| 258 this.title = title; |
| 259 }, |
| 260 |
| 261 __proto__: TreeElement.prototype |
| 262 }; |
OLD | NEW |