OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/test/animation_timelines_test_common.h" | 5 #include "cc/test/animation_timelines_test_common.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "cc/animation/animation_events.h" | 8 #include "cc/animation/animation_events.h" |
9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
10 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
11 #include "cc/animation/animation_timeline.h" | 11 #include "cc/animation/animation_timeline.h" |
12 #include "cc/animation/element_animations.h" | 12 #include "cc/animation/element_animations.h" |
13 #include "cc/output/filter_operation.h" | 13 #include "cc/output/filter_operation.h" |
14 #include "cc/output/filter_operations.h" | 14 #include "cc/output/filter_operations.h" |
15 #include "ui/gfx/transform.h" | 15 #include "ui/gfx/transform.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 std::unique_ptr<TestLayer> TestLayer::Create() { | 19 std::unique_ptr<TestLayer> TestLayer::Create() { |
20 return base::WrapUnique(new TestLayer()); | 20 return base::WrapUnique(new TestLayer()); |
21 } | 21 } |
22 | 22 |
23 TestLayer::TestLayer() { | 23 TestLayer::TestLayer() { |
24 ClearMutatedProperties(); | 24 ClearMutatedProperties(); |
25 } | 25 } |
26 | 26 |
| 27 TestLayer::~TestLayer() {} |
| 28 |
27 void TestLayer::ClearMutatedProperties() { | 29 void TestLayer::ClearMutatedProperties() { |
28 transform_ = gfx::Transform(); | 30 transform_ = gfx::Transform(); |
29 opacity_ = 0; | 31 opacity_ = 0; |
30 filters_ = FilterOperations(); | 32 filters_ = FilterOperations(); |
31 scroll_offset_ = gfx::ScrollOffset(); | 33 scroll_offset_ = gfx::ScrollOffset(); |
32 has_potential_transform_animation_ = false; | |
33 transform_is_currently_animating_ = false; | |
34 has_potential_opacity_animation_ = false; | |
35 opacity_is_currently_animating_ = false; | |
36 has_potential_filter_animation_ = false; | |
37 filter_is_currently_animating_ = false; | |
38 | 34 |
39 for (int i = 0; i <= TargetProperty::LAST_TARGET_PROPERTY; ++i) | 35 has_potential_animation_.reset(); |
40 mutated_properties_[i] = false; | 36 is_currently_animating_.reset(); |
| 37 mutated_properties_.reset(); |
41 } | 38 } |
42 | 39 |
43 int TestLayer::transform_x() const { | 40 int TestLayer::transform_x() const { |
44 gfx::Vector2dF vec = transform_.To2dTranslation(); | 41 gfx::Vector2dF vec = transform_.To2dTranslation(); |
45 return static_cast<int>(vec.x()); | 42 return static_cast<int>(vec.x()); |
46 } | 43 } |
47 | 44 |
48 int TestLayer::transform_y() const { | 45 int TestLayer::transform_y() const { |
49 gfx::Vector2dF vec = transform_.To2dTranslation(); | 46 gfx::Vector2dF vec = transform_.To2dTranslation(); |
50 return static_cast<int>(vec.y()); | 47 return static_cast<int>(vec.y()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 116 |
120 void TestHostClient::SetElementScrollOffsetMutated( | 117 void TestHostClient::SetElementScrollOffsetMutated( |
121 ElementId element_id, | 118 ElementId element_id, |
122 ElementListType list_type, | 119 ElementListType list_type, |
123 const gfx::ScrollOffset& scroll_offset) { | 120 const gfx::ScrollOffset& scroll_offset) { |
124 TestLayer* layer = FindTestLayer(element_id, list_type); | 121 TestLayer* layer = FindTestLayer(element_id, list_type); |
125 if (layer) | 122 if (layer) |
126 layer->set_scroll_offset(scroll_offset); | 123 layer->set_scroll_offset(scroll_offset); |
127 } | 124 } |
128 | 125 |
129 void TestHostClient::ElementTransformIsAnimatingChanged( | 126 void TestHostClient::ElementIsAnimatingChanged( |
130 ElementId element_id, | 127 ElementId element_id, |
131 ElementListType list_type, | 128 ElementListType list_type, |
132 AnimationChangeType change_type, | 129 const PropertyAnimationState& mask, |
133 bool is_animating) { | 130 const PropertyAnimationState& state) { |
134 TestLayer* layer = FindTestLayer(element_id, list_type); | 131 TestLayer* layer = FindTestLayer(element_id, list_type); |
135 if (layer) { | 132 if (!layer) |
136 switch (change_type) { | 133 return; |
137 case AnimationChangeType::POTENTIAL: | 134 |
138 layer->set_has_potential_transform_animation(is_animating); | 135 for (int property = TargetProperty::FIRST_TARGET_PROPERTY; |
139 break; | 136 property <= TargetProperty::LAST_TARGET_PROPERTY; ++property) { |
140 case AnimationChangeType::RUNNING: | 137 TargetProperty::Type target_property = |
141 layer->set_transform_is_currently_animating(is_animating); | 138 static_cast<TargetProperty::Type>(property); |
142 break; | 139 if (mask.potentially_animating[property]) |
143 case AnimationChangeType::BOTH: | 140 layer->set_has_potential_animation(target_property, |
144 layer->set_has_potential_transform_animation(is_animating); | 141 state.potentially_animating[property]); |
145 layer->set_transform_is_currently_animating(is_animating); | 142 if (mask.currently_running[property]) |
146 break; | 143 layer->set_is_currently_animating(target_property, |
147 } | 144 state.currently_running[property]); |
148 } | 145 } |
149 } | 146 } |
150 | 147 |
151 void TestHostClient::ElementOpacityIsAnimatingChanged( | |
152 ElementId element_id, | |
153 ElementListType list_type, | |
154 AnimationChangeType change_type, | |
155 bool is_animating) { | |
156 TestLayer* layer = FindTestLayer(element_id, list_type); | |
157 if (layer) { | |
158 switch (change_type) { | |
159 case AnimationChangeType::POTENTIAL: | |
160 layer->set_has_potential_opacity_animation(is_animating); | |
161 break; | |
162 case AnimationChangeType::RUNNING: | |
163 layer->set_opacity_is_currently_animating(is_animating); | |
164 break; | |
165 case AnimationChangeType::BOTH: | |
166 layer->set_has_potential_opacity_animation(is_animating); | |
167 layer->set_opacity_is_currently_animating(is_animating); | |
168 break; | |
169 } | |
170 } | |
171 } | |
172 | |
173 void TestHostClient::ElementFilterIsAnimatingChanged( | |
174 ElementId element_id, | |
175 ElementListType list_type, | |
176 AnimationChangeType change_type, | |
177 bool is_animating) { | |
178 TestLayer* layer = FindTestLayer(element_id, list_type); | |
179 if (layer) { | |
180 switch (change_type) { | |
181 case AnimationChangeType::POTENTIAL: | |
182 layer->set_has_potential_filter_animation(is_animating); | |
183 break; | |
184 case AnimationChangeType::RUNNING: | |
185 layer->set_filter_is_currently_animating(is_animating); | |
186 break; | |
187 case AnimationChangeType::BOTH: | |
188 layer->set_has_potential_filter_animation(is_animating); | |
189 layer->set_filter_is_currently_animating(is_animating); | |
190 break; | |
191 } | |
192 } | |
193 } | |
194 | |
195 void TestHostClient::SetScrollOffsetForAnimation( | 148 void TestHostClient::SetScrollOffsetForAnimation( |
196 const gfx::ScrollOffset& scroll_offset) { | 149 const gfx::ScrollOffset& scroll_offset) { |
197 scroll_offset_ = scroll_offset; | 150 scroll_offset_ = scroll_offset; |
198 } | 151 } |
199 | 152 |
200 gfx::ScrollOffset TestHostClient::GetScrollOffsetForAnimation( | 153 gfx::ScrollOffset TestHostClient::GetScrollOffsetForAnimation( |
201 ElementId element_id) const { | 154 ElementId element_id) const { |
202 return scroll_offset_; | 155 return scroll_offset_; |
203 } | 156 } |
204 | 157 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 TestLayer* layer = FindTestLayer(element_id, list_type); | 215 TestLayer* layer = FindTestLayer(element_id, list_type); |
263 EXPECT_TRUE(layer); | 216 EXPECT_TRUE(layer); |
264 return layer->scroll_offset(); | 217 return layer->scroll_offset(); |
265 } | 218 } |
266 | 219 |
267 bool TestHostClient::GetTransformIsCurrentlyAnimating( | 220 bool TestHostClient::GetTransformIsCurrentlyAnimating( |
268 ElementId element_id, | 221 ElementId element_id, |
269 ElementListType list_type) const { | 222 ElementListType list_type) const { |
270 TestLayer* layer = FindTestLayer(element_id, list_type); | 223 TestLayer* layer = FindTestLayer(element_id, list_type); |
271 EXPECT_TRUE(layer); | 224 EXPECT_TRUE(layer); |
272 return layer->transform_is_currently_animating(); | 225 return layer->is_currently_animating(TargetProperty::TRANSFORM); |
273 } | 226 } |
274 | 227 |
275 bool TestHostClient::GetHasPotentialTransformAnimation( | 228 bool TestHostClient::GetHasPotentialTransformAnimation( |
276 ElementId element_id, | 229 ElementId element_id, |
277 ElementListType list_type) const { | 230 ElementListType list_type) const { |
278 TestLayer* layer = FindTestLayer(element_id, list_type); | 231 TestLayer* layer = FindTestLayer(element_id, list_type); |
279 EXPECT_TRUE(layer); | 232 EXPECT_TRUE(layer); |
280 return layer->has_potential_transform_animation(); | 233 return layer->has_potential_animation(TargetProperty::TRANSFORM); |
281 } | 234 } |
282 | 235 |
283 bool TestHostClient::GetOpacityIsCurrentlyAnimating( | 236 bool TestHostClient::GetOpacityIsCurrentlyAnimating( |
284 ElementId element_id, | 237 ElementId element_id, |
285 ElementListType list_type) const { | 238 ElementListType list_type) const { |
286 TestLayer* layer = FindTestLayer(element_id, list_type); | 239 TestLayer* layer = FindTestLayer(element_id, list_type); |
287 EXPECT_TRUE(layer); | 240 EXPECT_TRUE(layer); |
288 return layer->opacity_is_currently_animating(); | 241 return layer->is_currently_animating(TargetProperty::OPACITY); |
289 } | 242 } |
290 | 243 |
291 bool TestHostClient::GetHasPotentialOpacityAnimation( | 244 bool TestHostClient::GetHasPotentialOpacityAnimation( |
292 ElementId element_id, | 245 ElementId element_id, |
293 ElementListType list_type) const { | 246 ElementListType list_type) const { |
294 TestLayer* layer = FindTestLayer(element_id, list_type); | 247 TestLayer* layer = FindTestLayer(element_id, list_type); |
295 EXPECT_TRUE(layer); | 248 EXPECT_TRUE(layer); |
296 return layer->has_potential_opacity_animation(); | 249 return layer->has_potential_animation(TargetProperty::OPACITY); |
297 } | 250 } |
298 | 251 |
299 bool TestHostClient::GetFilterIsCurrentlyAnimating( | 252 bool TestHostClient::GetFilterIsCurrentlyAnimating( |
300 ElementId element_id, | 253 ElementId element_id, |
301 ElementListType list_type) const { | 254 ElementListType list_type) const { |
302 TestLayer* layer = FindTestLayer(element_id, list_type); | 255 TestLayer* layer = FindTestLayer(element_id, list_type); |
303 EXPECT_TRUE(layer); | 256 EXPECT_TRUE(layer); |
304 return layer->filter_is_currently_animating(); | 257 return layer->is_currently_animating(TargetProperty::FILTER); |
305 } | 258 } |
306 | 259 |
307 bool TestHostClient::GetHasPotentialFilterAnimation( | 260 bool TestHostClient::GetHasPotentialFilterAnimation( |
308 ElementId element_id, | 261 ElementId element_id, |
309 ElementListType list_type) const { | 262 ElementListType list_type) const { |
310 TestLayer* layer = FindTestLayer(element_id, list_type); | 263 TestLayer* layer = FindTestLayer(element_id, list_type); |
311 EXPECT_TRUE(layer); | 264 EXPECT_TRUE(layer); |
312 return layer->has_potential_filter_animation(); | 265 return layer->has_potential_animation(TargetProperty::FILTER); |
313 } | 266 } |
314 | 267 |
315 void TestHostClient::ExpectFilterPropertyMutated(ElementId element_id, | 268 void TestHostClient::ExpectFilterPropertyMutated(ElementId element_id, |
316 ElementListType list_type, | 269 ElementListType list_type, |
317 float brightness) const { | 270 float brightness) const { |
318 TestLayer* layer = FindTestLayer(element_id, list_type); | 271 TestLayer* layer = FindTestLayer(element_id, list_type); |
319 EXPECT_TRUE(layer); | 272 EXPECT_TRUE(layer); |
320 EXPECT_TRUE(layer->is_property_mutated(TargetProperty::FILTER)); | 273 EXPECT_TRUE(layer->is_property_mutated(TargetProperty::FILTER)); |
321 EXPECT_EQ(brightness, layer->brightness()); | 274 EXPECT_EQ(brightness, layer->brightness()); |
322 } | 275 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 498 } |
546 | 499 |
547 return result; | 500 return result; |
548 } | 501 } |
549 | 502 |
550 void AnimationTimelinesTest::PushProperties() { | 503 void AnimationTimelinesTest::PushProperties() { |
551 host_->PushPropertiesTo(host_impl_); | 504 host_->PushPropertiesTo(host_impl_); |
552 } | 505 } |
553 | 506 |
554 } // namespace cc | 507 } // namespace cc |
OLD | NEW |