Chromium Code Reviews| 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 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 bool operator()(const Tile* a, const Tile* b) { | 33 bool operator()(const Tile* a, const Tile* b) { |
| 34 const TilePriority& a_priority = | 34 const TilePriority& a_priority = |
| 35 a->priority_for_tree_priority(tree_priority_); | 35 a->priority_for_tree_priority(tree_priority_); |
| 36 const TilePriority& b_priority = | 36 const TilePriority& b_priority = |
| 37 b->priority_for_tree_priority(tree_priority_); | 37 b->priority_for_tree_priority(tree_priority_); |
| 38 | 38 |
| 39 // Evict a before b if their priority bins differ and a has the higher | 39 // Evict a before b if their priority bins differ and a has the higher |
| 40 // priority bin. | 40 // priority bin. |
| 41 if (a_priority.priority_bin != b_priority.priority_bin) | 41 if (a_priority.priority_bin != b_priority.priority_bin) |
| 42 return a_priority.priority_bin > b_priority.priority_bin; | 42 return a_priority.priority_bin > b_priority.priority_bin; |
|
reveman
2014/08/14 09:01:50
should this not be a DCHECK too?
vmpstr
2014/08/14 22:05:50
Good point, yes!
| |
| 43 | 43 |
| 44 // Or if a is not required and b is required. | 44 DCHECK(a->required_for_activation() == b->required_for_activation()); |
| 45 if (a->required_for_activation() != b->required_for_activation()) | |
| 46 return b->required_for_activation(); | |
| 47 | 45 |
| 48 // Or if a is occluded and b is unoccluded. | 46 // Or if a is occluded and b is unoccluded. |
| 49 bool a_is_occluded = a->is_occluded_for_tree_priority(tree_priority_); | 47 bool a_is_occluded = a->is_occluded_for_tree_priority(tree_priority_); |
| 50 bool b_is_occluded = b->is_occluded_for_tree_priority(tree_priority_); | 48 bool b_is_occluded = b->is_occluded_for_tree_priority(tree_priority_); |
| 51 if (a_is_occluded != b_is_occluded) | 49 if (a_is_occluded != b_is_occluded) |
| 52 return a_is_occluded; | 50 return a_is_occluded; |
| 53 | 51 |
| 54 // Or if a is farther away from visible. | 52 // Or if a is farther away from visible. |
| 55 return a_priority.distance_to_visible > b_priority.distance_to_visible; | 53 return a_priority.distance_to_visible > b_priority.distance_to_visible; |
| 56 } | 54 } |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 cache->previous_result = result; | 838 cache->previous_result = result; |
| 841 return result; | 839 return result; |
| 842 } | 840 } |
| 843 | 841 |
| 844 void PictureLayerTiling::UpdateEvictionCacheIfNeeded( | 842 void PictureLayerTiling::UpdateEvictionCacheIfNeeded( |
| 845 TreePriority tree_priority) { | 843 TreePriority tree_priority) { |
| 846 if (eviction_tiles_cache_valid_ && | 844 if (eviction_tiles_cache_valid_ && |
| 847 eviction_cache_tree_priority_ == tree_priority) | 845 eviction_cache_tree_priority_ == tree_priority) |
| 848 return; | 846 return; |
| 849 | 847 |
| 850 eventually_eviction_tiles_.clear(); | 848 for (int i = 0; i < NUM_EVICTION_CATEGORIES; ++i) |
| 851 soon_eviction_tiles_.clear(); | 849 eviction_tiles_[i].clear(); |
| 852 now_eviction_tiles_.clear(); | |
| 853 now_and_required_for_activation_eviction_tiles_.clear(); | |
| 854 | 850 |
| 855 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 851 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 856 // TODO(vmpstr): This should update the priority if UpdateTilePriorities | 852 // TODO(vmpstr): This should update the priority if UpdateTilePriorities |
| 857 // changes not to do this. | 853 // changes not to do this. |
| 858 Tile* tile = it->second; | 854 Tile* tile = it->second; |
| 859 const TilePriority& priority = | 855 const TilePriority& priority = |
| 860 tile->priority_for_tree_priority(tree_priority); | 856 tile->priority_for_tree_priority(tree_priority); |
| 861 switch (priority.priority_bin) { | 857 switch (priority.priority_bin) { |
| 862 case TilePriority::EVENTUALLY: | 858 case TilePriority::EVENTUALLY: |
| 863 eventually_eviction_tiles_.push_back(tile); | 859 if (tile->required_for_activation()) |
| 860 eviction_tiles_[EVENTUALLY_AND_REQUIRED_FOR_ACTIVATION].push_back( | |
| 861 tile); | |
| 862 else | |
| 863 eviction_tiles_[EVENTUALLY].push_back(tile); | |
| 864 break; | 864 break; |
| 865 case TilePriority::SOON: | 865 case TilePriority::SOON: |
| 866 soon_eviction_tiles_.push_back(tile); | 866 if (tile->required_for_activation()) |
| 867 eviction_tiles_[SOON_AND_REQUIRED_FOR_ACTIVATION].push_back(tile); | |
| 868 else | |
| 869 eviction_tiles_[SOON].push_back(tile); | |
| 867 break; | 870 break; |
| 868 case TilePriority::NOW: | 871 case TilePriority::NOW: |
| 869 if (tile->required_for_activation()) | 872 if (tile->required_for_activation()) |
| 870 now_and_required_for_activation_eviction_tiles_.push_back(tile); | 873 eviction_tiles_[NOW_AND_REQUIRED_FOR_ACTIVATION].push_back(tile); |
| 871 else | 874 else |
| 872 now_eviction_tiles_.push_back(tile); | 875 eviction_tiles_[NOW].push_back(tile); |
| 873 break; | 876 break; |
| 874 } | 877 } |
| 875 } | 878 } |
| 876 | 879 |
| 877 // TODO(vmpstr): Do this lazily. One option is to have a "sorted" flag that | 880 // TODO(vmpstr): Do this lazily. One option is to have a "sorted" flag that |
| 878 // can be updated for each of the queues. | 881 // can be updated for each of the queues. |
| 879 TileEvictionOrder sort_order(tree_priority); | 882 TileEvictionOrder sort_order(tree_priority); |
| 880 std::sort(eventually_eviction_tiles_.begin(), | 883 for (int i = 0; i < NUM_EVICTION_CATEGORIES; ++i) { |
| 881 eventually_eviction_tiles_.end(), | 884 std::sort(eviction_tiles_[i].begin(), eviction_tiles_[i].end(), sort_order); |
| 882 sort_order); | 885 } |
| 883 std::sort( | |
| 884 soon_eviction_tiles_.begin(), soon_eviction_tiles_.end(), sort_order); | |
| 885 std::sort(now_eviction_tiles_.begin(), now_eviction_tiles_.end(), sort_order); | |
| 886 std::sort(now_and_required_for_activation_eviction_tiles_.begin(), | |
| 887 now_and_required_for_activation_eviction_tiles_.end(), | |
| 888 sort_order); | |
| 889 | 886 |
| 890 eviction_tiles_cache_valid_ = true; | 887 eviction_tiles_cache_valid_ = true; |
| 891 eviction_cache_tree_priority_ = tree_priority; | 888 eviction_cache_tree_priority_ = tree_priority; |
| 892 } | 889 } |
| 893 | 890 |
| 894 const std::vector<Tile*>* PictureLayerTiling::GetEvictionTiles( | 891 const std::vector<Tile*>* PictureLayerTiling::GetEvictionTiles( |
| 895 TreePriority tree_priority, | 892 TreePriority tree_priority, |
| 896 EvictionCategory category) { | 893 EvictionCategory category) { |
| 897 UpdateEvictionCacheIfNeeded(tree_priority); | 894 UpdateEvictionCacheIfNeeded(tree_priority); |
| 898 switch (category) { | 895 return &eviction_tiles_[category]; |
| 899 case EVENTUALLY: | |
| 900 return &eventually_eviction_tiles_; | |
| 901 case SOON: | |
| 902 return &soon_eviction_tiles_; | |
| 903 case NOW: | |
| 904 return &now_eviction_tiles_; | |
| 905 case NOW_AND_REQUIRED_FOR_ACTIVATION: | |
| 906 return &now_and_required_for_activation_eviction_tiles_; | |
| 907 } | |
| 908 NOTREACHED(); | |
| 909 return &eventually_eviction_tiles_; | |
| 910 } | 896 } |
| 911 | 897 |
| 912 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator() | 898 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator() |
| 913 : tiling_(NULL), current_tile_(NULL) {} | 899 : tiling_(NULL), current_tile_(NULL) {} |
| 914 | 900 |
| 915 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator( | 901 PictureLayerTiling::TilingRasterTileIterator::TilingRasterTileIterator( |
| 916 PictureLayerTiling* tiling, | 902 PictureLayerTiling* tiling, |
| 917 WhichTree tree) | 903 WhichTree tree) |
| 918 : tiling_(tiling), phase_(VISIBLE_RECT), tree_(tree), current_tile_(NULL) { | 904 : tiling_(tiling), phase_(VISIBLE_RECT), tree_(tree), current_tile_(NULL) { |
| 919 if (!tiling_->has_visible_rect_tiles_) { | 905 if (!tiling_->has_visible_rect_tiles_) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 DCHECK(*this); | 1059 DCHECK(*this); |
| 1074 do { | 1060 do { |
| 1075 ++current_eviction_tiles_index_; | 1061 ++current_eviction_tiles_index_; |
| 1076 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && | 1062 } while (current_eviction_tiles_index_ != eviction_tiles_->size() && |
| 1077 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); | 1063 !(*eviction_tiles_)[current_eviction_tiles_index_]->HasResources()); |
| 1078 | 1064 |
| 1079 return *this; | 1065 return *this; |
| 1080 } | 1066 } |
| 1081 | 1067 |
| 1082 } // namespace cc | 1068 } // namespace cc |
| OLD | NEW |