Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 void KeyframeEffectModelBase::ensureInterpolationEffectPopulated() const | 202 void KeyframeEffectModelBase::ensureInterpolationEffectPopulated() const |
| 203 { | 203 { |
| 204 if (m_interpolationEffect.isPopulated()) | 204 if (m_interpolationEffect.isPopulated()) |
| 205 return; | 205 return; |
| 206 | 206 |
| 207 for (const auto& entry : *m_keyframeGroups) { | 207 for (const auto& entry : *m_keyframeGroups) { |
| 208 const PropertySpecificKeyframeVector& keyframes = entry.value->keyframes (); | 208 const PropertySpecificKeyframeVector& keyframes = entry.value->keyframes (); |
| 209 for (size_t i = 0; i < keyframes.size() - 1; i++) { | 209 for (size_t i = 0; i < keyframes.size() - 1; i++) { |
| 210 double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limit s<double>::infinity()); | 210 double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limit s<double>::infinity()); |
| 211 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset(); | 211 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset(); |
| 212 if (applyTo == 1) | |
| 213 applyTo = std::numeric_limits<double>::infinity(); | |
| 214 | 212 |
| 215 m_interpolationEffect.addInterpolationsFromKeyframes(entry.key, *key frames[i], *keyframes[i + 1], applyFrom, applyTo); | 213 if (keyframes[i]->offset() == keyframes[i + 1]->offset()) { |
| 214 // The interpolation we add should use the same keyframe value o n both ends | |
| 215 if (keyframes[i]->offset() == 0) { | |
| 216 // This keyframe pair is used for iteration progress < 0, at which point we want to use the start value for both | |
| 217 m_interpolationEffect.addInterpolationsFromKeyframes(entry.k ey, *keyframes[i], *keyframes[i], applyFrom, applyTo); | |
| 218 } else { | |
|
alancutter (OOO until 2018)
2016/05/02 07:35:35
Can this be "else if (offset == 1)"?
suzyh_UTC10 (ex-contributor)
2016/05/02 08:34:10
Hmm... I think that at this point, offset can stil
| |
| 219 m_interpolationEffect.addInterpolationsFromKeyframes(entry.k ey, *keyframes[i + 1], *keyframes[i + 1], applyFrom, applyTo); | |
| 220 } | |
| 221 } else { | |
| 222 m_interpolationEffect.addInterpolationsFromKeyframes(entry.key, *keyframes[i], *keyframes[i + 1], applyFrom, applyTo); | |
| 223 } | |
| 216 } | 224 } |
| 217 } | 225 } |
| 218 | 226 |
| 219 m_interpolationEffect.setPopulated(); | 227 m_interpolationEffect.setPopulated(); |
| 220 } | 228 } |
| 221 | 229 |
| 222 bool KeyframeEffectModelBase::isReplaceOnly() | 230 bool KeyframeEffectModelBase::isReplaceOnly() |
| 223 { | 231 { |
| 224 ensureKeyframeGroups(); | 232 ensureKeyframeGroups(); |
| 225 for (const auto& entry : *m_keyframeGroups) { | 233 for (const auto& entry : *m_keyframeGroups) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 240 } | 248 } |
| 241 | 249 |
| 242 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(Pass RefPtr<Keyframe::PropertySpecificKeyframe> keyframe) | 250 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(Pass RefPtr<Keyframe::PropertySpecificKeyframe> keyframe) |
| 243 { | 251 { |
| 244 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of fset()); | 252 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of fset()); |
| 245 m_keyframes.append(keyframe); | 253 m_keyframes.append(keyframe); |
| 246 } | 254 } |
| 247 | 255 |
| 248 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyf rames() | 256 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyf rames() |
| 249 { | 257 { |
| 250 // As an optimization, removes keyframes in the following categories, as | 258 // As an optimization, removes interior keyframes that have the same offset |
| 251 // they will never be used by sample(). | 259 // as both their neighbours, as they will never be used by sample(). |
| 252 // - End keyframes with the same offset as their neighbor | |
| 253 // - Interior keyframes with the same offset as both their neighbors | |
| 254 // Note that synthetic keyframes must be added before this method is | 260 // Note that synthetic keyframes must be added before this method is |
| 255 // called. | 261 // called. |
| 256 ASSERT(m_keyframes.size() >= 2); | 262 ASSERT(m_keyframes.size() >= 2); |
| 257 for (int i = m_keyframes.size() - 1; i >= 0; --i) { | 263 for (int i = m_keyframes.size() - 2; i > 0; --i) { |
| 258 double offset = m_keyframes[i]->offset(); | 264 double offset = m_keyframes[i]->offset(); |
| 259 bool hasSameOffsetAsPreviousNeighbor = !i || m_keyframes[i - 1]->offset( ) == offset; | 265 bool hasSameOffsetAsPreviousNeighbor = m_keyframes[i - 1]->offset() == o ffset; |
| 260 bool hasSameOffsetAsNextNeighbor = i == static_cast<int>(m_keyframes.siz e() - 1) || m_keyframes[i + 1]->offset() == offset; | 266 bool hasSameOffsetAsNextNeighbor = m_keyframes[i + 1]->offset() == offse t; |
|
alancutter (OOO until 2018)
2016/05/02 07:35:35
Much nicer!
| |
| 261 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) | 267 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) |
| 262 m_keyframes.remove(i); | 268 m_keyframes.remove(i); |
| 263 } | 269 } |
| 264 ASSERT(m_keyframes.size() >= 2); | 270 ASSERT(m_keyframes.size() >= 2); |
| 265 } | 271 } |
| 266 | 272 |
| 267 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtr<TimingFunction> zeroOffsetEasing) | 273 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtr<TimingFunction> zeroOffsetEasing) |
| 268 { | 274 { |
| 269 ASSERT(!m_keyframes.isEmpty()); | 275 ASSERT(!m_keyframes.isEmpty()); |
| 270 | 276 |
| 271 bool addedSyntheticKeyframe = false; | 277 bool addedSyntheticKeyframe = false; |
| 272 | 278 |
| 273 if (m_keyframes.first()->offset() != 0.0) { | 279 if (m_keyframes.first()->offset() != 0.0) { |
| 274 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, zeroOffset Easing)); | 280 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, zeroOffset Easing)); |
| 275 addedSyntheticKeyframe = true; | 281 addedSyntheticKeyframe = true; |
| 276 } | 282 } |
| 277 if (m_keyframes.last()->offset() != 1.0) { | 283 if (m_keyframes.last()->offset() != 1.0) { |
| 278 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); | 284 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); |
| 279 addedSyntheticKeyframe = true; | 285 addedSyntheticKeyframe = true; |
| 280 } | 286 } |
| 281 | 287 |
| 282 return addedSyntheticKeyframe; | 288 return addedSyntheticKeyframe; |
| 283 } | 289 } |
| 284 | 290 |
| 285 } // namespace blink | 291 } // namespace blink |
| OLD | NEW |