| 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> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "cc/base/cc_export.h" | 13 #include "cc/base/cc_export.h" |
| 13 #include "cc/trees/channel_impl.h" | 14 #include "cc/trees/channel_impl.h" |
| 14 #include "cc/trees/channel_main.h" | 15 #include "cc/trees/channel_main.h" |
| 15 #include "cc/trees/proxy_common.h" | 16 #include "cc/trees/proxy_common.h" |
| 16 #include "cc/trees/proxy_impl.h" | 17 #include "cc/trees/proxy_impl.h" |
| 17 #include "cc/trees/proxy_main.h" | 18 #include "cc/trees/proxy_main.h" |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // called on the impl thread because: | 70 // called on the impl thread because: |
| 70 // 1) The only impl-threaded callers of ThreadedChannel are the ThreadedChannel | 71 // 1) The only impl-threaded callers of ThreadedChannel are the ThreadedChannel |
| 71 // itself and ProxyImpl which is created and owned by the ThreadedChannel. | 72 // itself and ProxyImpl which is created and owned by the ThreadedChannel. |
| 72 // 2) ThreadedChannel blocks the main thread in | 73 // 2) ThreadedChannel blocks the main thread in |
| 73 // ThreadedChannel::SynchronouslyCloseImpl to wait for the impl-thread teardown | 74 // ThreadedChannel::SynchronouslyCloseImpl to wait for the impl-thread teardown |
| 74 // to complete, so there is no risk of any queued tasks calling it on the impl | 75 // to complete, so there is no risk of any queued tasks calling it on the impl |
| 75 // thread after it has been deleted on the main thread. | 76 // thread after it has been deleted on the main thread. |
| 76 | 77 |
| 77 class CC_EXPORT ThreadedChannel : public ChannelMain, public ChannelImpl { | 78 class CC_EXPORT ThreadedChannel : public ChannelMain, public ChannelImpl { |
| 78 public: | 79 public: |
| 79 static scoped_ptr<ThreadedChannel> Create( | 80 static std::unique_ptr<ThreadedChannel> Create( |
| 80 ProxyMain* proxy_main, | 81 ProxyMain* proxy_main, |
| 81 TaskRunnerProvider* task_runner_provider); | 82 TaskRunnerProvider* task_runner_provider); |
| 82 | 83 |
| 83 ~ThreadedChannel() override; | 84 ~ThreadedChannel() override; |
| 84 | 85 |
| 85 // ChannelMain Implementation | 86 // ChannelMain Implementation |
| 86 void UpdateTopControlsStateOnImpl(TopControlsState constraints, | 87 void UpdateTopControlsStateOnImpl(TopControlsState constraints, |
| 87 TopControlsState current, | 88 TopControlsState current, |
| 88 bool animate) override; | 89 bool animate) override; |
| 89 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override; | 90 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) override; | 103 void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) override; |
| 103 void MainFrameWillHappenOnImplForTesting( | 104 void MainFrameWillHappenOnImplForTesting( |
| 104 CompletionEvent* completion, | 105 CompletionEvent* completion, |
| 105 bool* main_frame_will_happen) override; | 106 bool* main_frame_will_happen) override; |
| 106 void StartCommitOnImpl(CompletionEvent* completion, | 107 void StartCommitOnImpl(CompletionEvent* completion, |
| 107 LayerTreeHost* layer_tree_host, | 108 LayerTreeHost* layer_tree_host, |
| 108 base::TimeTicks main_thread_start_time, | 109 base::TimeTicks main_thread_start_time, |
| 109 bool hold_commit_for_activation) override; | 110 bool hold_commit_for_activation) override; |
| 110 void SynchronouslyInitializeImpl( | 111 void SynchronouslyInitializeImpl( |
| 111 LayerTreeHost* layer_tree_host, | 112 LayerTreeHost* layer_tree_host, |
| 112 scoped_ptr<BeginFrameSource> external_begin_frame_source) override; | 113 std::unique_ptr<BeginFrameSource> external_begin_frame_source) override; |
| 113 void SynchronouslyCloseImpl() override; | 114 void SynchronouslyCloseImpl() override; |
| 114 | 115 |
| 115 // ChannelImpl Implementation | 116 // ChannelImpl Implementation |
| 116 void DidCompleteSwapBuffers() override; | 117 void DidCompleteSwapBuffers() override; |
| 117 void SetRendererCapabilitiesMainCopy( | 118 void SetRendererCapabilitiesMainCopy( |
| 118 const RendererCapabilities& capabilities) override; | 119 const RendererCapabilities& capabilities) override; |
| 119 void BeginMainFrameNotExpectedSoon() override; | 120 void BeginMainFrameNotExpectedSoon() override; |
| 120 void DidCommitAndDrawFrame() override; | 121 void DidCommitAndDrawFrame() override; |
| 121 void SetAnimationEvents(scoped_ptr<AnimationEvents> events) override; | 122 void SetAnimationEvents(std::unique_ptr<AnimationEvents> events) override; |
| 122 void DidLoseOutputSurface() override; | 123 void DidLoseOutputSurface() override; |
| 123 void RequestNewOutputSurface() override; | 124 void RequestNewOutputSurface() override; |
| 124 void DidInitializeOutputSurface( | 125 void DidInitializeOutputSurface( |
| 125 bool success, | 126 bool success, |
| 126 const RendererCapabilities& capabilities) override; | 127 const RendererCapabilities& capabilities) override; |
| 127 void DidCompletePageScaleAnimation() override; | 128 void DidCompletePageScaleAnimation() override; |
| 128 void PostFrameTimingEventsOnMain( | 129 void PostFrameTimingEventsOnMain( |
| 129 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 130 std::unique_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 130 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) | 131 std::unique_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) |
| 131 override; | 132 override; |
| 132 void BeginMainFrame( | 133 void BeginMainFrame(std::unique_ptr<BeginMainFrameAndCommitState> |
| 133 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override; | 134 begin_main_frame_state) override; |
| 134 | 135 |
| 135 protected: | 136 protected: |
| 136 ThreadedChannel(ProxyMain* proxy_main, | 137 ThreadedChannel(ProxyMain* proxy_main, |
| 137 TaskRunnerProvider* task_runner_provider); | 138 TaskRunnerProvider* task_runner_provider); |
| 138 | 139 |
| 139 // Virtual for testing. | 140 // Virtual for testing. |
| 140 virtual scoped_ptr<ProxyImpl> CreateProxyImpl( | 141 virtual std::unique_ptr<ProxyImpl> CreateProxyImpl( |
| 141 ChannelImpl* channel_impl, | 142 ChannelImpl* channel_impl, |
| 142 LayerTreeHost* layer_tree_host, | 143 LayerTreeHost* layer_tree_host, |
| 143 TaskRunnerProvider* task_runner_provider, | 144 TaskRunnerProvider* task_runner_provider, |
| 144 scoped_ptr<BeginFrameSource> external_begin_frame_source); | 145 std::unique_ptr<BeginFrameSource> external_begin_frame_source); |
| 145 | 146 |
| 146 private: | 147 private: |
| 147 // The members of this struct should be accessed on the main thread only. | 148 // The members of this struct should be accessed on the main thread only. |
| 148 struct MainThreadOnly { | 149 struct MainThreadOnly { |
| 149 explicit MainThreadOnly(ProxyMain* proxy_main); | 150 explicit MainThreadOnly(ProxyMain* proxy_main); |
| 150 ~MainThreadOnly(); | 151 ~MainThreadOnly(); |
| 151 | 152 |
| 152 base::WeakPtrFactory<ProxyMain> proxy_main_weak_factory; | 153 base::WeakPtrFactory<ProxyMain> proxy_main_weak_factory; |
| 153 bool initialized; | 154 bool initialized; |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 // The members of this struct should be accessed on the impl thread only. | 157 // The members of this struct should be accessed on the impl thread only. |
| 157 struct CompositorThreadOnly { | 158 struct CompositorThreadOnly { |
| 158 explicit CompositorThreadOnly(base::WeakPtr<ProxyMain> proxy_main_weak_ptr); | 159 explicit CompositorThreadOnly(base::WeakPtr<ProxyMain> proxy_main_weak_ptr); |
| 159 ~CompositorThreadOnly(); | 160 ~CompositorThreadOnly(); |
| 160 | 161 |
| 161 scoped_ptr<ProxyImpl> proxy_impl; | 162 std::unique_ptr<ProxyImpl> proxy_impl; |
| 162 | 163 |
| 163 // We use a scoped_ptr for the weak ptr factory here since the factory is | 164 // We use a unique_ptr for the weak ptr factory here since the factory is |
| 164 // created after ProxyImpl is created in InitializeImplOnImpl. Since the | 165 // created after ProxyImpl is created in InitializeImplOnImpl. Since the |
| 165 // weak ptrs are needed only by the ThreadedChannel to safely post tasks on | 166 // weak ptrs are needed only by the ThreadedChannel to safely post tasks on |
| 166 // ProxyImpl to be run on the impl thread, we avoid creating it in ProxyImpl | 167 // ProxyImpl to be run on the impl thread, we avoid creating it in ProxyImpl |
| 167 // and ensure that it is destroyed before ProxyImpl during the impl-thread | 168 // and ensure that it is destroyed before ProxyImpl during the impl-thread |
| 168 // tear down in CloseImplOnImpl. | 169 // tear down in CloseImplOnImpl. |
| 169 scoped_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory; | 170 std::unique_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory; |
| 170 | 171 |
| 171 // Used on the impl thread to queue calls to ProxyMain to be run on the main | 172 // Used on the impl thread to queue calls to ProxyMain to be run on the main |
| 172 // thread. Since the weak pointer is invalidated after the impl-thread tear | 173 // thread. Since the weak pointer is invalidated after the impl-thread tear |
| 173 // down in SynchronouslyCloseImpl, this ensures that any tasks posted to | 174 // down in SynchronouslyCloseImpl, this ensures that any tasks posted to |
| 174 // ProxyMain from the impl thread are abandoned after the impl side has been | 175 // ProxyMain from the impl thread are abandoned after the impl side has been |
| 175 // destroyed. | 176 // destroyed. |
| 176 base::WeakPtr<ProxyMain> proxy_main_weak_ptr; | 177 base::WeakPtr<ProxyMain> proxy_main_weak_ptr; |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 // Called on impl thread. | 180 // Called on impl thread. |
| 180 void InitializeImplOnImpl( | 181 void InitializeImplOnImpl( |
| 181 CompletionEvent* completion, | 182 CompletionEvent* completion, |
| 182 LayerTreeHost* layer_tree_host, | 183 LayerTreeHost* layer_tree_host, |
| 183 scoped_ptr<BeginFrameSource> external_begin_frame_source); | 184 std::unique_ptr<BeginFrameSource> external_begin_frame_source); |
| 184 void CloseImplOnImpl(CompletionEvent* completion); | 185 void CloseImplOnImpl(CompletionEvent* completion); |
| 185 | 186 |
| 186 bool IsInitialized() const; | 187 bool IsInitialized() const; |
| 187 | 188 |
| 188 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; | 189 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; |
| 189 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; | 190 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; |
| 190 bool IsMainThread() const; | 191 bool IsMainThread() const; |
| 191 bool IsImplThread() const; | 192 bool IsImplThread() const; |
| 192 | 193 |
| 193 TaskRunnerProvider* task_runner_provider_; | 194 TaskRunnerProvider* task_runner_provider_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 207 // Used on the main thread to safely queue calls to ProxyImpl to be run on the | 208 // Used on the main thread to safely queue calls to ProxyImpl to be run on the |
| 208 // impl thread. | 209 // impl thread. |
| 209 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; | 210 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; |
| 210 | 211 |
| 211 DISALLOW_COPY_AND_ASSIGN(ThreadedChannel); | 212 DISALLOW_COPY_AND_ASSIGN(ThreadedChannel); |
| 212 }; | 213 }; |
| 213 | 214 |
| 214 } // namespace cc | 215 } // namespace cc |
| 215 | 216 |
| 216 #endif // CC_TREES_THREADED_CHANNEL_H_ | 217 #endif // CC_TREES_THREADED_CHANNEL_H_ |
| OLD | NEW |