| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 TileMapKey key = iter.index(); | 160 TileMapKey key = iter.index(); |
| 161 TileMap::iterator find = tiles_.find(key); | 161 TileMap::iterator find = tiles_.find(key); |
| 162 if (find != tiles_.end()) | 162 if (find != tiles_.end()) |
| 163 continue; | 163 continue; |
| 164 CreateTile(key.first, key.second, twin_tiling); | 164 CreateTile(key.first, key.second, twin_tiling); |
| 165 } | 165 } |
| 166 | 166 |
| 167 VerifyLiveTilesRect(); | 167 VerifyLiveTilesRect(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void PictureLayerTiling::UpdateTilesToCurrentPile( | 170 void PictureLayerTiling::UpdateTilesToCurrentRasterSource( |
| 171 const Region& layer_invalidation, | 171 const Region& layer_invalidation, |
| 172 const gfx::Size& new_layer_bounds) { | 172 const gfx::Size& new_layer_bounds) { |
| 173 DCHECK(!new_layer_bounds.IsEmpty()); | 173 DCHECK(!new_layer_bounds.IsEmpty()); |
| 174 | 174 |
| 175 gfx::Size tile_size = tiling_data_.max_texture_size(); | 175 gfx::Size content_bounds = |
| 176 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); |
| 177 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
| 176 | 178 |
| 177 if (new_layer_bounds != layer_bounds_) { | 179 if (new_layer_bounds != layer_bounds_) { |
| 178 gfx::Size content_bounds = | |
| 179 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); | |
| 180 | |
| 181 tile_size = client_->CalculateTileSize(content_bounds); | |
| 182 if (tile_size.IsEmpty()) { | 180 if (tile_size.IsEmpty()) { |
| 183 layer_bounds_ = gfx::Size(); | 181 layer_bounds_ = gfx::Size(); |
| 184 content_bounds = gfx::Size(); | 182 content_bounds = gfx::Size(); |
| 185 } else { | 183 } else { |
| 186 layer_bounds_ = new_layer_bounds; | 184 layer_bounds_ = new_layer_bounds; |
| 187 } | 185 } |
| 188 | 186 |
| 189 // The SetLiveTilesRect() method would drop tiles outside the new bounds, | 187 // The SetLiveTilesRect() method would drop tiles outside the new bounds, |
| 190 // but may do so incorrectly if resizing the tiling causes the number of | 188 // but may do so incorrectly if resizing the tiling causes the number of |
| 191 // tiles in the tiling_data_ to change. | 189 // tiles in the tiling_data_ to change. |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 return false; | 690 return false; |
| 693 | 691 |
| 694 if (contents_scale_ != 1.f) { | 692 if (contents_scale_ != 1.f) { |
| 695 tile_query_rect = | 693 tile_query_rect = |
| 696 gfx::ScaleToEnclosingRect(tile_query_rect, 1.0f / contents_scale_); | 694 gfx::ScaleToEnclosingRect(tile_query_rect, 1.0f / contents_scale_); |
| 697 } | 695 } |
| 698 | 696 |
| 699 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); | 697 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); |
| 700 } | 698 } |
| 701 | 699 |
| 702 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { | 700 bool PictureLayerTiling::IsTileRequiredForActivationIfVisible( |
| 701 const Tile* tile) const { |
| 703 DCHECK_EQ(PENDING_TREE, client_->GetTree()); | 702 DCHECK_EQ(PENDING_TREE, client_->GetTree()); |
| 704 | 703 |
| 705 // Note that although this function will determine whether tile is required | 704 // This function assumes that the tile is visible (i.e. in the viewport). The |
| 706 // for activation assuming that it is in visible (ie in the viewport). That is | 705 // caller needs to make sure that this condition is met to ensure we don't |
| 707 // to say, even if the tile is outside of the viewport, it will be treated as | 706 // block activation on tiles outside of the viewport. |
| 708 // if it was inside (there are no explicit checks for this). Hence, this | |
| 709 // function is only called for visible tiles to ensure we don't block | |
| 710 // activation on tiles outside of the viewport. | |
| 711 | 707 |
| 712 // If we are not allowed to mark tiles as required for activation, then don't | 708 // If we are not allowed to mark tiles as required for activation, then don't |
| 713 // do it. | 709 // do it. |
| 714 if (!can_require_tiles_for_activation_) | 710 if (!can_require_tiles_for_activation_) |
| 715 return false; | 711 return false; |
| 716 | 712 |
| 717 if (resolution_ != HIGH_RESOLUTION) | 713 if (resolution_ != HIGH_RESOLUTION) |
| 718 return false; | 714 return false; |
| 719 | 715 |
| 720 if (IsTileOccluded(tile)) | 716 if (IsTileOccluded(tile)) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 737 Tile* twin_tile = | 733 Tile* twin_tile = |
| 738 twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index()); | 734 twin_tiling->TileAt(tile->tiling_i_index(), tile->tiling_j_index()); |
| 739 // If twin tile is missing, it might not have a recording, so we don't need | 735 // If twin tile is missing, it might not have a recording, so we don't need |
| 740 // this tile to be required for activation. | 736 // this tile to be required for activation. |
| 741 if (!twin_tile) | 737 if (!twin_tile) |
| 742 return false; | 738 return false; |
| 743 | 739 |
| 744 return true; | 740 return true; |
| 745 } | 741 } |
| 746 | 742 |
| 743 bool PictureLayerTiling::IsTileRequiredForDrawIfVisible( |
| 744 const Tile* tile) const { |
| 745 DCHECK_EQ(ACTIVE_TREE, client_->GetTree()); |
| 746 |
| 747 // This function assumes that the tile is visible (i.e. in the viewport). |
| 748 |
| 749 if (resolution_ != HIGH_RESOLUTION) |
| 750 return false; |
| 751 |
| 752 if (IsTileOccluded(tile)) |
| 753 return false; |
| 754 |
| 755 return true; |
| 756 } |
| 757 |
| 747 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { | 758 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { |
| 748 UpdateTilePriority(tile); | 759 UpdateTilePriority(tile); |
| 749 | 760 |
| 750 const PictureLayerTiling* twin_tiling = | 761 const PictureLayerTiling* twin_tiling = |
| 751 client_->GetPendingOrActiveTwinTiling(this); | 762 client_->GetPendingOrActiveTwinTiling(this); |
| 752 if (!tile->is_shared() || !twin_tiling) { | 763 if (!tile->is_shared() || !twin_tiling) { |
| 753 WhichTree tree = client_->GetTree(); | 764 WhichTree tree = client_->GetTree(); |
| 754 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; | 765 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; |
| 755 tile->SetPriority(twin_tree, TilePriority()); | 766 tile->SetPriority(twin_tree, TilePriority()); |
| 756 tile->set_is_occluded(twin_tree, false); | 767 tile->set_is_occluded(twin_tree, false); |
| 757 if (twin_tree == PENDING_TREE) | 768 if (twin_tree == PENDING_TREE) |
| 758 tile->set_required_for_activation(false); | 769 tile->set_required_for_activation(false); |
| 770 else |
| 771 tile->set_required_for_draw(false); |
| 759 return; | 772 return; |
| 760 } | 773 } |
| 761 | 774 |
| 762 twin_tiling->UpdateTilePriority(tile); | 775 twin_tiling->UpdateTilePriority(tile); |
| 763 } | 776 } |
| 764 | 777 |
| 765 void PictureLayerTiling::UpdateTilePriority(Tile* tile) const { | 778 void PictureLayerTiling::UpdateTilePriority(Tile* tile) const { |
| 766 // TODO(vmpstr): This code should return the priority instead of setting it on | 779 // TODO(vmpstr): This code should return the priority instead of setting it on |
| 767 // the tile. This should be a part of the change to move tile priority from | 780 // the tile. This should be a part of the change to move tile priority from |
| 768 // tiles into iterators. | 781 // tiles into iterators. |
| 782 TilePriority::PriorityBin max_tile_priority_bin = |
| 783 client_->GetMaxTilePriorityBin(); |
| 769 WhichTree tree = client_->GetTree(); | 784 WhichTree tree = client_->GetTree(); |
| 770 | 785 |
| 771 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); | 786 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); |
| 772 gfx::Rect tile_bounds = | 787 gfx::Rect tile_bounds = |
| 773 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); | 788 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
| 774 | 789 |
| 775 if (current_visible_rect_.Intersects(tile_bounds)) { | 790 if (max_tile_priority_bin <= TilePriority::NOW && |
| 791 current_visible_rect_.Intersects(tile_bounds)) { |
| 776 tile->SetPriority(tree, TilePriority(resolution_, TilePriority::NOW, 0)); | 792 tile->SetPriority(tree, TilePriority(resolution_, TilePriority::NOW, 0)); |
| 777 if (tree == PENDING_TREE) | 793 if (tree == PENDING_TREE) { |
| 778 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); | 794 tile->set_required_for_activation( |
| 795 IsTileRequiredForActivationIfVisible(tile)); |
| 796 } else { |
| 797 tile->set_required_for_draw(IsTileRequiredForDrawIfVisible(tile)); |
| 798 } |
| 779 tile->set_is_occluded(tree, IsTileOccluded(tile)); | 799 tile->set_is_occluded(tree, IsTileOccluded(tile)); |
| 780 return; | 800 return; |
| 781 } | 801 } |
| 782 | 802 |
| 783 if (tree == PENDING_TREE) | 803 if (tree == PENDING_TREE) |
| 784 tile->set_required_for_activation(false); | 804 tile->set_required_for_activation(false); |
| 805 else |
| 806 tile->set_required_for_draw(false); |
| 785 tile->set_is_occluded(tree, false); | 807 tile->set_is_occluded(tree, false); |
| 786 | 808 |
| 787 DCHECK_GT(content_to_screen_scale_, 0.f); | 809 DCHECK_GT(content_to_screen_scale_, 0.f); |
| 788 float distance_to_visible = | 810 float distance_to_visible = |
| 789 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * | 811 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * |
| 790 content_to_screen_scale_; | 812 content_to_screen_scale_; |
| 791 | 813 |
| 792 if (current_soon_border_rect_.Intersects(tile_bounds) || | 814 if (max_tile_priority_bin <= TilePriority::SOON && |
| 793 current_skewport_rect_.Intersects(tile_bounds)) { | 815 (current_soon_border_rect_.Intersects(tile_bounds) || |
| 816 current_skewport_rect_.Intersects(tile_bounds))) { |
| 794 tile->SetPriority( | 817 tile->SetPriority( |
| 795 tree, | 818 tree, |
| 796 TilePriority(resolution_, TilePriority::SOON, distance_to_visible)); | 819 TilePriority(resolution_, TilePriority::SOON, distance_to_visible)); |
| 797 return; | 820 return; |
| 798 } | 821 } |
| 799 | 822 |
| 800 tile->SetPriority( | 823 tile->SetPriority( |
| 801 tree, | 824 tree, |
| 802 TilePriority(resolution_, TilePriority::EVENTUALLY, distance_to_visible)); | 825 TilePriority(resolution_, TilePriority::EVENTUALLY, distance_to_visible)); |
| 803 } | 826 } |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 DCHECK(*this); | 1257 DCHECK(*this); |
| 1235 do { | 1258 do { |
| 1236 ++current_eviction_tiles_index_; | 1259 ++current_eviction_tiles_index_; |
| 1237 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && | 1260 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && |
| 1238 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); | 1261 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); |
| 1239 | 1262 |
| 1240 return *this; | 1263 return *this; |
| 1241 } | 1264 } |
| 1242 | 1265 |
| 1243 } // namespace cc | 1266 } // namespace cc |
| OLD | NEW |