| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 virtual void DidCommit() OVERRIDE { test_hooks_->DidCommit(); } | 314 virtual void DidCommit() OVERRIDE { test_hooks_->DidCommit(); } |
| 315 | 315 |
| 316 virtual void DidCommitAndDrawFrame() OVERRIDE { | 316 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 317 test_hooks_->DidCommitAndDrawFrame(); | 317 test_hooks_->DidCommitAndDrawFrame(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 virtual void DidCompleteSwapBuffers() OVERRIDE { | 320 virtual void DidCompleteSwapBuffers() OVERRIDE { |
| 321 test_hooks_->DidCompleteSwapBuffers(); | 321 test_hooks_->DidCompleteSwapBuffers(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 virtual void ScheduleComposite() OVERRIDE { | |
| 325 test_hooks_->ScheduleComposite(); | |
| 326 } | |
| 327 | |
| 328 virtual void ScheduleAnimation() OVERRIDE { | |
| 329 test_hooks_->ScheduleAnimation(); | |
| 330 } | |
| 331 | |
| 332 virtual void DidPostSwapBuffers() OVERRIDE {} | 324 virtual void DidPostSwapBuffers() OVERRIDE {} |
| 333 virtual void DidAbortSwapBuffers() OVERRIDE {} | 325 virtual void DidAbortSwapBuffers() OVERRIDE {} |
| 334 | 326 |
| 335 private: | 327 private: |
| 336 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks) | 328 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks) |
| 337 : test_hooks_(test_hooks) {} | 329 : test_hooks_(test_hooks) {} |
| 338 | 330 |
| 339 TestHooks* test_hooks_; | 331 TestHooks* test_hooks_; |
| 340 }; | 332 }; |
| 341 | 333 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 386 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |
| 395 TestHooks* test_hooks_; | 387 TestHooks* test_hooks_; |
| 396 bool test_started_; | 388 bool test_started_; |
| 397 }; | 389 }; |
| 398 | 390 |
| 399 LayerTreeTest::LayerTreeTest() | 391 LayerTreeTest::LayerTreeTest() |
| 400 : beginning_(false), | 392 : beginning_(false), |
| 401 end_when_begin_returns_(false), | 393 end_when_begin_returns_(false), |
| 402 timed_out_(false), | 394 timed_out_(false), |
| 403 scheduled_(false), | 395 scheduled_(false), |
| 404 schedule_when_set_visible_true_(false), | |
| 405 started_(false), | 396 started_(false), |
| 406 ended_(false), | 397 ended_(false), |
| 407 delegating_renderer_(false), | 398 delegating_renderer_(false), |
| 408 timeout_seconds_(0), | 399 timeout_seconds_(0), |
| 409 weak_factory_(this) { | 400 weak_factory_(this) { |
| 410 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); | 401 main_thread_weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 411 | 402 |
| 412 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was | 403 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was |
| 413 // specified (for running in a debugger). | 404 // specified (for running in a debugger). |
| 414 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 405 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 gfx::Size device_root_bounds = gfx::ToCeiledSize( | 548 gfx::Size device_root_bounds = gfx::ToCeiledSize( |
| 558 gfx::ScaleSize(root_bounds, layer_tree_host_->device_scale_factor())); | 549 gfx::ScaleSize(root_bounds, layer_tree_host_->device_scale_factor())); |
| 559 layer_tree_host_->SetViewportSize(device_root_bounds); | 550 layer_tree_host_->SetViewportSize(device_root_bounds); |
| 560 } | 551 } |
| 561 | 552 |
| 562 void LayerTreeTest::Timeout() { | 553 void LayerTreeTest::Timeout() { |
| 563 timed_out_ = true; | 554 timed_out_ = true; |
| 564 EndTest(); | 555 EndTest(); |
| 565 } | 556 } |
| 566 | 557 |
| 567 void LayerTreeTest::ScheduleComposite() { | |
| 568 if (!started_ || scheduled_) | |
| 569 return; | |
| 570 scheduled_ = true; | |
| 571 main_task_runner_->PostTask( | |
| 572 FROM_HERE, | |
| 573 base::Bind(&LayerTreeTest::DispatchComposite, main_thread_weak_ptr_)); | |
| 574 } | |
| 575 | |
| 576 void LayerTreeTest::RealEndTest() { | 558 void LayerTreeTest::RealEndTest() { |
| 577 if (layer_tree_host_ && proxy()->CommitPendingForTesting()) { | 559 if (layer_tree_host_ && proxy()->CommitPendingForTesting()) { |
| 578 main_task_runner_->PostTask( | 560 main_task_runner_->PostTask( |
| 579 FROM_HERE, | 561 FROM_HERE, |
| 580 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); | 562 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); |
| 581 return; | 563 return; |
| 582 } | 564 } |
| 583 | 565 |
| 584 base::MessageLoop::current()->Quit(); | 566 base::MessageLoop::current()->Quit(); |
| 585 } | 567 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 599 |
| 618 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 600 void LayerTreeTest::DispatchSetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
| 619 DCHECK(!proxy() || proxy()->IsMainThread()); | 601 DCHECK(!proxy() || proxy()->IsMainThread()); |
| 620 | 602 |
| 621 if (layer_tree_host_) | 603 if (layer_tree_host_) |
| 622 layer_tree_host_->SetNeedsRedrawRect(damage_rect); | 604 layer_tree_host_->SetNeedsRedrawRect(damage_rect); |
| 623 } | 605 } |
| 624 | 606 |
| 625 void LayerTreeTest::DispatchSetVisible(bool visible) { | 607 void LayerTreeTest::DispatchSetVisible(bool visible) { |
| 626 DCHECK(!proxy() || proxy()->IsMainThread()); | 608 DCHECK(!proxy() || proxy()->IsMainThread()); |
| 627 | 609 if (layer_tree_host_) |
| 628 if (!layer_tree_host_) | 610 layer_tree_host_->SetVisible(visible); |
| 629 return; | |
| 630 | |
| 631 layer_tree_host_->SetVisible(visible); | |
| 632 | |
| 633 // If the LTH is being made visible and a previous ScheduleComposite() was | |
| 634 // deferred because the LTH was not visible, re-schedule the composite now. | |
| 635 if (layer_tree_host_->visible() && schedule_when_set_visible_true_) | |
| 636 ScheduleComposite(); | |
| 637 } | 611 } |
| 638 | 612 |
| 639 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() { | 613 void LayerTreeTest::DispatchSetNextCommitForcesRedraw() { |
| 640 DCHECK(!proxy() || proxy()->IsMainThread()); | 614 DCHECK(!proxy() || proxy()->IsMainThread()); |
| 641 | 615 |
| 642 if (layer_tree_host_) | 616 if (layer_tree_host_) |
| 643 layer_tree_host_->SetNextCommitForcesRedraw(); | 617 layer_tree_host_->SetNextCommitForcesRedraw(); |
| 644 } | 618 } |
| 645 | 619 |
| 646 void LayerTreeTest::DispatchComposite() { | |
| 647 scheduled_ = false; | |
| 648 | |
| 649 if (!layer_tree_host_) | |
| 650 return; | |
| 651 | |
| 652 // If the LTH is not visible, defer the composite until the LTH is made | |
| 653 // visible. | |
| 654 if (!layer_tree_host_->visible()) { | |
| 655 schedule_when_set_visible_true_ = true; | |
| 656 return; | |
| 657 } | |
| 658 | |
| 659 schedule_when_set_visible_true_ = false; | |
| 660 base::TimeTicks now = gfx::FrameTime::Now(); | |
| 661 layer_tree_host_->Composite(now); | |
| 662 } | |
| 663 | |
| 664 void LayerTreeTest::RunTest(bool threaded, | 620 void LayerTreeTest::RunTest(bool threaded, |
| 665 bool delegating_renderer, | 621 bool delegating_renderer, |
| 666 bool impl_side_painting) { | 622 bool impl_side_painting) { |
| 667 if (threaded) { | 623 if (threaded) { |
| 668 impl_thread_.reset(new base::Thread("Compositor")); | 624 impl_thread_.reset(new base::Thread("Compositor")); |
| 669 ASSERT_TRUE(impl_thread_->Start()); | 625 ASSERT_TRUE(impl_thread_->Start()); |
| 670 } | 626 } |
| 671 | 627 |
| 672 main_task_runner_ = base::MessageLoopProxy::current(); | 628 main_task_runner_ = base::MessageLoopProxy::current(); |
| 673 | 629 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 return -1; | 703 return -1; |
| 748 } | 704 } |
| 749 | 705 |
| 750 void LayerTreeTest::DestroyLayerTreeHost() { | 706 void LayerTreeTest::DestroyLayerTreeHost() { |
| 751 if (layer_tree_host_ && layer_tree_host_->root_layer()) | 707 if (layer_tree_host_ && layer_tree_host_->root_layer()) |
| 752 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); | 708 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); |
| 753 layer_tree_host_.reset(); | 709 layer_tree_host_.reset(); |
| 754 } | 710 } |
| 755 | 711 |
| 756 } // namespace cc | 712 } // namespace cc |
| OLD | NEW |