| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/animation/CompositorAnimations.h" | 31 #include "core/animation/CompositorAnimations.h" |
| 32 | 32 |
| 33 #include "core/animation/AnimationEffect.h" | 33 #include "core/animation/AnimationEffect.h" |
| 34 #include "core/animation/CompositorAnimationsImpl.h" | |
| 35 #include "core/animation/ElementAnimations.h" | 34 #include "core/animation/ElementAnimations.h" |
| 35 #include "core/animation/KeyframeEffectModel.h" |
| 36 #include "core/animation/animatable/AnimatableDouble.h" | 36 #include "core/animation/animatable/AnimatableDouble.h" |
| 37 #include "core/animation/animatable/AnimatableFilterOperations.h" | 37 #include "core/animation/animatable/AnimatableFilterOperations.h" |
| 38 #include "core/animation/animatable/AnimatableTransform.h" | 38 #include "core/animation/animatable/AnimatableTransform.h" |
| 39 #include "core/animation/animatable/AnimatableValue.h" | 39 #include "core/animation/animatable/AnimatableValue.h" |
| 40 #include "core/layout/LayoutBoxModelObject.h" | 40 #include "core/layout/LayoutBoxModelObject.h" |
| 41 #include "core/layout/LayoutObject.h" | 41 #include "core/layout/LayoutObject.h" |
| 42 #include "core/layout/compositing/CompositedLayerMapping.h" | 42 #include "core/layout/compositing/CompositedLayerMapping.h" |
| 43 #include "core/paint/PaintLayer.h" | 43 #include "core/paint/PaintLayer.h" |
| 44 #include "platform/RuntimeEnabledFeatures.h" | |
| 45 #include "platform/animation/AnimationTranslationUtil.h" | 44 #include "platform/animation/AnimationTranslationUtil.h" |
| 46 #include "platform/animation/CompositorAnimation.h" | 45 #include "platform/animation/CompositorAnimation.h" |
| 47 #include "platform/animation/CompositorAnimationPlayer.h" | 46 #include "platform/animation/CompositorAnimationPlayer.h" |
| 48 #include "platform/animation/CompositorFilterAnimationCurve.h" | 47 #include "platform/animation/CompositorFilterAnimationCurve.h" |
| 49 #include "platform/animation/CompositorFilterKeyframe.h" | 48 #include "platform/animation/CompositorFilterKeyframe.h" |
| 50 #include "platform/animation/CompositorFloatAnimationCurve.h" | 49 #include "platform/animation/CompositorFloatAnimationCurve.h" |
| 51 #include "platform/animation/CompositorFloatKeyframe.h" | 50 #include "platform/animation/CompositorFloatKeyframe.h" |
| 52 #include "platform/animation/CompositorTransformAnimationCurve.h" | 51 #include "platform/animation/CompositorTransformAnimationCurve.h" |
| 53 #include "platform/animation/CompositorTransformKeyframe.h" | 52 #include "platform/animation/CompositorTransformKeyframe.h" |
| 54 #include "platform/geometry/FloatBox.h" | 53 #include "platform/geometry/FloatBox.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 || (affectsFilter && attachedAnimation->affects(targetElement, CSSPr
opertyWebkitFilter)) | 133 || (affectsFilter && attachedAnimation->affects(targetElement, CSSPr
opertyWebkitFilter)) |
| 135 || (affectsBackdropFilter && attachedAnimation->affects(targetElemen
t, CSSPropertyBackdropFilter))) | 134 || (affectsBackdropFilter && attachedAnimation->affects(targetElemen
t, CSSPropertyBackdropFilter))) |
| 136 return true; | 135 return true; |
| 137 } | 136 } |
| 138 | 137 |
| 139 return false; | 138 return false; |
| 140 } | 139 } |
| 141 | 140 |
| 142 } // namespace | 141 } // namespace |
| 143 | 142 |
| 144 CompositorAnimations::CompositorAnimations() | |
| 145 { | |
| 146 } | |
| 147 | |
| 148 CompositorAnimations* CompositorAnimations::instance(CompositorAnimations* newIn
stance) | |
| 149 { | |
| 150 static CompositorAnimations* instance = new CompositorAnimations(); | |
| 151 if (newInstance) { | |
| 152 instance = newInstance; | |
| 153 } | |
| 154 return instance; | |
| 155 } | |
| 156 | |
| 157 bool CompositorAnimations::isCompositableProperty(CSSPropertyID property) | 143 bool CompositorAnimations::isCompositableProperty(CSSPropertyID property) |
| 158 { | 144 { |
| 159 for (CSSPropertyID id : compositableProperties) { | 145 for (CSSPropertyID id : compositableProperties) { |
| 160 if (property == id) | 146 if (property == id) |
| 161 return true; | 147 return true; |
| 162 } | 148 } |
| 163 return false; | 149 return false; |
| 164 } | 150 } |
| 165 | 151 |
| 166 const CSSPropertyID CompositorAnimations::compositableProperties[7] = { | 152 const CSSPropertyID CompositorAnimations::compositableProperties[7] = { |
| 167 CSSPropertyOpacity, | 153 CSSPropertyOpacity, |
| 168 CSSPropertyRotate, | 154 CSSPropertyRotate, |
| 169 CSSPropertyScale, | 155 CSSPropertyScale, |
| 170 CSSPropertyTransform, | 156 CSSPropertyTransform, |
| 171 CSSPropertyTranslate, | 157 CSSPropertyTranslate, |
| 172 CSSPropertyWebkitFilter, | 158 CSSPropertyWebkitFilter, |
| 173 CSSPropertyBackdropFilter | 159 CSSPropertyBackdropFilter |
| 174 }; | 160 }; |
| 175 | 161 |
| 176 bool CompositorAnimations::getAnimatedBoundingBox(FloatBox& box, const EffectMod
el& effect, double minValue, double maxValue) const | 162 bool CompositorAnimations::getAnimatedBoundingBox(FloatBox& box, const EffectMod
el& effect, double minValue, double maxValue) |
| 177 { | 163 { |
| 178 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef
fect); | 164 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef
fect); |
| 179 | 165 |
| 180 PropertyHandleSet properties = keyframeEffect.properties(); | 166 PropertyHandleSet properties = keyframeEffect.properties(); |
| 181 | 167 |
| 182 if (properties.isEmpty()) | 168 if (properties.isEmpty()) |
| 183 return true; | 169 return true; |
| 184 | 170 |
| 185 minValue = std::min(minValue, 0.0); | 171 minValue = std::min(minValue, 0.0); |
| 186 maxValue = std::max(maxValue, 1.0); | 172 maxValue = std::max(maxValue, 1.0); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 278 } |
| 293 } | 279 } |
| 294 | 280 |
| 295 // TODO: Support multiple transform property animations on the compositor | 281 // TODO: Support multiple transform property animations on the compositor |
| 296 if (transformPropertyCount > 1) | 282 if (transformPropertyCount > 1) |
| 297 return false; | 283 return false; |
| 298 | 284 |
| 299 if (animationToAdd && hasIncompatibleAnimations(targetElement, *animationToA
dd, effect)) | 285 if (animationToAdd && hasIncompatibleAnimations(targetElement, *animationToA
dd, effect)) |
| 300 return false; | 286 return false; |
| 301 | 287 |
| 302 CompositorAnimationsImpl::CompositorTiming out; | 288 CompositorTiming out; |
| 303 if (!CompositorAnimationsImpl::convertTimingForCompositor(timing, 0, out, an
imationPlaybackRate)) | 289 if (!convertTimingForCompositor(timing, 0, out, animationPlaybackRate)) |
| 304 return false; | 290 return false; |
| 305 | 291 |
| 306 return true; | 292 return true; |
| 307 } | 293 } |
| 308 | 294 |
| 309 void CompositorAnimations::cancelIncompatibleAnimationsOnCompositor(const Elemen
t& targetElement, const Animation& animationToAdd, const EffectModel& effectToAd
d) | 295 void CompositorAnimations::cancelIncompatibleAnimationsOnCompositor(const Elemen
t& targetElement, const Animation& animationToAdd, const EffectModel& effectToAd
d) |
| 310 { | 296 { |
| 311 const bool affectsOpacity = effectToAdd.affects(PropertyHandle(CSSPropertyOp
acity)); | 297 const bool affectsOpacity = effectToAdd.affects(PropertyHandle(CSSPropertyOp
acity)); |
| 312 const bool affectsTransform = effectToAdd.isTransformRelatedEffect(); | 298 const bool affectsTransform = effectToAdd.isTransformRelatedEffect(); |
| 313 const bool affectsFilter = effectToAdd.affects(PropertyHandle(CSSPropertyWeb
kitFilter)); | 299 const bool affectsFilter = effectToAdd.affects(PropertyHandle(CSSPropertyWeb
kitFilter)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 341 | 327 |
| 342 void CompositorAnimations::startAnimationOnCompositor(const Element& element, in
t group, double startTime, double timeOffset, const Timing& timing, const Animat
ion& animation, const EffectModel& effect, Vector<int>& startedAnimationIds, dou
ble animationPlaybackRate) | 328 void CompositorAnimations::startAnimationOnCompositor(const Element& element, in
t group, double startTime, double timeOffset, const Timing& timing, const Animat
ion& animation, const EffectModel& effect, Vector<int>& startedAnimationIds, dou
ble animationPlaybackRate) |
| 343 { | 329 { |
| 344 ASSERT(startedAnimationIds.isEmpty()); | 330 ASSERT(startedAnimationIds.isEmpty()); |
| 345 ASSERT(isCandidateForAnimationOnCompositor(timing, element, &animation, effe
ct, animationPlaybackRate)); | 331 ASSERT(isCandidateForAnimationOnCompositor(timing, element, &animation, effe
ct, animationPlaybackRate)); |
| 346 ASSERT(canStartAnimationOnCompositor(element)); | 332 ASSERT(canStartAnimationOnCompositor(element)); |
| 347 | 333 |
| 348 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef
fect); | 334 const KeyframeEffectModelBase& keyframeEffect = toKeyframeEffectModelBase(ef
fect); |
| 349 | 335 |
| 350 Vector<OwnPtr<CompositorAnimation>> animations; | 336 Vector<OwnPtr<CompositorAnimation>> animations; |
| 351 CompositorAnimationsImpl::getAnimationOnCompositor(timing, group, startTime,
timeOffset, keyframeEffect, animations, animationPlaybackRate); | 337 getAnimationOnCompositor(timing, group, startTime, timeOffset, keyframeEffec
t, animations, animationPlaybackRate); |
| 352 ASSERT(!animations.isEmpty()); | 338 ASSERT(!animations.isEmpty()); |
| 353 for (auto& compositorAnimation : animations) { | 339 for (auto& compositorAnimation : animations) { |
| 354 int id = compositorAnimation->id(); | 340 int id = compositorAnimation->id(); |
| 355 CompositorAnimationPlayer* compositorPlayer = animation.compositorPlayer
(); | 341 CompositorAnimationPlayer* compositorPlayer = animation.compositorPlayer
(); |
| 356 ASSERT(compositorPlayer); | 342 ASSERT(compositorPlayer); |
| 357 compositorPlayer->addAnimation(compositorAnimation.leakPtr()); | 343 compositorPlayer->addAnimation(compositorAnimation.leakPtr()); |
| 358 startedAnimationIds.append(id); | 344 startedAnimationIds.append(id); |
| 359 } | 345 } |
| 360 ASSERT(!startedAnimationIds.isEmpty()); | 346 ASSERT(!startedAnimationIds.isEmpty()); |
| 361 } | 347 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 PaintLayer* layer = toLayoutBoxModelObject(element.layoutObject())->layer(); | 404 PaintLayer* layer = toLayoutBoxModelObject(element.layoutObject())->layer(); |
| 419 ASSERT(layer); | 405 ASSERT(layer); |
| 420 | 406 |
| 421 CompositorAnimationPlayer* compositorPlayer = animation.compositorPlayer(); | 407 CompositorAnimationPlayer* compositorPlayer = animation.compositorPlayer(); |
| 422 ASSERT(compositorPlayer); | 408 ASSERT(compositorPlayer); |
| 423 | 409 |
| 424 ASSERT(layer->compositedLayerMapping()); | 410 ASSERT(layer->compositedLayerMapping()); |
| 425 compositorPlayer->attachLayer(layer->compositedLayerMapping()->mainGraphicsL
ayer()->platformLayer()); | 411 compositorPlayer->attachLayer(layer->compositedLayerMapping()->mainGraphicsL
ayer()->platformLayer()); |
| 426 } | 412 } |
| 427 | 413 |
| 428 // ----------------------------------------------------------------------- | 414 bool CompositorAnimations::convertTimingForCompositor(const Timing& timing, doub
le timeOffset, CompositorTiming& out, double animationPlaybackRate) |
| 429 // CompositorAnimationsImpl | |
| 430 // ----------------------------------------------------------------------- | |
| 431 | |
| 432 bool CompositorAnimationsImpl::convertTimingForCompositor(const Timing& timing,
double timeOffset, CompositorTiming& out, double animationPlaybackRate) | |
| 433 { | 415 { |
| 434 timing.assertValid(); | 416 timing.assertValid(); |
| 435 | 417 |
| 436 // FIXME: Compositor does not know anything about endDelay. | 418 // FIXME: Compositor does not know anything about endDelay. |
| 437 if (timing.endDelay != 0) | 419 if (timing.endDelay != 0) |
| 438 return false; | 420 return false; |
| 439 | 421 |
| 440 if (std::isnan(timing.iterationDuration) || !timing.iterationCount || !timin
g.iterationDuration) | 422 if (std::isnan(timing.iterationDuration) || !timing.iterationCount || !timin
g.iterationDuration) |
| 441 return false; | 423 return false; |
| 442 | 424 |
| 443 if (!std::isfinite(timing.iterationCount)) { | 425 out.adjustedIterationCount = std::isfinite(timing.iterationCount) ? timing.i
terationCount : -1; |
| 444 out.adjustedIterationCount = -1; | |
| 445 } else { | |
| 446 out.adjustedIterationCount = timing.iterationCount; | |
| 447 } | |
| 448 | |
| 449 out.scaledDuration = timing.iterationDuration; | 426 out.scaledDuration = timing.iterationDuration; |
| 450 out.direction = timing.direction; | 427 out.direction = timing.direction; |
| 451 // Compositor's time offset is positive for seeking into the animation. | 428 // Compositor's time offset is positive for seeking into the animation. |
| 452 out.scaledTimeOffset = -timing.startDelay / animationPlaybackRate + timeOffs
et; | 429 out.scaledTimeOffset = -timing.startDelay / animationPlaybackRate + timeOffs
et; |
| 453 out.playbackRate = timing.playbackRate * animationPlaybackRate; | 430 out.playbackRate = timing.playbackRate * animationPlaybackRate; |
| 454 out.fillMode = timing.fillMode == Timing::FillModeAuto ? Timing::FillModeNon
e : timing.fillMode; | 431 out.fillMode = timing.fillMode == Timing::FillModeAuto ? Timing::FillModeNon
e : timing.fillMode; |
| 455 out.iterationStart = timing.iterationStart; | 432 out.iterationStart = timing.iterationStart; |
| 456 out.assertValid(); | 433 |
| 434 DCHECK_GT(out.scaledDuration, 0); |
| 435 DCHECK(std::isfinite(out.scaledTimeOffset)); |
| 436 DCHECK(out.adjustedIterationCount > 0 || out.adjustedIterationCount == -1); |
| 437 DCHECK(std::isfinite(out.playbackRate) && out.playbackRate); |
| 438 DCHECK_GE(out.iterationStart, 0); |
| 439 |
| 457 return true; | 440 return true; |
| 458 } | 441 } |
| 459 | 442 |
| 460 namespace { | 443 namespace { |
| 461 | 444 |
| 462 template<typename PlatformAnimationCurveType, typename PlatformAnimationKeyframe
Type> | 445 template<typename PlatformAnimationCurveType, typename PlatformAnimationKeyframe
Type> |
| 463 void addCompositorKeyframeWithTimingFunction(PlatformAnimationCurveType& curve,
const PlatformAnimationKeyframeType& keyframe, const TimingFunction* timingFunct
ion) | 446 void addCompositorKeyframeWithTimingFunction(PlatformAnimationCurveType& curve,
const PlatformAnimationKeyframeType& keyframe, const TimingFunction* timingFunct
ion) |
| 464 { | 447 { |
| 465 if (!timingFunction) { | 448 if (!timingFunction) { |
| 466 curve.addCubicBezierKeyframe(keyframe, CubicBezierTimingFunction::EaseTy
pe::EASE); | 449 curve.addCubicBezierKeyframe(keyframe, CubicBezierTimingFunction::EaseTy
pe::EASE); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 // not happen eventually. Instead we should extract the CSSValue here | 549 // not happen eventually. Instead we should extract the CSSValue here |
| 567 // and convert using another set of toAnimatableXXXOperations functions. | 550 // and convert using another set of toAnimatableXXXOperations functions. |
| 568 const AnimatableValue* value = keyframe->getAnimatableValue().get(); | 551 const AnimatableValue* value = keyframe->getAnimatableValue().get(); |
| 569 | 552 |
| 570 addKeyframeToCurve(curve, keyframe.get(), value, keyframeTimingFunction)
; | 553 addKeyframeToCurve(curve, keyframe.get(), value, keyframeTimingFunction)
; |
| 571 } | 554 } |
| 572 } | 555 } |
| 573 | 556 |
| 574 } // namespace | 557 } // namespace |
| 575 | 558 |
| 576 void CompositorAnimationsImpl::getAnimationOnCompositor(const Timing& timing, in
t group, double startTime, double timeOffset, const KeyframeEffectModelBase& eff
ect, Vector<OwnPtr<CompositorAnimation>>& animations, double animationPlaybackRa
te) | 559 void CompositorAnimations::getAnimationOnCompositor(const Timing& timing, int gr
oup, double startTime, double timeOffset, const KeyframeEffectModelBase& effect,
Vector<OwnPtr<CompositorAnimation>>& animations, double animationPlaybackRate) |
| 577 { | 560 { |
| 578 ASSERT(animations.isEmpty()); | 561 ASSERT(animations.isEmpty()); |
| 579 CompositorTiming compositorTiming; | 562 CompositorTiming compositorTiming; |
| 580 bool timingValid = convertTimingForCompositor(timing, timeOffset, compositor
Timing, animationPlaybackRate); | 563 bool timingValid = convertTimingForCompositor(timing, timeOffset, compositor
Timing, animationPlaybackRate); |
| 581 ASSERT_UNUSED(timingValid, timingValid); | 564 ASSERT_UNUSED(timingValid, timingValid); |
| 582 | 565 |
| 583 PropertyHandleSet properties = effect.properties(); | 566 PropertyHandleSet properties = effect.properties(); |
| 584 ASSERT(!properties.isEmpty()); | 567 ASSERT(!properties.isEmpty()); |
| 585 for (const auto& property : properties) { | 568 for (const auto& property : properties) { |
| 586 PropertySpecificKeyframeVector values; | 569 PropertySpecificKeyframeVector values; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 break; | 656 break; |
| 674 default: | 657 default: |
| 675 ASSERT_NOT_REACHED(); | 658 ASSERT_NOT_REACHED(); |
| 676 } | 659 } |
| 677 animations.append(std::move(animation)); | 660 animations.append(std::move(animation)); |
| 678 } | 661 } |
| 679 ASSERT(!animations.isEmpty()); | 662 ASSERT(!animations.isEmpty()); |
| 680 } | 663 } |
| 681 | 664 |
| 682 } // namespace blink | 665 } // namespace blink |
| OLD | NEW |