[email protected] | 0fb2500 | 2012-10-12 07:20:02 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 4 | |
| 5 | #ifndef CCLayerAnimationController_h |
| 6 | #define CCLayerAnimationController_h |
| 7 | |
[email protected] | 1c0088f | 2012-10-17 00:29:30 | [diff] [blame] | 8 | #include "CCAnimationEvents.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 9 | |
| 10 | #include "base/basictypes.h" |
| 11 | #include "base/hash_tables.h" |
| 12 | #include "base/memory/scoped_ptr.h" |
| 13 | #include "cc/scoped_ptr_vector.h" |
| 14 | |
| 15 | namespace WebKit { |
| 16 | class WebTransformationMatrix; |
| 17 | } |
| 18 | |
| 19 | namespace cc { |
| 20 | |
| 21 | class Animation; |
| 22 | class IntSize; |
| 23 | class KeyframeValueList; |
| 24 | |
| 25 | class CCLayerAnimationControllerClient { |
| 26 | public: |
| 27 | virtual ~CCLayerAnimationControllerClient() { } |
| 28 | |
| 29 | virtual int id() const = 0; |
| 30 | virtual void setOpacityFromAnimation(float) = 0; |
| 31 | virtual float opacity() const = 0; |
| 32 | virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix&) = 0; |
| 33 | virtual const WebKit::WebTransformationMatrix& transform() const = 0; |
| 34 | }; |
| 35 | |
| 36 | class CCLayerAnimationController { |
| 37 | public: |
| 38 | static scoped_ptr<CCLayerAnimationController> create(CCLayerAnimationControllerClient*); |
| 39 | |
| 40 | virtual ~CCLayerAnimationController(); |
| 41 | |
| 42 | // These methods are virtual for testing. |
| 43 | virtual void addAnimation(scoped_ptr<CCActiveAnimation>); |
| 44 | virtual void pauseAnimation(int animationId, double timeOffset); |
| 45 | virtual void removeAnimation(int animationId); |
| 46 | virtual void removeAnimation(int animationId, CCActiveAnimation::TargetProperty); |
| 47 | virtual void suspendAnimations(double monotonicTime); |
| 48 | virtual void resumeAnimations(double monotonicTime); |
| 49 | |
| 50 | // Ensures that the list of active animations on the main thread and the impl thread |
| 51 | // are kept in sync. This function does not take ownership of the impl thread controller. |
| 52 | virtual void pushAnimationUpdatesTo(CCLayerAnimationController*); |
| 53 | |
| 54 | void animate(double monotonicTime, CCAnimationEventsVector*); |
| 55 | |
| 56 | // Returns the active animation in the given group, animating the given property, if such an |
| 57 | // animation exists. |
| 58 | CCActiveAnimation* getActiveAnimation(int groupId, CCActiveAnimation::TargetProperty) const; |
| 59 | |
| 60 | // Returns the active animation animating the given property that is either running, or is |
| 61 | // next to run, if such an animation exists. |
| 62 | CCActiveAnimation* getActiveAnimation(CCActiveAnimation::TargetProperty) const; |
| 63 | |
| 64 | // Returns true if there are any animations that have neither finished nor aborted. |
| 65 | bool hasActiveAnimation() const; |
| 66 | |
| 67 | // Returns true if there is an animation currently animating the given property, or |
| 68 | // if there is an animation scheduled to animate this property in the future. |
| 69 | bool isAnimatingProperty(CCActiveAnimation::TargetProperty) const; |
| 70 | |
| 71 | // This is called in response to an animation being started on the impl thread. This |
| 72 | // function updates the corresponding main thread animation's start time. |
| 73 | void notifyAnimationStarted(const CCAnimationEvent&); |
| 74 | |
| 75 | // If a sync is forced, then the next time animation updates are pushed to the impl |
| 76 | // thread, all animations will be transferred. |
| 77 | void setForceSync() { m_forceSync = true; } |
| 78 | |
| 79 | void setClient(CCLayerAnimationControllerClient*); |
| 80 | |
| 81 | protected: |
| 82 | explicit CCLayerAnimationController(CCLayerAnimationControllerClient*); |
| 83 | |
| 84 | private: |
| 85 | typedef base::hash_set<int> TargetProperties; |
| 86 | |
| 87 | void pushNewAnimationsToImplThread(CCLayerAnimationController*) const; |
| 88 | void removeAnimationsCompletedOnMainThread(CCLayerAnimationController*) const; |
| 89 | void pushPropertiesToImplThread(CCLayerAnimationController*) const; |
| 90 | void replaceImplThreadAnimations(CCLayerAnimationController*) const; |
| 91 | |
| 92 | void startAnimationsWaitingForNextTick(double monotonicTime, CCAnimationEventsVector*); |
| 93 | void startAnimationsWaitingForStartTime(double monotonicTime, CCAnimationEventsVector*); |
| 94 | void startAnimationsWaitingForTargetAvailability(double monotonicTime, CCAnimationEventsVector*); |
| 95 | void resolveConflicts(double monotonicTime); |
| 96 | void markAnimationsForDeletion(double monotonicTime, CCAnimationEventsVector*); |
| 97 | void purgeAnimationsMarkedForDeletion(); |
| 98 | |
| 99 | void tickAnimations(double monotonicTime); |
| 100 | |
| 101 | // If this is true, we force a sync to the impl thread. |
| 102 | bool m_forceSync; |
| 103 | |
| 104 | CCLayerAnimationControllerClient* m_client; |
| 105 | ScopedPtrVector<CCActiveAnimation> m_activeAnimations; |
| 106 | |
| 107 | DISALLOW_COPY_AND_ASSIGN(CCLayerAnimationController); |
| 108 | }; |
| 109 | |
| 110 | } // namespace cc |
| 111 | |
| 112 | #endif // CCLayerAnimationController_h |