Chromium Code Reviews| OLD | NEW |
|---|---|
| (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, gfx::Rect bundle_rect) | |
| 18 : RefCountedManaged<TileBundle>(tile_manager), | |
| 19 tile_manager_(tile_manager), | |
| 20 bundle_rect_(bundle_rect), | |
| 21 conservative_count_(0u), | |
| 22 needs_tile_swap_(false), | |
| 23 id_(s_next_id_++) { | |
| 24 DCHECK(!bundle_rect_.IsEmpty()); | |
| 25 | |
| 26 tiles_[ACTIVE_TREE].resize(bundle_rect_.height()); | |
| 27 for (int i = 0; i < bundle_rect_.height(); ++i) | |
| 28 tiles_[ACTIVE_TREE][i].resize(bundle_rect_.width()); | |
| 29 | |
| 30 tiles_[PENDING_TREE].resize(bundle_rect_.height()); | |
| 31 for (int i = 0; i < bundle_rect_.height(); ++i) | |
| 32 tiles_[PENDING_TREE][i].resize(bundle_rect_.width()); | |
| 33 } | |
| 34 | |
| 35 TileBundle::~TileBundle() {} | |
| 36 | |
| 37 Tile* TileBundle::TileAt(WhichTree tree, int index_x, int index_y) { | |
| 38 DCHECK(!needs_tile_swap_); | |
| 39 | |
| 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 DCHECK(!needs_tile_swap_); | |
| 50 | |
| 51 if (priority_[tree] == priority) | |
| 52 return; | |
| 53 | |
| 54 priority_[tree] = priority; | |
| 55 tile_manager_->DidChangeTileBundlePriority(this); | |
| 56 } | |
| 57 | |
| 58 TilePriority TileBundle::GetPriority(WhichTree tree) const { | |
| 59 return priority_[tree]; | |
| 60 } | |
| 61 | |
| 62 bool TileBundle::RemoveTileAt(WhichTree tree, int index_x, int index_y) { | |
| 63 DCHECK(!needs_tile_swap_); | |
| 64 | |
| 65 UpdateToLocalIndex(&index_x, &index_y); | |
| 66 bool removed = !!tiles_[tree][index_y][index_x]; | |
| 67 tiles_[tree][index_y][index_x] = NULL; | |
| 68 if (removed) | |
| 69 --conservative_count_; | |
| 70 return removed; | |
| 71 } | |
| 72 | |
| 73 void TileBundle::AddTileAt(WhichTree tree, | |
| 74 int index_x, | |
| 75 int index_y, | |
| 76 scoped_refptr<Tile> tile) { | |
| 77 DCHECK(!needs_tile_swap_); | |
| 78 | |
| 79 UpdateToLocalIndex(&index_x, &index_y); | |
| 80 DCHECK(!tiles_[tree][index_y][index_x]); | |
| 81 tiles_[tree][index_y][index_x] = tile; | |
| 82 ++conservative_count_; | |
| 83 } | |
| 84 | |
| 85 void TileBundle::DidBecomeRecycled() { | |
| 86 priority_[ACTIVE_TREE] = TilePriority(); | |
| 87 needs_tile_swap_ = !needs_tile_swap_; | |
| 88 } | |
| 89 | |
| 90 void TileBundle::DidBecomeActive() { | |
| 91 priority_[ACTIVE_TREE] = priority_[PENDING_TREE]; | |
| 92 priority_[PENDING_TREE] = TilePriority(); | |
| 93 tiles_[ACTIVE_TREE].swap(tiles_[PENDING_TREE]); | |
| 94 needs_tile_swap_ = false; | |
| 95 } | |
| 96 | |
| 97 void TileBundle::UpdateToLocalIndex(int* index_x, int* index_y) { | |
| 98 DCHECK(index_x); | |
| 99 DCHECK(index_y); | |
| 100 | |
| 101 *index_x -= bundle_rect_.x(); | |
|
enne (OOO)
2013/11/27 01:38:05
Is bundle_rect just a collection of tile indices o
vmpstr
2013/11/27 21:09:36
Done.
| |
| 102 *index_y -= bundle_rect_.y(); | |
| 103 | |
| 104 DCHECK_GE(*index_x, 0); | |
| 105 DCHECK_GE(*index_y, 0); | |
| 106 DCHECK_LT(*index_x, bundle_rect_.width()); | |
| 107 DCHECK_LT(*index_x, bundle_rect_.height()); | |
| 108 } | |
| 109 | |
| 110 void TileBundle::SwapTilesIfRequired() { | |
| 111 if (!needs_tile_swap_) | |
| 112 return; | |
| 113 | |
| 114 std::swap(priority_[ACTIVE_TREE], priority_[PENDING_TREE]); | |
| 115 tiles_[ACTIVE_TREE].swap(tiles_[PENDING_TREE]); | |
| 116 needs_tile_swap_ = false; | |
| 117 } | |
| 118 | |
| 119 TileBundle::Iterator::Iterator(TileBundle* bundle) | |
| 120 : bundle_(bundle), | |
| 121 current_tile_(NULL), | |
| 122 index_x_(0), | |
| 123 index_y_(0), | |
| 124 current_tree_(ACTIVE_TREE), | |
| 125 active_tree_only_tile_(false), | |
| 126 pending_tree_only_tile_(false) { | |
| 127 for (int i = 0; i < NUM_TREES; ++i) | |
| 128 priority_[i] = NULL; | |
| 129 | |
| 130 if (!InitializeNewTileForTree(ACTIVE_TREE)) | |
| 131 ++(*this); | |
| 132 } | |
| 133 | |
| 134 TileBundle::Iterator::~Iterator() {} | |
| 135 | |
| 136 TileBundle::Iterator& TileBundle::Iterator::operator++() { | |
| 137 if (current_tree_ == ACTIVE_TREE && InitializeNewTileForTree(PENDING_TREE)) | |
| 138 return *this; | |
| 139 | |
| 140 do { | |
| 141 ++index_x_; | |
| 142 if (index_x_ >= bundle_->bundle_rect_.width()) { | |
| 143 index_x_ = 0; | |
| 144 ++index_y_; | |
| 145 } | |
| 146 } while (index_y_ < bundle_->bundle_rect_.height() && | |
| 147 !InitializeNewTileForTree(ACTIVE_TREE) && | |
| 148 !InitializeNewTileForTree(PENDING_TREE)); | |
| 149 return *this; | |
| 150 } | |
| 151 | |
| 152 bool TileBundle::Iterator::InitializeNewTileForTree(WhichTree tree) { | |
| 153 Tile* tile = bundle_->TileAtLocalIndex(tree, index_x_, index_y_); | |
| 154 if (!tile || tile == current_tile_) | |
| 155 return false; | |
| 156 | |
| 157 current_tree_ = tree; | |
| 158 current_tile_ = tile; | |
| 159 priority_[tree] = &bundle_->priority_[tree]; | |
| 160 | |
| 161 WhichTree twin_tree = (tree == ACTIVE_TREE) ? PENDING_TREE : ACTIVE_TREE; | |
| 162 Tile* twin_tile = bundle_->TileAtLocalIndex(twin_tree, index_x_, index_y_); | |
| 163 if (twin_tile == tile) { | |
| 164 priority_[twin_tree] = &bundle_->priority_[twin_tree]; | |
| 165 active_tree_only_tile_ = false; | |
| 166 pending_tree_only_tile_ = false; | |
| 167 } else { | |
| 168 active_tree_only_tile_ = (tree == ACTIVE_TREE); | |
| 169 pending_tree_only_tile_ = (tree == PENDING_TREE); | |
| 170 } | |
| 171 return true; | |
| 172 } | |
| 173 | |
| 174 } // namespace cc | |
| OLD | NEW |