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