• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5'use strict';
6
7base.require('base.rect');
8base.require('cc.constants');
9base.require('cc.region');
10base.require('tracing.trace_model.object_instance');
11
12base.exportTo('cc', function() {
13  var constants = cc.constants;
14  var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
15
16  /**
17   * @constructor
18   */
19  function LayerImplSnapshot() {
20    ObjectSnapshot.apply(this, arguments);
21  }
22
23  LayerImplSnapshot.prototype = {
24    __proto__: ObjectSnapshot.prototype,
25
26    preInitialize: function() {
27      cc.preInitializeObject(this);
28
29      this.layerTreeImpl_ = undefined;
30      this.parentLayer = undefined;
31    },
32
33    initialize: function() {
34      // Defaults.
35      this.invalidation = new cc.Region();
36      this.pictures = [];
37
38      // Import & validate this.args
39      cc.moveRequiredFieldsFromArgsToToplevel(
40          this, ['layerId', 'children',
41            'layerQuad']);
42      cc.moveOptionalFieldsFromArgsToToplevel(
43          this, ['maskLayer', 'replicaLayer']);
44
45      // Leave bounds in both places.
46      this.bounds = base.Rect.FromXYWH(
47          0, 0,
48          this.args.bounds.width, this.args.bounds.height);
49
50      for (var i = 0; i < this.children.length; i++)
51        this.children[i].parentLayer = this;
52      if (this.maskLayer)
53        this.maskLayer.parentLayer = this;
54      if (this.replicaLayer)
55        this.maskLayer.replicaLayer = this;
56    },
57
58    get layerTreeImpl() {
59      if (this.layerTreeImpl_)
60        return this.layerTreeImpl_;
61      if (this.parentLayer)
62        return this.parentLayer.layerTreeImpl;
63      return undefined;
64    },
65    set layerTreeImpl(layerTreeImpl) {
66      this.layerTreeImpl_ = layerTreeImpl;
67    },
68
69    get activeLayer() {
70      if (this.layerTreeImpl.whichTree == constants.ACTIVE_TREE)
71        return this;
72      var activeTree = this.layerTreeImpl.layerTreeHostImpl.activeTree;
73      return activeTree.findLayerWithId(this.layerId);
74    },
75
76    get pendingLayer() {
77      if (this.layerTreeImpl.whichTree == constants.PENDING_TREE)
78        return this;
79      var pendingTree = this.layerTreeImpl.layerTreeHostImpl.pendingTree;
80      return pendingTree.findLayerWithId(this.layerId);
81    }
82  };
83
84  /**
85   * @constructor
86   */
87  function PictureLayerImplSnapshot() {
88    LayerImplSnapshot.apply(this, arguments);
89  }
90
91  PictureLayerImplSnapshot.prototype = {
92    __proto__: LayerImplSnapshot.prototype,
93
94    initialize: function() {
95      LayerImplSnapshot.prototype.initialize.call(this);
96
97      if (this.args.invalidation) {
98        this.invalidation = cc.RegionFromArray(this.args.invalidation);
99        delete this.args.invalidation;
100      }
101      if (this.args.pictures) {
102        this.pictures = this.args.pictures;
103      }
104    }
105  };
106
107  ObjectSnapshot.register('cc::LayerImpl', LayerImplSnapshot);
108  ObjectSnapshot.register('cc::PictureLayerImpl', PictureLayerImplSnapshot);
109
110  ObjectSnapshot.register('cc::DelegatedRendererLayerImpl', LayerImplSnapshot);
111  ObjectSnapshot.register('cc::HeadsUpDisplayLayerImpl', LayerImplSnapshot);
112  ObjectSnapshot.register('cc::IOSurfaceLayerImpl', LayerImplSnapshot);
113  ObjectSnapshot.register('cc::NinePatchLayerImpl', LayerImplSnapshot);
114  ObjectSnapshot.register('cc::PictureImageLayerImpl', LayerImplSnapshot);
115  ObjectSnapshot.register('cc::ScrollbarLayerImpl', LayerImplSnapshot);
116  ObjectSnapshot.register('cc::SolidColorLayerImpl', LayerImplSnapshot);
117  ObjectSnapshot.register('cc::TextureLayerImpl', LayerImplSnapshot);
118  ObjectSnapshot.register('cc::TiledLayerImpl', LayerImplSnapshot);
119  ObjectSnapshot.register('cc::VideoLayerImpl', LayerImplSnapshot);
120
121  return {
122    LayerImplSnapshot: LayerImplSnapshot,
123    PictureLayerImplSnapshot: PictureLayerImplSnapshot
124  };
125});
126