| 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 15 matching lines...) Expand all Loading... |
| 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 | 31 |
| 32 #include "core/animation/CompositorAnimations.h" | 32 #include "core/animation/CompositorAnimations.h" |
| 33 | 33 |
| 34 #include "core/animation/Animation.h" | 34 #include "core/animation/Animation.h" |
| 35 #include "core/animation/AnimationTimeline.h" | 35 #include "core/animation/AnimationTimeline.h" |
| 36 #include "core/animation/CompositorAnimationsImpl.h" | |
| 37 #include "core/animation/CompositorPendingAnimations.h" | 36 #include "core/animation/CompositorPendingAnimations.h" |
| 38 #include "core/animation/ElementAnimations.h" | 37 #include "core/animation/ElementAnimations.h" |
| 39 #include "core/animation/KeyframeEffect.h" | 38 #include "core/animation/KeyframeEffect.h" |
| 40 #include "core/animation/animatable/AnimatableDouble.h" | 39 #include "core/animation/animatable/AnimatableDouble.h" |
| 41 #include "core/animation/animatable/AnimatableFilterOperations.h" | 40 #include "core/animation/animatable/AnimatableFilterOperations.h" |
| 42 #include "core/animation/animatable/AnimatableTransform.h" | 41 #include "core/animation/animatable/AnimatableTransform.h" |
| 43 #include "core/animation/animatable/AnimatableValueTestHelper.h" | 42 #include "core/animation/animatable/AnimatableValueTestHelper.h" |
| 44 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
| 45 #include "core/layout/LayoutObject.h" | 44 #include "core/layout/LayoutObject.h" |
| 46 #include "core/testing/DummyPageHolder.h" | 45 #include "core/testing/DummyPageHolder.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 62 namespace blink { | 61 namespace blink { |
| 63 | 62 |
| 64 class AnimationCompositorAnimationsTest : public ::testing::Test { | 63 class AnimationCompositorAnimationsTest : public ::testing::Test { |
| 65 protected: | 64 protected: |
| 66 RefPtr<TimingFunction> m_linearTimingFunction; | 65 RefPtr<TimingFunction> m_linearTimingFunction; |
| 67 RefPtr<TimingFunction> m_cubicEaseTimingFunction; | 66 RefPtr<TimingFunction> m_cubicEaseTimingFunction; |
| 68 RefPtr<TimingFunction> m_cubicCustomTimingFunction; | 67 RefPtr<TimingFunction> m_cubicCustomTimingFunction; |
| 69 RefPtr<TimingFunction> m_stepTimingFunction; | 68 RefPtr<TimingFunction> m_stepTimingFunction; |
| 70 | 69 |
| 71 Timing m_timing; | 70 Timing m_timing; |
| 72 CompositorAnimationsImpl::CompositorTiming m_compositorTiming; | 71 CompositorAnimations::CompositorTiming m_compositorTiming; |
| 73 OwnPtr<AnimatableValueKeyframeVector> m_keyframeVector2; | 72 OwnPtr<AnimatableValueKeyframeVector> m_keyframeVector2; |
| 74 Persistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimationEffect2; | 73 Persistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimationEffect2; |
| 75 OwnPtr<AnimatableValueKeyframeVector> m_keyframeVector5; | 74 OwnPtr<AnimatableValueKeyframeVector> m_keyframeVector5; |
| 76 Persistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimationEffect5; | 75 Persistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimationEffect5; |
| 77 | 76 |
| 78 Persistent<Document> m_document; | 77 Persistent<Document> m_document; |
| 79 Persistent<Element> m_element; | 78 Persistent<Element> m_element; |
| 80 Persistent<AnimationTimeline> m_timeline; | 79 Persistent<AnimationTimeline> m_timeline; |
| 81 OwnPtr<DummyPageHolder> m_pageHolder; | 80 OwnPtr<DummyPageHolder> m_pageHolder; |
| 82 | 81 |
| 83 void SetUp() override | 82 void SetUp() override |
| 84 { | 83 { |
| 85 m_linearTimingFunction = LinearTimingFunction::shared(); | 84 m_linearTimingFunction = LinearTimingFunction::shared(); |
| 86 m_cubicEaseTimingFunction = CubicBezierTimingFunction::preset(CubicBezie
rTimingFunction::EaseType::EASE); | 85 m_cubicEaseTimingFunction = CubicBezierTimingFunction::preset(CubicBezie
rTimingFunction::EaseType::EASE); |
| 87 m_cubicCustomTimingFunction = CubicBezierTimingFunction::create(1, 2, 3,
4); | 86 m_cubicCustomTimingFunction = CubicBezierTimingFunction::create(1, 2, 3,
4); |
| 88 m_stepTimingFunction = StepsTimingFunction::create(1, StepsTimingFunctio
n::StepPosition::END); | 87 m_stepTimingFunction = StepsTimingFunction::create(1, StepsTimingFunctio
n::StepPosition::END); |
| 89 | 88 |
| 90 m_timing = createCompositableTiming(); | 89 m_timing = createCompositableTiming(); |
| 91 m_compositorTiming = CompositorAnimationsImpl::CompositorTiming(); | 90 m_compositorTiming = CompositorAnimations::CompositorTiming(); |
| 92 // Make sure the CompositableTiming is really compositable, otherwise | 91 // Make sure the CompositableTiming is really compositable, otherwise |
| 93 // most other tests will fail. | 92 // most other tests will fail. |
| 94 ASSERT(convertTimingForCompositor(m_timing, m_compositorTiming)); | 93 ASSERT(convertTimingForCompositor(m_timing, m_compositorTiming)); |
| 95 | 94 |
| 96 m_keyframeVector2 = createCompositableFloatKeyframeVector(2); | 95 m_keyframeVector2 = createCompositableFloatKeyframeVector(2); |
| 97 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(
*m_keyframeVector2); | 96 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(
*m_keyframeVector2); |
| 98 | 97 |
| 99 m_keyframeVector5 = createCompositableFloatKeyframeVector(5); | 98 m_keyframeVector5 = createCompositableFloatKeyframeVector(5); |
| 100 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(
*m_keyframeVector5); | 99 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(
*m_keyframeVector5); |
| 101 | 100 |
| 102 m_pageHolder = DummyPageHolder::create(); | 101 m_pageHolder = DummyPageHolder::create(); |
| 103 m_document = &m_pageHolder->document(); | 102 m_document = &m_pageHolder->document(); |
| 104 m_document->animationClock().resetTimeForTesting(); | 103 m_document->animationClock().resetTimeForTesting(); |
| 105 | 104 |
| 106 m_timeline = AnimationTimeline::create(m_document.get()); | 105 m_timeline = AnimationTimeline::create(m_document.get()); |
| 107 m_timeline->resetForTesting(); | 106 m_timeline->resetForTesting(); |
| 108 m_element = m_document->createElement("test", ASSERT_NO_EXCEPTION); | 107 m_element = m_document->createElement("test", ASSERT_NO_EXCEPTION); |
| 109 } | 108 } |
| 110 | 109 |
| 111 public: | 110 public: |
| 112 bool convertTimingForCompositor(const Timing& t, CompositorAnimationsImpl::C
ompositorTiming& out) | 111 bool convertTimingForCompositor(const Timing& t, CompositorAnimations::Compo
sitorTiming& out) |
| 113 { | 112 { |
| 114 return CompositorAnimationsImpl::convertTimingForCompositor(t, 0, out, 1
); | 113 return CompositorAnimations::convertTimingForCompositor(t, 0, out, 1); |
| 115 } | 114 } |
| 116 bool isCandidateForAnimationOnCompositor(const Timing& timing, const EffectM
odel& effect) | 115 bool isCandidateForAnimationOnCompositor(const Timing& timing, const EffectM
odel& effect) |
| 117 { | 116 { |
| 118 return CompositorAnimations::instance()->isCandidateForAnimationOnCompos
itor(timing, *m_element.get(), nullptr, effect, 1); | 117 return CompositorAnimations::isCandidateForAnimationOnCompositor(timing,
*m_element.get(), nullptr, effect, 1); |
| 119 } | 118 } |
| 120 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<CompositorAnimation>>& animations) | 119 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<CompositorAnimation>>& animations) |
| 121 { | 120 { |
| 122 getAnimationOnCompositor(timing, effect, animations, 1); | 121 getAnimationOnCompositor(timing, effect, animations, 1); |
| 123 } | 122 } |
| 124 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<CompositorAnimation>>& animations, double playerPlay
backRate) | 123 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<CompositorAnimation>>& animations, double playerPlay
backRate) |
| 125 { | 124 { |
| 126 CompositorAnimationsImpl::getAnimationOnCompositor(timing, 0, std::numer
ic_limits<double>::quiet_NaN(), 0, effect, animations, playerPlaybackRate); | 125 CompositorAnimations::getAnimationOnCompositor(timing, 0, std::numeric_l
imits<double>::quiet_NaN(), 0, effect, animations, playerPlaybackRate); |
| 127 } | 126 } |
| 128 bool getAnimationBounds(FloatBox& boundingBox, const EffectModel& effect, do
uble minValue, double maxValue) | 127 bool getAnimationBounds(FloatBox& boundingBox, const EffectModel& effect, do
uble minValue, double maxValue) |
| 129 { | 128 { |
| 130 return CompositorAnimations::instance()->getAnimatedBoundingBox(bounding
Box, effect, minValue, maxValue); | 129 return CompositorAnimations::getAnimatedBoundingBox(boundingBox, effect,
minValue, maxValue); |
| 131 } | 130 } |
| 132 | 131 |
| 133 bool duplicateSingleKeyframeAndTestIsCandidateOnResult(AnimatableValueKeyfra
me* frame) | 132 bool duplicateSingleKeyframeAndTestIsCandidateOnResult(AnimatableValueKeyfra
me* frame) |
| 134 { | 133 { |
| 135 EXPECT_EQ(frame->offset(), 0); | 134 EXPECT_EQ(frame->offset(), 0); |
| 136 AnimatableValueKeyframeVector frames; | 135 AnimatableValueKeyframeVector frames; |
| 137 RefPtr<Keyframe> second = frame->cloneWithOffset(1); | 136 RefPtr<Keyframe> second = frame->cloneWithOffset(1); |
| 138 | 137 |
| 139 frames.append(frame); | 138 frames.append(frame); |
| 140 frames.append(toAnimatableValueKeyframe(second.get())); | 139 frames.append(toAnimatableValueKeyframe(second.get())); |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 keyFrames.append(createDefaultKeyframe(CSSPropertyOpacity, EffectModel::Comp
ositeReplace, 1.0).get()); | 975 keyFrames.append(createDefaultKeyframe(CSSPropertyOpacity, EffectModel::Comp
ositeReplace, 1.0).get()); |
| 977 EffectModel* animationEffect1 = AnimatableValueKeyframeEffectModel::create(k
eyFrames); | 976 EffectModel* animationEffect1 = AnimatableValueKeyframeEffectModel::create(k
eyFrames); |
| 978 EffectModel* animationEffect2 = AnimatableValueKeyframeEffectModel::create(k
eyFrames); | 977 EffectModel* animationEffect2 = AnimatableValueKeyframeEffectModel::create(k
eyFrames); |
| 979 | 978 |
| 980 Timing timing; | 979 Timing timing; |
| 981 timing.iterationDuration = 1.f; | 980 timing.iterationDuration = 1.f; |
| 982 | 981 |
| 983 // The first animation for opacity is ok to run on compositor. | 982 // The first animation for opacity is ok to run on compositor. |
| 984 KeyframeEffect* keyframeEffect1 = KeyframeEffect::create(element.get(), anim
ationEffect1, timing); | 983 KeyframeEffect* keyframeEffect1 = KeyframeEffect::create(element.get(), anim
ationEffect1, timing); |
| 985 Animation* animation1 = m_timeline->play(keyframeEffect1); | 984 Animation* animation1 = m_timeline->play(keyframeEffect1); |
| 986 EXPECT_TRUE(CompositorAnimations::instance()->isCandidateForAnimationOnCompo
sitor(timing, *element.get(), animation1, *animationEffect1, 1)); | 985 EXPECT_TRUE(CompositorAnimations::isCandidateForAnimationOnCompositor(timing
, *element.get(), animation1, *animationEffect1, 1)); |
| 987 | 986 |
| 988 // simulate KeyframeEffect::maybeStartAnimationOnCompositor | 987 // simulate KeyframeEffect::maybeStartAnimationOnCompositor |
| 989 Vector<int> compositorAnimationIds; | 988 Vector<int> compositorAnimationIds; |
| 990 compositorAnimationIds.append(1); | 989 compositorAnimationIds.append(1); |
| 991 keyframeEffect1->setCompositorAnimationIdsForTesting(compositorAnimationIds)
; | 990 keyframeEffect1->setCompositorAnimationIdsForTesting(compositorAnimationIds)
; |
| 992 EXPECT_TRUE(animation1->hasActiveAnimationsOnCompositor()); | 991 EXPECT_TRUE(animation1->hasActiveAnimationsOnCompositor()); |
| 993 | 992 |
| 994 // The second animation for opacity is not ok to run on compositor. | 993 // The second animation for opacity is not ok to run on compositor. |
| 995 KeyframeEffect* keyframeEffect2 = KeyframeEffect::create(element.get(), anim
ationEffect2, timing); | 994 KeyframeEffect* keyframeEffect2 = KeyframeEffect::create(element.get(), anim
ationEffect2, timing); |
| 996 Animation* animation2 = m_timeline->play(keyframeEffect2); | 995 Animation* animation2 = m_timeline->play(keyframeEffect2); |
| 997 EXPECT_FALSE(CompositorAnimations::instance()->isCandidateForAnimationOnComp
ositor(timing, *element.get(), animation2, *animationEffect2, 1)); | 996 EXPECT_FALSE(CompositorAnimations::isCandidateForAnimationOnCompositor(timin
g, *element.get(), animation2, *animationEffect2, 1)); |
| 998 EXPECT_FALSE(animation2->hasActiveAnimationsOnCompositor()); | 997 EXPECT_FALSE(animation2->hasActiveAnimationsOnCompositor()); |
| 999 | 998 |
| 1000 // A fallback to blink implementation needed, so cancel all compositor-side
opacity animations for this element. | 999 // A fallback to blink implementation needed, so cancel all compositor-side
opacity animations for this element. |
| 1001 animation2->cancelIncompatibleAnimationsOnCompositor(); | 1000 animation2->cancelIncompatibleAnimationsOnCompositor(); |
| 1002 | 1001 |
| 1003 EXPECT_FALSE(animation1->hasActiveAnimationsOnCompositor()); | 1002 EXPECT_FALSE(animation1->hasActiveAnimationsOnCompositor()); |
| 1004 EXPECT_FALSE(animation2->hasActiveAnimationsOnCompositor()); | 1003 EXPECT_FALSE(animation2->hasActiveAnimationsOnCompositor()); |
| 1005 | 1004 |
| 1006 simulateFrame(0); | 1005 simulateFrame(0); |
| 1007 EXPECT_EQ(2U, element->elementAnimations()->animations().size()); | 1006 EXPECT_EQ(2U, element->elementAnimations()->animations().size()); |
| 1008 simulateFrame(1.); | 1007 simulateFrame(1.); |
| 1009 | 1008 |
| 1010 element->setLayoutObject(nullptr); | 1009 element->setLayoutObject(nullptr); |
| 1011 LayoutObjectProxy::dispose(layoutObject); | 1010 LayoutObjectProxy::dispose(layoutObject); |
| 1012 | 1011 |
| 1013 ThreadHeap::collectAllGarbage(); | 1012 ThreadHeap::collectAllGarbage(); |
| 1014 EXPECT_TRUE(element->elementAnimations()->animations().isEmpty()); | 1013 EXPECT_TRUE(element->elementAnimations()->animations().isEmpty()); |
| 1015 } | 1014 } |
| 1016 | 1015 |
| 1017 } // namespace blink | 1016 } // namespace blink |
| OLD | NEW |