OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 |
| 5 #ifndef CCLayerAnimationController_h |
| 6 #define CCLayerAnimationController_h |
| 7 |
| 8 #include "CCAnimationEvents.h" |
| 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(CCLayerAnimationControl
lerClient*); |
| 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::TargetPrope
rty); |
| 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 imp
l thread |
| 51 // are kept in sync. This function does not take ownership of the impl threa
d 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 prop
erty, if such an |
| 57 // animation exists. |
| 58 CCActiveAnimation* getActiveAnimation(int groupId, CCActiveAnimation::Target
Property) 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) con
st; |
| 63 |
| 64 // Returns true if there are any animations that have neither finished nor a
borted. |
| 65 bool hasActiveAnimation() const; |
| 66 |
| 67 // Returns true if there is an animation currently animating the given prope
rty, 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 thre
ad. 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 t
he 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*) cons
t; |
| 89 void pushPropertiesToImplThread(CCLayerAnimationController*) const; |
| 90 void replaceImplThreadAnimations(CCLayerAnimationController*) const; |
| 91 |
| 92 void startAnimationsWaitingForNextTick(double monotonicTime, CCAnimationEven
tsVector*); |
| 93 void startAnimationsWaitingForStartTime(double monotonicTime, CCAnimationEve
ntsVector*); |
| 94 void startAnimationsWaitingForTargetAvailability(double monotonicTime, CCAni
mationEventsVector*); |
| 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 |
OLD | NEW |