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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Twin relationships should never change once established. | 118 // Twin relationships should never change once established. |
119 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); | 119 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); |
120 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); | 120 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); |
121 // The twin relationship does not need to exist before the first | 121 // The twin relationship does not need to exist before the first |
122 // PushPropertiesTo from pending to active layer since before that the active | 122 // PushPropertiesTo from pending to active layer since before that the active |
123 // layer can not have a pile or tilings, it has only been created and inserted | 123 // layer can not have a pile or tilings, it has only been created and inserted |
124 // into the tree at that point. | 124 // into the tree at that point. |
125 twin_layer_ = layer_impl; | 125 twin_layer_ = layer_impl; |
126 layer_impl->twin_layer_ = this; | 126 layer_impl->twin_layer_ = this; |
127 | 127 |
| 128 layer_impl->set_is_mask(is_mask_); |
128 layer_impl->UpdateRasterSource(raster_source_); | 129 layer_impl->UpdateRasterSource(raster_source_); |
129 | 130 |
130 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); | 131 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); |
131 // Tilings would be expensive to push, so we swap. | 132 // Tilings would be expensive to push, so we swap. |
132 layer_impl->tilings_.swap(tilings_); | 133 layer_impl->tilings_.swap(tilings_); |
133 layer_impl->tilings_->SetClient(layer_impl); | 134 layer_impl->tilings_->SetClient(layer_impl); |
134 if (tilings_) | 135 if (tilings_) |
135 tilings_->SetClient(this); | 136 tilings_->SetClient(this); |
136 | 137 |
137 // Ensure that the recycle tree doesn't have any unshared tiles. | 138 // Ensure that the recycle tree doesn't have any unshared tiles. |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); | 879 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); |
879 | 880 |
880 DCHECK(raster_source_->HasRecordings()); | 881 DCHECK(raster_source_->HasRecordings()); |
881 | 882 |
882 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | 883 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) |
883 twin_layer->SyncTiling(tiling); | 884 twin_layer->SyncTiling(tiling); |
884 | 885 |
885 return tiling; | 886 return tiling; |
886 } | 887 } |
887 | 888 |
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() { | 889 void PictureLayerImpl::RemoveAllTilings() { |
899 if (tilings_) | 890 if (tilings_) |
900 tilings_->RemoveAllTilings(); | 891 tilings_->RemoveAllTilings(); |
901 // If there are no tilings, then raster scales are no longer meaningful. | 892 // If there are no tilings, then raster scales are no longer meaningful. |
902 ResetRasterScale(); | 893 ResetRasterScale(); |
903 } | 894 } |
904 | 895 |
905 void PictureLayerImpl::AddTilingsForRasterScale() { | 896 void PictureLayerImpl::AddTilingsForRasterScale() { |
906 // Reset all resolution enums on tilings, we'll be setting new values in this | 897 // Reset all resolution enums on tilings, we'll be setting new values in this |
907 // function. | 898 // function. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( | 1080 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( |
1090 std::vector<PictureLayerTiling*> used_tilings) { | 1081 std::vector<PictureLayerTiling*> used_tilings) { |
1091 DCHECK(layer_tree_impl()->IsActiveTree()); | 1082 DCHECK(layer_tree_impl()->IsActiveTree()); |
1092 if (tilings_->num_tilings() == 0) | 1083 if (tilings_->num_tilings() == 0) |
1093 return; | 1084 return; |
1094 | 1085 |
1095 float min_acceptable_high_res_scale = std::min( | 1086 float min_acceptable_high_res_scale = std::min( |
1096 raster_contents_scale_, ideal_contents_scale_); | 1087 raster_contents_scale_, ideal_contents_scale_); |
1097 float max_acceptable_high_res_scale = std::max( | 1088 float max_acceptable_high_res_scale = std::max( |
1098 raster_contents_scale_, ideal_contents_scale_); | 1089 raster_contents_scale_, ideal_contents_scale_); |
1099 float twin_low_res_scale = 0.f; | |
1100 | 1090 |
1101 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); | 1091 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); |
1102 if (twin && twin->CanHaveTilings()) { | 1092 if (twin && twin->CanHaveTilings()) { |
1103 min_acceptable_high_res_scale = std::min( | 1093 min_acceptable_high_res_scale = std::min( |
1104 min_acceptable_high_res_scale, | 1094 min_acceptable_high_res_scale, |
1105 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); | 1095 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); |
1106 max_acceptable_high_res_scale = std::max( | 1096 max_acceptable_high_res_scale = std::max( |
1107 max_acceptable_high_res_scale, | 1097 max_acceptable_high_res_scale, |
1108 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); | 1098 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 } | 1099 } |
1119 | 1100 |
1120 // TODO(vmpstr): Put this logic into PictureLayerTilingSet. | 1101 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; |
1121 std::vector<PictureLayerTiling*> to_remove; | 1102 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
1122 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 1103 PictureLayerTilingSet* recycled_twin_set = |
1123 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 1104 recycled_twin ? recycled_twin->tilings_.get() : nullptr; |
1124 | 1105 |
1125 // Keep multiple high resolution tilings even if not used to help | 1106 tilings_->CleanUpTilings(min_acceptable_high_res_scale, |
1126 // activate earlier at non-ideal resolutions. | 1107 max_acceptable_high_res_scale, used_tilings, |
1127 if (tiling->contents_scale() >= min_acceptable_high_res_scale && | 1108 layer_tree_impl()->create_low_res_tiling(), twin_set, |
1128 tiling->contents_scale() <= max_acceptable_high_res_scale) | 1109 recycled_twin_set); |
1129 continue; | |
1130 | 1110 |
1131 // Keep low resolution tilings, if the layer should have them. | 1111 if (twin_set && twin_set->num_tilings() == 0) |
1132 if (layer_tree_impl()->create_low_res_tiling()) { | 1112 twin->ResetRasterScale(); |
1133 if (tiling->resolution() == LOW_RESOLUTION || | |
1134 tiling->contents_scale() == twin_low_res_scale) | |
1135 continue; | |
1136 } | |
1137 | 1113 |
1138 // Don't remove tilings that are being used (and thus would cause a flash.) | 1114 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) |
1139 if (std::find(used_tilings.begin(), used_tilings.end(), tiling) != | 1115 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 | 1116 |
1167 DCHECK_GT(tilings_->num_tilings(), 0u); | 1117 DCHECK_GT(tilings_->num_tilings(), 0u); |
1168 SanityCheckTilingState(); | 1118 SanityCheckTilingState(); |
1169 } | 1119 } |
1170 | 1120 |
1171 float PictureLayerImpl::MinimumContentsScale() const { | 1121 float PictureLayerImpl::MinimumContentsScale() const { |
1172 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1122 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
1173 | 1123 |
1174 // If the contents scale is less than 1 / width (also for height), | 1124 // 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 | 1125 // 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(); | 1623 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1674 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1624 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1675 return tiling_range.end - 1 - current_tiling_range_offset; | 1625 return tiling_range.end - 1 - current_tiling_range_offset; |
1676 } | 1626 } |
1677 } | 1627 } |
1678 NOTREACHED(); | 1628 NOTREACHED(); |
1679 return 0; | 1629 return 0; |
1680 } | 1630 } |
1681 | 1631 |
1682 } // namespace cc | 1632 } // namespace cc |
OLD | NEW |