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()) | 35 , m_layerAnimationController(LayerAnimationController::create(this)) |
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_anchorPointZ(0) | 44 , m_anchorPointZ(0) |
44 , m_isContainerForFixedPositionLayers(false) | 45 , m_isContainerForFixedPositionLayers(false) |
45 , m_fixedToContainerLayer(false) | 46 , m_fixedToContainerLayer(false) |
46 , m_isDrawable(false) | 47 , m_isDrawable(false) |
47 , m_masksToBounds(false) | 48 , m_masksToBounds(false) |
48 , m_contentsOpaque(false) | 49 , m_contentsOpaque(false) |
49 , m_doubleSided(true) | 50 , m_doubleSided(true) |
50 , m_useLCDText(false) | 51 , m_useLCDText(false) |
51 , m_preserves3D(false) | 52 , m_preserves3D(false) |
52 , m_useParentBackfaceVisibility(false) | 53 , m_useParentBackfaceVisibility(false) |
53 , m_drawCheckerboardForMissingTiles(false) | 54 , m_drawCheckerboardForMissingTiles(false) |
54 , m_forceRenderSurface(false) | 55 , m_forceRenderSurface(false) |
55 , m_replicaLayer(0) | 56 , m_replicaLayer(0) |
56 , m_rasterScale(1.0) | 57 , m_rasterScale(1.0) |
57 , m_automaticallyComputeRasterScale(false) | 58 , m_automaticallyComputeRasterScale(false) |
58 , m_boundsContainPageScale(false) | 59 , m_boundsContainPageScale(false) |
59 , m_layerAnimationDelegate(0) | 60 , m_layerAnimationDelegate(0) |
60 , m_layerScrollClient(0) | 61 , m_layerScrollClient(0) |
61 { | 62 { |
62 if (m_layerId < 0) { | 63 if (m_layerId < 0) { |
63 s_nextLayerId = 1; | 64 s_nextLayerId = 1; |
64 m_layerId = s_nextLayerId++; | 65 m_layerId = s_nextLayerId++; |
65 } | 66 } |
66 m_layerAnimationController->setId(m_layerId); | |
67 } | 67 } |
68 | 68 |
69 Layer::~Layer() | 69 Layer::~Layer() |
70 { | 70 { |
71 // 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 |
72 // 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. |
73 DCHECK(!parent()); | 73 DCHECK(!parent()); |
74 | 74 |
75 // Remove the parent reference from all children. | 75 // Remove the parent reference from all children. |
76 removeAllChildren(); | 76 removeAllChildren(); |
(...skipping 12 matching lines...) Expand all Loading... |
89 m_layerTreeHost = host; | 89 m_layerTreeHost = host; |
90 | 90 |
91 for (size_t i = 0; i < m_children.size(); ++i) | 91 for (size_t i = 0; i < m_children.size(); ++i) |
92 m_children[i]->setLayerTreeHost(host); | 92 m_children[i]->setLayerTreeHost(host); |
93 | 93 |
94 if (m_maskLayer) | 94 if (m_maskLayer) |
95 m_maskLayer->setLayerTreeHost(host); | 95 m_maskLayer->setLayerTreeHost(host); |
96 if (m_replicaLayer) | 96 if (m_replicaLayer) |
97 m_replicaLayer->setLayerTreeHost(host); | 97 m_replicaLayer->setLayerTreeHost(host); |
98 | 98 |
99 m_layerAnimationController->setAnimationRegistrar(host); | 99 // If this layer already has active animations, the host needs to be notifie
d. |
| 100 if (host && m_layerAnimationController->hasActiveAnimation()) |
| 101 host->didAddAnimation(); |
100 } | 102 } |
101 | 103 |
102 void Layer::setNeedsCommit() | 104 void Layer::setNeedsCommit() |
103 { | 105 { |
104 if (m_layerTreeHost) | 106 if (m_layerTreeHost) |
105 m_layerTreeHost->setNeedsCommit(); | 107 m_layerTreeHost->setNeedsCommit(); |
106 } | 108 } |
107 | 109 |
108 void Layer::setNeedsFullTreeSync() | 110 void Layer::setNeedsFullTreeSync() |
109 { | 111 { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 LayerTreeHost::setNeedsFilterContext(true); | 351 LayerTreeHost::setNeedsFilterContext(true); |
350 } | 352 } |
351 | 353 |
352 bool Layer::needsDisplay() const | 354 bool Layer::needsDisplay() const |
353 { | 355 { |
354 return m_needsDisplay; | 356 return m_needsDisplay; |
355 } | 357 } |
356 | 358 |
357 void Layer::setOpacity(float opacity) | 359 void Layer::setOpacity(float opacity) |
358 { | 360 { |
359 if (!m_layerAnimationController->setOpacity(opacity)) | 361 if (m_opacity == opacity) |
360 return; | 362 return; |
| 363 m_opacity = opacity; |
361 setNeedsCommit(); | 364 setNeedsCommit(); |
362 } | 365 } |
363 | 366 |
364 float Layer::opacity() const | |
365 { | |
366 return m_layerAnimationController->opacity(); | |
367 } | |
368 | |
369 bool Layer::opacityIsAnimating() const | 367 bool Layer::opacityIsAnimating() const |
370 { | 368 { |
371 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac
ity); | 369 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac
ity); |
372 } | 370 } |
373 | 371 |
374 void Layer::setContentsOpaque(bool opaque) | 372 void Layer::setContentsOpaque(bool opaque) |
375 { | 373 { |
376 if (m_contentsOpaque == opaque) | 374 if (m_contentsOpaque == opaque) |
377 return; | 375 return; |
378 m_contentsOpaque = opaque; | 376 m_contentsOpaque = opaque; |
(...skipping 11 matching lines...) Expand all Loading... |
390 void Layer::setSublayerTransform(const gfx::Transform& sublayerTransform) | 388 void Layer::setSublayerTransform(const gfx::Transform& sublayerTransform) |
391 { | 389 { |
392 if (m_sublayerTransform == sublayerTransform) | 390 if (m_sublayerTransform == sublayerTransform) |
393 return; | 391 return; |
394 m_sublayerTransform = sublayerTransform; | 392 m_sublayerTransform = sublayerTransform; |
395 setNeedsCommit(); | 393 setNeedsCommit(); |
396 } | 394 } |
397 | 395 |
398 void Layer::setTransform(const gfx::Transform& transform) | 396 void Layer::setTransform(const gfx::Transform& transform) |
399 { | 397 { |
400 if (!m_layerAnimationController->setTransform(transform)) | 398 if (m_transform == transform) |
401 return; | 399 return; |
| 400 m_transform = transform; |
402 setNeedsCommit(); | 401 setNeedsCommit(); |
403 } | 402 } |
404 | 403 |
405 const gfx::Transform& Layer::transform() const | |
406 { | |
407 return m_layerAnimationController->transform(); | |
408 } | |
409 | |
410 bool Layer::transformIsAnimating() const | 404 bool Layer::transformIsAnimating() const |
411 { | 405 { |
412 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran
sform); | 406 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran
sform); |
413 } | 407 } |
414 | 408 |
415 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) | 409 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) |
416 { | 410 { |
417 if (m_scrollOffset == scrollOffset) | 411 if (m_scrollOffset == scrollOffset) |
418 return; | 412 return; |
419 m_scrollOffset = scrollOffset; | 413 m_scrollOffset = scrollOffset; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 // arbitrarily large depending on page content, so we only push the property
if it's changed. | 576 // arbitrarily large depending on page content, so we only push the property
if it's changed. |
583 if (m_nonFastScrollableRegionChanged) { | 577 if (m_nonFastScrollableRegionChanged) { |
584 layer->setNonFastScrollableRegion(m_nonFastScrollableRegion); | 578 layer->setNonFastScrollableRegion(m_nonFastScrollableRegion); |
585 m_nonFastScrollableRegionChanged = false; | 579 m_nonFastScrollableRegionChanged = false; |
586 } | 580 } |
587 if (m_touchEventHandlerRegionChanged) { | 581 if (m_touchEventHandlerRegionChanged) { |
588 layer->setTouchEventHandlerRegion(m_touchEventHandlerRegion); | 582 layer->setTouchEventHandlerRegion(m_touchEventHandlerRegion); |
589 m_touchEventHandlerRegionChanged = false; | 583 m_touchEventHandlerRegionChanged = false; |
590 } | 584 } |
591 layer->setContentsOpaque(m_contentsOpaque); | 585 layer->setContentsOpaque(m_contentsOpaque); |
| 586 if (!opacityIsAnimating()) |
| 587 layer->setOpacity(m_opacity); |
592 layer->setPosition(m_position); | 588 layer->setPosition(m_position); |
593 layer->setIsContainerForFixedPositionLayers(m_isContainerForFixedPositionLay
ers); | 589 layer->setIsContainerForFixedPositionLayers(m_isContainerForFixedPositionLay
ers); |
594 layer->setFixedToContainerLayer(m_fixedToContainerLayer); | 590 layer->setFixedToContainerLayer(m_fixedToContainerLayer); |
595 layer->setPreserves3D(preserves3D()); | 591 layer->setPreserves3D(preserves3D()); |
596 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility); | 592 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility); |
597 layer->setScrollOffset(m_scrollOffset); | 593 layer->setScrollOffset(m_scrollOffset); |
598 layer->setMaxScrollOffset(m_maxScrollOffset); | 594 layer->setMaxScrollOffset(m_maxScrollOffset); |
599 layer->setSublayerTransform(m_sublayerTransform); | 595 layer->setSublayerTransform(m_sublayerTransform); |
| 596 if (!transformIsAnimating()) |
| 597 layer->setTransform(m_transform); |
600 | 598 |
601 // If the main thread commits multiple times before the impl thread actually
draws, then damage tracking | 599 // If the main thread commits multiple times before the impl thread actually
draws, then damage tracking |
602 // will become incorrect if we simply clobber the updateRect here. The Layer
Impl's updateRect needs to | 600 // will become incorrect if we simply clobber the updateRect here. The Layer
Impl's updateRect needs to |
603 // accumulate (i.e. union) any update changes that have occurred on the main
thread. | 601 // accumulate (i.e. union) any update changes that have occurred on the main
thread. |
604 m_updateRect.Union(layer->updateRect()); | 602 m_updateRect.Union(layer->updateRect()); |
605 layer->setUpdateRect(m_updateRect); | 603 layer->setUpdateRect(m_updateRect); |
606 | 604 |
607 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta()); | 605 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta()); |
608 layer->setSentScrollDelta(gfx::Vector2d()); | 606 layer->setSentScrollDelta(gfx::Vector2d()); |
609 | 607 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 return result; | 711 return result; |
714 } | 712 } |
715 return result; | 713 return result; |
716 } | 714 } |
717 | 715 |
718 int Layer::id() const | 716 int Layer::id() const |
719 { | 717 { |
720 return m_layerId; | 718 return m_layerId; |
721 } | 719 } |
722 | 720 |
| 721 float Layer::opacity() const |
| 722 { |
| 723 return m_opacity; |
| 724 } |
| 725 |
| 726 void Layer::setOpacityFromAnimation(float opacity) |
| 727 { |
| 728 // This is called due to an ongoing accelerated animation. Since this animat
ion is |
| 729 // also being run on the impl thread, there is no need to request a commit t
o push |
| 730 // this value over, so set the value directly rather than calling setOpacity
. |
| 731 m_opacity = opacity; |
| 732 } |
| 733 |
| 734 const gfx::Transform& Layer::transform() const |
| 735 { |
| 736 return m_transform; |
| 737 } |
| 738 |
| 739 void Layer::setTransformFromAnimation(const gfx::Transform& transform) |
| 740 { |
| 741 // This is called due to an ongoing accelerated animation. Since this animat
ion is |
| 742 // also being run on the impl thread, there is no need to request a commit t
o push |
| 743 // this value over, so set this value directly rather than calling setTransf
orm. |
| 744 m_transform = transform; |
| 745 } |
| 746 |
723 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) | 747 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) |
724 { | 748 { |
725 // WebCore currently assumes that accelerated animations will start soon | 749 // WebCore currently assumes that accelerated animations will start soon |
726 // after the animation is added. However we cannot guarantee that if we do | 750 // after the animation is added. However we cannot guarantee that if we do |
727 // not have a layerTreeHost that will setNeedsCommit(). | 751 // not have a layerTreeHost that will setNeedsCommit(). |
728 // Unfortunately, the fix below to guarantee correctness causes performance | 752 // Unfortunately, the fix below to guarantee correctness causes performance |
729 // regressions on Android, since Android has shipped for a long time | 753 // regressions on Android, since Android has shipped for a long time |
730 // with all animations accelerated. For this reason, we will live with | 754 // with all animations accelerated. For this reason, we will live with |
731 // this bug only on Android until the bug is fixed. | 755 // this bug only on Android until the bug is fixed. |
732 // http://crbug.com/129683 | 756 // http://crbug.com/129683 |
733 #if !defined(OS_ANDROID) | 757 #if !defined(OS_ANDROID) |
734 if (!m_layerTreeHost) | 758 if (!m_layerTreeHost) |
735 return false; | 759 return false; |
736 | 760 |
737 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) | 761 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) |
738 return false; | 762 return false; |
739 #endif | 763 #endif |
740 | 764 |
741 m_layerAnimationController->addAnimation(animation.Pass()); | 765 m_layerAnimationController->addAnimation(animation.Pass()); |
| 766 if (m_layerTreeHost) { |
| 767 m_layerTreeHost->didAddAnimation(); |
742 setNeedsCommit(); | 768 setNeedsCommit(); |
| 769 } |
743 return true; | 770 return true; |
744 } | 771 } |
745 | 772 |
746 void Layer::pauseAnimation(int animationId, double timeOffset) | 773 void Layer::pauseAnimation(int animationId, double timeOffset) |
747 { | 774 { |
748 m_layerAnimationController->pauseAnimation(animationId, timeOffset); | 775 m_layerAnimationController->pauseAnimation(animationId, timeOffset); |
749 setNeedsCommit(); | 776 setNeedsCommit(); |
750 } | 777 } |
751 | 778 |
752 void Layer::removeAnimation(int animationId) | 779 void Layer::removeAnimation(int animationId) |
753 { | 780 { |
754 m_layerAnimationController->removeAnimation(animationId); | 781 m_layerAnimationController->removeAnimation(animationId); |
755 setNeedsCommit(); | 782 setNeedsCommit(); |
756 } | 783 } |
757 | 784 |
758 void Layer::suspendAnimations(double monotonicTime) | 785 void Layer::suspendAnimations(double monotonicTime) |
759 { | 786 { |
760 m_layerAnimationController->suspendAnimations(monotonicTime); | 787 m_layerAnimationController->suspendAnimations(monotonicTime); |
761 setNeedsCommit(); | 788 setNeedsCommit(); |
762 } | 789 } |
763 | 790 |
764 void Layer::resumeAnimations(double monotonicTime) | 791 void Layer::resumeAnimations(double monotonicTime) |
765 { | 792 { |
766 m_layerAnimationController->resumeAnimations(monotonicTime); | 793 m_layerAnimationController->resumeAnimations(monotonicTime); |
767 setNeedsCommit(); | 794 setNeedsCommit(); |
768 } | 795 } |
769 | 796 |
770 void Layer::setLayerAnimationController(scoped_refptr<LayerAnimationController>
layerAnimationController) | 797 void Layer::setLayerAnimationController(scoped_ptr<LayerAnimationController> lay
erAnimationController) |
771 { | 798 { |
772 m_layerAnimationController = layerAnimationController; | 799 m_layerAnimationController = layerAnimationController.Pass(); |
773 if (m_layerAnimationController) { | 800 if (m_layerAnimationController) { |
774 m_layerAnimationController->setId(id()); | 801 m_layerAnimationController->setClient(this); |
775 m_layerAnimationController->setForceSync(); | 802 m_layerAnimationController->setForceSync(); |
776 } | 803 } |
777 setNeedsCommit(); | 804 setNeedsCommit(); |
778 } | 805 } |
779 | 806 |
780 scoped_refptr<LayerAnimationController> Layer::releaseLayerAnimationController() | 807 scoped_ptr<LayerAnimationController> Layer::releaseLayerAnimationController() |
781 { | 808 { |
782 scoped_refptr<LayerAnimationController> toReturn = m_layerAnimationControlle
r; | 809 scoped_ptr<LayerAnimationController> toReturn = m_layerAnimationController.P
ass(); |
783 m_layerAnimationController = LayerAnimationController::create(); | 810 m_layerAnimationController = LayerAnimationController::create(this); |
784 m_layerAnimationController->setId(id()); | 811 return toReturn.Pass(); |
785 m_layerAnimationController->setTransform(toReturn->transform()); | |
786 m_layerAnimationController->setOpacity(toReturn->opacity()); | |
787 return toReturn; | |
788 } | 812 } |
789 | 813 |
790 bool Layer::hasActiveAnimation() const | 814 bool Layer::hasActiveAnimation() const |
791 { | 815 { |
792 return m_layerAnimationController->hasActiveAnimation(); | 816 return m_layerAnimationController->hasActiveAnimation(); |
793 } | 817 } |
794 | 818 |
795 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock
Time) | 819 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock
Time) |
796 { | 820 { |
797 m_layerAnimationController->notifyAnimationStarted(event); | 821 m_layerAnimationController->notifyAnimationStarted(event); |
(...skipping 18 matching lines...) Expand all Loading... |
816 { | 840 { |
817 return 0; | 841 return 0; |
818 } | 842 } |
819 | 843 |
820 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*) | 844 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*) |
821 { | 845 { |
822 // Currently we don't use z-order to decide what to paint, so there's no nee
d to actually sort Layers. | 846 // Currently we don't use z-order to decide what to paint, so there's no nee
d to actually sort Layers. |
823 } | 847 } |
824 | 848 |
825 } // namespace cc | 849 } // namespace cc |
OLD | NEW |