Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: cc/test/layer_tree_test.cc

Issue 1513643010: cc:: Add remote mode to the compositor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use LayerTreeSettings::ToProtobuf, update comments. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "cc/animation/animation.h" 11 #include "cc/animation/animation.h"
12 #include "cc/animation/animation_host.h" 12 #include "cc/animation/animation_host.h"
13 #include "cc/animation/animation_registrar.h" 13 #include "cc/animation/animation_registrar.h"
14 #include "cc/animation/layer_animation_controller.h" 14 #include "cc/animation/layer_animation_controller.h"
15 #include "cc/animation/timing_function.h" 15 #include "cc/animation/timing_function.h"
16 #include "cc/base/switches.h" 16 #include "cc/base/switches.h"
17 #include "cc/input/input_handler.h" 17 #include "cc/input/input_handler.h"
18 #include "cc/layers/layer.h" 18 #include "cc/layers/layer.h"
19 #include "cc/layers/layer_impl.h" 19 #include "cc/layers/layer_impl.h"
20 #include "cc/test/animation_test_common.h" 20 #include "cc/test/animation_test_common.h"
21 #include "cc/test/begin_frame_args_test.h" 21 #include "cc/test/begin_frame_args_test.h"
22 #include "cc/test/fake_external_begin_frame_source.h" 22 #include "cc/test/fake_external_begin_frame_source.h"
23 #include "cc/test/fake_layer_tree_host_client.h" 23 #include "cc/test/fake_layer_tree_host_client.h"
24 #include "cc/test/fake_output_surface.h" 24 #include "cc/test/fake_output_surface.h"
25 #include "cc/test/remote_channel_impl_for_test.h"
25 #include "cc/test/test_context_provider.h" 26 #include "cc/test/test_context_provider.h"
26 #include "cc/test/test_gpu_memory_buffer_manager.h" 27 #include "cc/test/test_gpu_memory_buffer_manager.h"
27 #include "cc/test/test_shared_bitmap_manager.h" 28 #include "cc/test/test_shared_bitmap_manager.h"
28 #include "cc/test/test_task_graph_runner.h" 29 #include "cc/test/test_task_graph_runner.h"
30 #include "cc/test/threaded_channel_for_test.h"
29 #include "cc/trees/layer_tree_host_client.h" 31 #include "cc/trees/layer_tree_host_client.h"
30 #include "cc/trees/layer_tree_host_impl.h" 32 #include "cc/trees/layer_tree_host_impl.h"
31 #include "cc/trees/layer_tree_host_single_thread_client.h" 33 #include "cc/trees/layer_tree_host_single_thread_client.h"
32 #include "cc/trees/layer_tree_impl.h" 34 #include "cc/trees/layer_tree_impl.h"
33 #include "cc/trees/proxy_impl.h" 35 #include "cc/trees/proxy_impl.h"
34 #include "cc/trees/proxy_main.h" 36 #include "cc/trees/proxy_main.h"
37 #include "cc/trees/remote_channel_host.h"
38 #include "cc/trees/remote_channel_host_client.h"
35 #include "cc/trees/single_thread_proxy.h" 39 #include "cc/trees/single_thread_proxy.h"
36 #include "cc/trees/threaded_channel.h" 40 #include "cc/trees/threaded_channel.h"
37 #include "testing/gmock/include/gmock/gmock.h" 41 #include "testing/gmock/include/gmock/gmock.h"
38 #include "ui/gfx/geometry/size_conversions.h" 42 #include "ui/gfx/geometry/size_conversions.h"
39 43
40 namespace cc { 44 namespace cc {
41 45
42 void CreateVirtualViewportLayers(Layer* root_layer, 46 void CreateVirtualViewportLayers(Layer* root_layer,
43 scoped_refptr<Layer> outer_scroll_layer, 47 scoped_refptr<Layer> outer_scroll_layer,
44 const gfx::Size& inner_bounds, 48 const gfx::Size& inner_bounds,
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 LayerTreeHostImpl::NotifyTileStateChanged(tile); 347 LayerTreeHostImpl::NotifyTileStateChanged(tile);
344 test_hooks_->NotifyTileStateChangedOnThread(this, tile); 348 test_hooks_->NotifyTileStateChangedOnThread(this, tile);
345 } 349 }
346 350
347 private: 351 private:
348 TestHooks* test_hooks_; 352 TestHooks* test_hooks_;
349 bool block_notify_ready_to_activate_for_testing_; 353 bool block_notify_ready_to_activate_for_testing_;
350 bool notify_ready_to_activate_was_blocked_; 354 bool notify_ready_to_activate_was_blocked_;
351 }; 355 };
352 356
357 // Implementation of RemoteChannelHostClient for tests.
358 class RemoteChannelHostClientForTesting : public RemoteChannelHostClient {
359 public:
360 static scoped_ptr<RemoteChannelHostClientForTesting> Create(
361 TestHooks* test_hooks) {
362 return make_scoped_ptr(new RemoteChannelHostClientForTesting(test_hooks));
363 }
364
365 void OverrideLayerTreeSettings(LayerTreeSettings* settings) override {
366 test_hooks_->OverrideLayerTreeSettings(settings);
367 }
368
369 void DidShutdown() override { test_hooks_->DidShutdown(); }
370
371 private:
372 explicit RemoteChannelHostClientForTesting(TestHooks* test_hooks)
373 : test_hooks_(test_hooks) {}
374
375 TestHooks* test_hooks_;
376 };
377
353 // Implementation of LayerTreeHost callback interface. 378 // Implementation of LayerTreeHost callback interface.
354 class LayerTreeHostClientForTesting : public LayerTreeHostClient, 379 class LayerTreeHostClientForTesting : public LayerTreeHostClient,
355 public LayerTreeHostSingleThreadClient { 380 public LayerTreeHostSingleThreadClient {
356 public: 381 public:
357 static scoped_ptr<LayerTreeHostClientForTesting> Create( 382 static scoped_ptr<LayerTreeHostClientForTesting> Create(
358 TestHooks* test_hooks) { 383 TestHooks* test_hooks) {
359 return make_scoped_ptr(new LayerTreeHostClientForTesting(test_hooks)); 384 return make_scoped_ptr(new LayerTreeHostClientForTesting(test_hooks));
360 } 385 }
361 ~LayerTreeHostClientForTesting() override {} 386 ~LayerTreeHostClientForTesting() override {}
362 387
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) 447 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
423 override {} 448 override {}
424 449
425 private: 450 private:
426 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks) 451 explicit LayerTreeHostClientForTesting(TestHooks* test_hooks)
427 : test_hooks_(test_hooks) {} 452 : test_hooks_(test_hooks) {}
428 453
429 TestHooks* test_hooks_; 454 TestHooks* test_hooks_;
430 }; 455 };
431 456
457 // Injects RemoteChannelImplForTesting.
458 class RemoteChannelHostForTesting : public RemoteChannelHost {
459 public:
460 static scoped_ptr<RemoteChannelHostForTesting> Create(
461 TestHooks* test_hooks,
462 RemoteProtoChannel* remote_proto_channel,
463 RemoteChannelHostClient* client,
464 TaskGraphRunner* task_graph_runner,
465 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
466 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
467 return make_scoped_ptr(new RemoteChannelHostForTesting(
468 test_hooks, remote_proto_channel, client, task_graph_runner,
469 main_task_runner, impl_task_runner));
470 }
471
472 RemoteChannelImplForTest* remote_channel_impl_for_test() const {
473 return remote_channel_impl_for_test_;
474 }
475
476 private:
477 RemoteChannelHostForTesting(
478 TestHooks* test_hooks,
479 RemoteProtoChannel* remote_proto_channel,
480 RemoteChannelHostClient* client,
481 TaskGraphRunner* task_graph_runner,
482 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
483 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
484 : RemoteChannelHost(remote_proto_channel,
485 client,
486 task_graph_runner,
487 main_task_runner,
488 impl_task_runner),
489 test_hooks_(test_hooks) {}
490
491 scoped_ptr<RemoteChannelImpl> CreateRemoteChannelImpl(
492 RemoteChannelHost* remote_channel_host,
493 TaskGraphRunner* task_graph_runner,
494 const LayerTreeSettings& settings,
495 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
496 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) override {
497 scoped_ptr<RemoteChannelImplForTest> channel_impl =
498 RemoteChannelImplForTest::Create(test_hooks_, remote_channel_host,
499 task_graph_runner, settings,
500 main_task_runner, impl_task_runner);
501 remote_channel_impl_for_test_ = channel_impl.get();
502 return std::move(channel_impl);
503 }
504
505 TestHooks* test_hooks_;
506 RemoteChannelImplForTest* remote_channel_impl_for_test_;
507 };
508
432 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting. 509 // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
433 class LayerTreeHostForTesting : public LayerTreeHost { 510 class LayerTreeHostForTesting : public LayerTreeHost {
434 public: 511 public:
435 static scoped_ptr<LayerTreeHostForTesting> Create( 512 static scoped_ptr<LayerTreeHostForTesting> Create(
436 TestHooks* test_hooks, 513 TestHooks* test_hooks,
437 CompositorMode mode, 514 CompositorMode mode,
438 LayerTreeHostClientForTesting* client, 515 LayerTreeHostClientForTesting* client,
516 RemoteProtoChannel* remote_proto_channel,
439 SharedBitmapManager* shared_bitmap_manager, 517 SharedBitmapManager* shared_bitmap_manager,
440 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 518 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
441 TaskGraphRunner* task_graph_runner, 519 TaskGraphRunner* task_graph_runner,
442 const LayerTreeSettings& settings, 520 const LayerTreeSettings& settings,
443 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 521 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
444 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 522 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
445 scoped_ptr<BeginFrameSource> external_begin_frame_source) { 523 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
446 LayerTreeHost::InitParams params; 524 LayerTreeHost::InitParams params;
447 params.client = client; 525 params.client = client;
448 params.shared_bitmap_manager = shared_bitmap_manager; 526 params.shared_bitmap_manager = shared_bitmap_manager;
449 params.gpu_memory_buffer_manager = gpu_memory_buffer_manager; 527 params.gpu_memory_buffer_manager = gpu_memory_buffer_manager;
450 params.task_graph_runner = task_graph_runner; 528 params.task_graph_runner = task_graph_runner;
451 params.settings = &settings; 529 params.settings = &settings;
452 scoped_ptr<LayerTreeHostForTesting> layer_tree_host( 530 scoped_ptr<LayerTreeHostForTesting> layer_tree_host(
453 new LayerTreeHostForTesting(test_hooks, &params, mode)); 531 new LayerTreeHostForTesting(test_hooks, &params, mode));
454 scoped_ptr<TaskRunnerProvider> task_runner_provider = 532 scoped_ptr<TaskRunnerProvider> task_runner_provider =
455 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); 533 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
456 scoped_ptr<Proxy> proxy; 534 scoped_ptr<Proxy> proxy;
457 if (mode == CompositorMode::Threaded) { 535 switch (mode) {
458 DCHECK(impl_task_runner.get()); 536 case CompositorMode::SingleThreaded:
459 scoped_ptr<ProxyMain> proxy_main = ProxyMainForTest::CreateThreaded( 537 proxy = SingleThreadProxyForTest::Create(
460 test_hooks, layer_tree_host.get(), task_runner_provider.get(), 538 test_hooks, layer_tree_host.get(), client,
461 std::move(external_begin_frame_source)); 539 task_runner_provider.get(), std::move(external_begin_frame_source));
462 proxy = std::move(proxy_main); 540 break;
463 } else { 541 case CompositorMode::Threaded:
464 proxy = SingleThreadProxyForTest::Create( 542 DCHECK(impl_task_runner.get());
465 test_hooks, layer_tree_host.get(), client, task_runner_provider.get(), 543 {
466 std::move(external_begin_frame_source)); 544 scoped_ptr<ProxyMain> proxy_main = ProxyMainForTest::CreateThreaded(
545 test_hooks, layer_tree_host.get(), task_runner_provider.get(),
546 std::move(external_begin_frame_source));
547 proxy = std::move(proxy_main);
548 }
549 break;
550 case CompositorMode::Remote:
551 DCHECK(!impl_task_runner.get());
552 DCHECK(!external_begin_frame_source);
553 {
554 scoped_ptr<ProxyMain> proxy_main = ProxyMainForTest::CreateRemote(
555 test_hooks, remote_proto_channel, layer_tree_host.get(),
556 task_runner_provider.get());
557 proxy = std::move(proxy_main);
558 }
559 break;
560 default:
561 NOTREACHED();
467 } 562 }
468 layer_tree_host->InitializeForTesting(std::move(task_runner_provider), 563 layer_tree_host->InitializeForTesting(std::move(task_runner_provider),
469 std::move(proxy)); 564 std::move(proxy));
470 return layer_tree_host; 565 return layer_tree_host;
471 } 566 }
472 567
473 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl( 568 scoped_ptr<LayerTreeHostImpl> CreateLayerTreeHostImpl(
474 LayerTreeHostImplClient* host_impl_client) override { 569 LayerTreeHostImplClient* host_impl_client) override {
475 return LayerTreeHostImplForTesting::Create( 570 return LayerTreeHostImplForTesting::Create(
476 test_hooks_, settings(), host_impl_client, task_runner_provider(), 571 test_hooks_, settings(), host_impl_client, task_runner_provider(),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 616
522 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was 617 // Tests should timeout quickly unless --cc-layer-tree-test-no-timeout was
523 // specified (for running in a debugger). 618 // specified (for running in a debugger).
524 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 619 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
525 if (!command_line->HasSwitch(switches::kCCLayerTreeTestNoTimeout)) 620 if (!command_line->HasSwitch(switches::kCCLayerTreeTestNoTimeout))
526 timeout_seconds_ = 5; 621 timeout_seconds_ = 5;
527 } 622 }
528 623
529 LayerTreeTest::~LayerTreeTest() {} 624 LayerTreeTest::~LayerTreeTest() {}
530 625
626 bool LayerTreeTest::IsRemoteTest() const {
627 return mode_ == CompositorMode::Remote;
628 }
629
531 void LayerTreeTest::EndTest() { 630 void LayerTreeTest::EndTest() {
532 if (ended_) 631 if (ended_)
533 return; 632 return;
534 ended_ = true; 633 ended_ = true;
535 634
536 // For the case where we EndTest during BeginTest(), set a flag to indicate 635 // For the case where we EndTest during BeginTest(), set a flag to indicate
537 // that the test should end the second BeginTest regains control. 636 // that the test should end the second BeginTest regains control.
538 if (beginning_) { 637 if (beginning_) {
539 end_when_begin_returns_ = true; 638 end_when_begin_returns_ = true;
540 } else { 639 } else {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 client_ = LayerTreeHostClientForTesting::Create(this); 769 client_ = LayerTreeHostClientForTesting::Create(this);
671 770
672 scoped_ptr<FakeExternalBeginFrameSource> external_begin_frame_source; 771 scoped_ptr<FakeExternalBeginFrameSource> external_begin_frame_source;
673 if (settings_.use_external_begin_frame_source) { 772 if (settings_.use_external_begin_frame_source) {
674 external_begin_frame_source.reset(new FakeExternalBeginFrameSource( 773 external_begin_frame_source.reset(new FakeExternalBeginFrameSource(
675 settings_.renderer_settings.refresh_rate)); 774 settings_.renderer_settings.refresh_rate));
676 external_begin_frame_source_ = external_begin_frame_source.get(); 775 external_begin_frame_source_ = external_begin_frame_source.get();
677 } 776 }
678 777
679 DCHECK(!impl_thread_ || impl_thread_->task_runner().get()); 778 DCHECK(!impl_thread_ || impl_thread_->task_runner().get());
680 layer_tree_host_ = LayerTreeHostForTesting::Create( 779
681 this, mode_, client_.get(), shared_bitmap_manager_.get(), 780 if (IsRemoteTest()) {
682 gpu_memory_buffer_manager_.get(), task_graph_runner_.get(), settings_, 781 // It is important to create the RemoteChannelHost before the LayerTreeHost
683 base::ThreadTaskRunnerHandle::Get(), 782 // since the main compositor immediately sends an initialization message to
684 impl_thread_ ? impl_thread_->task_runner() : NULL, 783 // the impl compositor.
685 std::move(external_begin_frame_source)); 784 DCHECK(impl_thread_);
785 remote_channel_host_client_ =
786 RemoteChannelHostClientForTesting::Create(this);
787 remote_channel_host_for_testing_ = RemoteChannelHostForTesting::Create(
788 this, &remote_proto_channel_bridge_.channel_impl,
789 remote_channel_host_client_.get(), task_graph_runner_.get(),
790 base::ThreadTaskRunnerHandle::Get(), impl_thread_->task_runner());
791 DCHECK(remote_proto_channel_bridge_.channel_impl.HasReceiver());
792
793 layer_tree_host_ = LayerTreeHostForTesting::Create(
794 this, mode_, client_.get(), &remote_proto_channel_bridge_.channel_main,
795 nullptr, nullptr, task_graph_runner_.get(), settings_,
796 base::ThreadTaskRunnerHandle::Get(), nullptr,
797 std::move(external_begin_frame_source));
798 DCHECK(remote_proto_channel_bridge_.channel_main.HasReceiver());
799 } else {
800 layer_tree_host_ = LayerTreeHostForTesting::Create(
801 this, mode_, client_.get(), nullptr, shared_bitmap_manager_.get(),
802 gpu_memory_buffer_manager_.get(), task_graph_runner_.get(), settings_,
803 base::ThreadTaskRunnerHandle::Get(),
804 impl_thread_ ? impl_thread_->task_runner() : NULL,
805 std::move(external_begin_frame_source));
806 }
807
686 ASSERT_TRUE(layer_tree_host_); 808 ASSERT_TRUE(layer_tree_host_);
687 809
688 started_ = true; 810 started_ = true;
689 beginning_ = true; 811 beginning_ = true;
690 SetupTree(); 812 SetupTree();
691 WillBeginTest(); 813 WillBeginTest();
692 BeginTest(); 814 BeginTest();
693 beginning_ = false; 815 beginning_ = false;
694 if (end_when_begin_returns_) 816 if (end_when_begin_returns_)
695 RealEndTest(); 817 RealEndTest();
(...skipping 20 matching lines...) Expand all
716 layer_tree_host_->root_layer()->SetIsDrawable(true); 838 layer_tree_host_->root_layer()->SetIsDrawable(true);
717 } 839 }
718 840
719 void LayerTreeTest::Timeout() { 841 void LayerTreeTest::Timeout() {
720 timed_out_ = true; 842 timed_out_ = true;
721 EndTest(); 843 EndTest();
722 } 844 }
723 845
724 void LayerTreeTest::RealEndTest() { 846 void LayerTreeTest::RealEndTest() {
725 // TODO(mithro): Make this method only end when not inside an impl frame. 847 // TODO(mithro): Make this method only end when not inside an impl frame.
726 if (layer_tree_host_ && !timed_out_ && 848 bool main_frame_will_happen;
727 proxy()->MainFrameWillHappenForTesting()) { 849 if (IsRemoteTest()) {
850 main_frame_will_happen =
851 remote_channel_host_for_testing_
852 ? GetRemoteChannelImplForTest()->MainFrameWillHappenForTesting()
853 : false;
854 } else {
855 main_frame_will_happen =
856 layer_tree_host_ ? proxy()->MainFrameWillHappenForTesting() : false;
857 }
858
859 if (main_frame_will_happen && !timed_out_) {
728 main_task_runner_->PostTask( 860 main_task_runner_->PostTask(
729 FROM_HERE, 861 FROM_HERE,
730 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_)); 862 base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
731 return; 863 return;
732 } 864 }
733 865
734 base::MessageLoop::current()->QuitWhenIdle(); 866 base::MessageLoop::current()->QuitWhenIdle();
735 } 867 }
736 868
737 void LayerTreeTest::DispatchAddAnimation(Layer* layer_to_receive_animation, 869 void LayerTreeTest::DispatchAddAnimation(Layer* layer_to_receive_animation,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 layer_tree_host_->SetNextCommitForcesRedraw(); 935 layer_tree_host_->SetNextCommitForcesRedraw();
804 } 936 }
805 937
806 void LayerTreeTest::DispatchCompositeImmediately() { 938 void LayerTreeTest::DispatchCompositeImmediately() {
807 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread()); 939 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread());
808 if (layer_tree_host_) 940 if (layer_tree_host_)
809 layer_tree_host_->Composite(base::TimeTicks::Now()); 941 layer_tree_host_->Composite(base::TimeTicks::Now());
810 } 942 }
811 943
812 void LayerTreeTest::RunTest(CompositorMode mode, bool delegating_renderer) { 944 void LayerTreeTest::RunTest(CompositorMode mode, bool delegating_renderer) {
945 DCHECK(mode != CompositorMode::Deserializable);
813 mode_ = mode; 946 mode_ = mode;
814 if (mode_ == CompositorMode::Threaded) { 947 if (mode_ != CompositorMode::SingleThreaded) {
815 impl_thread_.reset(new base::Thread("Compositor")); 948 impl_thread_.reset(new base::Thread("Compositor"));
816 ASSERT_TRUE(impl_thread_->Start()); 949 ASSERT_TRUE(impl_thread_->Start());
817 } 950 }
818 951
819 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 952 main_task_runner_ = base::ThreadTaskRunnerHandle::Get();
820 953
821 shared_bitmap_manager_.reset(new TestSharedBitmapManager); 954 shared_bitmap_manager_.reset(new TestSharedBitmapManager);
822 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager); 955 gpu_memory_buffer_manager_.reset(new TestGpuMemoryBufferManager);
823 task_graph_runner_.reset(new TestTaskGraphRunner); 956 task_graph_runner_.reset(new TestTaskGraphRunner);
824 957
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 return FakeOutputSurface::CreateDelegating3d(); 1013 return FakeOutputSurface::CreateDelegating3d();
881 else 1014 else
882 return FakeOutputSurface::Create3d(); 1015 return FakeOutputSurface::Create3d();
883 } 1016 }
884 1017
885 TestWebGraphicsContext3D* LayerTreeTest::TestContext() { 1018 TestWebGraphicsContext3D* LayerTreeTest::TestContext() {
886 return static_cast<TestContextProvider*>(output_surface_->context_provider()) 1019 return static_cast<TestContextProvider*>(output_surface_->context_provider())
887 ->TestContext3d(); 1020 ->TestContext3d();
888 } 1021 }
889 1022
1023 void LayerTreeTest::DidShutdown() {
1024 ReceivedDidShutdown();
1025 DestroyRemoteChannelHost();
1026 }
1027
890 int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl) 1028 int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl)
891 const { 1029 const {
892 if (impl->pending_tree()) 1030 if (impl->pending_tree())
893 return impl->pending_tree()->source_frame_number(); 1031 return impl->pending_tree()->source_frame_number();
894 if (impl->active_tree()) 1032 if (impl->active_tree())
895 return impl->active_tree()->source_frame_number(); 1033 return impl->active_tree()->source_frame_number();
896 // Source frames start at 0, so this is invalid. 1034 // Source frames start at 0, so this is invalid.
897 return -1; 1035 return -1;
898 } 1036 }
899 1037
900 void LayerTreeTest::DestroyLayerTreeHost() { 1038 void LayerTreeTest::DestroyLayerTreeHost() {
901 if (layer_tree_host_ && layer_tree_host_->root_layer()) 1039 if (layer_tree_host_ && layer_tree_host_->root_layer())
902 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL); 1040 layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
903 layer_tree_host_ = nullptr; 1041 layer_tree_host_ = nullptr;
1042
1043 DCHECK(!remote_proto_channel_bridge_.channel_main.HasReceiver());
1044
1045 // Destroying the LayerTreeHost should destroy the RemoteChannelHost.
1046 DCHECK(!remote_channel_host_for_testing_);
1047 }
1048
1049 void LayerTreeTest::DestroyRemoteChannelHost() {
1050 DCHECK(IsRemoteTest());
1051 DCHECK(remote_channel_host_for_testing_);
1052
1053 remote_channel_host_for_testing_ = nullptr;
1054 DCHECK(!remote_proto_channel_bridge_.channel_impl.HasReceiver());
904 } 1055 }
905 1056
906 TaskGraphRunner* LayerTreeTest::task_graph_runner() const { 1057 TaskGraphRunner* LayerTreeTest::task_graph_runner() const {
907 return task_graph_runner_.get(); 1058 return task_graph_runner_.get();
908 } 1059 }
909 1060
910 LayerTreeHost* LayerTreeTest::layer_tree_host() { 1061 LayerTreeHost* LayerTreeTest::layer_tree_host() {
911 // We check for a null task_runner_provider here as we sometimes ask for the 1062 // We check for a null task_runner_provider here as we sometimes ask for the
912 // layer tree host when the task_runner_provider does not exist, often for 1063 // layer tree host when the task_runner_provider does not exist, often for
913 // checking settings after a test has completed. For example, 1064 // checking settings after a test has completed. For example,
914 // LTHPixelResourceTest::RunPixelResourceTest. See elsewhere in this file for 1065 // LTHPixelResourceTest::RunPixelResourceTest. See elsewhere in this file for
915 // other examples. 1066 // other examples.
916 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread() || 1067 DCHECK(!task_runner_provider() || task_runner_provider()->IsMainThread() ||
917 task_runner_provider()->IsMainThreadBlocked()); 1068 task_runner_provider()->IsMainThreadBlocked());
918 return layer_tree_host_.get(); 1069 return layer_tree_host_.get();
919 } 1070 }
920 1071
921 ProxyMainForTest* LayerTreeTest::GetProxyMainForTest() const { 1072 ProxyMainForTest* LayerTreeTest::GetProxyMainForTest() const {
922 DCHECK(HasImplThread()); 1073 DCHECK(HasImplThread());
923 return static_cast<ProxyMainForTest*>(proxy()); 1074 return static_cast<ProxyMainForTest*>(proxy());
924 } 1075 }
925 1076
926 ProxyImplForTest* LayerTreeTest::GetProxyImplForTest() const { 1077 ProxyImplForTest* LayerTreeTest::GetProxyImplForTest() const {
927 DCHECK(HasImplThread()); 1078 DCHECK(HasImplThread());
928 ThreadedChannel* threaded_channel = 1079
929 static_cast<ThreadedChannel*>(GetProxyMainForTest()->channel_main()); 1080 if (IsRemoteTest()) {
930 ProxyImpl* proxy_impl = threaded_channel->GetProxyImplForTesting(); 1081 return GetRemoteChannelImplForTest()->proxy_impl_for_test();
1082 }
1083
1084 ProxyImplForTest* proxy_impl_for_test =
1085 GetThreadedChannelForTest()->proxy_impl_for_test();
931 1086
932 // We check for null ProxyImpl since ProxyImpl exists in the ThreadedChannel 1087 // We check for null ProxyImpl since ProxyImpl exists in the ThreadedChannel
933 // only after it is initialized. 1088 // only after it is initialized.
934 DCHECK(proxy_impl); 1089 DCHECK(proxy_impl_for_test);
935 return static_cast<ProxyImplForTest*>(proxy_impl); 1090 return proxy_impl_for_test;
1091 }
1092
1093 ThreadedChannelForTest* LayerTreeTest::GetThreadedChannelForTest() const {
1094 DCHECK(mode_ == CompositorMode::Threaded);
1095
1096 return GetProxyMainForTest()->threaded_channel_for_test();
1097 }
1098
1099 RemoteChannelImplForTest* LayerTreeTest::GetRemoteChannelImplForTest() const {
1100 DCHECK(IsRemoteTest());
1101
1102 RemoteChannelImplForTest* remote_channel_impl_for_test =
1103 remote_channel_host_for_testing_->remote_channel_impl_for_test();
1104
1105 // We check for null RemoteChannelImpl since it is created only after the
1106 // RemoteChannelHost receives the initialization message.
1107 DCHECK(remote_channel_impl_for_test);
1108 return remote_channel_impl_for_test;
936 } 1109 }
937 1110
938 } // namespace cc 1111 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698