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

Side by Side Diff: Source/core/animation/CompositorAnimations.cpp

Issue 178263006: Handle direction control in compositor Animations (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: new patch: rebases against tot; fixes enum naming issue Created 6 years, 9 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "public/platform/WebTransformAnimationCurve.h" 51 #include "public/platform/WebTransformAnimationCurve.h"
52 #include "public/platform/WebTransformKeyframe.h" 52 #include "public/platform/WebTransformKeyframe.h"
53 53
54 #include <algorithm> 54 #include <algorithm>
55 #include <cmath> 55 #include <cmath>
56 56
57 namespace WebCore { 57 namespace WebCore {
58 58
59 namespace { 59 namespace {
60 60
61 void getKeyframeValuesForProperty(const KeyframeEffectModel* effect, CSSProperty ID id, double scale, bool reverse, KeyframeVector& values) 61 void getKeyframeValuesForProperty(const KeyframeEffectModel* effect, CSSProperty ID id, double scale, KeyframeVector& values)
62 { 62 {
63 ASSERT(values.isEmpty()); 63 ASSERT(values.isEmpty());
64 const KeyframeVector& group = effect->getPropertySpecificKeyframes(id); 64 const KeyframeVector& group = effect->getPropertySpecificKeyframes(id);
65 65
66 if (reverse) { 66 for (size_t i = 0; i < group.size(); ++i) {
67 for (size_t i = group.size(); i--;) { 67 double offset = group[i]->offset() * scale;
68 double offset = (1 - group[i]->offset()) * scale; 68 values.append(group[i]->cloneWithOffset(offset));
69 values.append(group[i]->cloneWithOffset(offset));
70 }
71 } else {
72 for (size_t i = 0; i < group.size(); ++i) {
73 double offset = group[i]->offset() * scale;
74 values.append(group[i]->cloneWithOffset(offset));
75 }
76 } 69 }
77 } 70 }
78 71
79 } 72 }
80 73
81 // ----------------------------------------------------------------------- 74 // -----------------------------------------------------------------------
82 // TimingFunctionReverser methods
83 // -----------------------------------------------------------------------
84
85 PassRefPtr<TimingFunction> CompositorAnimationsTimingFunctionReverser::reverse(c onst LinearTimingFunction* timefunc)
86 {
87 return const_cast<LinearTimingFunction*>(timefunc);
88 }
89
90 PassRefPtr<TimingFunction> CompositorAnimationsTimingFunctionReverser::reverse(c onst CubicBezierTimingFunction* timefunc)
91 {
92 switch (timefunc->subType()) {
93 case CubicBezierTimingFunction::EaseIn:
94 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease Out);
95 case CubicBezierTimingFunction::EaseOut:
96 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease In);
97 case CubicBezierTimingFunction::EaseInOut:
98 return const_cast<CubicBezierTimingFunction*>(timefunc);
99 case CubicBezierTimingFunction::Ease: // Ease is not symmetrical
100 case CubicBezierTimingFunction::Custom:
101 return CubicBezierTimingFunction::create(1 - timefunc->x2(), 1 - timefun c->y2(), 1 - timefunc->x1(), 1 - timefunc->y1());
102 default:
103 ASSERT_NOT_REACHED();
104 return PassRefPtr<TimingFunction>();
105 }
106 }
107
108 PassRefPtr<TimingFunction> CompositorAnimationsTimingFunctionReverser::reverse(c onst TimingFunction* timefunc)
109 {
110 switch (timefunc->type()) {
111 case TimingFunction::LinearFunction: {
112 const LinearTimingFunction* linear = toLinearTimingFunction(timefunc);
113 return reverse(linear);
114 }
115 case TimingFunction::CubicBezierFunction: {
116 const CubicBezierTimingFunction* cubic = toCubicBezierTimingFunction(tim efunc);
117 return reverse(cubic);
118 }
119
120 // Steps function can not be reversed.
121 case TimingFunction::StepsFunction:
122 default:
123 ASSERT_NOT_REACHED();
124 return PassRefPtr<TimingFunction>();
125 }
126 }
127
128 // -----------------------------------------------------------------------
129 // CompositorAnimations public API 75 // CompositorAnimations public API
130 // ----------------------------------------------------------------------- 76 // -----------------------------------------------------------------------
131 77
132 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim ing, const AnimationEffect& effect) 78 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim ing, const AnimationEffect& effect)
133 { 79 {
134 const KeyframeEffectModel& keyframeEffect = *toKeyframeEffectModel(&effect); 80 const KeyframeEffectModel& keyframeEffect = *toKeyframeEffectModel(&effect);
135 81
136 // Are the keyframes convertible? 82 // Are the keyframes convertible?
137 const KeyframeEffectModel::KeyframeVector frames = keyframeEffect.getFrames( ); 83 const KeyframeEffectModel::KeyframeVector frames = keyframeEffect.getFrames( );
138 for (size_t i = 0; i < frames.size(); ++i) { 84 for (size_t i = 0; i < frames.size(); ++i) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // All directions are supported. 255 // All directions are supported.
310 256
311 // Now attempt an actual conversion 257 // Now attempt an actual conversion
312 out.scaledDuration = timing.iterationDuration; 258 out.scaledDuration = timing.iterationDuration;
313 ASSERT(out.scaledDuration > 0); 259 ASSERT(out.scaledDuration > 0);
314 260
315 double scaledStartDelay = timing.startDelay; 261 double scaledStartDelay = timing.startDelay;
316 if (scaledStartDelay > 0 && scaledStartDelay > out.scaledDuration * timing.i terationCount) 262 if (scaledStartDelay > 0 && scaledStartDelay > out.scaledDuration * timing.i terationCount)
317 return false; 263 return false;
318 264
319 out.reverse = (timing.direction == Timing::PlaybackDirectionReverse 265 out.direction = timing.direction;
320 || timing.direction == Timing::PlaybackDirectionAlternateReverse);
321 out.alternate = (timing.direction == Timing::PlaybackDirectionAlternate
322 || timing.direction == Timing::PlaybackDirectionAlternateReverse);
323 266
324 if (!std::isfinite(timing.iterationCount)) { 267 if (!std::isfinite(timing.iterationCount)) {
325 out.adjustedIterationCount = -1; 268 out.adjustedIterationCount = -1;
326 } else { 269 } else {
327 out.adjustedIterationCount = std::floor(timing.iterationCount); 270 out.adjustedIterationCount = std::floor(timing.iterationCount);
328 ASSERT(out.adjustedIterationCount > 0); 271 ASSERT(out.adjustedIterationCount > 0);
329 } 272 }
330 273
331 // Compositor's time offset is positive for seeking into the animation. 274 // Compositor's time offset is positive for seeking into the animation.
332 out.scaledTimeOffset = -scaledStartDelay; 275 out.scaledTimeOffset = -scaledStartDelay;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 327
385 case TimingFunction::StepsFunction: 328 case TimingFunction::StepsFunction:
386 default: 329 default:
387 ASSERT_NOT_REACHED(); 330 ASSERT_NOT_REACHED();
388 return; 331 return;
389 } 332 }
390 } 333 }
391 334
392 } // namespace anoymous 335 } // namespace anoymous
393 336
394 void CompositorAnimationsImpl::addKeyframesToCurve(blink::WebAnimationCurve& cur ve, const KeyframeVector& keyframes, bool reverse) 337 void CompositorAnimationsImpl::addKeyframesToCurve(blink::WebAnimationCurve& cur ve, const KeyframeVector& keyframes)
395 { 338 {
396 for (size_t i = 0; i < keyframes.size(); i++) { 339 for (size_t i = 0; i < keyframes.size(); i++) {
397 RefPtr<TimingFunction> reversedTimingFunction;
398 const TimingFunction* keyframeTimingFunction = 0; 340 const TimingFunction* keyframeTimingFunction = 0;
399 if (i < keyframes.size() - 1) { // Ignore timing function of last frame. 341 if (i < keyframes.size() - 1) { // Ignore timing function of last frame.
400 if (reverse) { 342 keyframeTimingFunction = keyframes[i]->easing();
401 reversedTimingFunction = CompositorAnimationsTimingFunctionRever ser::reverse(keyframes[i + 1]->easing());
402 keyframeTimingFunction = reversedTimingFunction.get();
403 } else {
404 keyframeTimingFunction = keyframes[i]->easing();
405 }
406 } 343 }
407 344
408 ASSERT(!keyframes[i]->value()->dependsOnUnderlyingValue()); 345 ASSERT(!keyframes[i]->value()->dependsOnUnderlyingValue());
409 RefPtr<AnimatableValue> value = keyframes[i]->value()->compositeOnto(0); 346 RefPtr<AnimatableValue> value = keyframes[i]->value()->compositeOnto(0);
410 347
411 switch (curve.type()) { 348 switch (curve.type()) {
412 case blink::WebAnimationCurve::AnimationCurveTypeFilter: { 349 case blink::WebAnimationCurve::AnimationCurveTypeFilter: {
413 OwnPtr<blink::WebFilterOperations> ops = adoptPtr(blink::Platform::c urrent()->compositorSupport()->createFilterOperations()); 350 OwnPtr<blink::WebFilterOperations> ops = adoptPtr(blink::Platform::c urrent()->compositorSupport()->createFilterOperations());
414 bool converted = toWebFilterOperations(toAnimatableFilterOperations( value.get())->operations(), ops.get()); 351 bool converted = toWebFilterOperations(toAnimatableFilterOperations( value.get())->operations(), ops.get());
415 ASSERT_UNUSED(converted, converted); 352 ASSERT_UNUSED(converted, converted);
(...skipping 25 matching lines...) Expand all
441 } 378 }
442 379
443 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, co nst KeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animation s) 380 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, co nst KeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animation s)
444 { 381 {
445 ASSERT(animations.isEmpty()); 382 ASSERT(animations.isEmpty());
446 CompositorTiming compositorTiming; 383 CompositorTiming compositorTiming;
447 bool timingValid = convertTimingForCompositor(timing, compositorTiming); 384 bool timingValid = convertTimingForCompositor(timing, compositorTiming);
448 ASSERT_UNUSED(timingValid, timingValid); 385 ASSERT_UNUSED(timingValid, timingValid);
449 386
450 RefPtr<TimingFunction> timingFunction = timing.timingFunction; 387 RefPtr<TimingFunction> timingFunction = timing.timingFunction;
451 if (compositorTiming.reverse)
452 timingFunction = CompositorAnimationsTimingFunctionReverser::reverse(tim ingFunction.get());
453 388
454 PropertySet properties = effect.properties(); 389 PropertySet properties = effect.properties();
455 ASSERT(!properties.isEmpty()); 390 ASSERT(!properties.isEmpty());
456 for (PropertySet::iterator it = properties.begin(); it != properties.end(); ++it) { 391 for (PropertySet::iterator it = properties.begin(); it != properties.end(); ++it) {
457 392
458 KeyframeVector values; 393 KeyframeVector values;
459 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati on, compositorTiming.reverse, values); 394 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati on, values);
460 395
461 blink::WebAnimation::TargetProperty targetProperty; 396 blink::WebAnimation::TargetProperty targetProperty;
462 OwnPtr<blink::WebAnimationCurve> curve; 397 OwnPtr<blink::WebAnimationCurve> curve;
463 switch (*it) { 398 switch (*it) {
464 case CSSPropertyOpacity: { 399 case CSSPropertyOpacity: {
465 targetProperty = blink::WebAnimation::TargetPropertyOpacity; 400 targetProperty = blink::WebAnimation::TargetPropertyOpacity;
466 401
467 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current ()->compositorSupport()->createFloatAnimationCurve(); 402 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current ()->compositorSupport()->createFloatAnimationCurve();
468 addKeyframesToCurve(*floatCurve, values, compositorTiming.reverse); 403 addKeyframesToCurve(*floatCurve, values);
469 curve = adoptPtr(floatCurve); 404 curve = adoptPtr(floatCurve);
470 break; 405 break;
471 } 406 }
472 case CSSPropertyWebkitFilter: { 407 case CSSPropertyWebkitFilter: {
473 targetProperty = blink::WebAnimation::TargetPropertyFilter; 408 targetProperty = blink::WebAnimation::TargetPropertyFilter;
474 blink::WebFilterAnimationCurve* filterCurve = blink::Platform::curre nt()->compositorSupport()->createFilterAnimationCurve(); 409 blink::WebFilterAnimationCurve* filterCurve = blink::Platform::curre nt()->compositorSupport()->createFilterAnimationCurve();
475 addKeyframesToCurve(*filterCurve, values, compositorTiming.reverse); 410 addKeyframesToCurve(*filterCurve, values);
476 curve = adoptPtr(filterCurve); 411 curve = adoptPtr(filterCurve);
477 break; 412 break;
478 } 413 }
479 case CSSPropertyWebkitTransform: { 414 case CSSPropertyWebkitTransform: {
480 targetProperty = blink::WebAnimation::TargetPropertyTransform; 415 targetProperty = blink::WebAnimation::TargetPropertyTransform;
481 blink::WebTransformAnimationCurve* transformCurve = blink::Platform: :current()->compositorSupport()->createTransformAnimationCurve(); 416 blink::WebTransformAnimationCurve* transformCurve = blink::Platform: :current()->compositorSupport()->createTransformAnimationCurve();
482 addKeyframesToCurve(*transformCurve, values, compositorTiming.revers e); 417 addKeyframesToCurve(*transformCurve, values);
483 curve = adoptPtr(transformCurve); 418 curve = adoptPtr(transformCurve);
484 break; 419 break;
485 } 420 }
486 default: 421 default:
487 ASSERT_NOT_REACHED(); 422 ASSERT_NOT_REACHED();
488 continue; 423 continue;
489 } 424 }
490 ASSERT(curve.get()); 425 ASSERT(curve.get());
491 426
492 OwnPtr<blink::WebAnimation> animation = adoptPtr(blink::Platform::curren t()->compositorSupport()->createAnimation(*curve, targetProperty)); 427 OwnPtr<blink::WebAnimation> animation = adoptPtr(blink::Platform::curren t()->compositorSupport()->createAnimation(*curve, targetProperty));
493 428
494 animation->setIterations(compositorTiming.adjustedIterationCount); 429 animation->setIterations(compositorTiming.adjustedIterationCount);
495 animation->setTimeOffset(compositorTiming.scaledTimeOffset); 430 animation->setTimeOffset(compositorTiming.scaledTimeOffset);
496 animation->setAlternatesDirection(compositorTiming.alternate); 431
432 switch (compositorTiming.direction) {
433 case Timing::PlaybackDirectionNormal:
434 animation->setDirection(blink::WebAnimation::DirectionNormal);
435 break;
436 case Timing::PlaybackDirectionReverse:
437 animation->setDirection(blink::WebAnimation::DirectionReverse);
438 break;
439 case Timing::PlaybackDirectionAlternate:
440 animation->setDirection(blink::WebAnimation::DirectionAlternate);
441 break;
442 case Timing::PlaybackDirectionAlternateReverse:
443 animation->setDirection(blink::WebAnimation::DirectionAlternateRever se);
444 break;
445 default:
446 ASSERT_NOT_REACHED();
447 }
497 448
498 animations.append(animation.release()); 449 animations.append(animation.release());
499 } 450 }
500 ASSERT(!animations.isEmpty()); 451 ASSERT(!animations.isEmpty());
501 } 452 }
502 453
503 } // namespace WebCore 454 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/CompositorAnimations.h ('k') | Source/core/animation/CompositorAnimationsImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698