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