Home | History | Annotate | Download | only in cc
      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 
      7 base.require('tracing.trace_model.object_instance');
      8 base.require('cc.layer_impl');
      9 
     10 base.exportTo('cc', function() {
     11   var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
     12 
     13   /**
     14    * @constructor
     15    */
     16   function LayerTreeImplSnapshot() {
     17     ObjectSnapshot.apply(this, arguments);
     18   }
     19 
     20   LayerTreeImplSnapshot.prototype = {
     21     __proto__: ObjectSnapshot.prototype,
     22 
     23     preInitialize: function() {
     24       cc.preInitializeObject(this);
     25       this.layerTreeHostImpl = undefined;
     26       this.whichTree = undefined;
     27     },
     28 
     29     initialize: function() {
     30       cc.moveRequiredFieldsFromArgsToToplevel(
     31           this, ['rootLayer',
     32             'renderSurfaceLayerList']);
     33       this.rootLayer.layerTreeImpl = this;
     34     },
     35 
     36     iterLayers: function(func) {
     37       function visitLayer(layer, depth, isMask, isReplica) {
     38         func(layer, depth, isMask, isReplica);
     39         for (var i = 0; i < layer.children.length; i++)
     40           visitLayer(layer.children[i], depth + 1);
     41         if (layer.maskLayer)
     42           visitLayer(layer, depth + 1, true, false);
     43         if (layer.replicaLayer)
     44           visitLayer(layer, depth + 1, false, true);
     45       }
     46       visitLayer(this.rootLayer, 0, false, false);
     47     },
     48     findLayerWithId: function(id) {
     49       var foundLayer = undefined;
     50       function visitLayer(layer) {
     51         if (layer.layerId == id)
     52           foundLayer = layer;
     53       }
     54       this.iterLayers(visitLayer);
     55       return foundLayer;
     56     }
     57   };
     58 
     59   ObjectSnapshot.register('cc::LayerTreeImpl', LayerTreeImplSnapshot);
     60 
     61   return {
     62     LayerTreeImplSnapshot: LayerTreeImplSnapshot
     63   };
     64 });
     65