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

Unified 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: Rebase. Created 4 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: cc/test/layer_tree_test.cc
diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc
index 3234d45d2aeb0030794176b84aafe69f3cc88a51..68ec7cef9de3b01ca5fb8acf1286969942c703ae 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"
@@ -342,6 +346,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 {
@@ -421,6 +446,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:
@@ -428,6 +505,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,
@@ -446,15 +524,32 @@ 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());
- proxy = std::move(proxy_main);
- } else {
- proxy =
- SingleThreadProxyForTest::Create(test_hooks, layer_tree_host.get(),
- client, task_runner_provider.get());
+ switch (mode) {
+ case CompositorMode::SingleThreaded:
+ proxy = SingleThreadProxyForTest::Create(test_hooks,
+ layer_tree_host.get(), client,
+ task_runner_provider.get());
+ 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());
+ proxy = std::move(proxy_main);
vmpstr 2016/01/07 19:08:12 why not just proxy = ProxyMainForTest::CreateThrea
Khushal 2016/01/08 21:17:19 I think I was using a temp variable there earlier
+ }
+ 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);
vmpstr 2016/01/07 19:08:11 Same here
Khushal 2016/01/08 21:17:19 Done.
+ }
+ break;
+ default:
+ NOTREACHED();
}
layer_tree_host->InitializeForTesting(
std::move(task_runner_provider), std::move(proxy),
@@ -520,6 +615,10 @@ LayerTreeTest::LayerTreeTest()
LayerTreeTest::~LayerTreeTest() {}
+bool LayerTreeTest::IsRemoteTest() const {
+ return mode_ == CompositorMode::Remote;
+}
+
void LayerTreeTest::EndTest() {
if (ended_)
return;
@@ -669,12 +768,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
vmpstr 2016/01/07 19:08:12 What would be creating remote channel host in non-
Khushal 2016/01/08 21:17:19 As we discussed. I've removed the RemoteChannelHos
+ // 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;
@@ -715,8 +837,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_));
@@ -802,8 +934,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) {
vmpstr 2016/01/07 19:08:12 I think this should be explicitly mode_ == Threade
Khushal 2016/01/08 21:17:19 Done.
impl_thread_.reset(new base::Thread("Compositor"));
ASSERT_TRUE(impl_thread_->Start());
}
@@ -879,6 +1012,11 @@ TestWebGraphicsContext3D* LayerTreeTest::TestContext() {
->TestContext3d();
}
+void LayerTreeTest::DidShutdown() {
+ ReceivedDidShutdown();
+ DestroyRemoteChannelHost();
+}
+
int LayerTreeTest::LastCommittedSourceFrameNumber(LayerTreeHostImpl* impl)
const {
if (impl->pending_tree())
@@ -893,6 +1031,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 {
@@ -917,14 +1068,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

Powered by Google App Engine
This is Rietveld 408576698