Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
vmpstr
2016/01/11 21:50:15
2016
Khushal
2016/01/13 02:07:12
Done.
| |
| 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/trees/channel_impl.h" | |
| 13 #include "cc/trees/proxy.h" | |
| 14 #include "cc/trees/proxy_impl.h" | |
| 15 #include "cc/trees/remote_proto_channel.h" | |
| 16 | |
| 17 namespace cc { | |
| 18 class LayerTreeHost; | |
| 19 | |
| 20 namespace proto { | |
| 21 class CompositorMessage; | |
| 22 class CompositorMessageToImpl; | |
| 23 class CompositorMessageToMain; | |
| 24 } | |
| 25 | |
| 26 // The Proxy and ChannelImpl implementation for the remote compositor. | |
| 27 // The object life cycle and communication across threads is as follows: | |
| 28 // | |
| 29 // The RemoteChannelImpl is created by the remote client LayerTreeHost, which | |
| 30 // initializes the impl side of the compositor. | |
| 31 // | |
| 32 // Main Thread | Impl Thread | |
| 33 // | | |
| 34 // Proxy::Start | | |
| 35 // | | | |
| 36 // | RemoteChannelImpl | |
| 37 // --------------------------------------------------------------------------- | |
| 38 // RemoteChannelImpl::Start()---PostTask---> RemoteChannelImpl:: | |
| 39 // InitializeImplOnImpl | |
| 40 // | | |
| 41 // ProxyImpl::Create | |
| 42 // | | |
| 43 // . | |
| 44 // . | |
| 45 // ProxyImpl::ScheduledActionBegin | |
| 46 // OutputSurfaceCreation | |
| 47 // | | |
| 48 // ChannelImpl::RequestNewOutputSurface | |
| 49 // | | |
| 50 // RemoteChannelImpl:: | | |
| 51 // RequestNewOutputSurface()<----PostTask-------------- | |
| 52 // . | |
| 53 // . | |
| 54 // | | |
| 55 // RemoteChannelImpl:: | |
| 56 // ~RemoteChannelImpl() ---PostTask---> RemoteChannelImpl:: | |
| 57 // ShutdownImplOnImpl | |
| 58 // ---------------------------------------------------------------------------- | |
| 59 // | |
| 60 // The class is created and destroyed on the main thread but can be safely | |
| 61 // called from the main or impl thread. It is safe to call RemoteChannelImpl on | |
| 62 // the impl thread since: | |
| 63 // 1) The only impl threaded callers of RemoteChannelImpl is the | |
| 64 // RemoteChannelImpl itself and ProxyImpl which is created and owned by the | |
| 65 // RemoteChannelImpl. | |
| 66 // 2) The RemoteChannelImpl blocks the main thread in its dtor to wait for the | |
| 67 // impl-thread teardown to complete, which ensures that any tasks queued to call | |
| 68 // it on the impl thread are run before it is destroyed on the main thread. | |
|
vmpstr
2016/01/11 21:50:15
Can you also add a comment block about communicati
Khushal
2016/01/13 02:07:12
Done.
| |
| 69 | |
|
vmpstr
2016/01/11 21:50:15
nit: remove blank line
Khushal
2016/01/13 02:07:12
Done.
| |
| 70 class CC_EXPORT RemoteChannelImpl : public ChannelImpl, | |
| 71 public RemoteProtoChannel::ProtoReceiver, | |
| 72 public Proxy { | |
| 73 public: | |
| 74 static scoped_ptr<RemoteChannelImpl> Create( | |
| 75 LayerTreeHost* layer_tree_host, | |
| 76 RemoteProtoChannel* remote_proto_channel, | |
| 77 TaskRunnerProvider* task_runner_provider); | |
| 78 | |
| 79 ~RemoteChannelImpl() override; | |
| 80 | |
| 81 protected: | |
| 82 RemoteChannelImpl(LayerTreeHost* layer_tree_host, | |
| 83 RemoteProtoChannel* remote_proto_channel, | |
| 84 TaskRunnerProvider* task_runner_provider); | |
| 85 | |
| 86 // virtual for testing. | |
| 87 virtual scoped_ptr<ProxyImpl> CreateProxyImpl( | |
| 88 ChannelImpl* channel_impl, | |
| 89 LayerTreeHost* layer_tree_host, | |
| 90 TaskRunnerProvider* task_runner_provider, | |
| 91 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
| 92 | |
| 93 private: | |
| 94 struct MainThreadOnly { | |
| 95 LayerTreeHost* layer_tree_host; | |
| 96 RemoteProtoChannel* remote_proto_channel; | |
| 97 | |
| 98 bool started; | |
| 99 | |
| 100 RendererCapabilities renderer_capabilities; | |
| 101 | |
| 102 MainThreadOnly(LayerTreeHost* layer_tree_host, | |
| 103 RemoteProtoChannel* remote_proto_channel); | |
| 104 ~MainThreadOnly(); | |
| 105 }; | |
| 106 | |
| 107 struct CompositorThreadOnly { | |
| 108 scoped_ptr<ProxyImpl> proxy_impl; | |
| 109 scoped_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory; | |
| 110 | |
| 111 CompositorThreadOnly(); | |
| 112 ~CompositorThreadOnly(); | |
| 113 }; | |
| 114 | |
| 115 // called on main thread. | |
| 116 // RemoteProtoChannel::ProtoReceiver implementation. | |
| 117 void OnProtoReceived(scoped_ptr<proto::CompositorMessage> proto) override; | |
| 118 | |
| 119 // Proxy implementation | |
| 120 void FinishAllRendering() override; | |
| 121 bool IsStarted() const override; | |
| 122 bool CommitToActiveTree() const override; | |
| 123 void SetOutputSurface(OutputSurface* output_surface) override; | |
| 124 void ReleaseOutputSurface() override; | |
| 125 void SetVisible(bool visible) override; | |
| 126 void SetThrottleFrameProduction(bool throttle) override; | |
| 127 const RendererCapabilities& GetRendererCapabilities() const override; | |
| 128 void SetNeedsAnimate() override; | |
| 129 void SetNeedsUpdateLayers() override; | |
| 130 void SetNeedsCommit() override; | |
| 131 void SetNeedsRedraw(const gfx::Rect& damage_rect) override; | |
| 132 void SetNextCommitWaitsForActivation() override; | |
| 133 void NotifyInputThrottledUntilCommit() override; | |
| 134 void SetDeferCommits(bool defer_commits) override; | |
| 135 void MainThreadHasStoppedFlinging() override; | |
| 136 bool CommitRequested() const override; | |
| 137 bool BeginMainFrameRequested() const override; | |
| 138 void Start(scoped_ptr<BeginFrameSource> external_begin_frame_source) override; | |
| 139 void Stop() override; | |
| 140 bool SupportsImplScrolling() const override; | |
| 141 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override; | |
| 142 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override; | |
| 143 void UpdateTopControlsState(TopControlsState constraints, | |
| 144 TopControlsState current, | |
| 145 bool animate) override; | |
| 146 bool MainFrameWillHappenForTesting() override; | |
| 147 | |
| 148 // Called on impl thread. | |
| 149 // ChannelImpl implementation | |
| 150 void DidCompleteSwapBuffers() override; | |
| 151 void SetRendererCapabilitiesMainCopy( | |
| 152 const RendererCapabilities& capabilities) override; | |
| 153 void BeginMainFrameNotExpectedSoon() override; | |
| 154 void DidCommitAndDrawFrame() override; | |
| 155 void SetAnimationEvents(scoped_ptr<AnimationEventsVector> queue) override; | |
| 156 void DidLoseOutputSurface() override; | |
| 157 void RequestNewOutputSurface() override; | |
| 158 void DidInitializeOutputSurface( | |
| 159 bool success, | |
| 160 const RendererCapabilities& capabilities) override; | |
| 161 void DidCompletePageScaleAnimation() override; | |
| 162 void PostFrameTimingEventsOnMain( | |
| 163 scoped_ptr<FrameTimingTracker::CompositeTimingSet> composite_events, | |
| 164 scoped_ptr<FrameTimingTracker::MainFrameTimingSet> main_frame_events) | |
| 165 override; | |
| 166 void BeginMainFrame( | |
| 167 scoped_ptr<BeginMainFrameAndCommitState> begin_main_frame_state) override; | |
| 168 | |
| 169 void InitializeImplOnImpl(CompletionEvent* completion, | |
| 170 LayerTreeHost* layer_tree_host); | |
| 171 void ShutdownImplOnImpl(CompletionEvent* completion); | |
| 172 | |
| 173 MainThreadOnly& main(); | |
| 174 const MainThreadOnly& main() const; | |
| 175 CompositorThreadOnly& impl(); | |
| 176 const CompositorThreadOnly& impl() const; | |
| 177 | |
| 178 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; | |
| 179 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; | |
| 180 | |
| 181 // use accessors instead of these variables directly | |
| 182 MainThreadOnly main_thread_vars_unsafe_; | |
| 183 CompositorThreadOnly compositor_thread_vars_unsafe_; | |
| 184 | |
| 185 TaskRunnerProvider* task_runner_provider_; | |
| 186 | |
| 187 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; | |
| 188 | |
| 189 DISALLOW_COPY_AND_ASSIGN(RemoteChannelImpl); | |
| 190 }; | |
| 191 | |
| 192 } // namespace cc | |
| 193 | |
| 194 #endif // CC_TREES_REMOTE_CHANNEL_IMPL_H_ | |
| OLD | NEW |