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

Side by Side Diff: cc/layer.cc

Issue 11348256: Use an auxiliary list 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
« no previous file with comments | « cc/layer.h ('k') | cc/layer_animation_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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_rasterScale(1.0) 56 , m_rasterScale(1.0)
58 , m_automaticallyComputeRasterScale(false) 57 , m_automaticallyComputeRasterScale(false)
59 , m_boundsContainPageScale(false) 58 , m_boundsContainPageScale(false)
60 , m_layerAnimationDelegate(0) 59 , m_layerAnimationDelegate(0)
61 , m_layerScrollClient(0) 60 , m_layerScrollClient(0)
62 { 61 {
63 if (m_layerId < 0) { 62 if (m_layerId < 0) {
64 s_nextLayerId = 1; 63 s_nextLayerId = 1;
65 m_layerId = s_nextLayerId++; 64 m_layerId = s_nextLayerId++;
66 } 65 }
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
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 // If this layer already has active animations, the host needs to be notifie d. 99 m_layerAnimationController->setAnimationRegistrar(host);
100 if (host && m_layerAnimationController->hasActiveAnimation())
101 host->didAddAnimation();
102 } 100 }
103 101
104 void Layer::setNeedsCommit() 102 void Layer::setNeedsCommit()
105 { 103 {
106 if (m_layerTreeHost) 104 if (m_layerTreeHost)
107 m_layerTreeHost->setNeedsCommit(); 105 m_layerTreeHost->setNeedsCommit();
108 } 106 }
109 107
110 void Layer::setNeedsFullTreeSync() 108 void Layer::setNeedsFullTreeSync()
111 { 109 {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 LayerTreeHost::setNeedsFilterContext(true); 344 LayerTreeHost::setNeedsFilterContext(true);
347 } 345 }
348 346
349 bool Layer::needsDisplay() const 347 bool Layer::needsDisplay() const
350 { 348 {
351 return m_needsDisplay; 349 return m_needsDisplay;
352 } 350 }
353 351
354 void Layer::setOpacity(float opacity) 352 void Layer::setOpacity(float opacity)
355 { 353 {
356 if (m_opacity == opacity) 354 if (!m_layerAnimationController->setOpacity(opacity))
357 return; 355 return;
358 m_opacity = opacity;
359 setNeedsCommit(); 356 setNeedsCommit();
360 } 357 }
361 358
359 float Layer::opacity() const
360 {
361 return m_layerAnimationController->opacity();
362 }
363
362 bool Layer::opacityIsAnimating() const 364 bool Layer::opacityIsAnimating() const
363 { 365 {
364 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac ity); 366 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Opac ity);
365 } 367 }
366 368
367 void Layer::setContentsOpaque(bool opaque) 369 void Layer::setContentsOpaque(bool opaque)
368 { 370 {
369 if (m_contentsOpaque == opaque) 371 if (m_contentsOpaque == opaque)
370 return; 372 return;
371 m_contentsOpaque = opaque; 373 m_contentsOpaque = opaque;
(...skipping 11 matching lines...) Expand all
383 void Layer::setSublayerTransform(const gfx::Transform& sublayerTransform) 385 void Layer::setSublayerTransform(const gfx::Transform& sublayerTransform)
384 { 386 {
385 if (m_sublayerTransform == sublayerTransform) 387 if (m_sublayerTransform == sublayerTransform)
386 return; 388 return;
387 m_sublayerTransform = sublayerTransform; 389 m_sublayerTransform = sublayerTransform;
388 setNeedsCommit(); 390 setNeedsCommit();
389 } 391 }
390 392
391 void Layer::setTransform(const gfx::Transform& transform) 393 void Layer::setTransform(const gfx::Transform& transform)
392 { 394 {
393 if (m_transform == transform) 395 if (!m_layerAnimationController->setTransform(transform))
394 return; 396 return;
395 m_transform = transform;
396 setNeedsCommit(); 397 setNeedsCommit();
397 } 398 }
398 399
400 const gfx::Transform& Layer::transform() const
401 {
402 return m_layerAnimationController->transform();
403 }
404
399 bool Layer::transformIsAnimating() const 405 bool Layer::transformIsAnimating() const
400 { 406 {
401 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran sform); 407 return m_layerAnimationController->isAnimatingProperty(ActiveAnimation::Tran sform);
402 } 408 }
403 409
404 void Layer::setScrollOffset(gfx::Vector2d scrollOffset) 410 void Layer::setScrollOffset(gfx::Vector2d scrollOffset)
405 { 411 {
406 if (m_scrollOffset == scrollOffset) 412 if (m_scrollOffset == scrollOffset)
407 return; 413 return;
408 m_scrollOffset = scrollOffset; 414 m_scrollOffset = scrollOffset;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 // arbitrarily large depending on page content, so we only push the property if it's changed. 577 // arbitrarily large depending on page content, so we only push the property if it's changed.
572 if (m_nonFastScrollableRegionChanged) { 578 if (m_nonFastScrollableRegionChanged) {
573 layer->setNonFastScrollableRegion(m_nonFastScrollableRegion); 579 layer->setNonFastScrollableRegion(m_nonFastScrollableRegion);
574 m_nonFastScrollableRegionChanged = false; 580 m_nonFastScrollableRegionChanged = false;
575 } 581 }
576 if (m_touchEventHandlerRegionChanged) { 582 if (m_touchEventHandlerRegionChanged) {
577 layer->setTouchEventHandlerRegion(m_touchEventHandlerRegion); 583 layer->setTouchEventHandlerRegion(m_touchEventHandlerRegion);
578 m_touchEventHandlerRegionChanged = false; 584 m_touchEventHandlerRegionChanged = false;
579 } 585 }
580 layer->setContentsOpaque(m_contentsOpaque); 586 layer->setContentsOpaque(m_contentsOpaque);
581 if (!opacityIsAnimating())
582 layer->setOpacity(m_opacity);
583 layer->setPosition(m_position); 587 layer->setPosition(m_position);
584 layer->setIsContainerForFixedPositionLayers(m_isContainerForFixedPositionLay ers); 588 layer->setIsContainerForFixedPositionLayers(m_isContainerForFixedPositionLay ers);
585 layer->setFixedToContainerLayer(m_fixedToContainerLayer); 589 layer->setFixedToContainerLayer(m_fixedToContainerLayer);
586 layer->setPreserves3D(preserves3D()); 590 layer->setPreserves3D(preserves3D());
587 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility); 591 layer->setUseParentBackfaceVisibility(m_useParentBackfaceVisibility);
588 layer->setScrollOffset(m_scrollOffset); 592 layer->setScrollOffset(m_scrollOffset);
589 layer->setMaxScrollOffset(m_maxScrollOffset); 593 layer->setMaxScrollOffset(m_maxScrollOffset);
590 layer->setSublayerTransform(m_sublayerTransform); 594 layer->setSublayerTransform(m_sublayerTransform);
591 if (!transformIsAnimating())
592 layer->setTransform(m_transform);
593 595
594 // If the main thread commits multiple times before the impl thread actually draws, then damage tracking 596 // If the main thread commits multiple times before the impl thread actually draws, then damage tracking
595 // will become incorrect if we simply clobber the updateRect here. The Layer Impl's updateRect needs to 597 // will become incorrect if we simply clobber the updateRect here. The Layer Impl's updateRect needs to
596 // accumulate (i.e. union) any update changes that have occurred on the main thread. 598 // accumulate (i.e. union) any update changes that have occurred on the main thread.
597 m_updateRect.Union(layer->updateRect()); 599 m_updateRect.Union(layer->updateRect());
598 layer->setUpdateRect(m_updateRect); 600 layer->setUpdateRect(m_updateRect);
599 601
600 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta()); 602 layer->setScrollDelta(layer->scrollDelta() - layer->sentScrollDelta());
601 layer->setSentScrollDelta(gfx::Vector2d()); 603 layer->setSentScrollDelta(gfx::Vector2d());
602 604
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 return result; 708 return result;
707 } 709 }
708 return result; 710 return result;
709 } 711 }
710 712
711 int Layer::id() const 713 int Layer::id() const
712 { 714 {
713 return m_layerId; 715 return m_layerId;
714 } 716 }
715 717
716 float Layer::opacity() const
717 {
718 return m_opacity;
719 }
720
721 void Layer::setOpacityFromAnimation(float opacity)
722 {
723 // This is called due to an ongoing accelerated animation. Since this animat ion is
724 // also being run on the impl thread, there is no need to request a commit t o push
725 // this value over, so set the value directly rather than calling setOpacity .
726 m_opacity = opacity;
727 }
728
729 const gfx::Transform& Layer::transform() const
730 {
731 return m_transform;
732 }
733
734 void Layer::setTransformFromAnimation(const gfx::Transform& transform)
735 {
736 // This is called due to an ongoing accelerated animation. Since this animat ion is
737 // also being run on the impl thread, there is no need to request a commit t o push
738 // this value over, so set this value directly rather than calling setTransf orm.
739 m_transform = transform;
740 }
741
742 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation) 718 bool Layer::addAnimation(scoped_ptr <ActiveAnimation> animation)
743 { 719 {
744 // WebCore currently assumes that accelerated animations will start soon 720 // WebCore currently assumes that accelerated animations will start soon
745 // after the animation is added. However we cannot guarantee that if we do 721 // after the animation is added. However we cannot guarantee that if we do
746 // not have a layerTreeHost that will setNeedsCommit(). 722 // not have a layerTreeHost that will setNeedsCommit().
747 // Unfortunately, the fix below to guarantee correctness causes performance 723 // Unfortunately, the fix below to guarantee correctness causes performance
748 // regressions on Android, since Android has shipped for a long time 724 // regressions on Android, since Android has shipped for a long time
749 // with all animations accelerated. For this reason, we will live with 725 // with all animations accelerated. For this reason, we will live with
750 // this bug only on Android until the bug is fixed. 726 // this bug only on Android until the bug is fixed.
751 // http://crbug.com/129683 727 // http://crbug.com/129683
752 #if !defined(OS_ANDROID) 728 #if !defined(OS_ANDROID)
753 if (!m_layerTreeHost) 729 if (!m_layerTreeHost)
754 return false; 730 return false;
755 731
756 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) 732 if (!m_layerTreeHost->settings().acceleratedAnimationEnabled)
757 return false; 733 return false;
758 #endif 734 #endif
759 735
760 m_layerAnimationController->addAnimation(animation.Pass()); 736 m_layerAnimationController->addAnimation(animation.Pass());
761 if (m_layerTreeHost) {
762 m_layerTreeHost->didAddAnimation();
763 setNeedsCommit(); 737 setNeedsCommit();
764 }
765 return true; 738 return true;
766 } 739 }
767 740
768 void Layer::pauseAnimation(int animationId, double timeOffset) 741 void Layer::pauseAnimation(int animationId, double timeOffset)
769 { 742 {
770 m_layerAnimationController->pauseAnimation(animationId, timeOffset); 743 m_layerAnimationController->pauseAnimation(animationId, timeOffset);
771 setNeedsCommit(); 744 setNeedsCommit();
772 } 745 }
773 746
774 void Layer::removeAnimation(int animationId) 747 void Layer::removeAnimation(int animationId)
775 { 748 {
776 m_layerAnimationController->removeAnimation(animationId); 749 m_layerAnimationController->removeAnimation(animationId);
777 setNeedsCommit(); 750 setNeedsCommit();
778 } 751 }
779 752
780 void Layer::suspendAnimations(double monotonicTime) 753 void Layer::suspendAnimations(double monotonicTime)
781 { 754 {
782 m_layerAnimationController->suspendAnimations(monotonicTime); 755 m_layerAnimationController->suspendAnimations(monotonicTime);
783 setNeedsCommit(); 756 setNeedsCommit();
784 } 757 }
785 758
786 void Layer::resumeAnimations(double monotonicTime) 759 void Layer::resumeAnimations(double monotonicTime)
787 { 760 {
788 m_layerAnimationController->resumeAnimations(monotonicTime); 761 m_layerAnimationController->resumeAnimations(monotonicTime);
789 setNeedsCommit(); 762 setNeedsCommit();
790 } 763 }
791 764
792 void Layer::setLayerAnimationController(scoped_ptr<LayerAnimationController> lay erAnimationController) 765 void Layer::setLayerAnimationController(scoped_refptr<LayerAnimationController> layerAnimationController)
793 { 766 {
794 m_layerAnimationController = layerAnimationController.Pass(); 767 m_layerAnimationController = layerAnimationController;
795 if (m_layerAnimationController) { 768 if (m_layerAnimationController) {
796 m_layerAnimationController->setClient(this); 769 m_layerAnimationController->setId(id());
797 m_layerAnimationController->setForceSync(); 770 m_layerAnimationController->setForceSync();
798 } 771 }
799 setNeedsCommit(); 772 setNeedsCommit();
800 } 773 }
801 774
802 scoped_ptr<LayerAnimationController> Layer::releaseLayerAnimationController() 775 scoped_refptr<LayerAnimationController> Layer::releaseLayerAnimationController()
803 { 776 {
804 scoped_ptr<LayerAnimationController> toReturn = m_layerAnimationController.P ass(); 777 scoped_refptr<LayerAnimationController> toReturn = m_layerAnimationControlle r;
805 m_layerAnimationController = LayerAnimationController::create(this); 778 m_layerAnimationController = LayerAnimationController::create();
806 return toReturn.Pass(); 779 m_layerAnimationController->setId(id());
780 m_layerAnimationController->setTransform(toReturn->transform());
781 m_layerAnimationController->setOpacity(toReturn->opacity());
782 return toReturn;
807 } 783 }
808 784
809 bool Layer::hasActiveAnimation() const 785 bool Layer::hasActiveAnimation() const
810 { 786 {
811 return m_layerAnimationController->hasActiveAnimation(); 787 return m_layerAnimationController->hasActiveAnimation();
812 } 788 }
813 789
814 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock Time) 790 void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClock Time)
815 { 791 {
816 m_layerAnimationController->notifyAnimationStarted(event); 792 m_layerAnimationController->notifyAnimationStarted(event);
(...skipping 18 matching lines...) Expand all
835 { 811 {
836 return 0; 812 return 0;
837 } 813 }
838 814
839 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped _refptr<Layer> >::iterator, void*) 815 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped _refptr<Layer> >::iterator, void*)
840 { 816 {
841 // Currently we don't use z-order to decide what to paint, so there's no nee d to actually sort Layers. 817 // Currently we don't use z-order to decide what to paint, so there's no nee d to actually sort Layers.
842 } 818 }
843 819
844 } // namespace cc 820 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layer.h ('k') | cc/layer_animation_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698