Chromium Code Reviews| Index: cc/resources/picture_layer_tiling.cc |
| diff --git a/cc/resources/picture_layer_tiling.cc b/cc/resources/picture_layer_tiling.cc |
| index 939e0b163d4a459aa50d0437a9aec5b94c2f8230..9d06f26e118512514b6c06b6b4bfb4c03e053cb0 100644 |
| --- a/cc/resources/picture_layer_tiling.cc |
| +++ b/cc/resources/picture_layer_tiling.cc |
| @@ -10,6 +10,8 @@ |
| #include "base/debug/trace_event.h" |
| #include "cc/base/math_util.h" |
| +#include "cc/resources/tile.h" |
| +#include "cc/resources/tile_priority.h" |
| #include "ui/gfx/point_conversions.h" |
| #include "ui/gfx/rect_conversions.h" |
| #include "ui/gfx/safe_integer_conversions.h" |
| @@ -64,13 +66,6 @@ gfx::SizeF PictureLayerTiling::ContentSizeF() const { |
| return gfx::ScaleSize(layer_bounds_, contents_scale_); |
| } |
| -Tile* PictureLayerTiling::TileAt(int i, int j) const { |
| - TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); |
| - if (iter == tiles_.end()) |
| - return NULL; |
| - return iter->second.get(); |
| -} |
| - |
| void PictureLayerTiling::CreateTile(int i, |
| int j, |
| const PictureLayerTiling* twin_tiling) { |
| @@ -430,63 +425,36 @@ void PictureLayerTiling::UpdateTilePriorities( |
| last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; |
| last_visible_rect_in_content_space_ = visible_rect_in_content_space; |
| - // Assign now priority to all visible tiles. |
| - TilePriority now_priority(resolution_, TilePriority::NOW, 0); |
| - for (TilingData::Iterator iter(&tiling_data_, visible_rect_in_content_space); |
| - iter; |
| - ++iter) { |
| - TileMap::iterator find = tiles_.find(iter.index()); |
| - if (find == tiles_.end()) |
| - continue; |
| - Tile* tile = find->second.get(); |
| - |
| - tile->SetPriority(tree, now_priority); |
| - } |
| + current_skewport_ = skewport; |
| + current_eventually_rect_ = eventually_rect; |
| + current_visible_rect_in_content_space_ = visible_rect_in_content_space; |
| - // Assign soon priority to all tiles in the skewport that are not visible. |
| + TilePriority now_priority(resolution_, TilePriority::NOW, 0); |
| float content_to_screen_scale = |
| 1.0f / (contents_scale_ * layer_contents_scale); |
| - for (TilingData::DifferenceIterator iter( |
| - &tiling_data_, skewport, visible_rect_in_content_space); |
| - iter; |
| - ++iter) { |
| - TileMap::iterator find = tiles_.find(iter.index()); |
| - if (find == tiles_.end()) |
| - continue; |
| - Tile* tile = find->second.get(); |
| - gfx::Rect tile_bounds = |
| - tiling_data_.TileBounds(iter.index_x(), iter.index_y()); |
| - |
| - float distance_to_visible = |
| - visible_rect_in_content_space.ManhattanInternalDistance(tile_bounds) * |
| - content_to_screen_scale; |
| - |
| - TilePriority priority(resolution_, TilePriority::SOON, distance_to_visible); |
| - tile->SetPriority(tree, priority); |
| - } |
| - |
| - // Assign eventually priority to all tiles in the eventually rect that are not |
| - // in the skewport. |
| - for (TilingData::DifferenceIterator iter( |
| - &tiling_data_, eventually_rect, skewport); |
| - iter; |
| - ++iter) { |
| - TileMap::iterator find = tiles_.find(iter.index()); |
| - if (find == tiles_.end()) |
| + for (TilingRasterTileIterator it(this); it; ++it) { |
| + Tile* tile = *it; |
| + if (it.get_type() == TilingRasterTileIterator::VISIBLE) { |
| + tile->SetPriority(tree, now_priority); |
| continue; |
| - Tile* tile = find->second.get(); |
| + } |
| + |
| + TilePriority::PriorityBin bin = |
| + (it.get_type() == TilingRasterTileIterator::SKEWPORT) |
| + ? TilePriority::SOON |
| + : TilePriority::EVENTUALLY; |
| - gfx::Rect tile_bounds = |
| - tiling_data_.TileBounds(iter.index_x(), iter.index_y()); |
| + gfx::Rect tile_bounds = it.TileBounds(); |
| float distance_to_visible = |
| visible_rect_in_content_space.ManhattanInternalDistance(tile_bounds) * |
| content_to_screen_scale; |
| - TilePriority priority( |
| - resolution_, TilePriority::EVENTUALLY, distance_to_visible); |
| + |
| + TilePriority priority(resolution_, bin, distance_to_visible); |
| tile->SetPriority(tree, priority); |
| } |
| + last_update_tree_ = tree; |
| } |
| void PictureLayerTiling::SetLiveTilesRect( |
| @@ -556,6 +524,21 @@ void PictureLayerTiling::UpdateTilesToCurrentPile() { |
| } |
| } |
| +size_t PictureLayerTiling::RequiredGPUMemoryInBytes() const { |
| + size_t amount = 0; |
| + for (TilingData::Iterator iter(&tiling_data_, |
| + last_visible_rect_in_content_space_); |
| + iter; |
| + ++iter) { |
| + TileMap::const_iterator find = tiles_.find(iter.index()); |
| + if (find == tiles_.end()) |
| + continue; |
| + Tile* tile = find->second.get(); |
| + amount += tile->GPUMemoryUsageInBytes(); |
| + } |
| + return amount; |
| +} |
| + |
| scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { |
| scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| state->SetInteger("num_tiles", tiles_.size()); |
| @@ -723,4 +706,92 @@ gfx::Rect PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy( |
| return result; |
| } |
| +PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator() |
| + : tiling_(NULL), current_tile_(NULL) {} |
| + |
| +PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator( |
| + PictureLayerTiling* tiling) |
| + : tiling_(tiling), |
| + type_(VISIBLE), |
| + current_tile_(NULL), |
| + visible_iterator_(&tiling->tiling_data_, |
| + tiling->current_visible_rect_in_content_space_), |
| + spiral_iterator_(&tiling->tiling_data_, |
| + tiling->current_skewport_, |
| + tiling->current_visible_rect_in_content_space_, |
| + tiling->current_visible_rect_in_content_space_) { |
| + if (!visible_iterator_) { |
| + AdvancePhase(); |
| + return; |
| + } |
| + |
| + current_tile_ = |
| + tiling_->TileAt(visible_iterator_.index_x(), visible_iterator_.index_y()); |
| + if (!current_tile_) |
| + ++(*this); |
| +} |
| + |
| +PictureLayerTiling::TilingRasterTileIterator::~TilingRasterTileIterator() {} |
| + |
| +void PictureLayerTiling::TilingRasterTileIterator::AdvancePhase() { |
| + DCHECK_LT(type_, EVENTUALLY); |
| + |
| + do { |
| + type_ = static_cast<Type>(type_ + 1); |
| + if (type_ == EVENTUALLY) { |
| + spiral_iterator_ = TilingData::SpiralDifferenceIterator( |
| + &tiling_->tiling_data_, |
| + tiling_->current_eventually_rect_, |
| + tiling_->current_skewport_, |
| + tiling_->current_visible_rect_in_content_space_); |
| + } |
| + |
| + while (spiral_iterator_) { |
| + current_tile_ = tiling_->TileAt(spiral_iterator_.index_x(), |
| + spiral_iterator_.index_y()); |
| + if (current_tile_) |
| + break; |
| + ++spiral_iterator_; |
| + } |
| + |
| + if (!spiral_iterator_ && type_ == EVENTUALLY) |
| + break; |
| + } while (!spiral_iterator_); |
| +} |
| + |
| +PictureLayerTiling::TilingRasterTileIterator& |
| +PictureLayerTiling::TilingRasterTileIterator:: |
| +operator++() { |
|
epennerAtGoogle
2014/03/05 00:16:03
General question regarding final design: Is this e
vmpstr
2014/03/05 00:37:21
Yeah, the priority will be set lazily. I think her
|
| + current_tile_ = NULL; |
| + while (!current_tile_) { |
| + std::pair<int, int> next_index; |
| + switch (type_) { |
| + case VISIBLE: |
| + ++visible_iterator_; |
| + if (!visible_iterator_) { |
| + AdvancePhase(); |
| + return *this; |
| + } |
| + next_index = visible_iterator_.index(); |
| + break; |
| + case SKEWPORT: |
| + ++spiral_iterator_; |
| + if (!spiral_iterator_) { |
| + AdvancePhase(); |
| + return *this; |
| + } |
| + next_index = spiral_iterator_.index(); |
| + break; |
| + case EVENTUALLY: |
| + ++spiral_iterator_; |
| + if (!spiral_iterator_) |
| + return *this; |
| + next_index = spiral_iterator_.index(); |
| + break; |
| + } |
| + current_tile_ = tiling_->TileAt(next_index.first, next_index.second); |
| + } |
| + return *this; |
| +} |
| + |
| } // namespace cc |