Chromium Code Reviews| 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.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.LogTreeView(this.sidebarElement()); | |
| 42 this.addEventListener(WebInspector.SplitView.Events.SidebarSizeChanged, this .onResize, this); | |
| 41 | 43 |
| 42 this._model = model; | 44 this._model = model; |
| 43 this._layers3DView = layers3DView; | 45 this._layers3DView = layers3DView; |
| 44 | 46 |
| 45 this._canvas = this.element.createChild("canvas", "fill"); | 47 this._canvas = this.mainElement().createChild("canvas", "fill"); |
| 46 this._context = this._canvas.getContext("2d"); | 48 this._context = this._canvas.getContext("2d"); |
| 47 this._selectionWindow = new WebInspector.OverviewGrid.Window(this.element, t his.element); | 49 this._selectionWindow = new WebInspector.OverviewGrid.Window(this.mainElemen t(), this.mainElement()); |
| 48 this._selectionWindow.addEventListener(WebInspector.OverviewGrid.Events.Wind owChanged, this._onWindowChanged, this); | 50 this._selectionWindow.addEventListener(WebInspector.OverviewGrid.Events.Wind owChanged, this._onWindowChanged, this); |
| 49 | 51 |
| 50 this._innerBarWidth = 4 * window.devicePixelRatio; | 52 this._innerBarWidth = 4 * window.devicePixelRatio; |
| 51 this._minBarHeight = 4 * window.devicePixelRatio; | 53 this._minBarHeight = 4 * window.devicePixelRatio; |
| 52 this._barPaddingWidth = 2 * window.devicePixelRatio; | 54 this._barPaddingWidth = 2 * window.devicePixelRatio; |
| 53 this._outerBarWidth = this._innerBarWidth + this._barPaddingWidth; | 55 this._outerBarWidth = this._innerBarWidth + this._barPaddingWidth; |
| 54 | 56 |
| 55 this._reset(); | 57 this._reset(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 WebInspector.PaintProfilerView.prototype = { | 60 WebInspector.PaintProfilerView.prototype = { |
| 59 onResize: function() | 61 onResize: function() |
| 60 { | 62 { |
| 61 this._update(); | 63 this._update(); |
| 62 }, | 64 }, |
| 63 | 65 |
| 64 _update: function() | 66 _update: function() |
| 65 { | 67 { |
| 66 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; | 68 this._canvas.width = this.mainElement().clientWidth * window.devicePixel Ratio; |
| 67 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; | 69 this._canvas.height = this.mainElement().clientHeight * window.devicePix elRatio; |
| 68 this._samplesPerBar = 0; | 70 this._samplesPerBar = 0; |
| 69 if (!this._profiles || !this._profiles.length) | 71 if (!this._profiles || !this._profiles.length) |
| 70 return; | 72 return; |
| 71 | 73 |
| 72 var maxBars = Math.floor((this._canvas.width - 2 * this._barPaddingWidth ) / this._outerBarWidth); | 74 var maxBars = Math.floor((this._canvas.width - 2 * this._barPaddingWidth ) / this._outerBarWidth); |
| 73 var sampleCount = this._profiles[0].length; | 75 var sampleCount = this._profiles[0].length; |
| 74 this._samplesPerBar = Math.ceil(sampleCount / maxBars); | 76 this._samplesPerBar = Math.ceil(sampleCount / maxBars); |
| 75 var barCount = Math.floor(sampleCount / this._samplesPerBar); | 77 var barCount = Math.floor(sampleCount / this._samplesPerBar); |
| 76 | 78 |
| 77 var maxBarTime = 0; | 79 var maxBarTime = 0; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 | 125 |
| 124 var screenLeft = this._selectionWindow.windowLeft * this._canvas.width; | 126 var screenLeft = this._selectionWindow.windowLeft * this._canvas.width; |
| 125 var screenRight = this._selectionWindow.windowRight * this._canvas.width ; | 127 var screenRight = this._selectionWindow.windowRight * this._canvas.width ; |
| 126 | 128 |
| 127 var barLeft = Math.floor((screenLeft - this._barPaddingWidth) / this._ou terBarWidth); | 129 var barLeft = Math.floor((screenLeft - this._barPaddingWidth) / this._ou terBarWidth); |
| 128 var barRight = Math.floor((screenRight - this._barPaddingWidth + this._i nnerBarWidth)/ this._outerBarWidth); | 130 var barRight = Math.floor((screenRight - this._barPaddingWidth + this._i nnerBarWidth)/ this._outerBarWidth); |
| 129 | 131 |
| 130 var stepLeft = Math.max(0, barLeft * this._samplesPerBar); | 132 var stepLeft = Math.max(0, barLeft * this._samplesPerBar); |
| 131 var stepRight = Math.min(barRight * this._samplesPerBar, this._profiles[ 0].length); | 133 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)); | 134 this._snapshot.requestImage(stepLeft, stepRight, this._layers3DView.show ImageForLayer.bind(this._layers3DView, this._layer)); |
| 135 this._logTreeView.updateLog(stepLeft, stepRight); | |
| 133 }, | 136 }, |
| 134 | 137 |
| 135 _reset: function() | 138 _reset: function() |
| 136 { | 139 { |
| 137 this._snapshot = null; | 140 this._snapshot = null; |
| 138 this._profiles = null; | 141 this._profiles = null; |
| 139 this._selectionWindow.reset(); | 142 this._selectionWindow.reset(); |
| 140 }, | 143 }, |
| 141 | 144 |
| 142 /** | 145 /** |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 154 */ | 157 */ |
| 155 function onSnapshotDone(snapshot) | 158 function onSnapshotDone(snapshot) |
| 156 { | 159 { |
| 157 this._snapshot = snapshot; | 160 this._snapshot = snapshot; |
| 158 if (!snapshot) { | 161 if (!snapshot) { |
| 159 this._profiles = null; | 162 this._profiles = null; |
| 160 this._update(); | 163 this._update(); |
| 161 return; | 164 return; |
| 162 } | 165 } |
| 163 snapshot.requestImage(null, null, this._layers3DView.showImageForLay er.bind(this._layers3DView, this._layer)); | 166 snapshot.requestImage(null, null, this._layers3DView.showImageForLay er.bind(this._layers3DView, this._layer)); |
| 164 snapshot.profile(onProfileDone.bind(this)); | 167 snapshot.profile(onProfileDone.bind(this, snapshot)); |
| 165 } | 168 } |
| 166 | 169 |
| 167 /** | 170 /** |
| 171 * @param {!WebInspector.PaintProfilerSnapshot=} snapshot | |
| 168 * @param {!Array.<!LayerTreeAgent.PaintProfile>=} profiles | 172 * @param {!Array.<!LayerTreeAgent.PaintProfile>=} profiles |
| 169 * @this {WebInspector.PaintProfilerView} | 173 * @this {WebInspector.PaintProfilerView} |
| 170 */ | 174 */ |
| 171 function onProfileDone(profiles) | 175 function onProfileDone(snapshot, profiles) |
|
caseq
2014/06/05 16:25:40
You don't need to pass snapshot, it's already avai
malch
2014/06/09 05:59:44
Done.
| |
| 172 { | 176 { |
| 173 this._profiles = profiles; | 177 this._profiles = profiles; |
| 178 snapshot.commandLog(onCommandLogDone.bind(this)); | |
| 179 } | |
| 180 | |
| 181 /** | |
| 182 * @param {!Array.<!Object>=} log | |
| 183 * @this {WebInspector.PaintProfilerView} | |
| 184 */ | |
| 185 function onCommandLogDone(log) | |
| 186 { | |
| 187 this._logTreeView.setLog(log); | |
| 188 this._logTreeView.updateLog(); | |
| 174 this._update(); | 189 this._update(); |
| 175 } | 190 } |
| 176 }, | 191 }, |
| 177 | 192 |
| 193 __proto__: WebInspector.SplitView.prototype | |
| 194 }; | |
| 195 | |
| 196 /** | |
| 197 * @constructor | |
| 198 * @param {!Element} sidebarElement | |
|
caseq
2014/06/05 16:25:40
remove this.
rather than passing parent element to
malch
2014/06/09 05:59:45
Done.
| |
| 199 * @extends {WebInspector.VBox} | |
| 200 */ | |
| 201 WebInspector.LogTreeView = function(sidebarElement) | |
| 202 { | |
| 203 WebInspector.VBox.call(this); | |
| 204 this.setMinimumSize(100, 25); | |
| 205 this.show(sidebarElement); | |
| 206 | |
| 207 this._sidebarElement = this.element; | |
|
caseq
2014/06/05 16:25:40
Why do you need it? Just use this.element.
malch
2014/06/09 05:59:44
Done.
| |
| 208 this._sidebarElement.classList.add("sidebar", "outline-disclosure"); | |
|
caseq
2014/06/05 16:25:40
Not sure if we need "sidebar" class here.
malch
2014/06/09 05:59:44
Done.
| |
| 209 var sidebarTreeElement = this._sidebarElement.createChild("ol", "sidebar-tre e"); | |
| 210 this.sidebarTree = new TreeOutline(sidebarTreeElement); | |
| 211 | |
| 212 this._log = []; | |
| 213 } | |
| 214 | |
| 215 WebInspector.LogTreeView.prototype = { | |
| 216 setLog: function(log) | |
| 217 { | |
| 218 this._log = log; | |
| 219 }, | |
| 220 | |
| 221 /** | |
| 222 * @param {number=} stepLeft | |
| 223 * @param {number=} stepRight | |
| 224 */ | |
| 225 updateLog: function(stepLeft, stepRight) | |
| 226 { | |
| 227 var log = this._log; | |
| 228 stepLeft = stepLeft || 0; | |
| 229 stepRight = stepRight || log.length - 1; | |
| 230 this.sidebarTree.removeChildren(); | |
| 231 for (var i = stepLeft; i <= stepRight; ++i) { | |
| 232 var node = new WebInspector.LogTreeElement(log[i]); | |
| 233 this.sidebarTree.appendChild(node); | |
| 234 } | |
| 235 }, | |
| 236 | |
| 178 __proto__: WebInspector.VBox.prototype | 237 __proto__: WebInspector.VBox.prototype |
| 179 }; | 238 }; |
| 239 | |
| 240 /** | |
| 241 * @constructor | |
| 242 * @param {!Object} logItem | |
| 243 * @extends {TreeElement} | |
| 244 */ | |
| 245 WebInspector.LogTreeElement = function(logItem) | |
| 246 { | |
| 247 TreeElement.call(this, "", logItem); | |
| 248 this._update(); | |
| 249 } | |
| 250 | |
| 251 WebInspector.LogTreeElement.prototype = { | |
| 252 /** | |
| 253 * @param {!Object} param | |
| 254 * @param {string} name | |
| 255 * @return {string} | |
| 256 */ | |
| 257 _paramToString: function(param, name) | |
| 258 { | |
| 259 if (typeof param !== "object") | |
| 260 return typeof param === "string" && param.length > 100 ? name : JSON .stringify(param); | |
| 261 var str = ""; | |
| 262 var keyCount = 0; | |
| 263 for (var key in param) { | |
| 264 if (++keyCount > 4 || typeof param[key] === "object" || (typeof para m[key] === "string" && param[key].length > 100)) | |
| 265 return name; | |
| 266 if (str) | |
| 267 str += ", "; | |
| 268 str += param[key]; | |
| 269 } | |
| 270 return str; | |
| 271 }, | |
| 272 | |
| 273 /** | |
| 274 * @param {!Object} params | |
| 275 * @return {string} | |
| 276 */ | |
| 277 _paramsToString: function(params) | |
| 278 { | |
| 279 var str = ""; | |
| 280 for (var key in params) { | |
| 281 if (str) | |
| 282 str += ", "; | |
| 283 str += this._paramToString(params[key], key); | |
| 284 } | |
| 285 return str; | |
| 286 }, | |
| 287 | |
| 288 _update: function() | |
| 289 { | |
| 290 var logItem = this.representedObject; | |
| 291 var title = document.createDocumentFragment(); | |
| 292 title.textContent = logItem.method; | |
|
caseq
2014/06/05 16:25:40
let's build complete text first, then assign it to
malch
2014/06/09 05:59:44
Done.
| |
| 293 if (logItem.params) | |
| 294 title.textContent += "(" + this._paramsToString(logItem.params) + ") "; | |
| 295 this.title = title; | |
| 296 }, | |
| 297 | |
| 298 __proto__: TreeElement.prototype | |
| 299 }; | |
| OLD | NEW |