Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: third_party/WebKit/Source/core/animation/KeyframeEffectModel.cpp

Issue 1942703002: Fix handling of multiple keyframes at same offset (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/animation/InterpolationEffect.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 startIndex = i;
211 double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<dou ble>::infinity() : keyframes[i + 1]->offset(); 211 size_t endIndex = i+1;
212 if (applyTo == 1) 212 double startOffset = keyframes[startIndex]->offset();
213 double endOffset = keyframes[endIndex]->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(keyframes[endIndex + 1]->offset() != 0.0);
222 endIndex = startIndex;
223 }
224 }
225 if (i == keyframes.size() - 2) {
213 applyTo = std::numeric_limits<double>::infinity(); 226 applyTo = std::numeric_limits<double>::infinity();
227 ASSERT(endOffset == 1.0);
228 if (startOffset == 1.0) {
229 ASSERT(keyframes[startIndex - 1]->offset() != 1.0);
230 startIndex = endIndex;
231 }
232 }
214 233
215 m_interpolationEffect.addInterpolationsFromKeyframes(entry.key, *key frames[i], *keyframes[i + 1], applyFrom, applyTo); 234 if (applyFrom != applyTo) {
235 m_interpolationEffect.addInterpolationsFromKeyframes(
236 entry.key, *keyframes[startIndex], *keyframes[endIndex], app lyFrom, applyTo);
237 }
238 // else the interpolation will never be used in sampling
216 } 239 }
217 } 240 }
218 241
219 m_interpolationEffect.setPopulated(); 242 m_interpolationEffect.setPopulated();
220 } 243 }
221 244
222 bool KeyframeEffectModelBase::isReplaceOnly() 245 bool KeyframeEffectModelBase::isReplaceOnly()
223 { 246 {
224 ensureKeyframeGroups(); 247 ensureKeyframeGroups();
225 for (const auto& entry : *m_keyframeGroups) { 248 for (const auto& entry : *m_keyframeGroups) {
(...skipping 14 matching lines...) Expand all
240 } 263 }
241 264
242 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(Pass RefPtr<Keyframe::PropertySpecificKeyframe> keyframe) 265 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(Pass RefPtr<Keyframe::PropertySpecificKeyframe> keyframe)
243 { 266 {
244 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of fset()); 267 ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->of fset());
245 m_keyframes.append(keyframe); 268 m_keyframes.append(keyframe);
246 } 269 }
247 270
248 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyf rames() 271 void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyf rames()
249 { 272 {
250 // As an optimization, removes keyframes in the following categories, as 273 // As an optimization, removes interior keyframes that have the same offset
251 // they will never be used by sample(). 274 // 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 275 // Note that synthetic keyframes must be added before this method is
255 // called. 276 // called.
256 ASSERT(m_keyframes.size() >= 2); 277 ASSERT(m_keyframes.size() >= 2);
257 for (int i = m_keyframes.size() - 1; i >= 0; --i) { 278 for (int i = m_keyframes.size() - 2; i > 0; --i) {
258 double offset = m_keyframes[i]->offset(); 279 double offset = m_keyframes[i]->offset();
259 bool hasSameOffsetAsPreviousNeighbor = !i || m_keyframes[i - 1]->offset( ) == offset; 280 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; 281 bool hasSameOffsetAsNextNeighbor = m_keyframes[i + 1]->offset() == offse t;
261 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor) 282 if (hasSameOffsetAsPreviousNeighbor && hasSameOffsetAsNextNeighbor)
262 m_keyframes.remove(i); 283 m_keyframes.remove(i);
263 } 284 }
264 ASSERT(m_keyframes.size() >= 2); 285 ASSERT(m_keyframes.size() >= 2);
265 } 286 }
266 287
267 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtr<TimingFunction> zeroOffsetEasing) 288 bool KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyfram eIfRequired(PassRefPtr<TimingFunction> zeroOffsetEasing)
268 { 289 {
269 ASSERT(!m_keyframes.isEmpty()); 290 ASSERT(!m_keyframes.isEmpty());
270 291
271 bool addedSyntheticKeyframe = false; 292 bool addedSyntheticKeyframe = false;
272 293
273 if (m_keyframes.first()->offset() != 0.0) { 294 if (m_keyframes.first()->offset() != 0.0) {
274 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, zeroOffset Easing)); 295 m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, zeroOffset Easing));
275 addedSyntheticKeyframe = true; 296 addedSyntheticKeyframe = true;
276 } 297 }
277 if (m_keyframes.last()->offset() != 1.0) { 298 if (m_keyframes.last()->offset() != 1.0) {
278 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr)); 299 appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr));
279 addedSyntheticKeyframe = true; 300 addedSyntheticKeyframe = true;
280 } 301 }
281 302
282 return addedSyntheticKeyframe; 303 return addedSyntheticKeyframe;
283 } 304 }
284 305
285 } // namespace blink 306 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/animation/InterpolationEffect.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698