| 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/tiles/picture_layer_tiling.h" | 5 #include "cc/tiles/picture_layer_tiling.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 return true; | 715 return true; |
| 716 } | 716 } |
| 717 return pending_twin->IsTileOccludedOnCurrentTree(tile); | 717 return pending_twin->IsTileOccludedOnCurrentTree(tile); |
| 718 } | 718 } |
| 719 return true; | 719 return true; |
| 720 } | 720 } |
| 721 | 721 |
| 722 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const { | 722 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const { |
| 723 if (!current_occlusion_in_layer_space_.HasOcclusion()) | 723 if (!current_occlusion_in_layer_space_.HasOcclusion()) |
| 724 return false; | 724 return false; |
| 725 gfx::Rect tile_bounds = |
| 726 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
| 725 gfx::Rect tile_query_rect = | 727 gfx::Rect tile_query_rect = |
| 726 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); | 728 gfx::IntersectRects(tile_bounds, current_visible_rect_); |
| 727 // Explicitly check if the tile is outside the viewport. If so, we need to | 729 // Explicitly check if the tile is outside the viewport. If so, we need to |
| 728 // return false, since occlusion for this tile is unknown. | 730 // return false, since occlusion for this tile is unknown. |
| 729 if (tile_query_rect.IsEmpty()) | 731 if (tile_query_rect.IsEmpty()) |
| 730 return false; | 732 return false; |
| 731 | 733 |
| 732 if (contents_scale_ != 1.f) { | 734 if (contents_scale_ != 1.f) { |
| 733 tile_query_rect = | 735 tile_query_rect = |
| 734 gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / contents_scale_); | 736 gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / contents_scale_); |
| 735 } | 737 } |
| 736 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); | 738 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); |
| 737 } | 739 } |
| 738 | 740 |
| 739 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { | 741 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { |
| 740 if (tree_ == PENDING_TREE) { | 742 if (tree_ == PENDING_TREE) { |
| 741 if (!can_require_tiles_for_activation_) | 743 if (!can_require_tiles_for_activation_) |
| 742 return false; | 744 return false; |
| 743 | 745 |
| 744 if (resolution_ != HIGH_RESOLUTION) | 746 if (resolution_ != HIGH_RESOLUTION) |
| 745 return false; | 747 return false; |
| 746 | 748 |
| 747 if (IsTileOccluded(tile)) | 749 if (IsTileOccluded(tile)) |
| 748 return false; | 750 return false; |
| 749 | 751 |
| 750 bool tile_is_visible = | 752 // We may be checking the active tree tile here (since this function is also |
| 751 tile->content_rect().Intersects(current_visible_rect_); | 753 // called for active trees below, ensure that this is at all a valid tile on |
| 754 // the pending tree. |
| 755 if (tile->tiling_i_index() >= tiling_data_.num_tiles_x() || |
| 756 tile->tiling_j_index() >= tiling_data_.num_tiles_y()) { |
| 757 return false; |
| 758 } |
| 759 |
| 760 gfx::Rect tile_bounds = |
| 761 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
| 762 bool tile_is_visible = tile_bounds.Intersects(current_visible_rect_); |
| 752 if (!tile_is_visible) | 763 if (!tile_is_visible) |
| 753 return false; | 764 return false; |
| 754 | 765 |
| 755 if (client_->RequiresHighResToDraw()) | 766 if (client_->RequiresHighResToDraw()) |
| 756 return true; | 767 return true; |
| 757 | 768 |
| 758 const PictureLayerTiling* active_twin = | 769 const PictureLayerTiling* active_twin = |
| 759 client_->GetPendingOrActiveTwinTiling(this); | 770 client_->GetPendingOrActiveTwinTiling(this); |
| 760 if (!active_twin || !TilingMatchesTileIndices(active_twin)) | 771 if (!active_twin || !TilingMatchesTileIndices(active_twin)) |
| 761 return true; | 772 return true; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 786 return pending_twin->IsTileRequiredForActivation(tile); | 797 return pending_twin->IsTileRequiredForActivation(tile); |
| 787 } | 798 } |
| 788 | 799 |
| 789 bool PictureLayerTiling::IsTileRequiredForDraw(const Tile* tile) const { | 800 bool PictureLayerTiling::IsTileRequiredForDraw(const Tile* tile) const { |
| 790 if (tree_ == PENDING_TREE) | 801 if (tree_ == PENDING_TREE) |
| 791 return false; | 802 return false; |
| 792 | 803 |
| 793 if (resolution_ != HIGH_RESOLUTION) | 804 if (resolution_ != HIGH_RESOLUTION) |
| 794 return false; | 805 return false; |
| 795 | 806 |
| 796 bool tile_is_visible = current_visible_rect_.Intersects(tile->content_rect()); | 807 gfx::Rect tile_bounds = |
| 808 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
| 809 bool tile_is_visible = current_visible_rect_.Intersects(tile_bounds); |
| 797 if (!tile_is_visible) | 810 if (!tile_is_visible) |
| 798 return false; | 811 return false; |
| 799 | 812 |
| 800 if (IsTileOccludedOnCurrentTree(tile)) | 813 if (IsTileOccludedOnCurrentTree(tile)) |
| 801 return false; | 814 return false; |
| 802 return true; | 815 return true; |
| 803 } | 816 } |
| 804 | 817 |
| 805 void PictureLayerTiling::UpdateRequiredStatesOnTile(Tile* tile) const { | 818 void PictureLayerTiling::UpdateRequiredStatesOnTile(Tile* tile) const { |
| 806 DCHECK(tile); | |
| 807 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); | 819 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); |
| 808 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); | 820 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); |
| 809 } | 821 } |
| 810 | 822 |
| 811 PrioritizedTile PictureLayerTiling::MakePrioritizedTile( | 823 PrioritizedTile PictureLayerTiling::MakePrioritizedTile( |
| 812 Tile* tile, | 824 Tile* tile, |
| 813 PriorityRectType priority_rect_type) const { | 825 PriorityRectType priority_rect_type) const { |
| 814 DCHECK(tile); | 826 DCHECK(tile); |
| 815 DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect())) | 827 DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect())) |
| 816 << "Tile layer rect: " << tile->enclosing_layer_rect().ToString(); | 828 << "Tile layer rect: " << tile->enclosing_layer_rect().ToString(); |
| 817 | 829 |
| 830 UpdateRequiredStatesOnTile(tile); |
| 818 const auto& tile_priority = ComputePriorityForTile(tile, priority_rect_type); | 831 const auto& tile_priority = ComputePriorityForTile(tile, priority_rect_type); |
| 832 DCHECK((!tile->required_for_activation() && !tile->required_for_draw()) || |
| 833 tile_priority.priority_bin == TilePriority::NOW || |
| 834 !client_->HasValidTilePriorities()); |
| 835 |
| 819 // Note that TileManager will consider this flag but may rasterize the tile | 836 // Note that TileManager will consider this flag but may rasterize the tile |
| 820 // anyway (if tile is required for activation for example). We should process | 837 // anyway (if tile is required for activation for example). We should process |
| 821 // the tile for images only if it's further than half of the skewport extent. | 838 // the tile for images only if it's further than half of the skewport extent. |
| 822 bool process_for_images_only = | 839 bool process_for_images_only = |
| 823 tile_priority.distance_to_visible > min_preraster_distance_ && | 840 tile_priority.distance_to_visible > min_preraster_distance_ && |
| 824 (tile_priority.distance_to_visible > max_preraster_distance_ || | 841 (tile_priority.distance_to_visible > max_preraster_distance_ || |
| 825 tile_priority.distance_to_visible > | 842 tile_priority.distance_to_visible > |
| 826 0.5f * max_skewport_extent_in_screen_space_); | 843 0.5f * max_skewport_extent_in_screen_space_); |
| 827 return PrioritizedTile(tile, this, tile_priority, IsTileOccluded(tile), | 844 return PrioritizedTile(tile, this, tile_priority, IsTileOccluded(tile), |
| 828 process_for_images_only); | 845 process_for_images_only); |
| 829 } | 846 } |
| 830 | 847 |
| 831 std::map<const Tile*, PrioritizedTile> | 848 std::map<const Tile*, PrioritizedTile> |
| 832 PictureLayerTiling::UpdateAndGetAllPrioritizedTilesForTesting() const { | 849 PictureLayerTiling::UpdateAndGetAllPrioritizedTilesForTesting() const { |
| 833 std::map<const Tile*, PrioritizedTile> result; | 850 std::map<const Tile*, PrioritizedTile> result; |
| 834 for (const auto& key_tile_pair : tiles_) { | 851 for (const auto& key_tile_pair : tiles_) { |
| 835 Tile* tile = key_tile_pair.second.get(); | 852 Tile* tile = key_tile_pair.second.get(); |
| 836 UpdateRequiredStatesOnTile(tile); | |
| 837 PrioritizedTile prioritized_tile = | 853 PrioritizedTile prioritized_tile = |
| 838 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile)); | 854 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile)); |
| 839 result.insert(std::make_pair(prioritized_tile.tile(), prioritized_tile)); | 855 result.insert(std::make_pair(prioritized_tile.tile(), prioritized_tile)); |
| 840 } | 856 } |
| 841 return result; | 857 return result; |
| 842 } | 858 } |
| 843 | 859 |
| 844 TilePriority PictureLayerTiling::ComputePriorityForTile( | 860 TilePriority PictureLayerTiling::ComputePriorityForTile( |
| 845 const Tile* tile, | 861 const Tile* tile, |
| 846 PriorityRectType priority_rect_type) const { | 862 PriorityRectType priority_rect_type) const { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 938 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { |
| 923 size_t amount = 0; | 939 size_t amount = 0; |
| 924 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 940 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 925 const Tile* tile = it->second.get(); | 941 const Tile* tile = it->second.get(); |
| 926 amount += tile->GPUMemoryUsageInBytes(); | 942 amount += tile->GPUMemoryUsageInBytes(); |
| 927 } | 943 } |
| 928 return amount; | 944 return amount; |
| 929 } | 945 } |
| 930 | 946 |
| 931 } // namespace cc | 947 } // namespace cc |
| OLD | NEW |