OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/animation/EffectStack.h" | 5 #include "core/animation/EffectStack.h" |
6 | 6 |
7 #include "core/animation/AnimationClock.h" | 7 #include "core/animation/AnimationClock.h" |
8 #include "core/animation/CompositorPendingAnimations.h" | 8 #include "core/animation/CompositorPendingAnimations.h" |
9 #include "core/animation/DocumentTimeline.h" | 9 #include "core/animation/DocumentTimeline.h" |
10 #include "core/animation/ElementAnimations.h" | 10 #include "core/animation/ElementAnimations.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 KeyframeEffect* MakeKeyframeEffect(EffectModel* effect, | 67 KeyframeEffect* MakeKeyframeEffect(EffectModel* effect, |
68 double duration = 10) { | 68 double duration = 10) { |
69 Timing timing; | 69 Timing timing; |
70 timing.fill_mode = Timing::FillMode::BOTH; | 70 timing.fill_mode = Timing::FillMode::BOTH; |
71 timing.iteration_duration = duration; | 71 timing.iteration_duration = duration; |
72 return KeyframeEffect::Create(element.Get(), effect, timing); | 72 return KeyframeEffect::Create(element.Get(), effect, timing); |
73 } | 73 } |
74 | 74 |
75 AnimatableValue* InterpolationValue( | 75 double GetDoubleValue(const ActiveInterpolationsMap& active_interpolations, |
76 const ActiveInterpolationsMap& active_interpolations, | 76 CSSPropertyID id) { |
77 CSSPropertyID id) { | |
78 Interpolation& interpolation = | 77 Interpolation& interpolation = |
79 *active_interpolations.at(PropertyHandle(id)).at(0); | 78 *active_interpolations.at(PropertyHandle(id)).at(0); |
80 return ToLegacyStyleInterpolation(interpolation).CurrentValue().Get(); | 79 AnimatableValue* animatable_value = |
| 80 ToLegacyStyleInterpolation(interpolation).CurrentValue().Get(); |
| 81 return ToAnimatableDouble(animatable_value)->ToDouble(); |
81 } | 82 } |
82 | 83 |
83 std::unique_ptr<DummyPageHolder> page_holder; | 84 std::unique_ptr<DummyPageHolder> page_holder; |
84 Persistent<Document> document; | 85 Persistent<Document> document; |
85 Persistent<DocumentTimeline> timeline; | 86 Persistent<DocumentTimeline> timeline; |
86 Persistent<Element> element; | 87 Persistent<Element> element; |
87 }; | 88 }; |
88 | 89 |
89 TEST_F(AnimationEffectStackTest, ElementAnimationsSorted) { | 90 TEST_F(AnimationEffectStackTest, ElementAnimationsSorted) { |
90 Play(MakeKeyframeEffect( | 91 Play(MakeKeyframeEffect( |
91 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(1))), | 92 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(1))), |
92 10); | 93 10); |
93 Play(MakeKeyframeEffect( | 94 Play(MakeKeyframeEffect( |
94 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(2))), | 95 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(2))), |
95 15); | 96 15); |
96 Play(MakeKeyframeEffect( | 97 Play(MakeKeyframeEffect( |
97 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(3))), | 98 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(3))), |
98 5); | 99 5); |
99 ActiveInterpolationsMap result = EffectStack::ActiveInterpolations( | 100 ActiveInterpolationsMap result = EffectStack::ActiveInterpolations( |
100 &element->GetElementAnimations()->GetEffectStack(), 0, 0, | 101 &element->GetElementAnimations()->GetEffectStack(), 0, 0, |
101 KeyframeEffectReadOnly::kDefaultPriority); | 102 KeyframeEffectReadOnly::kDefaultPriority); |
102 EXPECT_EQ(1u, result.size()); | 103 EXPECT_EQ(1u, result.size()); |
103 EXPECT_TRUE(InterpolationValue(result, CSSPropertyFontSize) | 104 EXPECT_EQ(GetDoubleValue(result, CSSPropertyFontSize), 3); |
104 ->Equals(AnimatableDouble::Create(3).Get())); | |
105 } | 105 } |
106 | 106 |
107 TEST_F(AnimationEffectStackTest, NewAnimations) { | 107 TEST_F(AnimationEffectStackTest, NewAnimations) { |
108 Play(MakeKeyframeEffect( | 108 Play(MakeKeyframeEffect( |
109 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(1))), | 109 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(1))), |
110 15); | 110 15); |
111 Play(MakeKeyframeEffect( | 111 Play(MakeKeyframeEffect( |
112 MakeEffectModel(CSSPropertyZIndex, AnimatableDouble::Create(2))), | 112 MakeEffectModel(CSSPropertyZIndex, AnimatableDouble::Create(2))), |
113 10); | 113 10); |
114 HeapVector<Member<const InertEffect>> new_animations; | 114 HeapVector<Member<const InertEffect>> new_animations; |
115 InertEffect* inert1 = MakeInertEffect( | 115 InertEffect* inert1 = MakeInertEffect( |
116 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(3))); | 116 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(3))); |
117 InertEffect* inert2 = MakeInertEffect( | 117 InertEffect* inert2 = MakeInertEffect( |
118 MakeEffectModel(CSSPropertyZIndex, AnimatableDouble::Create(4))); | 118 MakeEffectModel(CSSPropertyZIndex, AnimatableDouble::Create(4))); |
119 new_animations.push_back(inert1); | 119 new_animations.push_back(inert1); |
120 new_animations.push_back(inert2); | 120 new_animations.push_back(inert2); |
121 ActiveInterpolationsMap result = EffectStack::ActiveInterpolations( | 121 ActiveInterpolationsMap result = EffectStack::ActiveInterpolations( |
122 &element->GetElementAnimations()->GetEffectStack(), &new_animations, 0, | 122 &element->GetElementAnimations()->GetEffectStack(), &new_animations, 0, |
123 KeyframeEffectReadOnly::kDefaultPriority); | 123 KeyframeEffectReadOnly::kDefaultPriority); |
124 EXPECT_EQ(2u, result.size()); | 124 EXPECT_EQ(2u, result.size()); |
125 EXPECT_TRUE(InterpolationValue(result, CSSPropertyFontSize) | 125 EXPECT_EQ(GetDoubleValue(result, CSSPropertyFontSize), 3); |
126 ->Equals(AnimatableDouble::Create(3).Get())); | 126 EXPECT_EQ(GetDoubleValue(result, CSSPropertyZIndex), 4); |
127 EXPECT_TRUE(InterpolationValue(result, CSSPropertyZIndex) | |
128 ->Equals(AnimatableDouble::Create(4).Get())); | |
129 } | 127 } |
130 | 128 |
131 TEST_F(AnimationEffectStackTest, CancelledAnimations) { | 129 TEST_F(AnimationEffectStackTest, CancelledAnimations) { |
132 HeapHashSet<Member<const Animation>> cancelled_animations; | 130 HeapHashSet<Member<const Animation>> cancelled_animations; |
133 Animation* animation = | 131 Animation* animation = |
134 Play(MakeKeyframeEffect(MakeEffectModel(CSSPropertyFontSize, | 132 Play(MakeKeyframeEffect(MakeEffectModel(CSSPropertyFontSize, |
135 AnimatableDouble::Create(1))), | 133 AnimatableDouble::Create(1))), |
136 0); | 134 0); |
137 cancelled_animations.insert(animation); | 135 cancelled_animations.insert(animation); |
138 Play(MakeKeyframeEffect( | 136 Play(MakeKeyframeEffect( |
139 MakeEffectModel(CSSPropertyZIndex, AnimatableDouble::Create(2))), | 137 MakeEffectModel(CSSPropertyZIndex, AnimatableDouble::Create(2))), |
140 0); | 138 0); |
141 ActiveInterpolationsMap result = EffectStack::ActiveInterpolations( | 139 ActiveInterpolationsMap result = EffectStack::ActiveInterpolations( |
142 &element->GetElementAnimations()->GetEffectStack(), 0, | 140 &element->GetElementAnimations()->GetEffectStack(), 0, |
143 &cancelled_animations, KeyframeEffectReadOnly::kDefaultPriority); | 141 &cancelled_animations, KeyframeEffectReadOnly::kDefaultPriority); |
144 EXPECT_EQ(1u, result.size()); | 142 EXPECT_EQ(1u, result.size()); |
145 EXPECT_TRUE(InterpolationValue(result, CSSPropertyZIndex) | 143 EXPECT_EQ(GetDoubleValue(result, CSSPropertyZIndex), 2); |
146 ->Equals(AnimatableDouble::Create(2).Get())); | |
147 } | 144 } |
148 | 145 |
149 TEST_F(AnimationEffectStackTest, ClearedEffectsRemoved) { | 146 TEST_F(AnimationEffectStackTest, ClearedEffectsRemoved) { |
150 Animation* animation = | 147 Animation* animation = |
151 Play(MakeKeyframeEffect(MakeEffectModel(CSSPropertyFontSize, | 148 Play(MakeKeyframeEffect(MakeEffectModel(CSSPropertyFontSize, |
152 AnimatableDouble::Create(1))), | 149 AnimatableDouble::Create(1))), |
153 10); | 150 10); |
154 ActiveInterpolationsMap result = EffectStack::ActiveInterpolations( | 151 ActiveInterpolationsMap result = EffectStack::ActiveInterpolations( |
155 &element->GetElementAnimations()->GetEffectStack(), 0, 0, | 152 &element->GetElementAnimations()->GetEffectStack(), 0, 0, |
156 KeyframeEffectReadOnly::kDefaultPriority); | 153 KeyframeEffectReadOnly::kDefaultPriority); |
157 EXPECT_EQ(1u, result.size()); | 154 EXPECT_EQ(1u, result.size()); |
158 EXPECT_TRUE(InterpolationValue(result, CSSPropertyFontSize) | 155 EXPECT_EQ(GetDoubleValue(result, CSSPropertyFontSize), 1); |
159 ->Equals(AnimatableDouble::Create(1).Get())); | |
160 | 156 |
161 animation->setEffect(0); | 157 animation->setEffect(0); |
162 result = EffectStack::ActiveInterpolations( | 158 result = EffectStack::ActiveInterpolations( |
163 &element->GetElementAnimations()->GetEffectStack(), 0, 0, | 159 &element->GetElementAnimations()->GetEffectStack(), 0, 0, |
164 KeyframeEffectReadOnly::kDefaultPriority); | 160 KeyframeEffectReadOnly::kDefaultPriority); |
165 EXPECT_EQ(0u, result.size()); | 161 EXPECT_EQ(0u, result.size()); |
166 } | 162 } |
167 | 163 |
168 TEST_F(AnimationEffectStackTest, ForwardsFillDiscarding) { | 164 TEST_F(AnimationEffectStackTest, ForwardsFillDiscarding) { |
169 Play(MakeKeyframeEffect( | 165 Play(MakeKeyframeEffect( |
170 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(1))), | 166 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(1))), |
171 2); | 167 2); |
172 Play(MakeKeyframeEffect( | 168 Play(MakeKeyframeEffect( |
173 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(2))), | 169 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(2))), |
174 6); | 170 6); |
175 Play(MakeKeyframeEffect( | 171 Play(MakeKeyframeEffect( |
176 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(3))), | 172 MakeEffectModel(CSSPropertyFontSize, AnimatableDouble::Create(3))), |
177 4); | 173 4); |
178 document->GetCompositorPendingAnimations().Update( | 174 document->GetCompositorPendingAnimations().Update( |
179 Optional<CompositorElementIdSet>()); | 175 Optional<CompositorElementIdSet>()); |
180 ActiveInterpolationsMap interpolations; | 176 ActiveInterpolationsMap interpolations; |
181 | 177 |
182 UpdateTimeline(11); | 178 UpdateTimeline(11); |
183 ThreadState::Current()->CollectAllGarbage(); | 179 ThreadState::Current()->CollectAllGarbage(); |
184 interpolations = EffectStack::ActiveInterpolations( | 180 interpolations = EffectStack::ActiveInterpolations( |
185 &element->GetElementAnimations()->GetEffectStack(), nullptr, nullptr, | 181 &element->GetElementAnimations()->GetEffectStack(), nullptr, nullptr, |
186 KeyframeEffectReadOnly::kDefaultPriority); | 182 KeyframeEffectReadOnly::kDefaultPriority); |
187 EXPECT_EQ(1u, interpolations.size()); | 183 EXPECT_EQ(1u, interpolations.size()); |
188 EXPECT_TRUE(InterpolationValue(interpolations, CSSPropertyFontSize) | 184 EXPECT_EQ(GetDoubleValue(interpolations, CSSPropertyFontSize), 3); |
189 ->Equals(AnimatableDouble::Create(3).Get())); | |
190 EXPECT_EQ(3u, SampledEffectCount()); | 185 EXPECT_EQ(3u, SampledEffectCount()); |
191 | 186 |
192 UpdateTimeline(13); | 187 UpdateTimeline(13); |
193 ThreadState::Current()->CollectAllGarbage(); | 188 ThreadState::Current()->CollectAllGarbage(); |
194 interpolations = EffectStack::ActiveInterpolations( | 189 interpolations = EffectStack::ActiveInterpolations( |
195 &element->GetElementAnimations()->GetEffectStack(), nullptr, nullptr, | 190 &element->GetElementAnimations()->GetEffectStack(), nullptr, nullptr, |
196 KeyframeEffectReadOnly::kDefaultPriority); | 191 KeyframeEffectReadOnly::kDefaultPriority); |
197 EXPECT_EQ(1u, interpolations.size()); | 192 EXPECT_EQ(1u, interpolations.size()); |
198 EXPECT_TRUE(InterpolationValue(interpolations, CSSPropertyFontSize) | 193 EXPECT_EQ(GetDoubleValue(interpolations, CSSPropertyFontSize), 3); |
199 ->Equals(AnimatableDouble::Create(3).Get())); | |
200 EXPECT_EQ(3u, SampledEffectCount()); | 194 EXPECT_EQ(3u, SampledEffectCount()); |
201 | 195 |
202 UpdateTimeline(15); | 196 UpdateTimeline(15); |
203 ThreadState::Current()->CollectAllGarbage(); | 197 ThreadState::Current()->CollectAllGarbage(); |
204 interpolations = EffectStack::ActiveInterpolations( | 198 interpolations = EffectStack::ActiveInterpolations( |
205 &element->GetElementAnimations()->GetEffectStack(), nullptr, nullptr, | 199 &element->GetElementAnimations()->GetEffectStack(), nullptr, nullptr, |
206 KeyframeEffectReadOnly::kDefaultPriority); | 200 KeyframeEffectReadOnly::kDefaultPriority); |
207 EXPECT_EQ(1u, interpolations.size()); | 201 EXPECT_EQ(1u, interpolations.size()); |
208 EXPECT_TRUE(InterpolationValue(interpolations, CSSPropertyFontSize) | 202 EXPECT_EQ(GetDoubleValue(interpolations, CSSPropertyFontSize), 3); |
209 ->Equals(AnimatableDouble::Create(3).Get())); | |
210 EXPECT_EQ(2u, SampledEffectCount()); | 203 EXPECT_EQ(2u, SampledEffectCount()); |
211 | 204 |
212 UpdateTimeline(17); | 205 UpdateTimeline(17); |
213 ThreadState::Current()->CollectAllGarbage(); | 206 ThreadState::Current()->CollectAllGarbage(); |
214 interpolations = EffectStack::ActiveInterpolations( | 207 interpolations = EffectStack::ActiveInterpolations( |
215 &element->GetElementAnimations()->GetEffectStack(), nullptr, nullptr, | 208 &element->GetElementAnimations()->GetEffectStack(), nullptr, nullptr, |
216 KeyframeEffectReadOnly::kDefaultPriority); | 209 KeyframeEffectReadOnly::kDefaultPriority); |
217 EXPECT_EQ(1u, interpolations.size()); | 210 EXPECT_EQ(1u, interpolations.size()); |
218 EXPECT_TRUE(InterpolationValue(interpolations, CSSPropertyFontSize) | 211 EXPECT_EQ(GetDoubleValue(interpolations, CSSPropertyFontSize), 3); |
219 ->Equals(AnimatableDouble::Create(3).Get())); | |
220 EXPECT_EQ(1u, SampledEffectCount()); | 212 EXPECT_EQ(1u, SampledEffectCount()); |
221 } | 213 } |
222 | 214 |
223 } // namespace blink | 215 } // namespace blink |
OLD | NEW |