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

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

Issue 2175553002: Raster PictureLayerTiling with fractional translation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Raster PictureLayerTiling with fractional translation Created 4 years, 5 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 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 823 }
824 824
825 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { 825 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) {
826 if (nearest_neighbor_ == nearest_neighbor) 826 if (nearest_neighbor_ == nearest_neighbor)
827 return; 827 return;
828 828
829 nearest_neighbor_ = nearest_neighbor; 829 nearest_neighbor_ = nearest_neighbor;
830 NoteLayerPropertyChanged(); 830 NoteLayerPropertyChanged();
831 } 831 }
832 832
833 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 833 PictureLayerTiling* PictureLayerImpl::AddTiling(
834 float contents_scale,
835 const gfx::Vector2dF& contents_translation) {
834 DCHECK(CanHaveTilings()); 836 DCHECK(CanHaveTilings());
835 DCHECK_GE(contents_scale, MinimumContentsScale()); 837 DCHECK_GE(contents_scale, MinimumContentsScale());
836 DCHECK_LE(contents_scale, MaximumContentsScale()); 838 DCHECK_LE(contents_scale, MaximumContentsScale());
837 DCHECK(raster_source_->HasRecordings()); 839 DCHECK(raster_source_->HasRecordings());
838 return tilings_->AddTiling(contents_scale, raster_source_); 840 return tilings_->AddTiling(contents_scale, contents_translation,
841 raster_source_);
839 } 842 }
840 843
841 void PictureLayerImpl::RemoveAllTilings() { 844 void PictureLayerImpl::RemoveAllTilings() {
842 tilings_->RemoveAllTilings(); 845 tilings_->RemoveAllTilings();
843 // If there are no tilings, then raster scales are no longer meaningful. 846 // If there are no tilings, then raster scales are no longer meaningful.
844 ResetRasterScale(); 847 ResetRasterScale();
845 } 848 }
846 849
847 void PictureLayerImpl::AddTilingsForRasterScale() { 850 void PictureLayerImpl::AddTilingsForRasterScale() {
848 // Reset all resolution enums on tilings, we'll be setting new values in this 851 // Reset all resolution enums on tilings, we'll be setting new values in this
849 // function. 852 // function.
850 tilings_->MarkAllTilingsNonIdeal(); 853 tilings_->MarkAllTilingsNonIdeal();
851 854
852 PictureLayerTiling* high_res = 855 PictureLayerTiling* high_res =
853 tilings_->FindTilingWithScale(raster_contents_scale_); 856 tilings_->FindTilingWithScale(raster_contents_scale_);
857
858 if (high_res) {
859 gfx::Vector2dF translation_error =
860 high_res->contents_translation() - raster_contents_translation_;
861 float error_x = std::abs(translation_error.x());
862 float error_y = std::abs(translation_error.y());
863 // Handle wrap over.
864 error_x = error_x > 0.5f ? 1.f - error_x : error_x;
865 error_y = error_y > 0.5f ? 1.f - error_y : error_y;
866 static constexpr float kErrorThreshold = 0.001;
enne (OOO) 2016/07/26 00:22:16 Where does this number come from? Should you just
trchen 2016/08/03 06:06:06 I'm worrying about tiny errors due to FP precision
trchen 2016/08/03 22:41:19 Note: This code path is removed in patch set 2, as
867 if (error_x > kErrorThreshold || error_y > kErrorThreshold) {
868 tilings_->Remove(high_res);
enne (OOO) 2016/07/26 00:22:16 It'd be nice if RecalculateRasterTranslation did a
trchen 2016/08/03 06:06:06 Not necessary. The low-res tiling is not pixel-exa
869 high_res = nullptr;
870 }
871 }
872
854 if (!high_res) { 873 if (!high_res) {
855 // We always need a high res tiling, so create one if it doesn't exist. 874 // We always need a high res tiling, so create one if it doesn't exist.
856 high_res = AddTiling(raster_contents_scale_); 875 high_res = AddTiling(raster_contents_scale_, raster_contents_translation_);
857 } else if (high_res->may_contain_low_resolution_tiles()) { 876 } else if (high_res->may_contain_low_resolution_tiles()) {
858 // If the tiling we find here was LOW_RESOLUTION previously, it may not be 877 // If the tiling we find here was LOW_RESOLUTION previously, it may not be
859 // fully rastered, so destroy the old tiles. 878 // fully rastered, so destroy the old tiles.
860 high_res->Reset(); 879 high_res->Reset();
861 // Reset the flag now that we'll make it high res, it will have fully 880 // Reset the flag now that we'll make it high res, it will have fully
862 // rastered content. 881 // rastered content.
863 high_res->reset_may_contain_low_resolution_tiles(); 882 high_res->reset_may_contain_low_resolution_tiles();
864 } 883 }
865 high_res->set_resolution(HIGH_RESOLUTION); 884 high_res->set_resolution(HIGH_RESOLUTION);
866 885
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 tilings_->FindTilingWithScale(low_res_raster_contents_scale_); 967 tilings_->FindTilingWithScale(low_res_raster_contents_scale_);
949 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); 968 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION);
950 969
951 // Only create new low res tilings when the transform is static. This 970 // Only create new low res tilings when the transform is static. This
952 // prevents wastefully creating a paired low res tiling for every new high 971 // prevents wastefully creating a paired low res tiling for every new high
953 // res tiling during a pinch or a CSS animation. 972 // res tiling during a pinch or a CSS animation.
954 bool is_pinching = layer_tree_impl()->PinchGestureActive(); 973 bool is_pinching = layer_tree_impl()->PinchGestureActive();
955 bool is_animating = draw_properties().screen_space_transform_is_animating; 974 bool is_animating = draw_properties().screen_space_transform_is_animating;
956 if (!is_pinching && !is_animating) { 975 if (!is_pinching && !is_animating) {
957 if (!low_res) 976 if (!low_res)
958 low_res = AddTiling(low_res_raster_contents_scale_); 977 low_res = AddTiling(low_res_raster_contents_scale_, gfx::Vector2dF());
959 low_res->set_resolution(LOW_RESOLUTION); 978 low_res->set_resolution(LOW_RESOLUTION);
960 } 979 }
961 } 980 }
962 981
982 void PictureLayerImpl::RecalculateRasterTranslation() {
983 raster_contents_translation_ = gfx::Vector2dF();
984 if (draw_properties().screen_space_transform_is_animating)
enne (OOO) 2016/07/26 00:22:16 This is my biggest worry in the patch. I get that
danakj 2016/07/27 22:52:17 Here's use counters that enne is referring to for
trchen 2016/08/03 06:06:06 I chatted with chris and also thought through a nu
985 return;
986
987 gfx::Transform screen_space_transform = ScreenSpaceTransform();
988 if (!screen_space_transform.IsScaleOrTranslation())
enne (OOO) 2016/07/26 00:22:16 Should this just be "is translation?"
enne (OOO) 2016/07/26 00:22:16 Should this just be "is translation?"
trchen 2016/08/03 06:06:06 Many bug reports are due to layers with odd pixel
989 return;
990
991 // Good match if the maximum alignment error on a layer of size 10000px
992 // does not exceed 0.001px.
993 static constexpr float kErrorThreshold = 0.0000001f;
994 if (std::abs(screen_space_transform.matrix().getFloat(0, 0) -
995 raster_contents_scale_) > kErrorThreshold ||
996 std::abs(screen_space_transform.matrix().getFloat(1, 1) -
997 raster_contents_scale_) > kErrorThreshold)
998 return;
999
1000 float origin_x = screen_space_transform.matrix().getFloat(0, 3);
1001 float origin_y = screen_space_transform.matrix().getFloat(1, 3);
1002 raster_contents_translation_ =
1003 gfx::Vector2dF(origin_x - floorf(origin_x), origin_y - floorf(origin_y));
1004 }
1005
963 void PictureLayerImpl::RecalculateRasterScales() { 1006 void PictureLayerImpl::RecalculateRasterScales() {
964 if (is_directly_composited_image_) { 1007 if (is_directly_composited_image_) {
965 if (!raster_source_scale_) 1008 if (!raster_source_scale_)
966 raster_source_scale_ = 1.f; 1009 raster_source_scale_ = 1.f;
967 1010
968 float min_scale = MinimumContentsScale(); 1011 float min_scale = MinimumContentsScale();
969 float max_scale = std::max(1.f, MinimumContentsScale()); 1012 float max_scale = std::max(1.f, MinimumContentsScale());
970 float clamped_ideal_source_scale_ = 1013 float clamped_ideal_source_scale_ =
971 std::max(min_scale, std::min(ideal_source_scale_, max_scale)); 1014 std::max(min_scale, std::min(ideal_source_scale_, max_scale));
972 1015
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 raster_contents_scale_ = 1.f * ideal_page_scale_ * ideal_device_scale_; 1108 raster_contents_scale_ = 1.f * ideal_page_scale_ * ideal_device_scale_;
1066 } 1109 }
1067 1110
1068 raster_contents_scale_ = 1111 raster_contents_scale_ =
1069 std::max(raster_contents_scale_, MinimumContentsScale()); 1112 std::max(raster_contents_scale_, MinimumContentsScale());
1070 raster_contents_scale_ = 1113 raster_contents_scale_ =
1071 std::min(raster_contents_scale_, MaximumContentsScale()); 1114 std::min(raster_contents_scale_, MaximumContentsScale());
1072 DCHECK_GE(raster_contents_scale_, MinimumContentsScale()); 1115 DCHECK_GE(raster_contents_scale_, MinimumContentsScale());
1073 DCHECK_LE(raster_contents_scale_, MaximumContentsScale()); 1116 DCHECK_LE(raster_contents_scale_, MaximumContentsScale());
1074 1117
1118 RecalculateRasterTranslation();
1119
1075 // If this layer would create zero or one tiles at this content scale, 1120 // If this layer would create zero or one tiles at this content scale,
1076 // don't create a low res tiling. 1121 // don't create a low res tiling.
1077 gfx::Size raster_bounds = 1122 gfx::Size raster_bounds =
1078 gfx::ScaleToCeiledSize(raster_source_->GetSize(), raster_contents_scale_); 1123 gfx::ScaleToCeiledSize(raster_source_->GetSize(), raster_contents_scale_);
1079 gfx::Size tile_size = CalculateTileSize(raster_bounds); 1124 gfx::Size tile_size = CalculateTileSize(raster_bounds);
1080 bool tile_covers_bounds = tile_size.width() >= raster_bounds.width() && 1125 bool tile_covers_bounds = tile_size.width() >= raster_bounds.width() &&
1081 tile_size.height() >= raster_bounds.height(); 1126 tile_size.height() >= raster_bounds.height();
1082 if (tile_size.IsEmpty() || tile_covers_bounds) { 1127 if (tile_size.IsEmpty() || tile_covers_bounds) {
1083 low_res_raster_contents_scale_ = raster_contents_scale_; 1128 low_res_raster_contents_scale_ = raster_contents_scale_;
1084 return; 1129 return;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { 1349 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1305 return !layer_tree_impl()->IsRecycleTree(); 1350 return !layer_tree_impl()->IsRecycleTree();
1306 } 1351 }
1307 1352
1308 bool PictureLayerImpl::HasValidTilePriorities() const { 1353 bool PictureLayerImpl::HasValidTilePriorities() const {
1309 return IsOnActiveOrPendingTree() && 1354 return IsOnActiveOrPendingTree() &&
1310 is_drawn_render_surface_layer_list_member(); 1355 is_drawn_render_surface_layer_list_member();
1311 } 1356 }
1312 1357
1313 } // namespace cc 1358 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698