Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / cc / layer_impl.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="/cc/constants.html">
9 <link rel="import" href="/cc/region.html">
10 <link rel="import" href="/cc/tile_coverage_rect.html">
11 <link rel="import" href="/tvcm/rect.html">
12 <link rel="import" href="/tracing/trace_model/object_instance.html">
13
14 <script>
15 'use strict';
16
17 tvcm.exportTo('cc', function() {
18   var constants = cc.constants;
19   var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
20
21   /**
22    * @constructor
23    */
24   function LayerImplSnapshot() {
25     ObjectSnapshot.apply(this, arguments);
26   }
27
28   LayerImplSnapshot.prototype = {
29     __proto__: ObjectSnapshot.prototype,
30
31     preInitialize: function() {
32       cc.preInitializeObject(this);
33
34       this.layerTreeImpl_ = undefined;
35       this.parentLayer = undefined;
36     },
37
38     initialize: function() {
39       // Defaults.
40       this.invalidation = new cc.Region();
41       this.unrecordedRegion = new cc.Region();
42       this.pictures = [];
43
44       // Import & validate this.args
45       cc.moveRequiredFieldsFromArgsToToplevel(
46           this, ['layerId', 'children',
47                  'layerQuad']);
48       cc.moveOptionalFieldsFromArgsToToplevel(
49           this, ['maskLayer', 'replicaLayer',
50                  'idealContentsScale', 'geometryContentsScale',
51                  'layoutRects', 'usingGpuRasterization']);
52
53       // Leave gpu memory usage in both places.
54       this.gpuMemoryUsageInBytes = this.args.gpuMemoryUsage;
55
56       // Leave bounds in both places.
57       this.bounds = tvcm.Rect.fromXYWH(
58           0, 0,
59           this.args.bounds.width, this.args.bounds.height);
60
61       if (this.args.animationBounds) {
62         // AnimationBounds[2] and [5] are the Z-component of the box.
63         this.animationBoundsRect = tvcm.Rect.fromXYWH(
64             this.args.animationBounds[0], this.args.animationBounds[1],
65             this.args.animationBounds[3], this.args.animationBounds[4]);
66       }
67
68       for (var i = 0; i < this.children.length; i++)
69         this.children[i].parentLayer = this;
70       if (this.maskLayer)
71         this.maskLayer.parentLayer = this;
72       if (this.replicaLayer)
73         this.maskLayer.replicaLayer = this;
74       if (!this.geometryContentsScale)
75         this.geometryContentsScale = 1.0;
76
77       this.touchEventHandlerRegion = cc.Region.fromArrayOrUndefined(
78           this.args.touchEventHandlerRegion);
79       this.wheelEventHandlerRegion = cc.Region.fromArrayOrUndefined(
80           this.args.wheelEventHandlerRegion);
81       this.nonFastScrollableRegion = cc.Region.fromArrayOrUndefined(
82           this.args.nonFastScrollableRegion);
83     },
84
85     get layerTreeImpl() {
86       if (this.layerTreeImpl_)
87         return this.layerTreeImpl_;
88       if (this.parentLayer)
89         return this.parentLayer.layerTreeImpl;
90       return undefined;
91     },
92     set layerTreeImpl(layerTreeImpl) {
93       this.layerTreeImpl_ = layerTreeImpl;
94     },
95
96     get activeLayer() {
97       if (this.layerTreeImpl.whichTree == constants.ACTIVE_TREE)
98         return this;
99       var activeTree = this.layerTreeImpl.layerTreeHostImpl.activeTree;
100       return activeTree.findLayerWithId(this.layerId);
101     },
102
103     get pendingLayer() {
104       if (this.layerTreeImpl.whichTree == constants.PENDING_TREE)
105         return this;
106       var pendingTree = this.layerTreeImpl.layerTreeHostImpl.pendingTree;
107       return pendingTree.findLayerWithId(this.layerId);
108     }
109   };
110
111   /**
112    * @constructor
113    */
114   function PictureLayerImplSnapshot() {
115     LayerImplSnapshot.apply(this, arguments);
116   }
117
118   PictureLayerImplSnapshot.prototype = {
119     __proto__: LayerImplSnapshot.prototype,
120
121     initialize: function() {
122       LayerImplSnapshot.prototype.initialize.call(this);
123
124       if (this.args.invalidation) {
125         this.invalidation = cc.Region.fromArray(this.args.invalidation);
126         delete this.args.invalidation;
127       }
128       if (this.args.unrecordedRegion) {
129         this.unrecordedRegion = cc.Region.fromArray(
130             this.args.unrecordedRegion);
131         delete this.args.unrecordedRegion;
132       }
133       if (this.args.pictures) {
134         this.pictures = this.args.pictures;
135
136         // The picture list comes in with an unknown ordering. We resort based
137         // on timestamp order so we will draw the base picture first and the
138         // various fixes on top of that.
139         this.pictures.sort(function(a, b) { return a.ts - b.ts; });
140       }
141
142       this.tileCoverageRects = [];
143       if (this.args.coverageTiles) {
144         for (var i = 0; i < this.args.coverageTiles.length; ++i) {
145           var rect = this.args.coverageTiles[i].geometryRect;
146           var tile = this.args.coverageTiles[i].tile;
147           this.tileCoverageRects.push(new cc.TileCoverageRect(rect, tile));
148         }
149         delete this.args.coverageTiles;
150       }
151     }
152   };
153
154   ObjectSnapshot.register('cc::LayerImpl', LayerImplSnapshot);
155   ObjectSnapshot.register('cc::PictureLayerImpl', PictureLayerImplSnapshot);
156
157   ObjectSnapshot.register('cc::DelegatedRendererLayerImpl', LayerImplSnapshot);
158   ObjectSnapshot.register('cc::HeadsUpDisplayLayerImpl', LayerImplSnapshot);
159   ObjectSnapshot.register('cc::IOSurfaceLayerImpl', LayerImplSnapshot);
160   ObjectSnapshot.register('cc::NinePatchLayerImpl', LayerImplSnapshot);
161   ObjectSnapshot.register('cc::PictureImageLayerImpl', LayerImplSnapshot);
162   ObjectSnapshot.register('cc::ScrollbarLayerImpl', LayerImplSnapshot);
163   ObjectSnapshot.register('cc::SolidColorLayerImpl', LayerImplSnapshot);
164   ObjectSnapshot.register('cc::TextureLayerImpl', LayerImplSnapshot);
165   ObjectSnapshot.register('cc::TiledLayerImpl', LayerImplSnapshot);
166   ObjectSnapshot.register('cc::VideoLayerImpl', LayerImplSnapshot);
167   ObjectSnapshot.register('cc::PaintedScrollbarLayerImpl', LayerImplSnapshot);
168
169   ObjectSnapshot.register('ClankPatchLayer', LayerImplSnapshot);
170   ObjectSnapshot.register('TabBorderLayer', LayerImplSnapshot);
171   ObjectSnapshot.register('CounterLayer', LayerImplSnapshot);
172
173   return {
174     LayerImplSnapshot: LayerImplSnapshot,
175     PictureLayerImplSnapshot: PictureLayerImplSnapshot
176   };
177 });
178 </script>