| 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 "blimp/client/core/compositor/blimp_compositor_frame_sink_proxy.h" | 14 #include "blimp/client/core/compositor/blimp_compositor_frame_sink_proxy.h" |
| 14 #include "blimp/client/core/input/blimp_input_manager.h" | |
| 15 #include "blimp/client/public/compositor/compositor_dependencies.h" | 15 #include "blimp/client/public/compositor/compositor_dependencies.h" |
| 16 #include "cc/surfaces/surface_factory_client.h" | 16 #include "cc/surfaces/surface_factory_client.h" |
| 17 #include "cc/trees/layer_tree_host.h" | 17 #include "cc/trees/layer_tree_host.h" |
| 18 #include "cc/trees/layer_tree_host_client.h" | 18 #include "cc/trees/layer_tree_host_client.h" |
| 19 #include "cc/trees/layer_tree_settings.h" | 19 #include "cc/trees/layer_tree_settings.h" |
| 20 #include "cc/trees/remote_proto_channel.h" | 20 #include "cc/trees/remote_proto_channel.h" |
| 21 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 22 #include "ui/gfx/native_widget_types.h" | 22 #include "ui/gfx/native_widget_types.h" |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 26 class Thread; | 26 class Thread; |
| 27 } // namespace base | 27 } // namespace base |
| 28 | 28 |
| 29 namespace cc { | 29 namespace cc { |
| 30 class InputHandler; |
| 31 |
| 30 namespace proto { | 32 namespace proto { |
| 31 class CompositorMessage; | 33 class CompositorMessage; |
| 32 } // namespace proto | 34 } // namespace proto |
| 33 | 35 |
| 34 class ContextProvider; | 36 class ContextProvider; |
| 35 class Layer; | 37 class Layer; |
| 36 class LayerTreeHost; | 38 class LayerTreeHost; |
| 37 class LayerTreeSettings; | 39 class LayerTreeSettings; |
| 38 class LocalFrameid; | 40 class LocalFrameid; |
| 39 class Surface; | 41 class Surface; |
| 40 class SurfaceFactory; | 42 class SurfaceFactory; |
| 41 class SurfaceIdAllocator; | 43 class SurfaceIdAllocator; |
| 42 } // namespace cc | 44 } // namespace cc |
| 43 | 45 |
| 44 namespace blimp { | 46 namespace blimp { |
| 45 class BlimpMessage; | 47 class BlimpMessage; |
| 46 | 48 |
| 47 namespace client { | 49 namespace client { |
| 48 | 50 |
| 49 class BlimpCompositorDependencies; | 51 class BlimpCompositorDependencies; |
| 50 | 52 |
| 51 // The BlimpCompositorClient provides the BlimpCompositor with the necessary | 53 // The BlimpCompositorClient provides the BlimpCompositor with the necessary |
| 52 // dependencies for cc::LayerTreeHost owned by this compositor and for | 54 // dependencies for cc::LayerTreeHost owned by this compositor and for |
| 53 // communicating the compositor and input messages to the corresponding | 55 // communicating the compositor and input messages to the corresponding |
| 54 // render widget of this compositor on the engine. | 56 // render widget of this compositor on the engine. |
| 55 class BlimpCompositorClient { | 57 class BlimpCompositorClient { |
| 56 public: | 58 public: |
| 57 // Should send web gesture events which could not be handled locally by the | |
| 58 // compositor to the engine. | |
| 59 virtual void SendWebGestureEvent( | |
| 60 const blink::WebGestureEvent& gesture_event) = 0; | |
| 61 | |
| 62 // Should send the compositor messages from the remote client LayerTreeHost of | 59 // Should send the compositor messages from the remote client LayerTreeHost of |
| 63 // this compositor to the corresponding remote server LayerTreeHost. | 60 // this compositor to the corresponding remote server LayerTreeHost. |
| 64 virtual void SendCompositorMessage( | 61 virtual void SendCompositorMessage( |
| 65 const cc::proto::CompositorMessage& message) = 0; | 62 const cc::proto::CompositorMessage& message) = 0; |
| 66 | 63 |
| 67 protected: | 64 protected: |
| 68 virtual ~BlimpCompositorClient() {} | 65 virtual ~BlimpCompositorClient() {} |
| 69 }; | 66 }; |
| 70 | 67 |
| 71 // BlimpCompositor provides the basic framework and setup to host a | 68 // BlimpCompositor provides the basic framework and setup to host a |
| 72 // LayerTreeHost. This class owns the remote client cc::LayerTreeHost, which | 69 // LayerTreeHost. This class owns the remote client cc::LayerTreeHost, which |
| 73 // performs the compositing work for the remote server LayerTreeHost. The server | 70 // performs the compositing work for the remote server LayerTreeHost. The server |
| 74 // LayerTreeHost for a BlimpCompositor is owned by the | 71 // LayerTreeHost for a BlimpCompositor is owned by the |
| 75 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a | 72 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a |
| 76 // RenderWidget, identified by a custom |render_widget_id| generated on the | 73 // RenderWidget, identified by a custom |render_widget_id| generated on the |
| 77 // engine. The lifetime of this compositor is controlled by its corresponding | 74 // engine. The lifetime of this compositor is controlled by its corresponding |
| 78 // RenderWidget. | 75 // RenderWidget. |
| 79 // This class should only be accessed from the main thread. | 76 // This class should only be accessed from the main thread. |
| 80 class BlimpCompositor : public cc::LayerTreeHostClient, | 77 class BlimpCompositor : public cc::LayerTreeHostClient, |
| 81 public cc::RemoteProtoChannel, | 78 public cc::RemoteProtoChannel, |
| 82 public BlimpInputManagerClient, | |
| 83 public BlimpCompositorFrameSinkProxy, | 79 public BlimpCompositorFrameSinkProxy, |
| 84 public cc::SurfaceFactoryClient { | 80 public cc::SurfaceFactoryClient { |
| 85 public: | 81 public: |
| 86 BlimpCompositor(BlimpCompositorDependencies* compositor_dependencies, | 82 BlimpCompositor(BlimpCompositorDependencies* compositor_dependencies, |
| 87 BlimpCompositorClient* client); | 83 BlimpCompositorClient* client); |
| 88 | 84 |
| 89 ~BlimpCompositor() override; | 85 ~BlimpCompositor() override; |
| 90 | 86 |
| 91 virtual void SetVisible(bool visible); | 87 virtual void SetVisible(bool visible); |
| 92 | 88 |
| 93 // Forwards the touch event to the |input_manager_|. | |
| 94 // virtual for testing. | |
| 95 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event); | |
| 96 | |
| 97 // Notifies |callback| when all pending commits have been drawn to the screen. | 89 // Notifies |callback| when all pending commits have been drawn to the screen. |
| 98 // If this compositor is destroyed or becomes hidden |callback| will be | 90 // If this compositor is destroyed or becomes hidden |callback| will be |
| 99 // notified. | 91 // notified. |
| 100 void NotifyWhenDonePendingCommits(base::Closure callback); | 92 void NotifyWhenDonePendingCommits(base::Closure callback); |
| 101 | 93 |
| 102 // Called to forward the compositor message from the remote server | 94 // Called to forward the compositor message from the remote server |
| 103 // LayerTreeHost of the render widget for this compositor. | 95 // LayerTreeHost of the render widget for this compositor. |
| 104 // virtual for testing. | 96 // virtual for testing. |
| 105 virtual void OnCompositorMessageReceived( | 97 virtual void OnCompositorMessageReceived( |
| 106 std::unique_ptr<cc::proto::CompositorMessage> message); | 98 std::unique_ptr<cc::proto::CompositorMessage> message); |
| 107 | 99 |
| 108 scoped_refptr<cc::Layer> layer() const { return layer_; } | 100 scoped_refptr<cc::Layer> layer() const { return layer_; } |
| 109 | 101 |
| 102 // Returns a reference to the InputHandler used to respond to input events on |
| 103 // the compositor thread. |
| 104 const base::WeakPtr<cc::InputHandler>& GetInputHandler(); |
| 105 |
| 110 private: | 106 private: |
| 111 friend class BlimpCompositorForTesting; | 107 friend class BlimpCompositorForTesting; |
| 112 | 108 |
| 113 // LayerTreeHostClient implementation. | 109 // LayerTreeHostClient implementation. |
| 114 void WillBeginMainFrame() override {} | 110 void WillBeginMainFrame() override {} |
| 115 void DidBeginMainFrame() override {} | 111 void DidBeginMainFrame() override {} |
| 116 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} | 112 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} |
| 117 void BeginMainFrameNotExpectedSoon() override {} | 113 void BeginMainFrameNotExpectedSoon() override {} |
| 118 void UpdateLayerTreeHost() override {} | 114 void UpdateLayerTreeHost() override {} |
| 119 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 115 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 120 const gfx::Vector2dF& outer_delta, | 116 const gfx::Vector2dF& outer_delta, |
| 121 const gfx::Vector2dF& elastic_overscroll_delta, | 117 const gfx::Vector2dF& elastic_overscroll_delta, |
| 122 float page_scale, | 118 float page_scale, |
| 123 float top_controls_delta) override {} | 119 float top_controls_delta) override {} |
| 124 void RequestNewCompositorFrameSink() override; | 120 void RequestNewCompositorFrameSink() override; |
| 125 void DidInitializeCompositorFrameSink() override; | 121 void DidInitializeCompositorFrameSink() override; |
| 126 // TODO(khushalsagar): Need to handle context initialization failures. | 122 // TODO(khushalsagar): Need to handle context initialization failures. |
| 127 void DidFailToInitializeCompositorFrameSink() override {} | 123 void DidFailToInitializeCompositorFrameSink() override {} |
| 128 void WillCommit() override {} | 124 void WillCommit() override {} |
| 129 void DidCommit() override {} | 125 void DidCommit() override {} |
| 130 void DidCommitAndDrawFrame() override; | 126 void DidCommitAndDrawFrame() override; |
| 131 void DidCompleteSwapBuffers() override {} | 127 void DidCompleteSwapBuffers() override {} |
| 132 void DidCompletePageScaleAnimation() override {} | 128 void DidCompletePageScaleAnimation() override {} |
| 133 | 129 |
| 134 // RemoteProtoChannel implementation. | 130 // RemoteProtoChannel implementation. |
| 135 void SetProtoReceiver(ProtoReceiver* receiver) override; | 131 void SetProtoReceiver(ProtoReceiver* receiver) override; |
| 136 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | 132 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 137 | 133 |
| 138 // BlimpInputManagerClient implementation. | |
| 139 void SendWebGestureEvent( | |
| 140 const blink::WebGestureEvent& gesture_event) override; | |
| 141 | |
| 142 // BlimpCompositorFrameSinkProxy implementation. | 134 // BlimpCompositorFrameSinkProxy implementation. |
| 143 void BindToProxyClient( | 135 void BindToProxyClient( |
| 144 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) override; | 136 base::WeakPtr<BlimpCompositorFrameSinkProxyClient> proxy_client) override; |
| 145 void SwapCompositorFrame(cc::CompositorFrame frame) override; | 137 void SwapCompositorFrame(cc::CompositorFrame frame) override; |
| 146 void UnbindProxyClient() override; | 138 void UnbindProxyClient() override; |
| 147 | 139 |
| 148 // SurfaceFactoryClient implementation. | 140 // SurfaceFactoryClient implementation. |
| 149 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | 141 void ReturnResources(const cc::ReturnedResourceArray& resources) override; |
| 150 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} | 142 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} |
| 151 | 143 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 193 |
| 202 // Surfaces related stuff and layer which holds the delegated content from the | 194 // Surfaces related stuff and layer which holds the delegated content from the |
| 203 // compositor. | 195 // compositor. |
| 204 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | 196 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; |
| 205 scoped_refptr<cc::Layer> layer_; | 197 scoped_refptr<cc::Layer> layer_; |
| 206 | 198 |
| 207 // To be notified of any incoming compositor protos that are specifically sent | 199 // To be notified of any incoming compositor protos that are specifically sent |
| 208 // to |render_widget_id_|. | 200 // to |render_widget_id_|. |
| 209 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; | 201 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; |
| 210 | 202 |
| 211 // Handles input events for the current render widget. The lifetime of the | |
| 212 // input manager is tied to the lifetime of the |host_| which owns the | |
| 213 // cc::InputHandler. The input events are forwarded to this input handler by | |
| 214 // the manager to be handled by the client compositor for the current render | |
| 215 // widget. | |
| 216 std::unique_ptr<BlimpInputManager> input_manager_; | |
| 217 | |
| 218 // The number of times a START_COMMIT proto has been received but a call to | 203 // The number of times a START_COMMIT proto has been received but a call to |
| 219 // DidCommitAndDrawFrame hasn't been seen. This should track the number of | 204 // DidCommitAndDrawFrame hasn't been seen. This should track the number of |
| 220 // outstanding commits. | 205 // outstanding commits. |
| 221 size_t outstanding_commits_; | 206 size_t outstanding_commits_; |
| 222 | 207 |
| 223 // When NotifyWhenDonePendingCommitsis called |outstanding_commits_| is copied | 208 // When NotifyWhenDonePendingCommitsis called |outstanding_commits_| is copied |
| 224 // along with the |callback| into this vector. Each time | 209 // along with the |callback| into this vector. Each time |
| 225 // DidCommitAndDrawFrame is called these entries get decremented. If they hit | 210 // DidCommitAndDrawFrame is called these entries get decremented. If they hit |
| 226 // 0 the callback is triggered. | 211 // 0 the callback is triggered. |
| 227 std::vector<std::pair<size_t, base::Closure>> pending_commit_trackers_; | 212 std::vector<std::pair<size_t, base::Closure>> pending_commit_trackers_; |
| 228 | 213 |
| 229 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; | 214 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; |
| 230 | 215 |
| 231 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 216 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 232 }; | 217 }; |
| 233 | 218 |
| 234 } // namespace client | 219 } // namespace client |
| 235 } // namespace blimp | 220 } // namespace blimp |
| 236 | 221 |
| 237 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 222 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| OLD | NEW |