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_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_
6#define CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_
7
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"
13
14namespace cc {
15
16class CC_EXPORT Keyframe {
17 public:
18  double Time() const;
19  const TimingFunction* timing_function() const {
20    return timing_function_.get();
21  }
22
23 protected:
24  Keyframe(double time, scoped_ptr<TimingFunction> timing_function);
25  virtual ~Keyframe();
26
27 private:
28  double time_;
29  scoped_ptr<TimingFunction> timing_function_;
30
31  DISALLOW_COPY_AND_ASSIGN(Keyframe);
32};
33
34class CC_EXPORT ColorKeyframe : public Keyframe {
35 public:
36  static scoped_ptr<ColorKeyframe> Create(
37      double time,
38      SkColor value,
39      scoped_ptr<TimingFunction> timing_function);
40  virtual ~ColorKeyframe();
41
42  SkColor Value() const;
43
44  scoped_ptr<ColorKeyframe> Clone() const;
45
46 private:
47  ColorKeyframe(double time,
48                SkColor value,
49                scoped_ptr<TimingFunction> timing_function);
50
51  SkColor value_;
52};
53
54class CC_EXPORT FloatKeyframe : public Keyframe {
55 public:
56  static scoped_ptr<FloatKeyframe> Create(
57      double time,
58      float value,
59      scoped_ptr<TimingFunction> timing_function);
60  virtual ~FloatKeyframe();
61
62  float Value() const;
63
64  scoped_ptr<FloatKeyframe> Clone() const;
65
66 private:
67  FloatKeyframe(double time,
68                float value,
69                scoped_ptr<TimingFunction> timing_function);
70
71  float value_;
72};
73
74class CC_EXPORT TransformKeyframe : public Keyframe {
75 public:
76  static scoped_ptr<TransformKeyframe> Create(
77      double time,
78      const TransformOperations& value,
79      scoped_ptr<TimingFunction> timing_function);
80  virtual ~TransformKeyframe();
81
82  const TransformOperations& Value() const;
83
84  scoped_ptr<TransformKeyframe> Clone() const;
85
86 private:
87  TransformKeyframe(
88      double time,
89      const TransformOperations& value,
90      scoped_ptr<TimingFunction> timing_function);
91
92  TransformOperations value_;
93};
94
95class CC_EXPORT FilterKeyframe : public Keyframe {
96 public:
97  static scoped_ptr<FilterKeyframe> Create(
98      double time,
99      const FilterOperations& value,
100      scoped_ptr<TimingFunction> timing_function);
101  virtual ~FilterKeyframe();
102
103  const FilterOperations& Value() const;
104
105  scoped_ptr<FilterKeyframe> Clone() const;
106
107 private:
108  FilterKeyframe(
109      double time,
110      const FilterOperations& value,
111      scoped_ptr<TimingFunction> timing_function);
112
113  FilterOperations value_;
114};
115
116class CC_EXPORT KeyframedColorAnimationCurve : public ColorAnimationCurve {
117 public:
118  // It is required that the keyframes be sorted by time.
119  static scoped_ptr<KeyframedColorAnimationCurve> Create();
120
121  virtual ~KeyframedColorAnimationCurve();
122
123  void AddKeyframe(scoped_ptr<ColorKeyframe> keyframe);
124
125  // AnimationCurve implementation
126  virtual double Duration() const OVERRIDE;
127  virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
128
129  // BackgrounColorAnimationCurve implementation
130  virtual SkColor GetValue(double t) const OVERRIDE;
131
132 private:
133  KeyframedColorAnimationCurve();
134
135  // Always sorted in order of increasing time. No two keyframes have the
136  // same time.
137  ScopedPtrVector<ColorKeyframe> keyframes_;
138
139  DISALLOW_COPY_AND_ASSIGN(KeyframedColorAnimationCurve);
140};
141
142class CC_EXPORT KeyframedFloatAnimationCurve : public FloatAnimationCurve {
143 public:
144  // It is required that the keyframes be sorted by time.
145  static scoped_ptr<KeyframedFloatAnimationCurve> Create();
146
147  virtual ~KeyframedFloatAnimationCurve();
148
149  void AddKeyframe(scoped_ptr<FloatKeyframe> keyframe);
150
151  // AnimationCurve implementation
152  virtual double Duration() const OVERRIDE;
153  virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
154
155  // FloatAnimationCurve implementation
156  virtual float GetValue(double t) const OVERRIDE;
157
158 private:
159  KeyframedFloatAnimationCurve();
160
161  // Always sorted in order of increasing time. No two keyframes have the
162  // same time.
163  ScopedPtrVector<FloatKeyframe> keyframes_;
164
165  DISALLOW_COPY_AND_ASSIGN(KeyframedFloatAnimationCurve);
166};
167
168class CC_EXPORT KeyframedTransformAnimationCurve
169    : public TransformAnimationCurve {
170 public:
171  // It is required that the keyframes be sorted by time.
172  static scoped_ptr<KeyframedTransformAnimationCurve> Create();
173
174  virtual ~KeyframedTransformAnimationCurve();
175
176  void AddKeyframe(scoped_ptr<TransformKeyframe> keyframe);
177
178  // AnimationCurve implementation
179  virtual double Duration() const OVERRIDE;
180  virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
181
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 MaximumTargetScale(bool forward_direction,
189                                  float* max_scale) const OVERRIDE;
190
191 private:
192  KeyframedTransformAnimationCurve();
193
194  // Always sorted in order of increasing time. No two keyframes have the
195  // same time.
196  ScopedPtrVector<TransformKeyframe> keyframes_;
197
198  DISALLOW_COPY_AND_ASSIGN(KeyframedTransformAnimationCurve);
199};
200
201class CC_EXPORT KeyframedFilterAnimationCurve
202    : public FilterAnimationCurve {
203 public:
204  // It is required that the keyframes be sorted by time.
205  static scoped_ptr<KeyframedFilterAnimationCurve> Create();
206
207  virtual ~KeyframedFilterAnimationCurve();
208
209  void AddKeyframe(scoped_ptr<FilterKeyframe> keyframe);
210
211  // AnimationCurve implementation
212  virtual double Duration() const OVERRIDE;
213  virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE;
214
215  // FilterAnimationCurve implementation
216  virtual FilterOperations GetValue(double t) const OVERRIDE;
217  virtual bool HasFilterThatMovesPixels() const OVERRIDE;
218
219 private:
220  KeyframedFilterAnimationCurve();
221
222  // Always sorted in order of increasing time. No two keyframes have the
223  // same time.
224  ScopedPtrVector<FilterKeyframe> keyframes_;
225
226  DISALLOW_COPY_AND_ASSIGN(KeyframedFilterAnimationCurve);
227};
228
229}  // namespace cc
230
231#endif  // CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_
232