Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3471)

Unified Diff: cc/animation.h

Issue 12517003: cc: Chromify the Animation and LayerAnimationController classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/animation.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/animation.h
diff --git a/cc/animation.h b/cc/animation.h
index 94cb8f243d9fcdc9fb232aa0e650343a412a8965..4c29488487879564e02e3a46a1de89d98a449018 100644
--- a/cc/animation.h
+++ b/cc/animation.h
@@ -17,152 +17,174 @@ class AnimationCurve;
// Specifically, the affected property, the run state (paused, finished, etc.),
// loop count, last pause time, and the total time spent paused.
class CC_EXPORT Animation {
-public:
- // Animations begin in one of the 'waiting' states. Animations waiting for the next tick
- // will start the next time the controller animates. Animations waiting for target
- // availibility will run as soon as their target property is free (and all the animations
- // animating with it are also able to run). Animations waiting for their start time to
- // come have be scheduled to run at a particular point in time. When this time arrives,
- // the controller will move the animations into the Starting state, and then into the
- // Running state. Running animations may toggle between Running and Paused, and may be
- // stopped by moving into either the Aborted or Finished states. A Finished animation
- // was allowed to run to completion, but an Aborted animation was not.
- enum RunState {
- WaitingForNextTick = 0,
- WaitingForTargetAvailability,
- WaitingForStartTime,
- WaitingForDeletion,
- Starting,
- Running,
- Paused,
- Finished,
- Aborted,
- // This sentinel must be last.
- RunStateEnumSize
- };
-
- enum TargetProperty {
- Transform = 0,
- Opacity,
- // This sentinel must be last.
- TargetPropertyEnumSize
- };
-
- static scoped_ptr<Animation> create(scoped_ptr<AnimationCurve>, int animationId, int groupId, TargetProperty);
-
- virtual ~Animation();
-
- int id() const { return m_id; }
- int group() const { return m_group; }
- TargetProperty targetProperty() const { return m_targetProperty; }
-
- RunState runState() const { return m_runState; }
- void setRunState(RunState, double monotonicTime);
-
- // This is the number of times that the animation will play. If this
- // value is zero the animation will not play. If it is negative, then
- // the animation will loop indefinitely.
- int iterations() const { return m_iterations; }
- void setIterations(int n) { m_iterations = n; }
-
- double startTime() const { return m_startTime; }
- void setStartTime(double monotonicTime) { m_startTime = monotonicTime; }
- bool hasSetStartTime() const { return !!m_startTime; }
-
- double timeOffset() const { return m_timeOffset; }
- void setTimeOffset(double monotonicTime) { m_timeOffset = monotonicTime; }
-
- void suspend(double monotonicTime);
- void resume(double monotonicTime);
-
- // If alternatesDirection is true, on odd numbered iterations we reverse the curve.
- bool alternatesDirection() const { return m_alternatesDirection; }
- void setAlternatesDirection(bool alternates) { m_alternatesDirection = alternates; }
-
- bool isFinishedAt(double monotonicTime) const;
- bool isFinished() const { return m_runState == Finished
- || m_runState == Aborted
- || m_runState == WaitingForDeletion; }
-
- AnimationCurve* curve() { return m_curve.get(); }
- const AnimationCurve* curve() const { return m_curve.get(); }
-
- // If this is true, even if the animation is running, it will not be tickable until
- // it is given a start time. This is true for animations running on the main thread.
- bool needsSynchronizedStartTime() const { return m_needsSynchronizedStartTime; }
- void setNeedsSynchronizedStartTime(bool needsSynchronizedStartTime) { m_needsSynchronizedStartTime = needsSynchronizedStartTime; }
-
- // Takes the given absolute time, and using the start time and the number
- // of iterations, returns the relative time in the current iteration.
- double trimTimeToCurrentIteration(double monotonicTime) const;
-
- enum InstanceType {
- ControllingInstance = 0,
- NonControllingInstance
- };
-
- scoped_ptr<Animation> clone(InstanceType) const;
- scoped_ptr<Animation> cloneAndInitialize(InstanceType, RunState initialRunState, double startTime) const;
- bool isControllingInstance() const { return m_isControllingInstance; }
-
- void pushPropertiesTo(Animation*) const;
-
- void setIsImplOnly(bool isImplOnly) { m_isImplOnly = isImplOnly; }
- bool isImplOnly() { return m_isImplOnly; }
-
-private:
- Animation(scoped_ptr<AnimationCurve>, int animationId, int groupId, TargetProperty);
-
- scoped_ptr<AnimationCurve> m_curve;
-
- // IDs are not necessarily unique.
- int m_id;
-
- // Animations that must be run together are called 'grouped' and have the same group id
- // Grouped animations are guaranteed to start at the same time and no other animations
- // may animate any of the group's target properties until all animations in the
- // group have finished animating. Note: an active animation's group id and target
- // property uniquely identify that animation.
- int m_group;
-
- TargetProperty m_targetProperty;
- RunState m_runState;
- int m_iterations;
- double m_startTime;
- bool m_alternatesDirection;
-
- // The time offset effectively pushes the start of the animation back in time. This is
- // used for resuming paused animations -- an animation is added with a non-zero time
- // offset, causing the animation to skip ahead to the desired point in time.
- double m_timeOffset;
-
- bool m_needsSynchronizedStartTime;
-
- // When an animation is suspended, it behaves as if it is paused and it also ignores
- // all run state changes until it is resumed. This is used for testing purposes.
- bool m_suspended;
-
- // These are used in trimTimeToCurrentIteration to account for time
- // spent while paused. This is not included in AnimationState since it
- // there is absolutely no need for clients of this controller to know
- // about these values.
- double m_pauseTime;
- double m_totalPausedTime;
-
- // Animations lead dual lives. An active animation will be conceptually owned by
- // two controllers, one on the impl thread and one on the main. In reality, there
- // will be two separate Animation instances for the same animation. They
- // will have the same group id and the same target property (these two values
- // uniquely identify an animation). The instance on the impl thread is the instance
- // that ultimately controls the values of the animating layer and so we will refer
- // to it as the 'controlling instance'.
- bool m_isControllingInstance;
-
- bool m_isImplOnly;
-
- DISALLOW_COPY_AND_ASSIGN(Animation);
+ public:
+ // Animations begin in one of the 'waiting' states. Animations waiting for the
+ // next tick will start the next time the controller animates. Animations
+ // waiting for target availibility will run as soon as their target property
+ // is free (and all the animations animating with it are also able to run).
+ // Animations waiting for their start time to come have be scheduled to run at
+ // a particular point in time. When this time arrives, the controller will
+ // move the animations into the Starting state, and then into the Running
+ // state. Running animations may toggle between Running and Paused, and may be
+ // stopped by moving into either the Aborted or Finished states. A Finished
+ // animation was allowed to run to completion, but an Aborted animation was
+ // not.
+ enum RunState {
+ WaitingForNextTick = 0,
+ WaitingForTargetAvailability,
+ WaitingForStartTime,
+ WaitingForDeletion,
+ Starting,
+ Running,
+ Paused,
+ Finished,
+ Aborted,
+ // This sentinel must be last.
+ RunStateEnumSize
+ };
+
+ enum TargetProperty {
+ Transform = 0,
+ Opacity,
+ // This sentinel must be last.
+ TargetPropertyEnumSize
+ };
+
+ static scoped_ptr<Animation> Create(scoped_ptr<AnimationCurve> curve,
+ int animation_id,
+ int group_id,
+ TargetProperty target_property);
+
+ virtual ~Animation();
+
+ int id() const { return id_; }
+ int group() const { return group_; }
+ TargetProperty target_property() const { return target_property_; }
+
+ RunState run_state() const { return run_state_; }
+ void SetRunState(RunState run_state, double monotonic_time);
+
+ // This is the number of times that the animation will play. If this
+ // value is zero the animation will not play. If it is negative, then
+ // the animation will loop indefinitely.
+ int iterations() const { return iterations_; }
+ void set_iterations(int n) { iterations_ = n; }
+
+ double start_time() const { return start_time_; }
+ void set_start_time(double monotonic_time) { start_time_ = monotonic_time; }
+ bool has_set_start_time() const { return !!start_time_; }
+
+ double time_offset() const { return time_offset_; }
+ void set_time_offset(double monotonic_time) { time_offset_ = monotonic_time; }
+
+ void Suspend(double monotonic_time);
+ void Resume(double monotonic_time);
+
+ // If alternatesDirection is true, on odd numbered iterations we reverse the
+ // curve.
+ bool alternates_direction() const { return alternates_direction_; }
+ void set_alternates_direction(bool alternates) {
+ alternates_direction_ = alternates;
+ }
+
+ bool IsFinishedAt(double monotonic_time) const;
+ bool is_finished() const {
+ return run_state_ == Finished ||
+ run_state_ == Aborted ||
+ run_state_ == WaitingForDeletion;
+ }
+
+ AnimationCurve* curve() { return curve_.get(); }
+ const AnimationCurve* curve() const { return curve_.get(); }
+
+ // If this is true, even if the animation is running, it will not be tickable
+ // until it is given a start time. This is true for animations running on the
+ // main thread.
+ bool needs_synchronized_start_time() const {
+ return needs_synchronized_start_time_;
+ }
+ void set_needs_synchronized_start_time(bool needs_synchronized_start_time) {
+ needs_synchronized_start_time_ = needs_synchronized_start_time;
+ }
+
+ // Takes the given absolute time, and using the start time and the number
+ // of iterations, returns the relative time in the current iteration.
+ double TrimTimeToCurrentIteration(double monotonic_time) const;
+
+ enum InstanceType {
+ ControllingInstance = 0,
+ NonControllingInstance
+ };
+
+ scoped_ptr<Animation> Clone(InstanceType instance_type) const;
+ scoped_ptr<Animation> CloneAndInitialize(InstanceType instance_type,
+ RunState initial_run_state,
+ double start_time) const;
+ bool is_controlling_instance() const { return is_controlling_instance_; }
+
+ void PushPropertiesTo(Animation* other) const;
+
+ void set_is_impl_only(bool is_impl_only) { is_impl_only_ = is_impl_only; }
+ bool is_impl_only() const { return is_impl_only_; }
+
+ private:
+ Animation(scoped_ptr<AnimationCurve> curve,
+ int animation_id,
+ int group_id,
+ TargetProperty target_property);
+
+ scoped_ptr<AnimationCurve> curve_;
+
+ // IDs are not necessarily unique.
+ int id_;
+
+ // Animations that must be run together are called 'grouped' and have the same
+ // group id. Grouped animations are guaranteed to start at the same time and
+ // no other animations may animate any of the group's target properties until
+ // all animations in the group have finished animating. Note: an active
+ // animation's group id and target property uniquely identify that animation.
+ int group_;
+
+ TargetProperty target_property_;
+ RunState run_state_;
+ int iterations_;
+ double start_time_;
+ bool alternates_direction_;
+
+ // The time offset effectively pushes the start of the animation back in time.
+ // This is used for resuming paused animations -- an animation is added with a
+ // non-zero time offset, causing the animation to skip ahead to the desired
+ // point in time.
+ double time_offset_;
+
+ bool needs_synchronized_start_time_;
+
+ // When an animation is suspended, it behaves as if it is paused and it also
+ // ignores all run state changes until it is resumed. This is used for testing
+ // purposes.
+ bool suspended_;
+
+ // These are used in trimTimeToCurrentIteration to account for time
+ // spent while paused. This is not included in AnimationState since it
+ // there is absolutely no need for clients of this controller to know
+ // about these values.
+ double pause_time_;
+ double total_paused_time_;
+
+ // Animations lead dual lives. An active animation will be conceptually owned
+ // by two controllers, one on the impl thread and one on the main. In reality,
+ // there will be two separate Animation instances for the same animation. They
+ // will have the same group id and the same target property (these two values
+ // uniquely identify an animation). The instance on the impl thread is the
+ // instance that ultimately controls the values of the animating layer and so
+ // we will refer to it as the 'controlling instance'.
+ bool is_controlling_instance_;
+
+ bool is_impl_only_;
+
+ DISALLOW_COPY_AND_ASSIGN(Animation);
};
-} // namespace cc
+} // namespace cc
#endif // CC_ANIMATION_H_
« no previous file with comments | « no previous file | cc/animation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698