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::INVALID_ID), | |
30 pinch_zoom_scrollbar_vertical_layer_id_(Layer::INVALID_ID), | |
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( | |
129 pinch_zoom_scrollbar_horizontal_layer_id_); | |
130 target_tree->SetPinchZoomVerticalLayerId( | |
131 pinch_zoom_scrollbar_vertical_layer_id_); | |
119 } | 132 } |
120 | 133 |
121 LayerImpl* LayerTreeImpl::RootScrollLayer() { | 134 LayerImpl* LayerTreeImpl::RootScrollLayer() { |
122 DCHECK(IsActiveTree()); | 135 DCHECK(IsActiveTree()); |
123 return root_scroll_layer_; | 136 return root_scroll_layer_; |
124 } | 137 } |
125 | 138 |
126 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { | 139 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() { |
127 DCHECK(IsActiveTree()); | 140 DCHECK(IsActiveTree()); |
128 return currently_scrolling_layer_; | 141 return currently_scrolling_layer_; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 layer->DidBecomeActive(); | 340 layer->DidBecomeActive(); |
328 for (size_t i = 0; i < layer->children().size(); ++i) | 341 for (size_t i = 0; i < layer->children().size(); ++i) |
329 DidBecomeActiveRecursive(layer->children()[i]); | 342 DidBecomeActiveRecursive(layer->children()[i]); |
330 } | 343 } |
331 | 344 |
332 void LayerTreeImpl::DidBecomeActive() { | 345 void LayerTreeImpl::DidBecomeActive() { |
333 if (RootLayer()) | 346 if (RootLayer()) |
334 DidBecomeActiveRecursive(RootLayer()); | 347 DidBecomeActiveRecursive(RootLayer()); |
335 FindRootScrollLayer(); | 348 FindRootScrollLayer(); |
336 UpdateMaxScrollOffset(); | 349 UpdateMaxScrollOffset(); |
350 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after | |
351 // each commit (and after the root scroll layer has its max scroll offset | |
352 // set), we need to update pinch zoom scrollbars. | |
353 UpdatePinchZoomScrollbars(); | |
337 } | 354 } |
338 | 355 |
339 bool LayerTreeImpl::ContentsTexturesPurged() const { | 356 bool LayerTreeImpl::ContentsTexturesPurged() const { |
340 return contents_textures_purged_; | 357 return contents_textures_purged_; |
341 } | 358 } |
342 | 359 |
343 void LayerTreeImpl::SetContentsTexturesPurged() { | 360 void LayerTreeImpl::SetContentsTexturesPurged() { |
344 contents_textures_purged_ = true; | 361 contents_textures_purged_ = true; |
345 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); | 362 layer_tree_host_impl_->OnCanDrawStateChangedForTree(this); |
346 } | 363 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); | 496 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_); |
480 for (LayerIteratorType it = LayerIteratorType::begin( | 497 for (LayerIteratorType it = LayerIteratorType::begin( |
481 &render_surface_layer_list_); it != end; ++it) { | 498 &render_surface_layer_list_); it != end; ++it) { |
482 if (!it.representsItself()) | 499 if (!it.representsItself()) |
483 continue; | 500 continue; |
484 state->Append((*it)->AsValue().release()); | 501 state->Append((*it)->AsValue().release()); |
485 } | 502 } |
486 return state.PassAs<base::Value>(); | 503 return state.PassAs<base::Value>(); |
487 } | 504 } |
488 | 505 |
506 void LayerTreeImpl::DidBeginScroll() { | |
507 if (HasPinchZoomScrollbars()) | |
508 FadeInPinchZoomScrollbars(); | |
509 } | |
510 | |
511 void LayerTreeImpl::DidUpdateScroll() { | |
512 if (HasPinchZoomScrollbars()) | |
513 UpdatePinchZoomScrollbars(); | |
514 } | |
515 | |
516 void LayerTreeImpl::DidEndScroll() { | |
517 if (HasPinchZoomScrollbars()) | |
518 FadeOutPinchZoomScrollbars(); | |
519 } | |
520 | |
521 void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) { | |
522 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id; | |
523 } | |
524 | |
525 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() { | |
526 return static_cast<ScrollbarLayerImpl*>(LayerById( | |
527 pinch_zoom_scrollbar_horizontal_layer_id_)); | |
528 } | |
529 | |
530 void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) { | |
531 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id; | |
532 } | |
533 | |
534 ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() { | |
535 return static_cast<ScrollbarLayerImpl*>(LayerById( | |
536 pinch_zoom_scrollbar_vertical_layer_id_)); | |
537 } | |
538 | |
539 void LayerTreeImpl::UpdatePinchZoomScrollbars() { | |
540 LayerImpl* root_scroll_layer = RootScrollLayer(); | |
541 if (!root_scroll_layer) | |
542 return; | |
543 | |
544 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) { | |
545 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x()); | |
546 scrollbar->SetTotalSize(root_scroll_layer->bounds().width()); | |
547 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x()); | |
548 } | |
549 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) { | |
550 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y()); | |
551 scrollbar->SetTotalSize(root_scroll_layer->bounds().height()); | |
552 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y()); | |
553 } | |
554 } | |
555 | |
556 static scoped_ptr<Animation> MakePinchZoomFadeAnimation( | |
557 float start_opacity, float end_opacity) { | |
558 scoped_ptr<KeyframedFloatAnimationCurve> curve = | |
559 KeyframedFloatAnimationCurve::Create(); | |
560 curve->AddKeyframe(FloatKeyframe::Create( | |
561 0, start_opacity, EaseInTimingFunction::create())); | |
562 curve->AddKeyframe(FloatKeyframe::Create( | |
563 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity, | |
564 EaseInTimingFunction::create())); | |
565 | |
566 scoped_ptr<Animation> animation = Animation::Create( | |
567 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(), | |
568 0, Animation::Opacity); | |
569 animation->set_is_impl_only(true); | |
570 | |
571 return animation.Pass(); | |
572 } | |
573 | |
574 static bool StartFadeInAnimation(ScrollbarLayerImpl* layer) { | |
575 // The start opacity value must be > 0 in order that the scrollbars get | |
576 // painted at the start of the animation, otherwise they never display. | |
577 float start_opacity = 0; // fmax(0.01, layer->opacity()); | |
578 ScrollbarLayerImpl* scrollbar = layer->ToScrollbarLayer(); | |
579 DCHECK(scrollbar); | |
580 LayerAnimationController* controller = layer->layer_animation_controller(); | |
581 // TODO() It shouldn't be necessary to manually remove the old animation. | |
enne (OOO)
2013/03/12 16:27:37
TODO(wjmaclean)
wjmaclean
2013/03/12 18:25:33
Done.
(I'm officially going insane ... I clearly
| |
582 if (Animation* animation = controller->GetAnimation(Animation::Opacity)) | |
583 controller->RemoveAnimation(animation->id()); | |
584 controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity, | |
585 PinchZoomScrollbar::kDefaultOpacity)); | |
586 | |
587 return layer->HasThumbTexture(); | |
enne (OOO)
2013/03/12 16:27:37
I still think this is the wrong way to go about th
wjmaclean
2013/03/12 18:25:33
OK, I've devised a way for the PZ scrollbars to al
| |
588 } | |
589 | |
590 void LayerTreeImpl::FadeInPinchZoomScrollbars() { | |
591 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1) | |
592 return; | |
593 | |
594 bool scrollbars_need_redraw = false; | |
595 if (!StartFadeInAnimation(PinchZoomScrollbarHorizontal())) | |
596 scrollbars_need_redraw = true; | |
597 if (!StartFadeInAnimation(PinchZoomScrollbarVertical())) | |
598 scrollbars_need_redraw = true; | |
599 | |
600 if (scrollbars_need_redraw) | |
601 SetNeedsRedraw(); | |
602 } | |
603 | |
604 static void StartFadeOutAnimation(LayerImpl* layer) { | |
605 float opacity = layer->opacity(); | |
606 if (!opacity) | |
607 return; | |
608 | |
609 LayerAnimationController* controller = layer->layer_animation_controller(); | |
610 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old | |
611 // animation. | |
612 if (Animation* animation = controller->GetAnimation(Animation::Opacity)) | |
613 controller->RemoveAnimation(animation->id()); | |
614 controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0)); | |
615 } | |
616 | |
617 void LayerTreeImpl::FadeOutPinchZoomScrollbars() { | |
618 if (!HasPinchZoomScrollbars()) | |
619 return; | |
620 | |
621 StartFadeOutAnimation(PinchZoomScrollbarHorizontal()); | |
622 StartFadeOutAnimation(PinchZoomScrollbarVertical()); | |
623 } | |
624 | |
625 bool LayerTreeImpl::HasPinchZoomScrollbars() const { | |
626 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID && | |
627 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID; | |
628 } | |
629 | |
630 | |
489 } // namespace cc | 631 } // namespace cc |
OLD | NEW |