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="/base/rect.html">
12 <link rel="import" href="/tracing/trace_model/object_instance.html">
17 tv.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.annotatedInvalidation = new cc.Region();
42 this.unrecordedRegion = new cc.Region();
45 // Import & validate this.args
46 cc.moveRequiredFieldsFromArgsToToplevel(
47 this, ['layerId', 'children',
49 cc.moveOptionalFieldsFromArgsToToplevel(
50 this, ['maskLayer', 'replicaLayer',
51 'idealContentsScale', 'geometryContentsScale',
52 'layoutRects', 'usingGpuRasterization']);
54 // Leave gpu memory usage in both places.
55 this.gpuMemoryUsageInBytes = this.args.gpuMemoryUsage;
57 // Leave bounds in both places.
58 this.bounds = tv.Rect.fromXYWH(
60 this.args.bounds.width, this.args.bounds.height);
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]);
69 for (var i = 0; i < this.children.length; i++)
70 this.children[i].parentLayer = this;
72 this.maskLayer.parentLayer = this;
73 if (this.replicaLayer)
74 this.replicaLayer.parentLayer = this;
75 if (!this.geometryContentsScale)
76 this.geometryContentsScale = 1.0;
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);
87 if (this.layerTreeImpl_)
88 return this.layerTreeImpl_;
90 return this.parentLayer.layerTreeImpl;
93 set layerTreeImpl(layerTreeImpl) {
94 this.layerTreeImpl_ = layerTreeImpl;
98 if (this.layerTreeImpl.whichTree == constants.ACTIVE_TREE)
100 var activeTree = this.layerTreeImpl.layerTreeHostImpl.activeTree;
101 return activeTree.findLayerWithId(this.layerId);
105 if (this.layerTreeImpl.whichTree == constants.PENDING_TREE)
107 var pendingTree = this.layerTreeImpl.layerTreeHostImpl.pendingTree;
108 return pendingTree.findLayerWithId(this.layerId);
115 function PictureLayerImplSnapshot() {
116 LayerImplSnapshot.apply(this, arguments);
119 PictureLayerImplSnapshot.prototype = {
120 __proto__: LayerImplSnapshot.prototype,
122 initialize: function() {
123 LayerImplSnapshot.prototype.initialize.call(this);
125 if (this.args.invalidation) {
126 this.invalidation = cc.Region.fromArray(this.args.invalidation);
127 delete this.args.invalidation;
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);
137 delete this.args.annotatedInvalidationRects;
139 if (this.args.unrecordedRegion) {
140 this.unrecordedRegion = cc.Region.fromArray(
141 this.args.unrecordedRegion);
142 delete this.args.unrecordedRegion;
144 if (this.args.pictures) {
145 this.pictures = this.args.pictures;
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; });
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));
160 delete this.args.coverageTiles;
165 ObjectSnapshot.register('cc::LayerImpl', LayerImplSnapshot);
166 ObjectSnapshot.register('cc::PictureLayerImpl', PictureLayerImplSnapshot);
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);
180 ObjectSnapshot.register('ClankPatchLayer', LayerImplSnapshot);
181 ObjectSnapshot.register('TabBorderLayer', LayerImplSnapshot);
182 ObjectSnapshot.register('CounterLayer', LayerImplSnapshot);
185 LayerImplSnapshot: LayerImplSnapshot,
186 PictureLayerImplSnapshot: PictureLayerImplSnapshot