| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CC_ACTIVE_ANIMATION_H_ | |
| 6 #define CC_ACTIVE_ANIMATION_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "cc/cc_export.h" | |
| 11 | |
| 12 namespace cc { | |
| 13 | |
| 14 class AnimationCurve; | |
| 15 | |
| 16 // An ActiveAnimation, contains all the state required to play an AnimationCurve
. | |
| 17 // Specifically, the affected property, the run state (paused, finished, etc.), | |
| 18 // loop count, last pause time, and the total time spent paused. | |
| 19 class CC_EXPORT ActiveAnimation { | |
| 20 public: | |
| 21 // Animations begin in one of the 'waiting' states. Animations waiting for t
he next tick | |
| 22 // will start the next time the controller animates. Animations waiting for
target | |
| 23 // availibility will run as soon as their target property is free (and all t
he animations | |
| 24 // animating with it are also able to run). Animations waiting for their sta
rt time to | |
| 25 // come have be scheduled to run at a particular point in time. When this ti
me arrives, | |
| 26 // the controller will move the animations into the Running state. Running a
nimations | |
| 27 // may toggle between Running and Paused, and may be stopped by moving into
either the | |
| 28 // Aborted or Finished states. A Finished animation was allowed to run to co
mpletion, but | |
| 29 // an Aborted animation was not. | |
| 30 enum RunState { | |
| 31 WaitingForNextTick = 0, | |
| 32 WaitingForTargetAvailability, | |
| 33 WaitingForStartTime, | |
| 34 WaitingForDeletion, | |
| 35 Running, | |
| 36 Paused, | |
| 37 Finished, | |
| 38 Aborted, | |
| 39 // This sentinel must be last. | |
| 40 RunStateEnumSize | |
| 41 }; | |
| 42 | |
| 43 enum TargetProperty { | |
| 44 Transform = 0, | |
| 45 Opacity, | |
| 46 // This sentinel must be last. | |
| 47 TargetPropertyEnumSize | |
| 48 }; | |
| 49 | |
| 50 static scoped_ptr<ActiveAnimation> create(scoped_ptr<AnimationCurve>, int an
imationId, int groupId, TargetProperty); | |
| 51 | |
| 52 virtual ~ActiveAnimation(); | |
| 53 | |
| 54 int id() const { return m_id; } | |
| 55 int group() const { return m_group; } | |
| 56 TargetProperty targetProperty() const { return m_targetProperty; } | |
| 57 | |
| 58 RunState runState() const { return m_runState; } | |
| 59 void setRunState(RunState, double monotonicTime); | |
| 60 | |
| 61 // This is the number of times that the animation will play. If this | |
| 62 // value is zero the animation will not play. If it is negative, then | |
| 63 // the animation will loop indefinitely. | |
| 64 int iterations() const { return m_iterations; } | |
| 65 void setIterations(int n) { m_iterations = n; } | |
| 66 | |
| 67 double startTime() const { return m_startTime; } | |
| 68 void setStartTime(double monotonicTime) { m_startTime = monotonicTime; } | |
| 69 bool hasSetStartTime() const { return !!m_startTime; } | |
| 70 | |
| 71 double timeOffset() const { return m_timeOffset; } | |
| 72 void setTimeOffset(double monotonicTime) { m_timeOffset = monotonicTime; } | |
| 73 | |
| 74 void suspend(double monotonicTime); | |
| 75 void resume(double monotonicTime); | |
| 76 | |
| 77 // If alternatesDirection is true, on odd numbered iterations we reverse the
curve. | |
| 78 bool alternatesDirection() const { return m_alternatesDirection; } | |
| 79 void setAlternatesDirection(bool alternates) { m_alternatesDirection = alter
nates; } | |
| 80 | |
| 81 bool isFinishedAt(double monotonicTime) const; | |
| 82 bool isFinished() const { return m_runState == Finished | |
| 83 || m_runState == Aborted | |
| 84 || m_runState == WaitingForDeletion; } | |
| 85 | |
| 86 AnimationCurve* curve() { return m_curve.get(); } | |
| 87 const AnimationCurve* curve() const { return m_curve.get(); } | |
| 88 | |
| 89 // If this is true, even if the animation is running, it will not be tickabl
e until | |
| 90 // it is given a start time. This is true for animations running on the main
thread. | |
| 91 bool needsSynchronizedStartTime() const { return m_needsSynchronizedStartTim
e; } | |
| 92 void setNeedsSynchronizedStartTime(bool needsSynchronizedStartTime) { m_need
sSynchronizedStartTime = needsSynchronizedStartTime; } | |
| 93 | |
| 94 // Takes the given absolute time, and using the start time and the number | |
| 95 // of iterations, returns the relative time in the current iteration. | |
| 96 double trimTimeToCurrentIteration(double monotonicTime) const; | |
| 97 | |
| 98 enum InstanceType { | |
| 99 ControllingInstance = 0, | |
| 100 NonControllingInstance | |
| 101 }; | |
| 102 | |
| 103 scoped_ptr<ActiveAnimation> clone(InstanceType) const; | |
| 104 scoped_ptr<ActiveAnimation> cloneAndInitialize(InstanceType, RunState initia
lRunState, double startTime) const; | |
| 105 bool isControllingInstance() const { return m_isControllingInstance; } | |
| 106 | |
| 107 void pushPropertiesTo(ActiveAnimation*) const; | |
| 108 | |
| 109 private: | |
| 110 ActiveAnimation(scoped_ptr<AnimationCurve>, int animationId, int groupId, Ta
rgetProperty); | |
| 111 | |
| 112 scoped_ptr<AnimationCurve> m_curve; | |
| 113 | |
| 114 // IDs are not necessarily unique. | |
| 115 int m_id; | |
| 116 | |
| 117 // Animations that must be run together are called 'grouped' and have the sa
me group id | |
| 118 // Grouped animations are guaranteed to start at the same time and no other
animations | |
| 119 // may animate any of the group's target properties until all animations in
the | |
| 120 // group have finished animating. Note: an active animation's group id and t
arget | |
| 121 // property uniquely identify that animation. | |
| 122 int m_group; | |
| 123 | |
| 124 TargetProperty m_targetProperty; | |
| 125 RunState m_runState; | |
| 126 int m_iterations; | |
| 127 double m_startTime; | |
| 128 bool m_alternatesDirection; | |
| 129 | |
| 130 // The time offset effectively pushes the start of the animation back in tim
e. This is | |
| 131 // used for resuming paused animations -- an animation is added with a non-z
ero time | |
| 132 // offset, causing the animation to skip ahead to the desired point in time. | |
| 133 double m_timeOffset; | |
| 134 | |
| 135 bool m_needsSynchronizedStartTime; | |
| 136 | |
| 137 // When an animation is suspended, it behaves as if it is paused and it also
ignores | |
| 138 // all run state changes until it is resumed. This is used for testing purpo
ses. | |
| 139 bool m_suspended; | |
| 140 | |
| 141 // These are used in trimTimeToCurrentIteration to account for time | |
| 142 // spent while paused. This is not included in AnimationState since it | |
| 143 // there is absolutely no need for clients of this controller to know | |
| 144 // about these values. | |
| 145 double m_pauseTime; | |
| 146 double m_totalPausedTime; | |
| 147 | |
| 148 // Animations lead dual lives. An active animation will be conceptually owne
d by | |
| 149 // two controllers, one on the impl thread and one on the main. In reality,
there | |
| 150 // will be two separate ActiveAnimation instances for the same animation. Th
ey | |
| 151 // will have the same group id and the same target property (these two value
s | |
| 152 // uniquely identify an animation). The instance on the impl thread is the i
nstance | |
| 153 // that ultimately controls the values of the animating layer and so we will
refer | |
| 154 // to it as the 'controlling instance'. | |
| 155 bool m_isControllingInstance; | |
| 156 | |
| 157 DISALLOW_COPY_AND_ASSIGN(ActiveAnimation); | |
| 158 }; | |
| 159 | |
| 160 } // namespace cc | |
| 161 | |
| 162 #endif // CC_ACTIVE_ANIMATION_H_ | |
| OLD | NEW |