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

Side by Side Diff: cc/resources/tile_bundle.cc

Issue 62283012: cc: Added tile bundles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
« no previous file with comments | « cc/resources/tile_bundle.h ('k') | cc/resources/tile_bundle_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 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 #include "cc/resources/tile_bundle.h"
6
7 #include <algorithm>
8
9 #include "cc/resources/picture_layer_tiling.h"
10 #include "cc/resources/tile.h"
11 #include "cc/resources/tile_manager.h"
12
13 namespace cc {
14
15 TileBundle::Id TileBundle::s_next_id_ = 0;
16
17 TileBundle::TileBundle(TileManager* tile_manager,
18 int offset_x,
19 int offset_y,
20 int width,
21 int height)
22 : RefCountedManaged<TileBundle>(tile_manager),
23 tile_manager_(tile_manager),
24 index_offset_x_(offset_x),
25 index_offset_y_(offset_y),
26 index_count_x_(width),
27 index_count_y_(height),
28 conservative_count_(0u),
29 needs_tile_swap_(false),
30 id_(s_next_id_++) {
31 tiles_[ACTIVE_TREE].resize(index_count_y_);
32 for (int i = 0; i < index_count_y_; ++i)
33 tiles_[ACTIVE_TREE][i].resize(index_count_x_);
34
35 tiles_[PENDING_TREE].resize(index_count_y_);
36 for (int i = 0; i < index_count_y_; ++i)
37 tiles_[PENDING_TREE][i].resize(index_count_x_);
38 }
39
40 TileBundle::~TileBundle() {}
41
42 Tile* TileBundle::TileAt(WhichTree tree, int index_x, int index_y) {
43 DCHECK(!needs_tile_swap_);
44
45 UpdateToLocalIndex(&index_x, &index_y);
46 return TileAtLocalIndex(tree, index_x, index_y);
47 }
48
49 Tile* TileBundle::TileAtLocalIndex(WhichTree tree, int index_x, int index_y) {
50 return tiles_[tree][index_y][index_x].get();
51 }
52
53 void TileBundle::SetPriority(WhichTree tree, const TilePriority& priority) {
54 DCHECK(!needs_tile_swap_);
55
56 if (priority_[tree] == priority)
57 return;
58
59 priority_[tree] = priority;
60 tile_manager_->DidChangeTileBundlePriority(this);
61 }
62
63 TilePriority TileBundle::GetPriority(WhichTree tree) const {
64 return priority_[tree];
65 }
66
67 bool TileBundle::RemoveTileAt(WhichTree tree, int index_x, int index_y) {
68 DCHECK(!needs_tile_swap_);
69
70 UpdateToLocalIndex(&index_x, &index_y);
71 bool removed = !!tiles_[tree][index_y][index_x];
72 tiles_[tree][index_y][index_x] = NULL;
73 if (removed)
74 --conservative_count_;
75 return removed;
76 }
77
78 void TileBundle::AddTileAt(WhichTree tree,
79 int index_x,
80 int index_y,
81 scoped_refptr<Tile> tile) {
82 DCHECK(!needs_tile_swap_);
83
84 UpdateToLocalIndex(&index_x, &index_y);
85 DCHECK(!tiles_[tree][index_y][index_x]);
86 tiles_[tree][index_y][index_x] = tile;
87 ++conservative_count_;
88 }
89
90 void TileBundle::DidBecomeRecycled() {
91 priority_[ACTIVE_TREE] = TilePriority();
92 needs_tile_swap_ = !needs_tile_swap_;
93 }
94
95 void TileBundle::DidBecomeActive() {
96 priority_[ACTIVE_TREE] = priority_[PENDING_TREE];
97 priority_[PENDING_TREE] = TilePriority();
98 tiles_[ACTIVE_TREE].swap(tiles_[PENDING_TREE]);
99 needs_tile_swap_ = false;
100 }
101
102 void TileBundle::UpdateToLocalIndex(int* index_x, int* index_y) {
103 DCHECK(index_x);
104 DCHECK(index_y);
105
106 *index_x -= index_offset_x_;
107 *index_y -= index_offset_y_;
108
109 DCHECK_GE(*index_x, 0);
110 DCHECK_GE(*index_y, 0);
111 DCHECK_LT(*index_x, index_count_x_);
112 DCHECK_LT(*index_x, index_count_y_);
113 }
114
115 void TileBundle::SwapTilesIfRequired() {
116 if (!needs_tile_swap_)
117 return;
118
119 std::swap(priority_[ACTIVE_TREE], priority_[PENDING_TREE]);
120 tiles_[ACTIVE_TREE].swap(tiles_[PENDING_TREE]);
121 needs_tile_swap_ = false;
122 }
123
124 TileBundle::Iterator::Iterator(TileBundle* bundle)
125 : bundle_(bundle),
126 current_tile_(NULL),
127 index_x_(0),
128 index_y_(0),
129 current_tree_(ACTIVE_TREE),
130 min_tree_(ACTIVE_TREE),
131 max_tree_(PENDING_TREE) {
132 if (!InitializeNewTile())
133 ++(*this);
134 }
135
136 TileBundle::Iterator::Iterator(TileBundle* bundle, WhichTree tree)
137 : bundle_(bundle),
138 current_tile_(NULL),
139 index_x_(0),
140 index_y_(0),
141 current_tree_(tree),
142 min_tree_(tree),
143 max_tree_(tree) {
144 if (!InitializeNewTile())
145 ++(*this);
146 }
147
148 TileBundle::Iterator::~Iterator() {}
149
150 TileBundle::Iterator& TileBundle::Iterator::operator++() {
151 while (true) {
152 // Try advancing the tree first.
153 while (current_tree_ < max_tree_) {
154 current_tree_ = static_cast<WhichTree>(current_tree_ + 1);
reveman 2013/12/03 23:13:10 should min/max/current_tree_ be unsigned instead?
enne (OOO) 2013/12/03 23:14:30 unsigned would be a style violation, I think.
vmpstr 2013/12/03 23:41:33 I kind of prefer to keep it as WhichTree to be a b
155 if (InitializeNewTile())
156 return *this;
157 }
158
159 // Next, advance the index.
160 ++index_x_;
161 if (index_x_ >= bundle_->index_count_x_) {
162 index_x_ = 0;
163 ++index_y_;
164 }
165
166 // If we're out of bounds, break: the iteration is finished.
167 if (index_y_ >= bundle_->index_count_y_)
168 break;
169
170 // Try to initialize the min tree.
171 current_tree_ = min_tree_;
reveman 2013/12/03 23:13:10 I like to think of the tree as just another index
vmpstr 2013/12/03 23:41:33 Oh I see what you mean. That's really nice! I was
172 if (InitializeNewTile())
173 return *this;
174 }
175 return *this;
176 }
177
178 bool TileBundle::Iterator::InitializeNewTile() {
179 Tile* tile = bundle_->TileAtLocalIndex(current_tree_, index_x_, index_y_);
180
181 // We succeed only if we have a tile and it is different
182 // from what we currently have. This is to avoid the iterator
183 // returning the same tile twice when it's shared between trees.
184 if (!tile || tile == current_tile_)
185 return false;
186
187 current_tile_ = tile;
188 return true;
189 }
190
191 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/tile_bundle.h ('k') | cc/resources/tile_bundle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698