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 |
| 29 LayerTreeHostImplHistory.prototype = { |
| 30 createNewLTHI: function() { |
| 31 var snapshotNumber = this.lthiSnapshots.length + 1; |
| 32 var lthi = new LayerTreeHostImpl(this, snapshotNumber); |
| 33 this.lthiSnapshots.push(lthi); |
| 34 this.allTilesBBox_ = undefined; |
| 35 return lthi; |
| 36 }, |
| 37 |
| 38 getOrCreateTileHistory: function(tileID) { |
| 39 if (!this.allTileHistories_[tileID]) |
| 40 this.allTileHistories_[tileID] = new ccfv.model.TileHistory(tileID); |
| 41 return this.allTileHistories_[tileID]; |
| 42 }, |
| 43 |
| 44 get allTilesBBox() { |
| 45 if (!this.allTilesBBox_) { |
| 46 var bbox = new base.BBox2(); |
| 47 for (var tileID in this.allTileHistories_) { |
| 48 var tileHistory = this.allTileHistories_[tileID]; |
| 49 for (var snapshotNumber in tileHistory.tilesBySnapshotNumber) { |
| 50 var tile = tileHistory.tilesBySnapshotNumber[snapshotNumber]; |
| 51 if (tile.priority[0].current_screen_quad) |
| 52 bbox.addQuad(tile.priority[0].current_screen_quad); |
| 53 if (tile.priority[1].current_screen_quad) |
| 54 bbox.addQuad(tile.priority[1].current_screen_quad); |
| 55 } |
| 56 } |
| 57 this.allTilesBBox_ = bbox; |
| 58 } |
| 59 return this.allTilesBBox_; |
| 60 }, |
| 61 }; |
| 62 |
| 63 /** |
| 64 * Represents a snapshot of the cc::LayerTreeHostImpl at an instant in time. |
| 65 * |
| 66 * @constructor |
| 67 */ |
| 68 function LayerTreeHostImpl(history, snapshotNumber) { |
| 69 this.history = history; |
| 70 this.snapshotNumber = snapshotNumber; |
| 71 this.deviceViewportSize = {} |
| 72 |
| 73 this.allTiles = []; |
| 74 |
| 75 this.rebuildNeeded_ = false; |
| 76 |
| 77 // These fields are affected by the rebuildIfNeeded_() flow. |
| 78 this.pendingTree_ = new ccfv.model.LayerTreeImpl(constants.PENDING_TREE); |
| 79 this.activeTree_ = new ccfv.model.LayerTreeImpl(constants.ACTIVE_TREE); |
| 80 this.inactiveTiles_ = []; |
| 81 } |
| 82 |
| 83 LayerTreeHostImpl.prototype = { |
| 84 get id() { |
| 85 return this.history.id; |
| 86 }, |
| 87 |
| 88 getOrCreateTile: function(tile_id) { |
| 89 var tileHistory = this.history.getOrCreateTileHistory(tile_id); |
| 90 var tile = tileHistory.getOrCreateTileForLTHI(this); |
| 91 this.allTiles.push(tile); |
| 92 this.rebuildNeeded_ = true; |
| 93 return tile; |
| 94 }, |
| 95 |
| 96 get activeTree() { |
| 97 this.rebuildIfNeeded_(); |
| 98 return this.activeTree_; |
| 99 }, |
| 100 |
| 101 get pendingTree() { |
| 102 this.rebuildIfNeeded_(); |
| 103 return this.pendingTree_; |
| 104 }, |
| 105 |
| 106 get inactiveTiles() { |
| 107 this.rebuildIfNeeded_(); |
| 108 return this.inactiveTiles_; |
| 109 }, |
| 110 |
| 111 rebuildIfNeeded_: function() { |
| 112 if (!this.rebuildNeeded_) |
| 113 return; |
| 114 this.activeTree_.resetTiles(); |
| 115 this.pendingTree_.resetTiles(); |
| 116 this.allTiles.forEach(function(tile) { |
| 117 if (tile.priority[constants.ACTIVE_TREE].is_live) |
| 118 this.activeTree_.tiles.push(tile); |
| 119 if (tile.priority[constants.PENDING_TREE].is_live) |
| 120 this.pendingTree_.tiles.push(tile); |
| 121 if (tile.priority[constants.PENDING_TREE].is_live == false && |
| 122 tile.priority[constants.ACTIVE_TREE].is_live == false) |
| 123 this.inactiveTiles_.push(tile); |
| 124 }, this); |
| 125 this.rebuildNeeded_ = false; |
| 126 }, |
| 127 }; |
| 128 |
| 129 return { |
| 130 LayerTreeHostImpl: LayerTreeHostImpl, |
| 131 LayerTreeHostImplHistory: LayerTreeHostImplHistory |
| 132 }; |
| 133 }); |
OLD | NEW |