| 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 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 if (tilings_) | 406 if (tilings_) |
| 407 RemoveAllTilings(); | 407 RemoveAllTilings(); |
| 408 | 408 |
| 409 ResetRasterScale(); | 409 ResetRasterScale(); |
| 410 } | 410 } |
| 411 | 411 |
| 412 void PictureLayerImpl::CalculateContentsScale( | 412 void PictureLayerImpl::CalculateContentsScale( |
| 413 float ideal_contents_scale, | 413 float ideal_contents_scale, |
| 414 float device_scale_factor, | 414 float device_scale_factor, |
| 415 float page_scale_factor, | 415 float page_scale_factor, |
| 416 float maximum_animation_contents_scale, |
| 416 bool animating_transform_to_screen, | 417 bool animating_transform_to_screen, |
| 417 float* contents_scale_x, | 418 float* contents_scale_x, |
| 418 float* contents_scale_y, | 419 float* contents_scale_y, |
| 419 gfx::Size* content_bounds) { | 420 gfx::Size* content_bounds) { |
| 420 DoPostCommitInitializationIfNeeded(); | 421 DoPostCommitInitializationIfNeeded(); |
| 421 | 422 |
| 422 // This function sets valid raster scales and manages tilings, so tile | 423 // This function sets valid raster scales and manages tilings, so tile |
| 423 // priorities can now be updated. | 424 // priorities can now be updated. |
| 424 should_update_tile_priorities_ = true; | 425 should_update_tile_priorities_ = true; |
| 425 | 426 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 448 float ideal_page_scale = page_scale_factor; | 449 float ideal_page_scale = page_scale_factor; |
| 449 float ideal_device_scale = device_scale_factor; | 450 float ideal_device_scale = device_scale_factor; |
| 450 float ideal_source_scale = | 451 float ideal_source_scale = |
| 451 ideal_contents_scale / ideal_page_scale / ideal_device_scale; | 452 ideal_contents_scale / ideal_page_scale / ideal_device_scale; |
| 452 | 453 |
| 453 ideal_contents_scale_ = std::max(ideal_contents_scale, min_contents_scale); | 454 ideal_contents_scale_ = std::max(ideal_contents_scale, min_contents_scale); |
| 454 ideal_page_scale_ = ideal_page_scale; | 455 ideal_page_scale_ = ideal_page_scale; |
| 455 ideal_device_scale_ = ideal_device_scale; | 456 ideal_device_scale_ = ideal_device_scale; |
| 456 ideal_source_scale_ = std::max(ideal_source_scale, min_source_scale); | 457 ideal_source_scale_ = std::max(ideal_source_scale, min_source_scale); |
| 457 | 458 |
| 458 ManageTilings(animating_transform_to_screen); | 459 ManageTilings(animating_transform_to_screen, |
| 460 maximum_animation_contents_scale); |
| 459 | 461 |
| 460 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious. | 462 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious. |
| 461 // There are (usually) several tilings at different scales. However, the | 463 // There are (usually) several tilings at different scales. However, the |
| 462 // content bounds is the (integer!) space in which quads are generated. | 464 // content bounds is the (integer!) space in which quads are generated. |
| 463 // In order to guarantee that we can fill this integer space with any set of | 465 // In order to guarantee that we can fill this integer space with any set of |
| 464 // tilings (and then map back to floating point texture coordinates), the | 466 // tilings (and then map back to floating point texture coordinates), the |
| 465 // contents scale must be at least as large as the largest of the tilings. | 467 // contents scale must be at least as large as the largest of the tilings. |
| 466 float max_contents_scale = min_contents_scale; | 468 float max_contents_scale = min_contents_scale; |
| 467 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 469 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 468 const PictureLayerTiling* tiling = tilings_->tiling_at(i); | 470 const PictureLayerTiling* tiling = tilings_->tiling_at(i); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 namespace { | 912 namespace { |
| 911 | 913 |
| 912 inline float PositiveRatio(float float1, float float2) { | 914 inline float PositiveRatio(float float1, float float2) { |
| 913 DCHECK_GT(float1, 0); | 915 DCHECK_GT(float1, 0); |
| 914 DCHECK_GT(float2, 0); | 916 DCHECK_GT(float2, 0); |
| 915 return float1 > float2 ? float1 / float2 : float2 / float1; | 917 return float1 > float2 ? float1 / float2 : float2 / float1; |
| 916 } | 918 } |
| 917 | 919 |
| 918 } // namespace | 920 } // namespace |
| 919 | 921 |
| 920 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) { | 922 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen, |
| 923 float maximum_animation_contents_scale) { |
| 921 DCHECK(ideal_contents_scale_); | 924 DCHECK(ideal_contents_scale_); |
| 922 DCHECK(ideal_page_scale_); | 925 DCHECK(ideal_page_scale_); |
| 923 DCHECK(ideal_device_scale_); | 926 DCHECK(ideal_device_scale_); |
| 924 DCHECK(ideal_source_scale_); | 927 DCHECK(ideal_source_scale_); |
| 925 DCHECK(CanHaveTilings()); | 928 DCHECK(CanHaveTilings()); |
| 926 DCHECK(!needs_post_commit_initialization_); | 929 DCHECK(!needs_post_commit_initialization_); |
| 927 | 930 |
| 928 bool change_target_tiling = | 931 bool change_target_tiling = |
| 929 raster_page_scale_ == 0.f || | 932 raster_page_scale_ == 0.f || |
| 930 raster_device_scale_ == 0.f || | 933 raster_device_scale_ == 0.f || |
| 931 raster_source_scale_ == 0.f || | 934 raster_source_scale_ == 0.f || |
| 932 raster_contents_scale_ == 0.f || | 935 raster_contents_scale_ == 0.f || |
| 933 low_res_raster_contents_scale_ == 0.f || | 936 low_res_raster_contents_scale_ == 0.f || |
| 934 ShouldAdjustRasterScale(animating_transform_to_screen); | 937 ShouldAdjustRasterScale(animating_transform_to_screen); |
| 935 | 938 |
| 936 if (tilings_->num_tilings() == 0) { | 939 if (tilings_->num_tilings() == 0) { |
| 937 DCHECK(change_target_tiling) | 940 DCHECK(change_target_tiling) |
| 938 << "A layer with no tilings shouldn't have valid raster scales"; | 941 << "A layer with no tilings shouldn't have valid raster scales"; |
| 939 } | 942 } |
| 940 | 943 |
| 941 // Store the value for the next time ShouldAdjustRasterScale is called. | 944 // Store the value for the next time ShouldAdjustRasterScale is called. |
| 942 raster_source_scale_was_animating_ = animating_transform_to_screen; | 945 raster_source_scale_was_animating_ = animating_transform_to_screen; |
| 943 | 946 |
| 944 if (!change_target_tiling) | 947 if (!change_target_tiling) |
| 945 return; | 948 return; |
| 946 | 949 |
| 947 if (!layer_tree_impl()->device_viewport_valid_for_tile_management()) | 950 if (!layer_tree_impl()->device_viewport_valid_for_tile_management()) |
| 948 return; | 951 return; |
| 949 | 952 |
| 950 RecalculateRasterScales(animating_transform_to_screen); | 953 RecalculateRasterScales(animating_transform_to_screen, |
| 954 maximum_animation_contents_scale); |
| 951 | 955 |
| 952 PictureLayerTiling* high_res = NULL; | 956 PictureLayerTiling* high_res = NULL; |
| 953 PictureLayerTiling* low_res = NULL; | 957 PictureLayerTiling* low_res = NULL; |
| 954 | 958 |
| 955 PictureLayerTiling* previous_low_res = NULL; | 959 PictureLayerTiling* previous_low_res = NULL; |
| 956 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 960 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 957 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 961 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
| 958 if (tiling->contents_scale() == raster_contents_scale_) | 962 if (tiling->contents_scale() == raster_contents_scale_) |
| 959 high_res = tiling; | 963 high_res = tiling; |
| 960 if (tiling->contents_scale() == low_res_raster_contents_scale_) | 964 if (tiling->contents_scale() == low_res_raster_contents_scale_) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 SanityCheckTilingState(); | 997 SanityCheckTilingState(); |
| 994 } | 998 } |
| 995 | 999 |
| 996 bool PictureLayerImpl::ShouldAdjustRasterScale( | 1000 bool PictureLayerImpl::ShouldAdjustRasterScale( |
| 997 bool animating_transform_to_screen) const { | 1001 bool animating_transform_to_screen) const { |
| 998 // TODO(danakj): Adjust raster source scale closer to ideal source scale at | 1002 // TODO(danakj): Adjust raster source scale closer to ideal source scale at |
| 999 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending | 1003 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending |
| 1000 // tree. This will allow CSS scale changes to get re-rastered at an | 1004 // tree. This will allow CSS scale changes to get re-rastered at an |
| 1001 // appropriate rate. | 1005 // appropriate rate. |
| 1002 | 1006 |
| 1003 if (raster_source_scale_was_animating_ && !animating_transform_to_screen) | 1007 if (raster_source_scale_was_animating_ != animating_transform_to_screen) |
| 1004 return true; | 1008 return true; |
| 1005 | 1009 |
| 1006 if (animating_transform_to_screen && | 1010 if (animating_transform_to_screen && |
| 1007 raster_contents_scale_ != ideal_contents_scale_ && | 1011 raster_contents_scale_ != ideal_contents_scale_ && |
| 1008 ShouldUseGpuRasterization()) | 1012 ShouldUseGpuRasterization()) |
| 1009 return true; | 1013 return true; |
| 1010 | 1014 |
| 1011 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 1015 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
| 1012 if (is_pinching && raster_page_scale_) { | 1016 if (is_pinching && raster_page_scale_) { |
| 1013 // We change our raster scale when it is: | 1017 // We change our raster scale when it is: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1041 float ratio = PositiveRatio(tiling_contents_scale, scale); | 1045 float ratio = PositiveRatio(tiling_contents_scale, scale); |
| 1042 if (ratio < snapped_ratio) { | 1046 if (ratio < snapped_ratio) { |
| 1043 snapped_contents_scale = tiling_contents_scale; | 1047 snapped_contents_scale = tiling_contents_scale; |
| 1044 snapped_ratio = ratio; | 1048 snapped_ratio = ratio; |
| 1045 } | 1049 } |
| 1046 } | 1050 } |
| 1047 return snapped_contents_scale; | 1051 return snapped_contents_scale; |
| 1048 } | 1052 } |
| 1049 | 1053 |
| 1050 void PictureLayerImpl::RecalculateRasterScales( | 1054 void PictureLayerImpl::RecalculateRasterScales( |
| 1051 bool animating_transform_to_screen) { | 1055 bool animating_transform_to_screen, |
| 1056 float maximum_animation_contents_scale) { |
| 1052 raster_device_scale_ = ideal_device_scale_; | 1057 raster_device_scale_ = ideal_device_scale_; |
| 1053 raster_source_scale_ = ideal_source_scale_; | 1058 raster_source_scale_ = ideal_source_scale_; |
| 1054 | 1059 |
| 1055 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 1060 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
| 1056 if (!is_pinching || raster_contents_scale_ == 0.f) { | 1061 if (!is_pinching || raster_contents_scale_ == 0.f) { |
| 1057 // When not pinching or when we have no previous scale, we use ideal scale: | 1062 // When not pinching or when we have no previous scale, we use ideal scale: |
| 1058 raster_page_scale_ = ideal_page_scale_; | 1063 raster_page_scale_ = ideal_page_scale_; |
| 1059 raster_contents_scale_ = ideal_contents_scale_; | 1064 raster_contents_scale_ = ideal_contents_scale_; |
| 1060 } else { | 1065 } else { |
| 1061 // See ShouldAdjustRasterScale: | 1066 // See ShouldAdjustRasterScale: |
| 1062 // - When zooming out, preemptively create new tiling at lower resolution. | 1067 // - When zooming out, preemptively create new tiling at lower resolution. |
| 1063 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. | 1068 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. |
| 1064 bool zooming_out = raster_page_scale_ > ideal_page_scale_; | 1069 bool zooming_out = raster_page_scale_ > ideal_page_scale_; |
| 1065 float desired_contents_scale = | 1070 float desired_contents_scale = |
| 1066 zooming_out ? raster_contents_scale_ / kMaxScaleRatioDuringPinch | 1071 zooming_out ? raster_contents_scale_ / kMaxScaleRatioDuringPinch |
| 1067 : raster_contents_scale_ * kMaxScaleRatioDuringPinch; | 1072 : raster_contents_scale_ * kMaxScaleRatioDuringPinch; |
| 1068 raster_contents_scale_ = SnappedContentsScale(desired_contents_scale); | 1073 raster_contents_scale_ = SnappedContentsScale(desired_contents_scale); |
| 1069 raster_page_scale_ = raster_contents_scale_ / raster_device_scale_; | 1074 raster_page_scale_ = raster_contents_scale_ / raster_device_scale_; |
| 1070 } | 1075 } |
| 1071 | 1076 |
| 1072 raster_contents_scale_ = | 1077 raster_contents_scale_ = |
| 1073 std::max(raster_contents_scale_, MinimumContentsScale()); | 1078 std::max(raster_contents_scale_, MinimumContentsScale()); |
| 1074 | 1079 |
| 1075 // Don't allow animating CSS scales to drop below 1 if we're not | 1080 // If we're not re-rasterizing during animation, rasterize at the maximum |
| 1076 // re-rasterizing during the animation. | 1081 // scale that will occur during the animation, if the maximum scale is |
| 1082 // known. |
| 1077 if (animating_transform_to_screen && !ShouldUseGpuRasterization()) { | 1083 if (animating_transform_to_screen && !ShouldUseGpuRasterization()) { |
| 1078 raster_contents_scale_ = std::max( | 1084 if (maximum_animation_contents_scale > 0.f) { |
| 1079 raster_contents_scale_, 1.f * ideal_page_scale_ * ideal_device_scale_); | 1085 raster_contents_scale_ = |
| 1086 std::max(raster_contents_scale_, maximum_animation_contents_scale); |
| 1087 } else { |
| 1088 raster_contents_scale_ = |
| 1089 std::max(raster_contents_scale_, |
| 1090 1.f * ideal_page_scale_ * ideal_device_scale_); |
| 1091 } |
| 1080 } | 1092 } |
| 1081 | 1093 |
| 1082 // If this layer would only create one tile at this content scale, | 1094 // If this layer would only create one tile at this content scale, |
| 1083 // don't create a low res tiling. | 1095 // don't create a low res tiling. |
| 1084 gfx::Size content_bounds = | 1096 gfx::Size content_bounds = |
| 1085 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), raster_contents_scale_)); | 1097 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), raster_contents_scale_)); |
| 1086 gfx::Size tile_size = CalculateTileSize(content_bounds); | 1098 gfx::Size tile_size = CalculateTileSize(content_bounds); |
| 1087 if (tile_size.width() >= content_bounds.width() && | 1099 if (tile_size.width() >= content_bounds.width() && |
| 1088 tile_size.height() >= content_bounds.height()) { | 1100 tile_size.height() >= content_bounds.height()) { |
| 1089 low_res_raster_contents_scale_ = raster_contents_scale_; | 1101 low_res_raster_contents_scale_ = raster_contents_scale_; |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 return iterator_index_ < iterators_.size(); | 1503 return iterator_index_ < iterators_.size(); |
| 1492 } | 1504 } |
| 1493 | 1505 |
| 1494 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( | 1506 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( |
| 1495 PictureLayerTiling::TilingEvictionTileIterator* it) const { | 1507 PictureLayerTiling::TilingEvictionTileIterator* it) const { |
| 1496 return it->get_type() == iteration_stage_ && | 1508 return it->get_type() == iteration_stage_ && |
| 1497 (**it)->required_for_activation() == required_for_activation_; | 1509 (**it)->required_for_activation() == required_for_activation_; |
| 1498 } | 1510 } |
| 1499 | 1511 |
| 1500 } // namespace cc | 1512 } // namespace cc |
| OLD | NEW |