OLD | NEW |
| (Empty) |
1 /* Copyright (c) 2012 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('base.bbox2'); | |
8 base.require('model.constants'); | |
9 base.require('model.tile'); | |
10 base.require('model.layer_tree_impl'); | |
11 | |
12 base.exportTo('ccfv.model', function() { | |
13 | |
14 var constants = ccfv.model.constants; | |
15 | |
16 /** | |
17 * Represents the history of a specific cc::LayerTreeHostImpl over time. | |
18 * | |
19 * @constructor | |
20 */ | |
21 function LayerTreeHostImplHistory(id) { | |
22 this.id = id; | |
23 this.lthiSnapshots = []; | |
24 | |
25 this.allTileHistories_ = {}; | |
26 this.allTilesBBox_ = undefined; | |
27 | |
28 this.allLayerImplHistories_ = {}; | |
29 }; | |
30 | |
31 LayerTreeHostImplHistory.prototype = { | |
32 createNewLTHI: function() { | |
33 var snapshotNumber = this.lthiSnapshots.length + 1; | |
34 var lthi = new LayerTreeHostImpl(this, snapshotNumber); | |
35 this.lthiSnapshots.push(lthi); | |
36 this.allTilesBBox_ = undefined; | |
37 this.allContentsScales_ = undefined; | |
38 return lthi; | |
39 }, | |
40 | |
41 getOrCreateTileHistory: function(tileID) { | |
42 if (!this.allTileHistories_[tileID]) | |
43 this.allTileHistories_[tileID] = new ccfv.model.TileHistory(tileID); | |
44 return this.allTileHistories_[tileID]; | |
45 }, | |
46 | |
47 getOrCreateLayerImplHistory: function(layerID) { | |
48 if (!this.allLayerImplHistories_[layerID]) | |
49 this.allLayerImplHistories_[layerID] = | |
50 new ccfv.model.LayerImplHistory(layerID); | |
51 return this.allLayerImplHistories_[layerID]; | |
52 }, | |
53 | |
54 get allContentsScales() { | |
55 if (this.allContentsScales_ !== undefined) | |
56 return this.allContentsScales_; | |
57 | |
58 var scales = {}; | |
59 for (var tileID in this.allTileHistories_) { | |
60 var tileHistory = this.allTileHistories_[tileID]; | |
61 scales[tileHistory.contentsScale] = true; | |
62 } | |
63 this.allContentsScales_ = base.dictionaryKeys(scales); | |
64 return this.allContentsScales_; | |
65 }, | |
66 | |
67 get allTilesBBox() { | |
68 if (!this.allTilesBBox_) { | |
69 var bbox = new base.BBox2(); | |
70 for (var tileID in this.allTileHistories_) { | |
71 var tileHistory = this.allTileHistories_[tileID]; | |
72 for (var snapshotNumber in tileHistory.tilesBySnapshotNumber) { | |
73 var tile = tileHistory.tilesBySnapshotNumber[snapshotNumber]; | |
74 if (tile.priority[0].current_screen_quad) | |
75 bbox.addQuad(tile.priority[0].current_screen_quad); | |
76 if (tile.priority[1].current_screen_quad) | |
77 bbox.addQuad(tile.priority[1].current_screen_quad); | |
78 } | |
79 } | |
80 this.allTilesBBox_ = bbox; | |
81 } | |
82 return this.allTilesBBox_; | |
83 }, | |
84 }; | |
85 | |
86 /** | |
87 * Represents a snapshot of the cc::LayerTreeHostImpl at an instant in time. | |
88 * | |
89 * @constructor | |
90 */ | |
91 function LayerTreeHostImpl(history, snapshotNumber) { | |
92 this.history = history; | |
93 this.snapshotNumber = snapshotNumber; | |
94 this.deviceViewportSize = {} | |
95 | |
96 this.allTiles = []; | |
97 | |
98 // These fields are affected by the rebuildIfNeeded_() flow. | |
99 this.pendingTree = new ccfv.model.LayerTreeImpl( | |
100 this, constants.PENDING_TREE); | |
101 this.activeTree = new ccfv.model.LayerTreeImpl( | |
102 this, constants.ACTIVE_TREE); | |
103 | |
104 this.tilesForTree_ = undefined; | |
105 this.inactiveTiles_ = []; | |
106 } | |
107 | |
108 LayerTreeHostImpl.prototype = { | |
109 get id() { | |
110 return this.history.id; | |
111 }, | |
112 | |
113 getTree: function(whichTree) { | |
114 if (whichTree === constants.ACTIVE_TREE) | |
115 return this.activeTree; | |
116 else if (whichTree === constants.PENDING_TREE) | |
117 return this.pendingTree; | |
118 else | |
119 throw new Error('Active or pending only.'); | |
120 }, | |
121 | |
122 getOrCreateTile: function(tileID) { | |
123 var tileHistory = this.history.getOrCreateTileHistory(tileID); | |
124 var tile = tileHistory.getOrCreateTileForLTHI(this); | |
125 this.allTiles.push(tile); | |
126 | |
127 this.activeTree.setTilesDirty(); | |
128 this.pendingTree.setTilesDirty(); | |
129 this.tilesForTree_ = undefined; | |
130 this.inactiveTiles_ = undefined; | |
131 | |
132 return tile; | |
133 }, | |
134 | |
135 get inactiveTiles() { | |
136 if (this.inactiveTiles_ === undefined) | |
137 this.rebuildTiles_(); | |
138 return this.inactiveTiles_; | |
139 }, | |
140 | |
141 getTilesForTree: function(which_tree) { | |
142 if (this.tilesForTree_ === undefined) | |
143 this.rebuildTiles_(); | |
144 return this.tilesForTree_[which_tree]; | |
145 }, | |
146 | |
147 rebuildTiles_: function() { | |
148 this.tilesForTree_ = [[], []]; | |
149 this.inactiveTiles_ = []; | |
150 this.allTiles.forEach(function(tile) { | |
151 if (tile.priority[constants.ACTIVE_TREE].is_live) | |
152 this.tilesForTree_[constants.ACTIVE_TREE].push(tile); | |
153 if (tile.priority[constants.PENDING_TREE].is_live) | |
154 this.tilesForTree_[constants.PENDING_TREE].push(tile); | |
155 if (tile.priority[constants.PENDING_TREE].is_live == false && | |
156 tile.priority[constants.ACTIVE_TREE].is_live == false) | |
157 this.inactiveTiles_.push(tile); | |
158 }, this); | |
159 }, | |
160 }; | |
161 | |
162 return { | |
163 LayerTreeHostImpl: LayerTreeHostImpl, | |
164 LayerTreeHostImplHistory: LayerTreeHostImplHistory | |
165 }; | |
166 }); | |
OLD | NEW |