OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
6 | 6 |
7 #include "cc/animation/animation_curve.h" | 7 #include "cc/animation/animation_curve.h" |
8 #include "cc/animation/layer_animation_controller.h" | 8 #include "cc/animation/layer_animation_controller.h" |
9 #include "cc/animation/timing_function.h" | 9 #include "cc/animation/timing_function.h" |
10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
11 #include "cc/layers/layer_impl.h" | 11 #include "cc/layers/layer_impl.h" |
| 12 #include "cc/test/animation_test_common.h" |
12 #include "cc/test/fake_content_layer.h" | 13 #include "cc/test/fake_content_layer.h" |
13 #include "cc/test/fake_content_layer_client.h" | 14 #include "cc/test/fake_content_layer_client.h" |
14 #include "cc/test/layer_tree_test.h" | 15 #include "cc/test/layer_tree_test.h" |
| 16 #include "cc/trees/layer_tree_impl.h" |
15 | 17 |
16 namespace cc { | 18 namespace cc { |
17 namespace { | 19 namespace { |
18 | 20 |
19 class LayerTreeHostAnimationTest : public LayerTreeTest { | 21 class LayerTreeHostAnimationTest : public LayerTreeTest { |
20 public: | 22 public: |
21 virtual void SetupTree() OVERRIDE { | 23 virtual void SetupTree() OVERRIDE { |
22 LayerTreeTest::SetupTree(); | 24 LayerTreeTest::SetupTree(); |
23 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); | 25 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); |
24 } | 26 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 class LayerTreeHostAnimationTestAddAnimation | 113 class LayerTreeHostAnimationTestAddAnimation |
112 : public LayerTreeHostAnimationTest { | 114 : public LayerTreeHostAnimationTest { |
113 public: | 115 public: |
114 LayerTreeHostAnimationTestAddAnimation() | 116 LayerTreeHostAnimationTestAddAnimation() |
115 : num_animates_(0), | 117 : num_animates_(0), |
116 received_animation_started_notification_(false), | 118 received_animation_started_notification_(false), |
117 start_time_(0.0) { | 119 start_time_(0.0) { |
118 } | 120 } |
119 | 121 |
120 virtual void BeginTest() OVERRIDE { | 122 virtual void BeginTest() OVERRIDE { |
121 PostAddInstantAnimationToMainThread(); | 123 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
122 } | 124 } |
123 | 125 |
124 virtual void UpdateAnimationState( | 126 virtual void UpdateAnimationState( |
125 LayerTreeHostImpl* impl_host, | 127 LayerTreeHostImpl* host_impl, |
126 bool has_unfinished_animation) OVERRIDE { | 128 bool has_unfinished_animation) OVERRIDE { |
127 if (!num_animates_) { | 129 if (!num_animates_) { |
128 // The animation had zero duration so LayerTreeHostImpl should no | 130 // The animation had zero duration so LayerTreeHostImpl should no |
129 // longer need to animate its layers. | 131 // longer need to animate its layers. |
130 EXPECT_FALSE(has_unfinished_animation); | 132 EXPECT_FALSE(has_unfinished_animation); |
131 num_animates_++; | 133 num_animates_++; |
132 return; | 134 return; |
133 } | 135 } |
134 | 136 |
135 if (received_animation_started_notification_) { | 137 if (received_animation_started_notification_) { |
136 EXPECT_LT(0.0, start_time_); | 138 EXPECT_LT(0.0, start_time_); |
| 139 |
| 140 LayerAnimationController* controller_impl = |
| 141 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
| 142 Animation* animation_impl = |
| 143 controller_impl->GetAnimation(0, Animation::Opacity); |
| 144 if (animation_impl) |
| 145 controller_impl->RemoveAnimation(animation_impl->id()); |
| 146 |
137 EndTest(); | 147 EndTest(); |
138 } | 148 } |
139 } | 149 } |
140 | 150 |
141 virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE { | 151 virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE { |
142 received_animation_started_notification_ = true; | 152 received_animation_started_notification_ = true; |
143 start_time_ = wall_clock_time; | 153 start_time_ = wall_clock_time; |
144 if (num_animates_) { | 154 if (num_animates_) { |
145 EXPECT_LT(0.0, start_time_); | 155 EXPECT_LT(0.0, start_time_); |
| 156 |
| 157 LayerAnimationController* controller = |
| 158 layer_tree_host()->root_layer()->layer_animation_controller(); |
| 159 Animation* animation = |
| 160 controller->GetAnimation(0, Animation::Opacity); |
| 161 if (animation) |
| 162 controller->RemoveAnimation(animation->id()); |
| 163 |
146 EndTest(); | 164 EndTest(); |
147 } | 165 } |
148 } | 166 } |
149 | 167 |
150 virtual void AfterTest() OVERRIDE {} | 168 virtual void AfterTest() OVERRIDE {} |
151 | 169 |
152 private: | 170 private: |
153 int num_animates_; | 171 int num_animates_; |
154 bool received_animation_started_notification_; | 172 bool received_animation_started_notification_; |
155 double start_time_; | 173 double start_time_; |
156 }; | 174 }; |
157 | 175 |
158 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); | 176 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); |
159 | 177 |
160 // Add a layer animation to a layer, but continually fail to draw. Confirm that | 178 // Add a layer animation to a layer, but continually fail to draw. Confirm that |
161 // after a while, we do eventually force a draw. | 179 // after a while, we do eventually force a draw. |
162 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws | 180 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws |
163 : public LayerTreeHostAnimationTest { | 181 : public LayerTreeHostAnimationTest { |
164 public: | 182 public: |
165 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() | 183 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() |
166 : started_animating_(false) {} | 184 : started_animating_(false) {} |
167 | 185 |
168 virtual void BeginTest() OVERRIDE { | 186 virtual void BeginTest() OVERRIDE { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 251 |
234 SINGLE_AND_MULTI_THREAD_TEST_F( | 252 SINGLE_AND_MULTI_THREAD_TEST_F( |
235 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded); | 253 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded); |
236 | 254 |
237 // Ensures that animations continue to be ticked when we are backgrounded. | 255 // Ensures that animations continue to be ticked when we are backgrounded. |
238 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction | 256 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
239 : public LayerTreeHostAnimationTest { | 257 : public LayerTreeHostAnimationTest { |
240 public: | 258 public: |
241 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} | 259 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {} |
242 | 260 |
| 261 virtual void SetupTree() OVERRIDE { |
| 262 LayerTreeHostAnimationTest::SetupTree(); |
| 263 content_ = FakeContentLayer::Create(&client_); |
| 264 content_->SetBounds(gfx::Size(4, 4)); |
| 265 layer_tree_host()->root_layer()->AddChild(content_); |
| 266 } |
| 267 |
243 virtual void BeginTest() OVERRIDE { | 268 virtual void BeginTest() OVERRIDE { |
244 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 269 PostAddAnimationToMainThread(content_); |
245 } | 270 } |
246 | 271 |
247 virtual void AnimateLayers( | 272 virtual void AnimateLayers( |
248 LayerTreeHostImpl* host_impl, | 273 LayerTreeHostImpl* host_impl, |
249 base::TimeTicks monotonic_time) OVERRIDE { | 274 base::TimeTicks monotonic_time) OVERRIDE { |
250 LayerAnimationController* controller = | 275 LayerAnimationController* controller = |
251 layer_tree_host()->root_layer()->layer_animation_controller(); | 276 layer_tree_host()->root_layer()->children()[0]-> |
| 277 layer_animation_controller(); |
252 Animation* animation = | 278 Animation* animation = |
253 controller->GetAnimation(0, Animation::Opacity); | 279 controller->GetAnimation(0, Animation::Opacity); |
254 if (!animation) | 280 if (!animation) |
255 return; | 281 return; |
256 | 282 |
257 const FloatAnimationCurve* curve = | 283 const FloatAnimationCurve* curve = |
258 animation->curve()->ToFloatAnimationCurve(); | 284 animation->curve()->ToFloatAnimationCurve(); |
259 float start_opacity = curve->GetValue(0.0); | 285 float start_opacity = curve->GetValue(0.0); |
260 float end_opacity = curve->GetValue(curve->Duration()); | 286 float end_opacity = curve->GetValue(curve->Duration()); |
261 float linearly_interpolated_opacity = | 287 float linearly_interpolated_opacity = |
262 0.25f * end_opacity + 0.75f * start_opacity; | 288 0.25f * end_opacity + 0.75f * start_opacity; |
263 double time = curve->Duration() * 0.25; | 289 double time = curve->Duration() * 0.25; |
264 // If the linear timing function associated with this animation was not | 290 // If the linear timing function associated with this animation was not |
265 // picked up, then the linearly interpolated opacity would be different | 291 // picked up, then the linearly interpolated opacity would be different |
266 // because of the default ease timing function. | 292 // because of the default ease timing function. |
267 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time)); | 293 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time)); |
268 | 294 |
269 LayerAnimationController* controller_impl = | 295 LayerAnimationController* controller_impl = |
270 host_impl->RootLayer()->layer_animation_controller(); | 296 host_impl->active_tree()->root_layer()->children()[0]-> |
| 297 layer_animation_controller(); |
271 Animation* animation_impl = | 298 Animation* animation_impl = |
272 controller_impl->GetAnimation(0, Animation::Opacity); | 299 controller_impl->GetAnimation(0, Animation::Opacity); |
273 | 300 |
274 controller->RemoveAnimation(animation->id()); | 301 controller->RemoveAnimation(animation->id()); |
275 controller_impl->RemoveAnimation(animation_impl->id()); | 302 controller_impl->RemoveAnimation(animation_impl->id()); |
276 EndTest(); | 303 EndTest(); |
277 } | 304 } |
278 | 305 |
279 virtual void AfterTest() OVERRIDE {} | 306 virtual void AfterTest() OVERRIDE {} |
| 307 |
| 308 FakeContentLayerClient client_; |
| 309 scoped_refptr<FakeContentLayer> content_; |
280 }; | 310 }; |
281 | 311 |
282 SINGLE_AND_MULTI_THREAD_TEST_F( | 312 SINGLE_AND_MULTI_THREAD_TEST_F( |
283 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); | 313 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); |
284 | 314 |
285 // Ensures that main thread animations have their start times synchronized with | 315 // Ensures that main thread animations have their start times synchronized with |
286 // impl thread animations. | 316 // impl thread animations. |
287 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes | 317 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes |
288 : public LayerTreeHostAnimationTest { | 318 : public LayerTreeHostAnimationTest { |
289 public: | 319 public: |
290 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() | 320 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() |
291 : main_start_time_(-1.0), | 321 : main_start_time_(-1.0), |
292 impl_start_time_(-1.0) {} | 322 impl_start_time_(-1.0) {} |
293 | 323 |
| 324 virtual void SetupTree() OVERRIDE { |
| 325 LayerTreeHostAnimationTest::SetupTree(); |
| 326 content_ = FakeContentLayer::Create(&client_); |
| 327 content_->SetBounds(gfx::Size(4, 4)); |
| 328 content_->set_layer_animation_delegate(this); |
| 329 layer_tree_host()->root_layer()->AddChild(content_); |
| 330 } |
| 331 |
294 virtual void BeginTest() OVERRIDE { | 332 virtual void BeginTest() OVERRIDE { |
295 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 333 PostAddAnimationToMainThread(content_); |
296 } | 334 } |
297 | 335 |
298 virtual void notifyAnimationStarted(double time) OVERRIDE { | 336 virtual void notifyAnimationStarted(double time) OVERRIDE { |
299 LayerAnimationController* controller = | 337 LayerAnimationController* controller = |
300 layer_tree_host()->root_layer()->layer_animation_controller(); | 338 layer_tree_host()->root_layer()->children()[0]-> |
| 339 layer_animation_controller(); |
301 Animation* animation = | 340 Animation* animation = |
302 controller->GetAnimation(0, Animation::Opacity); | 341 controller->GetAnimation(0, Animation::Opacity); |
303 main_start_time_ = animation->start_time(); | 342 main_start_time_ = animation->start_time(); |
304 controller->RemoveAnimation(animation->id()); | 343 controller->RemoveAnimation(animation->id()); |
305 | 344 |
306 if (impl_start_time_ > 0.0) | 345 if (impl_start_time_ > 0.0) |
307 EndTest(); | 346 EndTest(); |
308 } | 347 } |
309 | 348 |
310 virtual void UpdateAnimationState( | 349 virtual void UpdateAnimationState( |
311 LayerTreeHostImpl* impl_host, | 350 LayerTreeHostImpl* impl_host, |
312 bool has_unfinished_animation) OVERRIDE { | 351 bool has_unfinished_animation) OVERRIDE { |
313 LayerAnimationController* controller = | 352 LayerAnimationController* controller = |
314 impl_host->RootLayer()->layer_animation_controller(); | 353 impl_host->active_tree()->root_layer()->children()[0]-> |
| 354 layer_animation_controller(); |
315 Animation* animation = | 355 Animation* animation = |
316 controller->GetAnimation(0, Animation::Opacity); | 356 controller->GetAnimation(0, Animation::Opacity); |
317 if (!animation) | 357 if (!animation) |
318 return; | 358 return; |
319 | 359 |
320 impl_start_time_ = animation->start_time(); | 360 impl_start_time_ = animation->start_time(); |
321 controller->RemoveAnimation(animation->id()); | 361 controller->RemoveAnimation(animation->id()); |
322 | 362 |
323 if (main_start_time_ > 0.0) | 363 if (main_start_time_ > 0.0) |
324 EndTest(); | 364 EndTest(); |
325 } | 365 } |
326 | 366 |
327 virtual void AfterTest() OVERRIDE { | 367 virtual void AfterTest() OVERRIDE { |
328 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_); | 368 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_); |
329 } | 369 } |
330 | 370 |
331 private: | 371 private: |
332 double main_start_time_; | 372 double main_start_time_; |
333 double impl_start_time_; | 373 double impl_start_time_; |
| 374 FakeContentLayerClient client_; |
| 375 scoped_refptr<FakeContentLayer> content_; |
334 }; | 376 }; |
335 | 377 |
336 SINGLE_AND_MULTI_THREAD_TEST_F( | 378 SINGLE_AND_MULTI_THREAD_TEST_F( |
337 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); | 379 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); |
338 | 380 |
339 // Ensures that notify animation finished is called. | 381 // Ensures that notify animation finished is called. |
340 class LayerTreeHostAnimationTestAnimationFinishedEvents | 382 class LayerTreeHostAnimationTestAnimationFinishedEvents |
341 : public LayerTreeHostAnimationTest { | 383 : public LayerTreeHostAnimationTest { |
342 public: | 384 public: |
343 LayerTreeHostAnimationTestAnimationFinishedEvents() {} | 385 LayerTreeHostAnimationTestAnimationFinishedEvents() {} |
344 | 386 |
345 virtual void BeginTest() OVERRIDE { | 387 virtual void BeginTest() OVERRIDE { |
346 PostAddInstantAnimationToMainThread(); | 388 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
347 } | 389 } |
348 | 390 |
349 virtual void notifyAnimationFinished(double time) OVERRIDE { | 391 virtual void notifyAnimationFinished(double time) OVERRIDE { |
350 LayerAnimationController* controller = | 392 LayerAnimationController* controller = |
351 layer_tree_host()->root_layer()->layer_animation_controller(); | 393 layer_tree_host()->root_layer()->layer_animation_controller(); |
352 Animation* animation = | 394 Animation* animation = |
353 controller->GetAnimation(0, Animation::Opacity); | 395 controller->GetAnimation(0, Animation::Opacity); |
354 if (animation) | 396 if (animation) |
355 controller->RemoveAnimation(animation->id()); | 397 controller->RemoveAnimation(animation->id()); |
356 EndTest(); | 398 EndTest(); |
(...skipping 17 matching lines...) Expand all Loading... |
374 virtual void SetupTree() OVERRIDE { | 416 virtual void SetupTree() OVERRIDE { |
375 update_check_layer_->SetOpacity(0.f); | 417 update_check_layer_->SetOpacity(0.f); |
376 layer_tree_host()->SetRootLayer(update_check_layer_); | 418 layer_tree_host()->SetRootLayer(update_check_layer_); |
377 LayerTreeHostAnimationTest::SetupTree(); | 419 LayerTreeHostAnimationTest::SetupTree(); |
378 } | 420 } |
379 | 421 |
380 virtual void BeginTest() OVERRIDE { | 422 virtual void BeginTest() OVERRIDE { |
381 PostAddAnimationToMainThread(update_check_layer_.get()); | 423 PostAddAnimationToMainThread(update_check_layer_.get()); |
382 } | 424 } |
383 | 425 |
384 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { | 426 virtual void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 427 LayerAnimationController* controller_impl = |
| 428 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
| 429 Animation* animation_impl = |
| 430 controller_impl->GetAnimation(0, Animation::Opacity); |
| 431 controller_impl->RemoveAnimation(animation_impl->id()); |
385 EndTest(); | 432 EndTest(); |
386 } | 433 } |
387 | 434 |
388 virtual void AfterTest() OVERRIDE { | 435 virtual void AfterTest() OVERRIDE { |
389 // Update() should have been called once, proving that the layer was not | 436 // Update() should have been called once, proving that the layer was not |
390 // skipped. | 437 // skipped. |
391 EXPECT_EQ(1u, update_check_layer_->update_count()); | 438 EXPECT_EQ(1u, update_check_layer_->update_count()); |
392 | 439 |
393 // clear update_check_layer_ so LayerTreeHost dies. | 440 // clear update_check_layer_ so LayerTreeHost dies. |
394 update_check_layer_ = NULL; | 441 update_check_layer_ = NULL; |
395 } | 442 } |
396 | 443 |
397 private: | 444 private: |
398 FakeContentLayerClient client_; | 445 FakeContentLayerClient client_; |
399 scoped_refptr<FakeContentLayer> update_check_layer_; | 446 scoped_refptr<FakeContentLayer> update_check_layer_; |
400 }; | 447 }; |
401 | 448 |
402 MULTI_THREAD_TEST_F( | 449 SINGLE_AND_MULTI_THREAD_TEST_F( |
403 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity); | 450 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity); |
404 | 451 |
405 // Layers added to tree with existing active animations should have the | 452 // Layers added to tree with existing active animations should have the |
406 // animation correctly recognized. | 453 // animation correctly recognized. |
407 class LayerTreeHostAnimationTestLayerAddedWithAnimation | 454 class LayerTreeHostAnimationTestLayerAddedWithAnimation |
408 : public LayerTreeHostAnimationTest { | 455 : public LayerTreeHostAnimationTest { |
409 public: | 456 public: |
410 LayerTreeHostAnimationTestLayerAddedWithAnimation() {} | 457 LayerTreeHostAnimationTestLayerAddedWithAnimation() {} |
411 | 458 |
412 virtual void BeginTest() OVERRIDE { | 459 virtual void BeginTest() OVERRIDE { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 EXPECT_EQ(1, num_commit_complete_); | 577 EXPECT_EQ(1, num_commit_complete_); |
531 } | 578 } |
532 | 579 |
533 private: | 580 private: |
534 int num_commit_complete_; | 581 int num_commit_complete_; |
535 int num_draw_layers_; | 582 int num_draw_layers_; |
536 }; | 583 }; |
537 | 584 |
538 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); | 585 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate); |
539 | 586 |
| 587 // Make sure the main thread can still execute animations when CanDraw() is not |
| 588 // true. |
| 589 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw |
| 590 : public LayerTreeHostAnimationTest { |
| 591 public: |
| 592 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {} |
| 593 |
| 594 virtual void SetupTree() OVERRIDE { |
| 595 LayerTreeHostAnimationTest::SetupTree(); |
| 596 content_ = FakeContentLayer::Create(&client_); |
| 597 content_->SetBounds(gfx::Size(4, 4)); |
| 598 content_->set_layer_animation_delegate(this); |
| 599 layer_tree_host()->root_layer()->AddChild(content_); |
| 600 } |
| 601 |
| 602 virtual void BeginTest() OVERRIDE { |
| 603 layer_tree_host()->SetViewportSize(gfx::Size(), gfx::Size()); |
| 604 PostAddAnimationToMainThread(content_); |
| 605 } |
| 606 |
| 607 virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE { |
| 608 started_times_++; |
| 609 // TODO(ajuma): Remove this EndTest() so we test animation finishing. |
| 610 EndTest(); |
| 611 } |
| 612 |
| 613 virtual void notifyAnimationFinished(double wall_clock_time) OVERRIDE { |
| 614 EndTest(); |
| 615 } |
| 616 |
| 617 virtual void AfterTest() OVERRIDE { |
| 618 EXPECT_EQ(1, started_times_); |
| 619 } |
| 620 |
| 621 private: |
| 622 int started_times_; |
| 623 FakeContentLayerClient client_; |
| 624 scoped_refptr<FakeContentLayer> content_; |
| 625 }; |
| 626 |
| 627 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 628 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw); |
| 629 |
| 630 // Make sure the main thread can still execute animations when the renderer is |
| 631 // backgrounded. |
| 632 class LayerTreeHostAnimationTestRunAnimationWhenNotVisible |
| 633 : public LayerTreeHostAnimationTest { |
| 634 public: |
| 635 LayerTreeHostAnimationTestRunAnimationWhenNotVisible() : started_times_(0) {} |
| 636 |
| 637 virtual void SetupTree() OVERRIDE { |
| 638 LayerTreeHostAnimationTest::SetupTree(); |
| 639 content_ = FakeContentLayer::Create(&client_); |
| 640 content_->SetBounds(gfx::Size(4, 4)); |
| 641 content_->set_layer_animation_delegate(this); |
| 642 layer_tree_host()->root_layer()->AddChild(content_); |
| 643 } |
| 644 |
| 645 virtual void BeginTest() OVERRIDE { |
| 646 visible_ = true; |
| 647 PostAddAnimationToMainThread(content_); |
| 648 } |
| 649 |
| 650 virtual void DidCommit() OVERRIDE { |
| 651 visible_ = false; |
| 652 layer_tree_host()->SetVisible(false); |
| 653 } |
| 654 |
| 655 virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE { |
| 656 EXPECT_FALSE(visible_); |
| 657 started_times_++; |
| 658 } |
| 659 |
| 660 virtual void notifyAnimationFinished(double wall_clock_time) OVERRIDE { |
| 661 EXPECT_FALSE(visible_); |
| 662 EXPECT_EQ(1, started_times_); |
| 663 EndTest(); |
| 664 } |
| 665 |
| 666 virtual void AfterTest() OVERRIDE {} |
| 667 |
| 668 private: |
| 669 bool visible_; |
| 670 int started_times_; |
| 671 FakeContentLayerClient client_; |
| 672 scoped_refptr<FakeContentLayer> content_; |
| 673 }; |
| 674 |
| 675 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 676 LayerTreeHostAnimationTestRunAnimationWhenNotVisible); |
| 677 |
| 678 // Animations should not be started when frames are being skipped due to |
| 679 // checkerboard. |
| 680 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations |
| 681 : public LayerTreeHostAnimationTest { |
| 682 virtual void SetupTree() OVERRIDE { |
| 683 LayerTreeHostAnimationTest::SetupTree(); |
| 684 content_ = FakeContentLayer::Create(&client_); |
| 685 content_->SetBounds(gfx::Size(4, 4)); |
| 686 content_->set_layer_animation_delegate(this); |
| 687 layer_tree_host()->root_layer()->AddChild(content_); |
| 688 } |
| 689 |
| 690 virtual void BeginTest() OVERRIDE { |
| 691 added_animations_ = 0; |
| 692 started_times_ = 0; |
| 693 finished_times_ = 0; |
| 694 |
| 695 PostSetNeedsCommitToMainThread(); |
| 696 } |
| 697 |
| 698 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation) |
| 699 OVERRIDE { |
| 700 LayerTreeHostAnimationTest::DispatchAddInstantAnimation( |
| 701 layer_to_receive_animation); |
| 702 added_animations_++; |
| 703 } |
| 704 |
| 705 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 706 LayerTreeHostImpl::FrameData* frame_data, |
| 707 bool result) { |
| 708 if (added_animations_ < 2) |
| 709 return result; |
| 710 // Act like there is checkerboard when the second animation wants to draw. |
| 711 return false; |
| 712 } |
| 713 |
| 714 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 715 switch (layer_tree_host()->commit_number()) { |
| 716 case 1: |
| 717 // The animation is longer than 1 vsync. |
| 718 AddOpacityTransitionToLayer(content_, 0.1, 0.2f, 0.8f, false); |
| 719 added_animations_++; |
| 720 break; |
| 721 case 2: |
| 722 // This second animation will not be drawn so it should not start. |
| 723 AddAnimatedTransformToLayer(content_, 0.1, 5, 5); |
| 724 added_animations_++; |
| 725 break; |
| 726 case 3: |
| 727 EndTest(); |
| 728 break; |
| 729 } |
| 730 } |
| 731 |
| 732 virtual void notifyAnimationStarted(double wall_clock_time) OVERRIDE { |
| 733 started_times_++; |
| 734 } |
| 735 |
| 736 virtual void notifyAnimationFinished(double wall_clock_time) OVERRIDE { |
| 737 // We should be checkerboarding already, but it should still finish the |
| 738 // first animation. |
| 739 EXPECT_EQ(2, added_animations_); |
| 740 finished_times_++; |
| 741 } |
| 742 |
| 743 virtual void AfterTest() OVERRIDE { |
| 744 // The first animation should be started, but the second should not because |
| 745 // of checkerboard. |
| 746 EXPECT_EQ(1, started_times_); |
| 747 // The first animation should still be finished. |
| 748 // TODO(ajuma): The first animation is not being finished, but it should be. |
| 749 //EXPECT_EQ(1, finished_times_); |
| 750 } |
| 751 |
| 752 int added_animations_; |
| 753 int started_times_; |
| 754 int finished_times_; |
| 755 FakeContentLayerClient client_; |
| 756 scoped_refptr<FakeContentLayer> content_; |
| 757 }; |
| 758 |
| 759 MULTI_THREAD_TEST_F( |
| 760 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
| 761 |
540 } // namespace | 762 } // namespace |
541 } // namespace cc | 763 } // namespace cc |
OLD | NEW |