Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / cc / selection.js
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.
4
5 'use strict';
6
7 tvcm.require('tracing.analysis.generic_object_view');
8 tvcm.require('tracing.analysis.analyze_selection');
9 tvcm.require('tracing.analysis.analysis_results');
10
11 tvcm.exportTo('cc', function() {
12   var tsRound = tracing.analysis.tsRound;
13
14   var GenericObjectViewWithLabel = tracing.analysis.GenericObjectViewWithLabel;
15
16   function Selection() {
17     this.selectionToSetIfClicked = undefined;
18   };
19   Selection.prototype = {
20     /**
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.
24      */
25     get specicifity() {
26       throw new Error('Not implemented');
27     },
28
29     /**
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.
33      */
34     get associatedLayerId() {
35       throw new Error('Not implemented');
36     },
37
38     /**
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
42      * undefined.
43      */
44     get associatedRenderPassId() {
45       throw new Error('Not implemented');
46     },
47
48     /**
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.
52      */
53     get quadIfPending() {
54       throw new Error('Not implemented');
55     },
56
57     /**
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.
61      */
62     get quadIfActive() {
63       throw new Error('Not implemented');
64     },
65
66     /**
67      * A stable string describing what is selected. Used to determine a stable
68      * color of the highlight quads for this selection.
69      */
70     get title() {
71       throw new Error('Not implemented');
72     },
73
74     /**
75      * Called when the selection is made active in the layer view. Must return
76      * an HTMLElement that explains this selection in detail.
77      */
78     createAnalysis: function() {
79       throw new Error('Not implemented');
80     },
81
82     /**
83      * Should try to create the equivalent selection in the provided LTHI,
84      * or undefined if it can't be done.
85      */
86     findEquivalent: function(lthi) {
87       throw new Error('Not implemented');
88     }
89   };
90
91   /**
92    * @constructor
93    */
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;
99   }
100
101   RenderPassSelection.prototype = {
102     __proto__: Selection.prototype,
103
104     get specicifity() {
105       return 1;
106     },
107
108     get associatedLayerId() {
109       return undefined;
110     },
111
112     get associatedRenderPassId() {
113       return this.renderPassId_;
114     },
115
116     get renderPass() {
117       return this.renderPass_;
118     },
119
120     createAnalysis: function() {
121       var dataView = new GenericObjectViewWithLabel();
122       dataView.label = 'RenderPass ' + this.renderPassId_;
123       dataView.object = this.renderPass_.args;
124       return dataView;
125     },
126
127     get title() {
128       return this.renderPass_.objectInstance.typeName;
129     }
130   };
131
132   /**
133    * @constructor
134    */
135   function LayerSelection(layer) {
136     if (!layer)
137       throw new Error('Layer is required');
138     this.layer_ = layer;
139   }
140
141   LayerSelection.prototype = {
142     __proto__: Selection.prototype,
143
144     get specicifity() {
145       return 1;
146     },
147
148     get associatedLayerId() {
149       return this.layer_.layerId;
150     },
151
152     get associatedRenderPassId() {
153       return undefined;
154     },
155
156     get quadIfPending() {
157       return undefined;
158     },
159
160     get quadIfActive() {
161       return undefined;
162     },
163
164     get layer() {
165       return this.layer_;
166     },
167
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;
174       return dataView;
175     },
176
177     get title() {
178       return this.layer_.objectInstance.typeName;
179     },
180
181     findEquivalent: function(lthi) {
182       var layer = lthi.activeTree.findLayerWithId(this.layer_.layerId) ||
183           lthi.pendingTree.findLayerWithId(this.layer_.layerId);
184       if (!layer)
185         return undefined;
186       return new LayerSelection(layer);
187     }
188   };
189
190   /**
191    * @constructor
192    */
193   function TileSelection(tile) {
194     this.tile_ = tile;
195   }
196
197   TileSelection.prototype = {
198     __proto__: Selection.prototype,
199
200     get specicifity() {
201       return 2;
202     },
203
204     get associatedLayerId() {
205       return this.tile_.layerId;
206     },
207
208     get layerRect() {
209       return this.tile_.layerRect;
210     },
211
212     createAnalysis: function() {
213       var analysis = new GenericObjectViewWithLabel();
214       analysis.label = 'Tile ' + this.tile_.objectInstance.id + ' on layer ' +
215           this.tile_.layerId;
216       analysis.object = this.tile_.args;
217       return analysis;
218     },
219
220     get title() {
221       return this.tile_.objectInstance.typeName;
222     },
223
224     findEquivalent: function(lthi) {
225       var tileInstance = this.tile_.tileInstance;
226       if (lthi.ts < tileInstance.creationTs ||
227           lthi.ts >= tileInstance.deletionTs)
228         return undefined;
229       var tileSnapshot = tileInstance.getSnapshotAt(lthi.ts);
230       if (!tileSnapshot)
231         return undefined;
232       return new TileSelection(tileSnapshot);
233     }
234   };
235
236   /**
237    * @constructor
238    */
239   function LayerRectSelection(layer, rectType, rect, opt_data) {
240     this.layer_ = layer;
241     this.rectType_ = rectType;
242     this.rect_ = rect;
243     this.data_ = opt_data !== undefined ? opt_data : rect;
244   }
245
246   LayerRectSelection.prototype = {
247     __proto__: Selection.prototype,
248
249     get specicifity() {
250       return 2;
251     },
252
253     get associatedLayerId() {
254       return this.layer_.layerId;
255     },
256
257     get layerRect() {
258       return this.rect_;
259     },
260
261     createAnalysis: function() {
262       var analysis = new GenericObjectViewWithLabel();
263       analysis.label = this.rectType_ + ' on layer ' + this.layer_.layerId;
264       analysis.object = this.data_;
265       return analysis;
266     },
267
268     get title() {
269       return this.rectType_;
270     },
271
272     findEquivalent: function(lthi) {
273       return undefined;
274     }
275   };
276
277   /**
278    * @constructor
279    */
280   function RasterTaskSelection(rasterTask) {
281     this.rasterTask_ = rasterTask;
282   }
283
284   RasterTaskSelection.prototype = {
285     __proto__: Selection.prototype,
286
287     get specicifity() {
288       return 3;
289     },
290
291     get tile() {
292       return this.rasterTask_.args.data.tile_id;
293     },
294
295     get associatedLayerId() {
296       return this.tile.layerId;
297     },
298
299     get layerRect() {
300       return this.tile.layerRect;
301     },
302
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);
308       return analysis;
309     },
310
311     get title() {
312       return this.rasterTask_.title;
313     },
314
315     findEquivalent: function(lthi) {
316       // Raster tasks are only valid in one LTHI.
317       return undefined;
318     }
319   };
320
321   return {
322     Selection: Selection,
323     RenderPassSelection: RenderPassSelection,
324     LayerSelection: LayerSelection,
325     TileSelection: TileSelection,
326     LayerRectSelection: LayerRectSelection,
327     RasterTaskSelection: RasterTaskSelection
328   };
329 });