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

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: rebase 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
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 offset_x_(offset_x),
25 offset_y_(offset_y),
26 width_(width),
27 height_(height),
28 conservative_count_(0u),
29 needs_tile_swap_(false),
30 id_(s_next_id_++) {
31 tiles_[ACTIVE_TREE].resize(height_);
32 for (int i = 0; i < height_; ++i)
33 tiles_[ACTIVE_TREE][i].resize(width_);
34
35 tiles_[PENDING_TREE].resize(height_);
36 for (int i = 0; i < height_; ++i)
37 tiles_[PENDING_TREE][i].resize(width_);
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 -= offset_x_;
107 *index_y -= offset_y_;
108
109 DCHECK_GE(*index_x, 0);
110 DCHECK_GE(*index_y, 0);
111 DCHECK_LT(*index_x, width_);
112 DCHECK_LT(*index_x, height_);
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 trees_to_iterate_.push_back(ACTIVE_TREE);
131 trees_to_iterate_.push_back(PENDING_TREE);
132 if (!InitializeNewTileForTree(trees_to_iterate_[0]))
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 trees_to_iterate_.push_back(tree);
143 if (!InitializeNewTileForTree(trees_to_iterate_[0]))
144 ++(*this);
145 }
146
147 TileBundle::Iterator::~Iterator() {}
148
149 TileBundle::Iterator& TileBundle::Iterator::operator++() {
150 DCHECK_GT(trees_to_iterate_.size(), 0u);
151 DCHECK_LE(trees_to_iterate_.size(), 2u);
152
153 if (current_tree_ == trees_to_iterate_[0] &&
154 trees_to_iterate_.size() > 1 &&
155 InitializeNewTileForTree(trees_to_iterate_[1]))
reveman 2013/12/03 19:58:19 Could this be integrated in the loop below instead
vmpstr 2013/12/03 22:01:36 Done. I rewrote this a bit.
156 return *this;
157
158 do {
159 ++index_x_;
160 if (index_x_ >= bundle_->width_) {
161 index_x_ = 0;
162 ++index_y_;
163 }
164 } while (index_y_ < bundle_->height_ &&
165 !InitializeNewTileForTree(trees_to_iterate_[0]) &&
166 (trees_to_iterate_.size() == 1 ||
167 !InitializeNewTileForTree(trees_to_iterate_[1])));
reveman 2013/12/03 19:58:19 I find this code a bit hard to understand. Could s
vmpstr 2013/12/03 22:01:36 Done.
168 return *this;
169 }
170
171 bool TileBundle::Iterator::InitializeNewTileForTree(WhichTree tree) {
172 Tile* tile = bundle_->TileAtLocalIndex(tree, index_x_, index_y_);
173 if (!tile || tile == current_tile_)
reveman 2013/12/03 19:58:19 is the "tile == current_tile_" check needed? would
vmpstr 2013/12/03 22:01:36 We need this to make sure that the iterator doesn'
reveman 2013/12/03 23:13:10 Got it. Thanks for adding the comment.
174 return false;
175
176 current_tree_ = tree;
177 current_tile_ = tile;
178 return true;
179 }
180
181 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698