Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / cc / selection.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tracing/analysis/generic_object_view.html">
9
10 <script>
11 'use strict';
12
13 tv.exportTo('cc', function() {
14   var tsRound = tracing.analysis.tsRound;
15
16   var GenericObjectViewWithLabel = tracing.analysis.GenericObjectViewWithLabel;
17
18   function Selection() {
19     this.selectionToSetIfClicked = undefined;
20   };
21   Selection.prototype = {
22     /**
23      * When two things are picked in the UI, one must occasionally tie-break
24      * between them to decide what was really clicked. Things with higher
25      * specicifity will win.
26      */
27     get specicifity() {
28       throw new Error('Not implemented');
29     },
30
31     /**
32      * If a selection is related to a specific layer, then this returns the
33      * layerId of that layer. If the selection is not related to a layer, for
34      * example if the device viewport is selected, then this returns undefined.
35      */
36     get associatedLayerId() {
37       throw new Error('Not implemented');
38     },
39
40     /**
41      * If a selection is related to a specific render pass, then this returns
42      * the layerId of that layer. If the selection is not related to a layer,
43      * for example if the device viewport is selected, then this returns
44      * undefined.
45      */
46     get associatedRenderPassId() {
47       throw new Error('Not implemented');
48     },
49
50
51     get highlightsByLayerId() {
52       return {};
53     },
54
55     /**
56      * Called when the selection is made active in the layer view. Must return
57      * an HTMLElement that explains this selection in detail.
58      */
59     createAnalysis: function() {
60       throw new Error('Not implemented');
61     },
62
63     /**
64      * Should try to create the equivalent selection in the provided LTHI,
65      * or undefined if it can't be done.
66      */
67     findEquivalent: function(lthi) {
68       throw new Error('Not implemented');
69     }
70   };
71
72   /**
73    * @constructor
74    */
75   function RenderPassSelection(renderPass, renderPassId) {
76     if (!renderPass || (renderPassId === undefined))
77       throw new Error('Render pass (with id) is required');
78     this.renderPass_ = renderPass;
79     this.renderPassId_ = renderPassId;
80   }
81
82   RenderPassSelection.prototype = {
83     __proto__: Selection.prototype,
84
85     get specicifity() {
86       return 1;
87     },
88
89     get associatedLayerId() {
90       return undefined;
91     },
92
93     get associatedRenderPassId() {
94       return this.renderPassId_;
95     },
96
97     get renderPass() {
98       return this.renderPass_;
99     },
100
101     createAnalysis: function() {
102       var dataView = new GenericObjectViewWithLabel();
103       dataView.label = 'RenderPass ' + this.renderPassId_;
104       dataView.object = this.renderPass_.args;
105       return dataView;
106     },
107
108     get title() {
109       return this.renderPass_.objectInstance.typeName;
110     }
111   };
112
113   /**
114    * @constructor
115    */
116   function LayerSelection(layer) {
117     if (!layer)
118       throw new Error('Layer is required');
119     this.layer_ = layer;
120   }
121
122   LayerSelection.prototype = {
123     __proto__: Selection.prototype,
124
125     get specicifity() {
126       return 1;
127     },
128
129     get associatedLayerId() {
130       return this.layer_.layerId;
131     },
132
133     get associatedRenderPassId() {
134       return undefined;
135     },
136
137     get layer() {
138       return this.layer_;
139     },
140
141     createAnalysis: function() {
142       var dataView = new GenericObjectViewWithLabel();
143       dataView.label = 'Layer ' + this.layer_.layerId;
144       if (this.layer_.usingGpuRasterization)
145         dataView.label += ' (GPU-rasterized)';
146       dataView.object = this.layer_.args;
147       return dataView;
148     },
149
150     get title() {
151       return this.layer_.objectInstance.typeName;
152     },
153
154     findEquivalent: function(lthi) {
155       var layer = lthi.activeTree.findLayerWithId(this.layer_.layerId) ||
156           lthi.pendingTree.findLayerWithId(this.layer_.layerId);
157       if (!layer)
158         return undefined;
159       return new LayerSelection(layer);
160     }
161   };
162
163   /**
164    * @constructor
165    */
166   function TileSelection(tile, opt_data) {
167     this.tile_ = tile;
168     this.data_ = opt_data || {};
169   }
170
171   TileSelection.prototype = {
172     __proto__: Selection.prototype,
173
174     get specicifity() {
175       return 2;
176     },
177
178     get associatedLayerId() {
179       return this.tile_.layerId;
180     },
181
182     get highlightsByLayerId() {
183       var highlights = {}
184       highlights[this.tile_.layerId] = [
185         {
186           colorKey: this.tile_.objectInstance.typeName,
187           rect: this.tile_.layerRect
188         }
189       ];
190       return highlights;
191     },
192
193     createAnalysis: function() {
194       var analysis = new GenericObjectViewWithLabel();
195       analysis.label = 'Tile ' + this.tile_.objectInstance.id + ' on layer ' +
196           this.tile_.layerId;
197       if  (this.data_) {
198         analysis.object = {
199           moreInfo: this.data_,
200           tileArgs: this.tile_.args,
201         };
202       } else {
203         analysis.object = this.tile_.args;
204       }
205       return analysis;
206     },
207
208     findEquivalent: function(lthi) {
209       var tileInstance = this.tile_.tileInstance;
210       if (lthi.ts < tileInstance.creationTs ||
211           lthi.ts >= tileInstance.deletionTs)
212         return undefined;
213       var tileSnapshot = tileInstance.getSnapshotAt(lthi.ts);
214       if (!tileSnapshot)
215         return undefined;
216       return new TileSelection(tileSnapshot);
217     }
218   };
219
220   /**
221    * @constructor
222    */
223   function LayerRectSelection(layer, rectType, rect, opt_data) {
224     this.layer_ = layer;
225     this.rectType_ = rectType;
226     this.rect_ = rect;
227     this.data_ = opt_data !== undefined ? opt_data : rect;
228   }
229
230   LayerRectSelection.prototype = {
231     __proto__: Selection.prototype,
232
233     get specicifity() {
234       return 2;
235     },
236
237     get associatedLayerId() {
238       return this.layer_.layerId;
239     },
240
241
242     get highlightsByLayerId() {
243       var highlights = {}
244       highlights[this.layer_.layerId] = [
245         {
246           colorKey: this.rectType_,
247           rect: this.rect_
248         }
249       ];
250       return highlights;
251     },
252
253     createAnalysis: function() {
254       var analysis = new GenericObjectViewWithLabel();
255       analysis.label = this.rectType_ + ' on layer ' + this.layer_.layerId;
256       analysis.object = this.data_;
257       return analysis;
258     },
259
260     findEquivalent: function(lthi) {
261       return undefined;
262     }
263   };
264
265   /**
266    * @constructor
267    */
268   function AnimationRectSelection(layer, rect) {
269     this.layer_ = layer;
270     this.rect_ = rect;
271   }
272
273   AnimationRectSelection.prototype = {
274     __proto__: Selection.prototype,
275
276     get specicifity() {
277       return 0;
278     },
279
280     get associatedLayerId() {
281       return this.layer_.layerId;
282     },
283
284     createAnalysis: function() {
285       var analysis = new GenericObjectViewWithLabel();
286       analysis.label = 'Animation Bounds of layer ' + this.layer_.layerId;
287       analysis.object = this.rect_;
288       return analysis;
289     }
290   };
291
292   return {
293     Selection: Selection,
294     RenderPassSelection: RenderPassSelection,
295     LayerSelection: LayerSelection,
296     TileSelection: TileSelection,
297     LayerRectSelection: LayerRectSelection,
298     AnimationRectSelection: AnimationRectSelection,
299   };
300 });
301 </script>