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

Unified Diff: cc/trees/remote_channel_impl.h

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 side-by-side diff with in-line comments
Download patch
Index: cc/trees/remote_channel_impl.h
diff --git a/cc/trees/remote_channel_impl.h b/cc/trees/remote_channel_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..fcecc7bab255db6a958fef4ef0a43a0650012593
--- /dev/null
+++ b/cc/trees/remote_channel_impl.h
@@ -0,0 +1,202 @@
+// 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.
+
+#ifndef CC_TREES_REMOTE_CHANNEL_IMPL_H_
+#define CC_TREES_REMOTE_CHANNEL_IMPL_H_
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "cc/base/cc_export.h"
+#include "cc/base/completion_event.h"
+#include "cc/raster/task_graph_runner.h"
+#include "cc/trees/channel_impl.h"
+#include "cc/trees/proxy_impl.h"
+#include "cc/trees/remote_proto_channel.h"
+
+namespace cc {
+class LayerTreeHost;
+class LayerTreeSettings;
+class RemoteChannelHost;
+
+namespace proto {
+class CompositorMessage;
+class CompositorMessageToImpl;
+class CompositorMessageToMain;
+class InitializeImpl;
+}
+
+// The ChannelImpl implementation for the remote compositor. The lifetime of
+// this class is tied to the lifetime of the main components of the remote
+// compositor on the engine and the RemoteChannelHostClient.
+//
+// The object life cycle and communication across threads is as follows:
+//
+// The RemoteChannelImpl is created by the RemoteChannelHost on receiving
+// CompositorMessageToImpl:: InitializeImpl message from the main compositor.
+//
+// Main Thread | Impl Thread
+// |
+// RemoteChannelHost-> |
+// CreateRemoteChannelImpl() |
+// | |
+// | RemoteChannelImpl
+// ---------------------------------------------------------------------------
+// RemoteChannelImpl->Initialize()---PostTask---> RemoteChannelImpl::
David Trainor- moved to gerrit 2015/12/15 00:52:14 :: for all of these?
Khushal 2015/12/15 05:05:30 Done.
+// InitializeImplOnImpl
+// |
+// ProxyImpl::Create
+// |
+// .
+// .
+// ProxyImpl::ScheduledActionBegin
+// OutputSurfaceCreation
+// |
+// ChannelImpl::RequestNewOutputSurface
+// |
+// RemoteChannelImpl-> |
+// RequestNewOutputSurface()<----PostTask--------------
+// .
+// .
+// |
+// RemoteChannelImpl::
+// ~RemoteChannelImpl() ---PostTask---> RemoteChannelImpl::
+// ShutdownImplOnImpl
+// ----------------------------------------------------------------------------
+//
+// The destruction of the RemoteChannelImpl can be triggered by the
+// RemoteChannelHost in 2 cases:
+// 1) On receiving a CompositorMessageToImpl::CloseImpl message from the main
+// compositor.
+// 2) When the RemoteChannelHost is being destroyed, which will destroy the
+// RemoteChannelImpl.
+//
+// The class is created and destroyed on the main thread but can be safely
+// called from the main or impl thread. It is safe to call RemoteChannelImpl on
+// the impl thread since:
+// 1) The only impl threaded callers of RemoteChannelImpl is the
+// RemoteChannelImpl itself and ProxyImpl which is created and owned by the
+// RemoteChannelImpl.
+// 2) The RemoteChannelImpl blocks the main thread in its dtor to wait for the
+// impl-thread teardown to complete, which ensures that any tasks queued to call
+// it on the impl thread are run before it is destroyed on the main thread.
+
+class CC_EXPORT RemoteChannelImpl : public ChannelImpl {
+ public:
+ static scoped_ptr<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);
+
+ ~RemoteChannelImpl() override;
+
+ void Initialize();
+
+ void HandleProto(const proto::CompositorMessageToImpl& proto);
+
+ // Should be called on impl thread only.
+ ProxyImpl* GetProxyImplForTesting() const;
+
+ protected:
+ 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);
+
+ // virtual for testing.
+ virtual scoped_ptr<ProxyImpl> CreateProxyImpl(
+ ChannelImpl* channel_impl,
+ LayerTreeHost* layer_tree_host,
+ TaskRunnerProvider* task_runner_provider,
+ scoped_ptr<BeginFrameSource> external_begin_frame_source);
+
+ bool MainFrameWillHappenForTesting();
+
+ private:
+ struct MainThreadOnly {
+ RemoteChannelHost* remote_channel_host;
+
+ // For the remote mode, the data from the LayerTreeHost of the main
+ // compositor is deserialized to this LayerTreeHost which is used by
+ // ProxyImpl for the commit.
+ //
+ // Since the lifetime of this LayerTreeHost has to be tied to the lifetime
+ // of the main compositor, it is created and owned by the RemoteChannelImpl.
+ //
+ // It is *important* to note that the purpose of this LayerTreeHost is to
+ // run impl-threaded operations. The only method that can be called on it
+ // from the main thread is LayerTreeHost::FromProtobuf, used to add the
+ // commit data to this host.
+ scoped_ptr<LayerTreeHost> layer_tree_host;
+
+ 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);
+ ~MainThreadOnly();
+ };
+
+ struct CompositorThreadOnly {
+ scoped_ptr<ProxyImpl> proxy_impl;
+ scoped_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory;
+
+ CompositorThreadOnly();
+ ~CompositorThreadOnly();
+ };
+
+ // Called on impl thread.
+ // ChannelImpl implementation
+ void DidCompleteSwapBuffers() override;
+ void SetRendererCapabilitiesMainCopy(
+ const RendererCapabilities& capabilities) override;
+ void BeginMainFrameNotExpectedSoon() override;
+ void DidCommitAndDrawFrame() override;
+ void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override;
+ void DidLoseOutputSurface() override;
+ void RequestNewOutputSurface() override;
+ void DidInitializeOutputSurface(
+ bool success,
+ const RendererCapabilities& capabilities) override;
+ void DidCompletePageScaleAnimation() override;
+ void PostFrameTimingEventsOnMain(
+ scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events,
+ scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events)
+ override;
+ void BeginMainFrame(
+ scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override;
+
+ void InitializeImplOnImpl(CompletionEvent* completion,
+ LayerTreeHost* layer_tree_host);
+ void ShutdownImplOnImpl(CompletionEvent* completion);
+
+ // Called on main thread.
+ void MainThreadHasStoppedFlinging();
+
+ MainThreadOnly& main();
+ CompositorThreadOnly& impl();
+ const CompositorThreadOnly& impl() const;
+
+ base::SingleThreadTaskRunner* MainThreadTaskRunner() const;
+ base::SingleThreadTaskRunner* ImplThreadTaskRunner() const;
+
+ // use accessors instead of these variables directly
+ MainThreadOnly main_thread_vars_unsafe_;
+ CompositorThreadOnly compositor_thread_vars_unsafe_;
+
+ TaskRunnerProvider* task_runner_provider_;
+
+ base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(RemoteChannelImpl);
+};
+
+} // namespace cc
+
+#endif // CC_TREES_REMOTE_CHANNEL_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698