Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: cc/layer.cc

Issue 11443004: Maintain global lists of animation controllers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/animation_registrar.h"
9 #include "cc/layer_animation_controller.h" 10 #include "cc/layer_animation_controller.h"
10 #include "cc/layer_impl.h" 11 #include "cc/layer_impl.h"
11 #include "cc/layer_tree_host.h" 12 #include "cc/layer_tree_host.h"
12 #include "third_party/skia/include/core/SkImageFilter.h" 13 #include "third_party/skia/include/core/SkImageFilter.h"
13 #include "ui/gfx/rect_conversions.h" 14 #include "ui/gfx/rect_conversions.h"
14 #include <public/WebAnimationDelegate.h> 15 #include <public/WebAnimationDelegate.h>
15 #include <public/WebLayerScrollClient.h> 16 #include <public/WebLayerScrollClient.h>
16 #include <public/WebSize.h> 17 #include <public/WebSize.h>
17 18
18 using namespace std; 19 using namespace std;
19 20
20 namespace cc { 21 namespace cc {
21 22
22 static int s_nextLayerId = 1; 23 static int s_nextLayerId = 1;
23 24
24 scoped_refptr<Layer> Layer::create() 25 scoped_refptr<Layer> Layer::create()
25 { 26 {
26 return make_scoped_refptr(new Layer()); 27 return make_scoped_refptr(new Layer());
27 } 28 }
28 29
29 Layer::Layer() 30 Layer::Layer()
30 : m_needsDisplay(false) 31 : m_needsDisplay(false)
31 , m_stackingOrderChanged(false) 32 , m_stackingOrderChanged(false)
32 , m_layerId(s_nextLayerId++) 33 , m_layerId(s_nextLayerId++)
33 , m_parent(0) 34 , m_parent(0)
34 , m_layerTreeHost(0) 35 , m_layerTreeHost(0)
35 , m_layerAnimationController(LayerAnimationController::create(this)) 36 , m_layerAnimationController(LayerAnimationController::create(AnimationRegis trar::MainThread))
36 , m_scrollable(false) 37 , m_scrollable(false)
37 , m_shouldScrollOnMainThread(false) 38 , m_shouldScrollOnMainThread(false)
38 , m_haveWheelEventHandlers(false) 39 , m_haveWheelEventHandlers(false)
39 , m_nonFastScrollableRegionChanged(false) 40 , m_nonFastScrollableRegionChanged(false)
40 , m_touchEventHandlerRegionChanged(false) 41 , m_touchEventHandlerRegionChanged(false)
41 , m_anchorPoint(0.5, 0.5) 42 , m_anchorPoint(0.5, 0.5)
42 , m_backgroundColor(0) 43 , m_backgroundColor(0)
43 , m_opacity(1.0)
44 , m_anchorPointZ(0) 44 , m_anchorPointZ(0)
45 , m_isContainerForFixedPositionLayers(false) 45 , m_isContainerForFixedPositionLayers(false)
46 , m_fixedToContainerLayer(false) 46 , m_fixedToContainerLayer(false)
47 , m_isDrawable(false) 47 , m_isDrawable(false)
48 , m_masksToBounds(false) 48 , m_masksToBounds(false)
49 , m_contentsOpaque(false) 49 , m_contentsOpaque(false)
50 , m_doubleSided(true) 50 , m_doubleSided(true)
51 , m_useLCDText(false) 51 , m_useLCDText(false)
52 , m_preserves3D(false) 52 , m_preserves3D(false)
53 , m_useParentBackfaceVisibility(false) 53 , m_useParentBackfaceVisibility(false)
54 , m_drawCheckerboardForMissingTiles(false) 54 , m_drawCheckerboardForMissingTiles(false)
55 , m_forceRenderSurface(false) 55 , m_forceRenderSurface(false)
56 , m_replicaLayer(0) 56 , m_replicaLayer(0)
57 , m_drawOpacity(0) 57 , m_drawOpacity(0)
58 , m_drawOpacityIsAnimating(false) 58 , m_drawOpacityIsAnimating(false)
59 , m_renderTarget(0) 59 , m_renderTarget(0)
60 , m_drawTransformIsAnimating(false) 60 , m_drawTransformIsAnimating(false)
61 , m_screenSpaceTransformIsAnimating(false) 61 , m_screenSpaceTransformIsAnimating(false)
62 , m_isClipped(false) 62 , m_isClipped(false)
63 , m_rasterScale(1.0) 63 , m_rasterScale(1.0)
64 , m_automaticallyComputeRasterScale(false) 64 , m_automaticallyComputeRasterScale(false)
65 , m_boundsContainPageScale(false) 65 , m_boundsContainPageScale(false)
66 , m_layerAnimationDelegate(0) 66 , m_layerAnimationDelegate(0)
67 , m_layerScrollClient(0) 67 , m_layerScrollClient(0)
68 { 68 {
69 if (m_layerId < 0) { 69 if (m_layerId < 0) {
70 s_nextLayerId = 1; 70 s_nextLayerId = 1;
71 m_layerId = s_nextLayerId++; 71 m_layerId = s_nextLayerId++;
72 } 72 }
73 m_layerAnimationController->setId(m_layerId);
73 } 74 }
74 75
75 Layer::~Layer() 76 Layer::~Layer()
76 { 77 {
77 // Our parent should be holding a reference to us so there should be no 78 // 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. 79 // way for us to be destroyed while we still have a parent.
79 DCHECK(!parent()); 80 DCHECK(!parent());
80 81
81 // Remove the parent reference from all children. 82 // Remove the parent reference from all children.
82 removeAllChildren(); 83 removeAllChildren();
(...skipping 12 matching lines...) Expand all
95 m_layerTreeHost = host; 96 m_layerTreeHost = host;
96 97
97 for (size_t i = 0; i < m_children.size(); ++i) 98 for (size_t i = 0; i < m_children.size(); ++i)
98 m_children[i]->setLayerTreeHost(host); 99 m_children[i]->setLayerTreeHost(host);
99 100
100 if (m_maskLayer) 101 if (m_maskLayer)
101 m_maskLayer->setLayerTreeHost(host); 102 m_maskLayer->setLayerTreeHost(host);
102 if (m_replicaLayer) 103 if (m_replicaLayer)
103 m_replicaLayer->setLayerTreeHost(host); 104 m_replicaLayer->setLayerTreeHost(host);
104 105
105 // If this layer already has active animations, the host needs to be notifie d.
106 if (host && m_layerAnimationController->hasActiveAnimation()) 106 if (host && m_layerAnimationController->hasActiveAnimation())
107 host->didAddAnimation(); 107 host->didAddAnimation();
108 } 108 }
109 109
110 void Layer::setNeedsCommit() 110 void Layer::setNeedsCommit()
111 { 111 {
112 if (m_layerTreeHost) 112 if (m_layerTreeHost)
113 m_layerTreeHost->setNeedsCommit(); 113 m_layerTreeHost->setNeedsCommit();
114 } 114 }
115 115
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 LayerTreeHost::setNeedsFilterContext(true); 352 LayerTreeHost::setNeedsFilterContext(true);
353 } 353 }
354 354
355 bool Layer::needsDisplay() const 355 bool Layer::needsDisplay() const
356 { 356 {
357 return m_needsDisplay; 357 return m_needsDisplay;
358 } 358 }
359 359
360 void Layer::setOpacity(float opacity) 360 void Layer::setOpacity(float opacity)
361 { 361 {
362 if (m_opacity == opacity) 362 if (!m_layerAnimationController->setOpacity(opacity))
363 return; 363 return;
364 m_opacity = opacity;
365 setNeedsCommit(); 364 setNeedsCommit();
366 } 365 }
367 366
367 float Layer::opacity() const
368 {
369 return m_layerAnimationController->opacity();
370 }
371
368 bool Layer::opacityIsAnimating() const 372 bool Layer::opacityIsAnimating() const
369 { 373 {
370 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac ity); 374 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac ity);
371 } 375 }
372 376
373 void Layer::setContentsOpaque(bool opaque) 377 void Layer::setContentsOpaque(bool opaque)
374 { 378 {
375 if (m_contentsOpaque == opaque) 379 if (m_contentsOpaque == opaque)
376 return; 380 return;
377 m_contentsOpaque = opaque; 381 m_contentsOpaque = opaque;
(...skipping 11 matching lines...) Expand all
389 void Layer::setSublayerTransform(const gfx::Transform& sublayerTransform) 393 void Layer::setSublayerTransform(const gfx::Transform& sublayerTransform)
390 { 394 {
391 if (m_sublayerTransform == sublayerTransform) 395 if (m_sublayerTransform == sublayerTransform)
392 return; 396 return;
393 m_sublayerTransform = sublayerTransform; 397 m_sublayerTransform = sublayerTransform;
394 setNeedsCommit(); 398 setNeedsCommit();
395 } 399 }
396 400
397 void Layer::setTransform(const gfx::Transform& transform) 401 void Layer::setTransform(const gfx::Transform& transform)
398 { 402 {
399 if (m_transform == transform) 403 if (!m_layerAnimationController->setTransform(transform))
400 return; 404 return;
401 m_transform = transform;
402 setNeedsCommit(); 405 setNeedsCommit();
403 } 406 }
404 407
408 const gfx::Transform& Layer::transform() const
409 {
410 return m_layerAnimationController->transform();
411 }
412
405 bool Layer::transformIsAnimating() const 413 bool Layer::transformIsAnimating() const
406 { 414 {
407 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran sform); 415 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran sform);
408 } 416 }
409 417
410 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) 418 void Layer::setScrollOffset(gfx::Vector2d scrollOffset)
411 { 419 {
412 if (m_scrollOffset == scrollOffset) 420 if (m_scrollOffset == scrollOffset)
413 return; 421 return;
414 m_scrollOffset = scrollOffset; 422 m_scrollOffset = scrollOffset;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 // arbitrarily large depending on page content, so we only push the property if it's changed. 585 // arbitrarily large depending on page content, so we only push the property if it's changed.
578 if (m_nonFastScrollableRegionChanged) { 586 if (m_nonFastScrollableRegionChanged) {
579 layer->setNonFastScrollableRegion(m_nonFastScrollableRegion); 587 layer->setNonFastScrollableRegion(m_nonFastScrollableRegion);
580 m_nonFastScrollableRegionChanged = false; 588 m_nonFastScrollableRegionChanged = false;
581 } 589 }
582 if (m_touchEventHandlerRegionChanged) { 590 if (m_touchEventHandlerRegionChanged) {
583 layer->setTouchEventHandlerRegion(m_touchEventHandlerRegion); 591 layer->setTouchEventHandlerRegion(m_touchEventHandlerRegion);
584 m_touchEventHandlerRegionChanged = false; 592 m_touchEventHandlerRegionChanged = false;
585 } 593 }
586 layer->setContentsOpaque(m_contentsOpaque); 594 layer->setContentsOpaque(m_contentsOpaque);
587 if (!opacityIsAnimating())
588 layer->setOpacity(m_opacity);
589 layer->setPosition(m_position); 595 layer->setPosition(m_position);
590 layer->setIsContainerForFixedPositionLayers(m_isContainerForFixedPositionLay ers); 596 layer->setIsContainerForFixedPositionLayers(m_isContainerForFixedPositionLay ers);
591 layer->setFixedToContainerLayer(m_fixedToContainerLayer); 597 layer->setFixedToContainerLayer(m_fixedToContainerLayer);
592 layer->setPreserves3D(preserves3D()); 598 layer->setPreserves3D(preserves3D());
593 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility); 599 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility);
594 layer->setScrollOffset(m_scrollOffset); 600 layer->setScrollOffset(m_scrollOffset);
595 layer->setMaxScrollOffset(m_maxScrollOffset); 601 layer->setMaxScrollOffset(m_maxScrollOffset);
596 layer->setSublayerTransform(m_sublayerTransform); 602 layer->setSublayerTransform(m_sublayerTransform);
597 if (!transformIsAnimating())
598 layer->setTransform(m_transform);
599 603
600 // If the main thread commits multiple times before the impl thread actually draws, then damage tracking 604 // 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 605 // 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. 606 // accumulate (i.e. union) any update changes that have occurred on the main thread.
603 m_updateRect.Union(layer->updateRect()); 607 m_updateRect.Union(layer->updateRect());
604 layer->setUpdateRect(m_updateRect); 608 layer->setUpdateRect(m_updateRect);
605 609
606 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta()); 610 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta());
607 layer->setSentScrollDelta(gfx::Vector2d()); 611 layer->setSentScrollDelta(gfx::Vector2d());
608 612
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 return result; 716 return result;
713 } 717 }
714 return result; 718 return result;
715 } 719 }
716 720
717 int Layer::id() const 721 int Layer::id() const
718 { 722 {
719 return m_layerId; 723 return m_layerId;
720 } 724 }
721 725
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) 726 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation)
749 { 727 {
750 // WebCore currently assumes that accelerated animations will start soon 728 // WebCore currently assumes that accelerated animations will start soon
751 // after the animation is added. However we cannot guarantee that if we do 729 // after the animation is added. However we cannot guarantee that if we do
752 // not have a layerTreeHost that will setNeedsCommit(). 730 // not have a layerTreeHost that will setNeedsCommit().
753 // Unfortunately, the fix below to guarantee correctness causes performance 731 // Unfortunately, the fix below to guarantee correctness causes performance
754 // regressions on Android, since Android has shipped for a long time 732 // regressions on Android, since Android has shipped for a long time
755 // with all animations accelerated. For this reason, we will live with 733 // with all animations accelerated. For this reason, we will live with
756 // this bug only on Android until the bug is fixed. 734 // this bug only on Android until the bug is fixed.
757 // http://crbug.com/129683 735 // http://crbug.com/129683
758 #if !defined(OS_ANDROID) 736 #if !defined(OS_ANDROID)
759 if (!m_layerTreeHost) 737 if (!m_layerTreeHost)
760 return false; 738 return false;
761 739
762 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) 740 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled)
763 return false; 741 return false;
764 #endif 742 #endif
765 743
766 m_layerAnimationController->addAnimation(animation.Pass()); 744 m_layerAnimationController->addAnimation(animation.Pass());
767 if (m_layerTreeHost) { 745
768 m_layerTreeHost->didAddAnimation(); 746 m_layerTreeHost->didAddAnimation();
769 setNeedsCommit(); 747 setNeedsCommit();
770 }
771 return true; 748 return true;
772 } 749 }
773 750
774 void Layer::pauseAnimation(int animationId, double timeOffset) 751 void Layer::pauseAnimation(int animationId, double timeOffset)
775 { 752 {
776 m_layerAnimationController->pauseAnimation(animationId, timeOffset); 753 m_layerAnimationController->pauseAnimation(animationId, timeOffset);
777 setNeedsCommit(); 754 setNeedsCommit();
778 } 755 }
779 756
780 void Layer::removeAnimation(int animationId) 757 void Layer::removeAnimation(int animationId)
781 { 758 {
782 m_layerAnimationController->removeAnimation(animationId); 759 m_layerAnimationController->removeAnimation(animationId);
783 setNeedsCommit(); 760 setNeedsCommit();
784 } 761 }
785 762
786 void Layer::suspendAnimations(double monotonicTime) 763 void Layer::suspendAnimations(double monotonicTime)
787 { 764 {
788 m_layerAnimationController->suspendAnimations(monotonicTime); 765 m_layerAnimationController->suspendAnimations(monotonicTime);
789 setNeedsCommit(); 766 setNeedsCommit();
790 } 767 }
791 768
792 void Layer::resumeAnimations(double monotonicTime) 769 void Layer::resumeAnimations(double monotonicTime)
793 { 770 {
794 m_layerAnimationController->resumeAnimations(monotonicTime); 771 m_layerAnimationController->resumeAnimations(monotonicTime);
795 setNeedsCommit(); 772 setNeedsCommit();
796 } 773 }
797 774
798 void Layer::setLayerAnimationController(scoped_ptr<LayerAnimationController> lay erAnimationController) 775 void Layer::setLayerAnimationController(scoped_refptr<LayerAnimationController> layerAnimationController)
799 { 776 {
800 m_layerAnimationController = layerAnimationController.Pass(); 777 m_layerAnimationController = layerAnimationController;
801 if (m_layerAnimationController) { 778 if (m_layerAnimationController) {
802 m_layerAnimationController->setClient(this); 779 m_layerAnimationController->setId(id());
803 m_layerAnimationController->setForceSync(); 780 m_layerAnimationController->setForceSync();
804 } 781 }
805 setNeedsCommit(); 782 setNeedsCommit();
806 } 783 }
807 784
808 scoped_ptr<LayerAnimationController> Layer::releaseLayerAnimationController() 785 scoped_refptr<LayerAnimationController> Layer::releaseLayerAnimationController()
809 { 786 {
810 scoped_ptr<LayerAnimationController> toReturn = m_layerAnimationController.P ass(); 787 scoped_refptr<LayerAnimationController> toReturn = m_layerAnimationControlle r;
811 m_layerAnimationController = LayerAnimationController::create(this); 788 m_layerAnimationController = LayerAnimationController::create(AnimationRegis trar::MainThread);
812 return toReturn.Pass(); 789 m_layerAnimationController->setId(id());
790 m_layerAnimationController->setTransform(toReturn->transform());
791 m_layerAnimationController->setOpacity(toReturn->opacity());
792 return toReturn;
813 } 793 }
814 794
815 bool Layer::hasActiveAnimation() const 795 bool Layer::hasActiveAnimation() const
816 { 796 {
817 return m_layerAnimationController->hasActiveAnimation(); 797 return m_layerAnimationController->hasActiveAnimation();
818 } 798 }
819 799
820 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock Time) 800 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock Time)
821 { 801 {
822 m_layerAnimationController->notifyAnimationStarted(event); 802 m_layerAnimationController->notifyAnimationStarted(event);
(...skipping 18 matching lines...) Expand all
841 { 821 {
842 return 0; 822 return 0;
843 } 823 }
844 824
845 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*)
846 { 826 {
847 // 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.
848 } 828 }
849 829
850 } // namespace cc 830 } // namespace cc
OLDNEW
« cc/animation_registrar.h ('K') | « cc/layer.h ('k') | cc/layer_animation_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698