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

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

Issue 2565643002: [5/5] Add translated rasterization for PictureLayerImpl (Closed)
Patch Set: rebase && add unittests for slot conflict resolution and raster translation update policy Created 3 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
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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 } 725 }
726 726
727 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( 727 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling(
728 const PictureLayerTiling* tiling) const { 728 const PictureLayerTiling* tiling) const {
729 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); 729 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer();
730 if (!twin_layer) 730 if (!twin_layer)
731 return nullptr; 731 return nullptr;
732 const PictureLayerTiling* twin_tiling = 732 const PictureLayerTiling* twin_tiling =
733 twin_layer->tilings_->FindTilingWithScaleKey( 733 twin_layer->tilings_->FindTilingWithScaleKey(
734 tiling->contents_scale_key()); 734 tiling->contents_scale_key());
735 DCHECK(tiling->raster_transform().translation() == gfx::Vector2dF()); 735 if (twin_tiling &&
736 DCHECK(!twin_tiling || 736 twin_tiling->raster_transform() == tiling->raster_transform())
737 twin_tiling->raster_transform().translation() == gfx::Vector2dF()); 737 return twin_tiling;
738 return twin_tiling; 738 return nullptr;
739 } 739 }
740 740
741 bool PictureLayerImpl::RequiresHighResToDraw() const { 741 bool PictureLayerImpl::RequiresHighResToDraw() const {
742 return layer_tree_impl()->RequiresHighResToDraw(); 742 return layer_tree_impl()->RequiresHighResToDraw();
743 } 743 }
744 744
745 gfx::Rect PictureLayerImpl::GetEnclosingRectInTargetSpace() const { 745 gfx::Rect PictureLayerImpl::GetEnclosingRectInTargetSpace() const {
746 return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale()); 746 return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale());
747 } 747 }
748 748
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 } 884 }
885 885
886 void PictureLayerImpl::SetUseTransformedRasterization(bool use) { 886 void PictureLayerImpl::SetUseTransformedRasterization(bool use) {
887 if (use_transformed_rasterization_ == use) 887 if (use_transformed_rasterization_ == use)
888 return; 888 return;
889 889
890 use_transformed_rasterization_ = use; 890 use_transformed_rasterization_ = use;
891 NoteLayerPropertyChanged(); 891 NoteLayerPropertyChanged();
892 } 892 }
893 893
894 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 894 PictureLayerTiling* PictureLayerImpl::AddTiling(
895 const ScaleTranslate2d& contents_transform) {
895 DCHECK(CanHaveTilings()); 896 DCHECK(CanHaveTilings());
896 DCHECK_GE(contents_scale, MinimumContentsScale()); 897 DCHECK_GE(contents_transform.scale(), MinimumContentsScale());
897 DCHECK_LE(contents_scale, MaximumContentsScale()); 898 DCHECK_LE(contents_transform.scale(), MaximumContentsScale());
898 DCHECK(raster_source_->HasRecordings()); 899 DCHECK(raster_source_->HasRecordings());
899 return tilings_->AddTiling(ScaleTranslate2d(contents_scale, gfx::Vector2dF()), 900 return tilings_->AddTiling(contents_transform, raster_source_);
900 raster_source_);
901 } 901 }
902 902
903 void PictureLayerImpl::RemoveAllTilings() { 903 void PictureLayerImpl::RemoveAllTilings() {
904 tilings_->RemoveAllTilings(); 904 tilings_->RemoveAllTilings();
905 // If there are no tilings, then raster scales are no longer meaningful. 905 // If there are no tilings, then raster scales are no longer meaningful.
906 ResetRasterScale(); 906 ResetRasterScale();
907 } 907 }
908 908
909 void PictureLayerImpl::AddTilingsForRasterScale() { 909 void PictureLayerImpl::AddTilingsForRasterScale() {
910 // Reset all resolution enums on tilings, we'll be setting new values in this 910 // Reset all resolution enums on tilings, we'll be setting new values in this
911 // function. 911 // function.
912 tilings_->MarkAllTilingsNonIdeal(); 912 tilings_->MarkAllTilingsNonIdeal();
913 913
914 PictureLayerTiling* high_res = 914 PictureLayerTiling* high_res =
915 tilings_->FindTilingWithScaleKey(raster_contents_scale_); 915 tilings_->FindTilingWithScaleKey(raster_contents_scale_);
916 gfx::Vector2dF raster_translation =
917 CalculateRasterTranslation(raster_contents_scale_);
918 if (high_res &&
919 high_res->raster_transform().translation() != raster_translation) {
920 tilings_->Remove(high_res);
921 high_res = nullptr;
922 }
916 if (!high_res) { 923 if (!high_res) {
917 // We always need a high res tiling, so create one if it doesn't exist. 924 // We always need a high res tiling, so create one if it doesn't exist.
918 high_res = AddTiling(raster_contents_scale_); 925 high_res =
926 AddTiling(ScaleTranslate2d(raster_contents_scale_, raster_translation));
919 } else if (high_res->may_contain_low_resolution_tiles()) { 927 } else if (high_res->may_contain_low_resolution_tiles()) {
920 // If the tiling we find here was LOW_RESOLUTION previously, it may not be 928 // If the tiling we find here was LOW_RESOLUTION previously, it may not be
921 // fully rastered, so destroy the old tiles. 929 // fully rastered, so destroy the old tiles.
922 high_res->Reset(); 930 high_res->Reset();
923 // Reset the flag now that we'll make it high res, it will have fully 931 // Reset the flag now that we'll make it high res, it will have fully
924 // rastered content. 932 // rastered content.
925 high_res->reset_may_contain_low_resolution_tiles(); 933 high_res->reset_may_contain_low_resolution_tiles();
926 } 934 }
927 high_res->set_resolution(HIGH_RESOLUTION); 935 high_res->set_resolution(HIGH_RESOLUTION);
928 936
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 tilings_->FindTilingWithScaleKey(low_res_raster_contents_scale_); 1013 tilings_->FindTilingWithScaleKey(low_res_raster_contents_scale_);
1006 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); 1014 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION);
1007 1015
1008 // Only create new low res tilings when the transform is static. This 1016 // Only create new low res tilings when the transform is static. This
1009 // prevents wastefully creating a paired low res tiling for every new high 1017 // prevents wastefully creating a paired low res tiling for every new high
1010 // res tiling during a pinch or a CSS animation. 1018 // res tiling during a pinch or a CSS animation.
1011 bool is_pinching = layer_tree_impl()->PinchGestureActive(); 1019 bool is_pinching = layer_tree_impl()->PinchGestureActive();
1012 bool is_animating = draw_properties().screen_space_transform_is_animating; 1020 bool is_animating = draw_properties().screen_space_transform_is_animating;
1013 if (!is_pinching && !is_animating) { 1021 if (!is_pinching && !is_animating) {
1014 if (!low_res) 1022 if (!low_res)
1015 low_res = AddTiling(low_res_raster_contents_scale_); 1023 low_res = AddTiling(
1024 ScaleTranslate2d(low_res_raster_contents_scale_, gfx::Vector2dF()));
1016 low_res->set_resolution(LOW_RESOLUTION); 1025 low_res->set_resolution(LOW_RESOLUTION);
1017 } 1026 }
1018 } 1027 }
1019 1028
1020 void PictureLayerImpl::RecalculateRasterScales() { 1029 void PictureLayerImpl::RecalculateRasterScales() {
1021 if (is_directly_composited_image_) { 1030 if (is_directly_composited_image_) {
1022 if (!raster_source_scale_) 1031 if (!raster_source_scale_)
1023 raster_source_scale_ = 1.f; 1032 raster_source_scale_ = 1.f;
1024 1033
1025 float min_scale = MinimumContentsScale(); 1034 float min_scale = MinimumContentsScale();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 } 1180 }
1172 1181
1173 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; 1182 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr;
1174 tilings_->CleanUpTilings(min_acceptable_high_res_scale, 1183 tilings_->CleanUpTilings(min_acceptable_high_res_scale,
1175 max_acceptable_high_res_scale, used_tilings, 1184 max_acceptable_high_res_scale, used_tilings,
1176 twin_set); 1185 twin_set);
1177 DCHECK_GT(tilings_->num_tilings(), 0u); 1186 DCHECK_GT(tilings_->num_tilings(), 0u);
1178 SanityCheckTilingState(); 1187 SanityCheckTilingState();
1179 } 1188 }
1180 1189
1190 gfx::Vector2dF PictureLayerImpl::CalculateRasterTranslation(
1191 float raster_scale) {
1192 if (!use_transformed_rasterization_)
1193 return gfx::Vector2dF();
1194
1195 DCHECK(!draw_properties().screen_space_transform_is_animating);
1196 gfx::Transform draw_transform = DrawTransform();
1197 DCHECK(draw_transform.IsScaleOrTranslation());
1198
1199 // It is only useful to align the content space to the target space if their
1200 // relative pixel ratio is some small rational number. Currently we only
1201 // align if the relative pixel ratio is 1:1.
1202 // Good match if the maximum alignment error on a layer of size 10000px
1203 // does not exceed 0.001px.
1204 static constexpr float kErrorThreshold = 0.0000001f;
1205 if (std::abs(draw_transform.matrix().getFloat(0, 0) - raster_scale) >
1206 kErrorThreshold ||
1207 std::abs(draw_transform.matrix().getFloat(1, 1) - raster_scale) >
1208 kErrorThreshold)
1209 return gfx::Vector2dF();
1210
1211 // Extract the fractional part of layer origin in the target space.
1212 float origin_x = draw_transform.matrix().getFloat(0, 3);
1213 float origin_y = draw_transform.matrix().getFloat(1, 3);
1214 return gfx::Vector2dF(origin_x - floorf(origin_x),
1215 origin_y - floorf(origin_y));
1216 }
1217
1181 float PictureLayerImpl::MinimumContentsScale() const { 1218 float PictureLayerImpl::MinimumContentsScale() const {
1182 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; 1219 float setting_min = layer_tree_impl()->settings().minimum_contents_scale;
1183 1220
1184 // If the contents scale is less than 1 / width (also for height), 1221 // If the contents scale is less than 1 / width (also for height),
1185 // then it will end up having less than one pixel of content in that 1222 // then it will end up having less than one pixel of content in that
1186 // dimension. Bump the minimum contents scale up in this case to prevent 1223 // dimension. Bump the minimum contents scale up in this case to prevent
1187 // this from happening. 1224 // this from happening.
1188 int min_dimension = std::min(raster_source_->GetSize().width(), 1225 int min_dimension = std::min(raster_source_->GetSize().width(),
1189 raster_source_->GetSize().height()); 1226 raster_source_->GetSize().height());
1190 if (!min_dimension) 1227 if (!min_dimension)
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 } 1449 }
1413 1450
1414 invalidation_.Union(invalidation); 1451 invalidation_.Union(invalidation);
1415 tilings_->UpdateTilingsForImplSideInvalidation(invalidation); 1452 tilings_->UpdateTilingsForImplSideInvalidation(invalidation);
1416 SetNeedsPushProperties(); 1453 SetNeedsPushProperties();
1417 TRACE_EVENT_END1("cc", "PictureLayerImpl::InvalidateRegionForImages", 1454 TRACE_EVENT_END1("cc", "PictureLayerImpl::InvalidateRegionForImages",
1418 "Invalidation", invalidation.ToString()); 1455 "Invalidation", invalidation.ToString());
1419 } 1456 }
1420 1457
1421 } // namespace cc 1458 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698