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