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