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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); | 878 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); |
879 | 879 |
880 DCHECK(raster_source_->HasRecordings()); | 880 DCHECK(raster_source_->HasRecordings()); |
881 | 881 |
882 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | 882 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) |
883 twin_layer->SyncTiling(tiling); | 883 twin_layer->SyncTiling(tiling); |
884 | 884 |
885 return tiling; | 885 return tiling; |
886 } | 886 } |
887 | 887 |
888 void PictureLayerImpl::RemoveTiling(float contents_scale) { | |
889 if (!tilings_ || tilings_->num_tilings() == 0) | |
890 return; | |
891 | |
892 tilings_->RemoveTilingWithScale(contents_scale); | |
893 if (tilings_->num_tilings() == 0) | |
894 ResetRasterScale(); | |
895 SanityCheckTilingState(); | |
896 } | |
897 | |
898 void PictureLayerImpl::RemoveAllTilings() { | 888 void PictureLayerImpl::RemoveAllTilings() { |
899 if (tilings_) | 889 if (tilings_) |
900 tilings_->RemoveAllTilings(); | 890 tilings_->RemoveAllTilings(); |
901 // If there are no tilings, then raster scales are no longer meaningful. | 891 // If there are no tilings, then raster scales are no longer meaningful. |
902 ResetRasterScale(); | 892 ResetRasterScale(); |
903 } | 893 } |
904 | 894 |
905 void PictureLayerImpl::AddTilingsForRasterScale() { | 895 void PictureLayerImpl::AddTilingsForRasterScale() { |
906 // Reset all resolution enums on tilings, we'll be setting new values in this | 896 // Reset all resolution enums on tilings, we'll be setting new values in this |
907 // function. | 897 // function. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( | 1079 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( |
1090 std::vector<PictureLayerTiling*> used_tilings) { | 1080 std::vector<PictureLayerTiling*> used_tilings) { |
1091 DCHECK(layer_tree_impl()->IsActiveTree()); | 1081 DCHECK(layer_tree_impl()->IsActiveTree()); |
1092 if (tilings_->num_tilings() == 0) | 1082 if (tilings_->num_tilings() == 0) |
1093 return; | 1083 return; |
1094 | 1084 |
1095 float min_acceptable_high_res_scale = std::min( | 1085 float min_acceptable_high_res_scale = std::min( |
1096 raster_contents_scale_, ideal_contents_scale_); | 1086 raster_contents_scale_, ideal_contents_scale_); |
1097 float max_acceptable_high_res_scale = std::max( | 1087 float max_acceptable_high_res_scale = std::max( |
1098 raster_contents_scale_, ideal_contents_scale_); | 1088 raster_contents_scale_, ideal_contents_scale_); |
1099 float twin_low_res_scale = 0.f; | |
1100 | 1089 |
1101 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); | 1090 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); |
1102 if (twin && twin->CanHaveTilings()) { | 1091 if (twin && twin->CanHaveTilings()) { |
1103 min_acceptable_high_res_scale = std::min( | 1092 min_acceptable_high_res_scale = std::min( |
1104 min_acceptable_high_res_scale, | 1093 min_acceptable_high_res_scale, |
1105 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); | 1094 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); |
1106 max_acceptable_high_res_scale = std::max( | 1095 max_acceptable_high_res_scale = std::max( |
1107 max_acceptable_high_res_scale, | 1096 max_acceptable_high_res_scale, |
1108 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); | 1097 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); |
1109 | |
1110 // TODO(danakj): Remove the tilings_ check when we create them in the | |
1111 // constructor. | |
1112 if (twin->tilings_) { | |
1113 PictureLayerTiling* tiling = | |
1114 twin->tilings_->FindTilingWithResolution(LOW_RESOLUTION); | |
1115 if (tiling) | |
1116 twin_low_res_scale = tiling->contents_scale(); | |
1117 } | |
1118 } | 1098 } |
1119 | 1099 |
1120 // TODO(vmpstr): Put this logic into PictureLayerTilingSet. | 1100 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; |
1121 std::vector<PictureLayerTiling*> to_remove; | 1101 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
1122 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 1102 PictureLayerTilingSet* recycled_twin_set = |
1123 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 1103 recycled_twin ? recycled_twin->tilings_.get() : nullptr; |
1124 | 1104 |
1125 // Keep multiple high resolution tilings even if not used to help | 1105 tilings_->CleanUpTilings(min_acceptable_high_res_scale, |
1126 // activate earlier at non-ideal resolutions. | 1106 max_acceptable_high_res_scale, used_tilings, |
1127 if (tiling->contents_scale() >= min_acceptable_high_res_scale && | 1107 layer_tree_impl()->create_low_res_tiling(), twin_set, |
1128 tiling->contents_scale() <= max_acceptable_high_res_scale) | 1108 recycled_twin_set); |
1129 continue; | |
1130 | 1109 |
1131 // Keep low resolution tilings, if the layer should have them. | 1110 if (twin_set && twin_set->num_tilings() == 0) |
1132 if (layer_tree_impl()->create_low_res_tiling()) { | 1111 twin->ResetRasterScale(); |
1133 if (tiling->resolution() == LOW_RESOLUTION || | |
1134 tiling->contents_scale() == twin_low_res_scale) | |
1135 continue; | |
1136 } | |
1137 | 1112 |
1138 // Don't remove tilings that are being used (and thus would cause a flash.) | 1113 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) |
1139 if (std::find(used_tilings.begin(), used_tilings.end(), tiling) != | 1114 recycled_twin->ResetRasterScale(); |
1140 used_tilings.end()) | |
1141 continue; | |
1142 | |
1143 to_remove.push_back(tiling); | |
1144 } | |
1145 | |
1146 if (to_remove.empty()) | |
1147 return; | |
1148 | |
1149 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | |
1150 // Remove tilings on this tree and the twin tree. | |
1151 for (size_t i = 0; i < to_remove.size(); ++i) { | |
1152 const PictureLayerTiling* twin_tiling = | |
1153 GetPendingOrActiveTwinTiling(to_remove[i]); | |
1154 // Only remove tilings from the twin layer if they have | |
1155 // NON_IDEAL_RESOLUTION. | |
1156 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) | |
1157 twin->RemoveTiling(to_remove[i]->contents_scale()); | |
1158 // Remove the tiling from the recycle tree. Note that we ignore resolution, | |
1159 // since we don't need to maintain high/low res on the recycle tree. | |
1160 if (recycled_twin) | |
1161 recycled_twin->RemoveTiling(to_remove[i]->contents_scale()); | |
1162 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 | |
1163 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); | |
1164 tilings_->Remove(to_remove[i]); | |
1165 } | |
1166 | 1115 |
1167 DCHECK_GT(tilings_->num_tilings(), 0u); | 1116 DCHECK_GT(tilings_->num_tilings(), 0u); |
1168 SanityCheckTilingState(); | 1117 SanityCheckTilingState(); |
1169 } | 1118 } |
1170 | 1119 |
1171 float PictureLayerImpl::MinimumContentsScale() const { | 1120 float PictureLayerImpl::MinimumContentsScale() const { |
1172 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1121 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
1173 | 1122 |
1174 // If the contents scale is less than 1 / width (also for height), | 1123 // If the contents scale is less than 1 / width (also for height), |
1175 // then it will end up having less than one pixel of content in that | 1124 // then it will end up having less than one pixel of content in that |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1622 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1674 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1623 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1675 return tiling_range.end - 1 - current_tiling_range_offset; | 1624 return tiling_range.end - 1 - current_tiling_range_offset; |
1676 } | 1625 } |
1677 } | 1626 } |
1678 NOTREACHED(); | 1627 NOTREACHED(); |
1679 return 0; | 1628 return 0; |
1680 } | 1629 } |
1681 | 1630 |
1682 } // namespace cc | 1631 } // namespace cc |
OLD | NEW |