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.
5 #ifndef CCLayerAnimationController_h
6 #define CCLayerAnimationController_h
8 #include "CCAnimationEvents.h"
10 #include "base/basictypes.h"
11 #include "base/hash_tables.h"
12 #include "cc/own_ptr_vector.h"
13 #include <wtf/OwnPtr.h>
14 #include <wtf/PassOwnPtr.h>
17 class WebTransformationMatrix
;
24 class KeyframeValueList
;
26 class CCLayerAnimationControllerClient
{
28 virtual ~CCLayerAnimationControllerClient() { }
30 virtual int id() const = 0;
31 virtual void setOpacityFromAnimation(float) = 0;
32 virtual float opacity() const = 0;
33 virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix
&) = 0;
34 virtual const WebKit::WebTransformationMatrix
& transform() const = 0;
37 class CCLayerAnimationController
{
39 static PassOwnPtr
<CCLayerAnimationController
> create(CCLayerAnimationControllerClient
*);
41 virtual ~CCLayerAnimationController();
43 // These methods are virtual for testing.
44 virtual void addAnimation(PassOwnPtr
<CCActiveAnimation
>);
45 virtual void pauseAnimation(int animationId
, double timeOffset
);
46 virtual void removeAnimation(int animationId
);
47 virtual void removeAnimation(int animationId
, CCActiveAnimation::TargetProperty
);
48 virtual void suspendAnimations(double monotonicTime
);
49 virtual void resumeAnimations(double monotonicTime
);
51 // Ensures that the list of active animations on the main thread and the impl thread
52 // are kept in sync. This function does not take ownership of the impl thread controller.
53 virtual void pushAnimationUpdatesTo(CCLayerAnimationController
*);
55 void animate(double monotonicTime
, CCAnimationEventsVector
*);
57 // Returns the active animation in the given group, animating the given property, if such an
59 CCActiveAnimation
* getActiveAnimation(int groupId
, CCActiveAnimation::TargetProperty
) const;
61 // Returns the active animation animating the given property that is either running, or is
62 // next to run, if such an animation exists.
63 CCActiveAnimation
* getActiveAnimation(CCActiveAnimation::TargetProperty
) const;
65 // Returns true if there are any animations that have neither finished nor aborted.
66 bool hasActiveAnimation() const;
68 // Returns true if there is an animation currently animating the given property, or
69 // if there is an animation scheduled to animate this property in the future.
70 bool isAnimatingProperty(CCActiveAnimation::TargetProperty
) const;
72 // This is called in response to an animation being started on the impl thread. This
73 // function updates the corresponding main thread animation's start time.
74 void notifyAnimationStarted(const CCAnimationEvent
&);
76 // If a sync is forced, then the next time animation updates are pushed to the impl
77 // thread, all animations will be transferred.
78 void setForceSync() { m_forceSync
= true; }
80 void setClient(CCLayerAnimationControllerClient
*);
83 explicit CCLayerAnimationController(CCLayerAnimationControllerClient
*);
86 typedef base::hash_set
<int> TargetProperties
;
88 void pushNewAnimationsToImplThread(CCLayerAnimationController
*) const;
89 void removeAnimationsCompletedOnMainThread(CCLayerAnimationController
*) const;
90 void pushPropertiesToImplThread(CCLayerAnimationController
*) const;
91 void replaceImplThreadAnimations(CCLayerAnimationController
*) const;
93 void startAnimationsWaitingForNextTick(double monotonicTime
, CCAnimationEventsVector
*);
94 void startAnimationsWaitingForStartTime(double monotonicTime
, CCAnimationEventsVector
*);
95 void startAnimationsWaitingForTargetAvailability(double monotonicTime
, CCAnimationEventsVector
*);
96 void resolveConflicts(double monotonicTime
);
97 void markAnimationsForDeletion(double monotonicTime
, CCAnimationEventsVector
*);
98 void purgeAnimationsMarkedForDeletion();
100 void tickAnimations(double monotonicTime
);
102 // If this is true, we force a sync to the impl thread.
105 CCLayerAnimationControllerClient
* m_client
;
106 OwnPtrVector
<CCActiveAnimation
> m_activeAnimations
;
108 DISALLOW_COPY_AND_ASSIGN(CCLayerAnimationController
);
113 #endif // CCLayerAnimationController_h