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