OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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.h" | 5 #include "cc/layer.h" |
6 | 6 |
7 #include "cc/active_animation.h" | 7 #include "cc/active_animation.h" |
8 #include "cc/animation_events.h" | 8 #include "cc/animation_events.h" |
9 #include "cc/layer_animation_controller.h" | 9 #include "cc/layer_animation_controller.h" |
10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 { | 25 { |
26 return make_scoped_refptr(new Layer()); | 26 return make_scoped_refptr(new Layer()); |
27 } | 27 } |
28 | 28 |
29 Layer::Layer() | 29 Layer::Layer() |
30 : m_needsDisplay(false) | 30 : m_needsDisplay(false) |
31 , m_stackingOrderChanged(false) | 31 , m_stackingOrderChanged(false) |
32 , m_layerId(s_nextLayerId++) | 32 , m_layerId(s_nextLayerId++) |
33 , m_parent(0) | 33 , m_parent(0) |
34 , m_layerTreeHost(0) | 34 , m_layerTreeHost(0) |
35 , m_layerAnimationController(LayerAnimationController::create(this)) | |
36 , m_scrollable(false) | 35 , m_scrollable(false) |
37 , m_shouldScrollOnMainThread(false) | 36 , m_shouldScrollOnMainThread(false) |
38 , m_haveWheelEventHandlers(false) | 37 , m_haveWheelEventHandlers(false) |
39 , m_nonFastScrollableRegionChanged(false) | 38 , m_nonFastScrollableRegionChanged(false) |
40 , m_touchEventHandlerRegionChanged(false) | 39 , m_touchEventHandlerRegionChanged(false) |
41 , m_anchorPoint(0.5, 0.5) | 40 , m_anchorPoint(0.5, 0.5) |
42 , m_backgroundColor(0) | 41 , m_backgroundColor(0) |
43 , m_opacity(1.0) | 42 , m_opacity(1.0) |
44 , m_anchorPointZ(0) | 43 , m_anchorPointZ(0) |
45 , m_isContainerForFixedPositionLayers(false) | 44 , m_isContainerForFixedPositionLayers(false) |
(...skipping 10 matching lines...) Expand all Loading... |
56 , m_rasterScale(1.0) | 55 , m_rasterScale(1.0) |
57 , m_automaticallyComputeRasterScale(false) | 56 , m_automaticallyComputeRasterScale(false) |
58 , m_boundsContainPageScale(false) | 57 , m_boundsContainPageScale(false) |
59 , m_layerAnimationDelegate(0) | 58 , m_layerAnimationDelegate(0) |
60 , m_layerScrollClient(0) | 59 , m_layerScrollClient(0) |
61 { | 60 { |
62 if (m_layerId < 0) { | 61 if (m_layerId < 0) { |
63 s_nextLayerId = 1; | 62 s_nextLayerId = 1; |
64 m_layerId = s_nextLayerId++; | 63 m_layerId = s_nextLayerId++; |
65 } | 64 } |
| 65 m_layerAnimationController = LayerAnimationController::create(m_layerId); |
| 66 m_layerAnimationController->addObserver(this); |
66 } | 67 } |
67 | 68 |
68 Layer::~Layer() | 69 Layer::~Layer() |
69 { | 70 { |
70 // Our parent should be holding a reference to us so there should be no | 71 // Our parent should be holding a reference to us so there should be no |
71 // way for us to be destroyed while we still have a parent. | 72 // way for us to be destroyed while we still have a parent. |
72 DCHECK(!parent()); | 73 DCHECK(!parent()); |
73 | 74 |
| 75 m_layerAnimationController->removeObserver(this); |
| 76 |
74 // Remove the parent reference from all children. | 77 // Remove the parent reference from all children. |
75 removeAllChildren(); | 78 removeAllChildren(); |
76 } | 79 } |
77 | 80 |
78 void Layer::setLayerTreeHost(LayerTreeHost* host) | 81 void Layer::setLayerTreeHost(LayerTreeHost* host) |
79 { | 82 { |
80 if (m_layerTreeHost == host) | 83 if (m_layerTreeHost == host) |
81 return; | 84 return; |
82 | 85 |
83 m_layerTreeHost = host; | 86 m_layerTreeHost = host; |
84 | 87 |
85 for (size_t i = 0; i < m_children.size(); ++i) | 88 for (size_t i = 0; i < m_children.size(); ++i) |
86 m_children[i]->setLayerTreeHost(host); | 89 m_children[i]->setLayerTreeHost(host); |
87 | 90 |
88 if (m_maskLayer) | 91 if (m_maskLayer) |
89 m_maskLayer->setLayerTreeHost(host); | 92 m_maskLayer->setLayerTreeHost(host); |
90 if (m_replicaLayer) | 93 if (m_replicaLayer) |
91 m_replicaLayer->setLayerTreeHost(host); | 94 m_replicaLayer->setLayerTreeHost(host); |
92 | 95 |
93 // If this layer already has active animations, the host needs to be notifie
d. | 96 m_layerAnimationController->setAnimationRegistrar(host); |
94 if (host && m_layerAnimationController->hasActiveAnimation()) | |
95 host->didAddAnimation(); | |
96 } | 97 } |
97 | 98 |
98 void Layer::setNeedsCommit() | 99 void Layer::setNeedsCommit() |
99 { | 100 { |
100 if (m_layerTreeHost) | 101 if (m_layerTreeHost) |
101 m_layerTreeHost->setNeedsCommit(); | 102 m_layerTreeHost->setNeedsCommit(); |
102 } | 103 } |
103 | 104 |
104 void Layer::setNeedsFullTreeSync() | 105 void Layer::setNeedsFullTreeSync() |
105 { | 106 { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 } | 365 } |
365 | 366 |
366 void Layer::setOpacity(float opacity) | 367 void Layer::setOpacity(float opacity) |
367 { | 368 { |
368 if (m_opacity == opacity) | 369 if (m_opacity == opacity) |
369 return; | 370 return; |
370 m_opacity = opacity; | 371 m_opacity = opacity; |
371 setNeedsCommit(); | 372 setNeedsCommit(); |
372 } | 373 } |
373 | 374 |
| 375 float Layer::opacity() const |
| 376 { |
| 377 return m_opacity; |
| 378 } |
| 379 |
374 bool Layer::opacityIsAnimating() const | 380 bool Layer::opacityIsAnimating() const |
375 { | 381 { |
376 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac
ity); | 382 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac
ity); |
377 } | 383 } |
378 | 384 |
379 void Layer::setContentsOpaque(bool opaque) | 385 void Layer::setContentsOpaque(bool opaque) |
380 { | 386 { |
381 if (m_contentsOpaque == opaque) | 387 if (m_contentsOpaque == opaque) |
382 return; | 388 return; |
383 m_contentsOpaque = opaque; | 389 m_contentsOpaque = opaque; |
(...skipping 17 matching lines...) Expand all Loading... |
401 } | 407 } |
402 | 408 |
403 void Layer::setTransform(const gfx::Transform& transform) | 409 void Layer::setTransform(const gfx::Transform& transform) |
404 { | 410 { |
405 if (m_transform == transform) | 411 if (m_transform == transform) |
406 return; | 412 return; |
407 m_transform = transform; | 413 m_transform = transform; |
408 setNeedsCommit(); | 414 setNeedsCommit(); |
409 } | 415 } |
410 | 416 |
| 417 const gfx::Transform& Layer::transform() const |
| 418 { |
| 419 return m_transform; |
| 420 } |
| 421 |
411 bool Layer::transformIsAnimating() const | 422 bool Layer::transformIsAnimating() const |
412 { | 423 { |
413 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran
sform); | 424 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran
sform); |
414 } | 425 } |
415 | 426 |
416 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) | 427 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) |
417 { | 428 { |
418 if (m_scrollOffset == scrollOffset) | 429 if (m_scrollOffset == scrollOffset) |
419 return; | 430 return; |
420 m_scrollOffset = scrollOffset; | 431 m_scrollOffset = scrollOffset; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 DCHECK(!m_drawProperties.render_surface); | 705 DCHECK(!m_drawProperties.render_surface); |
695 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurface(this)); | 706 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurface(this)); |
696 m_drawProperties.render_target = this; | 707 m_drawProperties.render_target = this; |
697 } | 708 } |
698 | 709 |
699 int Layer::id() const | 710 int Layer::id() const |
700 { | 711 { |
701 return m_layerId; | 712 return m_layerId; |
702 } | 713 } |
703 | 714 |
704 float Layer::opacity() const | 715 void Layer::OnOpacityAnimated(float opacity) |
705 { | |
706 return m_opacity; | |
707 } | |
708 | |
709 void Layer::setOpacityFromAnimation(float opacity) | |
710 { | 716 { |
711 // This is called due to an ongoing accelerated animation. Since this animat
ion is | 717 // This is called due to an ongoing accelerated animation. Since this animat
ion is |
712 // also being run on the impl thread, there is no need to request a commit t
o push | 718 // also being run on the impl thread, there is no need to request a commit t
o push |
713 // this value over, so set the value directly rather than calling setOpacity
. | 719 // this value over, so set the value directly rather than calling setOpacity
. |
714 m_opacity = opacity; | 720 m_opacity = opacity; |
715 } | 721 } |
716 | 722 |
717 const gfx::Transform& Layer::transform() const | 723 void Layer::OnTransformAnimated(const gfx::Transform& transform) |
718 { | |
719 return m_transform; | |
720 } | |
721 | |
722 void Layer::setTransformFromAnimation(const gfx::Transform& transform) | |
723 { | 724 { |
724 // This is called due to an ongoing accelerated animation. Since this animat
ion is | 725 // This is called due to an ongoing accelerated animation. Since this animat
ion is |
725 // also being run on the impl thread, there is no need to request a commit t
o push | 726 // also being run on the impl thread, there is no need to request a commit t
o push |
726 // this value over, so set this value directly rather than calling setTransf
orm. | 727 // this value over, so set this value directly rather than calling setTransf
orm. |
727 m_transform = transform; | 728 m_transform = transform; |
728 } | 729 } |
729 | 730 |
730 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) | 731 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) |
731 { | 732 { |
732 // WebCore currently assumes that accelerated animations will start soon | 733 // WebCore currently assumes that accelerated animations will start soon |
733 // after the animation is added. However we cannot guarantee that if we do | 734 // after the animation is added. However we cannot guarantee that if we do |
734 // not have a layerTreeHost that will setNeedsCommit(). | 735 // not have a layerTreeHost that will setNeedsCommit(). |
735 // Unfortunately, the fix below to guarantee correctness causes performance | 736 // Unfortunately, the fix below to guarantee correctness causes performance |
736 // regressions on Android, since Android has shipped for a long time | 737 // regressions on Android, since Android has shipped for a long time |
737 // with all animations accelerated. For this reason, we will live with | 738 // with all animations accelerated. For this reason, we will live with |
738 // this bug only on Android until the bug is fixed. | 739 // this bug only on Android until the bug is fixed. |
739 // http://crbug.com/129683 | 740 // http://crbug.com/129683 |
740 #if !defined(OS_ANDROID) | 741 #if !defined(OS_ANDROID) |
741 if (!m_layerTreeHost) | 742 if (!m_layerTreeHost) |
742 return false; | 743 return false; |
743 | 744 |
744 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) | 745 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) |
745 return false; | 746 return false; |
746 #endif | 747 #endif |
747 | 748 |
748 m_layerAnimationController->addAnimation(animation.Pass()); | 749 m_layerAnimationController->addAnimation(animation.Pass()); |
749 if (m_layerTreeHost) { | 750 setNeedsCommit(); |
750 m_layerTreeHost->didAddAnimation(); | |
751 setNeedsCommit(); | |
752 } | |
753 return true; | 751 return true; |
754 } | 752 } |
755 | 753 |
756 void Layer::pauseAnimation(int animationId, double timeOffset) | 754 void Layer::pauseAnimation(int animationId, double timeOffset) |
757 { | 755 { |
758 m_layerAnimationController->pauseAnimation(animationId, timeOffset); | 756 m_layerAnimationController->pauseAnimation(animationId, timeOffset); |
759 setNeedsCommit(); | 757 setNeedsCommit(); |
760 } | 758 } |
761 | 759 |
762 void Layer::removeAnimation(int animationId) | 760 void Layer::removeAnimation(int animationId) |
763 { | 761 { |
764 m_layerAnimationController->removeAnimation(animationId); | 762 m_layerAnimationController->removeAnimation(animationId); |
765 setNeedsCommit(); | 763 setNeedsCommit(); |
766 } | 764 } |
767 | 765 |
768 void Layer::suspendAnimations(double monotonicTime) | 766 void Layer::suspendAnimations(double monotonicTime) |
769 { | 767 { |
770 m_layerAnimationController->suspendAnimations(monotonicTime); | 768 m_layerAnimationController->suspendAnimations(monotonicTime); |
771 setNeedsCommit(); | 769 setNeedsCommit(); |
772 } | 770 } |
773 | 771 |
774 void Layer::resumeAnimations(double monotonicTime) | 772 void Layer::resumeAnimations(double monotonicTime) |
775 { | 773 { |
776 m_layerAnimationController->resumeAnimations(monotonicTime); | 774 m_layerAnimationController->resumeAnimations(monotonicTime); |
777 setNeedsCommit(); | 775 setNeedsCommit(); |
778 } | 776 } |
779 | 777 |
780 void Layer::setLayerAnimationController(scoped_ptr<LayerAnimationController> lay
erAnimationController) | 778 void Layer::setLayerAnimationController(scoped_refptr<LayerAnimationController>
layerAnimationController) |
781 { | 779 { |
782 m_layerAnimationController = layerAnimationController.Pass(); | 780 m_layerAnimationController->removeObserver(this); |
783 if (m_layerAnimationController) { | 781 m_layerAnimationController = layerAnimationController; |
784 m_layerAnimationController->setClient(this); | 782 m_layerAnimationController->setForceSync(); |
785 m_layerAnimationController->setForceSync(); | 783 m_layerAnimationController->addObserver(this); |
786 } | |
787 setNeedsCommit(); | 784 setNeedsCommit(); |
788 } | 785 } |
789 | 786 |
790 scoped_ptr<LayerAnimationController> Layer::releaseLayerAnimationController() | 787 scoped_refptr<LayerAnimationController> Layer::releaseLayerAnimationController() |
791 { | 788 { |
792 scoped_ptr<LayerAnimationController> toReturn = m_layerAnimationController.P
ass(); | 789 m_layerAnimationController->removeObserver(this); |
793 m_layerAnimationController = LayerAnimationController::create(this); | 790 scoped_refptr<LayerAnimationController> toReturn = m_layerAnimationControlle
r; |
794 return toReturn.Pass(); | 791 m_layerAnimationController = LayerAnimationController::create(id()); |
| 792 m_layerAnimationController->addObserver(this); |
| 793 return toReturn; |
795 } | 794 } |
796 | 795 |
797 bool Layer::hasActiveAnimation() const | 796 bool Layer::hasActiveAnimation() const |
798 { | 797 { |
799 return m_layerAnimationController->hasActiveAnimation(); | 798 return m_layerAnimationController->hasActiveAnimation(); |
800 } | 799 } |
801 | 800 |
802 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock
Time) | 801 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock
Time) |
803 { | 802 { |
804 m_layerAnimationController->notifyAnimationStarted(event); | 803 m_layerAnimationController->notifyAnimationStarted(event); |
(...skipping 18 matching lines...) Expand all Loading... |
823 { | 822 { |
824 return 0; | 823 return 0; |
825 } | 824 } |
826 | 825 |
827 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*) | 826 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*) |
828 { | 827 { |
829 // Currently we don't use z-order to decide what to paint, so there's no nee
d to actually sort Layers. | 828 // Currently we don't use z-order to decide what to paint, so there's no nee
d to actually sort Layers. |
830 } | 829 } |
831 | 830 |
832 } // namespace cc | 831 } // namespace cc |
OLD | NEW |