| 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_scale_factor, |
| 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, maximum_animation_scale_factor); |
| 459 | 460 |
| 460 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious. | 461 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious. |
| 461 // There are (usually) several tilings at different scales. However, the | 462 // There are (usually) several tilings at different scales. However, the |
| 462 // content bounds is the (integer!) space in which quads are generated. | 463 // 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 | 464 // 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 | 465 // 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. | 466 // contents scale must be at least as large as the largest of the tilings. |
| 466 float max_contents_scale = min_contents_scale; | 467 float max_contents_scale = min_contents_scale; |
| 467 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 468 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 468 const PictureLayerTiling* tiling = tilings_->tiling_at(i); | 469 const PictureLayerTiling* tiling = tilings_->tiling_at(i); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 namespace { | 911 namespace { |
| 911 | 912 |
| 912 inline float PositiveRatio(float float1, float float2) { | 913 inline float PositiveRatio(float float1, float float2) { |
| 913 DCHECK_GT(float1, 0); | 914 DCHECK_GT(float1, 0); |
| 914 DCHECK_GT(float2, 0); | 915 DCHECK_GT(float2, 0); |
| 915 return float1 > float2 ? float1 / float2 : float2 / float1; | 916 return float1 > float2 ? float1 / float2 : float2 / float1; |
| 916 } | 917 } |
| 917 | 918 |
| 918 } // namespace | 919 } // namespace |
| 919 | 920 |
| 920 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) { | 921 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen, |
| 922 float maximum_animation_scale_factor) { |
| 921 DCHECK(ideal_contents_scale_); | 923 DCHECK(ideal_contents_scale_); |
| 922 DCHECK(ideal_page_scale_); | 924 DCHECK(ideal_page_scale_); |
| 923 DCHECK(ideal_device_scale_); | 925 DCHECK(ideal_device_scale_); |
| 924 DCHECK(ideal_source_scale_); | 926 DCHECK(ideal_source_scale_); |
| 925 DCHECK(CanHaveTilings()); | 927 DCHECK(CanHaveTilings()); |
| 926 DCHECK(!needs_post_commit_initialization_); | 928 DCHECK(!needs_post_commit_initialization_); |
| 927 | 929 |
| 928 bool change_target_tiling = | 930 bool change_target_tiling = |
| 929 raster_page_scale_ == 0.f || | 931 raster_page_scale_ == 0.f || |
| 930 raster_device_scale_ == 0.f || | 932 raster_device_scale_ == 0.f || |
| 931 raster_source_scale_ == 0.f || | 933 raster_source_scale_ == 0.f || |
| 932 raster_contents_scale_ == 0.f || | 934 raster_contents_scale_ == 0.f || |
| 933 low_res_raster_contents_scale_ == 0.f || | 935 low_res_raster_contents_scale_ == 0.f || |
| 934 ShouldAdjustRasterScale(animating_transform_to_screen); | 936 ShouldAdjustRasterScale(animating_transform_to_screen); |
| 935 | 937 |
| 936 if (tilings_->num_tilings() == 0) { | 938 if (tilings_->num_tilings() == 0) { |
| 937 DCHECK(change_target_tiling) | 939 DCHECK(change_target_tiling) |
| 938 << "A layer with no tilings shouldn't have valid raster scales"; | 940 << "A layer with no tilings shouldn't have valid raster scales"; |
| 939 } | 941 } |
| 940 | 942 |
| 941 // Store the value for the next time ShouldAdjustRasterScale is called. | 943 // Store the value for the next time ShouldAdjustRasterScale is called. |
| 942 raster_source_scale_was_animating_ = animating_transform_to_screen; | 944 raster_source_scale_was_animating_ = animating_transform_to_screen; |
| 943 | 945 |
| 944 if (!change_target_tiling) | 946 if (!change_target_tiling) |
| 945 return; | 947 return; |
| 946 | 948 |
| 947 if (!layer_tree_impl()->device_viewport_valid_for_tile_management()) | 949 if (!layer_tree_impl()->device_viewport_valid_for_tile_management()) |
| 948 return; | 950 return; |
| 949 | 951 |
| 950 RecalculateRasterScales(animating_transform_to_screen); | 952 RecalculateRasterScales(animating_transform_to_screen, |
| 953 maximum_animation_scale_factor); |
| 951 | 954 |
| 952 PictureLayerTiling* high_res = NULL; | 955 PictureLayerTiling* high_res = NULL; |
| 953 PictureLayerTiling* low_res = NULL; | 956 PictureLayerTiling* low_res = NULL; |
| 954 | 957 |
| 955 PictureLayerTiling* previous_low_res = NULL; | 958 PictureLayerTiling* previous_low_res = NULL; |
| 956 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 959 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 957 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 960 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
| 958 if (tiling->contents_scale() == raster_contents_scale_) | 961 if (tiling->contents_scale() == raster_contents_scale_) |
| 959 high_res = tiling; | 962 high_res = tiling; |
| 960 if (tiling->contents_scale() == low_res_raster_contents_scale_) | 963 if (tiling->contents_scale() == low_res_raster_contents_scale_) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 SanityCheckTilingState(); | 996 SanityCheckTilingState(); |
| 994 } | 997 } |
| 995 | 998 |
| 996 bool PictureLayerImpl::ShouldAdjustRasterScale( | 999 bool PictureLayerImpl::ShouldAdjustRasterScale( |
| 997 bool animating_transform_to_screen) const { | 1000 bool animating_transform_to_screen) const { |
| 998 // TODO(danakj): Adjust raster source scale closer to ideal source scale at | 1001 // TODO(danakj): Adjust raster source scale closer to ideal source scale at |
| 999 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending | 1002 // 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 | 1003 // tree. This will allow CSS scale changes to get re-rastered at an |
| 1001 // appropriate rate. | 1004 // appropriate rate. |
| 1002 | 1005 |
| 1003 if (raster_source_scale_was_animating_ && !animating_transform_to_screen) | 1006 if (raster_source_scale_was_animating_ != animating_transform_to_screen) |
| 1004 return true; | 1007 return true; |
| 1005 | 1008 |
| 1006 if (animating_transform_to_screen && | 1009 if (animating_transform_to_screen && |
| 1007 raster_contents_scale_ != ideal_contents_scale_ && | 1010 raster_contents_scale_ != ideal_contents_scale_ && |
| 1008 ShouldUseGpuRasterization()) | 1011 ShouldUseGpuRasterization()) |
| 1009 return true; | 1012 return true; |
| 1010 | 1013 |
| 1011 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 1014 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
| 1012 if (is_pinching && raster_page_scale_) { | 1015 if (is_pinching && raster_page_scale_) { |
| 1013 // We change our raster scale when it is: | 1016 // We change our raster scale when it is: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1041 float ratio = PositiveRatio(tiling_contents_scale, scale); | 1044 float ratio = PositiveRatio(tiling_contents_scale, scale); |
| 1042 if (ratio < snapped_ratio) { | 1045 if (ratio < snapped_ratio) { |
| 1043 snapped_contents_scale = tiling_contents_scale; | 1046 snapped_contents_scale = tiling_contents_scale; |
| 1044 snapped_ratio = ratio; | 1047 snapped_ratio = ratio; |
| 1045 } | 1048 } |
| 1046 } | 1049 } |
| 1047 return snapped_contents_scale; | 1050 return snapped_contents_scale; |
| 1048 } | 1051 } |
| 1049 | 1052 |
| 1050 void PictureLayerImpl::RecalculateRasterScales( | 1053 void PictureLayerImpl::RecalculateRasterScales( |
| 1051 bool animating_transform_to_screen) { | 1054 bool animating_transform_to_screen, |
| 1055 float maximum_animation_scale_factor) { |
| 1052 raster_device_scale_ = ideal_device_scale_; | 1056 raster_device_scale_ = ideal_device_scale_; |
| 1053 raster_source_scale_ = ideal_source_scale_; | 1057 raster_source_scale_ = ideal_source_scale_; |
| 1054 | 1058 |
| 1055 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 1059 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
| 1056 if (!is_pinching || raster_contents_scale_ == 0.f) { | 1060 if (!is_pinching || raster_contents_scale_ == 0.f) { |
| 1057 // When not pinching or when we have no previous scale, we use ideal scale: | 1061 // When not pinching or when we have no previous scale, we use ideal scale: |
| 1058 raster_page_scale_ = ideal_page_scale_; | 1062 raster_page_scale_ = ideal_page_scale_; |
| 1059 raster_contents_scale_ = ideal_contents_scale_; | 1063 raster_contents_scale_ = ideal_contents_scale_; |
| 1060 } else { | 1064 } else { |
| 1061 // See ShouldAdjustRasterScale: | 1065 // See ShouldAdjustRasterScale: |
| 1062 // - When zooming out, preemptively create new tiling at lower resolution. | 1066 // - When zooming out, preemptively create new tiling at lower resolution. |
| 1063 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. | 1067 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. |
| 1064 bool zooming_out = raster_page_scale_ > ideal_page_scale_; | 1068 bool zooming_out = raster_page_scale_ > ideal_page_scale_; |
| 1065 float desired_contents_scale = | 1069 float desired_contents_scale = |
| 1066 zooming_out ? raster_contents_scale_ / kMaxScaleRatioDuringPinch | 1070 zooming_out ? raster_contents_scale_ / kMaxScaleRatioDuringPinch |
| 1067 : raster_contents_scale_ * kMaxScaleRatioDuringPinch; | 1071 : raster_contents_scale_ * kMaxScaleRatioDuringPinch; |
| 1068 raster_contents_scale_ = SnappedContentsScale(desired_contents_scale); | 1072 raster_contents_scale_ = SnappedContentsScale(desired_contents_scale); |
| 1069 raster_page_scale_ = raster_contents_scale_ / raster_device_scale_; | 1073 raster_page_scale_ = raster_contents_scale_ / raster_device_scale_; |
| 1070 } | 1074 } |
| 1071 | 1075 |
| 1072 raster_contents_scale_ = | 1076 raster_contents_scale_ = |
| 1073 std::max(raster_contents_scale_, MinimumContentsScale()); | 1077 std::max(raster_contents_scale_, MinimumContentsScale()); |
| 1074 | 1078 |
| 1075 // Don't allow animating CSS scales to drop below 1 if we're not | 1079 // If we're not re-rasterizing during animation, rasterize at the maximum |
| 1076 // re-rasterizing during the animation. | 1080 // scale that will occur during the animation, if the maximum scale is |
| 1081 // known. |
| 1077 if (animating_transform_to_screen && !ShouldUseGpuRasterization()) { | 1082 if (animating_transform_to_screen && !ShouldUseGpuRasterization()) { |
| 1078 raster_contents_scale_ = std::max( | 1083 if (maximum_animation_scale_factor > 0.f) { |
| 1079 raster_contents_scale_, 1.f * ideal_page_scale_ * ideal_device_scale_); | 1084 raster_contents_scale_ = |
| 1085 std::max(raster_contents_scale_, |
| 1086 maximum_animation_scale_factor * ideal_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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 DCHECK(*this); | 1378 DCHECK(*this); |
| 1367 | 1379 |
| 1368 IteratorType index = stages_[current_stage_].iterator_type; | 1380 IteratorType index = stages_[current_stage_].iterator_type; |
| 1369 DCHECK(iterators_[index]); | 1381 DCHECK(iterators_[index]); |
| 1370 DCHECK(iterators_[index].get_type() == stages_[current_stage_].tile_type); | 1382 DCHECK(iterators_[index].get_type() == stages_[current_stage_].tile_type); |
| 1371 | 1383 |
| 1372 return *iterators_[index]; | 1384 return *iterators_[index]; |
| 1373 } | 1385 } |
| 1374 | 1386 |
| 1375 } // namespace cc | 1387 } // namespace cc |
| OLD | NEW |