TEST_F(AnimationEffectStackTest, ForwardsFillDiscarding) { play(makeKeyframeEffect( makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))), 2); play(makeKeyframeEffect( makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(2))), 6); play(makeKeyframeEffect( makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3))), 4); document->compositorPendingAnimations().update(); ActiveInterpolationsMap interpolations; updateTimeline(11); ThreadState::current()->collectAllGarbage(); interpolations = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), nullptr, nullptr, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(1u, interpolations.size()); EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize) ->equals(AnimatableDouble::create(3).get())); EXPECT_EQ(3u, sampledEffectCount()); updateTimeline(13); ThreadState::current()->collectAllGarbage(); interpolations = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), nullptr, nullptr, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(1u, interpolations.size()); EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize) ->equals(AnimatableDouble::create(3).get())); EXPECT_EQ(3u, sampledEffectCount()); updateTimeline(15); ThreadState::current()->collectAllGarbage(); interpolations = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), nullptr, nullptr, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(1u, interpolations.size()); EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize) ->equals(AnimatableDouble::create(3).get())); EXPECT_EQ(2u, sampledEffectCount()); updateTimeline(17); ThreadState::current()->collectAllGarbage(); interpolations = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), nullptr, nullptr, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(1u, interpolations.size()); EXPECT_TRUE(interpolationValue(interpolations, CSSPropertyFontSize) ->equals(AnimatableDouble::create(3).get())); EXPECT_EQ(1u, sampledEffectCount()); }
TEST_F(AnimationAnimationStackTest, NewAnimations) { play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 15); play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::create(2))).get(), 10); WillBeHeapVector<RawPtrWillBeMember<InertAnimation>> newAnimations; RefPtrWillBeRawPtr<InertAnimation> inert1 = makeInertAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble::create(3))); RefPtrWillBeRawPtr<InertAnimation> inert2 = makeInertAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::create(4))); newAnimations.append(inert1.get()); newAnimations.append(inert2.get()); WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> result = AnimationStack::activeInterpolations(&element->elementAnimations()->defaultStack(), &newAnimations, 0, Animation::DefaultPriority, 10); EXPECT_EQ(2u, result.size()); EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(AnimatableDouble::create(3).get())); EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(AnimatableDouble::create(4).get())); }
TEST_F(AnimationAnimationStackTest, ElementAnimationsSorted) { play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 10); play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble::create(2))).get(), 15); play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble::create(3))).get(), 5); WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> result = AnimationStack::activeInterpolations(&element->elementAnimations()->defaultStack(), 0, 0, Animation::DefaultPriority, 0); EXPECT_EQ(1u, result.size()); EXPECT_TRUE(interpolationValue(result.get(CSSPropertyFontSize))->equals(AnimatableDouble::create(3).get())); }
TEST_F(AnimationAnimationStackTest, CancelledAnimationPlayers) { WillBeHeapHashSet<RawPtrWillBeMember<const AnimationPlayer>> cancelledAnimationPlayers; RefPtrWillBeRawPtr<AnimationPlayer> player = play(makeAnimation(makeAnimationEffect(CSSPropertyFontSize, AnimatableDouble::create(1))).get(), 0); cancelledAnimationPlayers.add(player.get()); play(makeAnimation(makeAnimationEffect(CSSPropertyZIndex, AnimatableDouble::create(2))).get(), 0); WillBeHeapHashMap<CSSPropertyID, RefPtrWillBeMember<Interpolation>> result = AnimationStack::activeInterpolations(&element->elementAnimations()->defaultStack(), 0, &cancelledAnimationPlayers, Animation::DefaultPriority, 0); EXPECT_EQ(1u, result.size()); EXPECT_TRUE(interpolationValue(result.get(CSSPropertyZIndex))->equals(AnimatableDouble::create(2).get())); }
TEST_F(AnimationEffectStackTest, NewAnimations) { play(makeKeyframeEffect( makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))), 15); play(makeKeyframeEffect( makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(2))), 10); HeapVector<Member<const InertEffect>> newAnimations; InertEffect* inert1 = makeInertEffect( makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3))); InertEffect* inert2 = makeInertEffect( makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(4))); newAnimations.push_back(inert1); newAnimations.push_back(inert2); ActiveInterpolationsMap result = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), &newAnimations, 0, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(2u, result.size()); EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize) ->equals(AnimatableDouble::create(3).get())); EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex) ->equals(AnimatableDouble::create(4).get())); }
TEST_F(AnimationEffectStackTest, ElementAnimationsSorted) { play(makeKeyframeEffect( makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))), 10); play(makeKeyframeEffect( makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(2))), 15); play(makeKeyframeEffect( makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(3))), 5); ActiveInterpolationsMap result = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), 0, 0, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(1u, result.size()); EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize) ->equals(AnimatableDouble::create(3).get())); }
TEST_F(AnimationEffectStackTest, CancelledAnimations) { HeapHashSet<Member<const Animation>> cancelledAnimations; Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))), 0); cancelledAnimations.add(animation); play(makeKeyframeEffect( makeEffectModel(CSSPropertyZIndex, AnimatableDouble::create(2))), 0); ActiveInterpolationsMap result = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), 0, &cancelledAnimations, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(1u, result.size()); EXPECT_TRUE(interpolationValue(result, CSSPropertyZIndex) ->equals(AnimatableDouble::create(2).get())); }
TEST_F(AnimationInterpolableValueTest, SimpleList) { OwnPtrWillBeRawPtr<InterpolableList> listA = InterpolableList::create(3); listA->set(0, InterpolableNumber::create(0)); listA->set(1, InterpolableNumber::create(42)); listA->set(2, InterpolableNumber::create(20.5)); OwnPtrWillBeRawPtr<InterpolableList> listB = InterpolableList::create(3); listB->set(0, InterpolableNumber::create(100)); listB->set(1, InterpolableNumber::create(-200)); listB->set(2, InterpolableNumber::create(300)); RefPtrWillBeRawPtr<Interpolation> i = interpolateLists(listA.release(), listB.release(), 0.3); InterpolableList* outList = toInterpolableList(interpolationValue(*i.get())); EXPECT_FLOAT_EQ(30, toInterpolableNumber(outList->get(0))->value()); EXPECT_FLOAT_EQ(-30.6f, toInterpolableNumber(outList->get(1))->value()); EXPECT_FLOAT_EQ(104.35f, toInterpolableNumber(outList->get(2))->value()); }
TEST_F(AnimationEffectStackTest, ClearedEffectsRemoved) { Animation* animation = play(makeKeyframeEffect(makeEffectModel(CSSPropertyFontSize, AnimatableDouble::create(1))), 10); ActiveInterpolationsMap result = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), 0, 0, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(1u, result.size()); EXPECT_TRUE(interpolationValue(result, CSSPropertyFontSize) ->equals(AnimatableDouble::create(1).get())); animation->setEffect(0); result = EffectStack::activeInterpolations( &element->elementAnimations()->effectStack(), 0, 0, KeyframeEffectReadOnly::DefaultPriority); EXPECT_EQ(0u, result.size()); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RigTimeHistoryCurveMerger::computeInterpolatedValues() { m_validIntervalsForAllTimeSteps.clear(); m_allTimeSteps.clear(); m_interpolatedValuesForAllCurves.clear(); computeUnionOfTimeSteps(); const size_t curveCount = m_originalValues.size(); if (curveCount == 0) { return; } const size_t dataValueCount = m_allTimeSteps.size(); if (dataValueCount == 0) { return; } m_interpolatedValuesForAllCurves.resize(curveCount); std::vector<double> accumulatedValidValues(dataValueCount, 1.0); for (size_t curveIdx = 0; curveIdx < curveCount; curveIdx++) { std::vector<double>& curveValues = m_interpolatedValuesForAllCurves[curveIdx]; curveValues.resize(dataValueCount); for (size_t valueIndex = 0; valueIndex < dataValueCount; valueIndex++) { double interpolValue = interpolationValue(m_allTimeSteps[valueIndex], m_originalValues[curveIdx].first, m_originalValues[curveIdx].second); if (!RigCurveDataTools::isValidValue(interpolValue, false)) { accumulatedValidValues[valueIndex] = HUGE_VAL; } curveValues[valueIndex] = interpolValue; } } m_validIntervalsForAllTimeSteps = RigCurveDataTools::calculateIntervalsOfValidValues(accumulatedValidValues, false); }
TEST_F(AnimationInterpolableValueTest, NestedList) { OwnPtrWillBeRawPtr<InterpolableList> listA = InterpolableList::create(3); listA->set(0, InterpolableNumber::create(0)); OwnPtrWillBeRawPtr<InterpolableList> subListA = InterpolableList::create(1); subListA->set(0, InterpolableNumber::create(100)); listA->set(1, subListA.release()); listA->set(2, InterpolableBool::create(false)); OwnPtrWillBeRawPtr<InterpolableList> listB = InterpolableList::create(3); listB->set(0, InterpolableNumber::create(100)); OwnPtrWillBeRawPtr<InterpolableList> subListB = InterpolableList::create(1); subListB->set(0, InterpolableNumber::create(50)); listB->set(1, subListB.release()); listB->set(2, InterpolableBool::create(true)); RefPtrWillBeRawPtr<Interpolation> i = interpolateLists(listA.release(), listB.release(), 0.5); InterpolableList* outList = toInterpolableList(interpolationValue(*i.get())); EXPECT_FLOAT_EQ(50, toInterpolableNumber(outList->get(0))->value()); EXPECT_FLOAT_EQ(75, toInterpolableNumber(toInterpolableList(outList->get(1))->get(0))->value()); EXPECT_TRUE(toInterpolableBool(outList->get(2))->value()); }
bool interpolateBools(bool a, bool b, double progress) { RefPtrWillBeRawPtr<Interpolation> i = SampleInterpolation::create(InterpolableBool::create(a), InterpolableBool::create(b)); i->interpolate(0, progress); return toInterpolableBool(interpolationValue(*i.get()))->value(); }
double interpolateNumbers(double a, double b, double progress) { RefPtrWillBeRawPtr<Interpolation> i = SampleInterpolation::create(InterpolableNumber::create(a), InterpolableNumber::create(b)); i->interpolate(0, progress); return toInterpolableNumber(interpolationValue(*i.get()))->value(); }
double getInterpolableNumber(PassRefPtr<Interpolation> value) { return toInterpolableNumber(interpolationValue(*value.get()))->value(); }