Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: tools/cc-frame-viewer/src/model/layer_tree_host_impl.js

Issue 12287014: [cc-frame-viewer] Show layers and levels of detail (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 'use strict'; 5 'use strict';
6 6
7 base.require('base.bbox2'); 7 base.require('base.bbox2');
8 base.require('model.constants'); 8 base.require('model.constants');
9 base.require('model.tile'); 9 base.require('model.tile');
10 base.require('model.layer_tree_impl'); 10 base.require('model.layer_tree_impl');
11 11
12 base.exportTo('ccfv.model', function() { 12 base.exportTo('ccfv.model', function() {
13 13
14 var constants = ccfv.model.constants; 14 var constants = ccfv.model.constants;
15 15
16 /** 16 /**
17 * Represents the history of a specific cc::LayerTreeHostImpl over time. 17 * Represents the history of a specific cc::LayerTreeHostImpl over time.
18 * 18 *
19 * @constructor 19 * @constructor
20 */ 20 */
21 function LayerTreeHostImplHistory(id) { 21 function LayerTreeHostImplHistory(id) {
22 this.id = id; 22 this.id = id;
23 this.lthiSnapshots = []; 23 this.lthiSnapshots = [];
24 24
25 this.allTileHistories_ = {}; 25 this.allTileHistories_ = {};
26 this.allTilesBBox_ = undefined; 26 this.allTilesBBox_ = undefined;
27
28 this.allLayerImplHistories_ = {};
27 }; 29 };
28 30
29 LayerTreeHostImplHistory.prototype = { 31 LayerTreeHostImplHistory.prototype = {
30 createNewLTHI: function() { 32 createNewLTHI: function() {
31 var snapshotNumber = this.lthiSnapshots.length + 1; 33 var snapshotNumber = this.lthiSnapshots.length + 1;
32 var lthi = new LayerTreeHostImpl(this, snapshotNumber); 34 var lthi = new LayerTreeHostImpl(this, snapshotNumber);
33 this.lthiSnapshots.push(lthi); 35 this.lthiSnapshots.push(lthi);
34 this.allTilesBBox_ = undefined; 36 this.allTilesBBox_ = undefined;
37 this.allContentsScales_ = undefined;
35 return lthi; 38 return lthi;
36 }, 39 },
37 40
38 getOrCreateTileHistory: function(tileID) { 41 getOrCreateTileHistory: function(tileID) {
39 if (!this.allTileHistories_[tileID]) 42 if (!this.allTileHistories_[tileID])
40 this.allTileHistories_[tileID] = new ccfv.model.TileHistory(tileID); 43 this.allTileHistories_[tileID] = new ccfv.model.TileHistory(tileID);
41 return this.allTileHistories_[tileID]; 44 return this.allTileHistories_[tileID];
42 }, 45 },
43 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
44 get allTilesBBox() { 67 get allTilesBBox() {
45 if (!this.allTilesBBox_) { 68 if (!this.allTilesBBox_) {
46 var bbox = new base.BBox2(); 69 var bbox = new base.BBox2();
47 for (var tileID in this.allTileHistories_) { 70 for (var tileID in this.allTileHistories_) {
48 var tileHistory = this.allTileHistories_[tileID]; 71 var tileHistory = this.allTileHistories_[tileID];
49 for (var snapshotNumber in tileHistory.tilesBySnapshotNumber) { 72 for (var snapshotNumber in tileHistory.tilesBySnapshotNumber) {
50 var tile = tileHistory.tilesBySnapshotNumber[snapshotNumber]; 73 var tile = tileHistory.tilesBySnapshotNumber[snapshotNumber];
51 if (tile.priority[0].current_screen_quad) 74 if (tile.priority[0].current_screen_quad)
52 bbox.addQuad(tile.priority[0].current_screen_quad); 75 bbox.addQuad(tile.priority[0].current_screen_quad);
53 if (tile.priority[1].current_screen_quad) 76 if (tile.priority[1].current_screen_quad)
(...skipping 11 matching lines...) Expand all
65 * 88 *
66 * @constructor 89 * @constructor
67 */ 90 */
68 function LayerTreeHostImpl(history, snapshotNumber) { 91 function LayerTreeHostImpl(history, snapshotNumber) {
69 this.history = history; 92 this.history = history;
70 this.snapshotNumber = snapshotNumber; 93 this.snapshotNumber = snapshotNumber;
71 this.deviceViewportSize = {} 94 this.deviceViewportSize = {}
72 95
73 this.allTiles = []; 96 this.allTiles = [];
74 97
75 this.rebuildNeeded_ = false; 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);
76 103
77 // These fields are affected by the rebuildIfNeeded_() flow. 104 this.tilesForTree_ = undefined;
78 this.pendingTree_ = new ccfv.model.LayerTreeImpl(constants.PENDING_TREE);
79 this.activeTree_ = new ccfv.model.LayerTreeImpl(constants.ACTIVE_TREE);
80 this.inactiveTiles_ = []; 105 this.inactiveTiles_ = [];
81 } 106 }
82 107
83 LayerTreeHostImpl.prototype = { 108 LayerTreeHostImpl.prototype = {
84 get id() { 109 get id() {
85 return this.history.id; 110 return this.history.id;
86 }, 111 },
87 112
88 getOrCreateTile: function(tile_id) { 113 getTree: function(whichTree) {
89 var tileHistory = this.history.getOrCreateTileHistory(tile_id); 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);
90 var tile = tileHistory.getOrCreateTileForLTHI(this); 124 var tile = tileHistory.getOrCreateTileForLTHI(this);
91 this.allTiles.push(tile); 125 this.allTiles.push(tile);
92 this.rebuildNeeded_ = true; 126
127 this.activeTree.setTilesDirty();
128 this.pendingTree.setTilesDirty();
129 this.tilesForTree_ = undefined;
130 this.inactiveTiles_ = undefined;
131
93 return tile; 132 return tile;
94 }, 133 },
95 134
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() { 135 get inactiveTiles() {
107 this.rebuildIfNeeded_(); 136 if (this.inactiveTiles_ === undefined)
137 this.rebuildTiles_();
108 return this.inactiveTiles_; 138 return this.inactiveTiles_;
109 }, 139 },
110 140
111 rebuildIfNeeded_: function() { 141 getTilesForTree: function(which_tree) {
112 if (!this.rebuildNeeded_) 142 if (this.tilesForTree_ === undefined)
113 return; 143 this.rebuildTiles_();
114 this.activeTree_.resetTiles(); 144 return this.tilesForTree_[which_tree];
115 this.pendingTree_.resetTiles(); 145 },
146
147 rebuildTiles_: function() {
148 this.tilesForTree_ = [[], []];
149 this.inactiveTiles_ = [];
116 this.allTiles.forEach(function(tile) { 150 this.allTiles.forEach(function(tile) {
117 if (tile.priority[constants.ACTIVE_TREE].is_live) 151 if (tile.priority[constants.ACTIVE_TREE].is_live)
118 this.activeTree_.tiles.push(tile); 152 this.tilesForTree_[constants.ACTIVE_TREE].push(tile);
119 if (tile.priority[constants.PENDING_TREE].is_live) 153 if (tile.priority[constants.PENDING_TREE].is_live)
120 this.pendingTree_.tiles.push(tile); 154 this.tilesForTree_[constants.PENDING_TREE].push(tile);
121 if (tile.priority[constants.PENDING_TREE].is_live == false && 155 if (tile.priority[constants.PENDING_TREE].is_live == false &&
122 tile.priority[constants.ACTIVE_TREE].is_live == false) 156 tile.priority[constants.ACTIVE_TREE].is_live == false)
123 this.inactiveTiles_.push(tile); 157 this.inactiveTiles_.push(tile);
124 }, this); 158 }, this);
125 this.rebuildNeeded_ = false;
126 }, 159 },
127 }; 160 };
128 161
129 return { 162 return {
130 LayerTreeHostImpl: LayerTreeHostImpl, 163 LayerTreeHostImpl: LayerTreeHostImpl,
131 LayerTreeHostImplHistory: LayerTreeHostImplHistory 164 LayerTreeHostImplHistory: LayerTreeHostImplHistory
132 }; 165 };
133 }); 166 });
OLDNEW
« no previous file with comments | « tools/cc-frame-viewer/src/model/layer_impl.js ('k') | tools/cc-frame-viewer/src/model/layer_tree_impl.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698