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 CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_
6 #define CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_
8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/timing_function.h"
10 #include "cc/animation/transform_operations.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/base/scoped_ptr_vector.h"
16 class CC_EXPORT Keyframe {
19 const TimingFunction* timing_function() const {
20 return timing_function_.get();
24 Keyframe(double time, scoped_ptr<TimingFunction> timing_function);
29 scoped_ptr<TimingFunction> timing_function_;
31 DISALLOW_COPY_AND_ASSIGN(Keyframe);
34 class CC_EXPORT ColorKeyframe : public Keyframe {
36 static scoped_ptr<ColorKeyframe> Create(
39 scoped_ptr<TimingFunction> timing_function);
40 virtual ~ColorKeyframe();
42 SkColor Value() const;
44 scoped_ptr<ColorKeyframe> Clone() const;
47 ColorKeyframe(double time,
49 scoped_ptr<TimingFunction> timing_function);
54 class CC_EXPORT FloatKeyframe : public Keyframe {
56 static scoped_ptr<FloatKeyframe> Create(
59 scoped_ptr<TimingFunction> timing_function);
60 virtual ~FloatKeyframe();
64 scoped_ptr<FloatKeyframe> Clone() const;
67 FloatKeyframe(double time,
69 scoped_ptr<TimingFunction> timing_function);
74 class CC_EXPORT TransformKeyframe : public Keyframe {
76 static scoped_ptr<TransformKeyframe> Create(
78 const TransformOperations& value,
79 scoped_ptr<TimingFunction> timing_function);
80 virtual ~TransformKeyframe();
82 const TransformOperations& Value() const;
84 scoped_ptr<TransformKeyframe> Clone() const;
89 const TransformOperations& value,
90 scoped_ptr<TimingFunction> timing_function);
92 TransformOperations value_;
95 class CC_EXPORT FilterKeyframe : public Keyframe {
97 static scoped_ptr<FilterKeyframe> Create(
99 const FilterOperations& value,
100 scoped_ptr<TimingFunction> timing_function);
101 virtual ~FilterKeyframe();
103 const FilterOperations& Value() const;
105 scoped_ptr<FilterKeyframe> Clone() const;
110 const FilterOperations& value,
111 scoped_ptr<TimingFunction> timing_function);
113 FilterOperations value_;
116 class CC_EXPORT KeyframedColorAnimationCurve : public ColorAnimationCurve {
118 // It is required that the keyframes be sorted by time.
119 static scoped_ptr<KeyframedColorAnimationCurve> Create();
121 virtual ~KeyframedColorAnimationCurve();
123 void AddKeyframe(scoped_ptr<ColorKeyframe> keyframe);
125 // AnimationCurve implementation
126 virtual double Duration() const OVERRIDE;
127 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
129 // BackgrounColorAnimationCurve implementation
130 virtual SkColor GetValue(double t) const OVERRIDE;
133 KeyframedColorAnimationCurve();
135 // Always sorted in order of increasing time. No two keyframes have the
137 ScopedPtrVector<ColorKeyframe> keyframes_;
139 DISALLOW_COPY_AND_ASSIGN(KeyframedColorAnimationCurve);
142 class CC_EXPORT KeyframedFloatAnimationCurve : public FloatAnimationCurve {
144 // It is required that the keyframes be sorted by time.
145 static scoped_ptr<KeyframedFloatAnimationCurve> Create();
147 virtual ~KeyframedFloatAnimationCurve();
149 void AddKeyframe(scoped_ptr<FloatKeyframe> keyframe);
151 // AnimationCurve implementation
152 virtual double Duration() const OVERRIDE;
153 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
155 // FloatAnimationCurve implementation
156 virtual float GetValue(double t) const OVERRIDE;
159 KeyframedFloatAnimationCurve();
161 // Always sorted in order of increasing time. No two keyframes have the
163 ScopedPtrVector<FloatKeyframe> keyframes_;
165 DISALLOW_COPY_AND_ASSIGN(KeyframedFloatAnimationCurve);
168 class CC_EXPORT KeyframedTransformAnimationCurve
169 : public TransformAnimationCurve {
171 // It is required that the keyframes be sorted by time.
172 static scoped_ptr<KeyframedTransformAnimationCurve> Create();
174 virtual ~KeyframedTransformAnimationCurve();
176 void AddKeyframe(scoped_ptr<TransformKeyframe> keyframe);
178 // AnimationCurve implementation
179 virtual double Duration() const OVERRIDE;
180 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
182 // TransformAnimationCurve implementation
183 virtual gfx::Transform GetValue(double t) const OVERRIDE;
184 virtual bool AnimatedBoundsForBox(const gfx::BoxF& box,
185 gfx::BoxF* bounds) const OVERRIDE;
186 virtual bool AffectsScale() const OVERRIDE;
187 virtual bool IsTranslation() const OVERRIDE;
188 virtual bool MaximumScale(float* max_scale) const OVERRIDE;
191 KeyframedTransformAnimationCurve();
193 // Always sorted in order of increasing time. No two keyframes have the
195 ScopedPtrVector<TransformKeyframe> keyframes_;
197 DISALLOW_COPY_AND_ASSIGN(KeyframedTransformAnimationCurve);
200 class CC_EXPORT KeyframedFilterAnimationCurve
201 : public FilterAnimationCurve {
203 // It is required that the keyframes be sorted by time.
204 static scoped_ptr<KeyframedFilterAnimationCurve> Create();
206 virtual ~KeyframedFilterAnimationCurve();
208 void AddKeyframe(scoped_ptr<FilterKeyframe> keyframe);
210 // AnimationCurve implementation
211 virtual double Duration() const OVERRIDE;
212 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
214 // FilterAnimationCurve implementation
215 virtual FilterOperations GetValue(double t) const OVERRIDE;
216 virtual bool HasFilterThatMovesPixels() const OVERRIDE;
219 KeyframedFilterAnimationCurve();
221 // Always sorted in order of increasing time. No two keyframes have the
223 ScopedPtrVector<FilterKeyframe> keyframes_;
225 DISALLOW_COPY_AND_ASSIGN(KeyframedFilterAnimationCurve);
230 #endif // CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_