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/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/debug/trace_event_argument.h" | 8 #include "base/debug/trace_event_argument.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "cc/trees/layer_tree_settings.h" | 27 #include "cc/trees/layer_tree_settings.h" |
| 28 #include "cc/trees/proxy.h" | 28 #include "cc/trees/proxy.h" |
| 29 #include "ui/gfx/geometry/box_f.h" | 29 #include "ui/gfx/geometry/box_f.h" |
| 30 #include "ui/gfx/geometry/point_conversions.h" | 30 #include "ui/gfx/geometry/point_conversions.h" |
| 31 #include "ui/gfx/geometry/quad_f.h" | 31 #include "ui/gfx/geometry/quad_f.h" |
| 32 #include "ui/gfx/geometry/rect_conversions.h" | 32 #include "ui/gfx/geometry/rect_conversions.h" |
| 33 #include "ui/gfx/geometry/size_conversions.h" | 33 #include "ui/gfx/geometry/size_conversions.h" |
| 34 #include "ui/gfx/geometry/vector2d_conversions.h" | 34 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 35 | 35 |
| 36 namespace cc { | 36 namespace cc { |
| 37 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, int id) | 37 LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id) |
| 38 : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) { | |
| 39 } | |
| 40 | |
| 41 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, | |
| 42 int id, | |
| 43 scoped_refptr<SyncedScrollOffset> scroll_offset) | |
| 38 : parent_(nullptr), | 44 : parent_(nullptr), |
| 39 scroll_parent_(nullptr), | 45 scroll_parent_(nullptr), |
| 40 clip_parent_(nullptr), | 46 clip_parent_(nullptr), |
| 41 mask_layer_id_(-1), | 47 mask_layer_id_(-1), |
| 42 replica_layer_id_(-1), | 48 replica_layer_id_(-1), |
| 43 layer_id_(id), | 49 layer_id_(id), |
| 44 layer_tree_impl_(tree_impl), | 50 layer_tree_impl_(tree_impl), |
| 51 scroll_offset_(scroll_offset), | |
| 45 scroll_offset_delegate_(nullptr), | 52 scroll_offset_delegate_(nullptr), |
| 46 scroll_clip_layer_(nullptr), | 53 scroll_clip_layer_(nullptr), |
| 47 should_scroll_on_main_thread_(false), | 54 should_scroll_on_main_thread_(false), |
| 48 have_wheel_event_handlers_(false), | 55 have_wheel_event_handlers_(false), |
| 49 have_scroll_event_handlers_(false), | 56 have_scroll_event_handlers_(false), |
| 50 user_scrollable_horizontal_(true), | 57 user_scrollable_horizontal_(true), |
| 51 user_scrollable_vertical_(true), | 58 user_scrollable_vertical_(true), |
| 52 stacking_order_changed_(false), | 59 stacking_order_changed_(false), |
| 53 double_sided_(true), | 60 double_sided_(true), |
| 54 should_flatten_transform_(true), | 61 should_flatten_transform_(true), |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 bool resourceless_software_draw) { | 346 bool resourceless_software_draw) { |
| 340 return false; | 347 return false; |
| 341 } | 348 } |
| 342 | 349 |
| 343 void LayerImpl::GetContentsResourceId(ResourceProvider::ResourceId* resource_id, | 350 void LayerImpl::GetContentsResourceId(ResourceProvider::ResourceId* resource_id, |
| 344 gfx::Size* resource_size) const { | 351 gfx::Size* resource_size) const { |
| 345 NOTREACHED(); | 352 NOTREACHED(); |
| 346 *resource_id = 0; | 353 *resource_id = 0; |
| 347 } | 354 } |
| 348 | 355 |
| 349 void LayerImpl::SetSentScrollDelta(const gfx::Vector2dF& sent_scroll_delta) { | |
| 350 // Pending tree never has sent scroll deltas | |
| 351 DCHECK(layer_tree_impl()->IsActiveTree()); | |
| 352 | |
| 353 if (sent_scroll_delta_ == sent_scroll_delta) | |
| 354 return; | |
| 355 | |
| 356 sent_scroll_delta_ = sent_scroll_delta; | |
| 357 } | |
| 358 | |
| 359 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { | 356 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { |
| 360 gfx::Vector2dF adjusted_scroll = scroll; | 357 gfx::ScrollOffset adjusted_scroll(scroll); |
| 361 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) { | 358 if (layer_tree_impl()->settings().use_pinch_virtual_viewport) { |
| 362 if (!user_scrollable_horizontal_) | 359 if (!user_scrollable_horizontal_) |
| 363 adjusted_scroll.set_x(0); | 360 adjusted_scroll.set_x(0); |
| 364 if (!user_scrollable_vertical_) | 361 if (!user_scrollable_vertical_) |
| 365 adjusted_scroll.set_y(0); | 362 adjusted_scroll.set_y(0); |
| 366 } | 363 } |
| 367 DCHECK(scrollable()); | 364 DCHECK(scrollable()); |
| 368 gfx::Vector2dF min_delta = -ScrollOffsetToVector2dF(scroll_offset_); | 365 gfx::ScrollOffset old_offset = CurrentScrollOffset(); |
| 369 gfx::Vector2dF max_delta = MaxScrollOffset().DeltaFrom(scroll_offset_); | 366 gfx::ScrollOffset new_offset = |
| 370 // Clamp new_delta so that position + delta stays within scroll bounds. | 367 ClampScrollOffsetToLimits(old_offset + adjusted_scroll); |
| 371 gfx::Vector2dF new_delta = (ScrollDelta() + adjusted_scroll); | 368 SetScrollOffsetOnActiveTree(new_offset); |
| 372 new_delta.SetToMax(min_delta); | |
| 373 new_delta.SetToMin(max_delta); | |
| 374 gfx::Vector2dF unscrolled = | |
| 375 ScrollDelta() + scroll - new_delta; | |
| 376 SetScrollDelta(new_delta); | |
| 377 | 369 |
| 378 return unscrolled; | 370 gfx::ScrollOffset unscrolled = |
| 371 old_offset + gfx::ScrollOffset(scroll) - new_offset; | |
| 372 return gfx::Vector2dF(unscrolled.x(), unscrolled.y()); | |
| 379 } | 373 } |
| 380 | 374 |
| 381 void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) { | 375 void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) { |
| 382 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id); | 376 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id); |
| 383 } | 377 } |
| 384 | 378 |
| 385 bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const { | 379 bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const { |
| 386 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_ | 380 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_ |
| 387 : user_scrollable_vertical_; | 381 : user_scrollable_vertical_; |
| 388 } | 382 } |
| 389 | 383 |
| 390 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { | 384 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { |
| 391 if (sent_scroll_delta_.IsZero()) | |
| 392 return; | |
| 393 | |
| 394 // Pending tree never has sent scroll deltas | |
| 395 DCHECK(layer_tree_impl()->IsActiveTree()); | 385 DCHECK(layer_tree_impl()->IsActiveTree()); |
| 396 | 386 scroll_offset_->AbortCommit(); |
| 397 // The combination of pending tree and aborted commits with impl scrolls | |
| 398 // shouldn't happen; we don't know how to update its deltas correctly. | |
| 399 DCHECK(!layer_tree_impl()->FindPendingTreeLayerById(id())); | |
| 400 | |
| 401 // Apply sent scroll deltas to scroll position / scroll delta as if the | |
| 402 // main thread had applied them and then committed those values. | |
| 403 SetScrollOffsetAndDelta( | |
| 404 scroll_offset_ + gfx::ScrollOffset(sent_scroll_delta_), | |
| 405 ScrollDelta() - sent_scroll_delta_); | |
| 406 SetSentScrollDelta(gfx::Vector2dF()); | |
| 407 } | |
| 408 | |
| 409 void LayerImpl::ApplyScrollDeltasSinceBeginMainFrame() { | |
| 410 // Only the pending tree can have missing scrolls. | |
| 411 DCHECK(layer_tree_impl()->IsPendingTree()); | |
| 412 if (!scrollable()) | |
| 413 return; | |
| 414 | |
| 415 // Pending tree should never have sent scroll deltas. | |
| 416 DCHECK(sent_scroll_delta().IsZero()); | |
| 417 | |
| 418 LayerImpl* active_twin = layer_tree_impl()->FindActiveTreeLayerById(id()); | |
| 419 if (active_twin) { | |
| 420 // Scrolls that happens after begin frame (where the sent scroll delta | |
| 421 // comes from) and commit need to be applied to the pending tree | |
| 422 // so that it is up to date with the total scroll. | |
| 423 SetScrollDelta(active_twin->ScrollDelta() - | |
| 424 active_twin->sent_scroll_delta()); | |
| 425 } | |
| 426 } | 387 } |
| 427 | 388 |
| 428 InputHandler::ScrollStatus LayerImpl::TryScroll( | 389 InputHandler::ScrollStatus LayerImpl::TryScroll( |
| 429 const gfx::PointF& screen_space_point, | 390 const gfx::PointF& screen_space_point, |
| 430 InputHandler::ScrollInputType type) const { | 391 InputHandler::ScrollInputType type) const { |
| 431 if (should_scroll_on_main_thread()) { | 392 if (should_scroll_on_main_thread()) { |
| 432 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread"); | 393 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread"); |
| 433 return InputHandler::ScrollOnMainThread; | 394 return InputHandler::ScrollOnMainThread; |
| 434 } | 395 } |
| 435 | 396 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 // values x and y, ceil((x / y) * y) may be x + 1. | 455 // values x and y, ceil((x / y) * y) may be x + 1. |
| 495 content_rect.Intersect(gfx::Rect(content_bounds())); | 456 content_rect.Intersect(gfx::Rect(content_bounds())); |
| 496 return gfx::ToEnclosingRect(content_rect); | 457 return gfx::ToEnclosingRect(content_rect); |
| 497 } | 458 } |
| 498 | 459 |
| 499 skia::RefPtr<SkPicture> LayerImpl::GetPicture() { | 460 skia::RefPtr<SkPicture> LayerImpl::GetPicture() { |
| 500 return skia::RefPtr<SkPicture>(); | 461 return skia::RefPtr<SkPicture>(); |
| 501 } | 462 } |
| 502 | 463 |
| 503 scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 464 scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 504 return LayerImpl::Create(tree_impl, layer_id_); | 465 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_); |
| 505 } | 466 } |
| 506 | 467 |
| 507 void LayerImpl::PushPropertiesTo(LayerImpl* layer) { | 468 void LayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 508 layer->SetTransformOrigin(transform_origin_); | 469 layer->SetTransformOrigin(transform_origin_); |
| 509 layer->SetBackgroundColor(background_color_); | 470 layer->SetBackgroundColor(background_color_); |
| 510 layer->SetBounds(bounds_); | 471 layer->SetBounds(bounds_); |
| 511 layer->SetContentBounds(content_bounds()); | 472 layer->SetContentBounds(content_bounds()); |
| 512 layer->SetContentsScale(contents_scale_x(), contents_scale_y()); | 473 layer->SetContentsScale(contents_scale_x(), contents_scale_y()); |
| 513 layer->SetDoubleSided(double_sided_); | 474 layer->SetDoubleSided(double_sided_); |
| 514 layer->SetDrawCheckerboardForMissingTiles( | 475 layer->SetDrawCheckerboardForMissingTiles( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 534 layer->SetPositionConstraint(position_constraint_); | 495 layer->SetPositionConstraint(position_constraint_); |
| 535 layer->SetShouldFlattenTransform(should_flatten_transform_); | 496 layer->SetShouldFlattenTransform(should_flatten_transform_); |
| 536 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 497 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 537 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 498 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
| 538 | 499 |
| 539 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() | 500 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() |
| 540 : Layer::INVALID_ID); | 501 : Layer::INVALID_ID); |
| 541 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 502 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 542 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 503 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 543 | 504 |
| 544 // Save the difference but clear the sent delta so that we don't subtract | 505 layer->PushScrollOffset(nullptr); |
| 545 // it again in SetScrollOffsetAndDelta's pending twin mirroring logic. | |
| 546 gfx::Vector2dF remaining_delta = | |
| 547 layer->ScrollDelta() - layer->sent_scroll_delta(); | |
| 548 layer->SetSentScrollDelta(gfx::Vector2dF()); | |
| 549 layer->SetScrollOffsetAndDelta(scroll_offset_, remaining_delta); | |
| 550 | 506 |
| 551 layer->Set3dSortingContextId(sorting_context_id_); | 507 layer->Set3dSortingContextId(sorting_context_id_); |
| 552 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | 508 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
| 553 | 509 |
| 554 LayerImpl* scroll_parent = nullptr; | 510 LayerImpl* scroll_parent = nullptr; |
| 555 if (scroll_parent_) { | 511 if (scroll_parent_) { |
| 556 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 512 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| 557 DCHECK(scroll_parent); | 513 DCHECK(scroll_parent); |
| 558 } | 514 } |
| 559 | 515 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 745 replica_layer_->ResetAllChangeTrackingForSubtree(); | 701 replica_layer_->ResetAllChangeTrackingForSubtree(); |
| 746 } | 702 } |
| 747 | 703 |
| 748 for (size_t i = 0; i < children_.size(); ++i) | 704 for (size_t i = 0; i < children_.size(); ++i) |
| 749 children_[i]->ResetAllChangeTrackingForSubtree(); | 705 children_[i]->ResetAllChangeTrackingForSubtree(); |
| 750 | 706 |
| 751 needs_push_properties_ = false; | 707 needs_push_properties_ = false; |
| 752 num_dependents_need_push_properties_ = 0; | 708 num_dependents_need_push_properties_ = 0; |
| 753 } | 709 } |
| 754 | 710 |
| 755 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const { | 711 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() { |
| 756 return TotalScrollOffset(); | 712 return CurrentScrollOffset(); |
| 757 } | 713 } |
| 758 | 714 |
| 759 void LayerImpl::OnFilterAnimated(const FilterOperations& filters) { | 715 void LayerImpl::OnFilterAnimated(const FilterOperations& filters) { |
| 760 SetFilters(filters); | 716 SetFilters(filters); |
| 761 } | 717 } |
| 762 | 718 |
| 763 void LayerImpl::OnOpacityAnimated(float opacity) { | 719 void LayerImpl::OnOpacityAnimated(float opacity) { |
| 764 SetOpacity(opacity); | 720 SetOpacity(opacity); |
| 765 } | 721 } |
| 766 | 722 |
| 767 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { | 723 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { |
| 768 SetTransform(transform); | 724 SetTransform(transform); |
| 769 } | 725 } |
| 770 | 726 |
| 771 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { | 727 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { |
| 772 // Only layers in the active tree should need to do anything here, since | 728 // Only layers in the active tree should need to do anything here, since |
| 773 // layers in the pending tree will find out about these changes as a | 729 // layers in the pending tree will find out about these changes as a |
| 774 // result of the call to SetScrollDelta. | 730 // result of the shared SyncedProperty. |
| 775 if (!IsActive()) | 731 if (!IsActive()) |
| 776 return; | 732 return; |
| 777 | 733 |
| 778 SetScrollDelta(scroll_offset.DeltaFrom(scroll_offset_)); | 734 SetScrollOffsetOnActiveTree(scroll_offset); |
| 779 | 735 |
| 780 layer_tree_impl_->DidAnimateScrollOffset(); | 736 layer_tree_impl_->DidAnimateScrollOffset(); |
| 781 } | 737 } |
| 782 | 738 |
| 783 void LayerImpl::OnAnimationWaitingForDeletion() {} | 739 void LayerImpl::OnAnimationWaitingForDeletion() {} |
| 784 | 740 |
| 785 bool LayerImpl::IsActive() const { | 741 bool LayerImpl::IsActive() const { |
| 786 return layer_tree_impl_->IsActiveTree(); | 742 return layer_tree_impl_->IsActiveTree(); |
| 787 } | 743 } |
| 788 | 744 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 | 1033 |
| 1078 draw_properties_.contents_scale_x = contents_scale_x; | 1034 draw_properties_.contents_scale_x = contents_scale_x; |
| 1079 draw_properties_.contents_scale_y = contents_scale_y; | 1035 draw_properties_.contents_scale_y = contents_scale_y; |
| 1080 NoteLayerPropertyChanged(); | 1036 NoteLayerPropertyChanged(); |
| 1081 } | 1037 } |
| 1082 | 1038 |
| 1083 void LayerImpl::SetScrollOffsetDelegate( | 1039 void LayerImpl::SetScrollOffsetDelegate( |
| 1084 ScrollOffsetDelegate* scroll_offset_delegate) { | 1040 ScrollOffsetDelegate* scroll_offset_delegate) { |
| 1085 // Having both a scroll parent and a scroll offset delegate is unsupported. | 1041 // Having both a scroll parent and a scroll offset delegate is unsupported. |
| 1086 DCHECK(!scroll_parent_); | 1042 DCHECK(!scroll_parent_); |
| 1087 if (!scroll_offset_delegate && scroll_offset_delegate_) { | 1043 if (!scroll_offset_delegate && scroll_offset_delegate_) |
| 1088 scroll_delta_ = scroll_offset_delegate_->GetTotalScrollOffset().DeltaFrom( | 1044 scroll_offset_->SetCurrent(scroll_offset_delegate_->GetTotalScrollOffset()); |
| 1089 scroll_offset_); | 1045 gfx::ScrollOffset total_offset = CurrentScrollOffset(); |
| 1090 } | |
| 1091 gfx::ScrollOffset total_offset = TotalScrollOffset(); | |
| 1092 scroll_offset_delegate_ = scroll_offset_delegate; | 1046 scroll_offset_delegate_ = scroll_offset_delegate; |
| 1093 if (scroll_offset_delegate_) | 1047 if (scroll_offset_delegate_) |
| 1094 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); | 1048 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); |
| 1095 } | 1049 } |
| 1096 | 1050 |
| 1097 bool LayerImpl::IsExternalFlingActive() const { | 1051 bool LayerImpl::IsExternalFlingActive() const { |
| 1098 return scroll_offset_delegate_ && | 1052 return scroll_offset_delegate_ && |
| 1099 scroll_offset_delegate_->IsExternalFlingActive(); | 1053 scroll_offset_delegate_->IsExternalFlingActive(); |
| 1100 } | 1054 } |
| 1101 | 1055 |
| 1102 void LayerImpl::DidScroll() { | 1056 void LayerImpl::SetScrollOffsetOnActiveTree( |
| 1057 const gfx::ScrollOffset& scroll_offset) { | |
| 1058 DCHECK(IsActive()); | |
| 1059 if (scroll_offset_->SetCurrent(scroll_offset)) | |
| 1060 DidUpdateScrollOffset(); | |
| 1061 } | |
| 1062 | |
| 1063 void LayerImpl::PushScrollOffsetFromMainThread( | |
| 1064 const gfx::ScrollOffset& scroll_offset) { | |
| 1065 PushScrollOffset(&scroll_offset); | |
| 1066 } | |
| 1067 | |
| 1068 void LayerImpl::RefreshScrollDelegate() { | |
| 1069 if (scroll_offset_delegate_) { | |
| 1070 SetScrollOffsetOnActiveTree( | |
| 1071 gfx::ScrollOffset(scroll_offset_delegate_->GetTotalScrollOffset())); | |
| 1072 } | |
| 1073 } | |
| 1074 | |
| 1075 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() { | |
| 1076 RefreshScrollDelegate(); | |
|
enne (OOO)
2015/01/16 23:25:14
Is there a better place to do this? "CurrentScroll
aelias_OOO_until_Jul13
2015/01/30 05:52:30
Fixed. I added "RefreshFromScrollDelegate()" call
| |
| 1077 return scroll_offset_->Current(IsActive()); | |
| 1078 } | |
| 1079 | |
| 1080 void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) { | |
| 1081 DCHECK(scroll_offset || IsActive()); | |
| 1082 bool changed = false; | |
| 1083 if (scroll_offset) { | |
| 1084 DCHECK(!IsActive() || !layer_tree_impl_->settings().impl_side_painting); | |
| 1085 changed |= scroll_offset_->PushFromMainThread(*scroll_offset); | |
| 1086 } | |
| 1087 if (IsActive()) | |
| 1088 changed |= scroll_offset_->PushPendingToActive(); | |
| 1089 | |
| 1090 if (changed) | |
| 1091 DidUpdateScrollOffset(); | |
| 1092 } | |
| 1093 | |
| 1094 void LayerImpl::DidUpdateScrollOffset() { | |
| 1095 if (scroll_offset_delegate_) { | |
| 1096 scroll_offset_delegate_->SetTotalScrollOffset( | |
| 1097 scroll_offset_->Current(IsActive())); | |
| 1098 scroll_offset_delegate_->Update(); | |
| 1099 } | |
| 1100 | |
| 1103 NoteLayerPropertyChangedForSubtree(); | 1101 NoteLayerPropertyChangedForSubtree(); |
| 1104 ScrollbarParametersDidChange(false); | 1102 ScrollbarParametersDidChange(false); |
| 1105 } | 1103 } |
| 1106 | 1104 |
| 1107 void LayerImpl::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { | |
| 1108 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); | |
| 1109 } | |
| 1110 | |
| 1111 void LayerImpl::SetScrollOffsetAndDelta(const gfx::ScrollOffset& scroll_offset, | |
| 1112 const gfx::Vector2dF& scroll_delta) { | |
| 1113 bool changed = false; | |
| 1114 | |
| 1115 last_scroll_offset_ = scroll_offset; | |
| 1116 | |
| 1117 if (scroll_offset_ != scroll_offset) { | |
| 1118 changed = true; | |
| 1119 scroll_offset_ = scroll_offset; | |
| 1120 | |
| 1121 if (scroll_offset_delegate_) | |
| 1122 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); | |
| 1123 } | |
| 1124 | |
| 1125 if (ScrollDelta() != scroll_delta) { | |
| 1126 changed = true; | |
| 1127 if (layer_tree_impl()->IsActiveTree()) { | |
| 1128 LayerImpl* pending_twin = | |
| 1129 layer_tree_impl()->FindPendingTreeLayerById(id()); | |
| 1130 if (pending_twin) { | |
| 1131 // The pending twin can't mirror the scroll delta of the active | |
| 1132 // layer. Although the delta - sent scroll delta difference is | |
| 1133 // identical for both twins, the sent scroll delta for the pending | |
| 1134 // layer is zero, as anything that has been sent has been baked | |
| 1135 // into the layer's position/scroll offset as a part of commit. | |
| 1136 DCHECK(pending_twin->sent_scroll_delta().IsZero()); | |
| 1137 pending_twin->SetScrollDelta(scroll_delta - sent_scroll_delta()); | |
| 1138 } | |
| 1139 } | |
| 1140 | |
| 1141 if (scroll_offset_delegate_) { | |
| 1142 scroll_offset_delegate_->SetTotalScrollOffset( | |
| 1143 ScrollOffsetWithDelta(scroll_offset_, scroll_delta)); | |
| 1144 } else { | |
| 1145 scroll_delta_ = scroll_delta; | |
| 1146 } | |
| 1147 } | |
| 1148 | |
| 1149 if (changed) { | |
| 1150 if (scroll_offset_delegate_) | |
| 1151 scroll_offset_delegate_->Update(); | |
| 1152 DidScroll(); | |
| 1153 } | |
| 1154 } | |
| 1155 | |
| 1156 gfx::Vector2dF LayerImpl::ScrollDelta() const { | |
| 1157 if (scroll_offset_delegate_) { | |
| 1158 return scroll_offset_delegate_->GetTotalScrollOffset().DeltaFrom( | |
| 1159 scroll_offset_); | |
| 1160 } | |
| 1161 return scroll_delta_; | |
| 1162 } | |
| 1163 | |
| 1164 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& scroll_delta) { | |
| 1165 SetScrollOffsetAndDelta(scroll_offset_, scroll_delta); | |
| 1166 } | |
| 1167 | |
| 1168 gfx::ScrollOffset LayerImpl::TotalScrollOffset() const { | |
| 1169 return ScrollOffsetWithDelta(scroll_offset_, ScrollDelta()); | |
| 1170 } | |
| 1171 | |
| 1172 void LayerImpl::SetDoubleSided(bool double_sided) { | 1105 void LayerImpl::SetDoubleSided(bool double_sided) { |
| 1173 if (double_sided_ == double_sided) | 1106 if (double_sided_ == double_sided) |
| 1174 return; | 1107 return; |
| 1175 | 1108 |
| 1176 double_sided_ = double_sided; | 1109 double_sided_ = double_sided; |
| 1177 NoteLayerPropertyChangedForSubtree(); | 1110 NoteLayerPropertyChangedForSubtree(); |
| 1178 } | 1111 } |
| 1179 | 1112 |
| 1180 SimpleEnclosedRegion LayerImpl::VisibleContentOpaqueRegion() const { | 1113 SimpleEnclosedRegion LayerImpl::VisibleContentOpaqueRegion() const { |
| 1181 if (contents_opaque()) | 1114 if (contents_opaque()) |
| 1182 return SimpleEnclosedRegion(visible_content_rect()); | 1115 return SimpleEnclosedRegion(visible_content_rect()); |
| 1183 return SimpleEnclosedRegion(); | 1116 return SimpleEnclosedRegion(); |
| 1184 } | 1117 } |
| 1185 | 1118 |
| 1186 void LayerImpl::DidBeginTracing() {} | 1119 void LayerImpl::DidBeginTracing() {} |
| 1187 | 1120 |
| 1188 void LayerImpl::ReleaseResources() {} | 1121 void LayerImpl::ReleaseResources() {} |
| 1189 | 1122 |
| 1190 gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { | 1123 gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { |
| 1191 if (!scroll_clip_layer_ || bounds().IsEmpty()) | 1124 if (!scroll_clip_layer_ || bounds().IsEmpty()) |
| 1192 return gfx::ScrollOffset(); | 1125 return gfx::ScrollOffset(); |
| 1193 | 1126 |
| 1194 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer(); | 1127 LayerImpl const* page_scale_layer = layer_tree_impl()->page_scale_layer(); |
| 1195 DCHECK(this != page_scale_layer); | 1128 DCHECK(this != page_scale_layer); |
| 1196 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() || | 1129 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() || |
| 1197 IsContainerForFixedPositionLayers()); | 1130 IsContainerForFixedPositionLayers()); |
| 1198 | 1131 |
| 1199 gfx::SizeF scaled_scroll_bounds(BoundsForScrolling()); | |
| 1200 | |
| 1201 float scale_factor = 1.f; | 1132 float scale_factor = 1.f; |
| 1202 for (LayerImpl const* current_layer = this; | 1133 for (LayerImpl const* current_layer = this; |
| 1203 current_layer != scroll_clip_layer_; | 1134 current_layer != scroll_clip_layer_; |
| 1204 current_layer = current_layer->parent()) { | 1135 current_layer = current_layer->parent()) { |
| 1205 DCHECK(current_layer); | 1136 if (current_layer == page_scale_layer) |
| 1206 float current_layer_scale = 1.f; | 1137 scale_factor = layer_tree_impl()->current_page_scale_factor(); |
| 1138 } | |
| 1207 | 1139 |
| 1208 const gfx::Transform& layer_transform = current_layer->transform(); | 1140 gfx::SizeF scaled_scroll_bounds = |
| 1209 if (current_layer == page_scale_layer) { | 1141 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor)); |
| 1210 DCHECK(layer_transform.IsIdentity()); | |
| 1211 current_layer_scale = layer_tree_impl()->current_page_scale_factor(); | |
| 1212 } else { | |
| 1213 // TODO(wjmaclean) Should we allow for translation too? | |
| 1214 DCHECK(layer_transform.IsScale2d()); | |
| 1215 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); | |
| 1216 // TODO(wjmaclean) Allow for non-isotropic scales. | |
| 1217 DCHECK(layer_scale.x() == layer_scale.y()); | |
| 1218 current_layer_scale = layer_scale.x(); | |
| 1219 } | |
| 1220 | |
| 1221 scale_factor *= current_layer_scale; | |
| 1222 } | |
| 1223 // TODO(wjmaclean) Once we move to a model where the two-viewport model is | |
| 1224 // turned on in all builds, remove the next two lines. For now however, the | |
| 1225 // page scale layer may coincide with the clip layer, and so this is | |
| 1226 // necessary. | |
| 1227 if (page_scale_layer == scroll_clip_layer_) | |
| 1228 scale_factor *= layer_tree_impl()->current_page_scale_factor(); | |
| 1229 | |
| 1230 scaled_scroll_bounds.SetSize(scale_factor * scaled_scroll_bounds.width(), | |
| 1231 scale_factor * scaled_scroll_bounds.height()); | |
| 1232 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds); | 1142 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds); |
| 1233 | 1143 |
| 1234 gfx::ScrollOffset max_offset( | 1144 gfx::ScrollOffset max_offset( |
| 1235 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), | 1145 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), |
| 1236 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); | 1146 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); |
| 1237 // We need the final scroll offset to be in CSS coords. | 1147 // We need the final scroll offset to be in CSS coords. |
| 1238 max_offset.Scale(1 / scale_factor); | 1148 max_offset.Scale(1 / scale_factor); |
| 1239 max_offset.SetToMax(gfx::ScrollOffset()); | 1149 max_offset.SetToMax(gfx::ScrollOffset()); |
| 1240 return max_offset; | 1150 return max_offset; |
| 1241 } | 1151 } |
| 1242 | 1152 |
| 1153 gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits( | |
| 1154 gfx::ScrollOffset offset) const { | |
| 1155 offset.SetToMin(MaxScrollOffset()); | |
| 1156 offset.SetToMax(gfx::ScrollOffset()); | |
| 1157 return offset; | |
| 1158 } | |
| 1159 | |
| 1243 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { | 1160 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { |
| 1244 gfx::ScrollOffset max_offset = MaxScrollOffset(); | 1161 gfx::ScrollOffset old_offset = CurrentScrollOffset(); |
| 1245 gfx::ScrollOffset old_offset = TotalScrollOffset(); | 1162 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset); |
| 1246 gfx::ScrollOffset clamped_offset = old_offset; | |
| 1247 | |
| 1248 clamped_offset.SetToMin(max_offset); | |
| 1249 clamped_offset.SetToMax(gfx::ScrollOffset()); | |
| 1250 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset); | 1163 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset); |
| 1251 if (!delta.IsZero()) | 1164 if (!delta.IsZero()) |
| 1252 ScrollBy(delta); | 1165 ScrollBy(delta); |
| 1253 | |
| 1254 return delta; | 1166 return delta; |
| 1255 } | 1167 } |
| 1256 | 1168 |
| 1257 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, | 1169 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, |
| 1258 LayerImpl* scrollbar_clip_layer, | 1170 LayerImpl* scrollbar_clip_layer, |
| 1259 bool on_resize) const { | 1171 bool on_resize) const { |
| 1260 DCHECK(scrollbar_layer); | 1172 DCHECK(scrollbar_layer); |
| 1261 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer(); | 1173 LayerImpl* page_scale_layer = layer_tree_impl()->page_scale_layer(); |
| 1262 | 1174 |
| 1263 DCHECK(this != page_scale_layer); | 1175 DCHECK(this != page_scale_layer); |
| 1264 DCHECK(scrollbar_clip_layer); | 1176 DCHECK(scrollbar_clip_layer); |
| 1265 gfx::RectF clip_rect(gfx::PointF(), | 1177 gfx::RectF clip_rect(gfx::PointF(), |
| 1266 scrollbar_clip_layer->BoundsForScrolling()); | 1178 scrollbar_clip_layer->BoundsForScrolling()); |
| 1267 | 1179 |
| 1268 // See comment in MaxScrollOffset() regarding the use of the content layer | 1180 // See comment in MaxScrollOffset() regarding the use of the content layer |
| 1269 // bounds here. | 1181 // bounds here. |
| 1270 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling()); | 1182 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling()); |
| 1271 | 1183 |
| 1272 if (scroll_rect.size().IsEmpty()) | 1184 if (scroll_rect.size().IsEmpty()) |
| 1273 return; | 1185 return; |
| 1274 | 1186 |
| 1275 // TODO(wjmaclean) This computation is nearly identical to the one in | |
| 1276 // MaxScrollOffset. Find some way to combine these. | |
| 1277 gfx::ScrollOffset current_offset; | 1187 gfx::ScrollOffset current_offset; |
| 1278 for (LayerImpl const* current_layer = this; | 1188 for (LayerImpl const* current_layer = this; |
| 1279 current_layer != scrollbar_clip_layer; | 1189 current_layer != scrollbar_clip_layer; |
| 1280 current_layer = current_layer->parent()) { | 1190 current_layer = current_layer->parent()) { |
| 1281 DCHECK(current_layer); | 1191 current_offset += scroll_offset_->Current(IsActive()); |
| 1282 const gfx::Transform& layer_transform = current_layer->transform(); | |
| 1283 if (current_layer == page_scale_layer) { | 1192 if (current_layer == page_scale_layer) { |
| 1284 DCHECK(layer_transform.IsIdentity()); | |
| 1285 float scale_factor = layer_tree_impl()->current_page_scale_factor(); | 1193 float scale_factor = layer_tree_impl()->current_page_scale_factor(); |
| 1286 current_offset.Scale(scale_factor); | 1194 current_offset.Scale(scale_factor); |
| 1287 scroll_rect.Scale(scale_factor); | 1195 scroll_rect.Scale(scale_factor); |
| 1288 } else { | |
| 1289 DCHECK(layer_transform.IsScale2d()); | |
| 1290 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); | |
| 1291 DCHECK(layer_scale.x() == layer_scale.y()); | |
| 1292 gfx::ScrollOffset new_offset = ScrollOffsetWithDelta( | |
| 1293 current_layer->scroll_offset(), current_layer->ScrollDelta()); | |
| 1294 new_offset.Scale(layer_scale.x(), layer_scale.y()); | |
| 1295 current_offset += new_offset; | |
| 1296 } | 1196 } |
| 1297 } | 1197 } |
| 1298 // TODO(wjmaclean) Once we move to a model where the two-viewport model is | |
| 1299 // turned on in all builds, remove the next two lines. For now however, the | |
| 1300 // page scale layer may coincide with the clip layer, and so this is | |
| 1301 // necessary. | |
| 1302 if (page_scale_layer == scrollbar_clip_layer) { | |
| 1303 scroll_rect.Scale(layer_tree_impl()->current_page_scale_factor()); | |
| 1304 current_offset.Scale(layer_tree_impl()->current_page_scale_factor()); | |
| 1305 } | |
| 1306 | 1198 |
| 1307 bool scrollbar_needs_animation = false; | 1199 bool scrollbar_needs_animation = false; |
| 1308 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust( | 1200 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust( |
| 1309 scrollbar_clip_layer->bounds_delta().y()); | 1201 scrollbar_clip_layer->bounds_delta().y()); |
| 1310 if (scrollbar_layer->orientation() == HORIZONTAL) { | 1202 if (scrollbar_layer->orientation() == HORIZONTAL) { |
| 1311 float visible_ratio = clip_rect.width() / scroll_rect.width(); | 1203 float visible_ratio = clip_rect.width() / scroll_rect.width(); |
| 1312 scrollbar_needs_animation |= | 1204 scrollbar_needs_animation |= |
| 1313 scrollbar_layer->SetCurrentPos(current_offset.x()); | 1205 scrollbar_layer->SetCurrentPos(current_offset.x()); |
| 1314 scrollbar_needs_animation |= | 1206 scrollbar_needs_animation |= |
| 1315 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width()); | 1207 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width()); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1459 state->SetDouble("opacity", opacity()); | 1351 state->SetDouble("opacity", opacity()); |
| 1460 | 1352 |
| 1461 state->BeginArray("position"); | 1353 state->BeginArray("position"); |
| 1462 MathUtil::AddToTracedValue(position_, state); | 1354 MathUtil::AddToTracedValue(position_, state); |
| 1463 state->EndArray(); | 1355 state->EndArray(); |
| 1464 | 1356 |
| 1465 state->SetInteger("draws_content", DrawsContent()); | 1357 state->SetInteger("draws_content", DrawsContent()); |
| 1466 state->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes()); | 1358 state->SetInteger("gpu_memory_usage", GPUMemoryUsageInBytes()); |
| 1467 | 1359 |
| 1468 state->BeginArray("scroll_offset"); | 1360 state->BeginArray("scroll_offset"); |
| 1469 MathUtil::AddToTracedValue(scroll_offset_, state); | 1361 MathUtil::AddToTracedValue(scroll_offset_ |
| 1362 ? scroll_offset_->Current(IsActive()) | |
| 1363 : gfx::ScrollOffset(), | |
| 1364 state); | |
| 1470 state->EndArray(); | 1365 state->EndArray(); |
| 1471 | 1366 |
| 1472 state->BeginArray("transform_origin"); | 1367 state->BeginArray("transform_origin"); |
| 1473 MathUtil::AddToTracedValue(transform_origin_, state); | 1368 MathUtil::AddToTracedValue(transform_origin_, state); |
| 1474 state->EndArray(); | 1369 state->EndArray(); |
| 1475 | 1370 |
| 1476 bool clipped; | 1371 bool clipped; |
| 1477 gfx::QuadF layer_quad = MathUtil::MapQuad( | 1372 gfx::QuadF layer_quad = MathUtil::MapQuad( |
| 1478 screen_space_transform(), | 1373 screen_space_transform(), |
| 1479 gfx::QuadF(gfx::Rect(content_bounds())), | 1374 gfx::QuadF(gfx::Rect(content_bounds())), |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1595 SetNeedsPushProperties(); | 1490 SetNeedsPushProperties(); |
| 1596 layer_tree_impl()->set_needs_update_draw_properties(); | 1491 layer_tree_impl()->set_needs_update_draw_properties(); |
| 1597 if (should_have_render_surface) { | 1492 if (should_have_render_surface) { |
| 1598 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); | 1493 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); |
| 1599 return; | 1494 return; |
| 1600 } | 1495 } |
| 1601 render_surface_.reset(); | 1496 render_surface_.reset(); |
| 1602 } | 1497 } |
| 1603 | 1498 |
| 1604 } // namespace cc | 1499 } // namespace cc |
| OLD | NEW |