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 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 } | 737 } |
738 | 738 |
739 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( | 739 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( |
740 const PictureLayerTiling* tiling) const { | 740 const PictureLayerTiling* tiling) const { |
741 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); | 741 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); |
742 if (!twin_layer) | 742 if (!twin_layer) |
743 return nullptr; | 743 return nullptr; |
744 const PictureLayerTiling* twin_tiling = | 744 const PictureLayerTiling* twin_tiling = |
745 twin_layer->tilings_->FindTilingWithScaleKey( | 745 twin_layer->tilings_->FindTilingWithScaleKey( |
746 tiling->contents_scale_key()); | 746 tiling->contents_scale_key()); |
747 DCHECK(tiling->raster_transform().translation() == gfx::Vector2dF()); | 747 if (twin_tiling && |
748 DCHECK(!twin_tiling || | 748 twin_tiling->raster_transform() == tiling->raster_transform()) |
749 twin_tiling->raster_transform().translation() == gfx::Vector2dF()); | 749 return twin_tiling; |
750 return twin_tiling; | 750 return nullptr; |
751 } | 751 } |
752 | 752 |
753 bool PictureLayerImpl::RequiresHighResToDraw() const { | 753 bool PictureLayerImpl::RequiresHighResToDraw() const { |
754 return layer_tree_impl()->RequiresHighResToDraw(); | 754 return layer_tree_impl()->RequiresHighResToDraw(); |
755 } | 755 } |
756 | 756 |
757 gfx::Rect PictureLayerImpl::GetEnclosingRectInTargetSpace() const { | 757 gfx::Rect PictureLayerImpl::GetEnclosingRectInTargetSpace() const { |
758 return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale()); | 758 return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale()); |
759 } | 759 } |
760 | 760 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 } | 910 } |
911 | 911 |
912 void PictureLayerImpl::SetUseTransformedRasterization(bool use) { | 912 void PictureLayerImpl::SetUseTransformedRasterization(bool use) { |
913 if (use_transformed_rasterization_ == use) | 913 if (use_transformed_rasterization_ == use) |
914 return; | 914 return; |
915 | 915 |
916 use_transformed_rasterization_ = use; | 916 use_transformed_rasterization_ = use; |
917 NoteLayerPropertyChanged(); | 917 NoteLayerPropertyChanged(); |
918 } | 918 } |
919 | 919 |
920 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 920 PictureLayerTiling* PictureLayerImpl::AddTiling( |
| 921 const gfx::AxisTransform2d& contents_transform) { |
921 DCHECK(CanHaveTilings()); | 922 DCHECK(CanHaveTilings()); |
922 DCHECK_GE(contents_scale, MinimumContentsScale()); | 923 DCHECK_GE(contents_transform.scale(), MinimumContentsScale()); |
923 DCHECK_LE(contents_scale, MaximumContentsScale()); | 924 DCHECK_LE(contents_transform.scale(), MaximumContentsScale()); |
924 DCHECK(raster_source_->HasRecordings()); | 925 DCHECK(raster_source_->HasRecordings()); |
925 return tilings_->AddTiling( | 926 return tilings_->AddTiling(contents_transform, raster_source_); |
926 gfx::AxisTransform2d(contents_scale, gfx::Vector2dF()), raster_source_); | |
927 } | 927 } |
928 | 928 |
929 void PictureLayerImpl::RemoveAllTilings() { | 929 void PictureLayerImpl::RemoveAllTilings() { |
930 tilings_->RemoveAllTilings(); | 930 tilings_->RemoveAllTilings(); |
931 // If there are no tilings, then raster scales are no longer meaningful. | 931 // If there are no tilings, then raster scales are no longer meaningful. |
932 ResetRasterScale(); | 932 ResetRasterScale(); |
933 } | 933 } |
934 | 934 |
935 void PictureLayerImpl::AddTilingsForRasterScale() { | 935 void PictureLayerImpl::AddTilingsForRasterScale() { |
936 // Reset all resolution enums on tilings, we'll be setting new values in this | 936 // Reset all resolution enums on tilings, we'll be setting new values in this |
937 // function. | 937 // function. |
938 tilings_->MarkAllTilingsNonIdeal(); | 938 tilings_->MarkAllTilingsNonIdeal(); |
939 | 939 |
940 PictureLayerTiling* high_res = | 940 PictureLayerTiling* high_res = |
941 tilings_->FindTilingWithScaleKey(raster_contents_scale_); | 941 tilings_->FindTilingWithScaleKey(raster_contents_scale_); |
| 942 // Note: This function is always invoked when raster scale is recomputed, |
| 943 // but not necessarily changed. This means raster translation update is also |
| 944 // always done when there are significant changes that triggered raster scale |
| 945 // recomputation. |
| 946 gfx::Vector2dF raster_translation = |
| 947 CalculateRasterTranslation(raster_contents_scale_); |
| 948 if (high_res && |
| 949 high_res->raster_transform().translation() != raster_translation) { |
| 950 tilings_->Remove(high_res); |
| 951 high_res = nullptr; |
| 952 } |
942 if (!high_res) { | 953 if (!high_res) { |
943 // We always need a high res tiling, so create one if it doesn't exist. | 954 // We always need a high res tiling, so create one if it doesn't exist. |
944 high_res = AddTiling(raster_contents_scale_); | 955 high_res = AddTiling( |
| 956 gfx::AxisTransform2d(raster_contents_scale_, raster_translation)); |
945 } else if (high_res->may_contain_low_resolution_tiles()) { | 957 } else if (high_res->may_contain_low_resolution_tiles()) { |
946 // If the tiling we find here was LOW_RESOLUTION previously, it may not be | 958 // If the tiling we find here was LOW_RESOLUTION previously, it may not be |
947 // fully rastered, so destroy the old tiles. | 959 // fully rastered, so destroy the old tiles. |
948 high_res->Reset(); | 960 high_res->Reset(); |
949 // Reset the flag now that we'll make it high res, it will have fully | 961 // Reset the flag now that we'll make it high res, it will have fully |
950 // rastered content. | 962 // rastered content. |
951 high_res->reset_may_contain_low_resolution_tiles(); | 963 high_res->reset_may_contain_low_resolution_tiles(); |
952 } | 964 } |
953 high_res->set_resolution(HIGH_RESOLUTION); | 965 high_res->set_resolution(HIGH_RESOLUTION); |
954 | 966 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 tilings_->FindTilingWithScaleKey(low_res_raster_contents_scale_); | 1043 tilings_->FindTilingWithScaleKey(low_res_raster_contents_scale_); |
1032 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); | 1044 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); |
1033 | 1045 |
1034 // Only create new low res tilings when the transform is static. This | 1046 // Only create new low res tilings when the transform is static. This |
1035 // prevents wastefully creating a paired low res tiling for every new high | 1047 // prevents wastefully creating a paired low res tiling for every new high |
1036 // res tiling during a pinch or a CSS animation. | 1048 // res tiling during a pinch or a CSS animation. |
1037 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 1049 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
1038 bool is_animating = draw_properties().screen_space_transform_is_animating; | 1050 bool is_animating = draw_properties().screen_space_transform_is_animating; |
1039 if (!is_pinching && !is_animating) { | 1051 if (!is_pinching && !is_animating) { |
1040 if (!low_res) | 1052 if (!low_res) |
1041 low_res = AddTiling(low_res_raster_contents_scale_); | 1053 low_res = AddTiling(gfx::AxisTransform2d(low_res_raster_contents_scale_, |
| 1054 gfx::Vector2dF())); |
1042 low_res->set_resolution(LOW_RESOLUTION); | 1055 low_res->set_resolution(LOW_RESOLUTION); |
1043 } | 1056 } |
1044 } | 1057 } |
1045 | 1058 |
1046 void PictureLayerImpl::RecalculateRasterScales() { | 1059 void PictureLayerImpl::RecalculateRasterScales() { |
1047 if (is_directly_composited_image_) { | 1060 if (is_directly_composited_image_) { |
1048 if (!raster_source_scale_) | 1061 if (!raster_source_scale_) |
1049 raster_source_scale_ = 1.f; | 1062 raster_source_scale_ = 1.f; |
1050 | 1063 |
1051 float min_scale = MinimumContentsScale(); | 1064 float min_scale = MinimumContentsScale(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 } | 1210 } |
1198 | 1211 |
1199 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; | 1212 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; |
1200 tilings_->CleanUpTilings(min_acceptable_high_res_scale, | 1213 tilings_->CleanUpTilings(min_acceptable_high_res_scale, |
1201 max_acceptable_high_res_scale, used_tilings, | 1214 max_acceptable_high_res_scale, used_tilings, |
1202 twin_set); | 1215 twin_set); |
1203 DCHECK_GT(tilings_->num_tilings(), 0u); | 1216 DCHECK_GT(tilings_->num_tilings(), 0u); |
1204 SanityCheckTilingState(); | 1217 SanityCheckTilingState(); |
1205 } | 1218 } |
1206 | 1219 |
| 1220 gfx::Vector2dF PictureLayerImpl::CalculateRasterTranslation( |
| 1221 float raster_scale) { |
| 1222 if (!use_transformed_rasterization_) |
| 1223 return gfx::Vector2dF(); |
| 1224 |
| 1225 DCHECK(!draw_properties().screen_space_transform_is_animating); |
| 1226 gfx::Transform draw_transform = DrawTransform(); |
| 1227 DCHECK(draw_transform.IsScaleOrTranslation()); |
| 1228 |
| 1229 // It is only useful to align the content space to the target space if their |
| 1230 // relative pixel ratio is some small rational number. Currently we only |
| 1231 // align if the relative pixel ratio is 1:1. |
| 1232 // Good match if the maximum alignment error on a layer of size 10000px |
| 1233 // does not exceed 0.001px. |
| 1234 static constexpr float kErrorThreshold = 0.0000001f; |
| 1235 if (std::abs(draw_transform.matrix().getFloat(0, 0) - raster_scale) > |
| 1236 kErrorThreshold || |
| 1237 std::abs(draw_transform.matrix().getFloat(1, 1) - raster_scale) > |
| 1238 kErrorThreshold) |
| 1239 return gfx::Vector2dF(); |
| 1240 |
| 1241 // Extract the fractional part of layer origin in the target space. |
| 1242 float origin_x = draw_transform.matrix().getFloat(0, 3); |
| 1243 float origin_y = draw_transform.matrix().getFloat(1, 3); |
| 1244 return gfx::Vector2dF(origin_x - floorf(origin_x), |
| 1245 origin_y - floorf(origin_y)); |
| 1246 } |
| 1247 |
1207 float PictureLayerImpl::MinimumContentsScale() const { | 1248 float PictureLayerImpl::MinimumContentsScale() const { |
1208 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1249 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
1209 | 1250 |
1210 // If the contents scale is less than 1 / width (also for height), | 1251 // If the contents scale is less than 1 / width (also for height), |
1211 // then it will end up having less than one pixel of content in that | 1252 // then it will end up having less than one pixel of content in that |
1212 // dimension. Bump the minimum contents scale up in this case to prevent | 1253 // dimension. Bump the minimum contents scale up in this case to prevent |
1213 // this from happening. | 1254 // this from happening. |
1214 int min_dimension = std::min(raster_source_->GetSize().width(), | 1255 int min_dimension = std::min(raster_source_->GetSize().width(), |
1215 raster_source_->GetSize().height()); | 1256 raster_source_->GetSize().height()); |
1216 if (!min_dimension) | 1257 if (!min_dimension) |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 } | 1479 } |
1439 | 1480 |
1440 invalidation_.Union(invalidation); | 1481 invalidation_.Union(invalidation); |
1441 tilings_->UpdateTilingsForImplSideInvalidation(invalidation); | 1482 tilings_->UpdateTilingsForImplSideInvalidation(invalidation); |
1442 SetNeedsPushProperties(); | 1483 SetNeedsPushProperties(); |
1443 TRACE_EVENT_END1("cc", "PictureLayerImpl::InvalidateRegionForImages", | 1484 TRACE_EVENT_END1("cc", "PictureLayerImpl::InvalidateRegionForImages", |
1444 "Invalidation", invalidation.ToString()); | 1485 "Invalidation", invalidation.ToString()); |
1445 } | 1486 } |
1446 | 1487 |
1447 } // namespace cc | 1488 } // namespace cc |
OLD | NEW |