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 "base/time/time.h"
9 #include "cc/animation/animation_curve.h"
10 #include "cc/animation/timing_function.h"
11 #include "cc/animation/transform_operations.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/base/scoped_ptr_vector.h"
17 class CC_EXPORT Keyframe
{
19 base::TimeDelta
Time() const;
20 const TimingFunction
* timing_function() const {
21 return timing_function_
.get();
25 Keyframe(base::TimeDelta time
, scoped_ptr
<TimingFunction
> timing_function
);
29 base::TimeDelta time_
;
30 scoped_ptr
<TimingFunction
> timing_function_
;
32 DISALLOW_COPY_AND_ASSIGN(Keyframe
);
35 class CC_EXPORT ColorKeyframe
: public Keyframe
{
37 static scoped_ptr
<ColorKeyframe
> Create(
40 scoped_ptr
<TimingFunction
> timing_function
);
41 ~ColorKeyframe() override
;
43 SkColor
Value() const;
45 scoped_ptr
<ColorKeyframe
> Clone() const;
48 ColorKeyframe(base::TimeDelta time
,
50 scoped_ptr
<TimingFunction
> timing_function
);
55 class CC_EXPORT FloatKeyframe
: public Keyframe
{
57 static scoped_ptr
<FloatKeyframe
> Create(
60 scoped_ptr
<TimingFunction
> timing_function
);
61 ~FloatKeyframe() override
;
65 scoped_ptr
<FloatKeyframe
> Clone() const;
68 FloatKeyframe(base::TimeDelta time
,
70 scoped_ptr
<TimingFunction
> timing_function
);
75 class CC_EXPORT TransformKeyframe
: public Keyframe
{
77 static scoped_ptr
<TransformKeyframe
> Create(
79 const TransformOperations
& value
,
80 scoped_ptr
<TimingFunction
> timing_function
);
81 ~TransformKeyframe() override
;
83 const TransformOperations
& Value() const;
85 scoped_ptr
<TransformKeyframe
> Clone() const;
88 TransformKeyframe(base::TimeDelta time
,
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 ~FilterKeyframe() override
;
103 const FilterOperations
& Value() const;
105 scoped_ptr
<FilterKeyframe
> Clone() const;
108 FilterKeyframe(base::TimeDelta time
,
109 const FilterOperations
& value
,
110 scoped_ptr
<TimingFunction
> timing_function
);
112 FilterOperations value_
;
115 class CC_EXPORT KeyframedColorAnimationCurve
: public ColorAnimationCurve
{
117 // It is required that the keyframes be sorted by time.
118 static scoped_ptr
<KeyframedColorAnimationCurve
> Create();
120 ~KeyframedColorAnimationCurve() override
;
122 void AddKeyframe(scoped_ptr
<ColorKeyframe
> keyframe
);
123 void SetTimingFunction(scoped_ptr
<TimingFunction
> timing_function
) {
124 timing_function_
= timing_function
.Pass();
127 // AnimationCurve implementation
128 base::TimeDelta
Duration() const override
;
129 scoped_ptr
<AnimationCurve
> Clone() const override
;
131 // BackgrounColorAnimationCurve implementation
132 SkColor
GetValue(base::TimeDelta t
) const override
;
135 KeyframedColorAnimationCurve();
137 // Always sorted in order of increasing time. No two keyframes have the
139 ScopedPtrVector
<ColorKeyframe
> keyframes_
;
140 scoped_ptr
<TimingFunction
> timing_function_
;
142 DISALLOW_COPY_AND_ASSIGN(KeyframedColorAnimationCurve
);
145 class CC_EXPORT KeyframedFloatAnimationCurve
: public FloatAnimationCurve
{
147 // It is required that the keyframes be sorted by time.
148 static scoped_ptr
<KeyframedFloatAnimationCurve
> Create();
150 ~KeyframedFloatAnimationCurve() override
;
152 void AddKeyframe(scoped_ptr
<FloatKeyframe
> keyframe
);
153 void SetTimingFunction(scoped_ptr
<TimingFunction
> timing_function
) {
154 timing_function_
= timing_function
.Pass();
157 // AnimationCurve implementation
158 base::TimeDelta
Duration() const override
;
159 scoped_ptr
<AnimationCurve
> Clone() const override
;
161 // FloatAnimationCurve implementation
162 float GetValue(base::TimeDelta t
) const override
;
165 KeyframedFloatAnimationCurve();
167 // Always sorted in order of increasing time. No two keyframes have the
169 ScopedPtrVector
<FloatKeyframe
> keyframes_
;
170 scoped_ptr
<TimingFunction
> timing_function_
;
172 DISALLOW_COPY_AND_ASSIGN(KeyframedFloatAnimationCurve
);
175 class CC_EXPORT KeyframedTransformAnimationCurve
176 : public TransformAnimationCurve
{
178 // It is required that the keyframes be sorted by time.
179 static scoped_ptr
<KeyframedTransformAnimationCurve
> Create();
181 ~KeyframedTransformAnimationCurve() override
;
183 void AddKeyframe(scoped_ptr
<TransformKeyframe
> keyframe
);
184 void SetTimingFunction(scoped_ptr
<TimingFunction
> timing_function
) {
185 timing_function_
= timing_function
.Pass();
188 // AnimationCurve implementation
189 base::TimeDelta
Duration() const override
;
190 scoped_ptr
<AnimationCurve
> Clone() const override
;
192 // TransformAnimationCurve implementation
193 gfx::Transform
GetValue(base::TimeDelta t
) const override
;
194 bool AnimatedBoundsForBox(const gfx::BoxF
& box
,
195 gfx::BoxF
* bounds
) const override
;
196 bool AffectsScale() const override
;
197 bool PreservesAxisAlignment() const override
;
198 bool IsTranslation() const override
;
199 bool AnimationStartScale(bool forward_direction
,
200 float* start_scale
) const override
;
201 bool MaximumTargetScale(bool forward_direction
,
202 float* max_scale
) const override
;
205 KeyframedTransformAnimationCurve();
207 // Always sorted in order of increasing time. No two keyframes have the
209 ScopedPtrVector
<TransformKeyframe
> keyframes_
;
210 scoped_ptr
<TimingFunction
> timing_function_
;
212 DISALLOW_COPY_AND_ASSIGN(KeyframedTransformAnimationCurve
);
215 class CC_EXPORT KeyframedFilterAnimationCurve
216 : public FilterAnimationCurve
{
218 // It is required that the keyframes be sorted by time.
219 static scoped_ptr
<KeyframedFilterAnimationCurve
> Create();
221 ~KeyframedFilterAnimationCurve() override
;
223 void AddKeyframe(scoped_ptr
<FilterKeyframe
> keyframe
);
224 void SetTimingFunction(scoped_ptr
<TimingFunction
> timing_function
) {
225 timing_function_
= timing_function
.Pass();
228 // AnimationCurve implementation
229 base::TimeDelta
Duration() const override
;
230 scoped_ptr
<AnimationCurve
> Clone() const override
;
232 // FilterAnimationCurve implementation
233 FilterOperations
GetValue(base::TimeDelta t
) const override
;
234 bool HasFilterThatMovesPixels() const override
;
237 KeyframedFilterAnimationCurve();
239 // Always sorted in order of increasing time. No two keyframes have the
241 ScopedPtrVector
<FilterKeyframe
> keyframes_
;
242 scoped_ptr
<TimingFunction
> timing_function_
;
244 DISALLOW_COPY_AND_ASSIGN(KeyframedFilterAnimationCurve
);
249 #endif // CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_