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 11 matching lines...) Expand all Loading... |
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 } |
66 | 65 |
67 addLayerAnimationObserver(m_layerAnimationController.get()); | 66 m_layerAnimationController = LayerAnimationController::create(m_layerId); |
| 67 m_layerAnimationController->addObserver(this); |
| 68 addLayerAnimationEventObserver(m_layerAnimationController.get()); |
68 } | 69 } |
69 | 70 |
70 Layer::~Layer() | 71 Layer::~Layer() |
71 { | 72 { |
72 // Our parent should be holding a reference to us so there should be no | 73 // Our parent should be holding a reference to us so there should be no |
73 // way for us to be destroyed while we still have a parent. | 74 // way for us to be destroyed while we still have a parent. |
74 DCHECK(!parent()); | 75 DCHECK(!parent()); |
75 | 76 |
| 77 m_layerAnimationController->removeObserver(this); |
| 78 |
76 // Remove the parent reference from all children. | 79 // Remove the parent reference from all children. |
77 removeAllChildren(); | 80 removeAllChildren(); |
78 } | 81 } |
79 | 82 |
80 void Layer::setLayerTreeHost(LayerTreeHost* host) | 83 void Layer::setLayerTreeHost(LayerTreeHost* host) |
81 { | 84 { |
82 if (m_layerTreeHost == host) | 85 if (m_layerTreeHost == host) |
83 return; | 86 return; |
84 | 87 |
85 m_layerTreeHost = host; | 88 m_layerTreeHost = host; |
86 | 89 |
87 for (size_t i = 0; i < m_children.size(); ++i) | 90 for (size_t i = 0; i < m_children.size(); ++i) |
88 m_children[i]->setLayerTreeHost(host); | 91 m_children[i]->setLayerTreeHost(host); |
89 | 92 |
90 if (m_maskLayer) | 93 if (m_maskLayer) |
91 m_maskLayer->setLayerTreeHost(host); | 94 m_maskLayer->setLayerTreeHost(host); |
92 if (m_replicaLayer) | 95 if (m_replicaLayer) |
93 m_replicaLayer->setLayerTreeHost(host); | 96 m_replicaLayer->setLayerTreeHost(host); |
94 | 97 |
95 // If this layer already has active animations, the host needs to be notifie
d. | 98 m_layerAnimationController->setAnimationRegistrar(host ? host->animationRegi
strar() : 0); |
96 if (host && m_layerAnimationController->hasActiveAnimation()) | 99 |
97 host->didAddAnimation(); | 100 if (host && m_layerAnimationController->hasAnyAnimation()) |
| 101 host->setNeedsCommit(); |
98 } | 102 } |
99 | 103 |
100 void Layer::setNeedsCommit() | 104 void Layer::setNeedsCommit() |
101 { | 105 { |
102 if (m_layerTreeHost) | 106 if (m_layerTreeHost) |
103 m_layerTreeHost->setNeedsCommit(); | 107 m_layerTreeHost->setNeedsCommit(); |
104 } | 108 } |
105 | 109 |
106 void Layer::setNeedsFullTreeSync() | 110 void Layer::setNeedsFullTreeSync() |
107 { | 111 { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 370 } |
367 | 371 |
368 void Layer::setOpacity(float opacity) | 372 void Layer::setOpacity(float opacity) |
369 { | 373 { |
370 if (m_opacity == opacity) | 374 if (m_opacity == opacity) |
371 return; | 375 return; |
372 m_opacity = opacity; | 376 m_opacity = opacity; |
373 setNeedsCommit(); | 377 setNeedsCommit(); |
374 } | 378 } |
375 | 379 |
| 380 float Layer::opacity() const |
| 381 { |
| 382 return m_opacity; |
| 383 } |
| 384 |
376 bool Layer::opacityIsAnimating() const | 385 bool Layer::opacityIsAnimating() const |
377 { | 386 { |
378 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac
ity); | 387 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac
ity); |
379 } | 388 } |
380 | 389 |
381 void Layer::setContentsOpaque(bool opaque) | 390 void Layer::setContentsOpaque(bool opaque) |
382 { | 391 { |
383 if (m_contentsOpaque == opaque) | 392 if (m_contentsOpaque == opaque) |
384 return; | 393 return; |
385 m_contentsOpaque = opaque; | 394 m_contentsOpaque = opaque; |
(...skipping 17 matching lines...) Expand all Loading... |
403 } | 412 } |
404 | 413 |
405 void Layer::setTransform(const gfx::Transform& transform) | 414 void Layer::setTransform(const gfx::Transform& transform) |
406 { | 415 { |
407 if (m_transform == transform) | 416 if (m_transform == transform) |
408 return; | 417 return; |
409 m_transform = transform; | 418 m_transform = transform; |
410 setNeedsCommit(); | 419 setNeedsCommit(); |
411 } | 420 } |
412 | 421 |
| 422 const gfx::Transform& Layer::transform() const |
| 423 { |
| 424 return m_transform; |
| 425 } |
| 426 |
413 bool Layer::transformIsAnimating() const | 427 bool Layer::transformIsAnimating() const |
414 { | 428 { |
415 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran
sform); | 429 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran
sform); |
416 } | 430 } |
417 | 431 |
418 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) | 432 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) |
419 { | 433 { |
420 if (m_scrollOffset == scrollOffset) | 434 if (m_scrollOffset == scrollOffset) |
421 return; | 435 return; |
422 m_scrollOffset = scrollOffset; | 436 m_scrollOffset = scrollOffset; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 DCHECK(!m_drawProperties.render_surface); | 710 DCHECK(!m_drawProperties.render_surface); |
697 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurface(this)); | 711 m_drawProperties.render_surface = make_scoped_ptr(new RenderSurface(this)); |
698 m_drawProperties.render_target = this; | 712 m_drawProperties.render_target = this; |
699 } | 713 } |
700 | 714 |
701 int Layer::id() const | 715 int Layer::id() const |
702 { | 716 { |
703 return m_layerId; | 717 return m_layerId; |
704 } | 718 } |
705 | 719 |
706 float Layer::opacity() const | 720 void Layer::OnOpacityAnimated(float opacity) |
707 { | |
708 return m_opacity; | |
709 } | |
710 | |
711 void Layer::setOpacityFromAnimation(float opacity) | |
712 { | 721 { |
713 // This is called due to an ongoing accelerated animation. Since this animat
ion is | 722 // This is called due to an ongoing accelerated animation. Since this animat
ion is |
714 // also being run on the impl thread, there is no need to request a commit t
o push | 723 // also being run on the impl thread, there is no need to request a commit t
o push |
715 // this value over, so set the value directly rather than calling setOpacity
. | 724 // this value over, so set the value directly rather than calling setOpacity
. |
716 m_opacity = opacity; | 725 m_opacity = opacity; |
717 } | 726 } |
718 | 727 |
719 const gfx::Transform& Layer::transform() const | 728 void Layer::OnTransformAnimated(const gfx::Transform& transform) |
720 { | |
721 return m_transform; | |
722 } | |
723 | |
724 void Layer::setTransformFromAnimation(const gfx::Transform& transform) | |
725 { | 729 { |
726 // This is called due to an ongoing accelerated animation. Since this animat
ion is | 730 // This is called due to an ongoing accelerated animation. Since this animat
ion is |
727 // also being run on the impl thread, there is no need to request a commit t
o push | 731 // also being run on the impl thread, there is no need to request a commit t
o push |
728 // this value over, so set this value directly rather than calling setTransf
orm. | 732 // this value over, so set this value directly rather than calling setTransf
orm. |
729 m_transform = transform; | 733 m_transform = transform; |
730 } | 734 } |
731 | 735 |
732 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) | 736 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) |
733 { | 737 { |
734 // WebCore currently assumes that accelerated animations will start soon | 738 // WebCore currently assumes that accelerated animations will start soon |
735 // after the animation is added. However we cannot guarantee that if we do | 739 // after the animation is added. However we cannot guarantee that if we do |
736 // not have a layerTreeHost that will setNeedsCommit(). | 740 // not have a layerTreeHost that will setNeedsCommit(). |
737 // Unfortunately, the fix below to guarantee correctness causes performance | 741 // Unfortunately, the fix below to guarantee correctness causes performance |
738 // regressions on Android, since Android has shipped for a long time | 742 // regressions on Android, since Android has shipped for a long time |
739 // with all animations accelerated. For this reason, we will live with | 743 // with all animations accelerated. For this reason, we will live with |
740 // this bug only on Android until the bug is fixed. | 744 // this bug only on Android until the bug is fixed. |
741 // http://crbug.com/129683 | 745 // http://crbug.com/129683 |
742 #if !defined(OS_ANDROID) | 746 #if !defined(OS_ANDROID) |
743 if (!m_layerTreeHost) | 747 if (!m_layerTreeHost) |
744 return false; | 748 return false; |
745 | 749 |
746 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) | 750 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) |
747 return false; | 751 return false; |
748 #endif | 752 #endif |
749 | 753 |
750 m_layerAnimationController->addAnimation(animation.Pass()); | 754 m_layerAnimationController->addAnimation(animation.Pass()); |
751 if (m_layerTreeHost) { | 755 setNeedsCommit(); |
752 m_layerTreeHost->didAddAnimation(); | |
753 setNeedsCommit(); | |
754 } | |
755 return true; | 756 return true; |
756 } | 757 } |
757 | 758 |
758 void Layer::pauseAnimation(int animationId, double timeOffset) | 759 void Layer::pauseAnimation(int animationId, double timeOffset) |
759 { | 760 { |
760 m_layerAnimationController->pauseAnimation(animationId, timeOffset); | 761 m_layerAnimationController->pauseAnimation(animationId, timeOffset); |
761 setNeedsCommit(); | 762 setNeedsCommit(); |
762 } | 763 } |
763 | 764 |
764 void Layer::removeAnimation(int animationId) | 765 void Layer::removeAnimation(int animationId) |
765 { | 766 { |
766 m_layerAnimationController->removeAnimation(animationId); | 767 m_layerAnimationController->removeAnimation(animationId); |
767 setNeedsCommit(); | 768 setNeedsCommit(); |
768 } | 769 } |
769 | 770 |
770 void Layer::suspendAnimations(double monotonicTime) | 771 void Layer::suspendAnimations(double monotonicTime) |
771 { | 772 { |
772 m_layerAnimationController->suspendAnimations(monotonicTime); | 773 m_layerAnimationController->suspendAnimations(monotonicTime); |
773 setNeedsCommit(); | 774 setNeedsCommit(); |
774 } | 775 } |
775 | 776 |
776 void Layer::resumeAnimations(double monotonicTime) | 777 void Layer::resumeAnimations(double monotonicTime) |
777 { | 778 { |
778 m_layerAnimationController->resumeAnimations(monotonicTime); | 779 m_layerAnimationController->resumeAnimations(monotonicTime); |
779 setNeedsCommit(); | 780 setNeedsCommit(); |
780 } | 781 } |
781 | 782 |
782 void Layer::setLayerAnimationController(scoped_ptr<LayerAnimationController> lay
erAnimationController) | 783 void Layer::setLayerAnimationController(scoped_refptr<LayerAnimationController>
layerAnimationController) |
783 { | 784 { |
784 if (m_layerAnimationController) | 785 removeLayerAnimationEventObserver(m_layerAnimationController.get()); |
785 removeLayerAnimationObserver(m_layerAnimationController.get()); | 786 m_layerAnimationController->removeObserver(this); |
786 | 787 m_layerAnimationController = layerAnimationController; |
787 m_layerAnimationController = layerAnimationController.Pass(); | 788 m_layerAnimationController->setForceSync(); |
788 if (m_layerAnimationController) { | 789 m_layerAnimationController->addObserver(this); |
789 m_layerAnimationController->setClient(this); | 790 addLayerAnimationEventObserver(m_layerAnimationController.get()); |
790 m_layerAnimationController->setForceSync(); | |
791 addLayerAnimationObserver(m_layerAnimationController.get()); | |
792 } | |
793 setNeedsCommit(); | 791 setNeedsCommit(); |
794 } | 792 } |
795 | 793 |
796 scoped_ptr<LayerAnimationController> Layer::releaseLayerAnimationController() | 794 scoped_refptr<LayerAnimationController> Layer::releaseLayerAnimationController() |
797 { | 795 { |
798 scoped_ptr<LayerAnimationController> toReturn = m_layerAnimationController.P
ass(); | 796 m_layerAnimationController->removeObserver(this); |
799 m_layerAnimationController = LayerAnimationController::create(this); | 797 scoped_refptr<LayerAnimationController> toReturn = m_layerAnimationControlle
r; |
800 return toReturn.Pass(); | 798 m_layerAnimationController = LayerAnimationController::create(id()); |
| 799 m_layerAnimationController->addObserver(this); |
| 800 return toReturn; |
801 } | 801 } |
802 | 802 |
803 bool Layer::hasActiveAnimation() const | 803 bool Layer::hasActiveAnimation() const |
804 { | 804 { |
805 return m_layerAnimationController->hasActiveAnimation(); | 805 return m_layerAnimationController->hasActiveAnimation(); |
806 } | 806 } |
807 | 807 |
808 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock
Time) | 808 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock
Time) |
809 { | 809 { |
810 FOR_EACH_OBSERVER(LayerAnimationObserver, m_layerAnimationObservers, | 810 FOR_EACH_OBSERVER(LayerAnimationEventObserver, m_layerAnimationObservers, |
811 OnAnimationStarted(event)); | 811 OnAnimationStarted(event)); |
812 if (m_layerAnimationDelegate) | 812 if (m_layerAnimationDelegate) |
813 m_layerAnimationDelegate->notifyAnimationStarted(wallClockTime); | 813 m_layerAnimationDelegate->notifyAnimationStarted(wallClockTime); |
814 } | 814 } |
815 | 815 |
816 void Layer::notifyAnimationFinished(double wallClockTime) | 816 void Layer::notifyAnimationFinished(double wallClockTime) |
817 { | 817 { |
818 if (m_layerAnimationDelegate) | 818 if (m_layerAnimationDelegate) |
819 m_layerAnimationDelegate->notifyAnimationFinished(wallClockTime); | 819 m_layerAnimationDelegate->notifyAnimationFinished(wallClockTime); |
820 } | 820 } |
821 | 821 |
822 void Layer::addLayerAnimationObserver(LayerAnimationObserver* animationObserver) | 822 void Layer::addLayerAnimationEventObserver(LayerAnimationEventObserver* animatio
nObserver) |
823 { | 823 { |
824 if (!m_layerAnimationObservers.HasObserver(animationObserver)) | 824 if (!m_layerAnimationObservers.HasObserver(animationObserver)) |
825 m_layerAnimationObservers.AddObserver(animationObserver); | 825 m_layerAnimationObservers.AddObserver(animationObserver); |
826 } | 826 } |
827 | 827 |
828 void Layer::removeLayerAnimationObserver(LayerAnimationObserver* animationObserv
er) | 828 void Layer::removeLayerAnimationEventObserver(LayerAnimationEventObserver* anima
tionObserver) |
829 { | 829 { |
830 m_layerAnimationObservers.RemoveObserver(animationObserver); | 830 m_layerAnimationObservers.RemoveObserver(animationObserver); |
831 } | 831 } |
832 | 832 |
833 Region Layer::visibleContentOpaqueRegion() const | 833 Region Layer::visibleContentOpaqueRegion() const |
834 { | 834 { |
835 if (contentsOpaque()) | 835 if (contentsOpaque()) |
836 return visibleContentRect(); | 836 return visibleContentRect(); |
837 return Region(); | 837 return Region(); |
838 } | 838 } |
839 | 839 |
840 ScrollbarLayer* Layer::toScrollbarLayer() | 840 ScrollbarLayer* Layer::toScrollbarLayer() |
841 { | 841 { |
842 return 0; | 842 return 0; |
843 } | 843 } |
844 | 844 |
845 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*) | 845 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*) |
846 { | 846 { |
847 // Currently we don't use z-order to decide what to paint, so there's no nee
d to actually sort Layers. | 847 // Currently we don't use z-order to decide what to paint, so there's no nee
d to actually sort Layers. |
848 } | 848 } |
849 | 849 |
850 } // namespace cc | 850 } // namespace cc |
OLD | NEW |