OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_TREES_REMOTE_CHANNEL_IMPL_H_ | |
6 #define CC_TREES_REMOTE_CHANNEL_IMPL_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "cc/base/cc_export.h" | |
11 #include "cc/base/completion_event.h" | |
12 #include "cc/raster/task_graph_runner.h" | |
13 #include "cc/trees/channel_impl.h" | |
14 #include "cc/trees/proxy_impl.h" | |
15 #include "cc/trees/remote_proto_channel.h" | |
16 | |
17 namespace cc { | |
18 class LayerTreeHost; | |
19 class LayerTreeSettings; | |
20 class RemoteChannelHost; | |
21 | |
22 namespace proto { | |
23 class CompositorMessage; | |
24 class CompositorMessageToImpl; | |
25 class CompositorMessageToMain; | |
26 class InitializeImpl; | |
27 } | |
28 | |
29 // The ChannelImpl implementation for the remote compositor. The lifetime of | |
30 // this class is tied to the lifetime of the main components of the remote | |
31 // compositor on the engine and the RemoteChannelHostClient. | |
32 // | |
33 // The object life cycle and communication across threads is as follows: | |
34 // | |
35 // The RemoteChannelImpl is created by the RemoteChannelHost on receiving | |
36 // CompositorMessageToImpl:: InitializeImpl message from the main compositor. | |
37 // | |
38 // Main Thread | Impl Thread | |
39 // | | |
40 // RemoteChannelHost-> | | |
41 // CreateRemoteChannelImpl() | | |
42 // | | | |
43 // | RemoteChannelImpl | |
44 // --------------------------------------------------------------------------- | |
45 // 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.
| |
46 // InitializeImplOnImpl | |
47 // | | |
48 // ProxyImpl::Create | |
49 // | | |
50 // . | |
51 // . | |
52 // ProxyImpl::ScheduledActionBegin | |
53 // OutputSurfaceCreation | |
54 // | | |
55 // ChannelImpl::RequestNewOutputSurface | |
56 // | | |
57 // RemoteChannelImpl-> | | |
58 // RequestNewOutputSurface()<----PostTask-------------- | |
59 // . | |
60 // . | |
61 // | | |
62 // RemoteChannelImpl:: | |
63 // ~RemoteChannelImpl() ---PostTask---> RemoteChannelImpl:: | |
64 // ShutdownImplOnImpl | |
65 // ---------------------------------------------------------------------------- | |
66 // | |
67 // The destruction of the RemoteChannelImpl can be triggered by the | |
68 // RemoteChannelHost in 2 cases: | |
69 // 1) On receiving a CompositorMessageToImpl::CloseImpl message from the main | |
70 // compositor. | |
71 // 2) When the RemoteChannelHost is being destroyed, which will destroy the | |
72 // RemoteChannelImpl. | |
73 // | |
74 // The class is created and destroyed on the main thread but can be safely | |
75 // called from the main or impl thread. It is safe to call RemoteChannelImpl on | |
76 // the impl thread since: | |
77 // 1) The only impl threaded callers of RemoteChannelImpl is the | |
78 // RemoteChannelImpl itself and ProxyImpl which is created and owned by the | |
79 // RemoteChannelImpl. | |
80 // 2) The RemoteChannelImpl blocks the main thread in its dtor to wait for the | |
81 // impl-thread teardown to complete, which ensures that any tasks queued to call | |
82 // it on the impl thread are run before it is destroyed on the main thread. | |
83 | |
84 class CC_EXPORT RemoteChannelImpl : public ChannelImpl { | |
85 public: | |
86 static scoped_ptr<RemoteChannelImpl> Create( | |
87 RemoteChannelHost* remote_channel_host, | |
88 TaskGraphRunner* task_graph_runner, | |
89 const LayerTreeSettings& settings, | |
90 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
91 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); | |
92 | |
93 ~RemoteChannelImpl() override; | |
94 | |
95 void Initialize(); | |
96 | |
97 void HandleProto(const proto::CompositorMessageToImpl& proto); | |
98 | |
99 // Should be called on impl thread only. | |
100 ProxyImpl* GetProxyImplForTesting() const; | |
101 | |
102 protected: | |
103 RemoteChannelImpl( | |
104 RemoteChannelHost* remote_channel_host, | |
105 TaskGraphRunner* task_graph_runner, | |
106 const LayerTreeSettings& settings, | |
107 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
108 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); | |
109 | |
110 // virtual for testing. | |
111 virtual scoped_ptr<ProxyImpl> CreateProxyImpl( | |
112 ChannelImpl* channel_impl, | |
113 LayerTreeHost* layer_tree_host, | |
114 TaskRunnerProvider* task_runner_provider, | |
115 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
116 | |
117 bool MainFrameWillHappenForTesting(); | |
118 | |
119 private: | |
120 struct MainThreadOnly { | |
121 RemoteChannelHost* remote_channel_host; | |
122 | |
123 // For the remote mode, the data from the LayerTreeHost of the main | |
124 // compositor is deserialized to this LayerTreeHost which is used by | |
125 // ProxyImpl for the commit. | |
126 // | |
127 // Since the lifetime of this LayerTreeHost has to be tied to the lifetime | |
128 // of the main compositor, it is created and owned by the RemoteChannelImpl. | |
129 // | |
130 // It is *important* to note that the purpose of this LayerTreeHost is to | |
131 // run impl-threaded operations. The only method that can be called on it | |
132 // from the main thread is LayerTreeHost::FromProtobuf, used to add the | |
133 // commit data to this host. | |
134 scoped_ptr<LayerTreeHost> layer_tree_host; | |
135 | |
136 MainThreadOnly( | |
137 RemoteChannelImpl* remote_channel_impl, | |
138 RemoteChannelHost* remote_channel_host, | |
139 TaskGraphRunner* task_graph_runner, | |
140 const LayerTreeSettings& settings, | |
141 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
142 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); | |
143 ~MainThreadOnly(); | |
144 }; | |
145 | |
146 struct CompositorThreadOnly { | |
147 scoped_ptr<ProxyImpl> proxy_impl; | |
148 scoped_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory; | |
149 | |
150 CompositorThreadOnly(); | |
151 ~CompositorThreadOnly(); | |
152 }; | |
153 | |
154 // Called on impl thread. | |
155 // ChannelImpl implementation | |
156 void DidCompleteSwapBuffers() override; | |
157 void SetRendererCapabilitiesMainCopy( | |
158 const RendererCapabilities& capabilities) override; | |
159 void BeginMainFrameNotExpectedSoon() override; | |
160 void DidCommitAndDrawFrame() override; | |
161 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override; | |
162 void DidLoseOutputSurface() override; | |
163 void RequestNewOutputSurface() override; | |
164 void DidInitializeOutputSurface( | |
165 bool success, | |
166 const RendererCapabilities& capabilities) override; | |
167 void DidCompletePageScaleAnimation() override; | |
168 void PostFrameTimingEventsOnMain( | |
169 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | |
170 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) | |
171 override; | |
172 void BeginMainFrame( | |
173 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override; | |
174 | |
175 void InitializeImplOnImpl(CompletionEvent* completion, | |
176 LayerTreeHost* layer_tree_host); | |
177 void ShutdownImplOnImpl(CompletionEvent* completion); | |
178 | |
179 // Called on main thread. | |
180 void MainThreadHasStoppedFlinging(); | |
181 | |
182 MainThreadOnly& main(); | |
183 CompositorThreadOnly& impl(); | |
184 const CompositorThreadOnly& impl() const; | |
185 | |
186 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; | |
187 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; | |
188 | |
189 // use accessors instead of these variables directly | |
190 MainThreadOnly main_thread_vars_unsafe_; | |
191 CompositorThreadOnly compositor_thread_vars_unsafe_; | |
192 | |
193 TaskRunnerProvider* task_runner_provider_; | |
194 | |
195 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; | |
196 | |
197 DISALLOW_COPY_AND_ASSIGN(RemoteChannelImpl); | |
198 }; | |
199 | |
200 } // namespace cc | |
201 | |
202 #endif // CC_TREES_REMOTE_CHANNEL_IMPL_H_ | |
OLD | NEW |