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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 } | 880 } |
881 | 881 |
882 void PictureLayerImpl::SetUseTransformedRasterization(bool use) { | 882 void PictureLayerImpl::SetUseTransformedRasterization(bool use) { |
883 if (use_transformed_rasterization_ == use) | 883 if (use_transformed_rasterization_ == use) |
884 return; | 884 return; |
885 | 885 |
886 use_transformed_rasterization_ = use; | 886 use_transformed_rasterization_ = use; |
887 NoteLayerPropertyChanged(); | 887 NoteLayerPropertyChanged(); |
888 } | 888 } |
889 | 889 |
890 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 890 PictureLayerTiling* PictureLayerImpl::AddTiling(const ScaleTranslate2d& contents _transform) { |
891 DCHECK(CanHaveTilings()); | 891 DCHECK(CanHaveTilings()); |
892 DCHECK_GE(contents_scale, MinimumContentsScale()); | 892 DCHECK_GE(contents_transform.scale(), MinimumContentsScale()); |
893 DCHECK_LE(contents_scale, MaximumContentsScale()); | 893 DCHECK_LE(contents_transform.scale(), MaximumContentsScale()); |
894 DCHECK(raster_source_->HasRecordings()); | 894 DCHECK(raster_source_->HasRecordings()); |
895 return tilings_->AddTiling(ScaleTranslate2d(contents_scale, gfx::Vector2dF()), raster_source_); | 895 return tilings_->AddTiling(contents_transform, raster_source_); |
896 } | 896 } |
897 | 897 |
898 void PictureLayerImpl::RemoveAllTilings() { | 898 void PictureLayerImpl::RemoveAllTilings() { |
899 tilings_->RemoveAllTilings(); | 899 tilings_->RemoveAllTilings(); |
900 // If there are no tilings, then raster scales are no longer meaningful. | 900 // If there are no tilings, then raster scales are no longer meaningful. |
901 ResetRasterScale(); | 901 ResetRasterScale(); |
902 } | 902 } |
903 | 903 |
904 void PictureLayerImpl::AddTilingsForRasterScale() { | 904 void PictureLayerImpl::AddTilingsForRasterScale() { |
905 // Reset all resolution enums on tilings, we'll be setting new values in this | 905 // Reset all resolution enums on tilings, we'll be setting new values in this |
906 // function. | 906 // function. |
907 tilings_->MarkAllTilingsNonIdeal(); | 907 tilings_->MarkAllTilingsNonIdeal(); |
908 | 908 |
909 PictureLayerTiling* high_res = | 909 PictureLayerTiling* high_res = |
910 tilings_->FindTilingWithScaleKey(raster_contents_scale_); | 910 tilings_->FindTilingWithScaleKey(raster_contents_scale_); |
911 gfx::Vector2dF raster_translation = CalculateRasterTranslation(raster_contents _scale_); | |
912 if (high_res && high_res->raster_transform().translation() != raster_translati on) { | |
enne (OOO)
2017/01/03 22:54:00
This logic about changing the raster translation b
| |
913 tilings_->Remove(high_res); | |
914 high_res = nullptr; | |
915 } | |
911 if (!high_res) { | 916 if (!high_res) { |
912 // We always need a high res tiling, so create one if it doesn't exist. | 917 // We always need a high res tiling, so create one if it doesn't exist. |
913 high_res = AddTiling(raster_contents_scale_); | 918 high_res = AddTiling(ScaleTranslate2d(raster_contents_scale_, raster_transla tion)); |
914 } else if (high_res->may_contain_low_resolution_tiles()) { | 919 } else if (high_res->may_contain_low_resolution_tiles()) { |
915 // If the tiling we find here was LOW_RESOLUTION previously, it may not be | 920 // If the tiling we find here was LOW_RESOLUTION previously, it may not be |
916 // fully rastered, so destroy the old tiles. | 921 // fully rastered, so destroy the old tiles. |
917 high_res->Reset(); | 922 high_res->Reset(); |
918 // Reset the flag now that we'll make it high res, it will have fully | 923 // Reset the flag now that we'll make it high res, it will have fully |
919 // rastered content. | 924 // rastered content. |
920 high_res->reset_may_contain_low_resolution_tiles(); | 925 high_res->reset_may_contain_low_resolution_tiles(); |
921 } | 926 } |
922 high_res->set_resolution(HIGH_RESOLUTION); | 927 high_res->set_resolution(HIGH_RESOLUTION); |
923 | 928 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1000 tilings_->FindTilingWithScaleKey(low_res_raster_contents_scale_); | 1005 tilings_->FindTilingWithScaleKey(low_res_raster_contents_scale_); |
1001 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); | 1006 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); |
1002 | 1007 |
1003 // Only create new low res tilings when the transform is static. This | 1008 // Only create new low res tilings when the transform is static. This |
1004 // prevents wastefully creating a paired low res tiling for every new high | 1009 // prevents wastefully creating a paired low res tiling for every new high |
1005 // res tiling during a pinch or a CSS animation. | 1010 // res tiling during a pinch or a CSS animation. |
1006 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 1011 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
1007 bool is_animating = draw_properties().screen_space_transform_is_animating; | 1012 bool is_animating = draw_properties().screen_space_transform_is_animating; |
1008 if (!is_pinching && !is_animating) { | 1013 if (!is_pinching && !is_animating) { |
1009 if (!low_res) | 1014 if (!low_res) |
1010 low_res = AddTiling(low_res_raster_contents_scale_); | 1015 low_res = AddTiling(ScaleTranslate2d(low_res_raster_contents_scale_, gfx:: Vector2dF())); |
1011 low_res->set_resolution(LOW_RESOLUTION); | 1016 low_res->set_resolution(LOW_RESOLUTION); |
1012 } | 1017 } |
1013 } | 1018 } |
1014 | 1019 |
1015 void PictureLayerImpl::RecalculateRasterScales() { | 1020 void PictureLayerImpl::RecalculateRasterScales() { |
1016 if (is_directly_composited_image_) { | 1021 if (is_directly_composited_image_) { |
1017 if (!raster_source_scale_) | 1022 if (!raster_source_scale_) |
1018 raster_source_scale_ = 1.f; | 1023 raster_source_scale_ = 1.f; |
1019 | 1024 |
1020 float min_scale = MinimumContentsScale(); | 1025 float min_scale = MinimumContentsScale(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1166 } | 1171 } |
1167 | 1172 |
1168 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; | 1173 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; |
1169 tilings_->CleanUpTilings(min_acceptable_high_res_scale, | 1174 tilings_->CleanUpTilings(min_acceptable_high_res_scale, |
1170 max_acceptable_high_res_scale, used_tilings, | 1175 max_acceptable_high_res_scale, used_tilings, |
1171 twin_set); | 1176 twin_set); |
1172 DCHECK_GT(tilings_->num_tilings(), 0u); | 1177 DCHECK_GT(tilings_->num_tilings(), 0u); |
1173 SanityCheckTilingState(); | 1178 SanityCheckTilingState(); |
1174 } | 1179 } |
1175 | 1180 |
1181 gfx::Vector2dF PictureLayerImpl::CalculateRasterTranslation( | |
1182 float raster_scale) { | |
1183 if (!use_transformed_rasterization_) | |
1184 return gfx::Vector2dF(); | |
1185 | |
1186 DCHECK(!draw_properties().screen_space_transform_is_animating); | |
1187 gfx::Transform draw_transform = DrawTransform(); | |
1188 DCHECK(draw_transform.IsScaleOrTranslation()); | |
1189 | |
1190 // It is only useful to align the content space to the target space if their | |
1191 // relative pixel ratio is some small rational number. Currently we only | |
1192 // align if the relative pixel ratio is 1:1. | |
1193 // Good match if the maximum alignment error on a layer of size 10000px | |
1194 // does not exceed 0.001px. | |
1195 static constexpr float kErrorThreshold = 0.0000001f; | |
1196 if (std::abs(draw_transform.matrix().getFloat(0, 0) - raster_scale) > | |
1197 kErrorThreshold || | |
1198 std::abs(draw_transform.matrix().getFloat(1, 1) - raster_scale) > | |
1199 kErrorThreshold) | |
1200 return gfx::Vector2dF(); | |
1201 | |
1202 // Extract the fractional part of layer origin in the target space. | |
1203 float origin_x = draw_transform.matrix().getFloat(0, 3); | |
1204 float origin_y = draw_transform.matrix().getFloat(1, 3); | |
1205 return gfx::Vector2dF(origin_x - floorf(origin_x), | |
1206 origin_y - floorf(origin_y)); | |
1207 } | |
1208 | |
1176 float PictureLayerImpl::MinimumContentsScale() const { | 1209 float PictureLayerImpl::MinimumContentsScale() const { |
1177 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1210 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
1178 | 1211 |
1179 // If the contents scale is less than 1 / width (also for height), | 1212 // If the contents scale is less than 1 / width (also for height), |
1180 // then it will end up having less than one pixel of content in that | 1213 // then it will end up having less than one pixel of content in that |
1181 // dimension. Bump the minimum contents scale up in this case to prevent | 1214 // dimension. Bump the minimum contents scale up in this case to prevent |
1182 // this from happening. | 1215 // this from happening. |
1183 int min_dimension = std::min(raster_source_->GetSize().width(), | 1216 int min_dimension = std::min(raster_source_->GetSize().width(), |
1184 raster_source_->GetSize().height()); | 1217 raster_source_->GetSize().height()); |
1185 if (!min_dimension) | 1218 if (!min_dimension) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1356 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { | 1389 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { |
1357 return !layer_tree_impl()->IsRecycleTree(); | 1390 return !layer_tree_impl()->IsRecycleTree(); |
1358 } | 1391 } |
1359 | 1392 |
1360 bool PictureLayerImpl::HasValidTilePriorities() const { | 1393 bool PictureLayerImpl::HasValidTilePriorities() const { |
1361 return IsOnActiveOrPendingTree() && | 1394 return IsOnActiveOrPendingTree() && |
1362 is_drawn_render_surface_layer_list_member(); | 1395 is_drawn_render_surface_layer_list_member(); |
1363 } | 1396 } |
1364 | 1397 |
1365 } // namespace cc | 1398 } // namespace cc |
OLD | NEW |