Index: cc/trees/remote_channel_impl.cc |
diff --git a/cc/trees/remote_channel_impl.cc b/cc/trees/remote_channel_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3a1c5a104a25409a06ddce22cd444f52ba35de40 |
--- /dev/null |
+++ b/cc/trees/remote_channel_impl.cc |
@@ -0,0 +1,220 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/trees/remote_channel_impl.h" |
+ |
+#include "base/bind_helpers.h" |
+#include "base/single_thread_task_runner.h" |
+#include "cc/proto/compositor_message.pb.h" |
+#include "cc/proto/compositor_message_to_impl.pb.h" |
+#include "cc/proto/compositor_message_to_main.pb.h" |
+#include "cc/trees/layer_tree_host.h" |
+#include "cc/trees/layer_tree_settings.h" |
+ |
+namespace cc { |
+ |
+scoped_ptr<RemoteChannelImpl> RemoteChannelImpl::Create( |
+ 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) { |
+ return make_scoped_ptr( |
+ new RemoteChannelImpl(remote_channel_host, task_graph_runner, settings, |
+ main_task_runner, impl_task_runner)); |
+} |
+ |
+RemoteChannelImpl::RemoteChannelImpl( |
+ 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) |
+ : main_thread_vars_unsafe_(this, |
+ remote_channel_host, |
+ task_graph_runner, |
+ settings, |
+ main_task_runner, |
+ impl_task_runner) { |
+ DCHECK(task_runner_provider_->IsMainThread()); |
+} |
+ |
+RemoteChannelImpl::~RemoteChannelImpl() { |
+ DCHECK(task_runner_provider_->IsMainThread()); |
+ { |
+ CompletionEvent completion; |
+ DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
+ ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, base::Bind(&ProxyImpl::FinishGLOnImpl, proxy_impl_weak_ptr_, |
+ &completion)); |
+ completion.Wait(); |
+ } |
+ { |
+ CompletionEvent completion; |
+ DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
+ ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, base::Bind(&RemoteChannelImpl::ShutdownImplOnImpl, |
+ base::Unretained(this), &completion)); |
+ completion.Wait(); |
+ } |
+} |
+ |
+void RemoteChannelImpl::HandleProto( |
+ const proto::CompositorMessageToImpl& proto) { |
+ DCHECK(task_runner_provider_->IsMainThread()); |
+ switch (proto.message_type()) { |
+ case proto::CompositorMessageToImpl::MainThreadHasStoppedFlingingOnImpl: |
+ MainThreadHasStoppedFlinging(); |
+ break; |
+ default: |
+ // TODO(khushalsagar): Add more types here. |
+ NOTIMPLEMENTED(); |
+ } |
+} |
+ |
+scoped_ptr<ProxyImpl> RemoteChannelImpl::CreateProxyImpl( |
+ ChannelImpl* channel_impl, |
+ LayerTreeHost* layer_tree_host, |
+ TaskRunnerProvider* task_runner_provider, |
+ scoped_ptr<BeginFrameSource> external_begin_frame_source) { |
+ DCHECK(task_runner_provider_->IsImplThread()); |
+ return ProxyImpl::Create(channel_impl, layer_tree_host, task_runner_provider, |
+ std::move(external_begin_frame_source)); |
+} |
+ |
+bool RemoteChannelImpl::MainFrameWillHappenForTesting() { |
+ DCHECK(task_runner_provider_->IsMainThread()); |
+ bool main_frame_will_happen; |
+ { |
+ CompletionEvent completion; |
+ DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
+ ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ProxyImpl::MainFrameWillHappenOnImplForTesting, |
+ proxy_impl_weak_ptr_, &completion, &main_frame_will_happen)); |
+ completion.Wait(); |
+ } |
+ return main_frame_will_happen; |
+} |
+ |
+void RemoteChannelImpl::Initialize() { |
+ CompletionEvent completion; |
+ DebugScopedSetMainThreadBlocked main_thread_blocked(task_runner_provider_); |
+ ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, base::Bind(&RemoteChannelImpl::InitializeImplOnImpl, |
+ base::Unretained(this), &completion, |
+ main().layer_tree_host.get())); |
+ completion.Wait(); |
+} |
+ |
+void RemoteChannelImpl::InitializeImplOnImpl(CompletionEvent* completion, |
+ LayerTreeHost* layer_tree_host) { |
+ DCHECK(task_runner_provider_->IsMainThreadBlocked()); |
+ DCHECK(task_runner_provider_->IsImplThread()); |
+ |
+ impl().proxy_impl = |
+ CreateProxyImpl(this, layer_tree_host, task_runner_provider_, nullptr); |
+ impl().proxy_impl_weak_factory = make_scoped_ptr( |
+ new base::WeakPtrFactory<ProxyImpl>(impl().proxy_impl.get())); |
+ proxy_impl_weak_ptr_ = impl().proxy_impl_weak_factory->GetWeakPtr(); |
+ completion->Signal(); |
+} |
+ |
+void RemoteChannelImpl::ShutdownImplOnImpl(CompletionEvent* completion) { |
+ DCHECK(task_runner_provider_->IsMainThreadBlocked()); |
+ DCHECK(task_runner_provider_->IsImplThread()); |
+ |
+ // We must invalidate the proxy_impl weak ptrs and destroy the weak ptr |
+ // factory before destroying proxy_impl. |
+ impl().proxy_impl_weak_factory->InvalidateWeakPtrs(); |
+ impl().proxy_impl_weak_factory.reset(); |
+ |
+ impl().proxy_impl.reset(); |
+ completion->Signal(); |
+} |
+ |
+void RemoteChannelImpl::MainThreadHasStoppedFlinging() { |
+ ImplThreadTaskRunner()->PostTask( |
+ FROM_HERE, base::Bind(&ProxyImpl::MainThreadHasStoppedFlingingOnImpl, |
+ proxy_impl_weak_ptr_)); |
+} |
+ |
+void RemoteChannelImpl::DidCompleteSwapBuffers() {} |
+ |
+void RemoteChannelImpl::SetRendererCapabilitiesMainCopy( |
+ const RendererCapabilities& capabilities) {} |
+ |
+void RemoteChannelImpl::BeginMainFrameNotExpectedSoon() {} |
+ |
+void RemoteChannelImpl::DidCommitAndDrawFrame() {} |
+ |
+void RemoteChannelImpl::SetAnimationEvents( |
+ scoped_ptr<AnimationEventsVector> queue) {} |
+ |
+void RemoteChannelImpl::DidLoseOutputSurface() {} |
+ |
+void RemoteChannelImpl::RequestNewOutputSurface() {} |
+ |
+void RemoteChannelImpl::DidInitializeOutputSurface( |
+ bool success, |
+ const RendererCapabilities& capabilities) {} |
+ |
+void RemoteChannelImpl::DidCompletePageScaleAnimation() {} |
+ |
+void RemoteChannelImpl::PostFrameTimingEventsOnMain( |
+ scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
+ scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) {} |
+ |
+void RemoteChannelImpl::BeginMainFrame( |
+ scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) {} |
+ |
+RemoteChannelImpl::MainThreadOnly& RemoteChannelImpl::main() { |
+ DCHECK(task_runner_provider_->IsMainThread()); |
+ return main_thread_vars_unsafe_; |
+} |
+ |
+RemoteChannelImpl::CompositorThreadOnly& RemoteChannelImpl::impl() { |
+ DCHECK(task_runner_provider_->IsImplThread()); |
+ return compositor_thread_vars_unsafe_; |
+} |
+ |
+const RemoteChannelImpl::CompositorThreadOnly& RemoteChannelImpl::impl() const { |
+ DCHECK(task_runner_provider_->IsImplThread()); |
+ return compositor_thread_vars_unsafe_; |
+} |
+ |
+base::SingleThreadTaskRunner* RemoteChannelImpl::MainThreadTaskRunner() const { |
+ return task_runner_provider_->MainThreadTaskRunner(); |
+} |
+ |
+base::SingleThreadTaskRunner* RemoteChannelImpl::ImplThreadTaskRunner() const { |
+ return task_runner_provider_->ImplThreadTaskRunner(); |
+} |
+ |
+RemoteChannelImpl::MainThreadOnly::MainThreadOnly( |
+ RemoteChannelImpl* remote_channel_impl, |
+ 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) |
+ : remote_channel_host(remote_channel_host) { |
+ LayerTreeHost::InitParams params; |
+ params.task_graph_runner = task_graph_runner; |
+ params.main_task_runner = main_task_runner; |
+ params.settings = &settings; |
+ layer_tree_host = |
+ LayerTreeHost::CreateDeserializable(impl_task_runner, ¶ms); |
+ remote_channel_impl->task_runner_provider_ = |
+ layer_tree_host->task_runner_provider(); |
+} |
+ |
+RemoteChannelImpl::MainThreadOnly::~MainThreadOnly() {} |
+ |
+RemoteChannelImpl::CompositorThreadOnly::CompositorThreadOnly() |
+ : proxy_impl(nullptr), proxy_impl_weak_factory(nullptr) {} |
+ |
+RemoteChannelImpl::CompositorThreadOnly::~CompositorThreadOnly() {} |
+ |
+} // namespace cc |