1 // Copyright (c) 2013 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.
7 tvcm.require('tracing.analysis.generic_object_view');
8 tvcm.require('tracing.analysis.analyze_selection');
9 tvcm.require('tracing.analysis.analysis_results');
11 tvcm.exportTo('cc', function() {
12 var tsRound = tracing.analysis.tsRound;
14 var GenericObjectViewWithLabel = tracing.analysis.GenericObjectViewWithLabel;
16 function Selection() {
17 this.selectionToSetIfClicked = undefined;
19 Selection.prototype = {
21 * When two things are picked in the UI, one must occasionally tie-break
22 * between them to decide what was really clicked. Things with higher
23 * specicifity will win.
26 throw new Error('Not implemented');
30 * If a selection is related to a specific layer, then this returns the
31 * layerId of that layer. If the selection is not related to a layer, for
32 * example if the device viewport is selected, then this returns undefined.
34 get associatedLayerId() {
35 throw new Error('Not implemented');
39 * If a selection is related to a specific render pass, then this returns
40 * the layerId of that layer. If the selection is not related to a layer,
41 * for example if the device viewport is selected, then this returns
44 get associatedRenderPassId() {
45 throw new Error('Not implemented');
49 * If the selected item(s) is visible on the pending tree in a way that
50 * should be highlighted, returns the quad for the item on the pending tree.
51 * Otherwise, returns undefined.
54 throw new Error('Not implemented');
58 * If the selected item(s) is visible on the active tree in a way that
59 * should be highlighted, returns the quad for the item on the active tree.
60 * Otherwise, returns undefined.
63 throw new Error('Not implemented');
67 * A stable string describing what is selected. Used to determine a stable
68 * color of the highlight quads for this selection.
71 throw new Error('Not implemented');
75 * Called when the selection is made active in the layer view. Must return
76 * an HTMLElement that explains this selection in detail.
78 createAnalysis: function() {
79 throw new Error('Not implemented');
83 * Should try to create the equivalent selection in the provided LTHI,
84 * or undefined if it can't be done.
86 findEquivalent: function(lthi) {
87 throw new Error('Not implemented');
94 function RenderPassSelection(renderPass, renderPassId) {
95 if (!renderPass || (renderPassId === undefined))
96 throw new Error('Render pass (with id) is required');
97 this.renderPass_ = renderPass;
98 this.renderPassId_ = renderPassId;
101 RenderPassSelection.prototype = {
102 __proto__: Selection.prototype,
108 get associatedLayerId() {
112 get associatedRenderPassId() {
113 return this.renderPassId_;
117 return this.renderPass_;
120 createAnalysis: function() {
121 var dataView = new GenericObjectViewWithLabel();
122 dataView.label = 'RenderPass ' + this.renderPassId_;
123 dataView.object = this.renderPass_.args;
128 return this.renderPass_.objectInstance.typeName;
135 function LayerSelection(layer) {
137 throw new Error('Layer is required');
141 LayerSelection.prototype = {
142 __proto__: Selection.prototype,
148 get associatedLayerId() {
149 return this.layer_.layerId;
152 get associatedRenderPassId() {
156 get quadIfPending() {
168 createAnalysis: function() {
169 var dataView = new GenericObjectViewWithLabel();
170 dataView.label = 'Layer ' + this.layer_.layerId;
171 if (this.layer_.usingGpuRasterization)
172 dataView.label += ' (GPU-rasterized)';
173 dataView.object = this.layer_.args;
178 return this.layer_.objectInstance.typeName;
181 findEquivalent: function(lthi) {
182 var layer = lthi.activeTree.findLayerWithId(this.layer_.layerId) ||
183 lthi.pendingTree.findLayerWithId(this.layer_.layerId);
186 return new LayerSelection(layer);
193 function TileSelection(tile) {
197 TileSelection.prototype = {
198 __proto__: Selection.prototype,
204 get associatedLayerId() {
205 return this.tile_.layerId;
209 return this.tile_.layerRect;
212 createAnalysis: function() {
213 var analysis = new GenericObjectViewWithLabel();
214 analysis.label = 'Tile ' + this.tile_.objectInstance.id + ' on layer ' +
216 analysis.object = this.tile_.args;
221 return this.tile_.objectInstance.typeName;
224 findEquivalent: function(lthi) {
225 var tileInstance = this.tile_.tileInstance;
226 if (lthi.ts < tileInstance.creationTs ||
227 lthi.ts >= tileInstance.deletionTs)
229 var tileSnapshot = tileInstance.getSnapshotAt(lthi.ts);
232 return new TileSelection(tileSnapshot);
239 function LayerRectSelection(layer, rectType, rect, opt_data) {
241 this.rectType_ = rectType;
243 this.data_ = opt_data !== undefined ? opt_data : rect;
246 LayerRectSelection.prototype = {
247 __proto__: Selection.prototype,
253 get associatedLayerId() {
254 return this.layer_.layerId;
261 createAnalysis: function() {
262 var analysis = new GenericObjectViewWithLabel();
263 analysis.label = this.rectType_ + ' on layer ' + this.layer_.layerId;
264 analysis.object = this.data_;
269 return this.rectType_;
272 findEquivalent: function(lthi) {
280 function RasterTaskSelection(rasterTask) {
281 this.rasterTask_ = rasterTask;
284 RasterTaskSelection.prototype = {
285 __proto__: Selection.prototype,
292 return this.rasterTask_.args.data.tile_id;
295 get associatedLayerId() {
296 return this.tile.layerId;
300 return this.tile.layerRect;
303 createAnalysis: function() {
304 var sel = new tracing.Selection();
305 sel.push(this.rasterTask_);
306 var analysis = new tracing.analysis.AnalysisResults();
307 tracing.analysis.analyzeSelection(analysis, sel);
312 return this.rasterTask_.title;
315 findEquivalent: function(lthi) {
316 // Raster tasks are only valid in one LTHI.
322 Selection: Selection,
323 RenderPassSelection: RenderPassSelection,
324 LayerSelection: LayerSelection,
325 TileSelection: TileSelection,
326 LayerRectSelection: LayerRectSelection,
327 RasterTaskSelection: RasterTaskSelection