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 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 if (IsTileOccluded(tile)) | 800 if (IsTileOccluded(tile)) |
801 return false; | 801 return false; |
802 | 802 |
803 return true; | 803 return true; |
804 } | 804 } |
805 | 805 |
806 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { | 806 void PictureLayerTiling::UpdateTileAndTwinPriority(Tile* tile) const { |
807 WhichTree tree = client_->GetTree(); | 807 WhichTree tree = client_->GetTree(); |
808 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; | 808 WhichTree twin_tree = tree == ACTIVE_TREE ? PENDING_TREE : ACTIVE_TREE; |
809 | 809 |
810 UpdateTilePriorityForTree(tile, tree); | 810 tile->SetPriority(tree, ComputePriorityForTile(tile)); |
| 811 UpdateRequiredStateForTile(tile, tree); |
811 | 812 |
812 const PictureLayerTiling* twin_tiling = | 813 const PictureLayerTiling* twin_tiling = |
813 client_->GetPendingOrActiveTwinTiling(this); | 814 client_->GetPendingOrActiveTwinTiling(this); |
814 if (!tile->is_shared() || !twin_tiling) { | 815 if (!tile->is_shared() || !twin_tiling) { |
815 tile->SetPriority(twin_tree, TilePriority()); | 816 tile->SetPriority(twin_tree, TilePriority()); |
816 tile->set_is_occluded(twin_tree, false); | 817 tile->set_is_occluded(twin_tree, false); |
817 if (twin_tree == PENDING_TREE) | 818 if (twin_tree == PENDING_TREE) |
818 tile->set_required_for_activation(false); | 819 tile->set_required_for_activation(false); |
819 else | 820 else |
820 tile->set_required_for_draw(false); | 821 tile->set_required_for_draw(false); |
821 return; | 822 return; |
822 } | 823 } |
823 | 824 |
824 twin_tiling->UpdateTilePriorityForTree(tile, twin_tree); | 825 tile->SetPriority(twin_tree, twin_tiling->ComputePriorityForTile(tile)); |
| 826 twin_tiling->UpdateRequiredStateForTile(tile, twin_tree); |
825 } | 827 } |
826 | 828 |
827 void PictureLayerTiling::UpdateTilePriorityForTree(Tile* tile, | 829 void PictureLayerTiling::UpdateRequiredStateForTile(Tile* tile, |
828 WhichTree tree) const { | 830 WhichTree tree) const { |
829 // TODO(vmpstr): This code should return the priority instead of setting it on | 831 if (tile->priority(tree).priority_bin == TilePriority::NOW) { |
830 // the tile. This should be a part of the change to move tile priority from | |
831 // tiles into iterators. | |
832 TilePriority::PriorityBin max_tile_priority_bin = | |
833 client_->GetMaxTilePriorityBin(); | |
834 | |
835 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); | |
836 gfx::Rect tile_bounds = | |
837 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); | |
838 | |
839 if (max_tile_priority_bin <= TilePriority::NOW && | |
840 current_visible_rect_.Intersects(tile_bounds)) { | |
841 tile->SetPriority(tree, TilePriority(resolution_, TilePriority::NOW, 0)); | |
842 if (tree == PENDING_TREE) { | 832 if (tree == PENDING_TREE) { |
843 tile->set_required_for_activation( | 833 tile->set_required_for_activation( |
844 IsTileRequiredForActivationIfVisible(tile)); | 834 IsTileRequiredForActivationIfVisible(tile)); |
845 } else { | 835 } else { |
846 tile->set_required_for_draw(IsTileRequiredForDrawIfVisible(tile)); | 836 tile->set_required_for_draw(IsTileRequiredForDrawIfVisible(tile)); |
847 } | 837 } |
848 tile->set_is_occluded(tree, IsTileOccluded(tile)); | 838 tile->set_is_occluded(tree, IsTileOccluded(tile)); |
849 return; | 839 return; |
850 } | 840 } |
851 | 841 |
| 842 // Non-NOW bin tiles are not required or occluded. |
852 if (tree == PENDING_TREE) | 843 if (tree == PENDING_TREE) |
853 tile->set_required_for_activation(false); | 844 tile->set_required_for_activation(false); |
854 else | 845 else |
855 tile->set_required_for_draw(false); | 846 tile->set_required_for_draw(false); |
856 tile->set_is_occluded(tree, false); | 847 tile->set_is_occluded(tree, false); |
| 848 } |
| 849 |
| 850 TilePriority PictureLayerTiling::ComputePriorityForTile( |
| 851 const Tile* tile) const { |
| 852 // TODO(vmpstr): See if this can be moved to iterators. |
| 853 TilePriority::PriorityBin max_tile_priority_bin = |
| 854 client_->GetMaxTilePriorityBin(); |
| 855 |
| 856 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); |
| 857 gfx::Rect tile_bounds = |
| 858 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
| 859 |
| 860 if (max_tile_priority_bin <= TilePriority::NOW && |
| 861 current_visible_rect_.Intersects(tile_bounds)) { |
| 862 return TilePriority(resolution_, TilePriority::NOW, 0); |
| 863 } |
857 | 864 |
858 DCHECK_GT(current_content_to_screen_scale_, 0.f); | 865 DCHECK_GT(current_content_to_screen_scale_, 0.f); |
859 float distance_to_visible = | 866 float distance_to_visible = |
860 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * | 867 current_visible_rect_.ManhattanInternalDistance(tile_bounds) * |
861 current_content_to_screen_scale_; | 868 current_content_to_screen_scale_; |
862 | 869 |
863 if (max_tile_priority_bin <= TilePriority::SOON && | 870 if (max_tile_priority_bin <= TilePriority::SOON && |
864 (current_soon_border_rect_.Intersects(tile_bounds) || | 871 (current_soon_border_rect_.Intersects(tile_bounds) || |
865 current_skewport_rect_.Intersects(tile_bounds))) { | 872 current_skewport_rect_.Intersects(tile_bounds))) { |
866 tile->SetPriority( | 873 return TilePriority(resolution_, TilePriority::SOON, distance_to_visible); |
867 tree, | |
868 TilePriority(resolution_, TilePriority::SOON, distance_to_visible)); | |
869 return; | |
870 } | 874 } |
871 | 875 |
872 tile->SetPriority( | 876 return TilePriority(resolution_, TilePriority::EVENTUALLY, |
873 tree, | 877 distance_to_visible); |
874 TilePriority(resolution_, TilePriority::EVENTUALLY, distance_to_visible)); | |
875 } | 878 } |
876 | 879 |
877 void PictureLayerTiling::GetAllTilesForTracing( | 880 void PictureLayerTiling::GetAllTilesAndPrioritiesForTracing( |
878 std::set<const Tile*>* tiles) const { | 881 std::map<const Tile*, TilePriority>* tile_map) const { |
879 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 882 const PictureLayerTiling* twin_tiling = |
880 tiles->insert(it->second.get()); | 883 client_->GetPendingOrActiveTwinTiling(this); |
| 884 for (const auto& tile_pair : tiles_) { |
| 885 const Tile* tile = tile_pair.second.get(); |
| 886 const TilePriority& priority = ComputePriorityForTile(tile); |
| 887 const TilePriority& twin_priority = |
| 888 twin_tiling ? twin_tiling->ComputePriorityForTile(tile) |
| 889 : TilePriority(); |
| 890 |
| 891 // Store combined priority. |
| 892 (*tile_map)[tile] = TilePriority(priority, twin_priority); |
| 893 } |
881 } | 894 } |
882 | 895 |
883 void PictureLayerTiling::AsValueInto( | 896 void PictureLayerTiling::AsValueInto( |
884 base::trace_event::TracedValue* state) const { | 897 base::trace_event::TracedValue* state) const { |
885 state->SetInteger("num_tiles", tiles_.size()); | 898 state->SetInteger("num_tiles", tiles_.size()); |
886 state->SetDouble("content_scale", contents_scale_); | 899 state->SetDouble("content_scale", contents_scale_); |
887 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); | 900 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); |
888 } | 901 } |
889 | 902 |
890 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 903 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 break; | 1054 break; |
1042 } | 1055 } |
1043 | 1056 |
1044 gfx::Rect result(origin_x, origin_y, width, height); | 1057 gfx::Rect result(origin_x, origin_y, width, height); |
1045 if (cache) | 1058 if (cache) |
1046 cache->previous_result = result; | 1059 cache->previous_result = result; |
1047 return result; | 1060 return result; |
1048 } | 1061 } |
1049 | 1062 |
1050 } // namespace cc | 1063 } // namespace cc |
OLD | NEW |