| Index: cc/resources/picture_layer_tiling.cc
|
| diff --git a/cc/resources/picture_layer_tiling.cc b/cc/resources/picture_layer_tiling.cc
|
| index 914cf54350dfe4c786e01c58aa5a2ce6233172b7..2d530f58b7cf1e139786784d255a809eff0d3da7 100644
|
| --- a/cc/resources/picture_layer_tiling.cc
|
| +++ b/cc/resources/picture_layer_tiling.cc
|
| @@ -65,8 +65,10 @@ PictureLayerTiling::PictureLayerTiling(float contents_scale,
|
| client_(client),
|
| tiling_data_(gfx::Size(), gfx::Rect(), true),
|
| last_impl_frame_time_in_seconds_(0.0),
|
| - eviction_tiles_cache_valid_(false),
|
| - eviction_cache_tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES) {
|
| + current_visible_rect_has_tiles_(false),
|
| + current_skewport_has_tiles_(false),
|
| + current_eventually_rect_has_tiles_(false),
|
| + current_soon_border_rect_has_tiles_(false) {
|
| gfx::Size content_bounds =
|
| gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale));
|
| gfx::Size tile_size = client_->CalculateTileSize(content_bounds);
|
| @@ -118,24 +120,18 @@ Tile* PictureLayerTiling::CreateTile(int i,
|
|
|
| // Create a new tile because our twin didn't have a valid one.
|
| scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect);
|
| - if (tile.get())
|
| + if (tile.get()) {
|
| + tile->set_tiling_index(i, j);
|
| tiles_[key] = tile;
|
| + }
|
| return tile.get();
|
| }
|
|
|
| -void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() {
|
| - const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
|
| - bool include_borders = true;
|
| - for (TilingData::Iterator iter(
|
| - &tiling_data_, live_tiles_rect_, include_borders);
|
| - iter;
|
| - ++iter) {
|
| - TileMapKey key = iter.index();
|
| - TileMap::iterator find = tiles_.find(key);
|
| - if (find != tiles_.end())
|
| - continue;
|
| - CreateTile(key.first, key.second, twin_tiling);
|
| - }
|
| +Tile* PictureLayerTiling::GetOrCreateTileAt(int i, int j) {
|
| + Tile* existing_tile = TileAt(i, j);
|
| + if (existing_tile)
|
| + return existing_tile;
|
| + return CreateTile(i, j, client_->GetTwinTiling(this));
|
| }
|
|
|
| void PictureLayerTiling::SetLayerBounds(const gfx::Size& layer_bounds) {
|
| @@ -169,17 +165,7 @@ void PictureLayerTiling::SetLayerBounds(const gfx::Size& layer_bounds) {
|
| Invalidate(layer_region);
|
| }
|
|
|
| -void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_region) {
|
| - DoInvalidate(layer_region, false /* recreate_tiles */);
|
| -}
|
| -
|
| void PictureLayerTiling::Invalidate(const Region& layer_region) {
|
| - DoInvalidate(layer_region, true /* recreate_tiles */);
|
| -}
|
| -
|
| -void PictureLayerTiling::DoInvalidate(const Region& layer_region,
|
| - bool recreate_tiles) {
|
| - std::vector<TileMapKey> new_tile_keys;
|
| gfx::Rect expanded_live_tiles_rect(
|
| tiling_data_.ExpandRectToTileBoundsWithBorders(live_tiles_rect_));
|
| for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) {
|
| @@ -201,16 +187,50 @@ void PictureLayerTiling::DoInvalidate(const Region& layer_region,
|
| if (find == tiles_.end())
|
| continue;
|
| tiles_.erase(find);
|
| - if (recreate_tiles)
|
| - new_tile_keys.push_back(key);
|
| }
|
| }
|
| +}
|
| +
|
| +void PictureLayerTiling::UpdateTileOcclusion(Tile* tile) {
|
| + if (!tile)
|
| + return;
|
| +
|
| + bool is_occluded = occlusion_set_.count(std::make_pair(
|
| + tile->tiling_i_index(), tile->tiling_j_index())) != 0;
|
| + WhichTree tree = client_->GetTree();
|
| + tile->set_is_occluded(tree, is_occluded);
|
| +}
|
| +
|
| +bool PictureLayerTiling::IsTileRequiredForActivation(Tile* tile) const {
|
| + if (resolution_ != HIGH_RESOLUTION)
|
| + return false;
|
| +
|
| + WhichTree tree = client_->GetTree();
|
| + if (tree != PENDING_TREE)
|
| + return false;
|
| +
|
| + if (tile->is_occluded(tree))
|
| + return false;
|
| +
|
| + if (client_->RequiresHighResToDraw())
|
| + return true;
|
| +
|
| + const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
|
| + if (twin_tiling) {
|
| + if (twin_tiling->layer_bounds() != layer_bounds())
|
| + return true;
|
| +
|
| + if (twin_tiling->current_visible_rect_in_content_space_ !=
|
| + current_visible_rect_in_content_space_) {
|
| + return true;
|
| + }
|
|
|
| - if (recreate_tiles) {
|
| - const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
|
| - for (size_t i = 0; i < new_tile_keys.size(); ++i)
|
| - CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling);
|
| + Tile* twin_tile =
|
| + twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index());
|
| + if (!twin_tile || twin_tile == tile)
|
| + return false;
|
| }
|
| + return true;
|
| }
|
|
|
| PictureLayerTiling::CoverageIterator::CoverageIterator()
|
| @@ -462,102 +482,101 @@ 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;
|
|
|
| + const gfx::Rect& tiling_rect = TilingRect();
|
| current_visible_rect_in_content_space_ = visible_rect_in_content_space;
|
| + current_visible_rect_has_tiles_ =
|
| + tiling_rect.Intersects(current_visible_rect_in_content_space_);
|
| current_skewport_ = skewport;
|
| + current_skewport_has_tiles_ = tiling_rect.Intersects(current_skewport_);
|
| current_eventually_rect_ = eventually_rect;
|
| - eviction_tiles_cache_valid_ = false;
|
| -
|
| - TilePriority now_priority(resolution_, TilePriority::NOW, 0);
|
| - float content_to_screen_scale =
|
| - 1.0f / (contents_scale_ * ideal_contents_scale);
|
| -
|
| - // Assign now priority to all visible tiles.
|
| - bool include_borders = true;
|
| - for (TilingData::Iterator iter(
|
| - &tiling_data_, visible_rect_in_content_space, include_borders);
|
| - iter;
|
| - ++iter) {
|
| - TileMap::iterator find = tiles_.find(iter.index());
|
| - if (find == tiles_.end())
|
| - continue;
|
| - Tile* tile = find->second.get();
|
| + current_eventually_rect_has_tiles_ =
|
| + tiling_rect.Intersects(current_eventually_rect_);
|
| + content_to_screen_scale_ = 1.0f / (contents_scale_ * ideal_contents_scale);
|
|
|
| - tile->SetPriority(tree, now_priority);
|
| + current_soon_border_rect_ = visible_rect_in_content_space;
|
| + float border = kSoonBorderDistanceInScreenPixels / content_to_screen_scale_;
|
| + current_soon_border_rect_.Inset(-border, -border, -border, -border);
|
| + current_soon_border_rect_has_tiles_ =
|
| + tiling_rect.Intersects(current_soon_border_rect_);
|
|
|
| - // Set whether tile is occluded or not.
|
| - bool is_occluded = false;
|
| - if (occlusion_tracker) {
|
| + // Compute occluded indecies.
|
| + occlusion_set_.clear();
|
| + if (occlusion_tracker) {
|
| + bool include_borders = true;
|
| + for (TilingData::Iterator iter(
|
| + &tiling_data_, visible_rect_in_content_space, include_borders);
|
| + iter;
|
| + ++iter) {
|
| + gfx::Rect paint_rect =
|
| + tiling_data_.TileBoundsWithBorder(iter.index_x(), iter.index_y());
|
| + gfx::Rect tile_rect = paint_rect;
|
| + tile_rect.set_size(tiling_data_.max_texture_size());
|
| gfx::Rect tile_query_rect = ScaleToEnclosingRect(
|
| - IntersectRects(tile->content_rect(), visible_rect_in_content_space),
|
| + IntersectRects(tile_rect, visible_rect_in_content_space),
|
| 1.0f / contents_scale_);
|
| - // TODO(vmpstr): Remove render_target and draw_transform from the
|
| - // parameters so they can be hidden from the tiling.
|
| - is_occluded = occlusion_tracker->Occluded(
|
| + bool is_occluded = occlusion_tracker->Occluded(
|
| render_target, tile_query_rect, draw_transform);
|
| + if (!is_occluded)
|
| + continue;
|
| +
|
| + occlusion_set_.insert(iter.index());
|
| }
|
| - tile->set_is_occluded(tree, is_occluded);
|
| }
|
| +}
|
|
|
| - // Assign soon priority to skewport tiles.
|
| - 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();
|
| +void PictureLayerTiling::SetTileAndTwinPriority(Tile* tile) const {
|
| + // First update the twin if required.
|
| + const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
|
| + if (twin_tiling)
|
| + twin_tiling->SetTilePriority(tile);
|
| + SetTilePriority(tile);
|
| +}
|
|
|
| - gfx::Rect tile_bounds =
|
| - tiling_data_.TileBounds(iter.index_x(), iter.index_y());
|
| +void PictureLayerTiling::SetTilePriority(Tile* tile) const {
|
| + WhichTree tree = client_->GetTree();
|
|
|
| - float distance_to_visible =
|
| - visible_rect_in_content_space.ManhattanInternalDistance(tile_bounds) *
|
| - content_to_screen_scale;
|
| + // If we're on the pending tree, start by clearing out the required for
|
| + // activation flag.
|
| + if (tree == PENDING_TREE)
|
| + tile->set_required_for_activation(false);
|
|
|
| - TilePriority priority(resolution_, TilePriority::SOON, distance_to_visible);
|
| - tile->SetPriority(tree, priority);
|
| + // If this tiling doesn't have the given tile, then set default priority.
|
| + if (TileAt(tile->tiling_i_index(), tile->tiling_j_index()) != tile) {
|
| + tile->SetPriority(tree, TilePriority());
|
| + return;
|
| }
|
|
|
| - // Assign eventually priority to interest rect tiles.
|
| - for (TilingData::DifferenceIterator iter(
|
| - &tiling_data_, eventually_rect, skewport);
|
| - 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_.TileBoundsWithBorder(
|
| + tile->tiling_i_index(), tile->tiling_j_index());
|
|
|
| - gfx::Rect tile_bounds =
|
| - tiling_data_.TileBounds(iter.index_x(), iter.index_y());
|
| + // If we're in the now bin, set the priority and return.
|
| + if (current_visible_rect_in_content_space_.Intersects(tile_bounds)) {
|
| + tile->SetPriority(tree, TilePriority(resolution_, TilePriority::NOW, 0));
|
|
|
| - float distance_to_visible =
|
| - visible_rect_in_content_space.ManhattanInternalDistance(tile_bounds) *
|
| - content_to_screen_scale;
|
| - TilePriority priority(
|
| - resolution_, TilePriority::EVENTUALLY, distance_to_visible);
|
| - tile->SetPriority(tree, priority);
|
| + // If necessary, mark this visible tile as required for activation.
|
| + tile->set_required_for_activation(IsTileRequiredForActivation(tile));
|
| + return;
|
| }
|
|
|
| - // Upgrade the priority on border tiles to be SOON.
|
| - current_soon_border_rect_ = visible_rect_in_content_space;
|
| - float border = kSoonBorderDistanceInScreenPixels / content_to_screen_scale;
|
| - current_soon_border_rect_.Inset(-border, -border, -border, -border);
|
| - for (TilingData::DifferenceIterator iter(
|
| - &tiling_data_, current_soon_border_rect_, skewport);
|
| - iter;
|
| - ++iter) {
|
| - TileMap::iterator find = tiles_.find(iter.index());
|
| - if (find == tiles_.end())
|
| - continue;
|
| - Tile* tile = find->second.get();
|
| -
|
| - TilePriority priority(resolution_,
|
| - TilePriority::SOON,
|
| - tile->priority(tree).distance_to_visible);
|
| - tile->SetPriority(tree, priority);
|
| + // For non-now bin, we'll need to know distance to visible.
|
| + float distance_to_visible =
|
| + current_visible_rect_in_content_space_.ManhattanInternalDistance(
|
| + tile_bounds) *
|
| + content_to_screen_scale_;
|
| +
|
| + // Soon border and skewport tiles get SOON bin, otherwise they get EVENTUALLY
|
| + // bin.
|
| + if (current_soon_border_rect_.Intersects(tile_bounds) ||
|
| + current_skewport_.Intersects(tile_bounds)) {
|
| + tile->SetPriority(
|
| + tree,
|
| + TilePriority(resolution_, TilePriority::SOON, distance_to_visible));
|
| + return;
|
| }
|
| +
|
| + tile->SetPriority(
|
| + tree,
|
| + TilePriority(resolution_, TilePriority::EVENTUALLY, distance_to_visible));
|
| }
|
|
|
| void PictureLayerTiling::SetLiveTilesRect(
|
| @@ -581,36 +600,13 @@ void PictureLayerTiling::SetLiveTilesRect(
|
| tiles_.erase(found);
|
| }
|
|
|
| - const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this);
|
| -
|
| - // Iterate to allocate new tiles for all regions with newly exposed area.
|
| - for (TilingData::DifferenceIterator iter(&tiling_data_,
|
| - new_live_tiles_rect,
|
| - live_tiles_rect_);
|
| - iter;
|
| - ++iter) {
|
| - TileMapKey key(iter.index());
|
| - CreateTile(key.first, key.second, twin_tiling);
|
| - }
|
| -
|
| live_tiles_rect_ = new_live_tiles_rect;
|
| }
|
|
|
| -void PictureLayerTiling::DidBecomeRecycled() {
|
| - // DidBecomeActive below will set the active priority for tiles that are
|
| - // still in the tree. Calling this first on an active tiling that is becoming
|
| - // recycled takes care of tiles that are no longer in the active tree (eg.
|
| - // due to a pending invalidation).
|
| - for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
|
| - it->second->SetPriority(ACTIVE_TREE, TilePriority());
|
| - }
|
| -}
|
| -
|
| void PictureLayerTiling::DidBecomeActive() {
|
| PicturePileImpl* active_pile = client_->GetPile();
|
| for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
|
| - it->second->SetPriority(ACTIVE_TREE, it->second->priority(PENDING_TREE));
|
| - it->second->SetPriority(PENDING_TREE, TilePriority());
|
| + it->second->set_required_for_activation(false);
|
|
|
| // Tile holds a ref onto a picture pile. If the tile never gets invalidated
|
| // and recreated, then that picture pile ref could exist indefinitely. To
|
| @@ -797,23 +793,18 @@ gfx::Rect PictureLayerTiling::ExpandRectEquallyToAreaBoundedBy(
|
|
|
| void PictureLayerTiling::UpdateEvictionCacheIfNeeded(
|
| TreePriority tree_priority) {
|
| - if (eviction_tiles_cache_valid_ &&
|
| - eviction_cache_tree_priority_ == tree_priority)
|
| - return;
|
|
|
| eviction_tiles_cache_.clear();
|
| eviction_tiles_cache_.reserve(tiles_.size());
|
| for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
|
| - // TODO(vmpstr): This should update the priority if UpdateTilePriorities
|
| - // changes not to do this.
|
| + UpdateTileOcclusion(it->second);
|
| + SetTileAndTwinPriority(it->second);
|
| eviction_tiles_cache_.push_back(it->second);
|
| }
|
|
|
| std::sort(eviction_tiles_cache_.begin(),
|
| eviction_tiles_cache_.end(),
|
| TileEvictionOrder(tree_priority));
|
| - eviction_tiles_cache_valid_ = true;
|
| - eviction_cache_tree_priority_ = tree_priority;
|
| }
|
|
|
| PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator()
|
| @@ -824,50 +815,81 @@ PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator(
|
| WhichTree tree)
|
| : tiling_(tiling),
|
| type_(TilePriority::NOW),
|
| - visible_rect_in_content_space_(
|
| - tiling_->current_visible_rect_in_content_space_),
|
| - skewport_in_content_space_(tiling_->current_skewport_),
|
| - eventually_rect_in_content_space_(tiling_->current_eventually_rect_),
|
| - soon_border_rect_in_content_space_(tiling_->current_soon_border_rect_),
|
| tree_(tree),
|
| current_tile_(NULL),
|
| - visible_iterator_(&tiling->tiling_data_,
|
| - visible_rect_in_content_space_,
|
| - true /* include_borders */),
|
| - spiral_iterator_(&tiling->tiling_data_,
|
| - skewport_in_content_space_,
|
| - visible_rect_in_content_space_,
|
| - visible_rect_in_content_space_),
|
| skewport_processed_(false) {
|
| + if (tiling_->current_visible_rect_has_tiles_) {
|
| + visible_iterator_ =
|
| + TilingData::Iterator(&tiling_->tiling_data_,
|
| + tiling_->current_visible_rect_in_content_space_,
|
| + true /* include_borders */);
|
| + }
|
| +
|
| if (!visible_iterator_) {
|
| AdvancePhase();
|
| return;
|
| }
|
|
|
| - current_tile_ =
|
| - tiling_->TileAt(visible_iterator_.index_x(), visible_iterator_.index_y());
|
| - if (!current_tile_ || !TileNeedsRaster(current_tile_))
|
| + current_tile_ = tiling_->GetOrCreateTileAt(visible_iterator_.index_x(),
|
| + visible_iterator_.index_y());
|
| + if (!current_tile_) {
|
| ++(*this);
|
| + } else {
|
| + tiling_->UpdateTileOcclusion(current_tile_);
|
| + if (!TileNeedsRaster(current_tile_))
|
| + ++(*this);
|
| + else
|
| + tiling_->SetTileAndTwinPriority(current_tile_);
|
| + }
|
| }
|
|
|
| PictureLayerTiling::TilingRasterTileIterator::~TilingRasterTileIterator() {}
|
|
|
| void PictureLayerTiling::TilingRasterTileIterator::AdvancePhase() {
|
| DCHECK_LT(type_, TilePriority::EVENTUALLY);
|
| + DCHECK(!spiral_iterator_);
|
|
|
| do {
|
| - type_ = static_cast<TilePriority::PriorityBin>(type_ + 1);
|
| - if (type_ == TilePriority::EVENTUALLY) {
|
| + if (type_ == TilePriority::SOON && !skewport_processed_)
|
| + skewport_processed_ = true;
|
| + else
|
| + type_ = static_cast<TilePriority::PriorityBin>(type_ + 1);
|
| +
|
| + if (type_ == TilePriority::SOON && !skewport_processed_) {
|
| + if (!tiling_->current_soon_border_rect_has_tiles_)
|
| + continue;
|
| +
|
| + spiral_iterator_ = TilingData::SpiralDifferenceIterator(
|
| + &tiling_->tiling_data_,
|
| + tiling_->current_skewport_,
|
| + tiling_->current_visible_rect_in_content_space_,
|
| + tiling_->current_visible_rect_in_content_space_);
|
| + } else if (type_ == TilePriority::SOON && skewport_processed_) {
|
| + if (!tiling_->current_skewport_has_tiles_)
|
| + continue;
|
| +
|
| spiral_iterator_ = TilingData::SpiralDifferenceIterator(
|
| &tiling_->tiling_data_,
|
| - eventually_rect_in_content_space_,
|
| - skewport_in_content_space_,
|
| - visible_rect_in_content_space_);
|
| + tiling_->current_soon_border_rect_,
|
| + tiling_->current_skewport_,
|
| + tiling_->current_visible_rect_in_content_space_);
|
| + } else if (type_ == TilePriority::EVENTUALLY) {
|
| + if (!tiling_->current_eventually_rect_has_tiles_) {
|
| + current_tile_ = NULL;
|
| + break;
|
| + }
|
| +
|
| + spiral_iterator_ = TilingData::SpiralDifferenceIterator(
|
| + &tiling_->tiling_data_,
|
| + tiling_->current_eventually_rect_,
|
| + tiling_->current_skewport_,
|
| + tiling_->current_soon_border_rect_);
|
| }
|
|
|
| while (spiral_iterator_) {
|
| - current_tile_ = tiling_->TileAt(spiral_iterator_.index_x(),
|
| - spiral_iterator_.index_y());
|
| + current_tile_ = tiling_->GetOrCreateTileAt(spiral_iterator_.index_x(),
|
| + spiral_iterator_.index_y());
|
| + tiling_->UpdateTileOcclusion(current_tile_);
|
| if (current_tile_ && TileNeedsRaster(current_tile_))
|
| break;
|
| ++spiral_iterator_;
|
| @@ -878,6 +900,9 @@ void PictureLayerTiling::TilingRasterTileIterator::AdvancePhase() {
|
| break;
|
| }
|
| } while (!spiral_iterator_);
|
| +
|
| + if (current_tile_)
|
| + tiling_->SetTileAndTwinPriority(current_tile_);
|
| }
|
|
|
| PictureLayerTiling::TilingRasterTileIterator&
|
| @@ -898,20 +923,8 @@ operator++() {
|
| case TilePriority::SOON:
|
| ++spiral_iterator_;
|
| if (!spiral_iterator_) {
|
| - if (skewport_processed_) {
|
| - AdvancePhase();
|
| - return *this;
|
| - }
|
| - skewport_processed_ = true;
|
| - spiral_iterator_ = TilingData::SpiralDifferenceIterator(
|
| - &tiling_->tiling_data_,
|
| - soon_border_rect_in_content_space_,
|
| - skewport_in_content_space_,
|
| - visible_rect_in_content_space_);
|
| - if (!spiral_iterator_) {
|
| - AdvancePhase();
|
| - return *this;
|
| - }
|
| + AdvancePhase();
|
| + return *this;
|
| }
|
| next_index = spiral_iterator_.index();
|
| break;
|
| @@ -924,8 +937,13 @@ operator++() {
|
| next_index = spiral_iterator_.index();
|
| break;
|
| }
|
| - current_tile_ = tiling_->TileAt(next_index.first, next_index.second);
|
| + current_tile_ =
|
| + tiling_->GetOrCreateTileAt(next_index.first, next_index.second);
|
| + tiling_->UpdateTileOcclusion(current_tile_);
|
| }
|
| +
|
| + if (current_tile_)
|
| + tiling_->SetTileAndTwinPriority(current_tile_);
|
| return *this;
|
| }
|
|
|
|
|