Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_tree_impl.h" | 5 #include "cc/layer_tree_impl.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "cc/animation.h" | |
| 9 #include "cc/animation_id_provider.h" | |
| 8 #include "cc/heads_up_display_layer_impl.h" | 10 #include "cc/heads_up_display_layer_impl.h" |
| 11 #include "cc/keyframed_animation_curve.h" | |
| 9 #include "cc/layer_tree_host_common.h" | 12 #include "cc/layer_tree_host_common.h" |
| 10 #include "cc/layer_tree_host_impl.h" | 13 #include "cc/layer_tree_host_impl.h" |
| 14 #include "cc/pinch_zoom_scrollbar.h" | |
| 15 #include "cc/scrollbar_layer_impl.h" | |
| 11 #include "ui/gfx/vector2d_conversions.h" | 16 #include "ui/gfx/vector2d_conversions.h" |
| 12 | 17 |
| 13 namespace cc { | 18 namespace cc { |
| 14 | 19 |
| 15 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) | 20 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) |
| 16 : layer_tree_host_impl_(layer_tree_host_impl), | 21 : layer_tree_host_impl_(layer_tree_host_impl), |
| 17 source_frame_number_(-1), | 22 source_frame_number_(-1), |
| 18 hud_layer_(0), | 23 hud_layer_(0), |
| 19 root_scroll_layer_(0), | 24 root_scroll_layer_(0), |
| 20 currently_scrolling_layer_(0), | 25 currently_scrolling_layer_(0), |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 target_tree->SetViewportSizeInvalid(); | 114 target_tree->SetViewportSizeInvalid(); |
| 110 else | 115 else |
| 111 target_tree->ResetViewportSizeInvalid(); | 116 target_tree->ResetViewportSizeInvalid(); |
| 112 | 117 |
| 113 if (hud_layer()) | 118 if (hud_layer()) |
| 114 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( | 119 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
| 115 LayerTreeHostCommon::findLayerInSubtree( | 120 LayerTreeHostCommon::findLayerInSubtree( |
| 116 target_tree->RootLayer(), hud_layer()->id()))); | 121 target_tree->RootLayer(), hud_layer()->id()))); |
| 117 else | 122 else |
| 118 target_tree->set_hud_layer(NULL); | 123 target_tree->set_hud_layer(NULL); |
| 124 | |
| 125 target_tree->SetPinchZoomHorizontalLayerId(pinch_zoom_scrollbar_horizontal_lay er_id); | |
| 126 target_tree->SetPinchZoomVerticalLayerId(pinch_zoom_scrollbar_vertical_layer_i d); | |
| 119 } | 127 } |
| 120 | 128 |
| 121 LayerImpl* LayerTreeImpl::RootScrollLayer() { | 129 LayerImpl* LayerTreeImpl::RootScrollLayer() { |
| 122 DCHECK(IsActiveTree()); | 130 DCHECK(IsActiveTree()); |
| 123 return root_scroll_layer_; | 131 return root_scroll_layer_; |
| 124 } | 132 } |
| 125 | 133 |
| 126 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { | 134 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { |
| 127 DCHECK(IsActiveTree()); | 135 DCHECK(IsActiveTree()); |
| 128 return currently_scrolling_layer_; | 136 return currently_scrolling_layer_; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 layer->didBecomeActive(); | 335 layer->didBecomeActive(); |
| 328 for (size_t i = 0; i < layer->children().size(); ++i) | 336 for (size_t i = 0; i < layer->children().size(); ++i) |
| 329 DidBecomeActiveRecursive(layer->children()[i]); | 337 DidBecomeActiveRecursive(layer->children()[i]); |
| 330 } | 338 } |
| 331 | 339 |
| 332 void LayerTreeImpl::DidBecomeActive() { | 340 void LayerTreeImpl::DidBecomeActive() { |
| 333 if (RootLayer()) | 341 if (RootLayer()) |
| 334 DidBecomeActiveRecursive(RootLayer()); | 342 DidBecomeActiveRecursive(RootLayer()); |
| 335 FindRootScrollLayer(); | 343 FindRootScrollLayer(); |
| 336 UpdateMaxScrollOffset(); | 344 UpdateMaxScrollOffset(); |
| 345 // When becoming active there may not be a currently scrolling layer so we | |
| 346 // need to force the update. | |
| 347 UpdatePinchZoomScrollbarsIfNeeded(UPDATE_MAIN_THREAD_SCROLL); | |
|
enne (OOO)
2013/03/06 19:32:58
Can you explain this more clearly? Why would the s
wjmaclean
2013/03/06 22:36:53
Main-thread scrolls just update properties on the
| |
| 337 } | 348 } |
| 338 | 349 |
| 339 bool LayerTreeImpl::ContentsTexturesPurged() const { | 350 bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 340 return contents_textures_purged_; | 351 return contents_textures_purged_; |
| 341 } | 352 } |
| 342 | 353 |
| 343 void LayerTreeImpl::SetContentsTexturesPurged() { | 354 void LayerTreeImpl::SetContentsTexturesPurged() { |
| 344 contents_textures_purged_ = true; | 355 contents_textures_purged_ = true; |
| 345 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); | 356 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); |
| 346 } | 357 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); | 490 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); |
| 480 for (LayerIteratorType it = LayerIteratorType::begin( | 491 for (LayerIteratorType it = LayerIteratorType::begin( |
| 481 &render_surface_layer_list_); it != end; ++it) { | 492 &render_surface_layer_list_); it != end; ++it) { |
| 482 if (!it.representsItself()) | 493 if (!it.representsItself()) |
| 483 continue; | 494 continue; |
| 484 state->Append((*it)->AsValue().release()); | 495 state->Append((*it)->AsValue().release()); |
| 485 } | 496 } |
| 486 return state.PassAs<base::Value>(); | 497 return state.PassAs<base::Value>(); |
| 487 } | 498 } |
| 488 | 499 |
| 500 void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) { | |
| 501 pinch_zoom_scrollbar_horizontal_layer_id = layer_id; | |
| 502 } | |
| 503 | |
| 504 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() { | |
| 505 return static_cast<ScrollbarLayerImpl*>(LayerById( | |
| 506 pinch_zoom_scrollbar_horizontal_layer_id)); | |
| 507 } | |
| 508 | |
| 509 void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) { | |
| 510 pinch_zoom_scrollbar_vertical_layer_id = layer_id; | |
| 511 } | |
| 512 | |
| 513 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() { | |
| 514 return static_cast<ScrollbarLayerImpl*>(LayerById( | |
| 515 pinch_zoom_scrollbar_vertical_layer_id)); | |
| 516 } | |
| 517 | |
| 518 void LayerTreeImpl::UpdatePinchZoomScrollbarsIfNeeded( | |
| 519 PinchZoomScrollbarUpdateReason update_reason) { | |
| 520 LayerImpl* root_scroll_layer = RootScrollLayer(); | |
| 521 if (!root_scroll_layer || | |
| 522 (update_reason == UPDATE_IMPL_THREAD_SCROLL && | |
| 523 root_scroll_layer != CurrentlyScrollingLayer())) | |
|
enne (OOO)
2013/03/06 19:32:58
What does the currently scrolling layer have to do
wjmaclean
2013/03/06 22:36:53
I had intended not to update the PZ scrollbars if
| |
| 524 return; | |
| 525 | |
| 526 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) { | |
| 527 scrollbar->setCurrentPos(root_scroll_layer->scrollOffset().x()); | |
| 528 scrollbar->setTotalSize(root_scroll_layer->bounds().width()); | |
| 529 scrollbar->setMaximum(root_scroll_layer->maxScrollOffset().x()); | |
| 530 } | |
| 531 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) { | |
| 532 scrollbar->setCurrentPos(root_scroll_layer->scrollOffset().y()); | |
| 533 scrollbar->setTotalSize(root_scroll_layer->bounds().height()); | |
| 534 scrollbar->setMaximum(root_scroll_layer->maxScrollOffset().y()); | |
| 535 } | |
| 536 } | |
| 537 | |
| 538 static scoped_ptr<Animation> MakePinchZoomFadeAnimation( | |
| 539 float start_opacity, float end_opacity) { | |
| 540 scoped_ptr<KeyframedFloatAnimationCurve> curve = | |
| 541 KeyframedFloatAnimationCurve::create(); | |
| 542 curve->addKeyframe(FloatKeyframe::create( | |
| 543 0, start_opacity, EaseInTimingFunction::create())); | |
| 544 curve->addKeyframe(FloatKeyframe::create( | |
| 545 PinchZoomScrollbar::kFadeDuration, end_opacity, | |
| 546 EaseInTimingFunction::create())); | |
| 547 | |
| 548 scoped_ptr<Animation> animation = Animation::create(curve.PassAs<AnimationCurv e>(), AnimationIdProvider::NextAnimationId(), 0, Animation::Opacity); | |
| 549 animation->setIsImplAnimationOnly(true); | |
| 550 | |
| 551 return animation.Pass(); | |
| 552 } | |
| 553 | |
| 554 void LayerTreeImpl::FadeInPinchZoomScrollbars() { | |
| 555 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1) | |
| 556 return; | |
| 557 | |
| 558 animationRegistrar()->GetAnimationControllerForId( | |
| 559 pinch_zoom_scrollbar_horizontal_layer_id)->addAnimation( | |
| 560 MakePinchZoomFadeAnimation(0.01, PinchZoomScrollbar::kDefaultOpacity)); | |
|
enne (OOO)
2013/03/06 19:32:58
Shouldn't you start the fade animation from the cu
wjmaclean
2013/03/06 22:36:53
Agreed, but we need the start opacity to be non-ze
enne (OOO)
2013/03/06 22:45:38
This is an impl-only animation. How does that int
wjmaclean
2013/03/07 22:57:39
Since the PZ scrollbar starts with opacity 0, it d
| |
| 561 | |
| 562 animationRegistrar()->GetAnimationControllerForId( | |
| 563 pinch_zoom_scrollbar_vertical_layer_id)->addAnimation( | |
| 564 MakePinchZoomFadeAnimation(0.01, PinchZoomScrollbar::kDefaultOpacity)); | |
| 565 } | |
| 566 | |
| 567 void LayerTreeImpl::FadeOutPinchZoomScrollbars() { | |
| 568 if (!HasPinchZoomScrollbars()) | |
| 569 return; | |
| 570 | |
| 571 if (PinchZoomScrollbarHorizontal()->opacity() == 0 && | |
| 572 PinchZoomScrollbarVertical()->opacity() == 0) | |
| 573 return; | |
| 574 | |
| 575 animationRegistrar()->GetAnimationControllerForId( | |
| 576 pinch_zoom_scrollbar_horizontal_layer_id)->addAnimation( | |
| 577 MakePinchZoomFadeAnimation(PinchZoomScrollbar::kDefaultOpacity, 0)); | |
| 578 | |
| 579 animationRegistrar()->GetAnimationControllerForId( | |
| 580 pinch_zoom_scrollbar_vertical_layer_id)->addAnimation( | |
| 581 MakePinchZoomFadeAnimation(PinchZoomScrollbar::kDefaultOpacity, 0)); | |
| 582 } | |
| 583 | |
| 489 } // namespace cc | 584 } // namespace cc |
| OLD | NEW |