| 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 "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "cc/animation/animation.h" | 13 #include "cc/animation/animation.h" |
| 14 #include "cc/animation/animation_host.h" | 14 #include "cc/animation/animation_host.h" |
| 15 #include "cc/animation/animation_player.h" | 15 #include "cc/animation/animation_player.h" |
| 16 #include "cc/animation/timing_function.h" | 16 #include "cc/animation/timing_function.h" |
| 17 #include "cc/base/switches.h" | 17 #include "cc/base/switches.h" |
| 18 #include "cc/blimp/remote_compositor_bridge.h" | |
| 19 #include "cc/input/input_handler.h" | 18 #include "cc/input/input_handler.h" |
| 20 #include "cc/layers/layer.h" | 19 #include "cc/layers/layer.h" |
| 21 #include "cc/layers/layer_impl.h" | 20 #include "cc/layers/layer_impl.h" |
| 22 #include "cc/output/buffer_to_texture_target_map.h" | 21 #include "cc/output/buffer_to_texture_target_map.h" |
| 23 #include "cc/test/animation_test_common.h" | 22 #include "cc/test/animation_test_common.h" |
| 24 #include "cc/test/begin_frame_args_test.h" | 23 #include "cc/test/begin_frame_args_test.h" |
| 25 #include "cc/test/fake_image_serialization_processor.h" | |
| 26 #include "cc/test/fake_layer_tree_host_client.h" | 24 #include "cc/test/fake_layer_tree_host_client.h" |
| 27 #include "cc/test/fake_output_surface.h" | 25 #include "cc/test/fake_output_surface.h" |
| 28 #include "cc/test/layer_tree_host_remote_for_testing.h" | |
| 29 #include "cc/test/test_compositor_frame_sink.h" | 26 #include "cc/test/test_compositor_frame_sink.h" |
| 30 #include "cc/test/test_context_provider.h" | 27 #include "cc/test/test_context_provider.h" |
| 31 #include "cc/test/test_shared_bitmap_manager.h" | 28 #include "cc/test/test_shared_bitmap_manager.h" |
| 32 #include "cc/trees/layer_tree_host_client.h" | 29 #include "cc/trees/layer_tree_host_client.h" |
| 33 #include "cc/trees/layer_tree_host_impl.h" | 30 #include "cc/trees/layer_tree_host_impl.h" |
| 34 #include "cc/trees/layer_tree_host_single_thread_client.h" | 31 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 35 #include "cc/trees/layer_tree_impl.h" | 32 #include "cc/trees/layer_tree_impl.h" |
| 36 #include "cc/trees/proxy_impl.h" | 33 #include "cc/trees/proxy_impl.h" |
| 37 #include "cc/trees/proxy_main.h" | 34 #include "cc/trees/proxy_main.h" |
| 38 #include "cc/trees/single_thread_proxy.h" | 35 #include "cc/trees/single_thread_proxy.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 case CompositorMode::SINGLE_THREADED: | 359 case CompositorMode::SINGLE_THREADED: |
| 363 proxy = SingleThreadProxy::Create(layer_tree_host.get(), | 360 proxy = SingleThreadProxy::Create(layer_tree_host.get(), |
| 364 single_thread_client, | 361 single_thread_client, |
| 365 task_runner_provider.get()); | 362 task_runner_provider.get()); |
| 366 break; | 363 break; |
| 367 case CompositorMode::THREADED: | 364 case CompositorMode::THREADED: |
| 368 DCHECK(impl_task_runner.get()); | 365 DCHECK(impl_task_runner.get()); |
| 369 proxy = base::MakeUnique<ProxyMain>(layer_tree_host.get(), | 366 proxy = base::MakeUnique<ProxyMain>(layer_tree_host.get(), |
| 370 task_runner_provider.get()); | 367 task_runner_provider.get()); |
| 371 break; | 368 break; |
| 372 case CompositorMode::REMOTE: | |
| 373 NOTREACHED(); | |
| 374 } | 369 } |
| 375 layer_tree_host->InitializeForTesting(std::move(task_runner_provider), | 370 layer_tree_host->InitializeForTesting(std::move(task_runner_provider), |
| 376 std::move(proxy)); | 371 std::move(proxy)); |
| 377 return layer_tree_host; | 372 return layer_tree_host; |
| 378 } | 373 } |
| 379 | 374 |
| 380 std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( | 375 std::unique_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( |
| 381 LayerTreeHostImplClient* host_impl_client) override { | 376 LayerTreeHostImplClient* host_impl_client) override { |
| 382 std::unique_ptr<LayerTreeHostImpl> host_impl = | 377 std::unique_ptr<LayerTreeHostImpl> host_impl = |
| 383 LayerTreeHostImplForTesting::Create( | 378 LayerTreeHostImplForTesting::Create( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 407 LayerTreeHostInProcess::InitParams* params, | 402 LayerTreeHostInProcess::InitParams* params, |
| 408 CompositorMode mode) | 403 CompositorMode mode) |
| 409 : LayerTreeHostInProcess(params, mode), | 404 : LayerTreeHostInProcess(params, mode), |
| 410 test_hooks_(test_hooks), | 405 test_hooks_(test_hooks), |
| 411 test_started_(false) {} | 406 test_started_(false) {} |
| 412 | 407 |
| 413 TestHooks* test_hooks_; | 408 TestHooks* test_hooks_; |
| 414 bool test_started_; | 409 bool test_started_; |
| 415 }; | 410 }; |
| 416 | 411 |
| 417 // Adapts the LayerTreeHostRemoteForTesting to inject the | |
| 418 // LayerTreeHostInProcess. | |
| 419 class LayerTreeHostRemoteForLayerTreeTest | |
| 420 : public LayerTreeHostRemoteForTesting { | |
| 421 public: | |
| 422 static std::unique_ptr<LayerTreeHostRemoteForLayerTreeTest> Create( | |
| 423 TestHooks* test_hooks, | |
| 424 LayerTreeHostClient* client, | |
| 425 LayerTreeSettings const* settings, | |
| 426 TaskGraphRunner* task_graph_runner, | |
| 427 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 428 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | |
| 429 MutatorHost* mutator_host) { | |
| 430 std::unique_ptr<FakeImageSerializationProcessor> | |
| 431 image_serialization_processor = | |
| 432 base::MakeUnique<FakeImageSerializationProcessor>(); | |
| 433 | |
| 434 LayerTreeHostRemote::InitParams params; | |
| 435 params.client = client; | |
| 436 params.main_task_runner = main_task_runner; | |
| 437 params.mutator_host = mutator_host; | |
| 438 params.remote_compositor_bridge = | |
| 439 CreateRemoteCompositorBridge(main_task_runner); | |
| 440 params.engine_picture_cache = | |
| 441 image_serialization_processor->CreateEnginePictureCache(); | |
| 442 params.settings = settings; | |
| 443 | |
| 444 std::unique_ptr<LayerTreeHostRemoteForLayerTreeTest> layer_tree_host = | |
| 445 base::WrapUnique( | |
| 446 new LayerTreeHostRemoteForLayerTreeTest(¶ms, test_hooks)); | |
| 447 layer_tree_host->Initialize(task_graph_runner, main_task_runner, | |
| 448 impl_task_runner, | |
| 449 std::move(image_serialization_processor)); | |
| 450 return layer_tree_host; | |
| 451 } | |
| 452 | |
| 453 ~LayerTreeHostRemoteForLayerTreeTest() override = default; | |
| 454 | |
| 455 std::unique_ptr<LayerTreeHostInProcess> CreateLayerTreeHostInProcess( | |
| 456 LayerTreeHostClient* client, | |
| 457 TaskGraphRunner* task_graph_runner, | |
| 458 const LayerTreeSettings& settings, | |
| 459 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 460 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | |
| 461 MutatorHost* mutator_host) override { | |
| 462 return LayerTreeHostForTesting::Create( | |
| 463 test_hooks_, CompositorMode::THREADED, client, nullptr, | |
| 464 task_graph_runner, settings, main_task_runner, impl_task_runner, | |
| 465 mutator_host); | |
| 466 } | |
| 467 | |
| 468 private: | |
| 469 LayerTreeHostRemoteForLayerTreeTest(InitParams* params, TestHooks* test_hooks) | |
| 470 : LayerTreeHostRemoteForTesting(params), test_hooks_(test_hooks) {} | |
| 471 | |
| 472 TestHooks* test_hooks_; | |
| 473 }; | |
| 474 | |
| 475 class LayerTreeTestCompositorFrameSinkClient | 412 class LayerTreeTestCompositorFrameSinkClient |
| 476 : public TestCompositorFrameSinkClient { | 413 : public TestCompositorFrameSinkClient { |
| 477 public: | 414 public: |
| 478 explicit LayerTreeTestCompositorFrameSinkClient(TestHooks* hooks) | 415 explicit LayerTreeTestCompositorFrameSinkClient(TestHooks* hooks) |
| 479 : hooks_(hooks) {} | 416 : hooks_(hooks) {} |
| 480 | 417 |
| 481 // TestCompositorFrameSinkClient implementation. | 418 // TestCompositorFrameSinkClient implementation. |
| 482 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( | 419 std::unique_ptr<OutputSurface> CreateDisplayOutputSurface( |
| 483 scoped_refptr<ContextProvider> compositor_context_provider) override { | 420 scoped_refptr<ContextProvider> compositor_context_provider) override { |
| 484 return hooks_->CreateDisplayOutputSurfaceOnThread( | 421 return hooks_->CreateDisplayOutputSurfaceOnThread( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 512 timeout_seconds_ = 5; | 449 timeout_seconds_ = 5; |
| 513 if (command_line->HasSwitch(switches::kCCLayerTreeTestLongTimeout)) | 450 if (command_line->HasSwitch(switches::kCCLayerTreeTestLongTimeout)) |
| 514 timeout_seconds_ = 5 * 60; | 451 timeout_seconds_ = 5 * 60; |
| 515 } | 452 } |
| 516 | 453 |
| 517 LayerTreeTest::~LayerTreeTest() { | 454 LayerTreeTest::~LayerTreeTest() { |
| 518 if (animation_host_) | 455 if (animation_host_) |
| 519 animation_host_->SetMutatorHostClient(nullptr); | 456 animation_host_->SetMutatorHostClient(nullptr); |
| 520 } | 457 } |
| 521 | 458 |
| 522 bool LayerTreeTest::IsRemoteTest() const { | |
| 523 return mode_ == CompositorMode::REMOTE; | |
| 524 } | |
| 525 | |
| 526 gfx::Vector2dF LayerTreeTest::ScrollDelta(LayerImpl* layer_impl) { | 459 gfx::Vector2dF LayerTreeTest::ScrollDelta(LayerImpl* layer_impl) { |
| 527 gfx::ScrollOffset delta = | 460 gfx::ScrollOffset delta = |
| 528 layer_impl->layer_tree_impl() | 461 layer_impl->layer_tree_impl() |
| 529 ->property_trees() | 462 ->property_trees() |
| 530 ->scroll_tree.GetScrollOffsetDeltaForTesting(layer_impl->id()); | 463 ->scroll_tree.GetScrollOffsetDeltaForTesting(layer_impl->id()); |
| 531 return gfx::Vector2dF(delta.x(), delta.y()); | 464 return gfx::Vector2dF(delta.x(), delta.y()); |
| 532 } | 465 } |
| 533 | 466 |
| 534 void LayerTreeTest::EndTest() { | 467 void LayerTreeTest::EndTest() { |
| 535 if (ended_) | 468 if (ended_) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 | 587 |
| 655 DCHECK(!impl_thread_ || impl_thread_->task_runner().get()); | 588 DCHECK(!impl_thread_ || impl_thread_->task_runner().get()); |
| 656 | 589 |
| 657 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner = | 590 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner = |
| 658 base::ThreadTaskRunnerHandle::Get(); | 591 base::ThreadTaskRunnerHandle::Get(); |
| 659 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner = | 592 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner = |
| 660 impl_thread_ ? impl_thread_->task_runner() : nullptr; | 593 impl_thread_ ? impl_thread_->task_runner() : nullptr; |
| 661 | 594 |
| 662 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); | 595 animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 663 | 596 |
| 664 if (IsRemoteTest()) { | 597 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host_for_testing = |
| 665 std::unique_ptr<LayerTreeHostRemoteForLayerTreeTest> | 598 LayerTreeHostForTesting::Create( |
| 666 layer_tree_host_remote = LayerTreeHostRemoteForLayerTreeTest::Create( | 599 this, mode_, client_.get(), client_.get(), task_graph_runner_.get(), |
| 667 this, client_.get(), &settings_, task_graph_runner_.get(), | 600 settings_, main_task_runner, impl_task_runner, animation_host_.get()); |
| 668 main_task_runner, impl_task_runner, animation_host_.get()); | 601 layer_tree_host_in_process_ = layer_tree_host_for_testing.get(); |
| 669 layer_tree_host_in_process_ = | 602 layer_tree_host_ = std::move(layer_tree_host_for_testing); |
| 670 layer_tree_host_remote->layer_tree_host_in_process(); | |
| 671 layer_tree_host_ = std::move(layer_tree_host_remote); | |
| 672 } else { | |
| 673 std::unique_ptr<LayerTreeHostForTesting> layer_tree_host_for_testing = | |
| 674 LayerTreeHostForTesting::Create( | |
| 675 this, mode_, client_.get(), client_.get(), task_graph_runner_.get(), | |
| 676 settings_, main_task_runner, impl_task_runner, | |
| 677 animation_host_.get()); | |
| 678 layer_tree_host_in_process_ = layer_tree_host_for_testing.get(); | |
| 679 layer_tree_host_ = std::move(layer_tree_host_for_testing); | |
| 680 } | |
| 681 | 603 |
| 682 ASSERT_TRUE(layer_tree_host_); | 604 ASSERT_TRUE(layer_tree_host_); |
| 683 | 605 |
| 684 main_task_runner_ = | 606 main_task_runner_ = |
| 685 layer_tree_host_->GetTaskRunnerProvider()->MainThreadTaskRunner(); | 607 layer_tree_host_->GetTaskRunnerProvider()->MainThreadTaskRunner(); |
| 686 impl_task_runner_ = | 608 impl_task_runner_ = |
| 687 layer_tree_host_->GetTaskRunnerProvider()->ImplThreadTaskRunner(); | 609 layer_tree_host_->GetTaskRunnerProvider()->ImplThreadTaskRunner(); |
| 688 if (!impl_task_runner_) { | 610 if (!impl_task_runner_) { |
| 689 // For tests, if there's no impl thread, make things easier by just giving | 611 // For tests, if there's no impl thread, make things easier by just giving |
| 690 // the main thread task runner. | 612 // the main thread task runner. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 } | 734 } |
| 813 | 735 |
| 814 void LayerTreeTest::DispatchNextCommitWaitsForActivation() { | 736 void LayerTreeTest::DispatchNextCommitWaitsForActivation() { |
| 815 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 737 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 816 if (layer_tree_host_) | 738 if (layer_tree_host_) |
| 817 layer_tree_host_->SetNextCommitWaitsForActivation(); | 739 layer_tree_host_->SetNextCommitWaitsForActivation(); |
| 818 } | 740 } |
| 819 | 741 |
| 820 void LayerTreeTest::RunTest(CompositorMode mode) { | 742 void LayerTreeTest::RunTest(CompositorMode mode) { |
| 821 mode_ = mode; | 743 mode_ = mode; |
| 822 if (mode_ == CompositorMode::THREADED || mode_ == CompositorMode::REMOTE) { | 744 if (mode_ == CompositorMode::THREADED) { |
| 823 impl_thread_.reset(new base::Thread("Compositor")); | 745 impl_thread_.reset(new base::Thread("Compositor")); |
| 824 ASSERT_TRUE(impl_thread_->Start()); | 746 ASSERT_TRUE(impl_thread_->Start()); |
| 825 } | 747 } |
| 826 | 748 |
| 827 shared_bitmap_manager_.reset(new TestSharedBitmapManager); | 749 shared_bitmap_manager_.reset(new TestSharedBitmapManager); |
| 828 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager); | 750 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager); |
| 829 task_graph_runner_.reset(new TestTaskGraphRunner); | 751 task_graph_runner_.reset(new TestTaskGraphRunner); |
| 830 | 752 |
| 831 // Spend less time waiting for BeginFrame because the output is | 753 // Spend less time waiting for BeginFrame because the output is |
| 832 // mocked out. | 754 // mocked out. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 | 835 |
| 914 LayerTreeHost* LayerTreeTest::layer_tree_host() { | 836 LayerTreeHost* LayerTreeTest::layer_tree_host() { |
| 915 DCHECK(task_runner_provider()->IsMainThread() || | 837 DCHECK(task_runner_provider()->IsMainThread() || |
| 916 task_runner_provider()->IsMainThreadBlocked()); | 838 task_runner_provider()->IsMainThreadBlocked()); |
| 917 return layer_tree_host_.get(); | 839 return layer_tree_host_.get(); |
| 918 } | 840 } |
| 919 | 841 |
| 920 LayerTreeHostInProcess* LayerTreeTest::layer_tree_host_in_process() { | 842 LayerTreeHostInProcess* LayerTreeTest::layer_tree_host_in_process() { |
| 921 DCHECK(task_runner_provider()->IsMainThread() || | 843 DCHECK(task_runner_provider()->IsMainThread() || |
| 922 task_runner_provider()->IsMainThreadBlocked()); | 844 task_runner_provider()->IsMainThreadBlocked()); |
| 923 DCHECK(!IsRemoteTest()); | |
| 924 return layer_tree_host_in_process_; | 845 return layer_tree_host_in_process_; |
| 925 } | 846 } |
| 926 | 847 |
| 927 Proxy* LayerTreeTest::proxy() { | 848 Proxy* LayerTreeTest::proxy() { |
| 928 return layer_tree_host_in_process() ? layer_tree_host_in_process()->proxy() | 849 return layer_tree_host_in_process() ? layer_tree_host_in_process()->proxy() |
| 929 : NULL; | 850 : NULL; |
| 930 } | 851 } |
| 931 | 852 |
| 932 } // namespace cc | 853 } // namespace cc |
| OLD | NEW |