OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_TREES_THREADED_CHANNEL_H_ | 5 #ifndef CC_TREES_THREADED_CHANNEL_H_ |
6 #define CC_TREES_THREADED_CHANNEL_H_ | 6 #define CC_TREES_THREADED_CHANNEL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "cc/base/cc_export.h" | 13 #include "cc/base/cc_export.h" |
14 #include "cc/trees/channel_impl.h" | 14 #include "cc/trees/channel_impl.h" |
15 #include "cc/trees/channel_main.h" | 15 #include "cc/trees/channel_main.h" |
16 #include "cc/trees/proxy_common.h" | 16 #include "cc/trees/proxy_common.h" |
17 #include "cc/trees/proxy_impl.h" | 17 #include "cc/trees/proxy_impl.h" |
18 #include "cc/trees/proxy_main.h" | 18 #include "cc/trees/proxy_main.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
22 } | 22 } |
23 | 23 |
24 namespace cc { | 24 namespace cc { |
25 class ChannelImpl; | 25 class ChannelImpl; |
26 class ChannelMain; | 26 class ChannelMain; |
27 class LayerTreeHost; | 27 class LayerTreeHostInProcess; |
28 class ProxyImpl; | 28 class ProxyImpl; |
29 class ProxyMain; | 29 class ProxyMain; |
30 | 30 |
31 // An implementation of ChannelMain and ChannelImpl that sends commands between | 31 // An implementation of ChannelMain and ChannelImpl that sends commands between |
32 // ProxyMain and ProxyImpl across thread boundaries. | 32 // ProxyMain and ProxyImpl across thread boundaries. |
33 // | 33 // |
34 // LayerTreeHost creates ThreadedChannel and passes the ownership to ProxyMain. | 34 // LayerTreeHostInProcess creates ThreadedChannel and passes the ownership to |
35 // The object life cycle and communication across threads is as follows: | 35 // ProxyMain. The object life cycle and communication across threads is as |
36 // | 36 // follows: |
37 // | 37 // |
38 // Main Thread | Impl Thread | 38 // Main Thread | Impl Thread |
39 // LayerTreeHost->InitializeProxy | | 39 // LayerTreeHostInProcess->InitializeProxy | |
40 // | | | 40 // | | |
41 // ProxyMain->Start() | | 41 // ProxyMain->Start() | |
42 // | ThreadedChannel | 42 // | ThreadedChannel |
43 // --------------------------------------------------------------------------- | 43 // --------------------------------------------------------------------------- |
44 // ChannelMain::SynchronouslyInitializeImpl ---PostTask---> ThreadedChannel:: | 44 // ChannelMain::SynchronouslyInitializeImpl ---PostTask---> ThreadedChannel:: |
45 // InitializeImplOnImpl | 45 // InitializeImplOnImpl |
46 // | | 46 // | |
47 // ProxyImpl::Create | 47 // ProxyImpl::Create |
48 // | | 48 // | |
49 // ProxyImpl->Initialize() | 49 // ProxyImpl->Initialize() |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 std::vector<std::unique_ptr<SwapPromise>> swap_promises) override; | 101 std::vector<std::unique_ptr<SwapPromise>> swap_promises) override; |
102 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override; | 102 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override; |
103 void SetVisibleOnImpl(bool visible) override; | 103 void SetVisibleOnImpl(bool visible) override; |
104 | 104 |
105 // Blocking calls to ProxyImpl | 105 // Blocking calls to ProxyImpl |
106 void ReleaseCompositorFrameSinkOnImpl(CompletionEvent* completion) override; | 106 void ReleaseCompositorFrameSinkOnImpl(CompletionEvent* completion) override; |
107 void MainFrameWillHappenOnImplForTesting( | 107 void MainFrameWillHappenOnImplForTesting( |
108 CompletionEvent* completion, | 108 CompletionEvent* completion, |
109 bool* main_frame_will_happen) override; | 109 bool* main_frame_will_happen) override; |
110 void NotifyReadyToCommitOnImpl(CompletionEvent* completion, | 110 void NotifyReadyToCommitOnImpl(CompletionEvent* completion, |
111 LayerTreeHost* layer_tree_host, | 111 LayerTreeHostInProcess* layer_tree_host, |
112 base::TimeTicks main_thread_start_time, | 112 base::TimeTicks main_thread_start_time, |
113 bool hold_commit_for_activation) override; | 113 bool hold_commit_for_activation) override; |
114 void SynchronouslyInitializeImpl( | 114 void SynchronouslyInitializeImpl( |
115 LayerTreeHost* layer_tree_host, | 115 LayerTreeHostInProcess* layer_tree_host, |
116 std::unique_ptr<BeginFrameSource> external_begin_frame_source) override; | 116 std::unique_ptr<BeginFrameSource> external_begin_frame_source) override; |
117 void SynchronouslyCloseImpl() override; | 117 void SynchronouslyCloseImpl() override; |
118 | 118 |
119 // ChannelImpl Implementation | 119 // ChannelImpl Implementation |
120 void DidCompleteSwapBuffers() override; | 120 void DidCompleteSwapBuffers() override; |
121 void BeginMainFrameNotExpectedSoon() override; | 121 void BeginMainFrameNotExpectedSoon() override; |
122 void DidCommitAndDrawFrame() override; | 122 void DidCommitAndDrawFrame() override; |
123 void SetAnimationEvents(std::unique_ptr<AnimationEvents> events) override; | 123 void SetAnimationEvents(std::unique_ptr<AnimationEvents> events) override; |
124 void DidLoseCompositorFrameSink() override; | 124 void DidLoseCompositorFrameSink() override; |
125 void RequestNewCompositorFrameSink() override; | 125 void RequestNewCompositorFrameSink() override; |
126 void DidInitializeCompositorFrameSink(bool success) override; | 126 void DidInitializeCompositorFrameSink(bool success) override; |
127 void DidCompletePageScaleAnimation() override; | 127 void DidCompletePageScaleAnimation() override; |
128 void BeginMainFrame(std::unique_ptr<BeginMainFrameAndCommitState> | 128 void BeginMainFrame(std::unique_ptr<BeginMainFrameAndCommitState> |
129 begin_main_frame_state) override; | 129 begin_main_frame_state) override; |
130 | 130 |
131 protected: | 131 protected: |
132 ThreadedChannel(ProxyMain* proxy_main, | 132 ThreadedChannel(ProxyMain* proxy_main, |
133 TaskRunnerProvider* task_runner_provider); | 133 TaskRunnerProvider* task_runner_provider); |
134 | 134 |
135 // Virtual for testing. | 135 // Virtual for testing. |
136 virtual std::unique_ptr<ProxyImpl> CreateProxyImpl( | 136 virtual std::unique_ptr<ProxyImpl> CreateProxyImpl( |
137 ChannelImpl* channel_impl, | 137 ChannelImpl* channel_impl, |
138 LayerTreeHost* layer_tree_host, | 138 LayerTreeHostInProcess* layer_tree_host, |
139 TaskRunnerProvider* task_runner_provider, | 139 TaskRunnerProvider* task_runner_provider, |
140 std::unique_ptr<BeginFrameSource> external_begin_frame_source); | 140 std::unique_ptr<BeginFrameSource> external_begin_frame_source); |
141 | 141 |
142 private: | 142 private: |
143 // The members of this struct should be accessed on the main thread only. | 143 // The members of this struct should be accessed on the main thread only. |
144 struct MainThreadOnly { | 144 struct MainThreadOnly { |
145 explicit MainThreadOnly(ProxyMain* proxy_main); | 145 explicit MainThreadOnly(ProxyMain* proxy_main); |
146 ~MainThreadOnly(); | 146 ~MainThreadOnly(); |
147 | 147 |
148 base::WeakPtrFactory<ProxyMain> proxy_main_weak_factory; | 148 base::WeakPtrFactory<ProxyMain> proxy_main_weak_factory; |
(...skipping 19 matching lines...) Expand all Loading... |
168 // thread. Since the weak pointer is invalidated after the impl-thread tear | 168 // thread. Since the weak pointer is invalidated after the impl-thread tear |
169 // down in SynchronouslyCloseImpl, this ensures that any tasks posted to | 169 // down in SynchronouslyCloseImpl, this ensures that any tasks posted to |
170 // ProxyMain from the impl thread are abandoned after the impl side has been | 170 // ProxyMain from the impl thread are abandoned after the impl side has been |
171 // destroyed. | 171 // destroyed. |
172 base::WeakPtr<ProxyMain> proxy_main_weak_ptr; | 172 base::WeakPtr<ProxyMain> proxy_main_weak_ptr; |
173 }; | 173 }; |
174 | 174 |
175 // Called on impl thread. | 175 // Called on impl thread. |
176 void InitializeImplOnImpl( | 176 void InitializeImplOnImpl( |
177 CompletionEvent* completion, | 177 CompletionEvent* completion, |
178 LayerTreeHost* layer_tree_host, | 178 LayerTreeHostInProcess* layer_tree_host, |
179 std::unique_ptr<BeginFrameSource> external_begin_frame_source); | 179 std::unique_ptr<BeginFrameSource> external_begin_frame_source); |
180 void CloseImplOnImpl(CompletionEvent* completion); | 180 void CloseImplOnImpl(CompletionEvent* completion); |
181 | 181 |
182 bool IsInitialized() const; | 182 bool IsInitialized() const; |
183 | 183 |
184 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; | 184 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; |
185 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; | 185 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; |
186 bool IsMainThread() const; | 186 bool IsMainThread() const; |
187 bool IsImplThread() const; | 187 bool IsImplThread() const; |
188 | 188 |
(...skipping 14 matching lines...) Expand all Loading... |
203 // Used on the main thread to safely queue calls to ProxyImpl to be run on the | 203 // Used on the main thread to safely queue calls to ProxyImpl to be run on the |
204 // impl thread. | 204 // impl thread. |
205 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; | 205 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; |
206 | 206 |
207 DISALLOW_COPY_AND_ASSIGN(ThreadedChannel); | 207 DISALLOW_COPY_AND_ASSIGN(ThreadedChannel); |
208 }; | 208 }; |
209 | 209 |
210 } // namespace cc | 210 } // namespace cc |
211 | 211 |
212 #endif // CC_TREES_THREADED_CHANNEL_H_ | 212 #endif // CC_TREES_THREADED_CHANNEL_H_ |
OLD | NEW |