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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 104 } |
99 | 105 |
100 public: | 106 public: |
101 | 107 |
102 bool convertTimingForCompositor(const Timing& t, CompositorAnimationsImpl::C
ompositorTiming& out) | 108 bool convertTimingForCompositor(const Timing& t, CompositorAnimationsImpl::C
ompositorTiming& out) |
103 { | 109 { |
104 return CompositorAnimationsImpl::convertTimingForCompositor(t, 0, out, 1
); | 110 return CompositorAnimationsImpl::convertTimingForCompositor(t, 0, out, 1
); |
105 } | 111 } |
106 bool isCandidateForAnimationOnCompositor(const Timing& timing, const Animati
onEffect& effect) | 112 bool isCandidateForAnimationOnCompositor(const Timing& timing, const Animati
onEffect& effect) |
107 { | 113 { |
108 return CompositorAnimations::instance()->isCandidateForAnimationOnCompos
itor(timing, effect, 1); | 114 return CompositorAnimations::instance()->isCandidateForAnimationOnCompos
itor(timing, nullptr, nullptr, effect, 1); |
109 } | 115 } |
110 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations) | 116 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations) |
111 { | 117 { |
112 return getAnimationOnCompositor(timing, effect, animations, 1); | 118 return getAnimationOnCompositor(timing, effect, animations, 1); |
113 } | 119 } |
114 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations, double player
PlaybackRate) | 120 void getAnimationOnCompositor(Timing& timing, AnimatableValueKeyframeEffectM
odel& effect, Vector<OwnPtr<WebCompositorAnimation> >& animations, double player
PlaybackRate) |
115 { | 121 { |
116 return CompositorAnimationsImpl::getAnimationOnCompositor(timing, 0, std
::numeric_limits<double>::quiet_NaN(), 0, effect, animations, playerPlaybackRate
); | 122 return CompositorAnimationsImpl::getAnimationOnCompositor(timing, 0, std
::numeric_limits<double>::quiet_NaN(), 0, effect, animations, playerPlaybackRate
); |
117 } | 123 } |
118 bool getAnimationBounds(FloatBox& boundingBox, const AnimationEffect& effect
, double minValue, double maxValue) | 124 bool getAnimationBounds(FloatBox& boundingBox, const AnimationEffect& effect
, double minValue, double maxValue) |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 EXPECT_EQ(to->offset(), 1.0); | 232 EXPECT_EQ(to->offset(), 1.0); |
227 } | 233 } |
228 if (!HasFatalFailure()) { | 234 if (!HasFatalFailure()) { |
229 return AnimatableValueKeyframeEffectModel::create(frames); | 235 return AnimatableValueKeyframeEffectModel::create(frames); |
230 } | 236 } |
231 return nullptr; | 237 return nullptr; |
232 } | 238 } |
233 | 239 |
234 }; | 240 }; |
235 | 241 |
| 242 class RenderObjectProxy : public RenderObject { |
| 243 public: |
| 244 explicit RenderObjectProxy(Node* node) |
| 245 : RenderObject(node) |
| 246 { |
| 247 } |
| 248 |
| 249 const char* renderName() const override { return nullptr; } |
| 250 void layout() override { } |
| 251 }; |
| 252 |
236 // ----------------------------------------------------------------------- | 253 // ----------------------------------------------------------------------- |
237 // ----------------------------------------------------------------------- | 254 // ----------------------------------------------------------------------- |
238 | 255 |
239 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKey
frameMultipleCSSProperties) | 256 TEST_F(AnimationCompositorAnimationsTest, isCandidateForAnimationOnCompositorKey
frameMultipleCSSProperties) |
240 { | 257 { |
241 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeGoodMultiple = createDef
aultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace); | 258 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeGoodMultiple = createDef
aultKeyframe(CSSPropertyOpacity, AnimationEffect::CompositeReplace); |
242 keyframeGoodMultiple->setPropertyValue(CSSPropertyTransform, AnimatableTrans
form::create(TransformOperations()).get()); | 259 keyframeGoodMultiple->setPropertyValue(CSSPropertyTransform, AnimatableTrans
form::create(TransformOperations()).get()); |
243 EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeGoodMu
ltiple.get())); | 260 EXPECT_TRUE(duplicateSingleKeyframeAndTestIsCandidateOnResult(keyframeGoodMu
ltiple.get())); |
244 | 261 |
245 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeBadMultipleID = createDe
faultKeyframe(CSSPropertyColor, AnimationEffect::CompositeReplace); | 262 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframeBadMultipleID = createDe
faultKeyframe(CSSPropertyColor, AnimationEffect::CompositeReplace); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> basicFrames = Animata
bleValueKeyframeEffectModel::create(basicFramesVector).get(); | 593 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> basicFrames = Animata
bleValueKeyframeEffectModel::create(basicFramesVector).get(); |
577 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g
et())); | 594 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g
et())); |
578 | 595 |
579 basicFramesVector[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezie
rTimingFunction::EaseIn)); | 596 basicFramesVector[0]->setEasing(CubicBezierTimingFunction::preset(CubicBezie
rTimingFunction::EaseIn)); |
580 basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector).
get(); | 597 basicFrames = AnimatableValueKeyframeEffectModel::create(basicFramesVector).
get(); |
581 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g
et())); | 598 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *basicFrames.g
et())); |
582 | 599 |
583 nonBasicFramesVector[0]->setEasing(m_linearTimingFunction.get()); | 600 nonBasicFramesVector[0]->setEasing(m_linearTimingFunction.get()); |
584 nonBasicFramesVector[1]->setEasing(CubicBezierTimingFunction::preset(CubicBe
zierTimingFunction::EaseIn)); | 601 nonBasicFramesVector[1]->setEasing(CubicBezierTimingFunction::preset(CubicBe
zierTimingFunction::EaseIn)); |
585 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> nonBasicFrames = Anim
atableValueKeyframeEffectModel::create(nonBasicFramesVector).get(); | 602 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> nonBasicFrames = Anim
atableValueKeyframeEffectModel::create(nonBasicFramesVector).get(); |
586 EXPECT_TRUE(CompositorAnimations::instance()->isCandidateForAnimationOnCompo
sitor(linearTiming, *nonBasicFrames.get(), 1)); | 603 EXPECT_TRUE(isCandidateForAnimationOnCompositor(linearTiming, *nonBasicFrame
s.get())); |
587 } | 604 } |
588 | 605 |
589 // ----------------------------------------------------------------------- | 606 // ----------------------------------------------------------------------- |
590 // ----------------------------------------------------------------------- | 607 // ----------------------------------------------------------------------- |
591 | 608 |
592 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimation) | 609 TEST_F(AnimationCompositorAnimationsTest, createSimpleOpacityAnimation) |
593 { | 610 { |
594 // Animation to convert | 611 // Animation to convert |
595 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyfra
meEffectModel( | 612 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> effect = createKeyfra
meEffectModel( |
596 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0
).get(), 0), | 613 createReplaceOpKeyframe(CSSPropertyOpacity, AnimatableDouble::create(2.0
).get(), 0), |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 .After(usesMockCurve); | 1163 .After(usesMockCurve); |
1147 | 1164 |
1148 // Go! | 1165 // Go! |
1149 setCompositorForTesting(mockCompositor); | 1166 setCompositorForTesting(mockCompositor); |
1150 Vector<OwnPtr<WebCompositorAnimation> > result; | 1167 Vector<OwnPtr<WebCompositorAnimation> > result; |
1151 getAnimationOnCompositor(m_timing, *effect.get(), result); | 1168 getAnimationOnCompositor(m_timing, *effect.get(), result); |
1152 EXPECT_EQ(1U, result.size()); | 1169 EXPECT_EQ(1U, result.size()); |
1153 result[0].clear(); | 1170 result[0].clear(); |
1154 } | 1171 } |
1155 | 1172 |
| 1173 TEST_F(AnimationCompositorAnimationsTest, CancelSamePropertyCompositorAnimations
) |
| 1174 { |
| 1175 WebCompositorSupportMock mockCompositor; |
| 1176 setCompositorForTesting(mockCompositor); |
| 1177 |
| 1178 RefPtrWillBeRawPtr<Document> document; |
| 1179 RefPtrWillBeRawPtr<AnimationTimeline> timeline; |
| 1180 |
| 1181 document = Document::create(); |
| 1182 document->animationClock().resetTimeForTesting(); |
| 1183 timeline = AnimationTimeline::create(document.get()); |
| 1184 |
| 1185 RefPtrWillBeRawPtr<Element> element = document->createElement("foo", ASSERT_
NO_EXCEPTION); |
| 1186 |
| 1187 RenderObjectProxy* renderer = new RenderObjectProxy(element.get()); |
| 1188 element->setRenderer(renderer); |
| 1189 |
| 1190 AnimatableValueKeyframeVector keyFrames; |
| 1191 keyFrames.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::
CompositeReplace, 0.0).get()); |
| 1192 keyFrames.append(createDefaultKeyframe(CSSPropertyOpacity, AnimationEffect::
CompositeReplace, 1.0).get()); |
| 1193 RefPtrWillBeRawPtr<AnimationEffect> animationEffect1 = AnimatableValueKeyfra
meEffectModel::create(keyFrames); |
| 1194 RefPtrWillBeRawPtr<AnimationEffect> animationEffect2 = AnimatableValueKeyfra
meEffectModel::create(keyFrames); |
| 1195 |
| 1196 Timing timing; |
| 1197 timing.iterationDuration = 1.f; |
| 1198 |
| 1199 // The first player for opacity is ok to run on compositor. |
| 1200 RefPtrWillBeRawPtr<Animation> animation1 = Animation::create(element.get(),
animationEffect1, timing); |
| 1201 RefPtrWillBeRawPtr<AnimationPlayer> player1 = timeline->play(animation1.get(
)); |
| 1202 EXPECT_TRUE(CompositorAnimations::instance()->isCandidateForAnimationOnCompo
sitor(timing, element.get(), player1.get(), *animationEffect1.get(), 1)); |
| 1203 |
| 1204 // simulate Animation::maybeStartAnimationOnCompositor |
| 1205 Vector<int> compositorAnimationIds; |
| 1206 compositorAnimationIds.append(1); |
| 1207 animation1->setCompositorAnimationIdsForTesting(compositorAnimationIds); |
| 1208 EXPECT_TRUE(player1->hasActiveAnimationsOnCompositor()); |
| 1209 |
| 1210 // The second player for opacity is not ok to run on compositor. |
| 1211 RefPtrWillBeRawPtr<Animation> animation2 = Animation::create(element.get(),
animationEffect2, timing); |
| 1212 RefPtrWillBeRawPtr<AnimationPlayer> player2 = timeline->play(animation2.get(
)); |
| 1213 EXPECT_FALSE(CompositorAnimations::instance()->isCandidateForAnimationOnComp
ositor(timing, element.get(), player2.get(), *animationEffect2.get(), 1)); |
| 1214 EXPECT_FALSE(player2->hasActiveAnimationsOnCompositor()); |
| 1215 |
| 1216 // A fallback to blink implementation needed, so cancel all compositor-side
opacity animations for this element. |
| 1217 player2->cancelAffectedAnimationsOnCompositor(); |
| 1218 |
| 1219 EXPECT_FALSE(player1->hasActiveAnimationsOnCompositor()); |
| 1220 EXPECT_FALSE(player2->hasActiveAnimationsOnCompositor()); |
| 1221 |
| 1222 // simulateFrame |
| 1223 document->animationClock().updateTime(0); |
| 1224 document->compositorPendingAnimations().update(false); |
| 1225 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
| 1226 |
| 1227 EXPECT_EQ(2U, element->activeAnimations()->players().size()); |
| 1228 |
| 1229 // simulateFrame |
| 1230 document->animationClock().updateTime(1.0); |
| 1231 document->compositorPendingAnimations().update(false); |
| 1232 timeline->serviceAnimations(TimingUpdateForAnimationFrame); |
| 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 |