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

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: perftest fix Created 7 years, 1 month 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 "cc/resources/picture_layer_tiling.h"
8 #include "cc/resources/tile.h"
9 #include "cc/resources/tile_manager.h"
10
11 namespace cc {
12
13 TileBundle::Id TileBundle::s_next_id_ = 0;
14
15 TileBundle::TileBundle(TileManager* tile_manager,
16 int width,
17 int height,
18 int offset_x,
19 int offset_y)
20 : RefCountedManaged<TileBundle>(tile_manager),
21 tile_manager_(tile_manager),
22 width_(width),
23 height_(height),
24 offset_x_(offset_x),
25 offset_y_(offset_y),
26 conservative_count_(0u),
27 id_(s_next_id_++) {
28 tiles_[ACTIVE_TREE].resize(height);
29 for (int i = 0; i < height; ++i)
30 tiles_[ACTIVE_TREE][i].resize(width);
31
32 tiles_[PENDING_TREE].resize(height);
33 for (int i = 0; i < height; ++i)
34 tiles_[PENDING_TREE][i].resize(width);
35 }
36
37 TileBundle::~TileBundle() {}
38
39 Tile* TileBundle::TileAt(WhichTree tree, int index_x, int index_y) {
40 UpdateToLocalIndex(&index_x, &index_y);
41 return TileAtLocalIndex(tree, index_x, index_y);
42 }
43
44 Tile* TileBundle::TileAtLocalIndex(WhichTree tree, int index_x, int index_y) {
45 return tiles_[tree][index_y][index_x].get();
46 }
47
48 void TileBundle::SetPriority(WhichTree tree, const TilePriority& priority) {
49 if (priority_[tree] == priority)
50 return;
51
52 priority_[tree] = priority;
53 tile_manager_->DidChangeTileBundlePriority(this);
54 }
55
56 TilePriority TileBundle::GetPriority(WhichTree tree) const {
57 return priority_[tree];
58 }
59
60 bool TileBundle::RemoveTileAt(WhichTree tree, int index_x, int index_y) {
61 UpdateToLocalIndex(&index_x, &index_y);
62 bool removed = !!tiles_[tree][index_y][index_x];
63 tiles_[tree][index_y][index_x] = NULL;
64 if (removed)
65 --conservative_count_;
66 return removed;
67 }
68
69 void TileBundle::AddTileAt(WhichTree tree,
70 int index_x,
71 int index_y,
72 scoped_refptr<Tile> tile) {
73 UpdateToLocalIndex(&index_x, &index_y);
74 DCHECK(!tiles_[tree][index_y][index_x]);
75 tiles_[tree][index_y][index_x] = tile;
enne (OOO) 2013/11/25 22:17:11 What about DCHECKing spatial relationships here, t
vmpstr 2013/11/27 00:03:15 A similar thing is dchecked in UpdateToLocalIndex
enne (OOO) 2013/11/27 01:38:05 Oh, I see. I guess I misunderstood what was being
76 ++conservative_count_;
77 }
78
79 void TileBundle::DidBecomeRecycled() {
80 priority_[ACTIVE_TREE] = TilePriority();
81 }
82
83 void TileBundle::DidBecomeActive() {
84 priority_[ACTIVE_TREE] = priority_[PENDING_TREE];
85 priority_[PENDING_TREE] = TilePriority();
86 tiles_[ACTIVE_TREE].swap(tiles_[PENDING_TREE]);
87 }
88
89 void TileBundle::UpdateToLocalIndex(int* index_x, int* index_y) {
90 DCHECK(index_x);
91 DCHECK(index_y);
92
93 *index_x -= offset_x_;
94 *index_y -= offset_y_;
95
96 DCHECK_GE(*index_x, 0);
97 DCHECK_GE(*index_y, 0);
98 DCHECK_LT(*index_x, width_);
99 DCHECK_LT(*index_x, height_);
100 }
101
102 TileBundle::Iterator::Iterator(TileBundle* bundle)
103 : bundle_(bundle),
104 current_tile_(NULL),
105 index_x_(0),
106 index_y_(0),
107 current_tree_(ACTIVE_TREE),
108 active_tree_only_tile_(false),
109 pending_tree_only_tile_(false) {
110 for (int i = 0; i < NUM_TREES; ++i)
111 priority_[i] = NULL;
112
113 if (!SetTile(ACTIVE_TREE))
114 ++(*this);
115 }
116
117 TileBundle::Iterator::~Iterator() {}
118
119 TileBundle::Iterator& TileBundle::Iterator::operator++() {
120 if (current_tree_ == ACTIVE_TREE && SetTile(PENDING_TREE))
121 return *this;
122
123 do {
124 ++index_x_;
125 if (index_x_ >= bundle_->width_) {
126 index_x_ = 0;
127 ++index_y_;
128 }
129 } while (index_y_ < bundle_->height_ &&
130 !SetTile(ACTIVE_TREE) &&
131 !SetTile(PENDING_TREE));
132 return *this;
133 }
134
135 bool TileBundle::Iterator::SetTile(WhichTree tree) {
136 Tile* tile = bundle_->TileAtLocalIndex(tree, index_x_, index_y_);
137 if (!tile || tile == current_tile_)
138 return false;
139
140 current_tree_ = tree;
141 current_tile_ = tile;
142 priority_[tree] = &bundle_->priority_[tree];
143
144 WhichTree twin_tree = (tree == ACTIVE_TREE) ? PENDING_TREE : ACTIVE_TREE;
145 Tile* twin_tile = bundle_->TileAtLocalIndex(twin_tree, index_x_, index_y_);
146 if (twin_tile == tile) {
147 priority_[twin_tree] = &bundle_->priority_[twin_tree];
148 active_tree_only_tile_ = false;
149 pending_tree_only_tile_ = false;
150 } else {
151 active_tree_only_tile_ = (tree == ACTIVE_TREE);
152 pending_tree_only_tile_ = (tree == PENDING_TREE);
153 }
154 return true;
155 }
156
157 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698