Chromium Code Reviews| 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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | |
| 10 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 11 #include "cc/trees/channel_impl.h" | 12 #include "cc/trees/channel_impl.h" |
| 12 #include "cc/trees/channel_main.h" | 13 #include "cc/trees/channel_main.h" |
| 13 #include "cc/trees/proxy_common.h" | 14 #include "cc/trees/proxy_common.h" |
| 14 #include "cc/trees/proxy_impl.h" | 15 #include "cc/trees/proxy_impl.h" |
| 15 #include "cc/trees/proxy_main.h" | 16 #include "cc/trees/proxy_main.h" |
| 16 #include "cc/trees/thread_proxy.h" | |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 class ChannelImpl; | 23 class ChannelImpl; |
| 24 class ChannelMain; | 24 class ChannelMain; |
| 25 class LayerTreeHost; | |
| 25 class ProxyImpl; | 26 class ProxyImpl; |
| 26 class ProxyMain; | 27 class ProxyMain; |
| 27 class ThreadProxy; | |
| 28 | 28 |
| 29 // An implementation of ChannelMain and ChannelImpl that sends commands between | 29 // An implementation of ChannelMain and ChannelImpl that sends commands between |
| 30 // ProxyMain and ProxyImpl across thread boundaries. | 30 // ProxyMain and ProxyImpl across thread boundaries. |
| 31 // | 31 // |
| 32 // LayerTreeHost creates ThreadedChannel and passes the ownership to ProxyMain. | 32 // LayerTreeHost creates ThreadedChannel and passes the ownership to ProxyMain. |
| 33 // The object life cycle and communication across threads is as follows: | 33 // The object life cycle and communication across threads is as follows: |
| 34 // | 34 // |
| 35 // | 35 // |
| 36 // Main Thread | Impl Thread | 36 // Main Thread | Impl Thread |
| 37 // LayerTreeHost->InitializeProxy | | 37 // LayerTreeHost->InitializeProxy | |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 59 // ProxyMain->LayerTreeHostClosed | 59 // ProxyMain->LayerTreeHostClosed |
| 60 // | | 60 // | |
| 61 // --------------------------------------------------------------------------- | 61 // --------------------------------------------------------------------------- |
| 62 // ChannelMain::SetLayerTreeClosedOnImpl---PostTask---> ProxyImpl-> | 62 // ChannelMain::SetLayerTreeClosedOnImpl---PostTask---> ProxyImpl-> |
| 63 // SetLayerTreeClosed | 63 // SetLayerTreeClosed |
| 64 // ---------------------------------------------------------------------------- | 64 // ---------------------------------------------------------------------------- |
| 65 | 65 |
| 66 class CC_EXPORT ThreadedChannel : public ChannelMain, public ChannelImpl { | 66 class CC_EXPORT ThreadedChannel : public ChannelMain, public ChannelImpl { |
| 67 public: | 67 public: |
| 68 static scoped_ptr<ThreadedChannel> Create( | 68 static scoped_ptr<ThreadedChannel> Create( |
| 69 // TODO(khushalsagar): Make this ProxyMain* and write the initialization | 69 ProxyMain* proxy_main, |
| 70 // sequence. Currently ThreadProxy implements both so we pass the pointer | |
| 71 // and set ProxyImpl. | |
| 72 ThreadProxy* thread_proxy, | |
| 73 TaskRunnerProvider* task_runner_provider); | 70 TaskRunnerProvider* task_runner_provider); |
| 74 | 71 |
| 75 ~ThreadedChannel() override; | 72 ~ThreadedChannel() override; |
| 76 | 73 |
| 74 // The members of this struct should be accessed on the main thread only. | |
| 75 struct MainThreadOnly { | |
| 76 base::WeakPtrFactory<ProxyMain> proxy_main_weak_factory; | |
| 77 bool initialized; | |
| 78 | |
| 79 explicit MainThreadOnly(ProxyMain* proxy_main); | |
| 80 ~MainThreadOnly(); | |
| 81 }; | |
| 82 | |
| 83 // The members of this struct should be accessed on the impl thread only. | |
| 84 struct CompositorThreadOnly { | |
| 85 scoped_ptr<ProxyImpl> proxy_impl; | |
| 86 scoped_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory; | |
| 87 | |
| 88 CompositorThreadOnly(); | |
| 89 ~CompositorThreadOnly(); | |
| 90 }; | |
| 91 | |
| 77 // ChannelMain Implementation | 92 // ChannelMain Implementation |
| 78 void SetThrottleFrameProductionOnImpl(bool throttle) override; | 93 void SetThrottleFrameProductionOnImpl(bool throttle) override; |
| 79 void UpdateTopControlsStateOnImpl(TopControlsState constraints, | 94 void UpdateTopControlsStateOnImpl(TopControlsState constraints, |
| 80 TopControlsState current, | 95 TopControlsState current, |
| 81 bool animate) override; | 96 bool animate) override; |
| 82 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override; | 97 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override; |
| 83 void MainThreadHasStoppedFlingingOnImpl() override; | 98 void MainThreadHasStoppedFlingingOnImpl() override; |
| 84 void SetInputThrottledUntilCommitOnImpl(bool is_throttled) override; | 99 void SetInputThrottledUntilCommitOnImpl(bool is_throttled) override; |
| 85 void SetDeferCommitsOnImpl(bool defer_commits) override; | 100 void SetDeferCommitsOnImpl(bool defer_commits) override; |
| 86 void SetNeedsCommitOnImpl() override; | 101 void SetNeedsCommitOnImpl() override; |
| 87 void BeginMainFrameAbortedOnImpl( | 102 void BeginMainFrameAbortedOnImpl( |
| 88 CommitEarlyOutReason reason, | 103 CommitEarlyOutReason reason, |
| 89 base::TimeTicks main_thread_start_time) override; | 104 base::TimeTicks main_thread_start_time) override; |
| 90 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override; | 105 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override; |
| 91 void SetVisibleOnImpl(bool visible) override; | 106 void SetVisibleOnImpl(bool visible) override; |
| 92 | 107 |
| 93 // Blocking calls to ProxyImpl | 108 // Blocking calls to ProxyImpl |
| 94 void FinishAllRenderingOnImpl(CompletionEvent* completion) override; | 109 void FinishAllRenderingOnImpl(CompletionEvent* completion) override; |
| 95 void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) override; | 110 void ReleaseOutputSurfaceOnImpl(CompletionEvent* completion) override; |
| 96 void FinishGLOnImpl(CompletionEvent* completion) override; | |
| 97 void MainFrameWillHappenOnImplForTesting( | 111 void MainFrameWillHappenOnImplForTesting( |
| 98 CompletionEvent* completion, | 112 CompletionEvent* completion, |
| 99 bool* main_frame_will_happen) override; | 113 bool* main_frame_will_happen) override; |
| 100 void StartCommitOnImpl(CompletionEvent* completion, | 114 void StartCommitOnImpl(CompletionEvent* completion, |
| 101 LayerTreeHost* layer_tree_host, | 115 LayerTreeHost* layer_tree_host, |
| 102 base::TimeTicks main_thread_start_time, | 116 base::TimeTicks main_thread_start_time, |
| 103 bool hold_commit_for_activation) override; | 117 bool hold_commit_for_activation) override; |
| 104 void InitializeImplOnImpl(CompletionEvent* completion, | 118 void SynchronouslyInitializeImpl( |
| 105 LayerTreeHost* layer_tree_host) override; | 119 LayerTreeHost* layer_tree_host, |
| 106 void LayerTreeHostClosedOnImpl(CompletionEvent* completion) override; | 120 scoped_ptr<BeginFrameSource> external_begin_frame_source) override; |
| 121 void SynchronouslyCloseImpl() override; | |
| 107 | 122 |
| 108 // ChannelImpl Implementation | 123 // ChannelImpl Implementation |
| 109 void DidCompleteSwapBuffers() override; | 124 void DidCompleteSwapBuffers() override; |
| 110 void SetRendererCapabilitiesMainCopy( | 125 void SetRendererCapabilitiesMainCopy( |
| 111 const RendererCapabilities& capabilities) override; | 126 const RendererCapabilities& capabilities) override; |
| 112 void BeginMainFrameNotExpectedSoon() override; | 127 void BeginMainFrameNotExpectedSoon() override; |
| 113 void DidCommitAndDrawFrame() override; | 128 void DidCommitAndDrawFrame() override; |
| 114 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override; | 129 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override; |
| 115 void DidLoseOutputSurface() override; | 130 void DidLoseOutputSurface() override; |
| 116 void RequestNewOutputSurface() override; | 131 void RequestNewOutputSurface() override; |
| 117 void DidInitializeOutputSurface( | 132 void DidInitializeOutputSurface( |
| 118 bool success, | 133 bool success, |
| 119 const RendererCapabilities& capabilities) override; | 134 const RendererCapabilities& capabilities) override; |
| 120 void DidCompletePageScaleAnimation() override; | 135 void DidCompletePageScaleAnimation() override; |
| 121 void PostFrameTimingEventsOnMain( | 136 void PostFrameTimingEventsOnMain( |
| 122 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | 137 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, |
| 123 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) | 138 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) |
| 124 override; | 139 override; |
| 125 void BeginMainFrame( | 140 void BeginMainFrame( |
| 126 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override; | 141 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override; |
| 127 | 142 |
| 143 // Should be called on impl thread only. | |
| 144 ProxyImpl* GetProxyImplForTesting() const; | |
| 145 | |
| 128 protected: | 146 protected: |
| 129 ThreadedChannel(ThreadProxy* thread_proxy, | 147 ThreadedChannel(ProxyMain* proxy_main, |
| 130 TaskRunnerProvider* task_runner_provider); | 148 TaskRunnerProvider* task_runner_provider); |
| 131 | 149 |
| 150 // virtual for testing. | |
| 151 virtual scoped_ptr<ProxyImpl> CreateProxyImpl( | |
| 152 ChannelImpl* channel_impl, | |
| 153 LayerTreeHost* layer_tree_host, | |
| 154 TaskRunnerProvider* task_runner_provider, | |
| 155 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
| 156 | |
| 132 private: | 157 private: |
| 158 // called on impl thread. | |
| 159 void InitializeImplOnImplThread( | |
|
Wez
2015/11/21 01:00:30
I thought we had agreed to break ThreadedChannel i
Khushal
2015/11/23 20:07:20
For this patch, It would make sense to keep the sp
| |
| 160 CompletionEvent* completion, | |
| 161 LayerTreeHost* layer_tree_host, | |
| 162 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
| 163 void CloseImplOnImplThread(CompletionEvent* completion); | |
| 164 | |
| 165 bool IsInitialized() const; | |
| 166 | |
| 133 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; | 167 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; |
| 134 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; | 168 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; |
| 135 | 169 |
| 136 ProxyMain* proxy_main_; | 170 // Use accessors instead of this variable directly. |
| 171 MainThreadOnly main_thread_only_vars_unsafe_; | |
| 172 MainThreadOnly& main(); | |
| 173 const MainThreadOnly& main() const; | |
| 137 | 174 |
| 138 ProxyImpl* proxy_impl_; | 175 // Use accessors instead of this variable directly. |
| 176 CompositorThreadOnly compositor_thread_vars_unsafe_; | |
| 177 CompositorThreadOnly& impl(); | |
| 178 const CompositorThreadOnly& impl() const; | |
| 139 | 179 |
| 140 TaskRunnerProvider* task_runner_provider_; | 180 TaskRunnerProvider* task_runner_provider_; |
| 141 | 181 |
| 142 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 182 base::WeakPtr<ProxyMain> proxy_main_weak_ptr_; |
| 143 | 183 |
| 144 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_; | 184 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; |
| 145 | 185 |
| 146 DISALLOW_COPY_AND_ASSIGN(ThreadedChannel); | 186 DISALLOW_COPY_AND_ASSIGN(ThreadedChannel); |
| 147 }; | 187 }; |
| 148 | 188 |
| 149 } // namespace cc | 189 } // namespace cc |
| 150 | 190 |
| 151 #endif // CC_TREES_THREADED_CHANNEL_H_ | 191 #endif // CC_TREES_THREADED_CHANNEL_H_ |
| OLD | NEW |