| 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_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 5 #ifndef BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace base { | 22 namespace base { |
| 23 class SingleThreadTaskRunner; | 23 class SingleThreadTaskRunner; |
| 24 class Thread; | 24 class Thread; |
| 25 } // namespace base | 25 } // namespace base |
| 26 | 26 |
| 27 namespace cc { | 27 namespace cc { |
| 28 namespace proto { | 28 namespace proto { |
| 29 class CompositorMessage; | 29 class CompositorMessage; |
| 30 class InitializeImpl; | 30 class InitializeImpl; |
| 31 } // namespace proto | 31 } // namespace proto |
| 32 |
| 33 class ContextProvider; |
| 32 class Layer; | 34 class Layer; |
| 33 class LayerTreeHost; | 35 class LayerTreeHost; |
| 36 class LayerTreeSettings; |
| 34 class Surface; | 37 class Surface; |
| 38 class SurfaceFactory; |
| 35 class SurfaceId; | 39 class SurfaceId; |
| 36 class SurfaceIdAllocator; | 40 class SurfaceIdAllocator; |
| 37 class SurfaceFactory; | |
| 38 class SurfaceManager; | |
| 39 } // namespace cc | 41 } // namespace cc |
| 40 | 42 |
| 41 namespace gpu { | |
| 42 class GpuMemoryBufferManager; | |
| 43 } // namespace gpu | |
| 44 | |
| 45 namespace blimp { | 43 namespace blimp { |
| 46 class BlimpMessage; | 44 class BlimpMessage; |
| 47 | 45 |
| 48 namespace client { | 46 namespace client { |
| 49 | 47 |
| 48 class BlimpCompositorDependencies; |
| 49 class CompositorDependencies; |
| 50 |
| 50 // The BlimpCompositorClient provides the BlimpCompositor with the necessary | 51 // The BlimpCompositorClient provides the BlimpCompositor with the necessary |
| 51 // dependencies for cc::LayerTreeHost owned by this compositor and for | 52 // dependencies for cc::LayerTreeHost owned by this compositor and for |
| 52 // communicating the compositor and input messages to the corresponding | 53 // communicating the compositor and input messages to the corresponding |
| 53 // render widget of this compositor on the engine. | 54 // render widget of this compositor on the engine. |
| 54 class BlimpCompositorClient { | 55 class BlimpCompositorClient { |
| 55 public: | 56 public: |
| 56 // These methods should provide the dependencies for cc::LayerTreeHost for | |
| 57 // this compositor. | |
| 58 virtual cc::LayerTreeSettings* GetLayerTreeSettings() = 0; | |
| 59 virtual scoped_refptr<base::SingleThreadTaskRunner> | |
| 60 GetCompositorTaskRunner() = 0; | |
| 61 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; | |
| 62 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; | |
| 63 virtual cc::ImageSerializationProcessor* GetImageSerializationProcessor() = 0; | |
| 64 | |
| 65 // Should send web gesture events which could not be handled locally by the | 57 // Should send web gesture events which could not be handled locally by the |
| 66 // compositor to the engine. | 58 // compositor to the engine. |
| 67 virtual void SendWebGestureEvent( | 59 virtual void SendWebGestureEvent( |
| 68 int render_widget_id, | 60 int render_widget_id, |
| 69 const blink::WebGestureEvent& gesture_event) = 0; | 61 const blink::WebGestureEvent& gesture_event) = 0; |
| 70 | 62 |
| 71 // Should send the compositor messages from the remote client LayerTreeHost of | 63 // Should send the compositor messages from the remote client LayerTreeHost of |
| 72 // this compositor to the corresponding remote server LayerTreeHost. | 64 // this compositor to the corresponding remote server LayerTreeHost. |
| 73 virtual void SendCompositorMessage( | 65 virtual void SendCompositorMessage( |
| 74 int render_widget_id, | 66 int render_widget_id, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 87 // engine. The lifetime of this compositor is controlled by its corresponding | 79 // engine. The lifetime of this compositor is controlled by its corresponding |
| 88 // RenderWidget. | 80 // RenderWidget. |
| 89 // This class should only be accessed from the main thread. | 81 // This class should only be accessed from the main thread. |
| 90 class BlimpCompositor : public cc::LayerTreeHostClient, | 82 class BlimpCompositor : public cc::LayerTreeHostClient, |
| 91 public cc::RemoteProtoChannel, | 83 public cc::RemoteProtoChannel, |
| 92 public BlimpInputManagerClient, | 84 public BlimpInputManagerClient, |
| 93 public BlimpOutputSurfaceClient, | 85 public BlimpOutputSurfaceClient, |
| 94 public cc::SurfaceFactoryClient { | 86 public cc::SurfaceFactoryClient { |
| 95 public: | 87 public: |
| 96 BlimpCompositor(const int render_widget_id, | 88 BlimpCompositor(const int render_widget_id, |
| 97 cc::SurfaceManager* surface_manager, | 89 BlimpCompositorDependencies* compositor_dependencies, |
| 98 uint32_t surface_client_id, | |
| 99 BlimpCompositorClient* client); | 90 BlimpCompositorClient* client); |
| 100 | 91 |
| 101 ~BlimpCompositor() override; | 92 ~BlimpCompositor() override; |
| 102 | 93 |
| 103 virtual void SetVisible(bool visible); | 94 virtual void SetVisible(bool visible); |
| 104 | 95 |
| 105 // Forwards the touch event to the |input_manager_|. | 96 // Forwards the touch event to the |input_manager_|. |
| 106 // virtual for testing. | 97 // virtual for testing. |
| 107 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event); | 98 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event); |
| 108 | 99 |
| 109 // Called to forward the compositor message from the remote server | 100 // Called to forward the compositor message from the remote server |
| 110 // LayerTreeHost of the render widget for this compositor. | 101 // LayerTreeHost of the render widget for this compositor. |
| 111 // virtual for testing. | 102 // virtual for testing. |
| 112 virtual void OnCompositorMessageReceived( | 103 virtual void OnCompositorMessageReceived( |
| 113 std::unique_ptr<cc::proto::CompositorMessage> message); | 104 std::unique_ptr<cc::proto::CompositorMessage> message); |
| 114 | 105 |
| 106 // Called when the a ContextProvider has been created by the |
| 107 // CompositorDependencies class. If |host_| is waiting on an OutputSurface |
| 108 // this will build one for it. |
| 109 void OnContextProviderCreated( |
| 110 const scoped_refptr<cc::ContextProvider>& provider); |
| 111 |
| 115 scoped_refptr<cc::Layer> layer() const { return layer_; } | 112 scoped_refptr<cc::Layer> layer() const { return layer_; } |
| 116 | 113 |
| 117 int render_widget_id() const { return render_widget_id_; } | 114 int render_widget_id() const { return render_widget_id_; } |
| 118 | 115 |
| 119 private: | 116 private: |
| 120 friend class BlimpCompositorForTesting; | 117 friend class BlimpCompositorForTesting; |
| 121 | 118 |
| 122 // LayerTreeHostClient implementation. | 119 // LayerTreeHostClient implementation. |
| 123 void WillBeginMainFrame() override {} | 120 void WillBeginMainFrame() override {} |
| 124 void DidBeginMainFrame() override {} | 121 void DidBeginMainFrame() override {} |
| 125 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} | 122 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} |
| 126 void BeginMainFrameNotExpectedSoon() override {} | 123 void BeginMainFrameNotExpectedSoon() override {} |
| 127 void UpdateLayerTreeHost() override {} | 124 void UpdateLayerTreeHost() override {} |
| 128 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 125 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 129 const gfx::Vector2dF& outer_delta, | 126 const gfx::Vector2dF& outer_delta, |
| 130 const gfx::Vector2dF& elastic_overscroll_delta, | 127 const gfx::Vector2dF& elastic_overscroll_delta, |
| 131 float page_scale, | 128 float page_scale, |
| 132 float top_controls_delta) override {} | 129 float top_controls_delta) override {} |
| 133 void RequestNewOutputSurface() override; | 130 void RequestNewOutputSurface() override; |
| 131 void DidInitializeOutputSurface() override; |
| 134 // TODO(khushalsagar): Need to handle context initialization failures. | 132 // TODO(khushalsagar): Need to handle context initialization failures. |
| 135 void DidInitializeOutputSurface() override {} | |
| 136 void DidFailToInitializeOutputSurface() override {} | 133 void DidFailToInitializeOutputSurface() override {} |
| 137 void WillCommit() override {} | 134 void WillCommit() override {} |
| 138 void DidCommit() override {} | 135 void DidCommit() override {} |
| 139 void DidCommitAndDrawFrame() override; | 136 void DidCommitAndDrawFrame() override; |
| 140 void DidCompleteSwapBuffers() override {} | 137 void DidCompleteSwapBuffers() override {} |
| 141 void DidCompletePageScaleAnimation() override {} | 138 void DidCompletePageScaleAnimation() override {} |
| 142 | 139 |
| 143 // RemoteProtoChannel implementation. | 140 // RemoteProtoChannel implementation. |
| 144 void SetProtoReceiver(ProtoReceiver* receiver) override; | 141 void SetProtoReceiver(ProtoReceiver* receiver) override; |
| 145 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | 142 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 146 | 143 |
| 147 // BlimpInputManagerClient implementation. | 144 // BlimpInputManagerClient implementation. |
| 148 void SendWebGestureEvent( | 145 void SendWebGestureEvent( |
| 149 const blink::WebGestureEvent& gesture_event) override; | 146 const blink::WebGestureEvent& gesture_event) override; |
| 150 | 147 |
| 151 // BlimpOutputSurfaceClient implementation. | 148 // BlimpOutputSurfaceClient implementation. |
| 152 void BindToOutputSurface( | 149 void BindToOutputSurface( |
| 153 base::WeakPtr<BlimpOutputSurface> output_surface) override; | 150 base::WeakPtr<BlimpOutputSurface> output_surface) override; |
| 154 void SwapCompositorFrame(cc::CompositorFrame frame) override; | 151 void SwapCompositorFrame(cc::CompositorFrame frame) override; |
| 155 void UnbindOutputSurface() override; | 152 void UnbindOutputSurface() override; |
| 156 | 153 |
| 157 // SurfaceFactoryClient implementation. | 154 // SurfaceFactoryClient implementation. |
| 158 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | 155 void ReturnResources(const cc::ReturnedResourceArray& resources) override; |
| 159 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} | 156 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} |
| 160 | 157 |
| 158 // Helper method to get the embedder dependencies. |
| 159 CompositorDependencies* GetEmbedderDeps(); |
| 160 |
| 161 // TODO(khushalsagar): Move all of this to the |DocumentView| or another | 161 // TODO(khushalsagar): Move all of this to the |DocumentView| or another |
| 162 // platform specific class. So we use the DelegatedFrameHostAndroid like the | 162 // platform specific class. So we use the DelegatedFrameHostAndroid like the |
| 163 // RenderWidgetHostViewAndroid. | 163 // RenderWidgetHostViewAndroid. |
| 164 void DestroyDelegatedContent(); | 164 void DestroyDelegatedContent(); |
| 165 | 165 |
| 166 // Helper method to build the internal CC LayerTreeHost instance from | 166 // Helper method to build the internal CC LayerTreeHost instance from |
| 167 // |message|. | 167 // |message|. |
| 168 void CreateLayerTreeHost( | 168 void CreateLayerTreeHost( |
| 169 const cc::proto::InitializeImpl& initialize_message); | 169 const cc::proto::InitializeImpl& initialize_message); |
| 170 | 170 |
| 171 // Helper method to destroy the internal CC LayerTreeHost instance and all its | 171 // Helper method to destroy the internal CC LayerTreeHost instance and all its |
| 172 // associated state. | 172 // associated state. |
| 173 void DestroyLayerTreeHost(); | 173 void DestroyLayerTreeHost(); |
| 174 | 174 |
| 175 // The unique identifier for the render widget for this compositor. | 175 // The unique identifier for the render widget for this compositor. |
| 176 const int render_widget_id_; | 176 const int render_widget_id_; |
| 177 | 177 |
| 178 BlimpCompositorClient* client_; | 178 BlimpCompositorClient* client_; |
| 179 | 179 |
| 180 BlimpCompositorDependencies* compositor_dependencies_; |
| 181 |
| 180 std::unique_ptr<cc::LayerTreeHost> host_; | 182 std::unique_ptr<cc::LayerTreeHost> host_; |
| 181 | 183 |
| 182 // Whether or not |host_| should be visible. This is stored in case |host_| | 184 // Whether or not |host_| should be visible. This is stored in case |host_| |
| 183 // is null when SetVisible() is called. | 185 // is null when SetVisible() is called. |
| 184 bool host_should_be_visible_; | 186 bool host_should_be_visible_; |
| 185 | 187 |
| 186 // The SurfaceFactory is bound to the lifetime of the BlimpOutputSurface. When | 188 // The SurfaceFactory is bound to the lifetime of the BlimpOutputSurface. When |
| 187 // detached, the surface factory will be destroyed. | 189 // detached, the surface factory will be destroyed. |
| 188 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | 190 std::unique_ptr<cc::SurfaceFactory> surface_factory_; |
| 189 base::WeakPtr<BlimpOutputSurface> output_surface_; | 191 base::WeakPtr<BlimpOutputSurface> output_surface_; |
| 190 | 192 |
| 193 // Whether or not |host_| has asked for an output surface. |
| 194 bool output_surface_request_pending_; |
| 195 |
| 191 // Data for the current frame. | 196 // Data for the current frame. |
| 192 cc::SurfaceId surface_id_; | 197 cc::SurfaceId surface_id_; |
| 193 gfx::Size current_surface_size_; | 198 gfx::Size current_surface_size_; |
| 194 | 199 |
| 195 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
| 196 base::ThreadChecker thread_checker_; | 200 base::ThreadChecker thread_checker_; |
| 197 | 201 |
| 198 // Surfaces related stuff and layer which holds the delegated content from the | 202 // Surfaces related stuff and layer which holds the delegated content from the |
| 199 // compositor. | 203 // compositor. |
| 200 cc::SurfaceManager* surface_manager_; | |
| 201 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | 204 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; |
| 202 scoped_refptr<cc::Layer> layer_; | 205 scoped_refptr<cc::Layer> layer_; |
| 203 | 206 |
| 204 // To be notified of any incoming compositor protos that are specifically sent | 207 // To be notified of any incoming compositor protos that are specifically sent |
| 205 // to |render_widget_id_|. | 208 // to |render_widget_id_|. |
| 206 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; | 209 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; |
| 207 | 210 |
| 208 // Handles input events for the current render widget. The lifetime of the | 211 // Handles input events for the current render widget. The lifetime of the |
| 209 // input manager is tied to the lifetime of the |host_| which owns the | 212 // input manager is tied to the lifetime of the |host_| which owns the |
| 210 // cc::InputHandler. The input events are forwarded to this input handler by | 213 // cc::InputHandler. The input events are forwarded to this input handler by |
| 211 // the manager to be handled by the client compositor for the current render | 214 // the manager to be handled by the client compositor for the current render |
| 212 // widget. | 215 // widget. |
| 213 std::unique_ptr<BlimpInputManager> input_manager_; | 216 std::unique_ptr<BlimpInputManager> input_manager_; |
| 214 | 217 |
| 215 base::WeakPtrFactory<BlimpCompositor> weak_factory_; | 218 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; |
| 216 | 219 |
| 217 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 220 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 218 }; | 221 }; |
| 219 | 222 |
| 220 } // namespace client | 223 } // namespace client |
| 221 } // namespace blimp | 224 } // namespace blimp |
| 222 | 225 |
| 223 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 226 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| OLD | NEW |