| 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/layer_impl.h" | 5 #include "cc/layers/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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 namespace cc { | 50 namespace cc { |
| 51 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) | 51 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) |
| 52 : layer_id_(id), | 52 : layer_id_(id), |
| 53 layer_tree_impl_(tree_impl), | 53 layer_tree_impl_(tree_impl), |
| 54 test_properties_(nullptr), | 54 test_properties_(nullptr), |
| 55 scroll_clip_layer_id_(Layer::INVALID_ID), | 55 scroll_clip_layer_id_(Layer::INVALID_ID), |
| 56 main_thread_scrolling_reasons_( | 56 main_thread_scrolling_reasons_( |
| 57 MainThreadScrollingReason::kNotScrollingOnMain), | 57 MainThreadScrollingReason::kNotScrollingOnMain), |
| 58 user_scrollable_horizontal_(true), | 58 user_scrollable_horizontal_(true), |
| 59 user_scrollable_vertical_(true), | 59 user_scrollable_vertical_(true), |
| 60 can_overscroll_(false), |
| 60 should_flatten_transform_from_property_tree_(false), | 61 should_flatten_transform_from_property_tree_(false), |
| 61 layer_property_changed_(false), | 62 layer_property_changed_(false), |
| 62 masks_to_bounds_(false), | 63 masks_to_bounds_(false), |
| 63 contents_opaque_(false), | 64 contents_opaque_(false), |
| 64 use_parent_backface_visibility_(false), | 65 use_parent_backface_visibility_(false), |
| 65 use_local_transform_for_backface_visibility_(false), | 66 use_local_transform_for_backface_visibility_(false), |
| 66 should_check_backface_visibility_(false), | 67 should_check_backface_visibility_(false), |
| 67 draws_content_(false), | 68 draws_content_(false), |
| 68 is_drawn_render_surface_layer_list_member_(false), | 69 is_drawn_render_surface_layer_list_member_(false), |
| 69 was_ever_ready_since_last_transform_animation_(true), | 70 was_ever_ready_since_last_transform_animation_(true), |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 NOTREACHED(); | 280 NOTREACHED(); |
| 280 *resource_id = 0; | 281 *resource_id = 0; |
| 281 } | 282 } |
| 282 | 283 |
| 283 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { | 284 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { |
| 284 ScrollTree& scroll_tree = layer_tree_impl()->property_trees()->scroll_tree; | 285 ScrollTree& scroll_tree = layer_tree_impl()->property_trees()->scroll_tree; |
| 285 ScrollNode* scroll_node = scroll_tree.Node(scroll_tree_index()); | 286 ScrollNode* scroll_node = scroll_tree.Node(scroll_tree_index()); |
| 286 return scroll_tree.ScrollBy(scroll_node, scroll, layer_tree_impl()); | 287 return scroll_tree.ScrollBy(scroll_node, scroll, layer_tree_impl()); |
| 287 } | 288 } |
| 288 | 289 |
| 289 void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) { | 290 void LayerImpl::SetScrollClipAndCanOverscroll(int scroll_clip_layer_id, |
| 290 if (scroll_clip_layer_id_ == scroll_clip_layer_id) | 291 bool can_overscroll) { |
| 292 if (scroll_clip_layer_id_ == scroll_clip_layer_id && |
| 293 can_overscroll_ == can_overscroll) |
| 291 return; | 294 return; |
| 292 | 295 |
| 293 layer_tree_impl()->UnregisterScrollLayer(this); | 296 layer_tree_impl()->UnregisterScrollLayer(this); |
| 294 scroll_clip_layer_id_ = scroll_clip_layer_id; | 297 scroll_clip_layer_id_ = scroll_clip_layer_id; |
| 298 can_overscroll_ = can_overscroll; |
| 295 layer_tree_impl()->RegisterScrollLayer(this); | 299 layer_tree_impl()->RegisterScrollLayer(this); |
| 296 } | 300 } |
| 297 | 301 |
| 298 LayerImpl* LayerImpl::scroll_clip_layer() const { | 302 LayerImpl* LayerImpl::scroll_clip_layer() const { |
| 299 return layer_tree_impl()->LayerById(scroll_clip_layer_id_); | 303 return layer_tree_impl()->LayerById(scroll_clip_layer_id_); |
| 300 } | 304 } |
| 301 | 305 |
| 302 bool LayerImpl::scrollable() const { | 306 bool LayerImpl::scrollable() const { |
| 303 return scroll_clip_layer_id_ != Layer::INVALID_ID; | 307 return scroll_clip_layer_id_ != Layer::INVALID_ID; |
| 304 } | 308 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 layer->layer_property_changed_ = true; | 361 layer->layer_property_changed_ = true; |
| 358 } | 362 } |
| 359 | 363 |
| 360 // If whether layer has render surface changes, we need to update draw | 364 // If whether layer has render surface changes, we need to update draw |
| 361 // properties. | 365 // properties. |
| 362 // TODO(weiliangc): Should be safely removed after impl side is able to | 366 // TODO(weiliangc): Should be safely removed after impl side is able to |
| 363 // update render surfaces without rebuilding property trees. | 367 // update render surfaces without rebuilding property trees. |
| 364 if (layer->has_render_surface() != has_render_surface()) | 368 if (layer->has_render_surface() != has_render_surface()) |
| 365 layer->layer_tree_impl()->set_needs_update_draw_properties(); | 369 layer->layer_tree_impl()->set_needs_update_draw_properties(); |
| 366 layer->SetBounds(bounds_); | 370 layer->SetBounds(bounds_); |
| 367 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 371 layer->SetScrollClipAndCanOverscroll(scroll_clip_layer_id_, can_overscroll_); |
| 368 layer->SetElementId(element_id_); | 372 layer->SetElementId(element_id_); |
| 369 layer->SetMutableProperties(mutable_properties_); | 373 layer->SetMutableProperties(mutable_properties_); |
| 370 | 374 |
| 371 // If the main thread commits multiple times before the impl thread actually | 375 // If the main thread commits multiple times before the impl thread actually |
| 372 // draws, then damage tracking will become incorrect if we simply clobber the | 376 // draws, then damage tracking will become incorrect if we simply clobber the |
| 373 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. | 377 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. |
| 374 // union) any update changes that have occurred on the main thread. | 378 // union) any update changes that have occurred on the main thread. |
| 375 update_rect_.Union(layer->update_rect()); | 379 update_rect_.Union(layer->update_rect()); |
| 376 layer->SetUpdateRect(update_rect_); | 380 layer->SetUpdateRect(update_rect_); |
| 377 | 381 |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 update_rect_ = update_rect; | 923 update_rect_ = update_rect; |
| 920 SetNeedsPushProperties(); | 924 SetNeedsPushProperties(); |
| 921 } | 925 } |
| 922 | 926 |
| 923 void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) { | 927 void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) { |
| 924 damage_rect_.Union(damage_rect); | 928 damage_rect_.Union(damage_rect); |
| 925 } | 929 } |
| 926 | 930 |
| 927 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { | 931 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { |
| 928 DCHECK(IsActive()); | 932 DCHECK(IsActive()); |
| 929 if (layer_tree_impl()->property_trees()->scroll_tree.SetScrollOffset( | 933 ScrollTree& scroll_tree = layer_tree_impl()->property_trees()->scroll_tree; |
| 930 id(), scroll_offset)) | 934 if (scroll_tree.SetScrollOffset(id(), scroll_offset, CurrentOverscroll())) |
| 931 layer_tree_impl()->DidUpdateScrollOffset(id(), transform_tree_index()); | 935 layer_tree_impl()->DidUpdateScrollOffset(id(), transform_tree_index()); |
| 932 } | 936 } |
| 933 | 937 |
| 934 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { | 938 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { |
| 935 return layer_tree_impl()->property_trees()->scroll_tree.current_scroll_offset( | 939 return layer_tree_impl()->property_trees()->scroll_tree.current_scroll_offset( |
| 936 id()); | 940 id()); |
| 937 } | 941 } |
| 938 | 942 |
| 943 void LayerImpl::SetCurrentOverscroll(const gfx::ScrollOffset& overscroll) { |
| 944 ScrollTree& scroll_tree = layer_tree_impl()->property_trees()->scroll_tree; |
| 945 if (scroll_tree.SetScrollOffset(id(), CurrentScrollOffset(), overscroll)) |
| 946 layer_tree_impl()->DidUpdateScrollOffset(id(), transform_tree_index()); |
| 947 } |
| 948 |
| 949 gfx::ScrollOffset LayerImpl::CurrentOverscroll() const { |
| 950 return layer_tree_impl()->property_trees()->scroll_tree.current_overscroll( |
| 951 id()); |
| 952 } |
| 953 |
| 939 void LayerImpl::UpdatePropertyTreeScrollOffset() { | 954 void LayerImpl::UpdatePropertyTreeScrollOffset() { |
| 940 // TODO(enne): in the future, scrolling should update the scroll tree | 955 // TODO(enne): in the future, scrolling should update the scroll tree |
| 941 // directly instead of going through layers. | 956 // directly instead of going through layers. |
| 942 TransformTree& transform_tree = | 957 TransformTree& transform_tree = |
| 943 layer_tree_impl()->property_trees()->transform_tree; | 958 layer_tree_impl()->property_trees()->transform_tree; |
| 944 TransformNode* node = transform_tree.Node(transform_tree_index_); | 959 TransformNode* node = transform_tree.Node(transform_tree_index_); |
| 945 gfx::ScrollOffset current_offset = CurrentScrollOffset(); | 960 gfx::ScrollOffset current_offset = |
| 946 if (node->scroll_offset != current_offset) { | 961 CurrentScrollOffset() + CurrentOverscroll(); |
| 947 node->scroll_offset = current_offset; | 962 if (node->scroll_offset_with_overscroll != current_offset) { |
| 963 node->scroll_offset_with_overscroll = current_offset; |
| 948 node->needs_local_transform_update = true; | 964 node->needs_local_transform_update = true; |
| 949 transform_tree.set_needs_update(true); | 965 transform_tree.set_needs_update(true); |
| 950 } | 966 } |
| 951 } | 967 } |
| 952 | 968 |
| 953 SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const { | 969 SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const { |
| 954 if (contents_opaque()) | 970 if (contents_opaque()) |
| 955 return SimpleEnclosedRegion(visible_layer_rect()); | 971 return SimpleEnclosedRegion(visible_layer_rect()); |
| 956 return SimpleEnclosedRegion(); | 972 return SimpleEnclosedRegion(); |
| 957 } | 973 } |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 .layer_transforms_should_scale_layer_contents) { | 1230 .layer_transforms_should_scale_layer_contents) { |
| 1215 return default_scale; | 1231 return default_scale; |
| 1216 } | 1232 } |
| 1217 | 1233 |
| 1218 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1234 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1219 ScreenSpaceTransform(), default_scale); | 1235 ScreenSpaceTransform(), default_scale); |
| 1220 return std::max(transform_scales.x(), transform_scales.y()); | 1236 return std::max(transform_scales.x(), transform_scales.y()); |
| 1221 } | 1237 } |
| 1222 | 1238 |
| 1223 } // namespace cc | 1239 } // namespace cc |
| OLD | NEW |