1<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/extras/chrome/cc/constants.html">
9<link rel="import" href="/tracing/extras/chrome/cc/region.html">
10<link rel="import" href="/tracing/extras/chrome/cc/tile_coverage_rect.html">
11<link rel="import" href="/tracing/base/rect.html">
12<link rel="import" href="/tracing/model/object_instance.html">
13
14<script>
15'use strict';
16
17tr.exportTo('tr.e.cc', function() {
18  var constants = tr.e.cc.constants;
19  var ObjectSnapshot = tr.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      tr.e.cc.preInitializeObject(this);
33
34      this.layerTreeImpl_ = undefined;
35      this.parentLayer = undefined;
36    },
37
38    initialize: function() {
39      // Defaults.
40      this.invalidation = new tr.e.cc.Region();
41      this.annotatedInvalidation = new tr.e.cc.Region();
42      this.unrecordedRegion = new tr.e.cc.Region();
43      this.pictures = [];
44
45      // Import & validate this.args
46      tr.e.cc.moveRequiredFieldsFromArgsToToplevel(
47          this, ['layerId', 'children',
48                 'layerQuad']);
49      tr.e.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 = tr.b.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 = tr.b.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      if (!this.idealContentsScale)
78        this.idealContentsScale = 1.0;
79
80      this.touchEventHandlerRegion = tr.e.cc.Region.fromArrayOrUndefined(
81          this.args.touchEventHandlerRegion);
82      this.wheelEventHandlerRegion = tr.e.cc.Region.fromArrayOrUndefined(
83          this.args.wheelEventHandlerRegion);
84      this.nonFastScrollableRegion = tr.e.cc.Region.fromArrayOrUndefined(
85          this.args.nonFastScrollableRegion);
86    },
87
88    get layerTreeImpl() {
89      if (this.layerTreeImpl_)
90        return this.layerTreeImpl_;
91      if (this.parentLayer)
92        return this.parentLayer.layerTreeImpl;
93      return undefined;
94    },
95    set layerTreeImpl(layerTreeImpl) {
96      this.layerTreeImpl_ = layerTreeImpl;
97    },
98
99    get activeLayer() {
100      if (this.layerTreeImpl.whichTree == constants.ACTIVE_TREE)
101        return this;
102      var activeTree = this.layerTreeImpl.layerTreeHostImpl.activeTree;
103      return activeTree.findLayerWithId(this.layerId);
104    },
105
106    get pendingLayer() {
107      if (this.layerTreeImpl.whichTree == constants.PENDING_TREE)
108        return this;
109      var pendingTree = this.layerTreeImpl.layerTreeHostImpl.pendingTree;
110      return pendingTree.findLayerWithId(this.layerId);
111    }
112  };
113
114  /**
115   * @constructor
116   */
117  function PictureLayerImplSnapshot() {
118    LayerImplSnapshot.apply(this, arguments);
119  }
120
121  PictureLayerImplSnapshot.prototype = {
122    __proto__: LayerImplSnapshot.prototype,
123
124    initialize: function() {
125      LayerImplSnapshot.prototype.initialize.call(this);
126
127      if (this.args.invalidation) {
128        this.invalidation = tr.e.cc.Region.fromArray(this.args.invalidation);
129        delete this.args.invalidation;
130      }
131      if (this.args.annotatedInvalidationRects) {
132        this.annotatedInvalidation = new tr.e.cc.Region();
133        for (var i = 0; i < this.args.annotatedInvalidationRects.length; ++i) {
134          var annotatedRect = this.args.annotatedInvalidationRects[i];
135          var rect = annotatedRect.geometryRect;
136          rect.reason = annotatedRect.reason;
137          this.annotatedInvalidation.addRect(rect);
138        }
139        delete this.args.annotatedInvalidationRects;
140      }
141      if (this.args.unrecordedRegion) {
142        this.unrecordedRegion = tr.e.cc.Region.fromArray(
143            this.args.unrecordedRegion);
144        delete this.args.unrecordedRegion;
145      }
146      if (this.args.pictures) {
147        this.pictures = this.args.pictures;
148
149        // The picture list comes in with an unknown ordering. We resort based
150        // on timestamp order so we will draw the base picture first and the
151        // various fixes on top of that.
152        this.pictures.sort(function(a, b) { return a.ts - b.ts; });
153      }
154
155      this.tileCoverageRects = [];
156      if (this.args.coverageTiles) {
157        for (var i = 0; i < this.args.coverageTiles.length; ++i) {
158          var rect = this.args.coverageTiles[i].geometryRect.scale(
159              this.idealContentsScale);
160          var tile = this.args.coverageTiles[i].tile;
161          this.tileCoverageRects.push(new tr.e.cc.TileCoverageRect(rect, tile));
162        }
163        delete this.args.coverageTiles;
164      }
165    }
166  };
167
168  ObjectSnapshot.register(
169      PictureLayerImplSnapshot,
170      {
171        typeName: 'cc::PictureLayerImpl'
172      });
173
174  ObjectSnapshot.register(
175      LayerImplSnapshot,
176      {
177        typeNames: [
178          'cc::LayerImpl',
179          'cc::DelegatedRendererLayerImpl',
180          'cc::HeadsUpDisplayLayerImpl',
181          'cc::IOSurfaceLayerImpl',
182          'cc::NinePatchLayerImpl',
183          'cc::PictureImageLayerImpl',
184          'cc::ScrollbarLayerImpl',
185          'cc::SolidColorLayerImpl',
186          'cc::SurfaceLayerImpl',
187          'cc::TextureLayerImpl',
188          'cc::TiledLayerImpl',
189          'cc::VideoLayerImpl',
190          'cc::PaintedScrollbarLayerImpl',
191          'ClankPatchLayer',
192          'TabBorderLayer',
193          'CounterLayer'
194        ]
195      });
196
197  return {
198    LayerImplSnapshot: LayerImplSnapshot,
199    PictureLayerImplSnapshot: PictureLayerImplSnapshot
200  };
201});
202</script>
203