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 KeyframeEffectModelBase* effect, CSSProp
ertyID id, double scale, bool reverse, PropertySpecificKeyframeVector& values) |
62 { | 62 { |
63 ASSERT(values.isEmpty()); | 63 ASSERT(values.isEmpty()); |
64 const KeyframeVector& group = effect->getPropertySpecificKeyframes(id); | 64 const PropertySpecificKeyframeVector& group = effect->getPropertySpecificKey
frames(id); |
65 | 65 |
66 if (reverse) { | 66 if (reverse) { |
67 for (size_t i = group.size(); i--;) { | 67 for (size_t i = group.size(); i--;) { |
68 double offset = (1 - group[i]->offset()) * scale; | 68 double offset = (1 - group[i]->offset()) * scale; |
69 values.append(group[i]->cloneWithOffset(offset)); | 69 values.append(group[i]->cloneWithOffset(offset)); |
70 } | 70 } |
71 } else { | 71 } else { |
72 for (size_t i = 0; i < group.size(); ++i) { | 72 for (size_t i = 0; i < group.size(); ++i) { |
73 double offset = group[i]->offset() * scale; | 73 double offset = group[i]->offset() * scale; |
74 values.append(group[i]->cloneWithOffset(offset)); | 74 values.append(group[i]->cloneWithOffset(offset)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return PassRefPtr<TimingFunction>(); | 124 return PassRefPtr<TimingFunction>(); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 // ----------------------------------------------------------------------- | 128 // ----------------------------------------------------------------------- |
129 // CompositorAnimations public API | 129 // CompositorAnimations public API |
130 // ----------------------------------------------------------------------- | 130 // ----------------------------------------------------------------------- |
131 | 131 |
132 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim
ing, const AnimationEffect& effect) | 132 bool CompositorAnimations::isCandidateForAnimationOnCompositor(const Timing& tim
ing, const AnimationEffect& effect) |
133 { | 133 { |
134 const KeyframeEffectModel& keyframeEffect = *toKeyframeEffectModel(&effect); | 134 const AnimatableValueKeyframeEffectModel& keyframeEffect = *toAnimatableValu
eKeyframeEffectModel(&effect); |
135 | 135 |
136 // Are the keyframes convertible? | 136 // Are the keyframes convertible? |
137 const KeyframeEffectModel::KeyframeVector frames = keyframeEffect.getFrames(
); | 137 const KeyframeVector frames = keyframeEffect.getFrames(); |
138 for (size_t i = 0; i < frames.size(); ++i) { | 138 for (size_t i = 0; i < frames.size(); ++i) { |
139 // Only replace mode can be accelerated | 139 // Only replace mode can be accelerated |
140 if (frames[i]->composite() != AnimationEffect::CompositeReplace) | 140 if (frames[i]->composite() != AnimationEffect::CompositeReplace) |
141 return false; | 141 return false; |
142 | 142 |
143 // Check all the properties can be accelerated | 143 // Check all the properties can be accelerated |
144 const PropertySet properties = frames[i]->properties(); // FIXME: proper
ties creates a whole new PropertySet! | 144 const PropertySet properties = frames[i]->properties(); // FIXME: proper
ties creates a whole new PropertySet! |
145 | 145 |
146 if (properties.isEmpty()) | 146 if (properties.isEmpty()) |
147 return false; | 147 return false; |
148 | 148 |
| 149 AnimatableValueKeyframe* frame = toAnimatableValueKeyframe(frames[i].get
()); |
| 150 |
149 for (PropertySet::const_iterator it = properties.begin(); it != properti
es.end(); ++it) { | 151 for (PropertySet::const_iterator it = properties.begin(); it != properti
es.end(); ++it) { |
150 switch (*it) { | 152 switch (*it) { |
151 case CSSPropertyOpacity: | 153 case CSSPropertyOpacity: |
152 continue; | 154 continue; |
153 case CSSPropertyTransform: | 155 case CSSPropertyTransform: |
154 if (toAnimatableTransform(frames[i]->propertyValue(CSSPropertyTr
ansform))->transformOperations().dependsOnBoxSize()) | 156 if (toAnimatableTransform(frame->propertyValue(CSSPropertyTransf
orm))->transformOperations().dependsOnBoxSize()) |
155 return false; | 157 return false; |
156 continue; | 158 continue; |
157 case CSSPropertyWebkitFilter: { | 159 case CSSPropertyWebkitFilter: { |
158 const FilterOperations& operations = toAnimatableFilterOperation
s(frames[i]->propertyValue(CSSPropertyWebkitFilter))->operations(); | 160 const FilterOperations& operations = toAnimatableFilterOperation
s(frame->propertyValue(CSSPropertyWebkitFilter))->operations(); |
159 if (operations.hasFilterThatMovesPixels()) | 161 if (operations.hasFilterThatMovesPixels()) |
160 return false; | 162 return false; |
161 for (size_t i = 0; i < operations.size(); i++) { | 163 for (size_t i = 0; i < operations.size(); i++) { |
162 const FilterOperation& op = *operations.at(i); | 164 const FilterOperation& op = *operations.at(i); |
163 if (op.type() == FilterOperation::VALIDATED_CUSTOM || op.typ
e() == FilterOperation::CUSTOM) | 165 if (op.type() == FilterOperation::VALIDATED_CUSTOM || op.typ
e() == FilterOperation::CUSTOM) |
164 return false; | 166 return false; |
165 } | 167 } |
166 continue; | 168 continue; |
167 } | 169 } |
168 default: | 170 default: |
(...skipping 25 matching lines...) Expand all Loading... |
194 | 196 |
195 default: | 197 default: |
196 ASSERT_NOT_REACHED(); | 198 ASSERT_NOT_REACHED(); |
197 return false; | 199 return false; |
198 } | 200 } |
199 | 201 |
200 if (frames.size() < 2) | 202 if (frames.size() < 2) |
201 return false; | 203 return false; |
202 | 204 |
203 // Search for any segments with StepsFunction. | 205 // Search for any segments with StepsFunction. |
204 WillBeHeapVector<RefPtrWillBeMember<Keyframe> >::const_iterator end = keyfra
meEffect.getFrames().end() - 1; // Ignore timing function of last frame. | 206 WillBeHeapVector<RefPtrWillBeMember<Keyframe> >::const_iterator end = frames
.end() - 1; // Ignore timing function of last frame. |
205 for (WillBeHeapVector<RefPtrWillBeMember<Keyframe> >::const_iterator iter =
keyframeEffect.getFrames().begin(); iter != end; ++iter) { | 207 for (WillBeHeapVector<RefPtrWillBeMember<Keyframe> >::const_iterator iter =
frames.begin(); iter != end; ++iter) { |
206 RELEASE_ASSERT((*iter)->easing()); | 208 RELEASE_ASSERT((*iter)->easing()); |
207 switch ((*iter)->easing()->type()) { | 209 switch ((*iter)->easing()->type()) { |
208 case TimingFunction::LinearFunction: | 210 case TimingFunction::LinearFunction: |
209 case TimingFunction::CubicBezierFunction: | 211 case TimingFunction::CubicBezierFunction: |
210 continue; | 212 continue; |
211 | 213 |
212 case TimingFunction::StepsFunction: | 214 case TimingFunction::StepsFunction: |
213 return false; | 215 return false; |
214 default: | 216 default: |
215 ASSERT_NOT_REACHED(); | 217 ASSERT_NOT_REACHED(); |
216 return false; | 218 return false; |
217 } | 219 } |
218 } | 220 } |
219 | 221 |
220 return true; | 222 return true; |
221 } | 223 } |
222 | 224 |
223 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element) | 225 bool CompositorAnimations::canStartAnimationOnCompositor(const Element& element) |
224 { | 226 { |
225 return element.renderer() && element.renderer()->compositingState() == Paint
sIntoOwnBacking; | 227 return element.renderer() && element.renderer()->compositingState() == Paint
sIntoOwnBacking; |
226 } | 228 } |
227 | 229 |
228 bool CompositorAnimations::startAnimationOnCompositor(const Element& element, co
nst Timing& timing, const AnimationEffect& effect, Vector<int>& startedAnimation
Ids) | 230 bool CompositorAnimations::startAnimationOnCompositor(const Element& element, co
nst Timing& timing, const AnimationEffect& effect, Vector<int>& startedAnimation
Ids) |
229 { | 231 { |
230 ASSERT(startedAnimationIds.isEmpty()); | 232 ASSERT(startedAnimationIds.isEmpty()); |
231 ASSERT(isCandidateForAnimationOnCompositor(timing, effect)); | 233 ASSERT(isCandidateForAnimationOnCompositor(timing, effect)); |
232 ASSERT(canStartAnimationOnCompositor(element)); | 234 ASSERT(canStartAnimationOnCompositor(element)); |
233 | 235 |
234 const KeyframeEffectModel& keyframeEffect = *toKeyframeEffectModel(&effect); | 236 const AnimatableValueKeyframeEffectModel& keyframeEffect = *toAnimatableValu
eKeyframeEffectModel(&effect); |
235 | 237 |
236 RenderLayer* layer = toRenderBoxModelObject(element.renderer())->layer(); | 238 RenderLayer* layer = toRenderBoxModelObject(element.renderer())->layer(); |
237 ASSERT(layer); | 239 ASSERT(layer); |
238 | 240 |
239 Vector<OwnPtr<blink::WebAnimation> > animations; | 241 Vector<OwnPtr<blink::WebAnimation> > animations; |
240 CompositorAnimationsImpl::getAnimationOnCompositor(timing, keyframeEffect, a
nimations); | 242 CompositorAnimationsImpl::getAnimationOnCompositor(timing, keyframeEffect, a
nimations); |
241 ASSERT(!animations.isEmpty()); | 243 ASSERT(!animations.isEmpty()); |
242 for (size_t i = 0; i < animations.size(); ++i) { | 244 for (size_t i = 0; i < animations.size(); ++i) { |
243 int id = animations[i]->id(); | 245 int id = animations[i]->id(); |
244 if (!layer->compositedLayerMapping()->mainGraphicsLayer()->addAnimation(
animations[i].release())) { | 246 if (!layer->compositedLayerMapping()->mainGraphicsLayer()->addAnimation(
animations[i].release())) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 386 |
385 case TimingFunction::StepsFunction: | 387 case TimingFunction::StepsFunction: |
386 default: | 388 default: |
387 ASSERT_NOT_REACHED(); | 389 ASSERT_NOT_REACHED(); |
388 return; | 390 return; |
389 } | 391 } |
390 } | 392 } |
391 | 393 |
392 } // namespace anoymous | 394 } // namespace anoymous |
393 | 395 |
394 void CompositorAnimationsImpl::addKeyframesToCurve(blink::WebAnimationCurve& cur
ve, const KeyframeVector& keyframes, bool reverse) | 396 void CompositorAnimationsImpl::addKeyframesToCurve(blink::WebAnimationCurve& cur
ve, const PropertySpecificKeyframeVector& keyframes, bool reverse) |
395 { | 397 { |
396 for (size_t i = 0; i < keyframes.size(); i++) { | 398 for (size_t i = 0; i < keyframes.size(); i++) { |
397 RefPtr<TimingFunction> reversedTimingFunction; | 399 RefPtr<TimingFunction> reversedTimingFunction; |
398 const TimingFunction* keyframeTimingFunction = 0; | 400 const TimingFunction* keyframeTimingFunction = 0; |
399 if (i < keyframes.size() - 1) { // Ignore timing function of last frame. | 401 if (i < keyframes.size() - 1) { // Ignore timing function of last frame. |
400 if (reverse) { | 402 if (reverse) { |
401 reversedTimingFunction = CompositorAnimationsTimingFunctionRever
ser::reverse(keyframes[i + 1]->easing()); | 403 reversedTimingFunction = CompositorAnimationsTimingFunctionRever
ser::reverse(keyframes[i + 1]->easing()); |
402 keyframeTimingFunction = reversedTimingFunction.get(); | 404 keyframeTimingFunction = reversedTimingFunction.get(); |
403 } else { | 405 } else { |
404 keyframeTimingFunction = keyframes[i]->easing(); | 406 keyframeTimingFunction = keyframes[i]->easing(); |
405 } | 407 } |
406 } | 408 } |
407 | 409 |
408 const AnimatableValue* value = keyframes[i]->value(); | 410 const AnimatableValue* value = toAnimatableValuePropertySpecificKeyframe
(keyframes[i].get())->value(); |
409 | 411 |
410 switch (curve.type()) { | 412 switch (curve.type()) { |
411 case blink::WebAnimationCurve::AnimationCurveTypeFilter: { | 413 case blink::WebAnimationCurve::AnimationCurveTypeFilter: { |
412 OwnPtr<blink::WebFilterOperations> ops = adoptPtr(blink::Platform::c
urrent()->compositorSupport()->createFilterOperations()); | 414 OwnPtr<blink::WebFilterOperations> ops = adoptPtr(blink::Platform::c
urrent()->compositorSupport()->createFilterOperations()); |
413 bool converted = toWebFilterOperations(toAnimatableFilterOperations(
value)->operations(), ops.get()); | 415 bool converted = toWebFilterOperations(toAnimatableFilterOperations(
value)->operations(), ops.get()); |
414 ASSERT_UNUSED(converted, converted); | 416 ASSERT_UNUSED(converted, converted); |
415 | 417 |
416 blink::WebFilterKeyframe filterKeyframe(keyframes[i]->offset(), ops.
release()); | 418 blink::WebFilterKeyframe filterKeyframe(keyframes[i]->offset(), ops.
release()); |
417 blink::WebFilterAnimationCurve* filterCurve = static_cast<blink::Web
FilterAnimationCurve*>(&curve); | 419 blink::WebFilterAnimationCurve* filterCurve = static_cast<blink::Web
FilterAnimationCurve*>(&curve); |
418 addKeyframeWithTimingFunction(*filterCurve, filterKeyframe, keyframe
TimingFunction); | 420 addKeyframeWithTimingFunction(*filterCurve, filterKeyframe, keyframe
TimingFunction); |
(...skipping 13 matching lines...) Expand all Loading... |
432 blink::WebTransformAnimationCurve* transformCurve = static_cast<blin
k::WebTransformAnimationCurve*>(&curve); | 434 blink::WebTransformAnimationCurve* transformCurve = static_cast<blin
k::WebTransformAnimationCurve*>(&curve); |
433 addKeyframeWithTimingFunction(*transformCurve, transformKeyframe, ke
yframeTimingFunction); | 435 addKeyframeWithTimingFunction(*transformCurve, transformKeyframe, ke
yframeTimingFunction); |
434 break; | 436 break; |
435 } | 437 } |
436 default: | 438 default: |
437 ASSERT_NOT_REACHED(); | 439 ASSERT_NOT_REACHED(); |
438 } | 440 } |
439 } | 441 } |
440 } | 442 } |
441 | 443 |
442 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, co
nst KeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimation> >& animation
s) | 444 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, co
nst AnimatableValueKeyframeEffectModel& effect, Vector<OwnPtr<blink::WebAnimatio
n> >& animations) |
443 { | 445 { |
444 ASSERT(animations.isEmpty()); | 446 ASSERT(animations.isEmpty()); |
445 CompositorTiming compositorTiming; | 447 CompositorTiming compositorTiming; |
446 bool timingValid = convertTimingForCompositor(timing, compositorTiming); | 448 bool timingValid = convertTimingForCompositor(timing, compositorTiming); |
447 ASSERT_UNUSED(timingValid, timingValid); | 449 ASSERT_UNUSED(timingValid, timingValid); |
448 | 450 |
449 RefPtr<TimingFunction> timingFunction = timing.timingFunction; | 451 RefPtr<TimingFunction> timingFunction = timing.timingFunction; |
450 if (compositorTiming.reverse) | 452 if (compositorTiming.reverse) |
451 timingFunction = CompositorAnimationsTimingFunctionReverser::reverse(tim
ingFunction.get()); | 453 timingFunction = CompositorAnimationsTimingFunctionReverser::reverse(tim
ingFunction.get()); |
452 | 454 |
453 PropertySet properties = effect.properties(); | 455 PropertySet properties = effect.properties(); |
454 ASSERT(!properties.isEmpty()); | 456 ASSERT(!properties.isEmpty()); |
455 for (PropertySet::iterator it = properties.begin(); it != properties.end();
++it) { | 457 for (PropertySet::iterator it = properties.begin(); it != properties.end();
++it) { |
456 | 458 |
457 KeyframeVector values; | 459 PropertySpecificKeyframeVector values; |
458 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati
on, compositorTiming.reverse, values); | 460 getKeyframeValuesForProperty(&effect, *it, compositorTiming.scaledDurati
on, compositorTiming.reverse, values); |
459 | 461 |
460 blink::WebAnimation::TargetProperty targetProperty; | 462 blink::WebAnimation::TargetProperty targetProperty; |
461 OwnPtr<blink::WebAnimationCurve> curve; | 463 OwnPtr<blink::WebAnimationCurve> curve; |
462 switch (*it) { | 464 switch (*it) { |
463 case CSSPropertyOpacity: { | 465 case CSSPropertyOpacity: { |
464 targetProperty = blink::WebAnimation::TargetPropertyOpacity; | 466 targetProperty = blink::WebAnimation::TargetPropertyOpacity; |
465 | 467 |
466 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current
()->compositorSupport()->createFloatAnimationCurve(); | 468 blink::WebFloatAnimationCurve* floatCurve = blink::Platform::current
()->compositorSupport()->createFloatAnimationCurve(); |
467 addKeyframesToCurve(*floatCurve, values, compositorTiming.reverse); | 469 addKeyframesToCurve(*floatCurve, values, compositorTiming.reverse); |
(...skipping 25 matching lines...) Expand all Loading... |
493 animation->setIterations(compositorTiming.adjustedIterationCount); | 495 animation->setIterations(compositorTiming.adjustedIterationCount); |
494 animation->setTimeOffset(compositorTiming.scaledTimeOffset); | 496 animation->setTimeOffset(compositorTiming.scaledTimeOffset); |
495 animation->setAlternatesDirection(compositorTiming.alternate); | 497 animation->setAlternatesDirection(compositorTiming.alternate); |
496 | 498 |
497 animations.append(animation.release()); | 499 animations.append(animation.release()); |
498 } | 500 } |
499 ASSERT(!animations.isEmpty()); | 501 ASSERT(!animations.isEmpty()); |
500 } | 502 } |
501 | 503 |
502 } // namespace WebCore | 504 } // namespace WebCore |
OLD | NEW |