Chromium Code Reviews| Index: cc/resources/tile_bundle.cc |
| diff --git a/cc/resources/tile_bundle.cc b/cc/resources/tile_bundle.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1cd3424e9a36a8275b874b0fee93d1ec7ad21880 |
| --- /dev/null |
| +++ b/cc/resources/tile_bundle.cc |
| @@ -0,0 +1,157 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/resources/tile_bundle.h" |
| + |
| +#include "cc/resources/picture_layer_tiling.h" |
| +#include "cc/resources/tile.h" |
| +#include "cc/resources/tile_manager.h" |
| + |
| +namespace cc { |
| + |
| +TileBundle::Id TileBundle::s_next_id_ = 0; |
| + |
| +TileBundle::TileBundle(TileManager* tile_manager, |
| + int width, |
| + int height, |
| + int offset_x, |
| + int offset_y) |
| + : RefCountedManaged<TileBundle>(tile_manager), |
| + tile_manager_(tile_manager), |
| + width_(width), |
| + height_(height), |
| + offset_x_(offset_x), |
| + offset_y_(offset_y), |
| + conservative_count_(0u), |
| + id_(s_next_id_++) { |
| + tiles_[ACTIVE_TREE].resize(height); |
| + for (int i = 0; i < height; ++i) |
| + tiles_[ACTIVE_TREE][i].resize(width); |
| + |
| + tiles_[PENDING_TREE].resize(height); |
| + for (int i = 0; i < height; ++i) |
| + tiles_[PENDING_TREE][i].resize(width); |
| +} |
| + |
| +TileBundle::~TileBundle() {} |
| + |
| +Tile* TileBundle::TileAt(WhichTree tree, int index_x, int index_y) { |
| + UpdateToLocalIndex(&index_x, &index_y); |
| + return TileAtLocalIndex(tree, index_x, index_y); |
| +} |
| + |
| +Tile* TileBundle::TileAtLocalIndex(WhichTree tree, int index_x, int index_y) { |
| + return tiles_[tree][index_y][index_x].get(); |
| +} |
| + |
| +void TileBundle::SetPriority(WhichTree tree, const TilePriority& priority) { |
| + if (priority_[tree] == priority) |
| + return; |
| + |
| + priority_[tree] = priority; |
| + tile_manager_->DidChangeTileBundlePriority(this); |
| +} |
| + |
| +TilePriority TileBundle::GetPriority(WhichTree tree) const { |
| + return priority_[tree]; |
| +} |
| + |
| +bool TileBundle::RemoveTileAt(WhichTree tree, int index_x, int index_y) { |
| + UpdateToLocalIndex(&index_x, &index_y); |
| + bool removed = !!tiles_[tree][index_y][index_x]; |
| + tiles_[tree][index_y][index_x] = NULL; |
| + if (removed) |
| + --conservative_count_; |
| + return removed; |
| +} |
| + |
| +void TileBundle::AddTileAt(WhichTree tree, |
| + int index_x, |
| + int index_y, |
| + scoped_refptr<Tile> tile) { |
| + UpdateToLocalIndex(&index_x, &index_y); |
| + DCHECK(!tiles_[tree][index_y][index_x]); |
| + 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
|
| + ++conservative_count_; |
| +} |
| + |
| +void TileBundle::DidBecomeRecycled() { |
| + priority_[ACTIVE_TREE] = TilePriority(); |
| +} |
| + |
| +void TileBundle::DidBecomeActive() { |
| + priority_[ACTIVE_TREE] = priority_[PENDING_TREE]; |
| + priority_[PENDING_TREE] = TilePriority(); |
| + tiles_[ACTIVE_TREE].swap(tiles_[PENDING_TREE]); |
| +} |
| + |
| +void TileBundle::UpdateToLocalIndex(int* index_x, int* index_y) { |
| + DCHECK(index_x); |
| + DCHECK(index_y); |
| + |
| + *index_x -= offset_x_; |
| + *index_y -= offset_y_; |
| + |
| + DCHECK_GE(*index_x, 0); |
| + DCHECK_GE(*index_y, 0); |
| + DCHECK_LT(*index_x, width_); |
| + DCHECK_LT(*index_x, height_); |
| +} |
| + |
| +TileBundle::Iterator::Iterator(TileBundle* bundle) |
| + : bundle_(bundle), |
| + current_tile_(NULL), |
| + index_x_(0), |
| + index_y_(0), |
| + current_tree_(ACTIVE_TREE), |
| + active_tree_only_tile_(false), |
| + pending_tree_only_tile_(false) { |
| + for (int i = 0; i < NUM_TREES; ++i) |
| + priority_[i] = NULL; |
| + |
| + if (!SetTile(ACTIVE_TREE)) |
| + ++(*this); |
| +} |
| + |
| +TileBundle::Iterator::~Iterator() {} |
| + |
| +TileBundle::Iterator& TileBundle::Iterator::operator++() { |
| + if (current_tree_ == ACTIVE_TREE && SetTile(PENDING_TREE)) |
| + return *this; |
| + |
| + do { |
| + ++index_x_; |
| + if (index_x_ >= bundle_->width_) { |
| + index_x_ = 0; |
| + ++index_y_; |
| + } |
| + } while (index_y_ < bundle_->height_ && |
| + !SetTile(ACTIVE_TREE) && |
| + !SetTile(PENDING_TREE)); |
| + return *this; |
| +} |
| + |
| +bool TileBundle::Iterator::SetTile(WhichTree tree) { |
| + Tile* tile = bundle_->TileAtLocalIndex(tree, index_x_, index_y_); |
| + if (!tile || tile == current_tile_) |
| + return false; |
| + |
| + current_tree_ = tree; |
| + current_tile_ = tile; |
| + priority_[tree] = &bundle_->priority_[tree]; |
| + |
| + WhichTree twin_tree = (tree == ACTIVE_TREE) ? PENDING_TREE : ACTIVE_TREE; |
| + Tile* twin_tile = bundle_->TileAtLocalIndex(twin_tree, index_x_, index_y_); |
| + if (twin_tile == tile) { |
| + priority_[twin_tree] = &bundle_->priority_[twin_tree]; |
| + active_tree_only_tile_ = false; |
| + pending_tree_only_tile_ = false; |
| + } else { |
| + active_tree_only_tile_ = (tree == ACTIVE_TREE); |
| + pending_tree_only_tile_ = (tree == PENDING_TREE); |
| + } |
| + return true; |
| +} |
| + |
| +} // namespace cc |