Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 } | 844 } |
| 845 | 845 |
| 846 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { | 846 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { |
| 847 if (nearest_neighbor_ == nearest_neighbor) | 847 if (nearest_neighbor_ == nearest_neighbor) |
| 848 return; | 848 return; |
| 849 | 849 |
| 850 nearest_neighbor_ = nearest_neighbor; | 850 nearest_neighbor_ = nearest_neighbor; |
| 851 NoteLayerPropertyChanged(); | 851 NoteLayerPropertyChanged(); |
| 852 } | 852 } |
| 853 | 853 |
| 854 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 854 PictureLayerTiling* PictureLayerImpl::AddTiling( |
| 855 float contents_scale, | |
| 856 const gfx::Vector2dF& contents_translation) { | |
| 855 DCHECK(CanHaveTilings()); | 857 DCHECK(CanHaveTilings()); |
| 856 DCHECK_GE(contents_scale, MinimumContentsScale()); | 858 DCHECK_GE(contents_scale, MinimumContentsScale()); |
| 857 DCHECK_LE(contents_scale, MaximumContentsScale()); | 859 DCHECK_LE(contents_scale, MaximumContentsScale()); |
| 858 DCHECK(raster_source_->HasRecordings()); | 860 DCHECK(raster_source_->HasRecordings()); |
| 859 return tilings_->AddTiling(contents_scale, raster_source_); | 861 return tilings_->AddTiling(contents_scale, contents_translation, |
| 862 raster_source_); | |
| 860 } | 863 } |
| 861 | 864 |
| 862 void PictureLayerImpl::RemoveAllTilings() { | 865 void PictureLayerImpl::RemoveAllTilings() { |
| 863 tilings_->RemoveAllTilings(); | 866 tilings_->RemoveAllTilings(); |
| 864 // If there are no tilings, then raster scales are no longer meaningful. | 867 // If there are no tilings, then raster scales are no longer meaningful. |
| 865 ResetRasterScale(); | 868 ResetRasterScale(); |
| 866 } | 869 } |
| 867 | 870 |
| 868 void PictureLayerImpl::AddTilingsForRasterScale() { | 871 void PictureLayerImpl::AddTilingsForRasterScale() { |
| 869 // Reset all resolution enums on tilings, we'll be setting new values in this | 872 // Reset all resolution enums on tilings, we'll be setting new values in this |
| 870 // function. | 873 // function. |
| 871 tilings_->MarkAllTilingsNonIdeal(); | 874 tilings_->MarkAllTilingsNonIdeal(); |
| 872 | 875 |
| 873 PictureLayerTiling* high_res = | 876 PictureLayerTiling* high_res = |
| 874 tilings_->FindTilingWithScale(raster_contents_scale_); | 877 tilings_->FindTilingWithScale(raster_contents_scale_); |
|
enne (OOO)
2016/08/22 22:57:39
What if the layer moves and the contents translati
trchen
2016/08/29 10:14:48
It was what was done in patchset 1, but later I ch
| |
| 875 if (!high_res) { | 878 if (!high_res) { |
| 879 gfx::Vector2dF raster_translation = CalculateRasterTranslation(); | |
| 876 // We always need a high res tiling, so create one if it doesn't exist. | 880 // We always need a high res tiling, so create one if it doesn't exist. |
| 877 high_res = AddTiling(raster_contents_scale_); | 881 high_res = AddTiling(raster_contents_scale_, raster_translation); |
| 878 } else if (high_res->may_contain_low_resolution_tiles()) { | 882 } else if (high_res->may_contain_low_resolution_tiles()) { |
| 879 // If the tiling we find here was LOW_RESOLUTION previously, it may not be | 883 // If the tiling we find here was LOW_RESOLUTION previously, it may not be |
| 880 // fully rastered, so destroy the old tiles. | 884 // fully rastered, so destroy the old tiles. |
| 881 high_res->Reset(); | 885 high_res->Reset(); |
| 882 // Reset the flag now that we'll make it high res, it will have fully | 886 // Reset the flag now that we'll make it high res, it will have fully |
| 883 // rastered content. | 887 // rastered content. |
| 884 high_res->reset_may_contain_low_resolution_tiles(); | 888 high_res->reset_may_contain_low_resolution_tiles(); |
| 885 } | 889 } |
| 886 high_res->set_resolution(HIGH_RESOLUTION); | 890 high_res->set_resolution(HIGH_RESOLUTION); |
| 887 | 891 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 969 tilings_->FindTilingWithScale(low_res_raster_contents_scale_); | 973 tilings_->FindTilingWithScale(low_res_raster_contents_scale_); |
| 970 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); | 974 DCHECK(!low_res || low_res->resolution() != HIGH_RESOLUTION); |
| 971 | 975 |
| 972 // Only create new low res tilings when the transform is static. This | 976 // Only create new low res tilings when the transform is static. This |
| 973 // prevents wastefully creating a paired low res tiling for every new high | 977 // prevents wastefully creating a paired low res tiling for every new high |
| 974 // res tiling during a pinch or a CSS animation. | 978 // res tiling during a pinch or a CSS animation. |
| 975 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 979 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
| 976 bool is_animating = draw_properties().screen_space_transform_is_animating; | 980 bool is_animating = draw_properties().screen_space_transform_is_animating; |
| 977 if (!is_pinching && !is_animating) { | 981 if (!is_pinching && !is_animating) { |
| 978 if (!low_res) | 982 if (!low_res) |
| 979 low_res = AddTiling(low_res_raster_contents_scale_); | 983 low_res = AddTiling(low_res_raster_contents_scale_, gfx::Vector2dF()); |
| 980 low_res->set_resolution(LOW_RESOLUTION); | 984 low_res->set_resolution(LOW_RESOLUTION); |
| 981 } | 985 } |
| 982 } | 986 } |
| 983 | 987 |
| 988 gfx::Vector2dF PictureLayerImpl::CalculateRasterTranslation() { | |
|
enne (OOO)
2016/08/22 22:57:39
This function depending on raster_contents_scale_
trchen
2016/08/29 10:14:48
Done.
| |
| 989 if (draw_properties().screen_space_transform_is_animating) | |
| 990 return gfx::Vector2dF(); | |
| 991 | |
| 992 gfx::Transform draw_transform = DrawTransform(); | |
|
trchen
2016/08/12 22:11:30
We can certainly use draw transform to align inste
enne (OOO)
2016/08/16 23:02:52
If you have a static draw transform, then you are
| |
| 993 if (!draw_transform.IsScaleOrTranslation()) | |
| 994 return gfx::Vector2dF(); | |
| 995 | |
| 996 // Good match if the maximum alignment error on a layer of size 10000px | |
| 997 // does not exceed 0.001px. | |
| 998 static constexpr float kErrorThreshold = 0.0000001f; | |
|
enne (OOO)
2016/08/22 22:57:39
I think this function needs some more comments. T
trchen
2016/08/29 10:14:48
Done.
| |
| 999 if (std::abs(draw_transform.matrix().getFloat(0, 0) - | |
| 1000 raster_contents_scale_) > kErrorThreshold || | |
| 1001 std::abs(draw_transform.matrix().getFloat(1, 1) - | |
| 1002 raster_contents_scale_) > kErrorThreshold) | |
| 1003 return gfx::Vector2dF(); | |
| 1004 | |
| 1005 float origin_x = draw_transform.matrix().getFloat(0, 3); | |
| 1006 float origin_y = draw_transform.matrix().getFloat(1, 3); | |
| 1007 return gfx::Vector2dF(origin_x - floorf(origin_x), | |
| 1008 origin_y - floorf(origin_y)); | |
| 1009 } | |
| 1010 | |
| 984 void PictureLayerImpl::RecalculateRasterScales() { | 1011 void PictureLayerImpl::RecalculateRasterScales() { |
| 985 if (is_directly_composited_image_) { | 1012 if (is_directly_composited_image_) { |
| 986 if (!raster_source_scale_) | 1013 if (!raster_source_scale_) |
| 987 raster_source_scale_ = 1.f; | 1014 raster_source_scale_ = 1.f; |
| 988 | 1015 |
| 989 float min_scale = MinimumContentsScale(); | 1016 float min_scale = MinimumContentsScale(); |
| 990 float max_scale = std::max(1.f, MinimumContentsScale()); | 1017 float max_scale = std::max(1.f, MinimumContentsScale()); |
| 991 float clamped_ideal_source_scale_ = | 1018 float clamped_ideal_source_scale_ = |
| 992 std::max(min_scale, std::min(ideal_source_scale_, max_scale)); | 1019 std::max(min_scale, std::min(ideal_source_scale_, max_scale)); |
| 993 | 1020 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1327 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { | 1354 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { |
| 1328 return !layer_tree_impl()->IsRecycleTree(); | 1355 return !layer_tree_impl()->IsRecycleTree(); |
| 1329 } | 1356 } |
| 1330 | 1357 |
| 1331 bool PictureLayerImpl::HasValidTilePriorities() const { | 1358 bool PictureLayerImpl::HasValidTilePriorities() const { |
| 1332 return IsOnActiveOrPendingTree() && | 1359 return IsOnActiveOrPendingTree() && |
| 1333 is_drawn_render_surface_layer_list_member(); | 1360 is_drawn_render_surface_layer_list_member(); |
| 1334 } | 1361 } |
| 1335 | 1362 |
| 1336 } // namespace cc | 1363 } // namespace cc |
| OLD | NEW |