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 /**
      8  * @fileoverview Provides the LayerTreeHostImpl model-level objects.
      9  */
     10 base.require('base.bbox2');
     11 base.require('tracing.trace_model.object_instance');
     12 base.require('cc.constants');
     13 base.require('cc.layer_tree_impl');
     14 base.require('cc.util');
     15 
     16 base.exportTo('cc', function() {
     17   var constants = cc.constants;
     18   var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
     19   var ObjectInstance = tracing.trace_model.ObjectInstance;
     20 
     21   /**
     22    * @constructor
     23    */
     24   function LayerTreeHostImplSnapshot() {
     25     ObjectSnapshot.apply(this, arguments);
     26   }
     27 
     28   LayerTreeHostImplSnapshot.prototype = {
     29     __proto__: ObjectSnapshot.prototype,
     30 
     31     preInitialize: function() {
     32       cc.preInitializeObject(this);
     33     },
     34 
     35     initialize: function() {
     36       cc.moveRequiredFieldsFromArgsToToplevel(
     37           this, ['deviceViewportSize',
     38             'activeTree']);
     39       cc.moveOptionalFieldsFromArgsToToplevel(
     40           this, ['pendingTree',
     41             'tiles']);
     42 
     43       this.activeTree.layerTreeHostImpl = this;
     44       this.activeTree.whichTree = constants.ACTIVE_TREE;
     45       if (this.pendingTree) {
     46         this.pendingTree.layerTreeHostImpl = this;
     47         this.pendingTree.whichTree = constants.PENDING_TREE;
     48       }
     49     },
     50 
     51     getTree: function(whichTree) {
     52       if (whichTree == constants.ACTIVE_TREE)
     53         return this.activeTree;
     54       if (whichTree == constants.PENDING_TREE)
     55         return this.pendingTree;
     56       throw new Exception('Unknown tree type + ' + whichTree);
     57     }
     58   };
     59 
     60   ObjectSnapshot.register('cc::LayerTreeHostImpl', LayerTreeHostImplSnapshot);
     61 
     62   /**
     63    * @constructor
     64    */
     65   function LayerTreeHostImplInstance() {
     66     ObjectInstance.apply(this, arguments);
     67 
     68     this.allLayersBBox_ = undefined;
     69   }
     70 
     71   LayerTreeHostImplInstance.prototype = {
     72     __proto__: ObjectInstance.prototype,
     73 
     74     get allContentsScales() {
     75       if (this.allContentsScales_)
     76         return this.allContentsScales_;
     77 
     78       var scales = {};
     79       for (var tileID in this.allTileHistories_) {
     80         var tileHistory = this.allTileHistories_[tileID];
     81         scales[tileHistory.contentsScale] = true;
     82       }
     83       this.allContentsScales_ = base.dictionaryKeys(scales);
     84       return this.allContentsScales_;
     85     },
     86 
     87     get allLayersBBox() {
     88       if (this.allLayersBBox_)
     89         return this.allLayersBBox_;
     90       var bbox = new base.BBox2();
     91       function handleTree(tree) {
     92         tree.renderSurfaceLayerList.forEach(function(layer) {
     93           bbox.addQuad(layer.layerQuad);
     94         });
     95       }
     96       this.snapshots.forEach(function(lthi) {
     97         handleTree(lthi.activeTree);
     98         if (lthi.pendingTree)
     99           handleTree(lthi.pendingTree);
    100       });
    101       this.allLayersBBox_ = bbox;
    102       return this.allLayersBBox_;
    103     }
    104   };
    105 
    106   ObjectInstance.register('cc::LayerTreeHostImpl', LayerTreeHostImplInstance);
    107 
    108   return {
    109     LayerTreeHostImplSnapshot: LayerTreeHostImplSnapshot,
    110     LayerTreeHostImplInstance: LayerTreeHostImplInstance
    111 
    112   };
    113 });
    114