OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 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 cr.define('gpu', function() { | |
5 function TracingController() { | |
6 this.overlay_ = $('gpu-tracing-overlay'); | |
arv (Not doing code reviews)
2011/02/23 17:51:25
I know we do this a lot in the options code but us
nduca
2011/02/23 23:34:13
I agree, it smells bad. I think there are two 'wro
| |
7 cr.ui.decorate(this.overlay_, gpu.Overlay); | |
8 | |
9 this.tracingEnabled_ = false; | |
arv (Not doing code reviews)
2011/02/23 17:51:25
I would move this to the prototype.
nduca
2011/02/23 23:34:13
Done.
| |
10 this.traceEvents_ = []; | |
11 } | |
12 TracingController.prototype = { | |
13 __proto__: cr.EventTarget.prototype, | |
14 | |
15 initUI : function(mainTabs) { | |
arv (Not doing code reviews)
2011/02/23 17:51:25
no ws before :
nduca
2011/02/23 23:34:13
Done.
| |
16 var startButton = $('gpu-tracing-start-button'); | |
17 var stopButton = $('gpu-tracing-stop-button'); | |
18 mainTabs.addCustomWidget(startButton); | |
19 | |
20 startButton.onclick = function() { | |
arv (Not doing code reviews)
2011/02/23 17:51:25
startButton.onclick = this.beginTracing.bind(this)
nduca
2011/02/23 23:34:13
Done.
| |
21 this.beginTracing(); | |
22 }.bind(this); | |
23 stopButton.onclick = function() { | |
24 this.endTracing(); | |
25 }.bind(this); | |
26 this.onclick = function() { | |
27 this.endTracing(); | |
28 }.bind(this); | |
29 }, | |
30 | |
31 /** | |
32 * Called by info_view to empty the trace buffer | |
33 */ | |
34 beginTracing : function() { | |
35 if(this.tracingEnabled_) throw new Error("Tracing already begun."); | |
arv (Not doing code reviews)
2011/02/23 17:51:25
line break
arv (Not doing code reviews)
2011/02/23 17:51:25
new is not needed here
nduca
2011/02/23 23:34:13
Done.
| |
36 | |
37 this.overlay_.show(); | |
38 | |
39 this.tracingEnabled_ = true; | |
40 console.log("Beginning to trace..."); | |
arv (Not doing code reviews)
2011/02/23 17:51:25
Use single quotes
| |
41 | |
42 this.traceEvents_ = []; | |
43 if(!browserBridge.debugMode) | |
44 chrome.send('beginTracing'); | |
45 | |
46 this.tracingEnabled_ = true; | |
47 | |
48 var e = new cr.Event('gpuTraceBegun'); | |
49 e.events = this.traceEvents_; | |
50 this.dispatchEvent(e); | |
51 | |
52 e = new cr.Event('gpuTraceEventsChanged'); | |
53 e.numEvents = this.traceEvents_.length; | |
54 this.dispatchEvent(e); | |
55 | |
56 this.currentlyBoundKeypressListener_ = this.onOverlayKeyPress_.bind(this); | |
arv (Not doing code reviews)
2011/02/23 17:51:25
I'm not sure this is cleaner but this can also be
nduca
2011/02/23 23:34:13
Thats pretty neat. I dislike that less than I woul
| |
57 window.addEventListener('keypress', this.currentlyBoundKeypressListener_); | |
58 }, | |
59 | |
60 onOverlayKeyPress_ : function(e) { | |
61 console.log(e); | |
62 if(e.charCode == 13) { // enter | |
arv (Not doing code reviews)
2011/02/23 17:51:25
if (e.keyIdentifier == 'Enter')
arv (Not doing code reviews)
2011/02/23 17:51:25
Whitespace after if
nduca
2011/02/23 23:34:13
Done.
| |
63 this.endTracing(); | |
64 } | |
65 }, | |
66 | |
67 /** | |
68 * Checks whether gpu tracing is enabled | |
69 */ | |
70 isGpuTracingEnabled : function() { | |
arv (Not doing code reviews)
2011/02/23 17:51:25
Maybe use a getter?
nduca
2011/02/23 23:34:13
Done.
| |
71 return this.tracingEnabled_; | |
72 }, | |
73 | |
74 /** | |
75 * Gets the currently traced events. If tracing is active, then | |
76 * this can change on the fly. | |
77 */ | |
78 getGpuTraceEvents : function() { | |
arv (Not doing code reviews)
2011/02/23 17:51:25
getter?
nduca
2011/02/23 23:34:13
Done.
| |
79 return this.traceEvents_; | |
80 }, | |
81 | |
82 /** | |
83 * Callbed by gpu c++ code when new GPU trace data arrives. | |
84 */ | |
85 onGpuTraceDataCollected: function(events) { | |
86 this.traceEvents_.push.apply(this.traceEvents_, events); | |
87 }, | |
88 | |
89 /** | |
90 * Called by info_view to finish tracing and update all views. | |
91 */ | |
92 endTracing : function() { | |
93 if(!this.tracingEnabled_) throw new Error("Tracing not begun."); | |
94 | |
95 window.removeEventListener('keypress', | |
96 this.currentlyBoundKeypressListener_); | |
97 | |
98 console.log("Finishing trace"); | |
99 if(!browserBridge.debugMode) | |
arv (Not doing code reviews)
2011/02/23 17:51:25
If else has curly braces then if should too
nduca
2011/02/23 23:34:13
Done.
| |
100 chrome.send('beginToEndTracing'); | |
101 else { | |
102 var events = getTimelineTestData1(); | |
103 this.onGpuTraceDataCollected(events); | |
104 window.setTimeout(this.onEndTracingComplete.bind(this), 250); | |
105 } | |
106 }, | |
107 /* Called by the browser when all processes ack tracing having completed. */ | |
108 onEndTracingComplete : function() { | |
109 this.overlay_.hide(); | |
110 this.tracingEnabled_ = false; | |
111 console.log("onEndTracingComplete p1 with " + | |
112 this.traceEvents_.length + " events."); | |
113 var e = new cr.Event('gpuTraceEnded'); | |
114 e.events = this.traceEvents_; | |
115 this.dispatchEvent(e); | |
116 }, | |
117 | |
118 selfTest : function() { | |
119 this.beginTracing(); | |
120 window.setTimeout(function() { | |
121 this.endTracing(); | |
arv (Not doing code reviews)
2011/02/23 17:51:25
this.endTracing.bind(this)
nduca
2011/02/23 23:34:13
Done.
| |
122 }.bind(this),500); | |
123 } | |
124 }; | |
125 return { | |
126 TracingController : TracingController | |
127 }; | |
128 }); | |
129 | |
OLD | NEW |