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 14 namespace cc { 15 16 class 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 34 class CC_EXPORT FloatKeyframe : public Keyframe { 35 public: 36 static scoped_ptr<FloatKeyframe> Create( 37 double time, 38 float value, 39 scoped_ptr<TimingFunction> timing_function); 40 virtual ~FloatKeyframe(); 41 42 float Value() const; 43 44 scoped_ptr<FloatKeyframe> Clone() const; 45 46 private: 47 FloatKeyframe(double time, 48 float value, 49 scoped_ptr<TimingFunction> timing_function); 50 51 float value_; 52 }; 53 54 class CC_EXPORT TransformKeyframe : public Keyframe { 55 public: 56 static scoped_ptr<TransformKeyframe> Create( 57 double time, 58 const TransformOperations& value, 59 scoped_ptr<TimingFunction> timing_function); 60 virtual ~TransformKeyframe(); 61 62 const TransformOperations& Value() const; 63 64 scoped_ptr<TransformKeyframe> Clone() const; 65 66 private: 67 TransformKeyframe( 68 double time, 69 const TransformOperations& value, 70 scoped_ptr<TimingFunction> timing_function); 71 72 TransformOperations value_; 73 }; 74 75 class CC_EXPORT FilterKeyframe : public Keyframe { 76 public: 77 static scoped_ptr<FilterKeyframe> Create( 78 double time, 79 const FilterOperations& value, 80 scoped_ptr<TimingFunction> timing_function); 81 virtual ~FilterKeyframe(); 82 83 const FilterOperations& Value() const; 84 85 scoped_ptr<FilterKeyframe> Clone() const; 86 87 private: 88 FilterKeyframe( 89 double time, 90 const FilterOperations& value, 91 scoped_ptr<TimingFunction> timing_function); 92 93 FilterOperations value_; 94 }; 95 96 class CC_EXPORT KeyframedFloatAnimationCurve : public FloatAnimationCurve { 97 public: 98 // It is required that the keyframes be sorted by time. 99 static scoped_ptr<KeyframedFloatAnimationCurve> Create(); 100 101 virtual ~KeyframedFloatAnimationCurve(); 102 103 void AddKeyframe(scoped_ptr<FloatKeyframe> keyframe); 104 105 // AnimationCurve implementation 106 virtual double Duration() const OVERRIDE; 107 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE; 108 109 // FloatAnimationCurve implementation 110 virtual float GetValue(double t) const OVERRIDE; 111 112 private: 113 KeyframedFloatAnimationCurve(); 114 115 // Always sorted in order of increasing time. No two keyframes have the 116 // same time. 117 ScopedPtrVector<FloatKeyframe> keyframes_; 118 119 DISALLOW_COPY_AND_ASSIGN(KeyframedFloatAnimationCurve); 120 }; 121 122 class CC_EXPORT KeyframedTransformAnimationCurve 123 : public TransformAnimationCurve { 124 public: 125 // It is required that the keyframes be sorted by time. 126 static scoped_ptr<KeyframedTransformAnimationCurve> Create(); 127 128 virtual ~KeyframedTransformAnimationCurve(); 129 130 void AddKeyframe(scoped_ptr<TransformKeyframe> keyframe); 131 132 // AnimationCurve implementation 133 virtual double Duration() const OVERRIDE; 134 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE; 135 136 // TransformAnimationCurve implementation 137 virtual gfx::Transform GetValue(double t) const OVERRIDE; 138 139 private: 140 KeyframedTransformAnimationCurve(); 141 142 // Always sorted in order of increasing time. No two keyframes have the 143 // same time. 144 ScopedPtrVector<TransformKeyframe> keyframes_; 145 146 DISALLOW_COPY_AND_ASSIGN(KeyframedTransformAnimationCurve); 147 }; 148 149 class CC_EXPORT KeyframedFilterAnimationCurve 150 : public FilterAnimationCurve { 151 public: 152 // It is required that the keyframes be sorted by time. 153 static scoped_ptr<KeyframedFilterAnimationCurve> Create(); 154 155 virtual ~KeyframedFilterAnimationCurve(); 156 157 void AddKeyframe(scoped_ptr<FilterKeyframe> keyframe); 158 159 // AnimationCurve implementation 160 virtual double Duration() const OVERRIDE; 161 virtual scoped_ptr<AnimationCurve> Clone() const OVERRIDE; 162 163 // FilterAnimationCurve implementation 164 virtual FilterOperations GetValue(double t) const OVERRIDE; 165 166 private: 167 KeyframedFilterAnimationCurve(); 168 169 // Always sorted in order of increasing time. No two keyframes have the 170 // same time. 171 ScopedPtrVector<FilterKeyframe> keyframes_; 172 173 DISALLOW_COPY_AND_ASSIGN(KeyframedFilterAnimationCurve); 174 }; 175 176 } // namespace cc 177 178 #endif // CC_ANIMATION_KEYFRAMED_ANIMATION_CURVE_H_ 179