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 14 matching lines...) Expand all Loading... |
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 "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "core/animation/CompositorAnimations.h" | 33 #include "core/animation/CompositorAnimations.h" |
34 | 34 |
| 35 #include "core/animation/ActiveAnimations.h" |
| 36 #include "core/animation/Animation.h" |
| 37 #include "core/animation/AnimationPlayer.h" |
| 38 #include "core/animation/AnimationTimeline.h" |
35 #include "core/animation/CompositorAnimationsImpl.h" | 39 #include "core/animation/CompositorAnimationsImpl.h" |
36 #include "core/animation/CompositorAnimationsTestHelper.h" | 40 #include "core/animation/CompositorAnimationsTestHelper.h" |
37 #include "core/animation/animatable/AnimatableDouble.h" | 41 #include "core/animation/animatable/AnimatableDouble.h" |
38 #include "core/animation/animatable/AnimatableFilterOperations.h" | 42 #include "core/animation/animatable/AnimatableFilterOperations.h" |
39 #include "core/animation/animatable/AnimatableTransform.h" | 43 #include "core/animation/animatable/AnimatableTransform.h" |
40 #include "core/animation/animatable/AnimatableValueTestHelper.h" | 44 #include "core/animation/animatable/AnimatableValueTestHelper.h" |
| 45 #include "core/dom/Document.h" |
| 46 #include "core/rendering/RenderObject.h" |
41 #include "platform/geometry/FloatBox.h" | 47 #include "platform/geometry/FloatBox.h" |
42 #include "platform/geometry/IntSize.h" | 48 #include "platform/geometry/IntSize.h" |
43 #include "platform/graphics/filters/FilterOperations.h" | 49 #include "platform/graphics/filters/FilterOperations.h" |
44 #include "platform/transforms/TransformOperations.h" | 50 #include "platform/transforms/TransformOperations.h" |
45 #include "platform/transforms/TranslateTransformOperation.h" | 51 #include "platform/transforms/TranslateTransformOperation.h" |
46 #include "public/platform/WebCompositorAnimation.h" | 52 #include "public/platform/WebCompositorAnimation.h" |
47 #include "wtf/HashFunctions.h" | 53 #include "wtf/HashFunctions.h" |
48 #include "wtf/OwnPtr.h" | 54 #include "wtf/OwnPtr.h" |
49 #include "wtf/PassOwnPtr.h" | 55 #include "wtf/PassOwnPtr.h" |
50 #include "wtf/PassRefPtr.h" | 56 #include "wtf/PassRefPtr.h" |
(...skipping 17 matching lines...) Expand all Loading... |
68 RefPtr<TimingFunction> m_cubicCustomTimingFunction; | 74 RefPtr<TimingFunction> m_cubicCustomTimingFunction; |
69 RefPtr<TimingFunction> m_stepTimingFunction; | 75 RefPtr<TimingFunction> m_stepTimingFunction; |
70 | 76 |
71 Timing m_timing; | 77 Timing m_timing; |
72 CompositorAnimationsImpl::CompositorTiming m_compositorTiming; | 78 CompositorAnimationsImpl::CompositorTiming m_compositorTiming; |
73 OwnPtrWillBePersistent<AnimatableValueKeyframeVector> m_keyframeVector2; | 79 OwnPtrWillBePersistent<AnimatableValueKeyframeVector> m_keyframeVector2; |
74 RefPtrWillBePersistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimati
onEffect2; | 80 RefPtrWillBePersistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimati
onEffect2; |
75 OwnPtrWillBePersistent<AnimatableValueKeyframeVector> m_keyframeVector5; | 81 OwnPtrWillBePersistent<AnimatableValueKeyframeVector> m_keyframeVector5; |
76 RefPtrWillBePersistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimati
onEffect5; | 82 RefPtrWillBePersistent<AnimatableValueKeyframeEffectModel> m_keyframeAnimati
onEffect5; |
77 | 83 |
| 84 RefPtrWillBePersistent<Document> m_document; |
| 85 RefPtrWillBePersistent<Element> m_element; |
| 86 RefPtrWillBePersistent<AnimationTimeline> m_timeline; |
| 87 |
78 virtual void SetUp() | 88 virtual void SetUp() |
79 { | 89 { |
80 AnimationCompositorAnimationsTestBase::SetUp(); | 90 AnimationCompositorAnimationsTestBase::SetUp(); |
81 | 91 |
82 m_linearTimingFunction = LinearTimingFunction::shared(); | 92 m_linearTimingFunction = LinearTimingFunction::shared(); |
83 m_cubicEaseTimingFunction = CubicBezierTimingFunction::preset(CubicBezie
rTimingFunction::Ease); | 93 m_cubicEaseTimingFunction = CubicBezierTimingFunction::preset(CubicBezie
rTimingFunction::Ease); |
84 m_cubicCustomTimingFunction = CubicBezierTimingFunction::create(1, 2, 3,
4); | 94 m_cubicCustomTimingFunction = CubicBezierTimingFunction::create(1, 2, 3,
4); |
85 m_stepTimingFunction = StepsTimingFunction::create(1, StepsTimingFunctio
n::End); | 95 m_stepTimingFunction = StepsTimingFunction::create(1, StepsTimingFunctio
n::End); |
86 | 96 |
87 m_timing = createCompositableTiming(); | 97 m_timing = createCompositableTiming(); |
88 m_compositorTiming = CompositorAnimationsImpl::CompositorTiming(); | 98 m_compositorTiming = CompositorAnimationsImpl::CompositorTiming(); |
89 // Make sure the CompositableTiming is really compositable, otherwise | 99 // Make sure the CompositableTiming is really compositable, otherwise |
90 // most other tests will fail. | 100 // most other tests will fail. |
91 ASSERT(convertTimingForCompositor(m_timing, m_compositorTiming)); | 101 ASSERT(convertTimingForCompositor(m_timing, m_compositorTiming)); |
92 | 102 |
93 m_keyframeVector2 = createCompositableFloatKeyframeVector(2); | 103 m_keyframeVector2 = createCompositableFloatKeyframeVector(2); |
94 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(
*m_keyframeVector2); | 104 m_keyframeAnimationEffect2 = AnimatableValueKeyframeEffectModel::create(
*m_keyframeVector2); |
95 | 105 |
96 m_keyframeVector5 = createCompositableFloatKeyframeVector(5); | 106 m_keyframeVector5 = createCompositableFloatKeyframeVector(5); |
97 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(
*m_keyframeVector5); | 107 m_keyframeAnimationEffect5 = AnimatableValueKeyframeEffectModel::create(
*m_keyframeVector5); |
| 108 |
| 109 m_document = Document::create(); |
| 110 m_document->animationClock().resetTimeForTesting(); |
| 111 m_timeline = AnimationTimeline::create(m_document.get()); |
| 112 m_element = m_document->createElement("test", ASSERT_NO_EXCEPTION); |
98 } | 113 } |
99 | 114 |
100 public: | 115 public: |
101 | 116 |
102 bool convertTimingForCompositor(const Timing& t, CompositorAnimationsImpl::C
ompositorTiming& out) | 117 bool convertTimingForCompositor(const Timing& t, CompositorAnimationsImpl::C
ompositorTiming& out) |
103 { | 118 { |
104 return CompositorAnimationsImpl::convertTimingForCompositor(t, 0, out, 1
); | 119 return CompositorAnimationsImpl::convertTimingForCompositor(t, 0, out, 1
); |
105 } | 120 } |
106 bool isCandidateForAnimationOnCompositor(const Timing& timing, const Animati
onEffect& effect) | 121 bool isCandidateForAnimationOnCompositor(const Timing& timing, const Animati
onEffect& effect) |
107 { | 122 { |
108 return CompositorAnimations::instance()->isCandidateForAnimationOnCompos
itor(timing, effect, 1); | 123 return CompositorAnimations::instance()->isCandidateForAnimationOnCompos
itor(timing, *m_element.get(), nullptr, effect, 1); |
109 } | 124 } |
110 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations) | 125 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations) |
111 { | 126 { |
112 return getAnimationOnCompositor(timing, effect, animations, 1); | 127 return getAnimationOnCompositor(timing, effect, animations, 1); |
113 } | 128 } |
114 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations, double player
PlaybackRate) | 129 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations, double player
PlaybackRate) |
115 { | 130 { |
116 return CompositorAnimationsImpl::getAnimationOnCompositor(timing, 0, std
::numeric_limits<double>::quiet_NaN(), 0, effect, animations, playerPlaybackRate
); | 131 return CompositorAnimationsImpl::getAnimationOnCompositor(timing, 0, std
::numeric_limits<double>::quiet_NaN(), 0, effect, animations, playerPlaybackRate
); |
117 } | 132 } |
118 bool getAnimationBounds(FloatBox& boundingBox, const AnimationEffect& effect
, double minValue, double maxValue) | 133 bool getAnimationBounds(FloatBox& boundingBox, const AnimationEffect& effect
, double minValue, double maxValue) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 EXPECT_EQ(d->offset(), 1.0); | 239 EXPECT_EQ(d->offset(), 1.0); |
225 } else { | 240 } else { |
226 EXPECT_EQ(to->offset(), 1.0); | 241 EXPECT_EQ(to->offset(), 1.0); |
227 } | 242 } |
228 if (!HasFatalFailure()) { | 243 if (!HasFatalFailure()) { |
229 return AnimatableValueKeyframeEffectModel::create(frames); | 244 return AnimatableValueKeyframeEffectModel::create(frames); |
230 } | 245 } |
231 return nullptr; | 246 return nullptr; |
232 } | 247 } |
233 | 248 |
| 249 void simulateFrame(double time) |
| 250 { |
| 251 m_document->animationClock().updateTime(time); |
| 252 m_document->compositorPendingAnimations().update(false); |
| 253 m_timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
| 254 } |
| 255 }; |
| 256 |
| 257 class RenderObjectProxy : public RenderObject { |
| 258 public: |
| 259 explicit RenderObjectProxy(Node* node) |
| 260 : RenderObject(node) |
| 261 { |
| 262 } |
| 263 |
| 264 const char* renderName() const override { return nullptr; } |
| 265 void layout() override { } |
234 }; | 266 }; |
235 | 267 |
236 // ----------------------------------------------------------------------- | 268 // ----------------------------------------------------------------------- |
237 // ----------------------------------------------------------------------- | 269 // ----------------------------------------------------------------------- |
238 | 270 |
239 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKey
frameMultipleCSSProperties) | 271 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKey
frameMultipleCSSProperties) |
240 { | 272 { |
241 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeGoodMultiple = createDef
aultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace); | 273 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeGoodMultiple = createDef
aultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace); |
242 keyframeGoodMultiple->setPropertyValue(CSSPropertyTransform, AnimatableTrans
form::create(TransformOperations()).get()); | 274 keyframeGoodMultiple->setPropertyValue(CSSPropertyTransform, AnimatableTrans
form::create(TransformOperations()).get()); |
243 EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeGoodMu
ltiple.get())); | 275 EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeGoodMu
ltiple.get())); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> basicFrames = Animata
bleValueKeyframeEffectModel::create(basicFramesVector).get(); | 608 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> basicFrames = Animata
bleValueKeyframeEffectModel::create(basicFramesVector).get(); |
577 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g
et())); | 609 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g
et())); |
578 | 610 |
579 basicFramesVector[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezie
rTimingFunction::EaseIn)); | 611 basicFramesVector[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezie
rTimingFunction::EaseIn)); |
580 basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector).
get(); | 612 basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector).
get(); |
581 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g
et())); | 613 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g
et())); |
582 | 614 |
583 nonBasicFramesVector[0]->setEasing(m_linearTimingFunction.get()); | 615 nonBasicFramesVector[0]->setEasing(m_linearTimingFunction.get()); |
584 nonBasicFramesVector[1]->setEasing(CubicBezierTimingFunction::preset(CubicBe
zierTimingFunction::EaseIn)); | 616 nonBasicFramesVector[1]->setEasing(CubicBezierTimingFunction::preset(CubicBe
zierTimingFunction::EaseIn)); |
585 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> nonBasicFrames = Anim
atableValueKeyframeEffectModel::create(nonBasicFramesVector).get(); | 617 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> nonBasicFrames = Anim
atableValueKeyframeEffectModel::create(nonBasicFramesVector).get(); |
586 EXPECT_TRUE(CompositorAnimations::instance()->isCandidateForAnimationOnCompo
sitor(linearTiming, *nonBasicFrames.get(), 1)); | 618 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *nonBasicFrame
s.get())); |
587 } | 619 } |
588 | 620 |
589 // ----------------------------------------------------------------------- | 621 // ----------------------------------------------------------------------- |
590 // ----------------------------------------------------------------------- | 622 // ----------------------------------------------------------------------- |
591 | 623 |
592 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimation) | 624 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimation) |
593 { | 625 { |
594 // Animation to convert | 626 // Animation to convert |
595 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyfra
meEffectModel( | 627 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyfra
meEffectModel( |
596 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0
).get(), 0), | 628 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0
).get(), 0), |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 .After(usesMockCurve); | 1178 .After(usesMockCurve); |
1147 | 1179 |
1148 // Go! | 1180 // Go! |
1149 setCompositorForTesting(mockCompositor); | 1181 setCompositorForTesting(mockCompositor); |
1150 Vector<OwnPtr<WebCompositorAnimation> > result; | 1182 Vector<OwnPtr<WebCompositorAnimation> > result; |
1151 getAnimationOnCompositor(m_timing, *effect.get(), result); | 1183 getAnimationOnCompositor(m_timing, *effect.get(), result); |
1152 EXPECT_EQ(1U, result.size()); | 1184 EXPECT_EQ(1U, result.size()); |
1153 result[0].clear(); | 1185 result[0].clear(); |
1154 } | 1186 } |
1155 | 1187 |
| 1188 TEST_F(AnimationCompositorAnimationsTest, CancelIncompatibleCompositorAnimations
) |
| 1189 { |
| 1190 WebCompositorSupportMock mockCompositor; |
| 1191 setCompositorForTesting(mockCompositor); |
| 1192 |
| 1193 RefPtrWillBeRawPtr<Element> element = m_document->createElement("shared", AS
SERT_NO_EXCEPTION); |
| 1194 |
| 1195 RenderObjectProxy* renderer = new RenderObjectProxy(element.get()); |
| 1196 element->setRenderer(renderer); |
| 1197 |
| 1198 AnimatableValueKeyframeVector keyFrames; |
| 1199 keyFrames.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::
CompositeReplace, 0.0).get()); |
| 1200 keyFrames.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::
CompositeReplace, 1.0).get()); |
| 1201 RefPtrWillBeRawPtr<AnimationEffect> animationEffect1 = AnimatableValueKeyfra
meEffectModel::create(keyFrames); |
| 1202 RefPtrWillBeRawPtr<AnimationEffect> animationEffect2 = AnimatableValueKeyfra
meEffectModel::create(keyFrames); |
| 1203 |
| 1204 Timing timing; |
| 1205 timing.iterationDuration = 1.f; |
| 1206 |
| 1207 // The first player for opacity is ok to run on compositor. |
| 1208 RefPtrWillBeRawPtr<Animation> animation1 = Animation::create(element.get(),
animationEffect1, timing); |
| 1209 RefPtrWillBeRawPtr<AnimationPlayer> player1 = m_timeline->play(animation1.ge
t()); |
| 1210 EXPECT_TRUE(CompositorAnimations::instance()->isCandidateForAnimationOnCompo
sitor(timing, *element.get(), player1.get(), *animationEffect1.get(), 1)); |
| 1211 |
| 1212 // simulate Animation::maybeStartAnimationOnCompositor |
| 1213 Vector<int> compositorAnimationIds; |
| 1214 compositorAnimationIds.append(1); |
| 1215 animation1->setCompositorAnimationIdsForTesting(compositorAnimationIds); |
| 1216 EXPECT_TRUE(player1->hasActiveAnimationsOnCompositor()); |
| 1217 |
| 1218 // The second player for opacity is not ok to run on compositor. |
| 1219 RefPtrWillBeRawPtr<Animation> animation2 = Animation::create(element.get(),
animationEffect2, timing); |
| 1220 RefPtrWillBeRawPtr<AnimationPlayer> player2 = m_timeline->play(animation2.ge
t()); |
| 1221 EXPECT_FALSE(CompositorAnimations::instance()->isCandidateForAnimationOnComp
ositor(timing, *element.get(), player2.get(), *animationEffect2.get(), 1)); |
| 1222 EXPECT_FALSE(player2->hasActiveAnimationsOnCompositor()); |
| 1223 |
| 1224 // A fallback to blink implementation needed, so cancel all compositor-side
opacity animations for this element. |
| 1225 player2->cancelIncompatibleAnimationsOnCompositor(); |
| 1226 |
| 1227 EXPECT_FALSE(player1->hasActiveAnimationsOnCompositor()); |
| 1228 EXPECT_FALSE(player2->hasActiveAnimationsOnCompositor()); |
| 1229 |
| 1230 simulateFrame(0); |
| 1231 EXPECT_EQ(2U, element->activeAnimations()->players().size()); |
| 1232 simulateFrame(1.); |
| 1233 |
| 1234 element->setRenderer(nullptr); |
| 1235 delete renderer; |
| 1236 renderer = nullptr; |
| 1237 |
| 1238 player1.release(); |
| 1239 player2.release(); |
| 1240 Heap::collectAllGarbage(); |
| 1241 EXPECT_TRUE(element->activeAnimations()->players().isEmpty()); |
| 1242 } |
| 1243 |
1156 } // namespace blink | 1244 } // namespace blink |
OLD | NEW |