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 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 return false; | 798 return false; |
799 return true; | 799 return true; |
800 } | 800 } |
801 | 801 |
802 void PictureLayerTiling::UpdateRequiredStatesOnTile(Tile* tile) const { | 802 void PictureLayerTiling::UpdateRequiredStatesOnTile(Tile* tile) const { |
803 DCHECK(tile); | 803 DCHECK(tile); |
804 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); | 804 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); |
805 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); | 805 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); |
806 } | 806 } |
807 | 807 |
808 PrioritizedTile PictureLayerTiling::MakePrioritizedTile(Tile* tile) const { | 808 PrioritizedTile PictureLayerTiling::MakePrioritizedTile( |
| 809 Tile* tile, |
| 810 PriorityRectType priority_rect_type) const { |
809 DCHECK(tile); | 811 DCHECK(tile); |
810 DCHECK( | 812 DCHECK( |
811 raster_source()->CoversRect(tile->content_rect(), tile->contents_scale())) | 813 raster_source()->CoversRect(tile->content_rect(), tile->contents_scale())) |
812 << "Recording rect: " | 814 << "Recording rect: " |
813 << gfx::ScaleToEnclosingRect(tile->content_rect(), | 815 << gfx::ScaleToEnclosingRect(tile->content_rect(), |
814 1.f / tile->contents_scale()).ToString(); | 816 1.f / tile->contents_scale()).ToString(); |
815 | 817 |
816 return PrioritizedTile(tile, raster_source(), ComputePriorityForTile(tile), | 818 return PrioritizedTile(tile, raster_source(), |
| 819 ComputePriorityForTile(tile, priority_rect_type), |
817 IsTileOccluded(tile)); | 820 IsTileOccluded(tile)); |
818 } | 821 } |
819 | 822 |
820 std::map<const Tile*, PrioritizedTile> | 823 std::map<const Tile*, PrioritizedTile> |
821 PictureLayerTiling::UpdateAndGetAllPrioritizedTilesForTesting() const { | 824 PictureLayerTiling::UpdateAndGetAllPrioritizedTilesForTesting() const { |
822 std::map<const Tile*, PrioritizedTile> result; | 825 std::map<const Tile*, PrioritizedTile> result; |
823 for (const auto& key_tile_pair : tiles_) { | 826 for (const auto& key_tile_pair : tiles_) { |
824 UpdateRequiredStatesOnTile(key_tile_pair.second); | 827 Tile* tile = key_tile_pair.second; |
| 828 UpdateRequiredStatesOnTile(tile); |
825 PrioritizedTile prioritized_tile = | 829 PrioritizedTile prioritized_tile = |
826 MakePrioritizedTile(key_tile_pair.second); | 830 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile)); |
827 result.insert(std::make_pair(prioritized_tile.tile(), prioritized_tile)); | 831 result.insert(std::make_pair(prioritized_tile.tile(), prioritized_tile)); |
828 } | 832 } |
829 return result; | 833 return result; |
830 } | 834 } |
831 | 835 |
832 TilePriority PictureLayerTiling::ComputePriorityForTile( | 836 TilePriority PictureLayerTiling::ComputePriorityForTile( |
833 const Tile* tile) const { | 837 const Tile* tile, |
| 838 PriorityRectType priority_rect_type) const { |
834 // TODO(vmpstr): See if this can be moved to iterators. | 839 // TODO(vmpstr): See if this can be moved to iterators. |
835 TilePriority::PriorityBin max_tile_priority_bin = | 840 TilePriority::PriorityBin max_tile_priority_bin = |
836 client_->GetMaxTilePriorityBin(); | 841 client_->GetMaxTilePriorityBin(); |
837 | 842 |
| 843 DCHECK_EQ(ComputePriorityRectTypeForTile(tile), priority_rect_type); |
838 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); | 844 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); |
| 845 |
| 846 TilePriority::PriorityBin priority_bin = max_tile_priority_bin; |
| 847 |
| 848 switch (priority_rect_type) { |
| 849 case VISIBLE_RECT: |
| 850 return TilePriority(resolution_, priority_bin, 0); |
| 851 case PENDING_VISIBLE_RECT: |
| 852 if (max_tile_priority_bin <= TilePriority::SOON) |
| 853 return TilePriority(resolution_, TilePriority::SOON, 0); |
| 854 priority_bin = TilePriority::EVENTUALLY; |
| 855 break; |
| 856 case SKEWPORT_RECT: |
| 857 case SOON_BORDER_RECT: |
| 858 if (max_tile_priority_bin <= TilePriority::SOON) |
| 859 priority_bin = TilePriority::SOON; |
| 860 break; |
| 861 case EVENTUALLY_RECT: |
| 862 priority_bin = TilePriority::EVENTUALLY; |
| 863 break; |
| 864 } |
| 865 |
839 gfx::Rect tile_bounds = | 866 gfx::Rect tile_bounds = |
840 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); | 867 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
841 | |
842 if (max_tile_priority_bin <= TilePriority::NOW && | |
843 current_visible_rect_.Intersects(tile_bounds)) { | |
844 return TilePriority(resolution_, TilePriority::NOW, 0); | |
845 } | |
846 | |
847 if (max_tile_priority_bin <= TilePriority::SOON && | |
848 pending_visible_rect().Intersects(tile_bounds)) { | |
849 return TilePriority(resolution_, TilePriority::SOON, 0); | |
850 } | |
851 | |
852 DCHECK_GT(current_content_to_screen_scale_, 0.f); | 868 DCHECK_GT(current_content_to_screen_scale_, 0.f); |
853 float distance_to_visible = | 869 float distance_to_visible = |
854 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * | 870 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * |
855 current_content_to_screen_scale_; | 871 current_content_to_screen_scale_; |
856 | 872 |
857 if (max_tile_priority_bin <= TilePriority::SOON && | 873 return TilePriority(resolution_, priority_bin, distance_to_visible); |
858 (current_soon_border_rect_.Intersects(tile_bounds) || | 874 } |
859 current_skewport_rect_.Intersects(tile_bounds))) { | |
860 return TilePriority(resolution_, TilePriority::SOON, distance_to_visible); | |
861 } | |
862 | 875 |
863 return TilePriority(resolution_, TilePriority::EVENTUALLY, | 876 PictureLayerTiling::PriorityRectType |
864 distance_to_visible); | 877 PictureLayerTiling::ComputePriorityRectTypeForTile(const Tile* tile) const { |
| 878 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); |
| 879 gfx::Rect tile_bounds = |
| 880 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
| 881 |
| 882 if (current_visible_rect_.Intersects(tile_bounds)) |
| 883 return VISIBLE_RECT; |
| 884 |
| 885 if (pending_visible_rect().Intersects(tile_bounds)) |
| 886 return PENDING_VISIBLE_RECT; |
| 887 |
| 888 if (current_skewport_rect_.Intersects(tile_bounds)) |
| 889 return SKEWPORT_RECT; |
| 890 |
| 891 if (current_soon_border_rect_.Intersects(tile_bounds)) |
| 892 return SOON_BORDER_RECT; |
| 893 |
| 894 DCHECK(current_eventually_rect_.Intersects(tile_bounds)); |
| 895 return EVENTUALLY_RECT; |
865 } | 896 } |
866 | 897 |
867 void PictureLayerTiling::GetAllPrioritizedTilesForTracing( | 898 void PictureLayerTiling::GetAllPrioritizedTilesForTracing( |
868 std::vector<PrioritizedTile>* prioritized_tiles) const { | 899 std::vector<PrioritizedTile>* prioritized_tiles) const { |
869 for (const auto& tile_pair : tiles_) { | 900 for (const auto& tile_pair : tiles_) { |
870 prioritized_tiles->push_back(MakePrioritizedTile(tile_pair.second)); | 901 Tile* tile = tile_pair.second; |
| 902 prioritized_tiles->push_back( |
| 903 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile))); |
871 } | 904 } |
872 } | 905 } |
873 | 906 |
874 void PictureLayerTiling::AsValueInto( | 907 void PictureLayerTiling::AsValueInto( |
875 base::trace_event::TracedValue* state) const { | 908 base::trace_event::TracedValue* state) const { |
876 state->SetInteger("num_tiles", tiles_.size()); | 909 state->SetInteger("num_tiles", tiles_.size()); |
877 state->SetDouble("content_scale", contents_scale_); | 910 state->SetDouble("content_scale", contents_scale_); |
878 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); | 911 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); |
879 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); | 912 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); |
880 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); | 913 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 break; | 1070 break; |
1038 } | 1071 } |
1039 | 1072 |
1040 gfx::Rect result(origin_x, origin_y, width, height); | 1073 gfx::Rect result(origin_x, origin_y, width, height); |
1041 if (cache) | 1074 if (cache) |
1042 cache->previous_result = result; | 1075 cache->previous_result = result; |
1043 return result; | 1076 return result; |
1044 } | 1077 } |
1045 | 1078 |
1046 } // namespace cc | 1079 } // namespace cc |
OLD | NEW |