Chromium Code Reviews| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCKeyframedAnimationCurve.h" | 7 #include "CCKeyframedAnimationCurve.h" |
| 8 | 8 |
| 9 #include <wtf/OwnPtr.h> | |
| 10 | |
| 11 using WebKit::WebTransformationMatrix; | 9 using WebKit::WebTransformationMatrix; |
| 12 | 10 |
| 13 namespace cc { | 11 namespace cc { |
| 14 | 12 |
| 15 namespace { | 13 namespace { |
| 16 | 14 |
| 17 template <class Keyframe> | 15 template <class Keyframe> |
| 18 void insertKeyframe(PassOwnPtr<Keyframe> popKeyframe, OwnPtrVector<Keyframe>& ke yframes) | 16 void insertKeyframe(scoped_ptr<Keyframe> keyframe, ScopedPtrVector<Keyframe>& ke yframes) |
| 19 { | 17 { |
| 20 OwnPtr<Keyframe> keyframe = popKeyframe; | |
| 21 | |
| 22 // Usually, the keyframes will be added in order, so this loop would be unne cessary and | 18 // Usually, the keyframes will be added in order, so this loop would be unne cessary and |
| 23 // we should skip it if possible. | 19 // we should skip it if possible. |
| 24 if (!keyframes.isEmpty() && keyframe->time() < keyframes.last()->time()) { | 20 if (!keyframes.isEmpty() && keyframe->time() < keyframes.last()->time()) { |
| 25 for (size_t i = 0; i < keyframes.size(); ++i) { | 21 for (size_t i = 0; i < keyframes.size(); ++i) { |
| 26 if (keyframe->time() < keyframes[i]->time()) { | 22 if (keyframe->time() < keyframes[i]->time()) { |
| 27 keyframes.insert(i, keyframe.release()); | 23 keyframes.insert(i, keyframe.Pass()); |
| 28 return; | 24 return; |
| 29 } | 25 } |
| 30 } | 26 } |
| 31 } | 27 } |
| 32 | 28 |
| 33 keyframes.append(keyframe.release()); | 29 keyframes.append(keyframe.Pass()); |
| 34 } | 30 } |
| 35 | 31 |
| 36 PassOwnPtr<CCTimingFunction> cloneTimingFunction(const CCTimingFunction* timingF unction) | 32 scoped_ptr<CCTimingFunction> cloneTimingFunction(const CCTimingFunction* timingF unction) |
| 37 { | 33 { |
| 38 ASSERT(timingFunction); | 34 ASSERT(timingFunction); |
| 39 OwnPtr<CCAnimationCurve> curve(timingFunction->clone()); | 35 scoped_ptr<CCAnimationCurve> curve(timingFunction->clone()); |
| 40 return adoptPtr(static_cast<CCTimingFunction*>(curve.leakPtr())); | 36 return scoped_ptr<CCTimingFunction>(static_cast<CCTimingFunction*>(curve.rel ease())); |
| 41 } | 37 } |
| 42 | 38 |
| 43 } // namespace | 39 } // namespace |
| 44 | 40 |
| 45 CCKeyframe::CCKeyframe(double time, PassOwnPtr<CCTimingFunction> timingFunction) | 41 CCKeyframe::CCKeyframe(double time, scoped_ptr<CCTimingFunction> timingFunction) |
| 46 : m_time(time) | 42 : m_time(time) |
| 47 , m_timingFunction(timingFunction) | 43 , m_timingFunction(timingFunction.Pass()) |
| 48 { | 44 { |
| 49 } | 45 } |
| 50 | 46 |
| 51 CCKeyframe::~CCKeyframe() | 47 CCKeyframe::~CCKeyframe() |
| 52 { | 48 { |
| 53 } | 49 } |
| 54 | 50 |
| 55 double CCKeyframe::time() const | 51 double CCKeyframe::time() const |
| 56 { | 52 { |
| 57 return m_time; | 53 return m_time; |
| 58 } | 54 } |
| 59 | 55 |
| 60 const CCTimingFunction* CCKeyframe::timingFunction() const | 56 const CCTimingFunction* CCKeyframe::timingFunction() const |
| 61 { | 57 { |
| 62 return m_timingFunction.get(); | 58 return m_timingFunction.get(); |
| 63 } | 59 } |
| 64 | 60 |
| 65 PassOwnPtr<CCFloatKeyframe> CCFloatKeyframe::create(double time, float value, Pa ssOwnPtr<CCTimingFunction> timingFunction) | 61 scoped_ptr<CCFloatKeyframe> CCFloatKeyframe::create(double time, float value, sc oped_ptr<CCTimingFunction> timingFunction) |
| 66 { | 62 { |
| 67 return adoptPtr(new CCFloatKeyframe(time, value, timingFunction)); | 63 return make_scoped_ptr(new CCFloatKeyframe(time, value, timingFunction.Pass( ))); |
| 68 } | 64 } |
| 69 | 65 |
| 70 CCFloatKeyframe::CCFloatKeyframe(double time, float value, PassOwnPtr<CCTimingFu nction> timingFunction) | 66 CCFloatKeyframe::CCFloatKeyframe(double time, float value, scoped_ptr<CCTimingFu nction> timingFunction) |
| 71 : CCKeyframe(time, timingFunction) | 67 : CCKeyframe(time, timingFunction.Pass()) |
| 72 , m_value(value) | 68 , m_value(value) |
| 73 { | 69 { |
| 74 } | 70 } |
| 75 | 71 |
| 76 CCFloatKeyframe::~CCFloatKeyframe() | 72 CCFloatKeyframe::~CCFloatKeyframe() |
| 77 { | 73 { |
| 78 } | 74 } |
| 79 | 75 |
| 80 float CCFloatKeyframe::value() const | 76 float CCFloatKeyframe::value() const |
| 81 { | 77 { |
| 82 return m_value; | 78 return m_value; |
| 83 } | 79 } |
| 84 | 80 |
| 85 PassOwnPtr<CCFloatKeyframe> CCFloatKeyframe::clone() const | 81 scoped_ptr<CCFloatKeyframe> CCFloatKeyframe::clone() const |
| 86 { | 82 { |
| 87 return CCFloatKeyframe::create(time(), value(), timingFunction() ? cloneTimi ngFunction(timingFunction()) : nullptr); | 83 return CCFloatKeyframe::create(time(), value(), timingFunction() ? cloneTimi ngFunction(timingFunction()) : scoped_ptr<CCTimingFunction>().Pass()); |
|
jamesr
2012/10/11 04:37:58
I wonder if this is teh funky because it's a terna
| |
| 88 } | 84 } |
| 89 | 85 |
| 90 PassOwnPtr<CCTransformKeyframe> CCTransformKeyframe::create(double time, const W ebKit::WebTransformOperations& value, PassOwnPtr<CCTimingFunction> timingFunctio n) | 86 scoped_ptr<CCTransformKeyframe> CCTransformKeyframe::create(double time, const W ebKit::WebTransformOperations& value, scoped_ptr<CCTimingFunction> timingFunctio n) |
| 91 { | 87 { |
| 92 return adoptPtr(new CCTransformKeyframe(time, value, timingFunction)); | 88 return make_scoped_ptr(new CCTransformKeyframe(time, value, timingFunction.P ass())); |
| 93 } | 89 } |
| 94 | 90 |
| 95 CCTransformKeyframe::CCTransformKeyframe(double time, const WebKit::WebTransform Operations& value, PassOwnPtr<CCTimingFunction> timingFunction) | 91 CCTransformKeyframe::CCTransformKeyframe(double time, const WebKit::WebTransform Operations& value, scoped_ptr<CCTimingFunction> timingFunction) |
| 96 : CCKeyframe(time, timingFunction) | 92 : CCKeyframe(time, timingFunction.Pass()) |
| 97 , m_value(value) | 93 , m_value(value) |
| 98 { | 94 { |
| 99 } | 95 } |
| 100 | 96 |
| 101 CCTransformKeyframe::~CCTransformKeyframe() | 97 CCTransformKeyframe::~CCTransformKeyframe() |
| 102 { | 98 { |
| 103 } | 99 } |
| 104 | 100 |
| 105 const WebKit::WebTransformOperations& CCTransformKeyframe::value() const | 101 const WebKit::WebTransformOperations& CCTransformKeyframe::value() const |
| 106 { | 102 { |
| 107 return m_value; | 103 return m_value; |
| 108 } | 104 } |
| 109 | 105 |
| 110 PassOwnPtr<CCTransformKeyframe> CCTransformKeyframe::clone() const | 106 scoped_ptr<CCTransformKeyframe> CCTransformKeyframe::clone() const |
| 111 { | 107 { |
| 112 return CCTransformKeyframe::create(time(), value(), timingFunction() ? clone TimingFunction(timingFunction()) : nullptr); | 108 return CCTransformKeyframe::create(time(), value(), timingFunction() ? clone TimingFunction(timingFunction()) : scoped_ptr<CCTimingFunction>().Pass()); |
| 113 } | 109 } |
| 114 | 110 |
| 115 PassOwnPtr<CCKeyframedFloatAnimationCurve> CCKeyframedFloatAnimationCurve::creat e() | 111 scoped_ptr<CCKeyframedFloatAnimationCurve> CCKeyframedFloatAnimationCurve::creat e() |
| 116 { | 112 { |
| 117 return adoptPtr(new CCKeyframedFloatAnimationCurve); | 113 return make_scoped_ptr(new CCKeyframedFloatAnimationCurve); |
| 118 } | 114 } |
| 119 | 115 |
| 120 CCKeyframedFloatAnimationCurve::CCKeyframedFloatAnimationCurve() | 116 CCKeyframedFloatAnimationCurve::CCKeyframedFloatAnimationCurve() |
| 121 { | 117 { |
| 122 } | 118 } |
| 123 | 119 |
| 124 CCKeyframedFloatAnimationCurve::~CCKeyframedFloatAnimationCurve() | 120 CCKeyframedFloatAnimationCurve::~CCKeyframedFloatAnimationCurve() |
| 125 { | 121 { |
| 126 } | 122 } |
| 127 | 123 |
| 128 void CCKeyframedFloatAnimationCurve::addKeyframe(PassOwnPtr<CCFloatKeyframe> key frame) | 124 void CCKeyframedFloatAnimationCurve::addKeyframe(scoped_ptr<CCFloatKeyframe> key frame) |
| 129 { | 125 { |
| 130 insertKeyframe(keyframe, m_keyframes); | 126 insertKeyframe(keyframe.Pass(), m_keyframes); |
| 131 } | 127 } |
| 132 | 128 |
| 133 double CCKeyframedFloatAnimationCurve::duration() const | 129 double CCKeyframedFloatAnimationCurve::duration() const |
| 134 { | 130 { |
| 135 return m_keyframes.last()->time() - m_keyframes.first()->time(); | 131 return m_keyframes.last()->time() - m_keyframes.first()->time(); |
| 136 } | 132 } |
| 137 | 133 |
| 138 PassOwnPtr<CCAnimationCurve> CCKeyframedFloatAnimationCurve::clone() const | 134 scoped_ptr<CCAnimationCurve> CCKeyframedFloatAnimationCurve::clone() const |
| 139 { | 135 { |
| 140 OwnPtr<CCKeyframedFloatAnimationCurve> toReturn(CCKeyframedFloatAnimationCur ve::create()); | 136 scoped_ptr<CCKeyframedFloatAnimationCurve> toReturn(CCKeyframedFloatAnimatio nCurve::create()); |
| 141 for (size_t i = 0; i < m_keyframes.size(); ++i) | 137 for (size_t i = 0; i < m_keyframes.size(); ++i) |
| 142 toReturn->addKeyframe(m_keyframes[i]->clone()); | 138 toReturn->addKeyframe(m_keyframes[i]->clone()); |
| 143 return toReturn.release(); | 139 return toReturn.PassAs<CCAnimationCurve>(); |
| 144 } | 140 } |
| 145 | 141 |
| 146 float CCKeyframedFloatAnimationCurve::getValue(double t) const | 142 float CCKeyframedFloatAnimationCurve::getValue(double t) const |
| 147 { | 143 { |
| 148 if (t <= m_keyframes.first()->time()) | 144 if (t <= m_keyframes.first()->time()) |
| 149 return m_keyframes.first()->value(); | 145 return m_keyframes.first()->value(); |
| 150 | 146 |
| 151 if (t >= m_keyframes.last()->time()) | 147 if (t >= m_keyframes.last()->time()) |
| 152 return m_keyframes.last()->value(); | 148 return m_keyframes.last()->value(); |
| 153 | 149 |
| 154 size_t i = 0; | 150 size_t i = 0; |
| 155 for (; i < m_keyframes.size() - 1; ++i) { | 151 for (; i < m_keyframes.size() - 1; ++i) { |
| 156 if (t < m_keyframes[i+1]->time()) | 152 if (t < m_keyframes[i+1]->time()) |
| 157 break; | 153 break; |
| 158 } | 154 } |
| 159 | 155 |
| 160 float progress = static_cast<float>((t - m_keyframes[i]->time()) / (m_keyfra mes[i+1]->time() - m_keyframes[i]->time())); | 156 float progress = static_cast<float>((t - m_keyframes[i]->time()) / (m_keyfra mes[i+1]->time() - m_keyframes[i]->time())); |
| 161 | 157 |
| 162 if (m_keyframes[i]->timingFunction()) | 158 if (m_keyframes[i]->timingFunction()) |
| 163 progress = m_keyframes[i]->timingFunction()->getValue(progress); | 159 progress = m_keyframes[i]->timingFunction()->getValue(progress); |
| 164 | 160 |
| 165 return m_keyframes[i]->value() + (m_keyframes[i+1]->value() - m_keyframes[i] ->value()) * progress; | 161 return m_keyframes[i]->value() + (m_keyframes[i+1]->value() - m_keyframes[i] ->value()) * progress; |
| 166 } | 162 } |
| 167 | 163 |
| 168 PassOwnPtr<CCKeyframedTransformAnimationCurve> CCKeyframedTransformAnimationCurv e::create() | 164 scoped_ptr<CCKeyframedTransformAnimationCurve> CCKeyframedTransformAnimationCurv e::create() |
| 169 { | 165 { |
| 170 return adoptPtr(new CCKeyframedTransformAnimationCurve); | 166 return make_scoped_ptr(new CCKeyframedTransformAnimationCurve); |
| 171 } | 167 } |
| 172 | 168 |
| 173 CCKeyframedTransformAnimationCurve::CCKeyframedTransformAnimationCurve() | 169 CCKeyframedTransformAnimationCurve::CCKeyframedTransformAnimationCurve() |
| 174 { | 170 { |
| 175 } | 171 } |
| 176 | 172 |
| 177 CCKeyframedTransformAnimationCurve::~CCKeyframedTransformAnimationCurve() | 173 CCKeyframedTransformAnimationCurve::~CCKeyframedTransformAnimationCurve() |
| 178 { | 174 { |
| 179 } | 175 } |
| 180 | 176 |
| 181 void CCKeyframedTransformAnimationCurve::addKeyframe(PassOwnPtr<CCTransformKeyfr ame> keyframe) | 177 void CCKeyframedTransformAnimationCurve::addKeyframe(scoped_ptr<CCTransformKeyfr ame> keyframe) |
| 182 { | 178 { |
| 183 insertKeyframe(keyframe, m_keyframes); | 179 insertKeyframe(keyframe.Pass(), m_keyframes); |
| 184 } | 180 } |
| 185 | 181 |
| 186 double CCKeyframedTransformAnimationCurve::duration() const | 182 double CCKeyframedTransformAnimationCurve::duration() const |
| 187 { | 183 { |
| 188 return m_keyframes.last()->time() - m_keyframes.first()->time(); | 184 return m_keyframes.last()->time() - m_keyframes.first()->time(); |
| 189 } | 185 } |
| 190 | 186 |
| 191 PassOwnPtr<CCAnimationCurve> CCKeyframedTransformAnimationCurve::clone() const | 187 scoped_ptr<CCAnimationCurve> CCKeyframedTransformAnimationCurve::clone() const |
| 192 { | 188 { |
| 193 OwnPtr<CCKeyframedTransformAnimationCurve> toReturn(CCKeyframedTransformAnim ationCurve::create()); | 189 scoped_ptr<CCKeyframedTransformAnimationCurve> toReturn(CCKeyframedTransform AnimationCurve::create()); |
| 194 for (size_t i = 0; i < m_keyframes.size(); ++i) | 190 for (size_t i = 0; i < m_keyframes.size(); ++i) |
| 195 toReturn->addKeyframe(m_keyframes[i]->clone()); | 191 toReturn->addKeyframe(m_keyframes[i]->clone()); |
| 196 return toReturn.release(); | 192 return toReturn.PassAs<CCAnimationCurve>(); |
| 197 } | 193 } |
| 198 | 194 |
| 199 WebTransformationMatrix CCKeyframedTransformAnimationCurve::getValue(double t) c onst | 195 WebTransformationMatrix CCKeyframedTransformAnimationCurve::getValue(double t) c onst |
| 200 { | 196 { |
| 201 if (t <= m_keyframes.first()->time()) | 197 if (t <= m_keyframes.first()->time()) |
| 202 return m_keyframes.first()->value().apply(); | 198 return m_keyframes.first()->value().apply(); |
| 203 | 199 |
| 204 if (t >= m_keyframes.last()->time()) | 200 if (t >= m_keyframes.last()->time()) |
| 205 return m_keyframes.last()->value().apply(); | 201 return m_keyframes.last()->value().apply(); |
| 206 | 202 |
| 207 size_t i = 0; | 203 size_t i = 0; |
| 208 for (; i < m_keyframes.size() - 1; ++i) { | 204 for (; i < m_keyframes.size() - 1; ++i) { |
| 209 if (t < m_keyframes[i+1]->time()) | 205 if (t < m_keyframes[i+1]->time()) |
| 210 break; | 206 break; |
| 211 } | 207 } |
| 212 | 208 |
| 213 double progress = (t - m_keyframes[i]->time()) / (m_keyframes[i+1]->time() - m_keyframes[i]->time()); | 209 double progress = (t - m_keyframes[i]->time()) / (m_keyframes[i+1]->time() - m_keyframes[i]->time()); |
| 214 | 210 |
| 215 if (m_keyframes[i]->timingFunction()) | 211 if (m_keyframes[i]->timingFunction()) |
| 216 progress = m_keyframes[i]->timingFunction()->getValue(progress); | 212 progress = m_keyframes[i]->timingFunction()->getValue(progress); |
| 217 | 213 |
| 218 return m_keyframes[i+1]->value().blend(m_keyframes[i]->value(), progress); | 214 return m_keyframes[i+1]->value().blend(m_keyframes[i]->value(), progress); |
| 219 } | 215 } |
| 220 | 216 |
| 221 } // namespace cc | 217 } // namespace cc |
| OLD | NEW |