Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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/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. | |
| 69 // | |
| 70 // The RemoteChannelImpl receives and processes messages from the remote server | |
| 71 // compositor on the main thread. The requests from ProxyImpl are received on | |
| 72 // the impl thread which may be directed to the LayerTreeHost on the client | |
| 73 // (for instance output surface requests) or sent to the LayerTreeHost on the | |
| 74 // server. The messages to the server are created on the impl thread and sent | |
| 75 // using the RemoteProtoChannel on the main thread. | |
| 76 class CC_EXPORT RemoteChannelImpl : public ChannelImpl, | |
| 77 public RemoteProtoChannel::ProtoReceiver, | |
| 78 public Proxy { | |
| 79 public: | |
| 80 static scoped_ptr<RemoteChannelImpl> Create( | |
| 81 LayerTreeHost* layer_tree_host, | |
| 82 RemoteProtoChannel* remote_proto_channel, | |
| 83 TaskRunnerProvider* task_runner_provider); | |
| 84 | |
| 85 ~RemoteChannelImpl() override; | |
| 86 | |
| 87 protected: | |
| 88 RemoteChannelImpl(LayerTreeHost* layer_tree_host, | |
| 89 RemoteProtoChannel* remote_proto_channel, | |
| 90 TaskRunnerProvider* task_runner_provider); | |
| 91 | |
| 92 // virtual for testing. | |
| 93 virtual scoped_ptr<ProxyImpl> CreateProxyImpl( | |
| 94 ChannelImpl* channel_impl, | |
| 95 LayerTreeHost* layer_tree_host, | |
| 96 TaskRunnerProvider* task_runner_provider, | |
| 97 scoped_ptr<BeginFrameSource> external_begin_frame_source); | |
| 98 | |
| 99 private: | |
| 100 struct MainThreadOnly { | |
| 101 LayerTreeHost* layer_tree_host; | |
| 102 RemoteProtoChannel* remote_proto_channel; | |
| 103 | |
| 104 bool started; | |
| 105 | |
| 106 RendererCapabilities renderer_capabilities; | |
| 107 | |
| 108 MainThreadOnly(LayerTreeHost* layer_tree_host, | |
| 109 RemoteProtoChannel* remote_proto_channel); | |
| 110 ~MainThreadOnly(); | |
| 111 }; | |
| 112 | |
| 113 struct CompositorThreadOnly { | |
| 114 scoped_ptr<ProxyImpl> proxy_impl; | |
| 115 scoped_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory; | |
| 116 | |
| 117 CompositorThreadOnly(); | |
| 118 ~CompositorThreadOnly(); | |
| 119 }; | |
| 120 | |
| 121 // called on main thread. | |
| 122 // RemoteProtoChannel::ProtoReceiver implementation. | |
| 123 void OnProtoReceived(scoped_ptr<proto::CompositorMessage> proto) override; | |
| 124 | |
| 125 // Proxy implementation | |
| 126 void FinishAllRendering() override; | |
| 127 bool IsStarted() const override; | |
| 128 bool CommitToActiveTree() const override; | |
| 129 void SetOutputSurface(OutputSurface* output_surface) override; | |
| 130 void ReleaseOutputSurface() override; | |
| 131 void SetVisible(bool visible) override; | |
| 132 void SetThrottleFrameProduction(bool throttle) override; | |
| 133 const RendererCapabilities& GetRendererCapabilities() const override; | |
| 134 void SetNeedsAnimate() override; | |
| 135 void SetNeedsUpdateLayers() override; | |
| 136 void SetNeedsCommit() override; | |
| 137 void SetNeedsRedraw(const gfx::Rect& damage_rect) override; | |
| 138 void SetNextCommitWaitsForActivation() override; | |
| 139 void NotifyInputThrottledUntilCommit() override; | |
| 140 void SetDeferCommits(bool defer_commits) override; | |
| 141 void MainThreadHasStoppedFlinging() override; | |
| 142 bool CommitRequested() const override; | |
| 143 bool BeginMainFrameRequested() const override; | |
| 144 void Start(scoped_ptr<BeginFrameSource> external_begin_frame_source) override; | |
| 145 void Stop() override; | |
| 146 bool SupportsImplScrolling() const override; | |
| 147 void SetChildrenNeedBeginFrames(bool children_need_begin_frames) override; | |
| 148 void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval) override; | |
| 149 void UpdateTopControlsState(TopControlsState constraints, | |
| 150 TopControlsState current, | |
| 151 bool animate) override; | |
| 152 bool MainFrameWillHappenForTesting() override; | |
| 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 // called on main thread. | |
|
ericrk
2016/01/20 22:32:29
why not move these up to the other "called on main
Khushal
2016/01/22 01:03:24
I was trying to write the interface implementation
ericrk
2016/01/22 18:36:59
hmm... yeah, that is the style, I guess we don't r
| |
| 176 void HandleProto(const proto::CompositorMessageToImpl& proto); | |
| 177 | |
| 178 void InitializeImplOnImpl(CompletionEvent* completion, | |
| 179 LayerTreeHost* layer_tree_host); | |
| 180 void ShutdownImplOnImpl(CompletionEvent* completion); | |
| 181 | |
| 182 MainThreadOnly& main(); | |
| 183 const MainThreadOnly& main() const; | |
| 184 CompositorThreadOnly& impl(); | |
| 185 const CompositorThreadOnly& impl() const; | |
| 186 | |
| 187 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; | |
| 188 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; | |
| 189 | |
| 190 // use accessors instead of these variables directly | |
| 191 MainThreadOnly main_thread_vars_unsafe_; | |
| 192 CompositorThreadOnly compositor_thread_vars_unsafe_; | |
| 193 | |
| 194 TaskRunnerProvider* task_runner_provider_; | |
| 195 | |
| 196 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; | |
| 197 | |
| 198 DISALLOW_COPY_AND_ASSIGN(RemoteChannelImpl); | |
| 199 }; | |
| 200 | |
| 201 } // namespace cc | |
| 202 | |
| 203 #endif // CC_TREES_REMOTE_CHANNEL_IMPL_H_ | |
| OLD | NEW |