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" | |
12 #include "cc/layer.h" | |
9 #include "cc/layer_tree_host_common.h" | 13 #include "cc/layer_tree_host_common.h" |
10 #include "cc/layer_tree_host_impl.h" | 14 #include "cc/layer_tree_host_impl.h" |
15 #include "cc/pinch_zoom_scrollbar.h" | |
16 #include "cc/scrollbar_layer_impl.h" | |
11 #include "ui/gfx/vector2d_conversions.h" | 17 #include "ui/gfx/vector2d_conversions.h" |
12 | 18 |
13 namespace cc { | 19 namespace cc { |
14 | 20 |
15 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) | 21 LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) |
16 : layer_tree_host_impl_(layer_tree_host_impl), | 22 : layer_tree_host_impl_(layer_tree_host_impl), |
17 source_frame_number_(-1), | 23 source_frame_number_(-1), |
18 hud_layer_(0), | 24 hud_layer_(0), |
19 root_scroll_layer_(0), | 25 root_scroll_layer_(0), |
20 currently_scrolling_layer_(0), | 26 currently_scrolling_layer_(0), |
21 background_color_(0), | 27 background_color_(0), |
22 has_transparent_background_(false), | 28 has_transparent_background_(false), |
29 pinch_zoom_scrollbar_horizontal_layer_id_(Layer::s_invalidLayerId), | |
30 pinch_zoom_scrollbar_vertical_layer_id_(Layer::s_invalidLayerId), | |
23 page_scale_factor_(1), | 31 page_scale_factor_(1), |
24 page_scale_delta_(1), | 32 page_scale_delta_(1), |
25 sent_page_scale_delta_(1), | 33 sent_page_scale_delta_(1), |
26 min_page_scale_factor_(0), | 34 min_page_scale_factor_(0), |
27 max_page_scale_factor_(0), | 35 max_page_scale_factor_(0), |
28 scrolling_layer_id_from_previous_tree_(0), | 36 scrolling_layer_id_from_previous_tree_(0), |
29 contents_textures_purged_(false), | 37 contents_textures_purged_(false), |
30 viewport_size_invalid_(false), | 38 viewport_size_invalid_(false), |
31 needs_update_draw_properties_(true), | 39 needs_update_draw_properties_(true), |
32 needs_full_tree_sync_(true) { | 40 needs_full_tree_sync_(true) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 target_tree->SetViewportSizeInvalid(); | 117 target_tree->SetViewportSizeInvalid(); |
110 else | 118 else |
111 target_tree->ResetViewportSizeInvalid(); | 119 target_tree->ResetViewportSizeInvalid(); |
112 | 120 |
113 if (hud_layer()) | 121 if (hud_layer()) |
114 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( | 122 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
115 LayerTreeHostCommon::findLayerInSubtree( | 123 LayerTreeHostCommon::findLayerInSubtree( |
116 target_tree->RootLayer(), hud_layer()->id()))); | 124 target_tree->RootLayer(), hud_layer()->id()))); |
117 else | 125 else |
118 target_tree->set_hud_layer(NULL); | 126 target_tree->set_hud_layer(NULL); |
127 | |
128 target_tree->SetPinchZoomHorizontalLayerId(pinch_zoom_scrollbar_horizontal_lay er_id_); | |
enne (OOO)
2013/03/11 21:08:24
style nit: 80 col.
wjmaclean
2013/03/12 16:13:07
Done.
| |
129 target_tree->SetPinchZoomVerticalLayerId(pinch_zoom_scrollbar_vertical_layer_i d_); | |
enne (OOO)
2013/03/11 21:08:24
style nit: 80 col.
wjmaclean
2013/03/12 16:13:07
Done.
| |
119 } | 130 } |
120 | 131 |
121 LayerImpl* LayerTreeImpl::RootScrollLayer() { | 132 LayerImpl* LayerTreeImpl::RootScrollLayer() { |
122 DCHECK(IsActiveTree()); | 133 DCHECK(IsActiveTree()); |
123 return root_scroll_layer_; | 134 return root_scroll_layer_; |
124 } | 135 } |
125 | 136 |
126 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { | 137 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { |
127 DCHECK(IsActiveTree()); | 138 DCHECK(IsActiveTree()); |
128 return currently_scrolling_layer_; | 139 return currently_scrolling_layer_; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 layer->didBecomeActive(); | 338 layer->didBecomeActive(); |
328 for (size_t i = 0; i < layer->children().size(); ++i) | 339 for (size_t i = 0; i < layer->children().size(); ++i) |
329 DidBecomeActiveRecursive(layer->children()[i]); | 340 DidBecomeActiveRecursive(layer->children()[i]); |
330 } | 341 } |
331 | 342 |
332 void LayerTreeImpl::DidBecomeActive() { | 343 void LayerTreeImpl::DidBecomeActive() { |
333 if (RootLayer()) | 344 if (RootLayer()) |
334 DidBecomeActiveRecursive(RootLayer()); | 345 DidBecomeActiveRecursive(RootLayer()); |
335 FindRootScrollLayer(); | 346 FindRootScrollLayer(); |
336 UpdateMaxScrollOffset(); | 347 UpdateMaxScrollOffset(); |
348 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after | |
349 // each commit (and after the root scroll layer has its max scroll offset | |
350 // set), we need to update pinch zoom scrollbars. | |
351 UpdatePinchZoomScrollbars(); | |
337 } | 352 } |
338 | 353 |
339 bool LayerTreeImpl::ContentsTexturesPurged() const { | 354 bool LayerTreeImpl::ContentsTexturesPurged() const { |
340 return contents_textures_purged_; | 355 return contents_textures_purged_; |
341 } | 356 } |
342 | 357 |
343 void LayerTreeImpl::SetContentsTexturesPurged() { | 358 void LayerTreeImpl::SetContentsTexturesPurged() { |
344 contents_textures_purged_ = true; | 359 contents_textures_purged_ = true; |
345 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); | 360 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); |
346 } | 361 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); | 494 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); |
480 for (LayerIteratorType it = LayerIteratorType::begin( | 495 for (LayerIteratorType it = LayerIteratorType::begin( |
481 &render_surface_layer_list_); it != end; ++it) { | 496 &render_surface_layer_list_); it != end; ++it) { |
482 if (!it.representsItself()) | 497 if (!it.representsItself()) |
483 continue; | 498 continue; |
484 state->Append((*it)->AsValue().release()); | 499 state->Append((*it)->AsValue().release()); |
485 } | 500 } |
486 return state.PassAs<base::Value>(); | 501 return state.PassAs<base::Value>(); |
487 } | 502 } |
488 | 503 |
504 void LayerTreeImpl::DidBeginScroll() { | |
505 if (HasPinchZoomScrollbars()) | |
506 FadeInPinchZoomScrollbars(); | |
507 } | |
508 | |
509 void LayerTreeImpl::DidUpdateScroll() { | |
510 if (HasPinchZoomScrollbars()) | |
511 UpdatePinchZoomScrollbars(); | |
512 } | |
513 | |
514 void LayerTreeImpl::DidEndScroll() { | |
515 if (HasPinchZoomScrollbars()) | |
516 FadeOutPinchZoomScrollbars(); | |
517 } | |
518 | |
519 void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) { | |
520 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id; | |
521 } | |
522 | |
523 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() { | |
524 return static_cast<ScrollbarLayerImpl*>(LayerById( | |
525 pinch_zoom_scrollbar_horizontal_layer_id_)); | |
526 } | |
527 | |
528 void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) { | |
529 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id; | |
530 } | |
531 | |
532 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() { | |
533 return static_cast<ScrollbarLayerImpl*>(LayerById( | |
534 pinch_zoom_scrollbar_vertical_layer_id_)); | |
535 } | |
536 | |
537 void LayerTreeImpl::UpdatePinchZoomScrollbars() { | |
538 LayerImpl* root_scroll_layer = RootScrollLayer(); | |
539 if (!root_scroll_layer) | |
540 return; | |
541 | |
542 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) { | |
543 scrollbar->setCurrentPos(root_scroll_layer->scrollOffset().x()); | |
544 scrollbar->setTotalSize(root_scroll_layer->bounds().width()); | |
545 scrollbar->setMaximum(root_scroll_layer->maxScrollOffset().x()); | |
546 } | |
547 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) { | |
548 scrollbar->setCurrentPos(root_scroll_layer->scrollOffset().y()); | |
549 scrollbar->setTotalSize(root_scroll_layer->bounds().height()); | |
550 scrollbar->setMaximum(root_scroll_layer->maxScrollOffset().y()); | |
551 } | |
552 } | |
553 | |
554 static scoped_ptr<Animation> MakePinchZoomFadeAnimation( | |
555 float start_opacity, float end_opacity) { | |
556 scoped_ptr<KeyframedFloatAnimationCurve> curve = | |
557 KeyframedFloatAnimationCurve::create(); | |
558 curve->addKeyframe(FloatKeyframe::create( | |
559 0, start_opacity, EaseInTimingFunction::create())); | |
560 curve->addKeyframe(FloatKeyframe::create( | |
561 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity, | |
562 EaseInTimingFunction::create())); | |
563 | |
564 scoped_ptr<Animation> animation = Animation::create( | |
565 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(), | |
566 0, Animation::Opacity); | |
567 animation->setIsImplOnly(true); | |
568 | |
569 return animation.Pass(); | |
570 } | |
571 | |
572 static void StartFadeInAnimation(LayerImpl* layer) { | |
573 // The start opacity value must be > 0 in order that the scrollbars get | |
574 // painted at the start of the animation, otherwise they never display. | |
575 float start_opacity = fmax(0.01, layer->opacity()); | |
enne (OOO)
2013/03/11 21:08:24
Can you help me understand how an impl-side animat
wjmaclean
2013/03/12 16:13:07
The very first time the scrollbars need to be show
| |
576 LayerAnimationController* controller = layer->layerAnimationController(); | |
577 // TODO() It shouldn't be necessary to manually remove the old animation. | |
578 if (Animation* animation = controller->getAnimation(Animation::Opacity)) | |
579 controller->removeAnimation(animation->id()); | |
580 controller->addAnimation(MakePinchZoomFadeAnimation(start_opacity, | |
581 PinchZoomScrollbar::kDefaultOpacity)); | |
582 } | |
583 | |
584 void LayerTreeImpl::FadeInPinchZoomScrollbars() { | |
585 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1) | |
586 return; | |
587 | |
588 StartFadeInAnimation(PinchZoomScrollbarHorizontal()); | |
589 StartFadeInAnimation(PinchZoomScrollbarVertical()); | |
590 } | |
591 | |
592 static void StartFadeOutAnimation(LayerImpl* layer) { | |
593 float opacity = layer->opacity(); | |
594 if (!opacity) | |
595 return; | |
596 | |
597 LayerAnimationController* controller = layer->layerAnimationController(); | |
598 // TODO() It shouldn't be necessary to manually remove the old animation. | |
enne (OOO)
2013/03/11 21:08:24
TODO(wjmaclean)
wjmaclean
2013/03/12 16:13:07
Done.
| |
599 if (Animation* animation = controller->getAnimation(Animation::Opacity)) | |
600 controller->removeAnimation(animation->id()); | |
601 controller->addAnimation(MakePinchZoomFadeAnimation(opacity, 0)); | |
602 } | |
603 | |
604 void LayerTreeImpl::FadeOutPinchZoomScrollbars() { | |
605 if (!HasPinchZoomScrollbars()) | |
606 return; | |
607 | |
608 StartFadeOutAnimation(PinchZoomScrollbarHorizontal()); | |
609 StartFadeOutAnimation(PinchZoomScrollbarVertical()); | |
610 } | |
611 | |
612 bool LayerTreeImpl::HasPinchZoomScrollbars() const { | |
613 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::s_invalidLayerId && | |
614 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::s_invalidLayerId; | |
615 } | |
616 | |
617 | |
489 } // namespace cc | 618 } // namespace cc |
OLD | NEW |