| Index: cc/test/layer_tree_test.cc
|
| diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc
|
| index d68ec6744bf8f72135da6a993027cccc369c28b2..f2f36e66ee6121e723fb2aaa4478833e5ffb9991 100644
|
| --- a/cc/test/layer_tree_test.cc
|
| +++ b/cc/test/layer_tree_test.cc
|
| @@ -22,16 +22,20 @@
|
| #include "cc/test/fake_external_begin_frame_source.h"
|
| #include "cc/test/fake_layer_tree_host_client.h"
|
| #include "cc/test/fake_output_surface.h"
|
| +#include "cc/test/remote_channel_impl_for_test.h"
|
| #include "cc/test/test_context_provider.h"
|
| #include "cc/test/test_gpu_memory_buffer_manager.h"
|
| #include "cc/test/test_shared_bitmap_manager.h"
|
| #include "cc/test/test_task_graph_runner.h"
|
| +#include "cc/test/threaded_channel_for_test.h"
|
| #include "cc/trees/layer_tree_host_client.h"
|
| #include "cc/trees/layer_tree_host_impl.h"
|
| #include "cc/trees/layer_tree_host_single_thread_client.h"
|
| #include "cc/trees/layer_tree_impl.h"
|
| #include "cc/trees/proxy_impl.h"
|
| #include "cc/trees/proxy_main.h"
|
| +#include "cc/trees/remote_channel_host.h"
|
| +#include "cc/trees/remote_channel_host_client.h"
|
| #include "cc/trees/single_thread_proxy.h"
|
| #include "cc/trees/threaded_channel.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| @@ -350,6 +354,27 @@ class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
|
| bool notify_ready_to_activate_was_blocked_;
|
| };
|
|
|
| +// Implementation of RemoteChannelHostClient for tests.
|
| +class RemoteChannelHostClientForTesting : public RemoteChannelHostClient {
|
| + public:
|
| + static scoped_ptr<RemoteChannelHostClientForTesting> Create(
|
| + TestHooks* test_hooks) {
|
| + return make_scoped_ptr(new RemoteChannelHostClientForTesting(test_hooks));
|
| + }
|
| +
|
| + void OverrideLayerTreeSettings(LayerTreeSettings* settings) override {
|
| + test_hooks_->OverrideLayerTreeSettings(settings);
|
| + }
|
| +
|
| + void DidShutdown() override { test_hooks_->DidShutdown(); }
|
| +
|
| + private:
|
| + explicit RemoteChannelHostClientForTesting(TestHooks* test_hooks)
|
| + : test_hooks_(test_hooks) {}
|
| +
|
| + TestHooks* test_hooks_;
|
| +};
|
| +
|
| // Implementation of LayerTreeHost callback interface.
|
| class LayerTreeHostClientForTesting : public LayerTreeHostClient,
|
| public LayerTreeHostSingleThreadClient {
|
| @@ -429,6 +454,58 @@ class LayerTreeHostClientForTesting : public LayerTreeHostClient,
|
| TestHooks* test_hooks_;
|
| };
|
|
|
| +// Injects RemoteChannelImplForTesting.
|
| +class RemoteChannelHostForTesting : public RemoteChannelHost {
|
| + public:
|
| + static scoped_ptr<RemoteChannelHostForTesting> Create(
|
| + TestHooks* test_hooks,
|
| + RemoteProtoChannel* remote_proto_channel,
|
| + RemoteChannelHostClient* client,
|
| + TaskGraphRunner* task_graph_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) {
|
| + return make_scoped_ptr(new RemoteChannelHostForTesting(
|
| + test_hooks, remote_proto_channel, client, task_graph_runner,
|
| + main_task_runner, impl_task_runner));
|
| + }
|
| +
|
| + RemoteChannelImplForTest* remote_channel_impl_for_test() const {
|
| + return remote_channel_impl_for_test_;
|
| + }
|
| +
|
| + private:
|
| + RemoteChannelHostForTesting(
|
| + TestHooks* test_hooks,
|
| + RemoteProtoChannel* remote_proto_channel,
|
| + RemoteChannelHostClient* client,
|
| + TaskGraphRunner* task_graph_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner)
|
| + : RemoteChannelHost(remote_proto_channel,
|
| + client,
|
| + task_graph_runner,
|
| + main_task_runner,
|
| + impl_task_runner),
|
| + test_hooks_(test_hooks) {}
|
| +
|
| + scoped_ptr<RemoteChannelImpl> CreateRemoteChannelImpl(
|
| + RemoteChannelHost* remote_channel_host,
|
| + TaskGraphRunner* task_graph_runner,
|
| + const LayerTreeSettings& settings,
|
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) override {
|
| + scoped_ptr<RemoteChannelImplForTest> channel_impl =
|
| + RemoteChannelImplForTest::Create(test_hooks_, remote_channel_host,
|
| + task_graph_runner, settings,
|
| + main_task_runner, impl_task_runner);
|
| + remote_channel_impl_for_test_ = channel_impl.get();
|
| + return std::move(channel_impl);
|
| + }
|
| +
|
| + TestHooks* test_hooks_;
|
| + RemoteChannelImplForTest* remote_channel_impl_for_test_;
|
| +};
|
| +
|
| // Adapts LayerTreeHost for test. Injects LayerTreeHostImplForTesting.
|
| class LayerTreeHostForTesting : public LayerTreeHost {
|
| public:
|
| @@ -436,6 +513,7 @@ class LayerTreeHostForTesting : public LayerTreeHost {
|
| TestHooks* test_hooks,
|
| CompositorMode mode,
|
| LayerTreeHostClientForTesting* client,
|
| + RemoteProtoChannel* remote_proto_channel,
|
| SharedBitmapManager* shared_bitmap_manager,
|
| gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
|
| TaskGraphRunner* task_graph_runner,
|
| @@ -454,16 +532,33 @@ class LayerTreeHostForTesting : public LayerTreeHost {
|
| scoped_ptr<TaskRunnerProvider> task_runner_provider =
|
| TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
|
| scoped_ptr<Proxy> proxy;
|
| - if (mode == CompositorMode::Threaded) {
|
| - DCHECK(impl_task_runner.get());
|
| - scoped_ptr<ProxyMain> proxy_main = ProxyMainForTest::CreateThreaded(
|
| - test_hooks, layer_tree_host.get(), task_runner_provider.get(),
|
| - std::move(external_begin_frame_source));
|
| - proxy = std::move(proxy_main);
|
| - } else {
|
| - proxy = SingleThreadProxyForTest::Create(
|
| - test_hooks, layer_tree_host.get(), client, task_runner_provider.get(),
|
| - std::move(external_begin_frame_source));
|
| + switch (mode) {
|
| + case CompositorMode::SingleThreaded:
|
| + proxy = SingleThreadProxyForTest::Create(
|
| + test_hooks, layer_tree_host.get(), client,
|
| + task_runner_provider.get(), std::move(external_begin_frame_source));
|
| + break;
|
| + case CompositorMode::Threaded:
|
| + DCHECK(impl_task_runner.get());
|
| + {
|
| + scoped_ptr<ProxyMain> proxy_main = ProxyMainForTest::CreateThreaded(
|
| + test_hooks, layer_tree_host.get(), task_runner_provider.get(),
|
| + std::move(external_begin_frame_source));
|
| + proxy = std::move(proxy_main);
|
| + }
|
| + break;
|
| + case CompositorMode::Remote:
|
| + DCHECK(!impl_task_runner.get());
|
| + DCHECK(!external_begin_frame_source);
|
| + {
|
| + scoped_ptr<ProxyMain> proxy_main = ProxyMainForTest::CreateRemote(
|
| + test_hooks, remote_proto_channel, layer_tree_host.get(),
|
| + task_runner_provider.get());
|
| + proxy = std::move(proxy_main);
|
| + }
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| }
|
| layer_tree_host->InitializeForTesting(std::move(task_runner_provider),
|
| std::move(proxy));
|
| @@ -528,6 +623,10 @@ LayerTreeTest::LayerTreeTest()
|
|
|
| LayerTreeTest::~LayerTreeTest() {}
|
|
|
| +bool LayerTreeTest::IsRemoteTest() const {
|
| + return mode_ == CompositorMode::Remote;
|
| +}
|
| +
|
| void LayerTreeTest::EndTest() {
|
| if (ended_)
|
| return;
|
| @@ -677,12 +776,35 @@ void LayerTreeTest::DoBeginTest() {
|
| }
|
|
|
| DCHECK(!impl_thread_ || impl_thread_->task_runner().get());
|
| - layer_tree_host_ = LayerTreeHostForTesting::Create(
|
| - this, mode_, client_.get(), shared_bitmap_manager_.get(),
|
| - gpu_memory_buffer_manager_.get(), task_graph_runner_.get(), settings_,
|
| - base::ThreadTaskRunnerHandle::Get(),
|
| - impl_thread_ ? impl_thread_->task_runner() : NULL,
|
| - std::move(external_begin_frame_source));
|
| +
|
| + if (IsRemoteTest()) {
|
| + // It is important to create the RemoteChannelHost before the LayerTreeHost
|
| + // since the main compositor immediately sends an initialization message to
|
| + // the impl compositor.
|
| + DCHECK(impl_thread_);
|
| + remote_channel_host_client_ =
|
| + RemoteChannelHostClientForTesting::Create(this);
|
| + remote_channel_host_for_testing_ = RemoteChannelHostForTesting::Create(
|
| + this, &remote_proto_channel_bridge_.channel_impl,
|
| + remote_channel_host_client_.get(), task_graph_runner_.get(),
|
| + base::ThreadTaskRunnerHandle::Get(), impl_thread_->task_runner());
|
| + DCHECK(remote_proto_channel_bridge_.channel_impl.HasReceiver());
|
| +
|
| + layer_tree_host_ = LayerTreeHostForTesting::Create(
|
| + this, mode_, client_.get(), &remote_proto_channel_bridge_.channel_main,
|
| + nullptr, nullptr, task_graph_runner_.get(), settings_,
|
| + base::ThreadTaskRunnerHandle::Get(), nullptr,
|
| + std::move(external_begin_frame_source));
|
| + DCHECK(remote_proto_channel_bridge_.channel_main.HasReceiver());
|
| + } else {
|
| + layer_tree_host_ = LayerTreeHostForTesting::Create(
|
| + this, mode_, client_.get(), nullptr, shared_bitmap_manager_.get(),
|
| + gpu_memory_buffer_manager_.get(), task_graph_runner_.get(), settings_,
|
| + base::ThreadTaskRunnerHandle::Get(),
|
| + impl_thread_ ? impl_thread_->task_runner() : NULL,
|
| + std::move(external_begin_frame_source));
|
| + }
|
| +
|
| ASSERT_TRUE(layer_tree_host_);
|
|
|
| started_ = true;
|
| @@ -723,8 +845,18 @@ void LayerTreeTest::Timeout() {
|
|
|
| void LayerTreeTest::RealEndTest() {
|
| // TODO(mithro): Make this method only end when not inside an impl frame.
|
| - if (layer_tree_host_ && !timed_out_ &&
|
| - proxy()->MainFrameWillHappenForTesting()) {
|
| + bool main_frame_will_happen;
|
| + if (IsRemoteTest()) {
|
| + main_frame_will_happen =
|
| + remote_channel_host_for_testing_
|
| + ? GetRemoteChannelImplForTest()->MainFrameWillHappenForTesting()
|
| + : false;
|
| + } else {
|
| + main_frame_will_happen =
|
| + layer_tree_host_ ? proxy()->MainFrameWillHappenForTesting() : false;
|
| + }
|
| +
|
| + if (main_frame_will_happen && !timed_out_) {
|
| main_task_runner_->PostTask(
|
| FROM_HERE,
|
| base::Bind(&LayerTreeTest::RealEndTest, main_thread_weak_ptr_));
|
| @@ -810,8 +942,9 @@ void LayerTreeTest::DispatchCompositeImmediately() {
|
| }
|
|
|
| void LayerTreeTest::RunTest(CompositorMode mode, bool delegating_renderer) {
|
| + DCHECK(mode != CompositorMode::Deserializable);
|
| mode_ = mode;
|
| - if (mode_ == CompositorMode::Threaded) {
|
| + if (mode_ != CompositorMode::SingleThreaded) {
|
| impl_thread_.reset(new base::Thread("Compositor"));
|
| ASSERT_TRUE(impl_thread_->Start());
|
| }
|
| @@ -887,6 +1020,11 @@ TestWebGraphicsContext3D* LayerTreeTest::TestContext() {
|
| ->TestContext3d();
|
| }
|
|
|
| +void LayerTreeTest::DidShutdown() {
|
| + ReceivedDidShutdown();
|
| + DestroyRemoteChannelHost();
|
| +}
|
| +
|
| int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl)
|
| const {
|
| if (impl->pending_tree())
|
| @@ -901,6 +1039,19 @@ void LayerTreeTest::DestroyLayerTreeHost() {
|
| if (layer_tree_host_ && layer_tree_host_->root_layer())
|
| layer_tree_host_->root_layer()->SetLayerTreeHost(NULL);
|
| layer_tree_host_ = nullptr;
|
| +
|
| + DCHECK(!remote_proto_channel_bridge_.channel_main.HasReceiver());
|
| +
|
| + // Destroying the LayerTreeHost should destroy the RemoteChannelHost.
|
| + DCHECK(!remote_channel_host_for_testing_);
|
| +}
|
| +
|
| +void LayerTreeTest::DestroyRemoteChannelHost() {
|
| + DCHECK(IsRemoteTest());
|
| + DCHECK(remote_channel_host_for_testing_);
|
| +
|
| + remote_channel_host_for_testing_ = nullptr;
|
| + DCHECK(!remote_proto_channel_bridge_.channel_impl.HasReceiver());
|
| }
|
|
|
| TaskGraphRunner* LayerTreeTest::task_graph_runner() const {
|
| @@ -925,14 +1076,36 @@ ProxyMainForTest* LayerTreeTest::GetProxyMainForTest() const {
|
|
|
| ProxyImplForTest* LayerTreeTest::GetProxyImplForTest() const {
|
| DCHECK(HasImplThread());
|
| - ThreadedChannel* threaded_channel =
|
| - static_cast<ThreadedChannel*>(GetProxyMainForTest()->channel_main());
|
| - ProxyImpl* proxy_impl = threaded_channel->GetProxyImplForTesting();
|
| +
|
| + if (IsRemoteTest()) {
|
| + return GetRemoteChannelImplForTest()->proxy_impl_for_test();
|
| + }
|
| +
|
| + ProxyImplForTest* proxy_impl_for_test =
|
| + GetThreadedChannelForTest()->proxy_impl_for_test();
|
|
|
| // We check for null ProxyImpl since ProxyImpl exists in the ThreadedChannel
|
| // only after it is initialized.
|
| - DCHECK(proxy_impl);
|
| - return static_cast<ProxyImplForTest*>(proxy_impl);
|
| + DCHECK(proxy_impl_for_test);
|
| + return proxy_impl_for_test;
|
| +}
|
| +
|
| +ThreadedChannelForTest* LayerTreeTest::GetThreadedChannelForTest() const {
|
| + DCHECK(mode_ == CompositorMode::Threaded);
|
| +
|
| + return GetProxyMainForTest()->threaded_channel_for_test();
|
| +}
|
| +
|
| +RemoteChannelImplForTest* LayerTreeTest::GetRemoteChannelImplForTest() const {
|
| + DCHECK(IsRemoteTest());
|
| +
|
| + RemoteChannelImplForTest* remote_channel_impl_for_test =
|
| + remote_channel_host_for_testing_->remote_channel_impl_for_test();
|
| +
|
| + // We check for null RemoteChannelImpl since it is created only after the
|
| + // RemoteChannelHost receives the initialization message.
|
| + DCHECK(remote_channel_impl_for_test);
|
| + return remote_channel_impl_for_test;
|
| }
|
|
|
| } // namespace cc
|
|
|