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 // There are three cases here: | |
| 215 // - offset 0, used for iteration progress (-inf,0), which shoul d use the first offset 0 value | |
| 216 // - offset 1, used for iteration progress [1,inf), which should use the second offset 1 value | |
| 217 // - 0 < offset < 1, never used in sampling | |
|
alancutter (OOO until 2018)
2016/05/04 01:32:31
This comment is a touch close to being a straight
alancutter (OOO until 2018)
2016/05/04 01:35:32
Possible suggestion:
if (offset == 0) {
ASSERT
suzyh_UTC10 (ex-contributor)
2016/05/04 01:41:00
Fair. I was trying to explain why the first two ca
| |
| 218 if (keyframes[i]->offset() == 0) { | |
| 219 m_interpolationEffect.addInterpolationsFromKeyframes(entry.k ey, *keyframes[i], *keyframes[i], applyFrom, applyTo); | |
| 220 } else if (keyframes[i]->offset() == 1) { | |
| 221 m_interpolationEffect.addInterpolationsFromKeyframes(entry.k ey, *keyframes[i + 1], *keyframes[i + 1], applyFrom, applyTo); | |
| 222 } | |
| 223 } else { | |
| 224 m_interpolationEffect.addInterpolationsFromKeyframes(entry.key, *keyframes[i], *keyframes[i + 1], applyFrom, applyTo); | |
| 225 } | |
| 216 } | 226 } |
| 217 } | 227 } |
| 218 | 228 |
| 219 m_interpolationEffect.setPopulated(); | 229 m_interpolationEffect.setPopulated(); |
| 220 } | 230 } |
| 221 | 231 |
| 222 bool KeyframeEffectModelBase::isReplaceOnly() | 232 bool KeyframeEffectModelBase::isReplaceOnly() |
| 223 { | 233 { |
| 224 ensureKeyframeGroups(); | 234 ensureKeyframeGroups(); |
| 225 for (const auto& entry : *m_keyframeGroups) { | 235 for (const auto& entry : *m_keyframeGroups) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 240 } | 250 } |
| 241 | 251 |
| 242 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(Pass RefPtr<Keyframe::PropertySpecificKeyframe> keyframe) | 252 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(Pass RefPtr<Keyframe::PropertySpecificKeyframe> keyframe) |
| 243 { | 253 { |
| 244 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of fset()); | 254 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of fset()); |
| 245 m_keyframes.append(keyframe); | 255 m_keyframes.append(keyframe); |
| 246 } | 256 } |
| 247 | 257 |
| 248 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyf rames() | 258 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyf rames() |
| 249 { | 259 { |
| 250 // As an optimization, removes keyframes in the following categories, as | 260 // As an optimization, removes interior keyframes that have the same offset |
| 251 // they will never be used by sample(). | 261 // 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 | 262 // Note that synthetic keyframes must be added before this method is |
| 255 // called. | 263 // called. |
| 256 ASSERT(m_keyframes.size() >= 2); | 264 ASSERT(m_keyframes.size() >= 2); |
| 257 for (int i = m_keyframes.size() - 1; i >= 0; --i) { | 265 for (int i = m_keyframes.size() - 2; i > 0; --i) { |
| 258 double offset = m_keyframes[i]->offset(); | 266 double offset = m_keyframes[i]->offset(); |
| 259 bool hasSameOffsetAsPreviousNeighbor = !i || m_keyframes[i - 1]->offset( ) == offset; | 267 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; | 268 bool hasSameOffsetAsNextNeighbor = m_keyframes[i + 1]->offset() == offse t; |
| 261 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) | 269 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) |
| 262 m_keyframes.remove(i); | 270 m_keyframes.remove(i); |
| 263 } | 271 } |
| 264 ASSERT(m_keyframes.size() >= 2); | 272 ASSERT(m_keyframes.size() >= 2); |
| 265 } | 273 } |
| 266 | 274 |
| 267 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtr<TimingFunction> zeroOffsetEasing) | 275 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtr<TimingFunction> zeroOffsetEasing) |
| 268 { | 276 { |
| 269 ASSERT(!m_keyframes.isEmpty()); | 277 ASSERT(!m_keyframes.isEmpty()); |
| 270 | 278 |
| 271 bool addedSyntheticKeyframe = false; | 279 bool addedSyntheticKeyframe = false; |
| 272 | 280 |
| 273 if (m_keyframes.first()->offset() != 0.0) { | 281 if (m_keyframes.first()->offset() != 0.0) { |
| 274 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, zeroOffset Easing)); | 282 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, zeroOffset Easing)); |
| 275 addedSyntheticKeyframe = true; | 283 addedSyntheticKeyframe = true; |
| 276 } | 284 } |
| 277 if (m_keyframes.last()->offset() != 1.0) { | 285 if (m_keyframes.last()->offset() != 1.0) { |
| 278 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); | 286 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); |
| 279 addedSyntheticKeyframe = true; | 287 addedSyntheticKeyframe = true; |
| 280 } | 288 } |
| 281 | 289 |
| 282 return addedSyntheticKeyframe; | 290 return addedSyntheticKeyframe; |
| 283 } | 291 } |
| 284 | 292 |
| 285 } // namespace blink | 293 } // namespace blink |
| OLD | NEW |