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)) | 35 , m_layerAnimationController(LayerAnimationController::create()) |
36 , m_scrollable(false) | 36 , m_scrollable(false) |
37 , m_shouldScrollOnMainThread(false) | 37 , m_shouldScrollOnMainThread(false) |
38 , m_haveWheelEventHandlers(false) | 38 , m_haveWheelEventHandlers(false) |
39 , m_nonFastScrollableRegionChanged(false) | 39 , m_nonFastScrollableRegionChanged(false) |
40 , m_touchEventHandlerRegionChanged(false) | 40 , m_touchEventHandlerRegionChanged(false) |
41 , m_anchorPoint(0.5, 0.5) | 41 , m_anchorPoint(0.5, 0.5) |
42 , m_backgroundColor(0) | 42 , m_backgroundColor(0) |
43 , m_opacity(1.0) | 43 , m_opacity(1.0) |
44 , m_filter(0) | 44 , m_filter(0) |
45 , m_anchorPointZ(0) | 45 , m_anchorPointZ(0) |
(...skipping 18 matching lines...) Expand all Loading... | |
64 , m_rasterScale(1.0) | 64 , m_rasterScale(1.0) |
65 , m_automaticallyComputeRasterScale(false) | 65 , m_automaticallyComputeRasterScale(false) |
66 , m_boundsContainPageScale(false) | 66 , m_boundsContainPageScale(false) |
67 , m_layerAnimationDelegate(0) | 67 , m_layerAnimationDelegate(0) |
68 , m_layerScrollClient(0) | 68 , m_layerScrollClient(0) |
69 { | 69 { |
70 if (m_layerId < 0) { | 70 if (m_layerId < 0) { |
71 s_nextLayerId = 1; | 71 s_nextLayerId = 1; |
72 m_layerId = s_nextLayerId++; | 72 m_layerId = s_nextLayerId++; |
73 } | 73 } |
74 m_layerAnimationController->setId(m_layerId); | |
74 } | 75 } |
75 | 76 |
76 Layer::~Layer() | 77 Layer::~Layer() |
77 { | 78 { |
78 // Our parent should be holding a reference to us so there should be no | 79 // Our parent should be holding a reference to us so there should be no |
79 // way for us to be destroyed while we still have a parent. | 80 // way for us to be destroyed while we still have a parent. |
80 DCHECK(!parent()); | 81 DCHECK(!parent()); |
81 | 82 |
82 // Remove the parent reference from all children. | 83 // Remove the parent reference from all children. |
83 removeAllChildren(); | 84 removeAllChildren(); |
(...skipping 14 matching lines...) Expand all Loading... | |
98 m_layerTreeHost = host; | 99 m_layerTreeHost = host; |
99 | 100 |
100 for (size_t i = 0; i < m_children.size(); ++i) | 101 for (size_t i = 0; i < m_children.size(); ++i) |
101 m_children[i]->setLayerTreeHost(host); | 102 m_children[i]->setLayerTreeHost(host); |
102 | 103 |
103 if (m_maskLayer) | 104 if (m_maskLayer) |
104 m_maskLayer->setLayerTreeHost(host); | 105 m_maskLayer->setLayerTreeHost(host); |
105 if (m_replicaLayer) | 106 if (m_replicaLayer) |
106 m_replicaLayer->setLayerTreeHost(host); | 107 m_replicaLayer->setLayerTreeHost(host); |
107 | 108 |
108 // If this layer already has active animations, the host needs to be notifie d. | 109 m_layerAnimationController->setAnimationRegistrar(host); |
109 if (host && m_layerAnimationController->hasActiveAnimation()) | |
110 host->didAddAnimation(); | |
111 } | 110 } |
112 | 111 |
113 void Layer::setNeedsCommit() | 112 void Layer::setNeedsCommit() |
114 { | 113 { |
115 if (m_layerTreeHost) | 114 if (m_layerTreeHost) |
116 m_layerTreeHost->setNeedsCommit(); | 115 m_layerTreeHost->setNeedsCommit(); |
117 } | 116 } |
118 | 117 |
119 gfx::Rect Layer::layerRectToContentRect(const gfx::RectF& layerRect) const | 118 gfx::Rect Layer::layerRectToContentRect(const gfx::RectF& layerRect) const |
120 { | 119 { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 bool Layer::needsDisplay() const | 351 bool Layer::needsDisplay() const |
353 { | 352 { |
354 return m_needsDisplay; | 353 return m_needsDisplay; |
355 } | 354 } |
356 | 355 |
357 void Layer::setOpacity(float opacity) | 356 void Layer::setOpacity(float opacity) |
358 { | 357 { |
359 if (m_opacity == opacity) | 358 if (m_opacity == opacity) |
360 return; | 359 return; |
361 m_opacity = opacity; | 360 m_opacity = opacity; |
361 m_opacityLastUpdateTime = base::TimeTicks::Now(); | |
362 setNeedsCommit(); | 362 setNeedsCommit(); |
363 } | 363 } |
364 | 364 |
365 float Layer::opacity() const | |
366 { | |
367 if (m_layerAnimationController->opacityLastUpdateTime() > m_opacityLastUpdat eTime) | |
jamesr
2012/12/03 04:40:15
could you explain what this logic is for? anything
Ian Vollick
2012/12/03 14:47:03
Sure. Animation controllers used to push new value
enne (OOO)
2012/12/04 01:32:16
This is really strange to my eyes too. If the opa
Ian Vollick
2012/12/04 19:49:06
Yes, it should. In fact, in my latest patch we exp
| |
368 return m_layerAnimationController->opacity(); | |
369 return m_opacity; | |
370 } | |
371 | |
365 bool Layer::opacityIsAnimating() const | 372 bool Layer::opacityIsAnimating() const |
366 { | 373 { |
367 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac ity); | 374 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac ity); |
368 } | 375 } |
369 | 376 |
370 void Layer::setContentsOpaque(bool opaque) | 377 void Layer::setContentsOpaque(bool opaque) |
371 { | 378 { |
372 if (m_contentsOpaque == opaque) | 379 if (m_contentsOpaque == opaque) |
373 return; | 380 return; |
374 m_contentsOpaque = opaque; | 381 m_contentsOpaque = opaque; |
(...skipping 14 matching lines...) Expand all Loading... | |
389 return; | 396 return; |
390 m_sublayerTransform = sublayerTransform; | 397 m_sublayerTransform = sublayerTransform; |
391 setNeedsCommit(); | 398 setNeedsCommit(); |
392 } | 399 } |
393 | 400 |
394 void Layer::setTransform(const gfx::Transform& transform) | 401 void Layer::setTransform(const gfx::Transform& transform) |
395 { | 402 { |
396 if (m_transform == transform) | 403 if (m_transform == transform) |
397 return; | 404 return; |
398 m_transform = transform; | 405 m_transform = transform; |
406 m_transformLastUpdateTime = base::TimeTicks::Now(); | |
399 setNeedsCommit(); | 407 setNeedsCommit(); |
400 } | 408 } |
401 | 409 |
410 const gfx::Transform& Layer::transform() const | |
411 { | |
412 if (m_layerAnimationController->transformLastUpdateTime() > m_transformLastU pdateTime) | |
413 return m_layerAnimationController->transform(); | |
414 return m_transform; | |
415 } | |
416 | |
402 bool Layer::transformIsAnimating() const | 417 bool Layer::transformIsAnimating() const |
403 { | 418 { |
404 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran sform); | 419 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran sform); |
405 } | 420 } |
406 | 421 |
407 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) | 422 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) |
408 { | 423 { |
409 if (m_scrollOffset == scrollOffset) | 424 if (m_scrollOffset == scrollOffset) |
410 return; | 425 return; |
411 m_scrollOffset = scrollOffset; | 426 m_scrollOffset = scrollOffset; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 return true; | 720 return true; |
706 } | 721 } |
707 return false; | 722 return false; |
708 } | 723 } |
709 | 724 |
710 int Layer::id() const | 725 int Layer::id() const |
711 { | 726 { |
712 return m_layerId; | 727 return m_layerId; |
713 } | 728 } |
714 | 729 |
715 float Layer::opacity() const | |
716 { | |
717 return m_opacity; | |
718 } | |
719 | |
720 void Layer::setOpacityFromAnimation(float opacity) | |
721 { | |
722 // This is called due to an ongoing accelerated animation. Since this animat ion is | |
723 // also being run on the impl thread, there is no need to request a commit t o push | |
724 // this value over, so set the value directly rather than calling setOpacity . | |
725 m_opacity = opacity; | |
726 } | |
727 | |
728 const gfx::Transform& Layer::transform() const | |
729 { | |
730 return m_transform; | |
731 } | |
732 | |
733 void Layer::setTransformFromAnimation(const gfx::Transform& transform) | |
734 { | |
735 // This is called due to an ongoing accelerated animation. Since this animat ion is | |
736 // also being run on the impl thread, there is no need to request a commit t o push | |
737 // this value over, so set this value directly rather than calling setTransf orm. | |
738 m_transform = transform; | |
739 } | |
740 | |
741 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) | 730 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) |
742 { | 731 { |
743 // WebCore currently assumes that accelerated animations will start soon | 732 // WebCore currently assumes that accelerated animations will start soon |
744 // after the animation is added. However we cannot guarantee that if we do | 733 // after the animation is added. However we cannot guarantee that if we do |
745 // not have a layerTreeHost that will setNeedsCommit(). | 734 // not have a layerTreeHost that will setNeedsCommit(). |
746 // Unfortunately, the fix below to guarantee correctness causes performance | 735 // Unfortunately, the fix below to guarantee correctness causes performance |
747 // regressions on Android, since Android has shipped for a long time | 736 // regressions on Android, since Android has shipped for a long time |
748 // with all animations accelerated. For this reason, we will live with | 737 // with all animations accelerated. For this reason, we will live with |
749 // this bug only on Android until the bug is fixed. | 738 // this bug only on Android until the bug is fixed. |
750 // http://crbug.com/129683 | 739 // http://crbug.com/129683 |
751 #if !defined(OS_ANDROID) | 740 #if !defined(OS_ANDROID) |
752 if (!m_layerTreeHost) | 741 if (!m_layerTreeHost) |
753 return false; | 742 return false; |
754 | 743 |
755 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) | 744 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) |
756 return false; | 745 return false; |
757 #endif | 746 #endif |
758 | 747 |
759 m_layerAnimationController->addAnimation(animation.Pass()); | 748 m_layerAnimationController->addAnimation(animation.Pass()); |
760 if (m_layerTreeHost) { | |
761 m_layerTreeHost->didAddAnimation(); | |
762 setNeedsCommit(); | 749 setNeedsCommit(); |
763 } | |
764 return true; | 750 return true; |
765 } | 751 } |
766 | 752 |
767 void Layer::pauseAnimation(int animationId, double timeOffset) | 753 void Layer::pauseAnimation(int animationId, double timeOffset) |
768 { | 754 { |
769 m_layerAnimationController->pauseAnimation(animationId, timeOffset); | 755 m_layerAnimationController->pauseAnimation(animationId, timeOffset); |
770 setNeedsCommit(); | 756 setNeedsCommit(); |
771 } | 757 } |
772 | 758 |
773 void Layer::removeAnimation(int animationId) | 759 void Layer::removeAnimation(int animationId) |
774 { | 760 { |
775 m_layerAnimationController->removeAnimation(animationId); | 761 m_layerAnimationController->removeAnimation(animationId); |
776 setNeedsCommit(); | 762 setNeedsCommit(); |
777 } | 763 } |
778 | 764 |
779 void Layer::suspendAnimations(double monotonicTime) | 765 void Layer::suspendAnimations(double monotonicTime) |
780 { | 766 { |
781 m_layerAnimationController->suspendAnimations(monotonicTime); | 767 m_layerAnimationController->suspendAnimations(monotonicTime); |
782 setNeedsCommit(); | 768 setNeedsCommit(); |
783 } | 769 } |
784 | 770 |
785 void Layer::resumeAnimations(double monotonicTime) | 771 void Layer::resumeAnimations(double monotonicTime) |
786 { | 772 { |
787 m_layerAnimationController->resumeAnimations(monotonicTime); | 773 m_layerAnimationController->resumeAnimations(monotonicTime); |
788 setNeedsCommit(); | 774 setNeedsCommit(); |
789 } | 775 } |
790 | 776 |
791 void Layer::setLayerAnimationController(scoped_ptr<LayerAnimationController> lay erAnimationController) | 777 void Layer::setLayerAnimationController(scoped_refptr<LayerAnimationController> layerAnimationController) |
792 { | 778 { |
793 m_layerAnimationController = layerAnimationController.Pass(); | 779 m_layerAnimationController = layerAnimationController; |
794 if (m_layerAnimationController) { | 780 if (m_layerAnimationController) { |
795 m_layerAnimationController->setClient(this); | 781 m_layerAnimationController->setId(id()); |
796 m_layerAnimationController->setForceSync(); | 782 m_layerAnimationController->setForceSync(); |
797 } | 783 } |
798 setNeedsCommit(); | 784 setNeedsCommit(); |
799 } | 785 } |
800 | 786 |
801 scoped_ptr<LayerAnimationController> Layer::releaseLayerAnimationController() | 787 scoped_refptr<LayerAnimationController> Layer::releaseLayerAnimationController() |
802 { | 788 { |
803 scoped_ptr<LayerAnimationController> toReturn = m_layerAnimationController.P ass(); | 789 scoped_refptr<LayerAnimationController> toReturn = m_layerAnimationControlle r; |
804 m_layerAnimationController = LayerAnimationController::create(this); | 790 m_layerAnimationController = LayerAnimationController::create(); |
805 return toReturn.Pass(); | 791 m_layerAnimationController->setId(id()); |
792 return toReturn; | |
806 } | 793 } |
807 | 794 |
808 bool Layer::hasActiveAnimation() const | 795 bool Layer::hasActiveAnimation() const |
809 { | 796 { |
810 return m_layerAnimationController->hasActiveAnimation(); | 797 return m_layerAnimationController->hasActiveAnimation(); |
811 } | 798 } |
812 | 799 |
813 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock Time) | 800 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock Time) |
814 { | 801 { |
815 m_layerAnimationController->notifyAnimationStarted(event); | 802 m_layerAnimationController->notifyAnimationStarted(event); |
(...skipping 18 matching lines...) Expand all Loading... | |
834 { | 821 { |
835 return 0; | 822 return 0; |
836 } | 823 } |
837 | 824 |
838 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped _refptr<Layer> >::iterator, void*) | 825 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped _refptr<Layer> >::iterator, void*) |
839 { | 826 { |
840 // Currently we don't use z-order to decide what to paint, so there's no nee d to actually sort Layers. | 827 // Currently we don't use z-order to decide what to paint, so there's no nee d to actually sort Layers. |
841 } | 828 } |
842 | 829 |
843 } // namespace cc | 830 } // namespace cc |
OLD | NEW |