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

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

Issue 2068413002: cc: Remove fixed raster scale, stop rasterizing with will-change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compile fix Created 4 years, 6 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
« 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, 62 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl,
63 int id, 63 int id,
64 bool is_mask) 64 bool is_mask)
65 : LayerImpl(tree_impl, id), 65 : LayerImpl(tree_impl, id),
66 twin_layer_(nullptr), 66 twin_layer_(nullptr),
67 tilings_(CreatePictureLayerTilingSet()), 67 tilings_(CreatePictureLayerTilingSet()),
68 ideal_page_scale_(0.f), 68 ideal_page_scale_(0.f),
69 ideal_device_scale_(0.f), 69 ideal_device_scale_(0.f),
70 ideal_source_scale_(0.f), 70 ideal_source_scale_(0.f),
71 ideal_contents_scale_(0.f), 71 ideal_contents_scale_(0.f),
72 last_ideal_source_scale_(0.f),
73 raster_page_scale_(0.f), 72 raster_page_scale_(0.f),
74 raster_device_scale_(0.f), 73 raster_device_scale_(0.f),
75 raster_source_scale_(0.f), 74 raster_source_scale_(0.f),
76 raster_contents_scale_(0.f), 75 raster_contents_scale_(0.f),
77 low_res_raster_contents_scale_(0.f), 76 low_res_raster_contents_scale_(0.f),
78 raster_source_scale_is_fixed_(false),
79 was_screen_space_transform_animating_(false), 77 was_screen_space_transform_animating_(false),
80 only_used_low_res_last_append_quads_(false), 78 only_used_low_res_last_append_quads_(false),
81 is_mask_(is_mask), 79 is_mask_(is_mask),
82 nearest_neighbor_(false) { 80 nearest_neighbor_(false) {
83 layer_tree_impl()->RegisterPictureLayerImpl(this); 81 layer_tree_impl()->RegisterPictureLayerImpl(this);
84 } 82 }
85 83
86 PictureLayerImpl::~PictureLayerImpl() { 84 PictureLayerImpl::~PictureLayerImpl() {
87 if (twin_layer_) 85 if (twin_layer_)
88 twin_layer_->twin_layer_ = nullptr; 86 twin_layer_->twin_layer_ = nullptr;
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 if (layer_tree_impl()->IsActiveTree()) 425 if (layer_tree_impl()->IsActiveTree())
428 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_); 426 CleanUpTilingsOnActiveLayer(last_append_quads_tilings_);
429 427
430 UpdateIdealScales(); 428 UpdateIdealScales();
431 429
432 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { 430 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) {
433 RecalculateRasterScales(); 431 RecalculateRasterScales();
434 AddTilingsForRasterScale(); 432 AddTilingsForRasterScale();
435 } 433 }
436 434
437 // Inform layer tree impl if we will have blurry content because of fixed
438 // raster scale (note that this check should happen after we
439 // ReclaculateRasterScales, since that's the function that will determine
440 // whether our raster scale is fixed.
441 if (raster_source_scale_is_fixed_ && !has_will_change_transform_hint()) {
442 if (raster_source_scale_ != ideal_source_scale_)
443 layer_tree_impl()->SetFixedRasterScaleHasBlurryContent();
444 if (ideal_source_scale_ != last_ideal_source_scale_)
445 layer_tree_impl()->SetFixedRasterScaleAttemptedToChangeScale();
446 }
447
448 if (layer_tree_impl()->IsActiveTree()) 435 if (layer_tree_impl()->IsActiveTree())
449 AddLowResolutionTilingIfNeeded(); 436 AddLowResolutionTilingIfNeeded();
450 437
451 DCHECK(raster_page_scale_); 438 DCHECK(raster_page_scale_);
452 DCHECK(raster_device_scale_); 439 DCHECK(raster_device_scale_);
453 DCHECK(raster_source_scale_); 440 DCHECK(raster_source_scale_);
454 DCHECK(raster_contents_scale_); 441 DCHECK(raster_contents_scale_);
455 DCHECK(low_res_raster_contents_scale_); 442 DCHECK(low_res_raster_contents_scale_);
456 443
457 was_screen_space_transform_animating_ = 444 was_screen_space_transform_animating_ =
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 if (!is_pinching) { 895 if (!is_pinching) {
909 // When not pinching, match the ideal page scale factor. 896 // When not pinching, match the ideal page scale factor.
910 if (raster_page_scale_ != ideal_page_scale_) 897 if (raster_page_scale_ != ideal_page_scale_)
911 return true; 898 return true;
912 } 899 }
913 900
914 // Always match the ideal device scale factor. 901 // Always match the ideal device scale factor.
915 if (raster_device_scale_ != ideal_device_scale_) 902 if (raster_device_scale_ != ideal_device_scale_)
916 return true; 903 return true;
917 904
918 // When the source scale changes we want to match it, but not when animating
919 // or when we've fixed the scale in place.
920 if (!draw_properties().screen_space_transform_is_animating &&
921 !raster_source_scale_is_fixed_ &&
922 raster_source_scale_ != ideal_source_scale_)
923 return true;
924
925 if (raster_contents_scale_ > MaximumContentsScale()) 905 if (raster_contents_scale_ > MaximumContentsScale())
926 return true; 906 return true;
927 if (raster_contents_scale_ < MinimumContentsScale()) 907 if (raster_contents_scale_ < MinimumContentsScale())
928 return true; 908 return true;
929 909
930 return false; 910 // Don't change the raster scale if any of the following are true:
911 // - We have an animating transform.
912 // - We have a will-change transform hint.
913 // - The raster scale is already ideal.
914 if (draw_properties().screen_space_transform_is_animating ||
915 has_will_change_transform_hint() ||
916 raster_source_scale_ == ideal_source_scale_) {
917 return false;
918 }
919
920 // Match the raster scale in all other cases.
921 return true;
931 } 922 }
932 923
933 void PictureLayerImpl::AddLowResolutionTilingIfNeeded() { 924 void PictureLayerImpl::AddLowResolutionTilingIfNeeded() {
934 DCHECK(layer_tree_impl()->IsActiveTree()); 925 DCHECK(layer_tree_impl()->IsActiveTree());
935 926
936 if (!layer_tree_impl()->create_low_res_tiling()) 927 if (!layer_tree_impl()->create_low_res_tiling())
937 return; 928 return;
938 929
939 // We should have a high resolution tiling at raster_contents_scale, so if the 930 // We should have a high resolution tiling at raster_contents_scale, so if the
940 // low res one is the same then we shouldn't try to override this tiling by 931 // low res one is the same then we shouldn't try to override this tiling by
(...skipping 13 matching lines...) Expand all
954 if (!is_pinching && !is_animating) { 945 if (!is_pinching && !is_animating) {
955 if (!low_res) 946 if (!low_res)
956 low_res = AddTiling(low_res_raster_contents_scale_); 947 low_res = AddTiling(low_res_raster_contents_scale_);
957 low_res->set_resolution(LOW_RESOLUTION); 948 low_res->set_resolution(LOW_RESOLUTION);
958 } 949 }
959 } 950 }
960 951
961 void PictureLayerImpl::RecalculateRasterScales() { 952 void PictureLayerImpl::RecalculateRasterScales() {
962 float old_raster_contents_scale = raster_contents_scale_; 953 float old_raster_contents_scale = raster_contents_scale_;
963 float old_raster_page_scale = raster_page_scale_; 954 float old_raster_page_scale = raster_page_scale_;
964 float old_raster_source_scale = raster_source_scale_;
965 955
966 raster_device_scale_ = ideal_device_scale_; 956 raster_device_scale_ = ideal_device_scale_;
967 raster_page_scale_ = ideal_page_scale_; 957 raster_page_scale_ = ideal_page_scale_;
968 raster_source_scale_ = ideal_source_scale_; 958 raster_source_scale_ = ideal_source_scale_;
969 raster_contents_scale_ = ideal_contents_scale_; 959 raster_contents_scale_ = ideal_contents_scale_;
970 960
971 // If we're not animating, or leaving an animation, and the
972 // ideal_source_scale_ changes, then things are unpredictable, and we fix
973 // the raster_source_scale_ in place.
974 if (old_raster_source_scale &&
975 !draw_properties().screen_space_transform_is_animating &&
976 !was_screen_space_transform_animating_ &&
977 old_raster_source_scale != ideal_source_scale_)
978 raster_source_scale_is_fixed_ = true;
979
980 // TODO(danakj): Adjust raster source scale closer to ideal source scale at
981 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending
982 // tree. This will allow CSS scale changes to get re-rastered at an
983 // appropriate rate. (crbug.com/413636)
984 if (raster_source_scale_is_fixed_) {
985 raster_contents_scale_ /= raster_source_scale_;
986 raster_source_scale_ = 1.f;
987 }
988
989 // During pinch we completely ignore the current ideal scale, and just use 961 // During pinch we completely ignore the current ideal scale, and just use
990 // a multiple of the previous scale. 962 // a multiple of the previous scale.
991 bool is_pinching = layer_tree_impl()->PinchGestureActive(); 963 bool is_pinching = layer_tree_impl()->PinchGestureActive();
992 if (is_pinching && old_raster_contents_scale) { 964 if (is_pinching && old_raster_contents_scale) {
993 // See ShouldAdjustRasterScale: 965 // See ShouldAdjustRasterScale:
994 // - When zooming out, preemptively create new tiling at lower resolution. 966 // - When zooming out, preemptively create new tiling at lower resolution.
995 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. 967 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio.
996 bool zooming_out = old_raster_page_scale > ideal_page_scale_; 968 bool zooming_out = old_raster_page_scale > ideal_page_scale_;
997 float desired_contents_scale = old_raster_contents_scale; 969 float desired_contents_scale = old_raster_contents_scale;
998 if (zooming_out) { 970 if (zooming_out) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 // up larger than |max_texture_size|. 1121 // up larger than |max_texture_size|.
1150 return nextafterf(max_scale, 0.f); 1122 return nextafterf(max_scale, 0.f);
1151 } 1123 }
1152 1124
1153 void PictureLayerImpl::ResetRasterScale() { 1125 void PictureLayerImpl::ResetRasterScale() {
1154 raster_page_scale_ = 0.f; 1126 raster_page_scale_ = 0.f;
1155 raster_device_scale_ = 0.f; 1127 raster_device_scale_ = 0.f;
1156 raster_source_scale_ = 0.f; 1128 raster_source_scale_ = 0.f;
1157 raster_contents_scale_ = 0.f; 1129 raster_contents_scale_ = 0.f;
1158 low_res_raster_contents_scale_ = 0.f; 1130 low_res_raster_contents_scale_ = 0.f;
1159 raster_source_scale_is_fixed_ = false;
1160 } 1131 }
1161 1132
1162 bool PictureLayerImpl::CanHaveTilings() const { 1133 bool PictureLayerImpl::CanHaveTilings() const {
1163 if (raster_source_->IsSolidColor()) 1134 if (raster_source_->IsSolidColor())
1164 return false; 1135 return false;
1165 if (!DrawsContent()) 1136 if (!DrawsContent())
1166 return false; 1137 return false;
1167 if (!raster_source_->HasRecordings()) 1138 if (!raster_source_->HasRecordings())
1168 return false; 1139 return false;
1169 // If the |raster_source_| has a recording it should have non-empty bounds. 1140 // If the |raster_source_| has a recording it should have non-empty bounds.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 DCHECK(CanHaveTilings()); 1182 DCHECK(CanHaveTilings());
1212 1183
1213 float min_contents_scale = MinimumContentsScale(); 1184 float min_contents_scale = MinimumContentsScale();
1214 DCHECK_GT(min_contents_scale, 0.f); 1185 DCHECK_GT(min_contents_scale, 0.f);
1215 1186
1216 ideal_page_scale_ = IsAffectedByPageScale() 1187 ideal_page_scale_ = IsAffectedByPageScale()
1217 ? layer_tree_impl()->current_page_scale_factor() 1188 ? layer_tree_impl()->current_page_scale_factor()
1218 : 1.f; 1189 : 1.f;
1219 ideal_device_scale_ = layer_tree_impl()->device_scale_factor(); 1190 ideal_device_scale_ = layer_tree_impl()->device_scale_factor();
1220 ideal_contents_scale_ = std::max(GetIdealContentsScale(), min_contents_scale); 1191 ideal_contents_scale_ = std::max(GetIdealContentsScale(), min_contents_scale);
1221 last_ideal_source_scale_ = ideal_source_scale_;
1222 ideal_source_scale_ = 1192 ideal_source_scale_ =
1223 ideal_contents_scale_ / ideal_page_scale_ / ideal_device_scale_; 1193 ideal_contents_scale_ / ideal_page_scale_ / ideal_device_scale_;
1224 } 1194 }
1225 1195
1226 void PictureLayerImpl::GetDebugBorderProperties( 1196 void PictureLayerImpl::GetDebugBorderProperties(
1227 SkColor* color, 1197 SkColor* color,
1228 float* width) const { 1198 float* width) const {
1229 *color = DebugColors::TiledContentLayerBorderColor(); 1199 *color = DebugColors::TiledContentLayerBorderColor();
1230 *width = DebugColors::TiledContentLayerBorderWidth(layer_tree_impl()); 1200 *width = DebugColors::TiledContentLayerBorderWidth(layer_tree_impl());
1231 } 1201 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { 1261 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1292 return !layer_tree_impl()->IsRecycleTree(); 1262 return !layer_tree_impl()->IsRecycleTree();
1293 } 1263 }
1294 1264
1295 bool PictureLayerImpl::HasValidTilePriorities() const { 1265 bool PictureLayerImpl::HasValidTilePriorities() const {
1296 return IsOnActiveOrPendingTree() && 1266 return IsOnActiveOrPendingTree() &&
1297 is_drawn_render_surface_layer_list_member(); 1267 is_drawn_render_surface_layer_list_member();
1298 } 1268 }
1299 1269
1300 } // namespace cc 1270 } // 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