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/layer_tree_impl.html">
10 <link rel="import" href="/cc/util.html">
11 <link rel="import" href="/tvcm/bbox2.html">
12 <link rel="import" href="/tracing/trace_model/object_instance.html">
18 * @fileoverview Provides the LayerTreeHostImpl model-level objects.
20 tvcm.exportTo('cc', function() {
21 var constants = cc.constants;
23 var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
24 var ObjectInstance = tracing.trace_model.ObjectInstance;
29 function LayerTreeHostImplSnapshot() {
30 ObjectSnapshot.apply(this, arguments);
33 LayerTreeHostImplSnapshot.prototype = {
34 __proto__: ObjectSnapshot.prototype,
36 preInitialize: function() {
37 cc.preInitializeObject(this);
40 initialize: function() {
41 cc.moveRequiredFieldsFromArgsToToplevel(
42 this, ['deviceViewportSize',
44 cc.moveOptionalFieldsFromArgsToToplevel(
51 this.activeTree.layerTreeHostImpl = this;
52 this.activeTree.whichTree = constants.ACTIVE_TREE;
53 if (this.pendingTree) {
54 this.pendingTree.layerTreeHostImpl = this;
55 this.pendingTree.whichTree = constants.PENDING_TREE;
60 * Get all of tile scales and their associated names.
62 getContentsScaleNames: function() {
64 for (var i = 0; i < this.tiles.length; ++i) {
65 var tile = this.tiles[i];
66 // Return scale -> scale name mappings.
68 // 0.25 -> LOW_RESOLUTION
69 // 1.0 -> HIGH_RESOLUTION
70 // 0.75 -> NON_IDEAL_RESOLUTION
71 scales[tile.contentsScale] = tile.resolution;
76 getTree: function(whichTree) {
77 if (whichTree == constants.ACTIVE_TREE)
78 return this.activeTree;
79 if (whichTree == constants.PENDING_TREE)
80 return this.pendingTree;
81 throw new Exception('Unknown tree type + ' + whichTree);
84 get tilesHaveGpuMemoryUsageInfo() {
85 if (this.tilesHaveGpuMemoryUsageInfo_ !== undefined)
86 return this.tilesHaveGpuMemoryUsageInfo_;
88 for (var i = 0; i < this.tiles.length; i++) {
89 if (this.tiles[i].gpuMemoryUsageInBytes === undefined)
91 this.tilesHaveGpuMemoryUsageInfo_ = true;
94 this.tilesHaveGpuMemoryUsageInfo_ = false;
98 get gpuMemoryUsageInBytes() {
99 if (!this.tilesHaveGpuMemoryUsageInfo)
103 for (var i = 0; i < this.tiles.length; i++) {
104 var u = this.tiles[i].gpuMemoryUsageInBytes;
112 ObjectSnapshot.register('cc::LayerTreeHostImpl', LayerTreeHostImplSnapshot);
117 function LayerTreeHostImplInstance() {
118 ObjectInstance.apply(this, arguments);
120 this.allLayersBBox_ = undefined;
123 LayerTreeHostImplInstance.prototype = {
124 __proto__: ObjectInstance.prototype,
126 get allContentsScales() {
127 if (this.allContentsScales_)
128 return this.allContentsScales_;
131 for (var tileID in this.allTileHistories_) {
132 var tileHistory = this.allTileHistories_[tileID];
133 scales[tileHistory.contentsScale] = true;
135 this.allContentsScales_ = tvcm.dictionaryKeys(scales);
136 return this.allContentsScales_;
139 get allLayersBBox() {
140 if (this.allLayersBBox_)
141 return this.allLayersBBox_;
142 var bbox = new tvcm.BBox2();
143 function handleTree(tree) {
144 tree.renderSurfaceLayerList.forEach(function(layer) {
145 bbox.addQuad(layer.layerQuad);
148 this.snapshots.forEach(function(lthi) {
149 handleTree(lthi.activeTree);
150 if (lthi.pendingTree)
151 handleTree(lthi.pendingTree);
153 this.allLayersBBox_ = bbox;
154 return this.allLayersBBox_;
158 ObjectInstance.register('cc::LayerTreeHostImpl', LayerTreeHostImplInstance);
161 LayerTreeHostImplSnapshot: LayerTreeHostImplSnapshot,
162 LayerTreeHostImplInstance: LayerTreeHostImplInstance