blob: 2fdb91c611aa3f65e1fbe7dbce85e46d9e22e4fa [file] [log] [blame]
[email protected]0fb25002012-10-12 07:20:021// 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]cd57cc5a2012-10-12 22:43:414
5#ifndef CCLayerAnimationController_h
6#define CCLayerAnimationController_h
7
[email protected]1c0088f2012-10-17 00:29:308#include "CCAnimationEvents.h"
[email protected]cd57cc5a2012-10-12 22:43:419
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
15namespace WebKit {
16class WebTransformationMatrix;
17}
18
19namespace cc {
20
21class Animation;
22class IntSize;
23class KeyframeValueList;
24
25class CCLayerAnimationControllerClient {
26public:
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
36class CCLayerAnimationController {
37public:
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
81protected:
82 explicit CCLayerAnimationController(CCLayerAnimationControllerClient*);
83
84private:
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