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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 200 } |
| 201 | 201 |
| 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 size_t startKeyframe = i; |
|
alancutter (OOO until 2018)
2016/05/04 07:00:03
I'd call these startIndex and endIndex to avoid co
suzyh_UTC10 (ex-contributor)
2016/05/04 07:15:32
Done.
| |
| 211 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset(); | 211 size_t endKeyframe = i+1; |
| 212 if (applyTo == 1) | 212 double startOffset = keyframes[startKeyframe]->offset(); |
| 213 double endOffset = keyframes[endKeyframe]->offset(); | |
| 214 double applyFrom = startOffset; | |
| 215 double applyTo = endOffset; | |
| 216 | |
| 217 if (i == 0) { | |
| 218 applyFrom = -std::numeric_limits<double>::infinity(); | |
| 219 ASSERT(startOffset == 0.0); | |
| 220 if (endOffset == 0.0) { | |
| 221 ASSERT(endKeyframe + 1 < keyframes.size() | |
|
alancutter (OOO until 2018)
2016/05/04 07:00:03
No need to check this, WTF::Vector indexing comes
suzyh_UTC10 (ex-contributor)
2016/05/04 07:15:32
Done.
| |
| 222 && keyframes[endKeyframe + 1]->offset() != 0.0); | |
| 223 endKeyframe = startKeyframe; | |
| 224 } | |
| 225 } | |
| 226 if (i == keyframes.size() - 2) { | |
| 213 applyTo = std::numeric_limits<double>::infinity(); | 227 applyTo = std::numeric_limits<double>::infinity(); |
| 228 ASSERT(endOffset == 1.0); | |
| 229 if (startOffset == 1.0) { | |
| 230 ASSERT(startKeyframe > 1 | |
|
alancutter (OOO until 2018)
2016/05/04 07:00:03
Won't this fail with [{}, {offset: 1}, {}]?
I don'
suzyh_UTC10 (ex-contributor)
2016/05/04 07:15:32
Ah, typo, that should have been startKeyframe >= 1
| |
| 231 && keyframes[startKeyframe - 1]->offset() != 1.0); | |
| 232 startKeyframe = endKeyframe; | |
| 233 } | |
| 234 } | |
| 214 | 235 |
| 215 m_interpolationEffect.addInterpolationsFromKeyframes(entry.key, *key frames[i], *keyframes[i + 1], applyFrom, applyTo); | 236 if (applyFrom != applyTo) { |
| 237 m_interpolationEffect.addInterpolationsFromKeyframes( | |
| 238 entry.key, *keyframes[startKeyframe], *keyframes[endKeyframe ], applyFrom, applyTo); | |
| 239 } | |
| 240 // else the interpolation will never be used in sampling | |
| 216 } | 241 } |
| 217 } | 242 } |
| 218 | 243 |
| 219 m_interpolationEffect.setPopulated(); | 244 m_interpolationEffect.setPopulated(); |
| 220 } | 245 } |
| 221 | 246 |
| 222 bool KeyframeEffectModelBase::isReplaceOnly() | 247 bool KeyframeEffectModelBase::isReplaceOnly() |
| 223 { | 248 { |
| 224 ensureKeyframeGroups(); | 249 ensureKeyframeGroups(); |
| 225 for (const auto& entry : *m_keyframeGroups) { | 250 for (const auto& entry : *m_keyframeGroups) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 240 } | 265 } |
| 241 | 266 |
| 242 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(Pass RefPtr<Keyframe::PropertySpecificKeyframe> keyframe) | 267 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(Pass RefPtr<Keyframe::PropertySpecificKeyframe> keyframe) |
| 243 { | 268 { |
| 244 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of fset()); | 269 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of fset()); |
| 245 m_keyframes.append(keyframe); | 270 m_keyframes.append(keyframe); |
| 246 } | 271 } |
| 247 | 272 |
| 248 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyf rames() | 273 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyf rames() |
| 249 { | 274 { |
| 250 // As an optimization, removes keyframes in the following categories, as | 275 // As an optimization, removes interior keyframes that have the same offset |
| 251 // they will never be used by sample(). | 276 // 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 | 277 // Note that synthetic keyframes must be added before this method is |
| 255 // called. | 278 // called. |
| 256 ASSERT(m_keyframes.size() >= 2); | 279 ASSERT(m_keyframes.size() >= 2); |
| 257 for (int i = m_keyframes.size() - 1; i >= 0; --i) { | 280 for (int i = m_keyframes.size() - 2; i > 0; --i) { |
| 258 double offset = m_keyframes[i]->offset(); | 281 double offset = m_keyframes[i]->offset(); |
| 259 bool hasSameOffsetAsPreviousNeighbor = !i || m_keyframes[i - 1]->offset( ) == offset; | 282 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; | 283 bool hasSameOffsetAsNextNeighbor = m_keyframes[i + 1]->offset() == offse t; |
| 261 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) | 284 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) |
| 262 m_keyframes.remove(i); | 285 m_keyframes.remove(i); |
| 263 } | 286 } |
| 264 ASSERT(m_keyframes.size() >= 2); | 287 ASSERT(m_keyframes.size() >= 2); |
| 265 } | 288 } |
| 266 | 289 |
| 267 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtr<TimingFunction> zeroOffsetEasing) | 290 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtr<TimingFunction> zeroOffsetEasing) |
| 268 { | 291 { |
| 269 ASSERT(!m_keyframes.isEmpty()); | 292 ASSERT(!m_keyframes.isEmpty()); |
| 270 | 293 |
| 271 bool addedSyntheticKeyframe = false; | 294 bool addedSyntheticKeyframe = false; |
| 272 | 295 |
| 273 if (m_keyframes.first()->offset() != 0.0) { | 296 if (m_keyframes.first()->offset() != 0.0) { |
| 274 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, zeroOffset Easing)); | 297 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, zeroOffset Easing)); |
| 275 addedSyntheticKeyframe = true; | 298 addedSyntheticKeyframe = true; |
| 276 } | 299 } |
| 277 if (m_keyframes.last()->offset() != 1.0) { | 300 if (m_keyframes.last()->offset() != 1.0) { |
| 278 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); | 301 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); |
| 279 addedSyntheticKeyframe = true; | 302 addedSyntheticKeyframe = true; |
| 280 } | 303 } |
| 281 | 304 |
| 282 return addedSyntheticKeyframe; | 305 return addedSyntheticKeyframe; |
| 283 } | 306 } |
| 284 | 307 |
| 285 } // namespace blink | 308 } // namespace blink |
| OLD | NEW |