| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 /** | |
| 7 * @fileoverview ProfilingView visualizes GPU_TRACE events using the | |
| 8 * gpu.Timeline component. | |
| 9 */ | |
| 10 cr.define('gpu', function() { | |
| 11 /** | |
| 12 * ProfilingView | |
| 13 * @constructor | |
| 14 * @extends {gpu.Tab} | |
| 15 */ | |
| 16 ProfilingView = cr.ui.define(cr.ui.TabPanel); | |
| 17 | |
| 18 ProfilingView.prototype = { | |
| 19 __proto__: cr.ui.TabPanel.prototype, | |
| 20 | |
| 21 traceEvents_: [], | |
| 22 | |
| 23 decorate: function() { | |
| 24 cr.ui.TabPanel.prototype.decorate.apply(this); | |
| 25 | |
| 26 // make the <list>/add/save/record element | |
| 27 this.controlDiv_ = document.createElement('div'); | |
| 28 this.controlDiv_.className = 'control'; | |
| 29 this.appendChild(this.controlDiv_); | |
| 30 | |
| 31 this.recordBn_ = document.createElement('button'); | |
| 32 this.recordBn_.textContent = 'Record'; | |
| 33 this.recordBn_.addEventListener('click', this.onRecord_.bind(this)); | |
| 34 | |
| 35 this.saveBn_ = document.createElement('button'); | |
| 36 this.saveBn_.textContent = 'Save'; | |
| 37 this.saveBn_.addEventListener('click', this.onSave_.bind(this)); | |
| 38 | |
| 39 this.loadBn_ = document.createElement('button'); | |
| 40 this.loadBn_.textContent = 'Load'; | |
| 41 this.loadBn_.addEventListener('click', this.onLoad_.bind(this)); | |
| 42 | |
| 43 this.container_ = document.createElement('div'); | |
| 44 this.container_.className = 'container'; | |
| 45 | |
| 46 this.timelineView_ = new TimelineView(); | |
| 47 | |
| 48 this.controlDiv_.appendChild(this.recordBn_); | |
| 49 if (!browserBridge.debugMode) { | |
| 50 this.controlDiv_.appendChild(this.loadBn_); | |
| 51 this.controlDiv_.appendChild(this.saveBn_); | |
| 52 } | |
| 53 | |
| 54 this.container_.appendChild(this.timelineView_); | |
| 55 this.appendChild(this.container_); | |
| 56 | |
| 57 document.addEventListener('keypress', this.onKeypress_.bind(this)); | |
| 58 | |
| 59 tracingController.addEventListener('traceEnded', | |
| 60 this.onRecordDone_.bind(this)); | |
| 61 tracingController.addEventListener('loadTraceFileComplete', | |
| 62 this.onLoadTraceFileComplete_.bind(this)); | |
| 63 tracingController.addEventListener('saveTraceFileComplete', | |
| 64 this.onSaveTraceFileComplete_.bind(this)); | |
| 65 tracingController.addEventListener('loadTraceFileCanceled', | |
| 66 this.onLoadTraceFileCanceled_.bind(this)); | |
| 67 tracingController.addEventListener('saveTraceFileCanceled', | |
| 68 this.onSaveTraceFileCanceled_.bind(this)); | |
| 69 this.refresh_(); | |
| 70 }, | |
| 71 | |
| 72 refresh_: function() { | |
| 73 var hasEvents = this.traceEvents_ && this.traceEvents_.length; | |
| 74 | |
| 75 this.saveBn_.disabled = !hasEvents; | |
| 76 | |
| 77 this.timelineView_.traceEvents = this.traceEvents_; | |
| 78 }, | |
| 79 | |
| 80 onKeypress_: function(event) { | |
| 81 if (event.keyCode == 114 && !tracingController.isTracingEnabled) { | |
| 82 if (!this.selected) | |
| 83 this.selected = true; | |
| 84 this.onRecord_(); | |
| 85 } | |
| 86 }, | |
| 87 | |
| 88 /////////////////////////////////////////////////////////////////////////// | |
| 89 | |
| 90 onRecord_: function() { | |
| 91 tracingController.beginTracing(); | |
| 92 }, | |
| 93 | |
| 94 onRecordDone_: function() { | |
| 95 this.traceEvents_ = tracingController.traceEvents; | |
| 96 this.refresh_(); | |
| 97 }, | |
| 98 | |
| 99 /////////////////////////////////////////////////////////////////////////// | |
| 100 | |
| 101 onSave_: function() { | |
| 102 this.overlayEl_ = new gpu.Overlay(); | |
| 103 this.overlayEl_.className = 'profiling-overlay'; | |
| 104 | |
| 105 var labelEl = document.createElement('div'); | |
| 106 labelEl.className = 'label'; | |
| 107 labelEl.textContent = 'Saving...'; | |
| 108 this.overlayEl_.appendChild(labelEl); | |
| 109 this.overlayEl_.visible = true; | |
| 110 | |
| 111 tracingController.beginSaveTraceFile(this.traceEvents_); | |
| 112 }, | |
| 113 | |
| 114 onSaveTraceFileComplete_: function(e) { | |
| 115 this.overlayEl_.visible = false; | |
| 116 this.overlayEl_ = undefined; | |
| 117 }, | |
| 118 | |
| 119 onSaveTraceFileCanceled_: function(e) { | |
| 120 this.overlayEl_.visible = false; | |
| 121 this.overlayEl_ = undefined; | |
| 122 }, | |
| 123 | |
| 124 /////////////////////////////////////////////////////////////////////////// | |
| 125 | |
| 126 onLoad_: function() { | |
| 127 this.overlayEl_ = new gpu.Overlay(); | |
| 128 this.overlayEl_.className = 'profiling-overlay'; | |
| 129 | |
| 130 var labelEl = document.createElement('div'); | |
| 131 labelEl.className = 'label'; | |
| 132 labelEl.textContent = 'Loading...'; | |
| 133 this.overlayEl_.appendChild(labelEl); | |
| 134 this.overlayEl_.visible = true; | |
| 135 | |
| 136 tracingController.beginLoadTraceFile(); | |
| 137 }, | |
| 138 | |
| 139 onLoadTraceFileComplete_: function(e) { | |
| 140 this.overlayEl_.visible = false; | |
| 141 this.overlayEl_ = undefined; | |
| 142 | |
| 143 this.traceEvents_ = e.events; | |
| 144 this.refresh_(); | |
| 145 }, | |
| 146 | |
| 147 onLoadTraceFileCanceled_: function(e) { | |
| 148 this.overlayEl_.visible = false; | |
| 149 this.overlayEl_ = undefined; | |
| 150 } | |
| 151 }; | |
| 152 | |
| 153 return { | |
| 154 ProfilingView: ProfilingView | |
| 155 }; | |
| 156 }); | |
| OLD | NEW |