| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 tilings_(CreatePictureLayerTilingSet()), | 67 tilings_(CreatePictureLayerTilingSet()), |
| 68 ideal_page_scale_(0.f), | 68 ideal_page_scale_(0.f), |
| 69 ideal_device_scale_(0.f), | 69 ideal_device_scale_(0.f), |
| 70 ideal_source_scale_(0.f), | 70 ideal_source_scale_(0.f), |
| 71 ideal_contents_scale_(0.f), | 71 ideal_contents_scale_(0.f), |
| 72 raster_page_scale_(0.f), | 72 raster_page_scale_(0.f), |
| 73 raster_device_scale_(0.f), | 73 raster_device_scale_(0.f), |
| 74 raster_source_scale_(0.f), | 74 raster_source_scale_(0.f), |
| 75 raster_contents_scale_(0.f), | 75 raster_contents_scale_(0.f), |
| 76 low_res_raster_contents_scale_(0.f), | 76 low_res_raster_contents_scale_(0.f), |
| 77 raster_source_scale_is_fixed_(false), |
| 77 was_screen_space_transform_animating_(false), | 78 was_screen_space_transform_animating_(false), |
| 78 only_used_low_res_last_append_quads_(false), | 79 only_used_low_res_last_append_quads_(false), |
| 79 is_mask_(is_mask), | 80 is_mask_(is_mask), |
| 80 nearest_neighbor_(false) { | 81 nearest_neighbor_(false) { |
| 81 layer_tree_impl()->RegisterPictureLayerImpl(this); | 82 layer_tree_impl()->RegisterPictureLayerImpl(this); |
| 82 } | 83 } |
| 83 | 84 |
| 84 PictureLayerImpl::~PictureLayerImpl() { | 85 PictureLayerImpl::~PictureLayerImpl() { |
| 85 if (twin_layer_) | 86 if (twin_layer_) |
| 86 twin_layer_->twin_layer_ = nullptr; | 87 twin_layer_->twin_layer_ = nullptr; |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 if (!is_pinching) { | 896 if (!is_pinching) { |
| 896 // When not pinching, match the ideal page scale factor. | 897 // When not pinching, match the ideal page scale factor. |
| 897 if (raster_page_scale_ != ideal_page_scale_) | 898 if (raster_page_scale_ != ideal_page_scale_) |
| 898 return true; | 899 return true; |
| 899 } | 900 } |
| 900 | 901 |
| 901 // Always match the ideal device scale factor. | 902 // Always match the ideal device scale factor. |
| 902 if (raster_device_scale_ != ideal_device_scale_) | 903 if (raster_device_scale_ != ideal_device_scale_) |
| 903 return true; | 904 return true; |
| 904 | 905 |
| 905 // When the source scale changes we want to match it, but not when animating. | 906 // When the source scale changes we want to match it, but not when animating |
| 907 // or when we've fixed the scale in place. |
| 906 if (!draw_properties().screen_space_transform_is_animating && | 908 if (!draw_properties().screen_space_transform_is_animating && |
| 909 !raster_source_scale_is_fixed_ && |
| 907 raster_source_scale_ != ideal_source_scale_) | 910 raster_source_scale_ != ideal_source_scale_) |
| 908 return true; | 911 return true; |
| 909 | 912 |
| 910 if (raster_contents_scale_ > MaximumContentsScale()) | 913 if (raster_contents_scale_ > MaximumContentsScale()) |
| 911 return true; | 914 return true; |
| 912 if (raster_contents_scale_ < MinimumContentsScale()) | 915 if (raster_contents_scale_ < MinimumContentsScale()) |
| 913 return true; | 916 return true; |
| 914 | 917 |
| 915 return false; | 918 return false; |
| 916 } | 919 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 937 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 940 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
| 938 bool is_animating = draw_properties().screen_space_transform_is_animating; | 941 bool is_animating = draw_properties().screen_space_transform_is_animating; |
| 939 if (!is_pinching && !is_animating) { | 942 if (!is_pinching && !is_animating) { |
| 940 if (!low_res) | 943 if (!low_res) |
| 941 low_res = AddTiling(low_res_raster_contents_scale_); | 944 low_res = AddTiling(low_res_raster_contents_scale_); |
| 942 low_res->set_resolution(LOW_RESOLUTION); | 945 low_res->set_resolution(LOW_RESOLUTION); |
| 943 } | 946 } |
| 944 } | 947 } |
| 945 | 948 |
| 946 void PictureLayerImpl::RecalculateRasterScales() { | 949 void PictureLayerImpl::RecalculateRasterScales() { |
| 947 const float old_raster_contents_scale = raster_contents_scale_; | 950 float old_raster_contents_scale = raster_contents_scale_; |
| 948 const float old_raster_page_scale = raster_page_scale_; | 951 float old_raster_page_scale = raster_page_scale_; |
| 952 float old_raster_source_scale = raster_source_scale_; |
| 949 | 953 |
| 950 raster_device_scale_ = ideal_device_scale_; | 954 raster_device_scale_ = ideal_device_scale_; |
| 951 raster_page_scale_ = ideal_page_scale_; | 955 raster_page_scale_ = ideal_page_scale_; |
| 952 raster_source_scale_ = ideal_source_scale_; | 956 raster_source_scale_ = ideal_source_scale_; |
| 953 raster_contents_scale_ = ideal_contents_scale_; | 957 raster_contents_scale_ = ideal_contents_scale_; |
| 954 | 958 |
| 959 // If we're not animating, or leaving an animation, and the |
| 960 // ideal_source_scale_ changes, then things are unpredictable, and we fix |
| 961 // the raster_source_scale_ in place. |
| 962 if (old_raster_source_scale && |
| 963 !draw_properties().screen_space_transform_is_animating && |
| 964 !was_screen_space_transform_animating_ && |
| 965 old_raster_source_scale != ideal_source_scale_) |
| 966 raster_source_scale_is_fixed_ = true; |
| 967 |
| 968 // TODO(danakj): Adjust raster source scale closer to ideal source scale at |
| 969 // a throttled rate. Possibly make use of invalidation_.IsEmpty() on pending |
| 970 // tree. This will allow CSS scale changes to get re-rastered at an |
| 971 // appropriate rate. (crbug.com/413636) |
| 972 if (raster_source_scale_is_fixed_) { |
| 973 raster_contents_scale_ /= raster_source_scale_; |
| 974 raster_source_scale_ = 1.f; |
| 975 } |
| 976 |
| 955 // During pinch we completely ignore the current ideal scale, and just use | 977 // During pinch we completely ignore the current ideal scale, and just use |
| 956 // a multiple of the previous scale. | 978 // a multiple of the previous scale. |
| 957 bool is_pinching = layer_tree_impl()->PinchGestureActive(); | 979 bool is_pinching = layer_tree_impl()->PinchGestureActive(); |
| 958 if (is_pinching && old_raster_contents_scale) { | 980 if (is_pinching && old_raster_contents_scale) { |
| 959 // See ShouldAdjustRasterScale: | 981 // See ShouldAdjustRasterScale: |
| 960 // - When zooming out, preemptively create new tiling at lower resolution. | 982 // - When zooming out, preemptively create new tiling at lower resolution. |
| 961 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. | 983 // - When zooming in, approximate ideal using multiple of kMaxScaleRatio. |
| 962 bool zooming_out = old_raster_page_scale > ideal_page_scale_; | 984 bool zooming_out = old_raster_page_scale > ideal_page_scale_; |
| 963 float desired_contents_scale = old_raster_contents_scale; | 985 float desired_contents_scale = old_raster_contents_scale; |
| 964 if (zooming_out) { | 986 if (zooming_out) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 // up larger than |max_texture_size|. | 1137 // up larger than |max_texture_size|. |
| 1116 return nextafterf(max_scale, 0.f); | 1138 return nextafterf(max_scale, 0.f); |
| 1117 } | 1139 } |
| 1118 | 1140 |
| 1119 void PictureLayerImpl::ResetRasterScale() { | 1141 void PictureLayerImpl::ResetRasterScale() { |
| 1120 raster_page_scale_ = 0.f; | 1142 raster_page_scale_ = 0.f; |
| 1121 raster_device_scale_ = 0.f; | 1143 raster_device_scale_ = 0.f; |
| 1122 raster_source_scale_ = 0.f; | 1144 raster_source_scale_ = 0.f; |
| 1123 raster_contents_scale_ = 0.f; | 1145 raster_contents_scale_ = 0.f; |
| 1124 low_res_raster_contents_scale_ = 0.f; | 1146 low_res_raster_contents_scale_ = 0.f; |
| 1147 raster_source_scale_is_fixed_ = false; |
| 1125 } | 1148 } |
| 1126 | 1149 |
| 1127 bool PictureLayerImpl::CanHaveTilings() const { | 1150 bool PictureLayerImpl::CanHaveTilings() const { |
| 1128 if (raster_source_->IsSolidColor()) | 1151 if (raster_source_->IsSolidColor()) |
| 1129 return false; | 1152 return false; |
| 1130 if (!DrawsContent()) | 1153 if (!DrawsContent()) |
| 1131 return false; | 1154 return false; |
| 1132 if (!raster_source_->HasRecordings()) | 1155 if (!raster_source_->HasRecordings()) |
| 1133 return false; | 1156 return false; |
| 1134 // If the |raster_source_| has a recording it should have non-empty bounds. | 1157 // 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... |
| 1198 std::vector<PrioritizedTile>* prioritized_tiles) const { | 1221 std::vector<PrioritizedTile>* prioritized_tiles) const { |
| 1199 if (!tilings_) | 1222 if (!tilings_) |
| 1200 return; | 1223 return; |
| 1201 tilings_->GetAllPrioritizedTilesForTracing(prioritized_tiles); | 1224 tilings_->GetAllPrioritizedTilesForTracing(prioritized_tiles); |
| 1202 } | 1225 } |
| 1203 | 1226 |
| 1204 void PictureLayerImpl::AsValueInto( | 1227 void PictureLayerImpl::AsValueInto( |
| 1205 base::trace_event::TracedValue* state) const { | 1228 base::trace_event::TracedValue* state) const { |
| 1206 LayerImpl::AsValueInto(state); | 1229 LayerImpl::AsValueInto(state); |
| 1207 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); | 1230 state->SetDouble("ideal_contents_scale", ideal_contents_scale_); |
| 1208 state->SetDouble("raster_contents_scale", raster_contents_scale_); | |
| 1209 state->SetDouble("geometry_contents_scale", MaximumTilingContentsScale()); | 1231 state->SetDouble("geometry_contents_scale", MaximumTilingContentsScale()); |
| 1210 state->BeginArray("tilings"); | 1232 state->BeginArray("tilings"); |
| 1211 tilings_->AsValueInto(state); | 1233 tilings_->AsValueInto(state); |
| 1212 state->EndArray(); | 1234 state->EndArray(); |
| 1213 | 1235 |
| 1214 MathUtil::AddToTracedValue("tile_priority_rect", | 1236 MathUtil::AddToTracedValue("tile_priority_rect", |
| 1215 viewport_rect_for_tile_priority_in_content_space_, | 1237 viewport_rect_for_tile_priority_in_content_space_, |
| 1216 state); | 1238 state); |
| 1217 MathUtil::AddToTracedValue("visible_rect", visible_layer_rect(), state); | 1239 MathUtil::AddToTracedValue("visible_rect", visible_layer_rect(), state); |
| 1218 | 1240 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 | 1277 |
| 1256 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { | 1278 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { |
| 1257 return !layer_tree_impl()->IsRecycleTree(); | 1279 return !layer_tree_impl()->IsRecycleTree(); |
| 1258 } | 1280 } |
| 1259 | 1281 |
| 1260 bool PictureLayerImpl::HasValidTilePriorities() const { | 1282 bool PictureLayerImpl::HasValidTilePriorities() const { |
| 1261 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember(); | 1283 return IsOnActiveOrPendingTree() && IsDrawnRenderSurfaceLayerListMember(); |
| 1262 } | 1284 } |
| 1263 | 1285 |
| 1264 } // namespace cc | 1286 } // namespace cc |
| OLD | NEW |