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 <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <set> | 10 #include <set> |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 tilings_(CreatePictureLayerTilingSet()), | 62 tilings_(CreatePictureLayerTilingSet()), |
63 ideal_page_scale_(0.f), | 63 ideal_page_scale_(0.f), |
64 ideal_device_scale_(0.f), | 64 ideal_device_scale_(0.f), |
65 ideal_source_scale_(0.f), | 65 ideal_source_scale_(0.f), |
66 ideal_contents_scale_(0.f), | 66 ideal_contents_scale_(0.f), |
67 raster_page_scale_(0.f), | 67 raster_page_scale_(0.f), |
68 raster_device_scale_(0.f), | 68 raster_device_scale_(0.f), |
69 raster_source_scale_(0.f), | 69 raster_source_scale_(0.f), |
70 raster_contents_scale_(0.f), | 70 raster_contents_scale_(0.f), |
71 low_res_raster_contents_scale_(0.f), | 71 low_res_raster_contents_scale_(0.f), |
| 72 raster_source_scale_is_fixed_(false), |
72 was_screen_space_transform_animating_(false), | 73 was_screen_space_transform_animating_(false), |
73 only_used_low_res_last_append_quads_(false), | 74 only_used_low_res_last_append_quads_(false), |
74 is_mask_(is_mask), | 75 is_mask_(is_mask), |
75 nearest_neighbor_(false) { | 76 nearest_neighbor_(false) { |
76 layer_tree_impl()->RegisterPictureLayerImpl(this); | 77 layer_tree_impl()->RegisterPictureLayerImpl(this); |
77 } | 78 } |
78 | 79 |
79 PictureLayerImpl::~PictureLayerImpl() { | 80 PictureLayerImpl::~PictureLayerImpl() { |
80 if (twin_layer_) | 81 if (twin_layer_) |
81 twin_layer_->twin_layer_ = nullptr; | 82 twin_layer_->twin_layer_ = nullptr; |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 if (!is_pinching) { | 883 if (!is_pinching) { |
883 // When not pinching, match the ideal page scale factor. | 884 // When not pinching, match the ideal page scale factor. |
884 if (raster_page_scale_ != ideal_page_scale_) | 885 if (raster_page_scale_ != ideal_page_scale_) |
885 return true; | 886 return true; |
886 } | 887 } |
887 | 888 |
888 // Always match the ideal device scale factor. | 889 // Always match the ideal device scale factor. |
889 if (raster_device_scale_ != ideal_device_scale_) | 890 if (raster_device_scale_ != ideal_device_scale_) |
890 return true; | 891 return true; |
891 | 892 |
892 // When the source scale changes we want to match it, but not when animating. | 893 // When the source scale changes we want to match it, but not when animating |
| 894 // or when we've fixed the scale in place. |
893 if (!draw_properties().screen_space_transform_is_animating && | 895 if (!draw_properties().screen_space_transform_is_animating && |
| 896 !raster_source_scale_is_fixed_ && |
894 raster_source_scale_ != ideal_source_scale_) | 897 raster_source_scale_ != ideal_source_scale_) |
895 return true; | 898 return true; |
896 | 899 |
897 if (raster_contents_scale_ > MaximumContentsScale()) | 900 if (raster_contents_scale_ > MaximumContentsScale()) |
898 return true; | 901 return true; |
899 if (raster_contents_scale_ < MinimumContentsScale()) | 902 if (raster_contents_scale_ < MinimumContentsScale()) |
900 return true; | 903 return true; |
901 | 904 |
902 return false; | 905 return false; |
903 } | 906 } |
(...skipping 20 matching lines...) Expand all Loading... |
924 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 927 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
925 bool is_animating = draw_properties().screen_space_transform_is_animating; | 928 bool is_animating = draw_properties().screen_space_transform_is_animating; |
926 if (!is_pinching && !is_animating) { | 929 if (!is_pinching && !is_animating) { |
927 if (!low_res) | 930 if (!low_res) |
928 low_res = AddTiling(low_res_raster_contents_scale_); | 931 low_res = AddTiling(low_res_raster_contents_scale_); |
929 low_res->set_resolution(LOW_RESOLUTION); | 932 low_res->set_resolution(LOW_RESOLUTION); |
930 } | 933 } |
931 } | 934 } |
932 | 935 |
933 void PictureLayerImpl::RecalculateRasterScales() { | 936 void PictureLayerImpl::RecalculateRasterScales() { |
934 const float old_raster_contents_scale = raster_contents_scale_; | 937 float old_raster_contents_scale = raster_contents_scale_; |
935 const float old_raster_page_scale = raster_page_scale_; | 938 float old_raster_page_scale = raster_page_scale_; |
| 939 float old_raster_source_scale = raster_source_scale_; |
936 | 940 |
937 raster_device_scale_ = ideal_device_scale_; | 941 raster_device_scale_ = ideal_device_scale_; |
938 raster_page_scale_ = ideal_page_scale_; | 942 raster_page_scale_ = ideal_page_scale_; |
939 raster_source_scale_ = ideal_source_scale_; | 943 raster_source_scale_ = ideal_source_scale_; |
940 raster_contents_scale_ = ideal_contents_scale_; | 944 raster_contents_scale_ = ideal_contents_scale_; |
941 | 945 |
| 946 // If we're not animating, or leaving an animation, and the |
| 947 // ideal_source_scale_ changes, then things are unpredictable, and we fix |
| 948 // the raster_source_scale_ in place. |
| 949 if (old_raster_source_scale && |
| 950 !draw_properties().screen_space_transform_is_animating && |
| 951 !was_screen_space_transform_animating_ && |
| 952 old_raster_source_scale != ideal_source_scale_) |
| 953 raster_source_scale_is_fixed_ = true; |
| 954 |
| 955 // TODO(danakj): Adjust raster source scale closer to ideal source scale at |
| 956 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending |
| 957 // tree. This will allow CSS scale changes to get re-rastered at an |
| 958 // appropriate rate. (crbug.com/413636) |
| 959 if (raster_source_scale_is_fixed_) { |
| 960 raster_contents_scale_ /= raster_source_scale_; |
| 961 raster_source_scale_ = 1.f; |
| 962 } |
| 963 |
942 // During pinch we completely ignore the current ideal scale, and just use | 964 // During pinch we completely ignore the current ideal scale, and just use |
943 // a multiple of the previous scale. | 965 // a multiple of the previous scale. |
944 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 966 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
945 if (is_pinching && old_raster_contents_scale) { | 967 if (is_pinching && old_raster_contents_scale) { |
946 // See ShouldAdjustRasterScale: | 968 // See ShouldAdjustRasterScale: |
947 // - When zooming out, preemptively create new tiling at lower resolution. | 969 // - When zooming out, preemptively create new tiling at lower resolution. |
948 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. | 970 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. |
949 bool zooming_out = old_raster_page_scale > ideal_page_scale_; | 971 bool zooming_out = old_raster_page_scale > ideal_page_scale_; |
950 float desired_contents_scale = old_raster_contents_scale; | 972 float desired_contents_scale = old_raster_contents_scale; |
951 if (zooming_out) { | 973 if (zooming_out) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 // up larger than |max_texture_size|. | 1122 // up larger than |max_texture_size|. |
1101 return nextafterf(max_scale, 0.f); | 1123 return nextafterf(max_scale, 0.f); |
1102 } | 1124 } |
1103 | 1125 |
1104 void PictureLayerImpl::ResetRasterScale() { | 1126 void PictureLayerImpl::ResetRasterScale() { |
1105 raster_page_scale_ = 0.f; | 1127 raster_page_scale_ = 0.f; |
1106 raster_device_scale_ = 0.f; | 1128 raster_device_scale_ = 0.f; |
1107 raster_source_scale_ = 0.f; | 1129 raster_source_scale_ = 0.f; |
1108 raster_contents_scale_ = 0.f; | 1130 raster_contents_scale_ = 0.f; |
1109 low_res_raster_contents_scale_ = 0.f; | 1131 low_res_raster_contents_scale_ = 0.f; |
| 1132 raster_source_scale_is_fixed_ = false; |
1110 } | 1133 } |
1111 | 1134 |
1112 bool PictureLayerImpl::CanHaveTilings() const { | 1135 bool PictureLayerImpl::CanHaveTilings() const { |
1113 if (raster_source_->IsSolidColor()) | 1136 if (raster_source_->IsSolidColor()) |
1114 return false; | 1137 return false; |
1115 if (!DrawsContent()) | 1138 if (!DrawsContent()) |
1116 return false; | 1139 return false; |
1117 if (!raster_source_->HasRecordings()) | 1140 if (!raster_source_->HasRecordings()) |
1118 return false; | 1141 return false; |
1119 // If the |raster_source_| has a recording it should have non-empty bounds. | 1142 // If the |raster_source_| has a recording it should have non-empty bounds. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 std::vector<PrioritizedTile>* prioritized_tiles) const { | 1206 std::vector<PrioritizedTile>* prioritized_tiles) const { |
1184 if (!tilings_) | 1207 if (!tilings_) |
1185 return; | 1208 return; |
1186 tilings_->GetAllPrioritizedTilesForTracing(prioritized_tiles); | 1209 tilings_->GetAllPrioritizedTilesForTracing(prioritized_tiles); |
1187 } | 1210 } |
1188 | 1211 |
1189 void PictureLayerImpl::AsValueInto( | 1212 void PictureLayerImpl::AsValueInto( |
1190 base::trace_event::TracedValue* state) const { | 1213 base::trace_event::TracedValue* state) const { |
1191 LayerImpl::AsValueInto(state); | 1214 LayerImpl::AsValueInto(state); |
1192 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); | 1215 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); |
1193 state->SetDouble("raster_contents_scale", raster_contents_scale_); | |
1194 state->SetDouble("geometry_contents_scale", MaximumTilingContentsScale()); | 1216 state->SetDouble("geometry_contents_scale", MaximumTilingContentsScale()); |
1195 state->BeginArray("tilings"); | 1217 state->BeginArray("tilings"); |
1196 tilings_->AsValueInto(state); | 1218 tilings_->AsValueInto(state); |
1197 state->EndArray(); | 1219 state->EndArray(); |
1198 | 1220 |
1199 MathUtil::AddToTracedValue("tile_priority_rect", | 1221 MathUtil::AddToTracedValue("tile_priority_rect", |
1200 viewport_rect_for_tile_priority_in_content_space_, | 1222 viewport_rect_for_tile_priority_in_content_space_, |
1201 state); | 1223 state); |
1202 MathUtil::AddToTracedValue("visible_rect", visible_layer_rect(), state); | 1224 MathUtil::AddToTracedValue("visible_rect", visible_layer_rect(), state); |
1203 | 1225 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 | 1262 |
1241 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { | 1263 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { |
1242 return !layer_tree_impl()->IsRecycleTree(); | 1264 return !layer_tree_impl()->IsRecycleTree(); |
1243 } | 1265 } |
1244 | 1266 |
1245 bool PictureLayerImpl::HasValidTilePriorities() const { | 1267 bool PictureLayerImpl::HasValidTilePriorities() const { |
1246 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember(); | 1268 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember(); |
1247 } | 1269 } |
1248 | 1270 |
1249 } // namespace cc | 1271 } // namespace cc |
OLD | NEW |