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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 | 347 |
348 RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const { | 348 RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const { |
349 return RenderPassId(0, 0); | 349 return RenderPassId(0, 0); |
350 } | 350 } |
351 | 351 |
352 ResourceProvider::ResourceId LayerImpl::ContentsResourceId() const { | 352 ResourceProvider::ResourceId LayerImpl::ContentsResourceId() const { |
353 NOTREACHED(); | 353 NOTREACHED(); |
354 return 0; | 354 return 0; |
355 } | 355 } |
356 | 356 |
357 void LayerImpl::SetSentScrollDelta(const gfx::Vector2d& sent_scroll_delta) { | 357 void LayerImpl::SetSentScrollDelta(const gfx::ScrollOffset& sent_scroll_delta) { |
358 // Pending tree never has sent scroll deltas | 358 // Pending tree never has sent scroll deltas |
359 DCHECK(layer_tree_impl()->IsActiveTree()); | 359 DCHECK(layer_tree_impl()->IsActiveTree()); |
360 | 360 |
361 if (sent_scroll_delta_ == sent_scroll_delta) | 361 if (sent_scroll_delta_ == sent_scroll_delta) |
362 return; | 362 return; |
363 | 363 |
364 sent_scroll_delta_ = sent_scroll_delta; | 364 sent_scroll_delta_ = sent_scroll_delta; |
365 } | 365 } |
366 | 366 |
367 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { | 367 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { |
368 DCHECK(scrollable()); | 368 DCHECK(scrollable()); |
369 gfx::Vector2dF min_delta = -scroll_offset_; | 369 gfx::Vector2dF min_delta = -ToVector2dF(scroll_offset_); |
370 gfx::Vector2dF max_delta = MaxScrollOffset() - scroll_offset_; | 370 gfx::Vector2dF max_delta = MaxScrollOffset() - ToVector2dF(scroll_offset_); |
danakj
2014/09/25 15:13:30
to ToVector2dF after the subtraction - MaxScrollOf
Yufeng Shen (Slow to review)
2014/09/25 20:06:23
Done.
| |
371 // Clamp new_delta so that position + delta stays within scroll bounds. | 371 // Clamp new_delta so that position + delta stays within scroll bounds. |
372 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); | 372 gfx::Vector2dF new_delta = (ScrollDelta() + scroll); |
373 new_delta.SetToMax(min_delta); | 373 new_delta.SetToMax(min_delta); |
374 new_delta.SetToMin(max_delta); | 374 new_delta.SetToMin(max_delta); |
375 gfx::Vector2dF unscrolled = | 375 gfx::Vector2dF unscrolled = |
376 ScrollDelta() + scroll - new_delta; | 376 ScrollDelta() + scroll - new_delta; |
377 SetScrollDelta(new_delta); | 377 SetScrollDelta(new_delta); |
378 | 378 |
379 return unscrolled; | 379 return unscrolled; |
380 } | 380 } |
(...skipping 11 matching lines...) Expand all Loading... | |
392 // | 392 // |
393 // This function should not change the total scroll offset; it just shifts | 393 // This function should not change the total scroll offset; it just shifts |
394 // some of the scroll delta to the scroll offset. Therefore, adjust these | 394 // some of the scroll delta to the scroll offset. Therefore, adjust these |
395 // variables directly rather than calling the scroll offset delegate to | 395 // variables directly rather than calling the scroll offset delegate to |
396 // avoid sending it multiple spurious calls. | 396 // avoid sending it multiple spurious calls. |
397 // | 397 // |
398 // Because of the way scroll delta is calculated with a delegate, this will | 398 // Because of the way scroll delta is calculated with a delegate, this will |
399 // leave the total scroll offset unchanged on this layer regardless of | 399 // leave the total scroll offset unchanged on this layer regardless of |
400 // whether a delegate is being used. | 400 // whether a delegate is being used. |
401 scroll_offset_ += sent_scroll_delta_; | 401 scroll_offset_ += sent_scroll_delta_; |
402 scroll_delta_ -= sent_scroll_delta_; | 402 scroll_delta_ -= ToVector2dF(sent_scroll_delta_); |
403 sent_scroll_delta_ = gfx::Vector2d(); | 403 sent_scroll_delta_ = gfx::ScrollOffset(); |
404 } | 404 } |
405 | 405 |
406 void LayerImpl::ApplyScrollDeltasSinceBeginMainFrame() { | 406 void LayerImpl::ApplyScrollDeltasSinceBeginMainFrame() { |
407 // Only the pending tree can have missing scrolls. | 407 // Only the pending tree can have missing scrolls. |
408 DCHECK(layer_tree_impl()->IsPendingTree()); | 408 DCHECK(layer_tree_impl()->IsPendingTree()); |
409 if (!scrollable()) | 409 if (!scrollable()) |
410 return; | 410 return; |
411 | 411 |
412 // Pending tree should never have sent scroll deltas. | 412 // Pending tree should never have sent scroll deltas. |
413 DCHECK(sent_scroll_delta().IsZero()); | 413 DCHECK(sent_scroll_delta().IsZero()); |
414 | 414 |
415 LayerImpl* active_twin = layer_tree_impl()->FindActiveTreeLayerById(id()); | 415 LayerImpl* active_twin = layer_tree_impl()->FindActiveTreeLayerById(id()); |
416 if (active_twin) { | 416 if (active_twin) { |
417 // Scrolls that happens after begin frame (where the sent scroll delta | 417 // Scrolls that happens after begin frame (where the sent scroll delta |
418 // comes from) and commit need to be applied to the pending tree | 418 // comes from) and commit need to be applied to the pending tree |
419 // so that it is up to date with the total scroll. | 419 // so that it is up to date with the total scroll. |
420 SetScrollDelta(active_twin->ScrollDelta() - | 420 SetScrollDelta(active_twin->ScrollDelta() - |
421 active_twin->sent_scroll_delta()); | 421 ToVector2dF(active_twin->sent_scroll_delta())); |
422 } | 422 } |
423 } | 423 } |
424 | 424 |
425 InputHandler::ScrollStatus LayerImpl::TryScroll( | 425 InputHandler::ScrollStatus LayerImpl::TryScroll( |
426 const gfx::PointF& screen_space_point, | 426 const gfx::PointF& screen_space_point, |
427 InputHandler::ScrollInputType type) const { | 427 InputHandler::ScrollInputType type) const { |
428 if (should_scroll_on_main_thread()) { | 428 if (should_scroll_on_main_thread()) { |
429 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread"); | 429 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread"); |
430 return InputHandler::ScrollOnMainThread; | 430 return InputHandler::ScrollOnMainThread; |
431 } | 431 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 layer->SetPositionConstraint(position_constraint_); | 531 layer->SetPositionConstraint(position_constraint_); |
532 layer->SetShouldFlattenTransform(should_flatten_transform_); | 532 layer->SetShouldFlattenTransform(should_flatten_transform_); |
533 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 533 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
534 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); | 534 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
535 | 535 |
536 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() | 536 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() |
537 : Layer::INVALID_ID); | 537 : Layer::INVALID_ID); |
538 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 538 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
539 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 539 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
540 layer->SetScrollOffsetAndDelta( | 540 layer->SetScrollOffsetAndDelta( |
541 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); | 541 scroll_offset_, |
542 layer->SetSentScrollDelta(gfx::Vector2d()); | 542 layer->ScrollDelta() - ToVector2dF(layer->sent_scroll_delta())); |
543 layer->SetSentScrollDelta(gfx::ScrollOffset()); | |
543 layer->Set3dSortingContextId(sorting_context_id_); | 544 layer->Set3dSortingContextId(sorting_context_id_); |
544 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | 545 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
545 | 546 |
546 LayerImpl* scroll_parent = NULL; | 547 LayerImpl* scroll_parent = NULL; |
547 if (scroll_parent_) { | 548 if (scroll_parent_) { |
548 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 549 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
549 DCHECK(scroll_parent); | 550 DCHECK(scroll_parent); |
550 } | 551 } |
551 | 552 |
552 layer->SetScrollParent(scroll_parent); | 553 layer->SetScrollParent(scroll_parent); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 SetTransform(transform); | 753 SetTransform(transform); |
753 } | 754 } |
754 | 755 |
755 void LayerImpl::OnScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset) { | 756 void LayerImpl::OnScrollOffsetAnimated(const gfx::Vector2dF& scroll_offset) { |
756 // Only layers in the active tree should need to do anything here, since | 757 // Only layers in the active tree should need to do anything here, since |
757 // layers in the pending tree will find out about these changes as a | 758 // layers in the pending tree will find out about these changes as a |
758 // result of the call to SetScrollDelta. | 759 // result of the call to SetScrollDelta. |
759 if (!IsActive()) | 760 if (!IsActive()) |
760 return; | 761 return; |
761 | 762 |
762 SetScrollDelta(scroll_offset - scroll_offset_); | 763 SetScrollDelta(scroll_offset - ToVector2dF(scroll_offset_)); |
763 | 764 |
764 layer_tree_impl_->DidAnimateScrollOffset(); | 765 layer_tree_impl_->DidAnimateScrollOffset(); |
765 } | 766 } |
766 | 767 |
767 void LayerImpl::OnAnimationWaitingForDeletion() {} | 768 void LayerImpl::OnAnimationWaitingForDeletion() {} |
768 | 769 |
769 bool LayerImpl::IsActive() const { | 770 bool LayerImpl::IsActive() const { |
770 return layer_tree_impl_->IsActiveTree(); | 771 return layer_tree_impl_->IsActiveTree(); |
771 } | 772 } |
772 | 773 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1057 draw_properties_.contents_scale_x = contents_scale_x; | 1058 draw_properties_.contents_scale_x = contents_scale_x; |
1058 draw_properties_.contents_scale_y = contents_scale_y; | 1059 draw_properties_.contents_scale_y = contents_scale_y; |
1059 NoteLayerPropertyChanged(); | 1060 NoteLayerPropertyChanged(); |
1060 } | 1061 } |
1061 | 1062 |
1062 void LayerImpl::SetScrollOffsetDelegate( | 1063 void LayerImpl::SetScrollOffsetDelegate( |
1063 ScrollOffsetDelegate* scroll_offset_delegate) { | 1064 ScrollOffsetDelegate* scroll_offset_delegate) { |
1064 // Having both a scroll parent and a scroll offset delegate is unsupported. | 1065 // Having both a scroll parent and a scroll offset delegate is unsupported. |
1065 DCHECK(!scroll_parent_); | 1066 DCHECK(!scroll_parent_); |
1066 if (!scroll_offset_delegate && scroll_offset_delegate_) { | 1067 if (!scroll_offset_delegate && scroll_offset_delegate_) { |
1067 scroll_delta_ = | 1068 scroll_delta_ = scroll_offset_delegate_->GetTotalScrollOffset() - |
1068 scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; | 1069 ToVector2dF(scroll_offset_); |
1069 } | 1070 } |
1070 gfx::Vector2dF total_offset = TotalScrollOffset(); | 1071 gfx::Vector2dF total_offset = TotalScrollOffset(); |
1071 scroll_offset_delegate_ = scroll_offset_delegate; | 1072 scroll_offset_delegate_ = scroll_offset_delegate; |
1072 if (scroll_offset_delegate_) | 1073 if (scroll_offset_delegate_) |
1073 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); | 1074 scroll_offset_delegate_->SetTotalScrollOffset(total_offset); |
1074 } | 1075 } |
1075 | 1076 |
1076 bool LayerImpl::IsExternalFlingActive() const { | 1077 bool LayerImpl::IsExternalFlingActive() const { |
1077 return scroll_offset_delegate_ && | 1078 return scroll_offset_delegate_ && |
1078 scroll_offset_delegate_->IsExternalFlingActive(); | 1079 scroll_offset_delegate_->IsExternalFlingActive(); |
1079 } | 1080 } |
1080 | 1081 |
1081 void LayerImpl::SetScrollOffset(const gfx::Vector2d& scroll_offset) { | 1082 void LayerImpl::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) { |
1082 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); | 1083 SetScrollOffsetAndDelta(scroll_offset, ScrollDelta()); |
1083 } | 1084 } |
1084 | 1085 |
1085 void LayerImpl::SetScrollOffsetAndDelta(const gfx::Vector2d& scroll_offset, | 1086 void LayerImpl::SetScrollOffsetAndDelta(const gfx::ScrollOffset& scroll_offset, |
1086 const gfx::Vector2dF& scroll_delta) { | 1087 const gfx::Vector2dF& scroll_delta) { |
1087 bool changed = false; | 1088 bool changed = false; |
1088 | 1089 |
1089 last_scroll_offset_ = scroll_offset; | 1090 last_scroll_offset_ = ToVector2dF(scroll_offset); |
1090 | 1091 |
1091 if (scroll_offset_ != scroll_offset) { | 1092 if (scroll_offset_ != scroll_offset) { |
1092 changed = true; | 1093 changed = true; |
1093 scroll_offset_ = scroll_offset; | 1094 scroll_offset_ = scroll_offset; |
1094 | 1095 |
1095 if (scroll_offset_delegate_) | 1096 if (scroll_offset_delegate_) |
1096 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); | 1097 scroll_offset_delegate_->SetTotalScrollOffset(TotalScrollOffset()); |
1097 } | 1098 } |
1098 | 1099 |
1099 if (ScrollDelta() != scroll_delta) { | 1100 if (ScrollDelta() != scroll_delta) { |
1100 changed = true; | 1101 changed = true; |
1101 if (layer_tree_impl()->IsActiveTree()) { | 1102 if (layer_tree_impl()->IsActiveTree()) { |
1102 LayerImpl* pending_twin = | 1103 LayerImpl* pending_twin = |
1103 layer_tree_impl()->FindPendingTreeLayerById(id()); | 1104 layer_tree_impl()->FindPendingTreeLayerById(id()); |
1104 if (pending_twin) { | 1105 if (pending_twin) { |
1105 // The pending twin can't mirror the scroll delta of the active | 1106 // The pending twin can't mirror the scroll delta of the active |
1106 // layer. Although the delta - sent scroll delta difference is | 1107 // layer. Although the delta - sent scroll delta difference is |
1107 // identical for both twins, the sent scroll delta for the pending | 1108 // identical for both twins, the sent scroll delta for the pending |
1108 // layer is zero, as anything that has been sent has been baked | 1109 // layer is zero, as anything that has been sent has been baked |
1109 // into the layer's position/scroll offset as a part of commit. | 1110 // into the layer's position/scroll offset as a part of commit. |
1110 DCHECK(pending_twin->sent_scroll_delta().IsZero()); | 1111 DCHECK(pending_twin->sent_scroll_delta().IsZero()); |
1111 pending_twin->SetScrollDelta(scroll_delta - sent_scroll_delta()); | 1112 pending_twin->SetScrollDelta(scroll_delta - |
1113 ToVector2dF(sent_scroll_delta())); | |
1112 } | 1114 } |
1113 } | 1115 } |
1114 | 1116 |
1115 if (scroll_offset_delegate_) { | 1117 if (scroll_offset_delegate_) { |
1116 scroll_offset_delegate_->SetTotalScrollOffset(scroll_offset_ + | 1118 scroll_offset_delegate_->SetTotalScrollOffset( |
1117 scroll_delta); | 1119 ToVector2dF(scroll_offset_) + scroll_delta); |
1118 } else { | 1120 } else { |
1119 scroll_delta_ = scroll_delta; | 1121 scroll_delta_ = scroll_delta; |
1120 } | 1122 } |
1121 } | 1123 } |
1122 | 1124 |
1123 if (changed) { | 1125 if (changed) { |
1124 NoteLayerPropertyChangedForSubtree(); | 1126 NoteLayerPropertyChangedForSubtree(); |
1125 ScrollbarParametersDidChange(); | 1127 ScrollbarParametersDidChange(); |
1126 } | 1128 } |
1127 } | 1129 } |
1128 | 1130 |
1129 gfx::Vector2dF LayerImpl::ScrollDelta() const { | 1131 gfx::Vector2dF LayerImpl::ScrollDelta() const { |
1130 if (scroll_offset_delegate_) | 1132 if (scroll_offset_delegate_) { |
1131 return scroll_offset_delegate_->GetTotalScrollOffset() - scroll_offset_; | 1133 return scroll_offset_delegate_->GetTotalScrollOffset() - |
1134 ToVector2dF(scroll_offset_); | |
1135 } | |
1132 return scroll_delta_; | 1136 return scroll_delta_; |
1133 } | 1137 } |
1134 | 1138 |
1135 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& scroll_delta) { | 1139 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& scroll_delta) { |
1136 SetScrollOffsetAndDelta(scroll_offset_, scroll_delta); | 1140 SetScrollOffsetAndDelta(scroll_offset_, scroll_delta); |
1137 } | 1141 } |
1138 | 1142 |
1139 gfx::Vector2dF LayerImpl::TotalScrollOffset() const { | 1143 gfx::Vector2dF LayerImpl::TotalScrollOffset() const { |
1140 return scroll_offset_ + ScrollDelta(); | 1144 return ToVector2dF(scroll_offset_) + ScrollDelta(); |
1141 } | 1145 } |
1142 | 1146 |
1143 void LayerImpl::SetDoubleSided(bool double_sided) { | 1147 void LayerImpl::SetDoubleSided(bool double_sided) { |
1144 if (double_sided_ == double_sided) | 1148 if (double_sided_ == double_sided) |
1145 return; | 1149 return; |
1146 | 1150 |
1147 double_sided_ = double_sided; | 1151 double_sided_ = double_sided; |
1148 NoteLayerPropertyChangedForSubtree(); | 1152 NoteLayerPropertyChangedForSubtree(); |
1149 } | 1153 } |
1150 | 1154 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1253 const gfx::Transform& layer_transform = current_layer->transform(); | 1257 const gfx::Transform& layer_transform = current_layer->transform(); |
1254 if (current_layer == page_scale_layer) { | 1258 if (current_layer == page_scale_layer) { |
1255 DCHECK(layer_transform.IsIdentity()); | 1259 DCHECK(layer_transform.IsIdentity()); |
1256 float scale_factor = layer_tree_impl()->total_page_scale_factor(); | 1260 float scale_factor = layer_tree_impl()->total_page_scale_factor(); |
1257 current_offset.Scale(scale_factor); | 1261 current_offset.Scale(scale_factor); |
1258 scroll_rect.Scale(scale_factor); | 1262 scroll_rect.Scale(scale_factor); |
1259 } else { | 1263 } else { |
1260 DCHECK(layer_transform.IsScale2d()); | 1264 DCHECK(layer_transform.IsScale2d()); |
1261 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); | 1265 gfx::Vector2dF layer_scale = layer_transform.Scale2d(); |
1262 DCHECK(layer_scale.x() == layer_scale.y()); | 1266 DCHECK(layer_scale.x() == layer_scale.y()); |
1263 gfx::Vector2dF new_offset = | 1267 gfx::Vector2dF new_offset = ToVector2dF(current_layer->scroll_offset()) + |
1264 current_layer->scroll_offset() + current_layer->ScrollDelta(); | 1268 current_layer->ScrollDelta(); |
1265 new_offset.Scale(layer_scale.x(), layer_scale.y()); | 1269 new_offset.Scale(layer_scale.x(), layer_scale.y()); |
1266 current_offset += new_offset; | 1270 current_offset += new_offset; |
1267 } | 1271 } |
1268 } | 1272 } |
1269 // TODO(wjmaclean) Once we move to a model where the two-viewport model is | 1273 // TODO(wjmaclean) Once we move to a model where the two-viewport model is |
1270 // turned on in all builds, remove the next two lines. For now however, the | 1274 // turned on in all builds, remove the next two lines. For now however, the |
1271 // page scale layer may coincide with the clip layer, and so this is | 1275 // page scale layer may coincide with the clip layer, and so this is |
1272 // necessary. | 1276 // necessary. |
1273 if (page_scale_layer == scrollbar_clip_layer) { | 1277 if (page_scale_layer == scrollbar_clip_layer) { |
1274 scroll_rect.Scale(layer_tree_impl()->total_page_scale_factor()); | 1278 scroll_rect.Scale(layer_tree_impl()->total_page_scale_factor()); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1548 } | 1552 } |
1549 | 1553 |
1550 void LayerImpl::NotifyAnimationFinished( | 1554 void LayerImpl::NotifyAnimationFinished( |
1551 base::TimeTicks monotonic_time, | 1555 base::TimeTicks monotonic_time, |
1552 Animation::TargetProperty target_property) { | 1556 Animation::TargetProperty target_property) { |
1553 if (target_property == Animation::ScrollOffset) | 1557 if (target_property == Animation::ScrollOffset) |
1554 layer_tree_impl_->InputScrollAnimationFinished(); | 1558 layer_tree_impl_->InputScrollAnimationFinished(); |
1555 } | 1559 } |
1556 | 1560 |
1557 } // namespace cc | 1561 } // namespace cc |
OLD | NEW |