Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: cc/layers/picture_layer_impl.cc

Issue 226283004: Rasterize at maximum scale for scale animations on CPU-rasterized layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/picture_layer_impl.h ('k') | cc/layers/picture_layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 if (tilings_) 410 if (tilings_)
411 RemoveAllTilings(); 411 RemoveAllTilings();
412 412
413 ResetRasterScale(); 413 ResetRasterScale();
414 } 414 }
415 415
416 void PictureLayerImpl::CalculateContentsScale( 416 void PictureLayerImpl::CalculateContentsScale(
417 float ideal_contents_scale, 417 float ideal_contents_scale,
418 float device_scale_factor, 418 float device_scale_factor,
419 float page_scale_factor, 419 float page_scale_factor,
420 float maximum_animation_contents_scale,
420 bool animating_transform_to_screen, 421 bool animating_transform_to_screen,
421 float* contents_scale_x, 422 float* contents_scale_x,
422 float* contents_scale_y, 423 float* contents_scale_y,
423 gfx::Size* content_bounds) { 424 gfx::Size* content_bounds) {
424 DoPostCommitInitializationIfNeeded(); 425 DoPostCommitInitializationIfNeeded();
425 426
426 // This function sets valid raster scales and manages tilings, so tile 427 // This function sets valid raster scales and manages tilings, so tile
427 // priorities can now be updated. 428 // priorities can now be updated.
428 should_update_tile_priorities_ = true; 429 should_update_tile_priorities_ = true;
429 430
(...skipping 22 matching lines...) Expand all
452 float ideal_page_scale = page_scale_factor; 453 float ideal_page_scale = page_scale_factor;
453 float ideal_device_scale = device_scale_factor; 454 float ideal_device_scale = device_scale_factor;
454 float ideal_source_scale = 455 float ideal_source_scale =
455 ideal_contents_scale / ideal_page_scale / ideal_device_scale; 456 ideal_contents_scale / ideal_page_scale / ideal_device_scale;
456 457
457 ideal_contents_scale_ = std::max(ideal_contents_scale, min_contents_scale); 458 ideal_contents_scale_ = std::max(ideal_contents_scale, min_contents_scale);
458 ideal_page_scale_ = ideal_page_scale; 459 ideal_page_scale_ = ideal_page_scale;
459 ideal_device_scale_ = ideal_device_scale; 460 ideal_device_scale_ = ideal_device_scale;
460 ideal_source_scale_ = std::max(ideal_source_scale, min_source_scale); 461 ideal_source_scale_ = std::max(ideal_source_scale, min_source_scale);
461 462
462 ManageTilings(animating_transform_to_screen); 463 ManageTilings(animating_transform_to_screen,
464 maximum_animation_contents_scale);
463 465
464 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious. 466 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious.
465 // There are (usually) several tilings at different scales. However, the 467 // There are (usually) several tilings at different scales. However, the
466 // content bounds is the (integer!) space in which quads are generated. 468 // content bounds is the (integer!) space in which quads are generated.
467 // In order to guarantee that we can fill this integer space with any set of 469 // In order to guarantee that we can fill this integer space with any set of
468 // tilings (and then map back to floating point texture coordinates), the 470 // tilings (and then map back to floating point texture coordinates), the
469 // contents scale must be at least as large as the largest of the tilings. 471 // contents scale must be at least as large as the largest of the tilings.
470 float max_contents_scale = min_contents_scale; 472 float max_contents_scale = min_contents_scale;
471 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 473 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
472 const PictureLayerTiling* tiling = tilings_->tiling_at(i); 474 const PictureLayerTiling* tiling = tilings_->tiling_at(i);
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 namespace { 909 namespace {
908 910
909 inline float PositiveRatio(float float1, float float2) { 911 inline float PositiveRatio(float float1, float float2) {
910 DCHECK_GT(float1, 0); 912 DCHECK_GT(float1, 0);
911 DCHECK_GT(float2, 0); 913 DCHECK_GT(float2, 0);
912 return float1 > float2 ? float1 / float2 : float2 / float1; 914 return float1 > float2 ? float1 / float2 : float2 / float1;
913 } 915 }
914 916
915 } // namespace 917 } // namespace
916 918
917 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen) { 919 void PictureLayerImpl::ManageTilings(bool animating_transform_to_screen,
920 float maximum_animation_contents_scale) {
918 DCHECK(ideal_contents_scale_); 921 DCHECK(ideal_contents_scale_);
919 DCHECK(ideal_page_scale_); 922 DCHECK(ideal_page_scale_);
920 DCHECK(ideal_device_scale_); 923 DCHECK(ideal_device_scale_);
921 DCHECK(ideal_source_scale_); 924 DCHECK(ideal_source_scale_);
922 DCHECK(CanHaveTilings()); 925 DCHECK(CanHaveTilings());
923 DCHECK(!needs_post_commit_initialization_); 926 DCHECK(!needs_post_commit_initialization_);
924 927
925 bool change_target_tiling = 928 bool change_target_tiling =
926 raster_page_scale_ == 0.f || 929 raster_page_scale_ == 0.f ||
927 raster_device_scale_ == 0.f || 930 raster_device_scale_ == 0.f ||
928 raster_source_scale_ == 0.f || 931 raster_source_scale_ == 0.f ||
929 raster_contents_scale_ == 0.f || 932 raster_contents_scale_ == 0.f ||
930 low_res_raster_contents_scale_ == 0.f || 933 low_res_raster_contents_scale_ == 0.f ||
931 ShouldAdjustRasterScale(animating_transform_to_screen); 934 ShouldAdjustRasterScale(animating_transform_to_screen);
932 935
933 if (tilings_->num_tilings() == 0) { 936 if (tilings_->num_tilings() == 0) {
934 DCHECK(change_target_tiling) 937 DCHECK(change_target_tiling)
935 << "A layer with no tilings shouldn't have valid raster scales"; 938 << "A layer with no tilings shouldn't have valid raster scales";
936 } 939 }
937 940
938 // Store the value for the next time ShouldAdjustRasterScale is called. 941 // Store the value for the next time ShouldAdjustRasterScale is called.
939 raster_source_scale_was_animating_ = animating_transform_to_screen; 942 raster_source_scale_was_animating_ = animating_transform_to_screen;
940 943
941 if (!change_target_tiling) 944 if (!change_target_tiling)
942 return; 945 return;
943 946
944 if (!layer_tree_impl()->device_viewport_valid_for_tile_management()) 947 if (!layer_tree_impl()->device_viewport_valid_for_tile_management())
945 return; 948 return;
946 949
947 RecalculateRasterScales(animating_transform_to_screen); 950 RecalculateRasterScales(animating_transform_to_screen,
951 maximum_animation_contents_scale);
948 952
949 PictureLayerTiling* high_res = NULL; 953 PictureLayerTiling* high_res = NULL;
950 PictureLayerTiling* low_res = NULL; 954 PictureLayerTiling* low_res = NULL;
951 955
952 PictureLayerTiling* previous_low_res = NULL; 956 PictureLayerTiling* previous_low_res = NULL;
953 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 957 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
954 PictureLayerTiling* tiling = tilings_->tiling_at(i); 958 PictureLayerTiling* tiling = tilings_->tiling_at(i);
955 if (tiling->contents_scale() == raster_contents_scale_) 959 if (tiling->contents_scale() == raster_contents_scale_)
956 high_res = tiling; 960 high_res = tiling;
957 if (tiling->contents_scale() == low_res_raster_contents_scale_) 961 if (tiling->contents_scale() == low_res_raster_contents_scale_)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 SanityCheckTilingState(); 994 SanityCheckTilingState();
991 } 995 }
992 996
993 bool PictureLayerImpl::ShouldAdjustRasterScale( 997 bool PictureLayerImpl::ShouldAdjustRasterScale(
994 bool animating_transform_to_screen) const { 998 bool animating_transform_to_screen) const {
995 // TODO(danakj): Adjust raster source scale closer to ideal source scale at 999 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
996 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending 1000 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
997 // tree. This will allow CSS scale changes to get re-rastered at an 1001 // tree. This will allow CSS scale changes to get re-rastered at an
998 // appropriate rate. 1002 // appropriate rate.
999 1003
1000 if (raster_source_scale_was_animating_ && !animating_transform_to_screen) 1004 if (raster_source_scale_was_animating_ != animating_transform_to_screen)
1001 return true; 1005 return true;
1002 1006
1003 if (animating_transform_to_screen && 1007 if (animating_transform_to_screen &&
1004 raster_contents_scale_ != ideal_contents_scale_ && 1008 raster_contents_scale_ != ideal_contents_scale_ &&
1005 ShouldUseGpuRasterization()) 1009 ShouldUseGpuRasterization())
1006 return true; 1010 return true;
1007 1011
1008 bool is_pinching = layer_tree_impl()->PinchGestureActive(); 1012 bool is_pinching = layer_tree_impl()->PinchGestureActive();
1009 if (is_pinching && raster_page_scale_) { 1013 if (is_pinching && raster_page_scale_) {
1010 // We change our raster scale when it is: 1014 // We change our raster scale when it is:
(...skipping 27 matching lines...) Expand all
1038 float ratio = PositiveRatio(tiling_contents_scale, scale); 1042 float ratio = PositiveRatio(tiling_contents_scale, scale);
1039 if (ratio < snapped_ratio) { 1043 if (ratio < snapped_ratio) {
1040 snapped_contents_scale = tiling_contents_scale; 1044 snapped_contents_scale = tiling_contents_scale;
1041 snapped_ratio = ratio; 1045 snapped_ratio = ratio;
1042 } 1046 }
1043 } 1047 }
1044 return snapped_contents_scale; 1048 return snapped_contents_scale;
1045 } 1049 }
1046 1050
1047 void PictureLayerImpl::RecalculateRasterScales( 1051 void PictureLayerImpl::RecalculateRasterScales(
1048 bool animating_transform_to_screen) { 1052 bool animating_transform_to_screen,
1053 float maximum_animation_contents_scale) {
1049 raster_device_scale_ = ideal_device_scale_; 1054 raster_device_scale_ = ideal_device_scale_;
1050 raster_source_scale_ = ideal_source_scale_; 1055 raster_source_scale_ = ideal_source_scale_;
1051 1056
1052 bool is_pinching = layer_tree_impl()->PinchGestureActive(); 1057 bool is_pinching = layer_tree_impl()->PinchGestureActive();
1053 if (!is_pinching || raster_contents_scale_ == 0.f) { 1058 if (!is_pinching || raster_contents_scale_ == 0.f) {
1054 // When not pinching or when we have no previous scale, we use ideal scale: 1059 // When not pinching or when we have no previous scale, we use ideal scale:
1055 raster_page_scale_ = ideal_page_scale_; 1060 raster_page_scale_ = ideal_page_scale_;
1056 raster_contents_scale_ = ideal_contents_scale_; 1061 raster_contents_scale_ = ideal_contents_scale_;
1057 } else { 1062 } else {
1058 // See ShouldAdjustRasterScale: 1063 // See ShouldAdjustRasterScale:
1059 // - When zooming out, preemptively create new tiling at lower resolution. 1064 // - When zooming out, preemptively create new tiling at lower resolution.
1060 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. 1065 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
1061 bool zooming_out = raster_page_scale_ > ideal_page_scale_; 1066 bool zooming_out = raster_page_scale_ > ideal_page_scale_;
1062 float desired_contents_scale = 1067 float desired_contents_scale =
1063 zooming_out ? raster_contents_scale_ / kMaxScaleRatioDuringPinch 1068 zooming_out ? raster_contents_scale_ / kMaxScaleRatioDuringPinch
1064 : raster_contents_scale_ * kMaxScaleRatioDuringPinch; 1069 : raster_contents_scale_ * kMaxScaleRatioDuringPinch;
1065 raster_contents_scale_ = SnappedContentsScale(desired_contents_scale); 1070 raster_contents_scale_ = SnappedContentsScale(desired_contents_scale);
1066 raster_page_scale_ = raster_contents_scale_ / raster_device_scale_; 1071 raster_page_scale_ = raster_contents_scale_ / raster_device_scale_;
1067 } 1072 }
1068 1073
1069 raster_contents_scale_ = 1074 raster_contents_scale_ =
1070 std::max(raster_contents_scale_, MinimumContentsScale()); 1075 std::max(raster_contents_scale_, MinimumContentsScale());
1071 1076
1072 // Don't allow animating CSS scales to drop below 1 if we're not 1077 // If we're not re-rasterizing during animation, rasterize at the maximum
1073 // re-rasterizing during the animation. 1078 // scale that will occur during the animation, if the maximum scale is
1079 // known.
1074 if (animating_transform_to_screen && !ShouldUseGpuRasterization()) { 1080 if (animating_transform_to_screen && !ShouldUseGpuRasterization()) {
1075 raster_contents_scale_ = std::max( 1081 if (maximum_animation_contents_scale > 0.f) {
1076 raster_contents_scale_, 1.f * ideal_page_scale_ * ideal_device_scale_); 1082 raster_contents_scale_ =
1083 std::max(raster_contents_scale_, maximum_animation_contents_scale);
1084 } else {
1085 raster_contents_scale_ =
1086 std::max(raster_contents_scale_,
1087 1.f * ideal_page_scale_ * ideal_device_scale_);
1088 }
1077 } 1089 }
1078 1090
1079 // If this layer would only create one tile at this content scale, 1091 // If this layer would only create one tile at this content scale,
1080 // don't create a low res tiling. 1092 // don't create a low res tiling.
1081 gfx::Size content_bounds = 1093 gfx::Size content_bounds =
1082 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), raster_contents_scale_)); 1094 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), raster_contents_scale_));
1083 gfx::Size tile_size = CalculateTileSize(content_bounds); 1095 gfx::Size tile_size = CalculateTileSize(content_bounds);
1084 if (tile_size.width() >= content_bounds.width() && 1096 if (tile_size.width() >= content_bounds.width() &&
1085 tile_size.height() >= content_bounds.height()) { 1097 tile_size.height() >= content_bounds.height()) {
1086 low_res_raster_contents_scale_ = raster_contents_scale_; 1098 low_res_raster_contents_scale_ = raster_contents_scale_;
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 return iterator_index_ < iterators_.size(); 1500 return iterator_index_ < iterators_.size();
1489 } 1501 }
1490 1502
1491 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( 1503 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType(
1492 PictureLayerTiling::TilingEvictionTileIterator* it) const { 1504 PictureLayerTiling::TilingEvictionTileIterator* it) const {
1493 return it->get_type() == iteration_stage_ && 1505 return it->get_type() == iteration_stage_ &&
1494 (**it)->required_for_activation() == required_for_activation_; 1506 (**it)->required_for_activation() == required_for_activation_;
1495 } 1507 }
1496 1508
1497 } // namespace cc 1509 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer_impl.h ('k') | cc/layers/picture_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698