| 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 BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 5 #ifndef BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| 6 #define BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 6 #define BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "blimp/client/core/compositor/blimp_compositor_frame_sink_proxy.h" | 14 #include "blimp/client/core/compositor/blimp_compositor_frame_sink_proxy.h" |
| 15 #include "blimp/client/public/compositor/compositor_dependencies.h" | 15 #include "blimp/client/public/compositor/compositor_dependencies.h" |
| 16 #include "cc/blimp/compositor_state_deserializer_client.h" | 16 #include "cc/blimp/compositor_state_deserializer.h" |
| 17 #include "cc/surfaces/surface_factory_client.h" | 17 #include "cc/surfaces/surface_factory_client.h" |
| 18 #include "cc/trees/layer_tree_host.h" | 18 #include "cc/trees/layer_tree_host.h" |
| 19 #include "cc/trees/layer_tree_host_client.h" | 19 #include "cc/trees/layer_tree_host_client.h" |
| 20 #include "cc/trees/layer_tree_settings.h" | 20 #include "cc/trees/layer_tree_settings.h" |
| 21 #include "cc/trees/remote_proto_channel.h" | 21 #include "cc/trees/remote_proto_channel.h" |
| 22 #include "ui/gfx/geometry/size.h" | 22 #include "ui/gfx/geometry/size.h" |
| 23 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
| 27 class Thread; | 27 class Thread; |
| 28 } // namespace base | 28 } // namespace base |
| 29 | 29 |
| 30 namespace cc { | 30 namespace cc { |
| 31 class InputHandler; | 31 class InputHandler; |
| 32 | 32 |
| 33 namespace proto { | 33 namespace proto { |
| 34 class CompositorMessage; | 34 class CompositorMessage; |
| 35 } // namespace proto | 35 } // namespace proto |
| 36 | 36 |
| 37 class CompositorStateDeserializer; | |
| 38 class ContextProvider; | 37 class ContextProvider; |
| 39 class CopyOutputRequest; | 38 class CopyOutputRequest; |
| 40 class Layer; | 39 class Layer; |
| 41 class LayerTreeHost; | 40 class LayerTreeHostInProcess; |
| 42 class LayerTreeSettings; | 41 class LayerTreeSettings; |
| 43 class LocalFrameid; | 42 class LocalFrameid; |
| 44 class Surface; | 43 class Surface; |
| 45 class SurfaceFactory; | 44 class SurfaceFactory; |
| 46 class SurfaceIdAllocator; | 45 class SurfaceIdAllocator; |
| 47 } // namespace cc | 46 } // namespace cc |
| 48 | 47 |
| 49 namespace blimp { | 48 namespace blimp { |
| 50 class BlimpMessage; | 49 class BlimpMessage; |
| 51 | 50 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 76 // RenderWidget, identified by a custom |render_widget_id| generated on the | 75 // RenderWidget, identified by a custom |render_widget_id| generated on the |
| 77 // engine. The lifetime of this compositor is controlled by its corresponding | 76 // engine. The lifetime of this compositor is controlled by its corresponding |
| 78 // RenderWidget. | 77 // RenderWidget. |
| 79 // This class should only be accessed from the main thread. | 78 // This class should only be accessed from the main thread. |
| 80 class BlimpCompositor : public cc::LayerTreeHostClient, | 79 class BlimpCompositor : public cc::LayerTreeHostClient, |
| 81 public cc::RemoteProtoChannel, | 80 public cc::RemoteProtoChannel, |
| 82 public BlimpCompositorFrameSinkProxy, | 81 public BlimpCompositorFrameSinkProxy, |
| 83 public cc::SurfaceFactoryClient, | 82 public cc::SurfaceFactoryClient, |
| 84 public cc::CompositorStateDeserializerClient { | 83 public cc::CompositorStateDeserializerClient { |
| 85 public: | 84 public: |
| 86 BlimpCompositor(BlimpCompositorDependencies* compositor_dependencies, | 85 static std::unique_ptr<BlimpCompositor> Create( |
| 87 BlimpCompositorClient* client, | 86 BlimpCompositorDependencies* compositor_dependencies, |
| 88 bool use_threaded_layer_tree_host); | 87 BlimpCompositorClient* client, |
| 88 bool use_threaded_layer_tree_host); |
| 89 | 89 |
| 90 ~BlimpCompositor() override; | 90 ~BlimpCompositor() override; |
| 91 | 91 |
| 92 virtual void SetVisible(bool visible); | 92 virtual void SetVisible(bool visible); |
| 93 | 93 |
| 94 // Requests a copy of the compositor frame. | 94 // Requests a copy of the compositor frame. |
| 95 // Setting |flush_pending_update| to true ensures that if a frame update on | 95 // Setting |flush_pending_update| to true ensures that if a frame update on |
| 96 // the main thread is pending, then it is drawn before copying from the | 96 // the main thread is pending, then it is drawn before copying from the |
| 97 // surface. | 97 // surface. |
| 98 void RequestCopyOfOutput(std::unique_ptr<cc::CopyOutputRequest> copy_request, | 98 void RequestCopyOfOutput(std::unique_ptr<cc::CopyOutputRequest> copy_request, |
| 99 bool flush_pending_update); | 99 bool flush_pending_update); |
| 100 | 100 |
| 101 // Called to forward the compositor message from the remote server | 101 // Called to forward the compositor message from the remote server |
| 102 // LayerTreeHost of the render widget for this compositor. | 102 // LayerTreeHost of the render widget for this compositor. |
| 103 // virtual for testing. | 103 // virtual for testing. |
| 104 virtual void OnCompositorMessageReceived( | 104 virtual void OnCompositorMessageReceived( |
| 105 std::unique_ptr<cc::proto::CompositorMessage> message); | 105 std::unique_ptr<cc::proto::CompositorMessage> message); |
| 106 | 106 |
| 107 scoped_refptr<cc::Layer> layer() const { return layer_; } | 107 scoped_refptr<cc::Layer> layer() const { return layer_; } |
| 108 | 108 |
| 109 // Returns a reference to the InputHandler used to respond to input events on | 109 // Returns a reference to the InputHandler used to respond to input events on |
| 110 // the compositor thread. | 110 // the compositor thread. |
| 111 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); | 111 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); |
| 112 | 112 |
| 113 private: | 113 cc::CompositorStateDeserializer* compositor_state_deserializer_for_testing() { |
| 114 friend class BlimpCompositorForTesting; | 114 return compositor_state_deserializer_.get(); |
| 115 class FrameTrackingSwapPromise; | 115 } |
| 116 | 116 |
| 117 // LayerTreeHostClient implementation. | 117 // LayerTreeHostClient implementation. |
| 118 void WillBeginMainFrame() override {} | 118 void WillBeginMainFrame() override {} |
| 119 void DidBeginMainFrame() override {} | 119 void DidBeginMainFrame() override {} |
| 120 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} | 120 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} |
| 121 void BeginMainFrameNotExpectedSoon() override {} | 121 void BeginMainFrameNotExpectedSoon() override {} |
| 122 void UpdateLayerTreeHost() override; | 122 void UpdateLayerTreeHost() override; |
| 123 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 123 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 124 const gfx::Vector2dF& outer_delta, | 124 const gfx::Vector2dF& outer_delta, |
| 125 const gfx::Vector2dF& elastic_overscroll_delta, | 125 const gfx::Vector2dF& elastic_overscroll_delta, |
| 126 float page_scale, | 126 float page_scale, |
| 127 float top_controls_delta) override {} | 127 float top_controls_delta) override; |
| 128 void RequestNewCompositorFrameSink() override; | 128 void RequestNewCompositorFrameSink() override; |
| 129 void DidInitializeCompositorFrameSink() override; | 129 void DidInitializeCompositorFrameSink() override; |
| 130 // TODO(khushalsagar): Need to handle context initialization failures. | 130 // TODO(khushalsagar): Need to handle context initialization failures. |
| 131 void DidFailToInitializeCompositorFrameSink() override {} | 131 void DidFailToInitializeCompositorFrameSink() override {} |
| 132 void WillCommit() override {} | 132 void WillCommit() override {} |
| 133 void DidCommit() override {} | 133 void DidCommit() override {} |
| 134 void DidCommitAndDrawFrame() override; | 134 void DidCommitAndDrawFrame() override; |
| 135 void DidReceiveCompositorFrameAck() override {} | 135 void DidReceiveCompositorFrameAck() override {} |
| 136 void DidCompletePageScaleAnimation() override {} | 136 void DidCompletePageScaleAnimation() override {} |
| 137 | 137 |
| 138 // CompositorStateDeserializerClient implementation. |
| 139 void DidUpdateLocalState() override; |
| 140 |
| 141 protected: |
| 142 BlimpCompositor(BlimpCompositorDependencies* compositor_dependencies, |
| 143 BlimpCompositorClient* client, |
| 144 bool use_threaded_layer_tree_host); |
| 145 |
| 146 void Initialize(); |
| 147 virtual std::unique_ptr<cc::LayerTreeHostInProcess> CreateLayerTreeHost(); |
| 148 |
| 149 private: |
| 150 class FrameTrackingSwapPromise; |
| 151 |
| 138 // RemoteProtoChannel implementation. | 152 // RemoteProtoChannel implementation. |
| 139 void SetProtoReceiver(ProtoReceiver* receiver) override; | 153 void SetProtoReceiver(ProtoReceiver* receiver) override; |
| 140 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | 154 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 141 | 155 |
| 142 // BlimpCompositorFrameSinkProxy implementation. | 156 // BlimpCompositorFrameSinkProxy implementation. |
| 143 void BindToProxyClient( | 157 void BindToProxyClient( |
| 144 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) override; | 158 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) override; |
| 145 void SubmitCompositorFrame(cc::CompositorFrame frame) override; | 159 void SubmitCompositorFrame(cc::CompositorFrame frame) override; |
| 146 void UnbindProxyClient() override; | 160 void UnbindProxyClient() override; |
| 147 | 161 |
| 148 // SurfaceFactoryClient implementation. | 162 // SurfaceFactoryClient implementation. |
| 149 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | 163 void ReturnResources(const cc::ReturnedResourceArray& resources) override; |
| 150 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} | 164 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} |
| 151 | 165 |
| 152 // CompositorStateDeserializerClient implementation. | |
| 153 bool ShouldRetainClientScroll(int engine_layer_id, | |
| 154 const gfx::ScrollOffset& new_offset) override; | |
| 155 bool ShouldRetainClientPageScale(float new_page_scale) override; | |
| 156 | |
| 157 void HandleCompositorMessageToImpl( | 166 void HandleCompositorMessageToImpl( |
| 158 std::unique_ptr<cc::proto::CompositorMessage> message); | 167 std::unique_ptr<cc::proto::CompositorMessage> message); |
| 159 | 168 |
| 160 // Called when the a ContextProvider has been created by the | 169 // Called when the a ContextProvider has been created by the |
| 161 // CompositorDependencies class. If |host_| is waiting on an | 170 // CompositorDependencies class. If |host_| is waiting on an |
| 162 // CompositorFrameSink this will build one for it. | 171 // CompositorFrameSink this will build one for it. |
| 163 void OnContextProvidersCreated( | 172 void OnContextProvidersCreated( |
| 164 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, | 173 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, |
| 165 const scoped_refptr<cc::ContextProvider>& worker_context_provider); | 174 const scoped_refptr<cc::ContextProvider>& worker_context_provider); |
| 166 | 175 |
| 167 // Helper method to get the embedder dependencies. | 176 // Helper method to get the embedder dependencies. |
| 168 CompositorDependencies* GetEmbedderDeps(); | 177 CompositorDependencies* GetEmbedderDeps(); |
| 169 | 178 |
| 170 // TODO(khushalsagar): Move all of this to the |DocumentView| or another | 179 // TODO(khushalsagar): Move all of this to the |DocumentView| or another |
| 171 // platform specific class. So we use the DelegatedFrameHostAndroid like the | 180 // platform specific class. So we use the DelegatedFrameHostAndroid like the |
| 172 // RenderWidgetHostViewAndroid. | 181 // RenderWidgetHostViewAndroid. |
| 173 void DestroyDelegatedContent(); | 182 void DestroyDelegatedContent(); |
| 174 | 183 |
| 175 // Helper method to build the internal CC LayerTreeHost instance from | |
| 176 // |message|. | |
| 177 void CreateLayerTreeHost(); | |
| 178 | |
| 179 // Helper method to destroy the internal CC LayerTreeHost instance and all its | 184 // Helper method to destroy the internal CC LayerTreeHost instance and all its |
| 180 // associated state. | 185 // associated state. |
| 181 void DestroyLayerTreeHost(); | 186 void DestroyLayerTreeHost(); |
| 182 | 187 |
| 183 // Acks a submitted CompositorFrame when it has been processed and another | 188 // Acks a submitted CompositorFrame when it has been processed and another |
| 184 // frame should be started. | 189 // frame should be started. |
| 185 void SubmitCompositorFrameAck(); | 190 void SubmitCompositorFrameAck(); |
| 186 | 191 |
| 187 // Called when the local copy of the layer with |engine_layer_id| on the | 192 // Sends an update to the engine if the state on the client was modified and |
| 188 // engine was scrolled on the compositor thread. | 193 // an ack for a previous update sent is not pending. |
| 189 void LayerScrolled(int engine_layer_id); | 194 void FlushClientState(); |
| 190 | 195 |
| 191 // Set to true if we are using a LayerTreeHostInProcess to process frame | 196 // Set to true if we are using a LayerTreeHostInProcess to process frame |
| 192 // updates from the engine. | 197 // updates from the engine. |
| 193 const bool use_threaded_layer_tree_host_; | 198 const bool use_threaded_layer_tree_host_; |
| 194 | 199 |
| 195 void MakeCopyRequestOnNextSwap( | 200 void MakeCopyRequestOnNextSwap( |
| 196 std::unique_ptr<cc::CopyOutputRequest> copy_request); | 201 std::unique_ptr<cc::CopyOutputRequest> copy_request); |
| 197 | 202 |
| 198 void RequestCopyOfOutputDeprecated( | 203 void RequestCopyOfOutputDeprecated( |
| 199 std::unique_ptr<cc::CopyOutputRequest> copy_request); | 204 std::unique_ptr<cc::CopyOutputRequest> copy_request); |
| 200 | 205 |
| 201 BlimpCompositorClient* client_; | 206 BlimpCompositorClient* client_; |
| 202 | 207 |
| 203 BlimpCompositorDependencies* compositor_dependencies_; | 208 BlimpCompositorDependencies* compositor_dependencies_; |
| 204 | 209 |
| 205 cc::FrameSinkId frame_sink_id_; | 210 cc::FrameSinkId frame_sink_id_; |
| 206 | 211 |
| 207 std::unique_ptr<cc::LayerTreeHost> host_; | 212 std::unique_ptr<cc::LayerTreeHostInProcess> host_; |
| 208 | 213 |
| 209 // The SurfaceFactory is bound to the lifetime of the |proxy_client_|. When | 214 // The SurfaceFactory is bound to the lifetime of the |proxy_client_|. When |
| 210 // detached, the surface factory will be destroyed. | 215 // detached, the surface factory will be destroyed. |
| 211 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | 216 std::unique_ptr<cc::SurfaceFactory> surface_factory_; |
| 212 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client_; | 217 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client_; |
| 213 | 218 |
| 214 // Whether or not |host_| has asked for a new CompositorFrameSink. | 219 // Whether or not |host_| has asked for a new CompositorFrameSink. |
| 215 bool compositor_frame_sink_request_pending_; | 220 bool compositor_frame_sink_request_pending_; |
| 216 | 221 |
| 217 // Data for the current frame. | 222 // Data for the current frame. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 247 // Stores a frame update received from the engine, when a threaded | 252 // Stores a frame update received from the engine, when a threaded |
| 248 // LayerTreeHost is used. There can only be a single frame in flight at any | 253 // LayerTreeHost is used. There can only be a single frame in flight at any |
| 249 // point. | 254 // point. |
| 250 std::unique_ptr<cc::proto::CompositorMessage> pending_frame_update_; | 255 std::unique_ptr<cc::proto::CompositorMessage> pending_frame_update_; |
| 251 | 256 |
| 252 // Used with a threaded LayerTreeHost to deserialize proto updates from the | 257 // Used with a threaded LayerTreeHost to deserialize proto updates from the |
| 253 // engine into the LayerTree. | 258 // engine into the LayerTree. |
| 254 std::unique_ptr<cc::CompositorStateDeserializer> | 259 std::unique_ptr<cc::CompositorStateDeserializer> |
| 255 compositor_state_deserializer_; | 260 compositor_state_deserializer_; |
| 256 | 261 |
| 262 // Set to true if the compositor state on the client was modified on the impl |
| 263 // thread and an update needs to be sent to the engine. |
| 264 bool client_state_dirty_ = false; |
| 265 |
| 266 // Set to true if a client state update was sent to the engine and an ack for |
| 267 // this update from the engine is pending. |
| 268 bool client_state_update_ack_pending_ = false; |
| 269 |
| 257 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; | 270 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; |
| 258 | 271 |
| 259 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 272 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 260 }; | 273 }; |
| 261 | 274 |
| 262 } // namespace client | 275 } // namespace client |
| 263 } // namespace blimp | 276 } // namespace blimp |
| 264 | 277 |
| 265 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 278 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| OLD | NEW |