OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "cc/animation/keyframed_animation_curve.h" | 7 #include "cc/animation/keyframed_animation_curve.h" |
8 #include "ui/gfx/animation/tween.h" | 8 #include "ui/gfx/animation/tween.h" |
9 #include "ui/gfx/box_f.h" | 9 #include "ui/gfx/box_f.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 float GetProgress(double t, size_t i, const Keyframes& keyframes) { | 33 float GetProgress(double t, size_t i, const Keyframes& keyframes) { |
34 float progress = | 34 float progress = |
35 static_cast<float>((t - keyframes[i]->Time()) / | 35 static_cast<float>((t - keyframes[i]->Time()) / |
36 (keyframes[i + 1]->Time() - keyframes[i]->Time())); | 36 (keyframes[i + 1]->Time() - keyframes[i]->Time())); |
37 | 37 |
38 if (keyframes[i]->timing_function()) | 38 if (keyframes[i]->timing_function()) |
39 progress = keyframes[i]->timing_function()->GetValue(progress); | 39 progress = keyframes[i]->timing_function()->GetValue(progress); |
40 return progress; | 40 return progress; |
41 } | 41 } |
42 | 42 |
43 scoped_ptr<TimingFunction> CloneTimingFunction( | |
44 const TimingFunction* timing_function) { | |
45 DCHECK(timing_function); | |
46 scoped_ptr<AnimationCurve> curve(timing_function->Clone()); | |
47 return scoped_ptr<TimingFunction>( | |
48 static_cast<TimingFunction*>(curve.release())); | |
49 } | |
50 | |
51 } // namespace | 43 } // namespace |
52 | 44 |
53 Keyframe::Keyframe(double time, scoped_ptr<TimingFunction> timing_function) | 45 Keyframe::Keyframe(double time, scoped_ptr<TimingFunction> timing_function) |
54 : time_(time), | 46 : time_(time), |
55 timing_function_(timing_function.Pass()) {} | 47 timing_function_(timing_function.Pass()) {} |
56 | 48 |
57 Keyframe::~Keyframe() {} | 49 Keyframe::~Keyframe() {} |
58 | 50 |
59 double Keyframe::Time() const { | 51 double Keyframe::Time() const { |
60 return time_; | 52 return time_; |
(...skipping 13 matching lines...) Expand all Loading... |
74 : Keyframe(time, timing_function.Pass()), | 66 : Keyframe(time, timing_function.Pass()), |
75 value_(value) {} | 67 value_(value) {} |
76 | 68 |
77 ColorKeyframe::~ColorKeyframe() {} | 69 ColorKeyframe::~ColorKeyframe() {} |
78 | 70 |
79 SkColor ColorKeyframe::Value() const { return value_; } | 71 SkColor ColorKeyframe::Value() const { return value_; } |
80 | 72 |
81 scoped_ptr<ColorKeyframe> ColorKeyframe::Clone() const { | 73 scoped_ptr<ColorKeyframe> ColorKeyframe::Clone() const { |
82 scoped_ptr<TimingFunction> func; | 74 scoped_ptr<TimingFunction> func; |
83 if (timing_function()) | 75 if (timing_function()) |
84 func = CloneTimingFunction(timing_function()); | 76 func = timing_function()->Clone(); |
85 return ColorKeyframe::Create(Time(), Value(), func.Pass()); | 77 return ColorKeyframe::Create(Time(), Value(), func.Pass()); |
86 } | 78 } |
87 | 79 |
88 scoped_ptr<FloatKeyframe> FloatKeyframe::Create( | 80 scoped_ptr<FloatKeyframe> FloatKeyframe::Create( |
89 double time, | 81 double time, |
90 float value, | 82 float value, |
91 scoped_ptr<TimingFunction> timing_function) { | 83 scoped_ptr<TimingFunction> timing_function) { |
92 return make_scoped_ptr( | 84 return make_scoped_ptr( |
93 new FloatKeyframe(time, value, timing_function.Pass())); | 85 new FloatKeyframe(time, value, timing_function.Pass())); |
94 } | 86 } |
95 | 87 |
96 FloatKeyframe::FloatKeyframe(double time, | 88 FloatKeyframe::FloatKeyframe(double time, |
97 float value, | 89 float value, |
98 scoped_ptr<TimingFunction> timing_function) | 90 scoped_ptr<TimingFunction> timing_function) |
99 : Keyframe(time, timing_function.Pass()), | 91 : Keyframe(time, timing_function.Pass()), |
100 value_(value) {} | 92 value_(value) {} |
101 | 93 |
102 FloatKeyframe::~FloatKeyframe() {} | 94 FloatKeyframe::~FloatKeyframe() {} |
103 | 95 |
104 float FloatKeyframe::Value() const { | 96 float FloatKeyframe::Value() const { |
105 return value_; | 97 return value_; |
106 } | 98 } |
107 | 99 |
108 scoped_ptr<FloatKeyframe> FloatKeyframe::Clone() const { | 100 scoped_ptr<FloatKeyframe> FloatKeyframe::Clone() const { |
109 scoped_ptr<TimingFunction> func; | 101 scoped_ptr<TimingFunction> func; |
110 if (timing_function()) | 102 if (timing_function()) |
111 func = CloneTimingFunction(timing_function()); | 103 func = timing_function()->Clone(); |
112 return FloatKeyframe::Create(Time(), Value(), func.Pass()); | 104 return FloatKeyframe::Create(Time(), Value(), func.Pass()); |
113 } | 105 } |
114 | 106 |
115 scoped_ptr<TransformKeyframe> TransformKeyframe::Create( | 107 scoped_ptr<TransformKeyframe> TransformKeyframe::Create( |
116 double time, | 108 double time, |
117 const TransformOperations& value, | 109 const TransformOperations& value, |
118 scoped_ptr<TimingFunction> timing_function) { | 110 scoped_ptr<TimingFunction> timing_function) { |
119 return make_scoped_ptr( | 111 return make_scoped_ptr( |
120 new TransformKeyframe(time, value, timing_function.Pass())); | 112 new TransformKeyframe(time, value, timing_function.Pass())); |
121 } | 113 } |
122 | 114 |
123 TransformKeyframe::TransformKeyframe(double time, | 115 TransformKeyframe::TransformKeyframe(double time, |
124 const TransformOperations& value, | 116 const TransformOperations& value, |
125 scoped_ptr<TimingFunction> timing_function) | 117 scoped_ptr<TimingFunction> timing_function) |
126 : Keyframe(time, timing_function.Pass()), | 118 : Keyframe(time, timing_function.Pass()), |
127 value_(value) {} | 119 value_(value) {} |
128 | 120 |
129 TransformKeyframe::~TransformKeyframe() {} | 121 TransformKeyframe::~TransformKeyframe() {} |
130 | 122 |
131 const TransformOperations& TransformKeyframe::Value() const { | 123 const TransformOperations& TransformKeyframe::Value() const { |
132 return value_; | 124 return value_; |
133 } | 125 } |
134 | 126 |
135 scoped_ptr<TransformKeyframe> TransformKeyframe::Clone() const { | 127 scoped_ptr<TransformKeyframe> TransformKeyframe::Clone() const { |
136 scoped_ptr<TimingFunction> func; | 128 scoped_ptr<TimingFunction> func; |
137 if (timing_function()) | 129 if (timing_function()) |
138 func = CloneTimingFunction(timing_function()); | 130 func = timing_function()->Clone(); |
139 return TransformKeyframe::Create(Time(), Value(), func.Pass()); | 131 return TransformKeyframe::Create(Time(), Value(), func.Pass()); |
140 } | 132 } |
141 | 133 |
142 scoped_ptr<FilterKeyframe> FilterKeyframe::Create( | 134 scoped_ptr<FilterKeyframe> FilterKeyframe::Create( |
143 double time, | 135 double time, |
144 const FilterOperations& value, | 136 const FilterOperations& value, |
145 scoped_ptr<TimingFunction> timing_function) { | 137 scoped_ptr<TimingFunction> timing_function) { |
146 return make_scoped_ptr( | 138 return make_scoped_ptr( |
147 new FilterKeyframe(time, value, timing_function.Pass())); | 139 new FilterKeyframe(time, value, timing_function.Pass())); |
148 } | 140 } |
149 | 141 |
150 FilterKeyframe::FilterKeyframe(double time, | 142 FilterKeyframe::FilterKeyframe(double time, |
151 const FilterOperations& value, | 143 const FilterOperations& value, |
152 scoped_ptr<TimingFunction> timing_function) | 144 scoped_ptr<TimingFunction> timing_function) |
153 : Keyframe(time, timing_function.Pass()), | 145 : Keyframe(time, timing_function.Pass()), |
154 value_(value) {} | 146 value_(value) {} |
155 | 147 |
156 FilterKeyframe::~FilterKeyframe() {} | 148 FilterKeyframe::~FilterKeyframe() {} |
157 | 149 |
158 const FilterOperations& FilterKeyframe::Value() const { | 150 const FilterOperations& FilterKeyframe::Value() const { |
159 return value_; | 151 return value_; |
160 } | 152 } |
161 | 153 |
162 scoped_ptr<FilterKeyframe> FilterKeyframe::Clone() const { | 154 scoped_ptr<FilterKeyframe> FilterKeyframe::Clone() const { |
163 scoped_ptr<TimingFunction> func; | 155 scoped_ptr<TimingFunction> func; |
164 if (timing_function()) | 156 if (timing_function()) |
165 func = CloneTimingFunction(timing_function()); | 157 func = timing_function()->Clone(); |
166 return FilterKeyframe::Create(Time(), Value(), func.Pass()); | 158 return FilterKeyframe::Create(Time(), Value(), func.Pass()); |
167 } | 159 } |
168 | 160 |
169 scoped_ptr<KeyframedColorAnimationCurve> KeyframedColorAnimationCurve:: | 161 scoped_ptr<KeyframedColorAnimationCurve> KeyframedColorAnimationCurve:: |
170 Create() { | 162 Create() { |
171 return make_scoped_ptr(new KeyframedColorAnimationCurve); | 163 return make_scoped_ptr(new KeyframedColorAnimationCurve); |
172 } | 164 } |
173 | 165 |
174 KeyframedColorAnimationCurve::KeyframedColorAnimationCurve() {} | 166 KeyframedColorAnimationCurve::KeyframedColorAnimationCurve() {} |
175 | 167 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 bool KeyframedFilterAnimationCurve::HasFilterThatMovesPixels() const { | 404 bool KeyframedFilterAnimationCurve::HasFilterThatMovesPixels() const { |
413 for (size_t i = 0; i < keyframes_.size(); ++i) { | 405 for (size_t i = 0; i < keyframes_.size(); ++i) { |
414 if (keyframes_[i]->Value().HasFilterThatMovesPixels()) { | 406 if (keyframes_[i]->Value().HasFilterThatMovesPixels()) { |
415 return true; | 407 return true; |
416 } | 408 } |
417 } | 409 } |
418 return false; | 410 return false; |
419 } | 411 } |
420 | 412 |
421 } // namespace cc | 413 } // namespace cc |
OLD | NEW |