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 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 Layer; | 38 class Layer; |
| 40 class LayerTreeHost; | 39 class LayerTreeHostInProcess; |
| 41 class LayerTreeSettings; | 40 class LayerTreeSettings; |
| 42 class LocalFrameid; | 41 class LocalFrameid; |
| 43 class Surface; | 42 class Surface; |
| 44 class SurfaceFactory; | 43 class SurfaceFactory; |
| 45 class SurfaceIdAllocator; | 44 class SurfaceIdAllocator; |
| 46 } // namespace cc | 45 } // namespace cc |
| 47 | 46 |
| 48 namespace blimp { | 47 namespace blimp { |
| 49 class BlimpMessage; | 48 class BlimpMessage; |
| 50 | 49 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 75 // RenderWidget, identified by a custom |render_widget_id| generated on the | 74 // RenderWidget, identified by a custom |render_widget_id| generated on the |
| 76 // engine. The lifetime of this compositor is controlled by its corresponding | 75 // engine. The lifetime of this compositor is controlled by its corresponding |
| 77 // RenderWidget. | 76 // RenderWidget. |
| 78 // This class should only be accessed from the main thread. | 77 // This class should only be accessed from the main thread. |
| 79 class BlimpCompositor : public cc::LayerTreeHostClient, | 78 class BlimpCompositor : public cc::LayerTreeHostClient, |
| 80 public cc::RemoteProtoChannel, | 79 public cc::RemoteProtoChannel, |
| 81 public BlimpCompositorFrameSinkProxy, | 80 public BlimpCompositorFrameSinkProxy, |
| 82 public cc::SurfaceFactoryClient, | 81 public cc::SurfaceFactoryClient, |
| 83 public cc::CompositorStateDeserializerClient { | 82 public cc::CompositorStateDeserializerClient { |
| 84 public: | 83 public: |
| 85 BlimpCompositor(BlimpCompositorDependencies* compositor_dependencies, | 84 static std::unique_ptr<BlimpCompositor> Create( |
| 86 BlimpCompositorClient* client, | 85 BlimpCompositorDependencies* compositor_dependencies, |
| 87 bool use_threaded_layer_tree_host); | 86 BlimpCompositorClient* client, |
| 87 bool use_threaded_layer_tree_host); | |
| 88 | 88 |
| 89 ~BlimpCompositor() override; | 89 ~BlimpCompositor() override; |
| 90 | 90 |
| 91 virtual void SetVisible(bool visible); | 91 virtual void SetVisible(bool visible); |
| 92 | 92 |
| 93 // Notifies |callback| when all pending commits have been drawn to the screen. | 93 // Notifies |callback| when all pending commits have been drawn to the screen. |
| 94 // If this compositor is destroyed or becomes hidden |callback| will be | 94 // If this compositor is destroyed or becomes hidden |callback| will be |
| 95 // notified. | 95 // notified. |
| 96 void NotifyWhenDonePendingCommits(base::Closure callback); | 96 void NotifyWhenDonePendingCommits(base::Closure callback); |
| 97 | 97 |
| 98 // Called to forward the compositor message from the remote server | 98 // Called to forward the compositor message from the remote server |
| 99 // LayerTreeHost of the render widget for this compositor. | 99 // LayerTreeHost of the render widget for this compositor. |
| 100 // virtual for testing. | 100 // virtual for testing. |
| 101 virtual void OnCompositorMessageReceived( | 101 virtual void OnCompositorMessageReceived( |
| 102 std::unique_ptr<cc::proto::CompositorMessage> message); | 102 std::unique_ptr<cc::proto::CompositorMessage> message); |
| 103 | 103 |
| 104 scoped_refptr<cc::Layer> layer() const { return layer_; } | 104 scoped_refptr<cc::Layer> layer() const { return layer_; } |
| 105 | 105 |
| 106 // Returns a reference to the InputHandler used to respond to input events on | 106 // Returns a reference to the InputHandler used to respond to input events on |
| 107 // the compositor thread. | 107 // the compositor thread. |
| 108 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); | 108 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); |
| 109 | 109 |
| 110 private: | 110 cc::CompositorStateDeserializer* compositor_state_deserializer_for_testing() { |
| 111 friend class BlimpCompositorForTesting; | 111 return compositor_state_deserializer_.get(); |
| 112 } | |
| 112 | 113 |
|
kuzminruslan
2016/10/30 13:18:40
perhaps forgotten private
Khushal
2016/10/31 23:00:27
I'm actually making it public because the tests ne
| |
| 113 // LayerTreeHostClient implementation. | 114 // LayerTreeHostClient implementation. |
| 114 void WillBeginMainFrame() override {} | 115 void WillBeginMainFrame() override {} |
| 115 void DidBeginMainFrame() override {} | 116 void DidBeginMainFrame() override {} |
| 116 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} | 117 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} |
| 117 void BeginMainFrameNotExpectedSoon() override {} | 118 void BeginMainFrameNotExpectedSoon() override {} |
| 118 void UpdateLayerTreeHost() override; | 119 void UpdateLayerTreeHost() override; |
| 119 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 120 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 120 const gfx::Vector2dF& outer_delta, | 121 const gfx::Vector2dF& outer_delta, |
| 121 const gfx::Vector2dF& elastic_overscroll_delta, | 122 const gfx::Vector2dF& elastic_overscroll_delta, |
| 122 float page_scale, | 123 float page_scale, |
| 123 float top_controls_delta) override {} | 124 float top_controls_delta) override; |
| 124 void RequestNewCompositorFrameSink() override; | 125 void RequestNewCompositorFrameSink() override; |
| 125 void DidInitializeCompositorFrameSink() override; | 126 void DidInitializeCompositorFrameSink() override; |
| 126 // TODO(khushalsagar): Need to handle context initialization failures. | 127 // TODO(khushalsagar): Need to handle context initialization failures. |
| 127 void DidFailToInitializeCompositorFrameSink() override {} | 128 void DidFailToInitializeCompositorFrameSink() override {} |
| 128 void WillCommit() override {} | 129 void WillCommit() override {} |
| 129 void DidCommit() override {} | 130 void DidCommit() override {} |
| 130 void DidCommitAndDrawFrame() override; | 131 void DidCommitAndDrawFrame() override; |
| 131 void DidReceiveCompositorFrameAck() override {} | 132 void DidReceiveCompositorFrameAck() override {} |
| 132 void DidCompletePageScaleAnimation() override {} | 133 void DidCompletePageScaleAnimation() override {} |
| 133 | 134 |
| 135 // CompositorStateDeserializerClient implementation. | |
| 136 void DidUpdateLocalState() override; | |
| 137 | |
| 138 protected: | |
| 139 BlimpCompositor(BlimpCompositorDependencies* compositor_dependencies, | |
| 140 BlimpCompositorClient* client, | |
| 141 bool use_threaded_layer_tree_host); | |
| 142 | |
| 143 void Initialize(); | |
| 144 virtual std::unique_ptr<cc::LayerTreeHostInProcess> CreateLayerTreeHost(); | |
| 145 | |
| 146 private: | |
| 134 // RemoteProtoChannel implementation. | 147 // RemoteProtoChannel implementation. |
| 135 void SetProtoReceiver(ProtoReceiver* receiver) override; | 148 void SetProtoReceiver(ProtoReceiver* receiver) override; |
| 136 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | 149 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 137 | 150 |
| 138 // BlimpCompositorFrameSinkProxy implementation. | 151 // BlimpCompositorFrameSinkProxy implementation. |
| 139 void BindToProxyClient( | 152 void BindToProxyClient( |
| 140 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) override; | 153 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) override; |
| 141 void SubmitCompositorFrame(cc::CompositorFrame frame) override; | 154 void SubmitCompositorFrame(cc::CompositorFrame frame) override; |
| 142 void UnbindProxyClient() override; | 155 void UnbindProxyClient() override; |
| 143 | 156 |
| 144 // SurfaceFactoryClient implementation. | 157 // SurfaceFactoryClient implementation. |
| 145 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | 158 void ReturnResources(const cc::ReturnedResourceArray& resources) override; |
| 146 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} | 159 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} |
| 147 | 160 |
| 148 // CompositorStateDeserializerClient implementation. | |
| 149 bool ShouldRetainClientScroll(int engine_layer_id, | |
| 150 const gfx::ScrollOffset& new_offset) override; | |
| 151 bool ShouldRetainClientPageScale(float new_page_scale) override; | |
| 152 | |
| 153 void HandleCompositorMessageToImpl( | 161 void HandleCompositorMessageToImpl( |
| 154 std::unique_ptr<cc::proto::CompositorMessage> message); | 162 std::unique_ptr<cc::proto::CompositorMessage> message); |
| 155 | 163 |
| 156 // Called when the a ContextProvider has been created by the | 164 // Called when the a ContextProvider has been created by the |
| 157 // CompositorDependencies class. If |host_| is waiting on an | 165 // CompositorDependencies class. If |host_| is waiting on an |
| 158 // CompositorFrameSink this will build one for it. | 166 // CompositorFrameSink this will build one for it. |
| 159 void OnContextProvidersCreated( | 167 void OnContextProvidersCreated( |
| 160 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, | 168 const scoped_refptr<cc::ContextProvider>& compositor_context_provider, |
| 161 const scoped_refptr<cc::ContextProvider>& worker_context_provider); | 169 const scoped_refptr<cc::ContextProvider>& worker_context_provider); |
| 162 | 170 |
| 163 // Helper method to get the embedder dependencies. | 171 // Helper method to get the embedder dependencies. |
| 164 CompositorDependencies* GetEmbedderDeps(); | 172 CompositorDependencies* GetEmbedderDeps(); |
| 165 | 173 |
| 166 // TODO(khushalsagar): Move all of this to the |DocumentView| or another | 174 // TODO(khushalsagar): Move all of this to the |DocumentView| or another |
| 167 // platform specific class. So we use the DelegatedFrameHostAndroid like the | 175 // platform specific class. So we use the DelegatedFrameHostAndroid like the |
| 168 // RenderWidgetHostViewAndroid. | 176 // RenderWidgetHostViewAndroid. |
| 169 void DestroyDelegatedContent(); | 177 void DestroyDelegatedContent(); |
| 170 | 178 |
| 171 // Helper method to build the internal CC LayerTreeHost instance from | |
| 172 // |message|. | |
| 173 void CreateLayerTreeHost(); | |
| 174 | |
| 175 // Helper method to destroy the internal CC LayerTreeHost instance and all its | 179 // Helper method to destroy the internal CC LayerTreeHost instance and all its |
| 176 // associated state. | 180 // associated state. |
| 177 void DestroyLayerTreeHost(); | 181 void DestroyLayerTreeHost(); |
| 178 | 182 |
| 179 // Updates |pending_commit_trackers_|, decrementing the count and, if 0, | 183 // Updates |pending_commit_trackers_|, decrementing the count and, if 0, |
| 180 // notifying the callback. If |flush| is true, flushes all entries regardless | 184 // notifying the callback. If |flush| is true, flushes all entries regardless |
| 181 // of the count. | 185 // of the count. |
| 182 void CheckPendingCommitCounts(bool flush); | 186 void CheckPendingCommitCounts(bool flush); |
| 183 | 187 |
| 184 // Acks a submitted CompositorFrame when it has been processed and another | 188 // Acks a submitted CompositorFrame when it has been processed and another |
| 185 // frame should be started. | 189 // frame should be started. |
| 186 void SubmitCompositorFrameAck(); | 190 void SubmitCompositorFrameAck(); |
| 187 | 191 |
| 188 // 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 |
| 189 // engine was scrolled on the compositor thread. | 193 // an ack for a previous update sent is not pending. |
| 190 void LayerScrolled(int engine_layer_id); | 194 void FlushClientState(); |
| 191 | 195 |
| 192 // 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 |
| 193 // updates from the engine. | 197 // updates from the engine. |
| 194 const bool use_threaded_layer_tree_host_; | 198 const bool use_threaded_layer_tree_host_; |
| 195 | 199 |
| 196 BlimpCompositorClient* client_; | 200 BlimpCompositorClient* client_; |
| 197 | 201 |
| 198 BlimpCompositorDependencies* compositor_dependencies_; | 202 BlimpCompositorDependencies* compositor_dependencies_; |
| 199 | 203 |
| 200 cc::FrameSinkId frame_sink_id_; | 204 cc::FrameSinkId frame_sink_id_; |
| 201 | 205 |
| 202 std::unique_ptr<cc::LayerTreeHost> host_; | 206 std::unique_ptr<cc::LayerTreeHostInProcess> host_; |
| 203 | 207 |
| 204 // The SurfaceFactory is bound to the lifetime of the |proxy_client_|. When | 208 // The SurfaceFactory is bound to the lifetime of the |proxy_client_|. When |
| 205 // detached, the surface factory will be destroyed. | 209 // detached, the surface factory will be destroyed. |
| 206 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | 210 std::unique_ptr<cc::SurfaceFactory> surface_factory_; |
| 207 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client_; | 211 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client_; |
| 208 | 212 |
| 209 // Whether or not |host_| has asked for a new CompositorFrameSink. | 213 // Whether or not |host_| has asked for a new CompositorFrameSink. |
| 210 bool compositor_frame_sink_request_pending_; | 214 bool compositor_frame_sink_request_pending_; |
| 211 | 215 |
| 212 // Data for the current frame. | 216 // Data for the current frame. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 238 // Stores a frame update received from the engine, when a threaded | 242 // Stores a frame update received from the engine, when a threaded |
| 239 // LayerTreeHost is used. There can only be a single frame in flight at any | 243 // LayerTreeHost is used. There can only be a single frame in flight at any |
| 240 // point. | 244 // point. |
| 241 std::unique_ptr<cc::proto::CompositorMessage> pending_frame_update_; | 245 std::unique_ptr<cc::proto::CompositorMessage> pending_frame_update_; |
| 242 | 246 |
| 243 // Used with a threaded LayerTreeHost to deserialize proto updates from the | 247 // Used with a threaded LayerTreeHost to deserialize proto updates from the |
| 244 // engine into the LayerTree. | 248 // engine into the LayerTree. |
| 245 std::unique_ptr<cc::CompositorStateDeserializer> | 249 std::unique_ptr<cc::CompositorStateDeserializer> |
| 246 compositor_state_deserializer_; | 250 compositor_state_deserializer_; |
| 247 | 251 |
| 252 // Set to true if the compositor state on the client was modified on the impl | |
| 253 // thread and an update needs to be sent to the engine. | |
| 254 bool client_state_dirty_ = false; | |
| 255 | |
| 256 // Set to true if a client state update was sent to the engine and an ack for | |
| 257 // this update from the engine is pending. | |
| 258 bool client_state_update_ack_pending_ = false; | |
| 259 | |
| 248 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; | 260 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; |
| 249 | 261 |
| 250 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 262 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 251 }; | 263 }; |
| 252 | 264 |
| 253 } // namespace client | 265 } // namespace client |
| 254 } // namespace blimp | 266 } // namespace blimp |
| 255 | 267 |
| 256 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 268 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| OLD | NEW |