OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_tree_test.h" | 5 #include "cc/test/layer_tree_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "cc/animation/animation.h" | 8 #include "cc/animation/animation.h" |
9 #include "cc/animation/animation_registrar.h" | 9 #include "cc/animation/animation_registrar.h" |
10 #include "cc/animation/layer_animation_controller.h" | 10 #include "cc/animation/layer_animation_controller.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 virtual void DidCommit() OVERRIDE { test_hooks_->DidCommit(); } | 305 virtual void DidCommit() OVERRIDE { test_hooks_->DidCommit(); } |
306 | 306 |
307 virtual void DidCommitAndDrawFrame() OVERRIDE { | 307 virtual void DidCommitAndDrawFrame() OVERRIDE { |
308 test_hooks_->DidCommitAndDrawFrame(); | 308 test_hooks_->DidCommitAndDrawFrame(); |
309 } | 309 } |
310 | 310 |
311 virtual void DidCompleteSwapBuffers() OVERRIDE { | 311 virtual void DidCompleteSwapBuffers() OVERRIDE { |
312 test_hooks_->DidCompleteSwapBuffers(); | 312 test_hooks_->DidCompleteSwapBuffers(); |
313 } | 313 } |
314 | 314 |
| 315 virtual void ScheduleComposite() OVERRIDE { |
| 316 test_hooks_->ScheduleComposite(); |
| 317 } |
| 318 |
| 319 virtual void ScheduleAnimation() OVERRIDE { |
| 320 test_hooks_->ScheduleAnimation(); |
| 321 } |
| 322 |
315 virtual void DidPostSwapBuffers() OVERRIDE {} | 323 virtual void DidPostSwapBuffers() OVERRIDE {} |
316 virtual void DidAbortSwapBuffers() OVERRIDE {} | 324 virtual void DidAbortSwapBuffers() OVERRIDE {} |
317 | 325 |
318 private: | 326 private: |
319 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks) | 327 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks) |
320 : test_hooks_(test_hooks) {} | 328 : test_hooks_(test_hooks) {} |
321 | 329 |
322 TestHooks* test_hooks_; | 330 TestHooks* test_hooks_; |
323 }; | 331 }; |
324 | 332 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 387 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
380 TestHooks* test_hooks_; | 388 TestHooks* test_hooks_; |
381 bool test_started_; | 389 bool test_started_; |
382 }; | 390 }; |
383 | 391 |
384 LayerTreeTest::LayerTreeTest() | 392 LayerTreeTest::LayerTreeTest() |
385 : beginning_(false), | 393 : beginning_(false), |
386 end_when_begin_returns_(false), | 394 end_when_begin_returns_(false), |
387 timed_out_(false), | 395 timed_out_(false), |
388 scheduled_(false), | 396 scheduled_(false), |
| 397 schedule_when_set_visible_true_(false), |
389 started_(false), | 398 started_(false), |
390 ended_(false), | 399 ended_(false), |
391 delegating_renderer_(false), | 400 delegating_renderer_(false), |
392 timeout_seconds_(0), | 401 timeout_seconds_(0), |
393 weak_factory_(this) { | 402 weak_factory_(this) { |
394 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); | 403 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); |
395 | 404 |
396 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was | 405 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was |
397 // specified (for running in a debugger). | 406 // specified (for running in a debugger). |
398 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 407 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 gfx::Size device_root_bounds = gfx::ToCeiledSize( | 551 gfx::Size device_root_bounds = gfx::ToCeiledSize( |
543 gfx::ScaleSize(root_bounds, layer_tree_host_->device_scale_factor())); | 552 gfx::ScaleSize(root_bounds, layer_tree_host_->device_scale_factor())); |
544 layer_tree_host_->SetViewportSize(device_root_bounds); | 553 layer_tree_host_->SetViewportSize(device_root_bounds); |
545 } | 554 } |
546 | 555 |
547 void LayerTreeTest::Timeout() { | 556 void LayerTreeTest::Timeout() { |
548 timed_out_ = true; | 557 timed_out_ = true; |
549 EndTest(); | 558 EndTest(); |
550 } | 559 } |
551 | 560 |
| 561 void LayerTreeTest::ScheduleComposite() { |
| 562 if (!started_ || scheduled_) |
| 563 return; |
| 564 scheduled_ = true; |
| 565 main_task_runner_->PostTask( |
| 566 FROM_HERE, |
| 567 base::Bind(&LayerTreeTest::DispatchComposite, main_thread_weak_ptr_)); |
| 568 } |
| 569 |
552 void LayerTreeTest::RealEndTest() { | 570 void LayerTreeTest::RealEndTest() { |
553 if (layer_tree_host_ && !timed_out_ && | 571 if (layer_tree_host_ && !timed_out_ && |
554 proxy()->MainFrameWillHappenForTesting()) { | 572 proxy()->MainFrameWillHappenForTesting()) { |
555 main_task_runner_->PostTask( | 573 main_task_runner_->PostTask( |
556 FROM_HERE, | 574 FROM_HERE, |
557 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); | 575 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); |
558 return; | 576 return; |
559 } | 577 } |
560 | 578 |
561 base::MessageLoop::current()->Quit(); | 579 base::MessageLoop::current()->Quit(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 | 612 |
595 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 613 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
596 DCHECK(!proxy() || proxy()->IsMainThread()); | 614 DCHECK(!proxy() || proxy()->IsMainThread()); |
597 | 615 |
598 if (layer_tree_host_) | 616 if (layer_tree_host_) |
599 layer_tree_host_->SetNeedsRedrawRect(damage_rect); | 617 layer_tree_host_->SetNeedsRedrawRect(damage_rect); |
600 } | 618 } |
601 | 619 |
602 void LayerTreeTest::DispatchSetVisible(bool visible) { | 620 void LayerTreeTest::DispatchSetVisible(bool visible) { |
603 DCHECK(!proxy() || proxy()->IsMainThread()); | 621 DCHECK(!proxy() || proxy()->IsMainThread()); |
604 if (layer_tree_host_) | 622 |
605 layer_tree_host_->SetVisible(visible); | 623 if (!layer_tree_host_) |
| 624 return; |
| 625 |
| 626 layer_tree_host_->SetVisible(visible); |
| 627 |
| 628 // If the LTH is being made visible and a previous ScheduleComposite() was |
| 629 // deferred because the LTH was not visible, re-schedule the composite now. |
| 630 if (layer_tree_host_->visible() && schedule_when_set_visible_true_) |
| 631 ScheduleComposite(); |
606 } | 632 } |
607 | 633 |
608 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() { | 634 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() { |
609 DCHECK(!proxy() || proxy()->IsMainThread()); | 635 DCHECK(!proxy() || proxy()->IsMainThread()); |
610 | 636 |
611 if (layer_tree_host_) | 637 if (layer_tree_host_) |
612 layer_tree_host_->SetNextCommitForcesRedraw(); | 638 layer_tree_host_->SetNextCommitForcesRedraw(); |
613 } | 639 } |
614 | 640 |
| 641 void LayerTreeTest::DispatchComposite() { |
| 642 scheduled_ = false; |
| 643 |
| 644 if (!layer_tree_host_) |
| 645 return; |
| 646 |
| 647 // If the LTH is not visible, defer the composite until the LTH is made |
| 648 // visible. |
| 649 if (!layer_tree_host_->visible()) { |
| 650 schedule_when_set_visible_true_ = true; |
| 651 return; |
| 652 } |
| 653 |
| 654 schedule_when_set_visible_true_ = false; |
| 655 base::TimeTicks now = gfx::FrameTime::Now(); |
| 656 layer_tree_host_->Composite(now); |
| 657 } |
| 658 |
615 void LayerTreeTest::RunTest(bool threaded, | 659 void LayerTreeTest::RunTest(bool threaded, |
616 bool delegating_renderer, | 660 bool delegating_renderer, |
617 bool impl_side_painting) { | 661 bool impl_side_painting) { |
618 if (threaded) { | 662 if (threaded) { |
619 impl_thread_.reset(new base::Thread("Compositor")); | 663 impl_thread_.reset(new base::Thread("Compositor")); |
620 ASSERT_TRUE(impl_thread_->Start()); | 664 ASSERT_TRUE(impl_thread_->Start()); |
621 } | 665 } |
622 | 666 |
623 main_task_runner_ = base::MessageLoopProxy::current(); | 667 main_task_runner_ = base::MessageLoopProxy::current(); |
624 | 668 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 return -1; | 742 return -1; |
699 } | 743 } |
700 | 744 |
701 void LayerTreeTest::DestroyLayerTreeHost() { | 745 void LayerTreeTest::DestroyLayerTreeHost() { |
702 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 746 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
703 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 747 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
704 layer_tree_host_.reset(); | 748 layer_tree_host_.reset(); |
705 } | 749 } |
706 | 750 |
707 } // namespace cc | 751 } // namespace cc |
OLD | NEW |