| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 NOTREACHED(); | 275 NOTREACHED(); |
| 275 *resource_id = 0; | 276 *resource_id = 0; |
| 276 } | 277 } |
| 277 | 278 |
| 278 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { | 279 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { |
| 279 ScrollTree& scroll_tree = layer_tree_impl()->property_trees()->scroll_tree; | 280 ScrollTree& scroll_tree = layer_tree_impl()->property_trees()->scroll_tree; |
| 280 ScrollNode* scroll_node = scroll_tree.Node(scroll_tree_index()); | 281 ScrollNode* scroll_node = scroll_tree.Node(scroll_tree_index()); |
| 281 return scroll_tree.ScrollBy(scroll_node, scroll, layer_tree_impl()); | 282 return scroll_tree.ScrollBy(scroll_node, scroll, layer_tree_impl()); |
| 282 } | 283 } |
| 283 | 284 |
| 284 void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) { | 285 void LayerImpl::SetScrollClipAndCanOverscroll(int scroll_clip_layer_id, |
| 285 if (scroll_clip_layer_id_ == scroll_clip_layer_id) | 286 bool can_overscroll) { |
| 287 if (scroll_clip_layer_id_ == scroll_clip_layer_id && |
| 288 can_overscroll_ == can_overscroll) |
| 286 return; | 289 return; |
| 287 | 290 |
| 288 layer_tree_impl()->UnregisterScrollLayer(this); | 291 layer_tree_impl()->UnregisterScrollLayer(this); |
| 289 scroll_clip_layer_id_ = scroll_clip_layer_id; | 292 scroll_clip_layer_id_ = scroll_clip_layer_id; |
| 293 can_overscroll_ = can_overscroll; |
| 290 layer_tree_impl()->RegisterScrollLayer(this); | 294 layer_tree_impl()->RegisterScrollLayer(this); |
| 291 } | 295 } |
| 292 | 296 |
| 293 LayerImpl* LayerImpl::scroll_clip_layer() const { | 297 LayerImpl* LayerImpl::scroll_clip_layer() const { |
| 294 return layer_tree_impl()->LayerById(scroll_clip_layer_id_); | 298 return layer_tree_impl()->LayerById(scroll_clip_layer_id_); |
| 295 } | 299 } |
| 296 | 300 |
| 297 bool LayerImpl::scrollable() const { | 301 bool LayerImpl::scrollable() const { |
| 298 return scroll_clip_layer_id_ != Layer::INVALID_ID; | 302 return scroll_clip_layer_id_ != Layer::INVALID_ID; |
| 299 } | 303 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 layer->layer_property_changed_ = true; | 355 layer->layer_property_changed_ = true; |
| 352 } | 356 } |
| 353 | 357 |
| 354 // If whether layer has render surface changes, we need to update draw | 358 // If whether layer has render surface changes, we need to update draw |
| 355 // properties. | 359 // properties. |
| 356 // TODO(weiliangc): Should be safely removed after impl side is able to | 360 // TODO(weiliangc): Should be safely removed after impl side is able to |
| 357 // update render surfaces without rebuilding property trees. | 361 // update render surfaces without rebuilding property trees. |
| 358 if (layer->has_render_surface() != has_render_surface()) | 362 if (layer->has_render_surface() != has_render_surface()) |
| 359 layer->layer_tree_impl()->set_needs_update_draw_properties(); | 363 layer->layer_tree_impl()->set_needs_update_draw_properties(); |
| 360 layer->SetBounds(bounds_); | 364 layer->SetBounds(bounds_); |
| 361 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 365 layer->SetScrollClipAndCanOverscroll(scroll_clip_layer_id_, can_overscroll_); |
| 362 layer->SetElementId(element_id_); | 366 layer->SetElementId(element_id_); |
| 363 layer->SetMutableProperties(mutable_properties_); | 367 layer->SetMutableProperties(mutable_properties_); |
| 364 | 368 |
| 365 // If the main thread commits multiple times before the impl thread actually | 369 // If the main thread commits multiple times before the impl thread actually |
| 366 // draws, then damage tracking will become incorrect if we simply clobber the | 370 // draws, then damage tracking will become incorrect if we simply clobber the |
| 367 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. | 371 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. |
| 368 // union) any update changes that have occurred on the main thread. | 372 // union) any update changes that have occurred on the main thread. |
| 369 update_rect_.Union(layer->update_rect()); | 373 update_rect_.Union(layer->update_rect()); |
| 370 layer->SetUpdateRect(update_rect_); | 374 layer->SetUpdateRect(update_rect_); |
| 371 | 375 |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 update_rect_ = update_rect; | 913 update_rect_ = update_rect; |
| 910 SetNeedsPushProperties(); | 914 SetNeedsPushProperties(); |
| 911 } | 915 } |
| 912 | 916 |
| 913 void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) { | 917 void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) { |
| 914 damage_rect_.Union(damage_rect); | 918 damage_rect_.Union(damage_rect); |
| 915 } | 919 } |
| 916 | 920 |
| 917 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { | 921 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { |
| 918 DCHECK(IsActive()); | 922 DCHECK(IsActive()); |
| 919 if (layer_tree_impl()->property_trees()->scroll_tree.SetScrollOffset( | 923 ScrollTree& scroll_tree = layer_tree_impl()->property_trees()->scroll_tree; |
| 920 id(), scroll_offset)) | 924 if (scroll_tree.SetScrollOffset(id(), scroll_offset, CurrentOverscroll())) |
| 921 layer_tree_impl()->DidUpdateScrollOffset(id(), transform_tree_index()); | 925 layer_tree_impl()->DidUpdateScrollOffset(id(), transform_tree_index()); |
| 922 } | 926 } |
| 923 | 927 |
| 924 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { | 928 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { |
| 925 return layer_tree_impl()->property_trees()->scroll_tree.current_scroll_offset( | 929 return layer_tree_impl()->property_trees()->scroll_tree.current_scroll_offset( |
| 926 id()); | 930 id()); |
| 927 } | 931 } |
| 928 | 932 |
| 933 void LayerImpl::SetCurrentOverscroll(const gfx::ScrollOffset& overscroll) { |
| 934 ScrollTree& scroll_tree = layer_tree_impl()->property_trees()->scroll_tree; |
| 935 if (scroll_tree.SetScrollOffset(id(), CurrentScrollOffset(), overscroll)) |
| 936 layer_tree_impl()->DidUpdateScrollOffset(id(), transform_tree_index()); |
| 937 } |
| 938 |
| 939 gfx::ScrollOffset LayerImpl::CurrentOverscroll() const { |
| 940 return layer_tree_impl()->property_trees()->scroll_tree.current_overscroll( |
| 941 id()); |
| 942 } |
| 943 |
| 929 void LayerImpl::UpdatePropertyTreeScrollOffset() { | 944 void LayerImpl::UpdatePropertyTreeScrollOffset() { |
| 930 // TODO(enne): in the future, scrolling should update the scroll tree | 945 // TODO(enne): in the future, scrolling should update the scroll tree |
| 931 // directly instead of going through layers. | 946 // directly instead of going through layers. |
| 932 TransformTree& transform_tree = | 947 TransformTree& transform_tree = |
| 933 layer_tree_impl()->property_trees()->transform_tree; | 948 layer_tree_impl()->property_trees()->transform_tree; |
| 934 TransformNode* node = transform_tree.Node(transform_tree_index_); | 949 TransformNode* node = transform_tree.Node(transform_tree_index_); |
| 935 gfx::ScrollOffset current_offset = CurrentScrollOffset(); | 950 gfx::ScrollOffset current_offset = |
| 936 if (node->scroll_offset != current_offset) { | 951 CurrentScrollOffset() + CurrentOverscroll(); |
| 937 node->scroll_offset = current_offset; | 952 if (node->scroll_offset_with_overscroll != current_offset) { |
| 953 node->scroll_offset_with_overscroll = current_offset; |
| 938 node->needs_local_transform_update = true; | 954 node->needs_local_transform_update = true; |
| 939 transform_tree.set_needs_update(true); | 955 transform_tree.set_needs_update(true); |
| 940 } | 956 } |
| 941 } | 957 } |
| 942 | 958 |
| 943 SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const { | 959 SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const { |
| 944 if (contents_opaque()) | 960 if (contents_opaque()) |
| 945 return SimpleEnclosedRegion(visible_layer_rect()); | 961 return SimpleEnclosedRegion(visible_layer_rect()); |
| 946 return SimpleEnclosedRegion(); | 962 return SimpleEnclosedRegion(); |
| 947 } | 963 } |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 .layer_transforms_should_scale_layer_contents) { | 1210 .layer_transforms_should_scale_layer_contents) { |
| 1195 return default_scale; | 1211 return default_scale; |
| 1196 } | 1212 } |
| 1197 | 1213 |
| 1198 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1214 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1199 ScreenSpaceTransform(), default_scale); | 1215 ScreenSpaceTransform(), default_scale); |
| 1200 return std::max(transform_scales.x(), transform_scales.y()); | 1216 return std::max(transform_scales.x(), transform_scales.y()); |
| 1201 } | 1217 } |
| 1202 | 1218 |
| 1203 } // namespace cc | 1219 } // namespace cc |
| OLD | NEW |