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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ChainedTimingFunction* timefunc) | |
109 { | |
110 RefPtr<ChainedTimingFunction> reversed = ChainedTimingFunction::create(); | |
111 for (size_t i = 0; i < timefunc->m_segments.size(); i++) { | |
112 size_t index = timefunc->m_segments.size() - i - 1; | |
113 | |
114 RefPtr<TimingFunction> rtf = reverse(timefunc->m_segments[index].m_timin
gFunction.get()); | |
115 reversed->appendSegment(1 - timefunc->m_segments[index].m_min, rtf.get()
); | |
116 } | |
117 return reversed; | |
118 } | |
119 | |
120 PassRefPtr<TimingFunction> CompositorAnimationsTimingFunctionReverser::reverse(c
onst TimingFunction* timefunc) | |
121 { | |
122 switch (timefunc->type()) { | |
123 case TimingFunction::LinearFunction: { | |
124 const LinearTimingFunction* linear = toLinearTimingFunction(timefunc); | |
125 return reverse(linear); | |
126 } | |
127 case TimingFunction::CubicBezierFunction: { | |
128 const CubicBezierTimingFunction* cubic = toCubicBezierTimingFunction(tim
efunc); | |
129 return reverse(cubic); | |
130 } | |
131 case TimingFunction::ChainedFunction: { | |
132 const ChainedTimingFunction* chained = toChainedTimingFunction(timefunc)
; | |
133 return reverse(chained); | |
134 } | |
135 | |
136 // Steps function can not be reversed. | |
137 case TimingFunction::StepsFunction: | |
138 default: | |
139 ASSERT_NOT_REACHED(); | |
140 return PassRefPtr<TimingFunction>(); | |
141 } | |
142 } | |
143 | |
144 // ----------------------------------------------------------------------- | |
145 // CompositorAnimations public API | 75 // CompositorAnimations public API |
146 // ----------------------------------------------------------------------- | 76 // ----------------------------------------------------------------------- |
147 | 77 |
148 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim
ing, const AnimationEffect& effect) | 78 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim
ing, const AnimationEffect& effect) |
149 { | 79 { |
150 const KeyframeEffectModel& keyframeEffect = *toKeyframeEffectModel(&effect); | 80 const KeyframeEffectModel& keyframeEffect = *toKeyframeEffectModel(&effect); |
151 | 81 |
152 // Are the keyframes convertible? | 82 // Are the keyframes convertible? |
153 const KeyframeEffectModel::KeyframeVector frames = keyframeEffect.getFrames(
); | 83 const KeyframeEffectModel::KeyframeVector frames = keyframeEffect.getFrames(
); |
154 for (size_t i = 0; i < frames.size(); ++i) { | 84 for (size_t i = 0; i < frames.size(); ++i) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // All directions are supported. | 262 // All directions are supported. |
333 | 263 |
334 // Now attempt an actual conversion | 264 // Now attempt an actual conversion |
335 out.scaledDuration = timing.iterationDuration; | 265 out.scaledDuration = timing.iterationDuration; |
336 ASSERT(out.scaledDuration > 0); | 266 ASSERT(out.scaledDuration > 0); |
337 | 267 |
338 double scaledStartDelay = timing.startDelay; | 268 double scaledStartDelay = timing.startDelay; |
339 if (scaledStartDelay > 0 && scaledStartDelay > out.scaledDuration * timing.i
terationCount) | 269 if (scaledStartDelay > 0 && scaledStartDelay > out.scaledDuration * timing.i
terationCount) |
340 return false; | 270 return false; |
341 | 271 |
342 out.reverse = (timing.direction == Timing::PlaybackDirectionReverse | 272 out.direction = static_cast<CompositorTiming::Direction>(timing.direction); |
343 || timing.direction == Timing::PlaybackDirectionAlternateReverse); | |
344 out.alternate = (timing.direction == Timing::PlaybackDirectionAlternate | |
345 || timing.direction == Timing::PlaybackDirectionAlternateReverse); | |
346 | 273 |
347 if (!std::isfinite(timing.iterationCount)) { | 274 if (!std::isfinite(timing.iterationCount)) { |
348 out.adjustedIterationCount = -1; | 275 out.adjustedIterationCount = -1; |
349 } else { | 276 } else { |
350 out.adjustedIterationCount = std::floor(timing.iterationCount); | 277 out.adjustedIterationCount = std::floor(timing.iterationCount); |
351 ASSERT(out.adjustedIterationCount > 0); | 278 ASSERT(out.adjustedIterationCount > 0); |
352 } | 279 } |
353 | 280 |
354 // Compositor's time offset is positive for seeking into the animation. | 281 // Compositor's time offset is positive for seeking into the animation. |
355 out.scaledTimeOffset = -scaledStartDelay; | 282 out.scaledTimeOffset = -scaledStartDelay; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 } | 404 } |
478 | 405 |
479 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, co
nst KeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animation
s) | 406 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, co
nst KeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animation
s) |
480 { | 407 { |
481 ASSERT(animations.isEmpty()); | 408 ASSERT(animations.isEmpty()); |
482 CompositorTiming compositorTiming; | 409 CompositorTiming compositorTiming; |
483 bool timingValid = convertTimingForCompositor(timing, compositorTiming); | 410 bool timingValid = convertTimingForCompositor(timing, compositorTiming); |
484 ASSERT_UNUSED(timingValid, timingValid); | 411 ASSERT_UNUSED(timingValid, timingValid); |
485 | 412 |
486 RefPtr<TimingFunction> timingFunction = timing.timingFunction; | 413 RefPtr<TimingFunction> timingFunction = timing.timingFunction; |
487 if (compositorTiming.reverse) | |
488 timingFunction = CompositorAnimationsTimingFunctionReverser::reverse(tim
ingFunction.get()); | |
489 | |
490 PropertySet properties = effect.properties(); | 414 PropertySet properties = effect.properties(); |
491 ASSERT(!properties.isEmpty()); | 415 ASSERT(!properties.isEmpty()); |
492 for (PropertySet::iterator it = properties.begin(); it != properties.end();
++it) { | 416 for (PropertySet::iterator it = properties.begin(); it != properties.end();
++it) { |
493 | 417 |
494 KeyframeVector values; | 418 KeyframeVector values; |
495 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati
on, compositorTiming.reverse, values); | 419 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati
on, values); |
496 | 420 |
497 blink::WebAnimation::TargetProperty targetProperty; | 421 blink::WebAnimation::TargetProperty targetProperty; |
498 OwnPtr<blink::WebAnimationCurve> curve; | 422 OwnPtr<blink::WebAnimationCurve> curve; |
499 switch (*it) { | 423 switch (*it) { |
500 case CSSPropertyOpacity: { | 424 case CSSPropertyOpacity: { |
501 targetProperty = blink::WebAnimation::TargetPropertyOpacity; | 425 targetProperty = blink::WebAnimation::TargetPropertyOpacity; |
502 | 426 |
503 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current
()->compositorSupport()->createFloatAnimationCurve(); | 427 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current
()->compositorSupport()->createFloatAnimationCurve(); |
504 addKeyframesToCurve(*floatCurve, values, *timingFunction.get()); | 428 addKeyframesToCurve(*floatCurve, values, *timingFunction.get()); |
505 curve = adoptPtr(floatCurve); | 429 curve = adoptPtr(floatCurve); |
(...skipping 16 matching lines...) Expand all Loading... |
522 default: | 446 default: |
523 ASSERT_NOT_REACHED(); | 447 ASSERT_NOT_REACHED(); |
524 continue; | 448 continue; |
525 } | 449 } |
526 ASSERT(curve.get()); | 450 ASSERT(curve.get()); |
527 | 451 |
528 OwnPtr<blink::WebAnimation> animation = adoptPtr(blink::Platform::curren
t()->compositorSupport()->createAnimation(*curve, targetProperty)); | 452 OwnPtr<blink::WebAnimation> animation = adoptPtr(blink::Platform::curren
t()->compositorSupport()->createAnimation(*curve, targetProperty)); |
529 | 453 |
530 animation->setIterations(compositorTiming.adjustedIterationCount); | 454 animation->setIterations(compositorTiming.adjustedIterationCount); |
531 animation->setTimeOffset(compositorTiming.scaledTimeOffset); | 455 animation->setTimeOffset(compositorTiming.scaledTimeOffset); |
532 animation->setAlternatesDirection(compositorTiming.alternate); | 456 animation->setDirection(static_cast<blink::WebAnimation::Direction>(comp
ositorTiming.direction)); |
533 | 457 |
534 animations.append(animation.release()); | 458 animations.append(animation.release()); |
535 } | 459 } |
536 ASSERT(!animations.isEmpty()); | 460 ASSERT(!animations.isEmpty()); |
537 } | 461 } |
538 | 462 |
539 } // namespace WebCore | 463 } // namespace WebCore |
OLD | NEW |