| 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 <queue> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "cc/base/cc_export.h" | |
| 13 #include "cc/base/completion_event.h" | |
| 14 #include "cc/proto/compositor_message_to_impl.pb.h" | |
| 15 #include "cc/trees/channel_impl.h" | |
| 16 #include "cc/trees/proxy.h" | |
| 17 #include "cc/trees/proxy_impl.h" | |
| 18 #include "cc/trees/remote_proto_channel.h" | |
| 19 | |
| 20 namespace cc { | |
| 21 class LayerTreeHostInProcess; | |
| 22 | |
| 23 namespace proto { | |
| 24 class CompositorMessage; | |
| 25 class CompositorMessageToImpl; | |
| 26 class CompositorMessageToMain; | |
| 27 } | |
| 28 | |
| 29 // The Proxy and ChannelImpl implementation for the remote compositor. | |
| 30 // The object life cycle and communication across threads is as follows: | |
| 31 // | |
| 32 // The RemoteChannelImpl is created by the remote client LayerTreeHost, which | |
| 33 // initializes the impl side of the compositor. | |
| 34 // | |
| 35 // Main Thread | Impl Thread | |
| 36 // | | |
| 37 // Proxy::Start | | |
| 38 // | | | |
| 39 // | RemoteChannelImpl | |
| 40 // --------------------------------------------------------------------------- | |
| 41 // RemoteChannelImpl::Start()---PostTask---> RemoteChannelImpl:: | |
| 42 // InitializeImplOnImpl | |
| 43 // | | |
| 44 // ProxyImpl::Create | |
| 45 // | | |
| 46 // . | |
| 47 // . | |
| 48 // ProxyImpl::ScheduledActionBegin | |
| 49 // CompositorFrameSinkCreation | |
| 50 // | | |
| 51 // ChannelImpl::RequestNewCompositorFrameSink | |
| 52 // | | |
| 53 // RemoteChannelImpl:: | | |
| 54 // RequestNewCompositorFrameSink()<----PostTask-------------- | |
| 55 // . | |
| 56 // . | |
| 57 // | | |
| 58 // RemoteChannelImpl:: | |
| 59 // ~RemoteChannelImpl() ---PostTask---> RemoteChannelImpl:: | |
| 60 // ShutdownImplOnImpl | |
| 61 // ---------------------------------------------------------------------------- | |
| 62 // | |
| 63 // The class is created and destroyed on the main thread but can be safely | |
| 64 // called from the main or impl thread. It is safe to call RemoteChannelImpl on | |
| 65 // the impl thread since: | |
| 66 // 1) The only impl threaded callers of RemoteChannelImpl is the | |
| 67 // RemoteChannelImpl itself and ProxyImpl which is created and owned by the | |
| 68 // RemoteChannelImpl. | |
| 69 // 2) The RemoteChannelImpl blocks the main thread in its dtor to wait for the | |
| 70 // impl-thread teardown to complete, which ensures that any tasks queued to call | |
| 71 // it on the impl thread are run before it is destroyed on the main thread. | |
| 72 // | |
| 73 // The RemoteChannelImpl receives and processes messages from the remote server | |
| 74 // compositor on the main thread. The requests from ProxyImpl are received on | |
| 75 // the impl thread which may be directed to the LayerTreeHostInProcesson the | |
| 76 // client (for instance output surface requests) or sent to the | |
| 77 // LayerTreeHostInProcess on the server. The messages to the server are created | |
| 78 // on the impl thread and sent using the RemoteProtoChannel on the main thread. | |
| 79 class CC_EXPORT RemoteChannelImpl : public ChannelImpl, | |
| 80 public RemoteProtoChannel::ProtoReceiver, | |
| 81 public Proxy { | |
| 82 public: | |
| 83 RemoteChannelImpl(LayerTreeHostInProcess* layer_tree_host, | |
| 84 RemoteProtoChannel* remote_proto_channel, | |
| 85 TaskRunnerProvider* task_runner_provider); | |
| 86 ~RemoteChannelImpl() override; | |
| 87 | |
| 88 // virtual for testing. | |
| 89 virtual std::unique_ptr<ProxyImpl> CreateProxyImpl( | |
| 90 ChannelImpl* channel_impl, | |
| 91 LayerTreeHostInProcess* layer_tree_host, | |
| 92 TaskRunnerProvider* task_runner_provider); | |
| 93 | |
| 94 private: | |
| 95 struct MainThreadOnly { | |
| 96 LayerTreeHostInProcess* layer_tree_host; | |
| 97 RemoteProtoChannel* remote_proto_channel; | |
| 98 | |
| 99 bool started; | |
| 100 | |
| 101 // This is set to true if we lost the output surface and can not push any | |
| 102 // commits to the impl thread. | |
| 103 bool waiting_for_compositor_frame_sink_initialization; | |
| 104 | |
| 105 // The queue of messages received from the server. The messages are added to | |
| 106 // this queue if we are waiting for a new output surface to be initialized. | |
| 107 std::queue<proto::CompositorMessageToImpl> pending_messages; | |
| 108 | |
| 109 base::WeakPtrFactory<RemoteChannelImpl> remote_channel_weak_factory; | |
| 110 | |
| 111 MainThreadOnly(RemoteChannelImpl*, | |
| 112 LayerTreeHostInProcess* layer_tree_host, | |
| 113 RemoteProtoChannel* remote_proto_channel); | |
| 114 ~MainThreadOnly(); | |
| 115 }; | |
| 116 | |
| 117 struct CompositorThreadOnly { | |
| 118 std::unique_ptr<ProxyImpl> proxy_impl; | |
| 119 std::unique_ptr<base::WeakPtrFactory<ProxyImpl>> proxy_impl_weak_factory; | |
| 120 base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr; | |
| 121 | |
| 122 CompositorThreadOnly( | |
| 123 base::WeakPtr<RemoteChannelImpl> remote_channel_weak_ptr); | |
| 124 ~CompositorThreadOnly(); | |
| 125 }; | |
| 126 | |
| 127 // called on main thread. | |
| 128 // RemoteProtoChannel::ProtoReceiver implementation. | |
| 129 void OnProtoReceived( | |
| 130 std::unique_ptr<proto::CompositorMessage> proto) override; | |
| 131 | |
| 132 // Proxy implementation | |
| 133 bool IsStarted() const override; | |
| 134 bool CommitToActiveTree() const override; | |
| 135 void SetCompositorFrameSink( | |
| 136 CompositorFrameSink* compositor_frame_sink) override; | |
| 137 void ReleaseCompositorFrameSink() override; | |
| 138 void SetVisible(bool visible) override; | |
| 139 void SetNeedsAnimate() override; | |
| 140 void SetNeedsUpdateLayers() override; | |
| 141 void SetNeedsCommit() override; | |
| 142 void SetNeedsRedraw(const gfx::Rect& damage_rect) override; | |
| 143 void SetNextCommitWaitsForActivation() override; | |
| 144 void NotifyInputThrottledUntilCommit() override; | |
| 145 void SetDeferCommits(bool defer_commits) override; | |
| 146 void MainThreadHasStoppedFlinging() override; | |
| 147 bool CommitRequested() const override; | |
| 148 bool BeginMainFrameRequested() const override; | |
| 149 void Start() override; | |
| 150 void Stop() override; | |
| 151 void SetMutator(std::unique_ptr<LayerTreeMutator> mutator) override; | |
| 152 bool SupportsImplScrolling() const override; | |
| 153 void UpdateBrowserControlsState(BrowserControlsState constraints, | |
| 154 BrowserControlsState current, | |
| 155 bool animate) override; | |
| 156 bool MainFrameWillHappenForTesting() override; | |
| 157 | |
| 158 // Called on impl thread. | |
| 159 // ChannelImpl implementation | |
| 160 void DidReceiveCompositorFrameAck() override; | |
| 161 void BeginMainFrameNotExpectedSoon() override; | |
| 162 void DidCommitAndDrawFrame() override; | |
| 163 void SetAnimationEvents(std::unique_ptr<MutatorEvents> queue) override; | |
| 164 void DidLoseCompositorFrameSink() override; | |
| 165 void RequestNewCompositorFrameSink() override; | |
| 166 void DidInitializeCompositorFrameSink(bool success) override; | |
| 167 void DidCompletePageScaleAnimation() override; | |
| 168 void BeginMainFrame(std::unique_ptr<BeginMainFrameAndCommitState> | |
| 169 begin_main_frame_state) override; | |
| 170 | |
| 171 void SendMessageProto(std::unique_ptr<proto::CompositorMessage> proto); | |
| 172 | |
| 173 // called on main thread. | |
| 174 void HandleProto(const proto::CompositorMessageToImpl& proto); | |
| 175 void DidReceiveCompositorFrameAckOnMain(); | |
| 176 void DidCommitAndDrawFrameOnMain(); | |
| 177 void DidLoseCompositorFrameSinkOnMain(); | |
| 178 void RequestNewCompositorFrameSinkOnMain(); | |
| 179 void DidInitializeCompositorFrameSinkOnMain(bool success); | |
| 180 void SendMessageProtoOnMain(std::unique_ptr<proto::CompositorMessage> proto); | |
| 181 void PostSetNeedsRedrawToImpl(const gfx::Rect& damaged_rect); | |
| 182 | |
| 183 void InitializeImplOnImpl(CompletionEvent* completion, | |
| 184 LayerTreeHostInProcess* layer_tree_host); | |
| 185 void ShutdownImplOnImpl(CompletionEvent* completion); | |
| 186 | |
| 187 MainThreadOnly& main(); | |
| 188 const MainThreadOnly& main() const; | |
| 189 CompositorThreadOnly& impl(); | |
| 190 const CompositorThreadOnly& impl() const; | |
| 191 | |
| 192 base::SingleThreadTaskRunner* MainThreadTaskRunner() const; | |
| 193 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const; | |
| 194 | |
| 195 TaskRunnerProvider* task_runner_provider_; | |
| 196 | |
| 197 // use accessors instead of these variables directly | |
| 198 MainThreadOnly main_thread_vars_unsafe_; | |
| 199 CompositorThreadOnly compositor_thread_vars_unsafe_; | |
| 200 | |
| 201 base::WeakPtr<ProxyImpl> proxy_impl_weak_ptr_; | |
| 202 | |
| 203 DISALLOW_COPY_AND_ASSIGN(RemoteChannelImpl); | |
| 204 }; | |
| 205 | |
| 206 } // namespace cc | |
| 207 | |
| 208 #endif // CC_TREES_REMOTE_CHANNEL_IMPL_H_ | |
| OLD | NEW |