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

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: alternative: change raster translation if and only if raster scale mutates Created 4 years, 4 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_);
854 if (!high_res) { 857 if (!high_res) {
858 gfx::Vector2dF raster_translation = CalculateRasterTranslation();
855 // We always need a high res tiling, so create one if it doesn't exist. 859 // We always need a high res tiling, so create one if it doesn't exist.
856 high_res = AddTiling(raster_contents_scale_); 860 high_res = AddTiling(raster_contents_scale_, raster_translation);
857 } else if (high_res->may_contain_low_resolution_tiles()) { 861 } else if (high_res->may_contain_low_resolution_tiles()) {
858 // If the tiling we find here was LOW_RESOLUTION previously, it may not be 862 // If the tiling we find here was LOW_RESOLUTION previously, it may not be
859 // fully rastered, so destroy the old tiles. 863 // fully rastered, so destroy the old tiles.
860 high_res->Reset(); 864 high_res->Reset();
861 // Reset the flag now that we'll make it high res, it will have fully 865 // Reset the flag now that we'll make it high res, it will have fully
862 // rastered content. 866 // rastered content.
863 high_res->reset_may_contain_low_resolution_tiles(); 867 high_res->reset_may_contain_low_resolution_tiles();
864 } 868 }
865 high_res->set_resolution(HIGH_RESOLUTION); 869 high_res->set_resolution(HIGH_RESOLUTION);
866 870
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 tilings_->FindTilingWithScale(low_res_raster_contents_scale_); 952 tilings_->FindTilingWithScale(low_res_raster_contents_scale_);
949 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); 953 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION);
950 954
951 // Only create new low res tilings when the transform is static. This 955 // 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 956 // prevents wastefully creating a paired low res tiling for every new high
953 // res tiling during a pinch or a CSS animation. 957 // res tiling during a pinch or a CSS animation.
954 bool is_pinching = layer_tree_impl()->PinchGestureActive(); 958 bool is_pinching = layer_tree_impl()->PinchGestureActive();
955 bool is_animating = draw_properties().screen_space_transform_is_animating; 959 bool is_animating = draw_properties().screen_space_transform_is_animating;
956 if (!is_pinching && !is_animating) { 960 if (!is_pinching && !is_animating) {
957 if (!low_res) 961 if (!low_res)
958 low_res = AddTiling(low_res_raster_contents_scale_); 962 low_res = AddTiling(low_res_raster_contents_scale_, gfx::Vector2dF());
959 low_res->set_resolution(LOW_RESOLUTION); 963 low_res->set_resolution(LOW_RESOLUTION);
960 } 964 }
961 } 965 }
962 966
967 gfx::Vector2dF PictureLayerImpl::CalculateRasterTranslation() {
enne (OOO) 2016/08/09 21:02:36 I think this function should use draw transform an
trchen 2016/08/10 01:44:14 Agreed. However ajuma@ mentioned that target trans
ajuma 2016/08/10 13:32:04 More specifically, once we're able to dynamically
enne (OOO) 2016/08/10 18:35:05 I think it is *required* that this approach change
968 if (draw_properties().screen_space_transform_is_animating)
969 return gfx::Vector2dF();
970
971 gfx::Transform screen_space_transform = ScreenSpaceTransform();
972 if (!screen_space_transform.IsScaleOrTranslation())
973 return gfx::Vector2dF();
974
975 // Good match if the maximum alignment error on a layer of size 10000px
976 // does not exceed 0.001px.
977 static constexpr float kErrorThreshold = 0.0000001f;
978 if (std::abs(screen_space_transform.matrix().getFloat(0, 0) -
979 raster_contents_scale_) > kErrorThreshold ||
980 std::abs(screen_space_transform.matrix().getFloat(1, 1) -
981 raster_contents_scale_) > kErrorThreshold)
982 return gfx::Vector2dF();
983
984 float origin_x = screen_space_transform.matrix().getFloat(0, 3);
985 float origin_y = screen_space_transform.matrix().getFloat(1, 3);
986 return gfx::Vector2dF(origin_x - floorf(origin_x),
987 origin_y - floorf(origin_y));
988 }
989
963 void PictureLayerImpl::RecalculateRasterScales() { 990 void PictureLayerImpl::RecalculateRasterScales() {
964 if (is_directly_composited_image_) { 991 if (is_directly_composited_image_) {
965 if (!raster_source_scale_) 992 if (!raster_source_scale_)
966 raster_source_scale_ = 1.f; 993 raster_source_scale_ = 1.f;
967 994
968 float min_scale = MinimumContentsScale(); 995 float min_scale = MinimumContentsScale();
969 float max_scale = std::max(1.f, MinimumContentsScale()); 996 float max_scale = std::max(1.f, MinimumContentsScale());
970 float clamped_ideal_source_scale_ = 997 float clamped_ideal_source_scale_ =
971 std::max(min_scale, std::min(ideal_source_scale_, max_scale)); 998 std::max(min_scale, std::min(ideal_source_scale_, max_scale));
972 999
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { 1331 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1305 return !layer_tree_impl()->IsRecycleTree(); 1332 return !layer_tree_impl()->IsRecycleTree();
1306 } 1333 }
1307 1334
1308 bool PictureLayerImpl::HasValidTilePriorities() const { 1335 bool PictureLayerImpl::HasValidTilePriorities() const {
1309 return IsOnActiveOrPendingTree() && 1336 return IsOnActiveOrPendingTree() &&
1310 is_drawn_render_surface_layer_list_member(); 1337 is_drawn_render_surface_layer_list_member();
1311 } 1338 }
1312 1339
1313 } // namespace cc 1340 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698