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.
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">
17 tvcm.exportTo('cc', function() {
18 var constants = cc.constants;
19 var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
24 function LayerImplSnapshot() {
25 ObjectSnapshot.apply(this, arguments);
28 LayerImplSnapshot.prototype = {
29 __proto__: ObjectSnapshot.prototype,
31 preInitialize: function() {
32 cc.preInitializeObject(this);
34 this.layerTreeImpl_ = undefined;
35 this.parentLayer = undefined;
38 initialize: function() {
40 this.invalidation = new cc.Region();
41 this.unrecordedRegion = new cc.Region();
44 // Import & validate this.args
45 cc.moveRequiredFieldsFromArgsToToplevel(
46 this, ['layerId', 'children',
48 cc.moveOptionalFieldsFromArgsToToplevel(
49 this, ['maskLayer', 'replicaLayer',
50 'idealContentsScale', 'geometryContentsScale',
51 'layoutRects', 'usingGpuRasterization']);
53 // Leave gpu memory usage in both places.
54 this.gpuMemoryUsageInBytes = this.args.gpuMemoryUsage;
56 // Leave bounds in both places.
57 this.bounds = tvcm.Rect.fromXYWH(
59 this.args.bounds.width, this.args.bounds.height);
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]);
68 for (var i = 0; i < this.children.length; i++)
69 this.children[i].parentLayer = this;
71 this.maskLayer.parentLayer = this;
72 if (this.replicaLayer)
73 this.replicaLayer.parentLayer = this;
74 if (!this.geometryContentsScale)
75 this.geometryContentsScale = 1.0;
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);
86 if (this.layerTreeImpl_)
87 return this.layerTreeImpl_;
89 return this.parentLayer.layerTreeImpl;
92 set layerTreeImpl(layerTreeImpl) {
93 this.layerTreeImpl_ = layerTreeImpl;
97 if (this.layerTreeImpl.whichTree == constants.ACTIVE_TREE)
99 var activeTree = this.layerTreeImpl.layerTreeHostImpl.activeTree;
100 return activeTree.findLayerWithId(this.layerId);
104 if (this.layerTreeImpl.whichTree == constants.PENDING_TREE)
106 var pendingTree = this.layerTreeImpl.layerTreeHostImpl.pendingTree;
107 return pendingTree.findLayerWithId(this.layerId);
114 function PictureLayerImplSnapshot() {
115 LayerImplSnapshot.apply(this, arguments);
118 PictureLayerImplSnapshot.prototype = {
119 __proto__: LayerImplSnapshot.prototype,
121 initialize: function() {
122 LayerImplSnapshot.prototype.initialize.call(this);
124 if (this.args.invalidation) {
125 this.invalidation = cc.Region.fromArray(this.args.invalidation);
126 delete this.args.invalidation;
128 if (this.args.unrecordedRegion) {
129 this.unrecordedRegion = cc.Region.fromArray(
130 this.args.unrecordedRegion);
131 delete this.args.unrecordedRegion;
133 if (this.args.pictures) {
134 this.pictures = this.args.pictures;
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; });
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));
149 delete this.args.coverageTiles;
154 ObjectSnapshot.register('cc::LayerImpl', LayerImplSnapshot);
155 ObjectSnapshot.register('cc::PictureLayerImpl', PictureLayerImplSnapshot);
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);
169 ObjectSnapshot.register('ClankPatchLayer', LayerImplSnapshot);
170 ObjectSnapshot.register('TabBorderLayer', LayerImplSnapshot);
171 ObjectSnapshot.register('CounterLayer', LayerImplSnapshot);
174 LayerImplSnapshot: LayerImplSnapshot,
175 PictureLayerImplSnapshot: PictureLayerImplSnapshot