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_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 #include <vector> | |
| 10 | 9 |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "blimp/client/core/compositor/output_surface_proxy.h" | |
| 13 #include "blimp/client/feature/compositor/blimp_input_manager.h" | 13 #include "blimp/client/feature/compositor/blimp_input_manager.h" |
| 14 #include "cc/surfaces/surface_factory_client.h" | |
| 14 #include "cc/trees/layer_tree_host.h" | 15 #include "cc/trees/layer_tree_host.h" |
| 15 #include "cc/trees/layer_tree_host_client.h" | 16 #include "cc/trees/layer_tree_host_client.h" |
| 16 #include "cc/trees/layer_tree_settings.h" | 17 #include "cc/trees/layer_tree_settings.h" |
| 17 #include "cc/trees/remote_proto_channel.h" | 18 #include "cc/trees/remote_proto_channel.h" |
| 18 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 19 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class SingleThreadTaskRunner; | 23 class SingleThreadTaskRunner; |
| 23 class Thread; | 24 class Thread; |
| 24 } | 25 } // namespace base |
| 25 | 26 |
| 26 namespace cc { | 27 namespace cc { |
| 27 namespace proto { | 28 namespace proto { |
| 28 class CompositorMessage; | 29 class CompositorMessage; |
| 29 class InitializeImpl; | 30 class InitializeImpl; |
| 30 } | 31 } |
|
David Trainor- moved to gerrit
2016/08/22 23:58:10
I've heard for small forward declaration namespace
Khushal
2016/08/23 02:53:11
Its nice to do that. Done.
| |
| 32 class Layer; | |
| 31 class LayerTreeHost; | 33 class LayerTreeHost; |
| 32 } | 34 class Surface; |
| 35 class SurfaceId; | |
| 36 class SurfaceIdAllocator; | |
| 37 class SurfaceFactory; | |
| 38 class SurfaceManager; | |
| 39 } // namespace cc | |
| 33 | 40 |
| 34 namespace blimp { | 41 namespace blimp { |
| 35 | |
| 36 class BlimpMessage; | 42 class BlimpMessage; |
| 37 | 43 |
| 38 namespace client { | 44 namespace client { |
| 45 class BlimpGpuMemoryBufferManager; | |
|
David Trainor- moved to gerrit
2016/08/22 23:58:10
Why the Blimp subclass?
Khushal
2016/08/23 02:53:12
Actually Not here. Its needed in the manager for t
| |
| 39 | 46 |
| 40 // The BlimpCompositorClient provides the BlimpCompositor with the necessary | 47 // The BlimpCompositorClient provides the BlimpCompositor with the necessary |
| 41 // dependencies for cc::LayerTreeHost owned by this compositor and for | 48 // dependencies for cc::LayerTreeHost owned by this compositor and for |
| 42 // communicating the compositor and input messages to the corresponding | 49 // communicating the compositor and input messages to the corresponding |
| 43 // render widget of this compositor on the engine. | 50 // render widget of this compositor on the engine. |
| 44 class BlimpCompositorClient { | 51 class BlimpCompositorClient { |
| 45 public: | 52 public: |
| 46 // These methods should provide the dependencies for cc::LayerTreeHost for | 53 // These methods should provide the dependencies for cc::LayerTreeHost for |
| 47 // this compositor. | 54 // this compositor. |
| 48 virtual cc::LayerTreeSettings* GetLayerTreeSettings() = 0; | 55 virtual cc::LayerTreeSettings* GetLayerTreeSettings() = 0; |
| 49 virtual scoped_refptr<base::SingleThreadTaskRunner> | 56 virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 50 GetCompositorTaskRunner() = 0; | 57 GetCompositorTaskRunner() = 0; |
| 51 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; | 58 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; |
| 52 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; | 59 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; |
| 53 virtual cc::ImageSerializationProcessor* GetImageSerializationProcessor() = 0; | 60 virtual cc::ImageSerializationProcessor* GetImageSerializationProcessor() = 0; |
| 54 virtual void DidCompleteSwapBuffers() = 0; | |
| 55 virtual void DidCommitAndDrawFrame() = 0; | |
| 56 | 61 |
| 57 // Should send web gesture events which could not be handled locally by the | 62 // Should send web gesture events which could not be handled locally by the |
| 58 // compositor to the engine. | 63 // compositor to the engine. |
| 59 virtual void SendWebGestureEvent( | 64 virtual void SendWebGestureEvent( |
| 60 int render_widget_id, | 65 int render_widget_id, |
| 61 const blink::WebGestureEvent& gesture_event) = 0; | 66 const blink::WebGestureEvent& gesture_event) = 0; |
| 62 | 67 |
| 63 // Should send the compositor messages from the remote client LayerTreeHost of | 68 // Should send the compositor messages from the remote client LayerTreeHost of |
| 64 // this compositor to the corresponding remote server LayerTreeHost. | 69 // this compositor to the corresponding remote server LayerTreeHost. |
| 65 virtual void SendCompositorMessage( | 70 virtual void SendCompositorMessage( |
| 66 int render_widget_id, | 71 int render_widget_id, |
| 67 const cc::proto::CompositorMessage& message) = 0; | 72 const cc::proto::CompositorMessage& message) = 0; |
| 68 | 73 |
| 69 protected: | 74 protected: |
| 70 virtual ~BlimpCompositorClient() {} | 75 virtual ~BlimpCompositorClient() {} |
| 71 }; | 76 }; |
| 72 | 77 |
| 73 // BlimpCompositor provides the basic framework and setup to host a | 78 // BlimpCompositor provides the basic framework and setup to host a |
| 74 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the | 79 // LayerTreeHost. This class owns the remote client cc::LayerTreeHost, which |
| 75 // compositor, but the LayerTreeHost does the compositing work. The rendering | 80 // performs the compositing work for the remote server LayerTreeHost. The server |
| 76 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set | |
| 77 // by SetAcceleratedWidget(). This class should only be accessed from the main | |
| 78 // thread. Any interaction with the compositing thread should happen through | |
| 79 // the LayerTreeHost. | |
| 80 // | |
| 81 // The Blimp compositor owns the remote client cc::LayerTreeHost, which performs | |
| 82 // the compositing work for the remote server LayerTreeHost. The server | |
| 83 // LayerTreeHost for a BlimpCompositor is owned by the | 81 // LayerTreeHost for a BlimpCompositor is owned by the |
| 84 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a | 82 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a |
| 85 // RenderWidget, identified by a custom |render_widget_id| generated on the | 83 // RenderWidget, identified by a custom |render_widget_id| generated on the |
| 86 // engine. The lifetime of this compositor is controlled by its corresponding | 84 // engine. The lifetime of this compositor is controlled by its corresponding |
| 87 // RenderWidget. | 85 // RenderWidget. |
| 88 class BlimpCompositor | 86 // This class should only be accessed from the main thread. |
| 89 : public cc::LayerTreeHostClient, | 87 class BlimpCompositor : public cc::LayerTreeHostClient, |
| 90 public cc::RemoteProtoChannel, | 88 public cc::RemoteProtoChannel, |
| 91 public BlimpInputManagerClient { | 89 public BlimpInputManagerClient, |
| 90 public OutputSurfaceProxy, | |
| 91 public cc::SurfaceFactoryClient { | |
| 92 public: | 92 public: |
| 93 BlimpCompositor(const int render_widget_id, BlimpCompositorClient* client); | 93 BlimpCompositor(const int render_widget_id, |
| 94 cc::SurfaceManager* surface_manager, | |
| 95 uint32_t surface_client_id, | |
| 96 BlimpCompositorClient* client); | |
| 94 | 97 |
| 95 ~BlimpCompositor() override; | 98 ~BlimpCompositor() override; |
| 96 | 99 |
| 97 // Sets whether or not this compositor actually draws to the output surface. | |
| 98 // Setting this to false will make the compositor drop all of its resources | |
| 99 // and the output surface. Setting it to true again will rebuild the output | |
| 100 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget). | |
| 101 // virtual for testing. | |
| 102 virtual void SetVisible(bool visible); | 100 virtual void SetVisible(bool visible); |
| 103 | 101 |
| 104 // Lets this compositor know that it can draw to |widget|. This means that, | |
| 105 // if this compositor is visible, it will build an output surface and GL | |
| 106 // context around |widget| and will draw to it. ReleaseAcceleratedWidget() | |
| 107 // *must* be called before SetAcceleratedWidget() is called with the same | |
| 108 // gfx::AcceleratedWidget on another compositor. | |
| 109 // virtual for testing. | |
| 110 virtual void SetAcceleratedWidget(gfx::AcceleratedWidget widget); | |
| 111 | |
| 112 // Releases the internally stored gfx::AcceleratedWidget and the associated | |
| 113 // output surface. This must be called before calling | |
| 114 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another | |
| 115 // compositor. | |
| 116 // virtual for testing. | |
| 117 virtual void ReleaseAcceleratedWidget(); | |
| 118 | |
| 119 // Forwards the touch event to the |input_manager_|. | 102 // Forwards the touch event to the |input_manager_|. |
| 120 // virtual for testing. | 103 // virtual for testing. |
| 121 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event); | 104 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event); |
| 122 | 105 |
| 123 // Called to forward the compositor message from the remote server | 106 // Called to forward the compositor message from the remote server |
| 124 // LayerTreeHost of the render widget for this compositor. | 107 // LayerTreeHost of the render widget for this compositor. |
| 125 // virtual for testing. | 108 // virtual for testing. |
| 126 virtual void OnCompositorMessageReceived( | 109 virtual void OnCompositorMessageReceived( |
| 127 std::unique_ptr<cc::proto::CompositorMessage> message); | 110 std::unique_ptr<cc::proto::CompositorMessage> message); |
| 128 | 111 |
| 112 scoped_refptr<cc::Layer> layer() const { return layer_; } | |
| 113 | |
| 129 int render_widget_id() const { return render_widget_id_; } | 114 int render_widget_id() const { return render_widget_id_; } |
| 130 | 115 |
| 131 private: | 116 private: |
| 132 friend class BlimpCompositorForTesting; | 117 friend class BlimpCompositorForTesting; |
| 133 | 118 |
| 134 // LayerTreeHostClient implementation. | 119 // LayerTreeHostClient implementation. |
| 135 void WillBeginMainFrame() override; | 120 void WillBeginMainFrame() override {} |
|
David Trainor- moved to gerrit
2016/08/22 23:58:10
w00t so much nicer!
Khushal
2016/08/23 02:53:11
:D
| |
| 136 void DidBeginMainFrame() override; | 121 void DidBeginMainFrame() override {} |
| 137 void BeginMainFrame(const cc::BeginFrameArgs& args) override; | 122 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} |
| 138 void BeginMainFrameNotExpectedSoon() override; | 123 void BeginMainFrameNotExpectedSoon() override {} |
| 139 void UpdateLayerTreeHost() override; | 124 void UpdateLayerTreeHost() override {} |
| 140 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 125 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 141 const gfx::Vector2dF& outer_delta, | 126 const gfx::Vector2dF& outer_delta, |
| 142 const gfx::Vector2dF& elastic_overscroll_delta, | 127 const gfx::Vector2dF& elastic_overscroll_delta, |
| 143 float page_scale, | 128 float page_scale, |
| 144 float top_controls_delta) override; | 129 float top_controls_delta) override {} |
| 145 void RequestNewOutputSurface() override; | 130 void RequestNewOutputSurface() override; |
| 146 void DidInitializeOutputSurface() override; | 131 // TODO(khushalsagar): Need to handle context initialization failures. |
| 147 void DidFailToInitializeOutputSurface() override; | 132 void DidInitializeOutputSurface() override {} |
| 148 void WillCommit() override; | 133 void DidFailToInitializeOutputSurface() override {} |
| 149 void DidCommit() override; | 134 void WillCommit() override {} |
| 135 void DidCommit() override {} | |
| 150 void DidCommitAndDrawFrame() override; | 136 void DidCommitAndDrawFrame() override; |
| 151 void DidCompleteSwapBuffers() override; | 137 void DidCompleteSwapBuffers() override {} |
| 152 void DidCompletePageScaleAnimation() override; | 138 void DidCompletePageScaleAnimation() override {} |
| 153 | 139 |
| 154 // RemoteProtoChannel implementation. | 140 // RemoteProtoChannel implementation. |
| 155 void SetProtoReceiver(ProtoReceiver* receiver) override; | 141 void SetProtoReceiver(ProtoReceiver* receiver) override; |
| 156 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | 142 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 157 | 143 |
| 158 // BlimpInputManagerClient implementation. | 144 // BlimpInputManagerClient implementation. |
| 159 void SendWebGestureEvent( | 145 void SendWebGestureEvent( |
| 160 const blink::WebGestureEvent& gesture_event) override; | 146 const blink::WebGestureEvent& gesture_event) override; |
| 161 | 147 |
| 162 // Internal method to correctly set the visibility on the |host_|. It will | 148 // OutputSurfaceProxy implementation. |
| 163 // make the |host_| visible if |visible| is true and we have a valid |window_| | 149 void BindToClient(base::WeakPtr<OutputSurfaceProxyClient> client) override; |
| 164 // If |visible_| is false, the host will also release its output surface. | 150 void SwapCompositorFrame(cc::CompositorFrame frame) override; |
| 165 void SetVisibleInternal(bool visible); | 151 void DetachFromClient() override; |
| 166 | 152 |
| 167 // Helper method to build the internal CC compositor instance from |message|. | 153 // SurfaceFactoryClient implementation. |
| 154 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | |
| 155 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} | |
| 156 | |
| 157 // TODO(khushalsagar): Move all of this to the |DocumentView| or another | |
| 158 // platform specific class. So we use the DelegatedFrameHostAndroid like the | |
| 159 // RenderWidgetHostViewAndroid. | |
| 160 void DestroyDelegatedContent(); | |
| 161 | |
| 162 // Helper method to build the internal CC LayerTreeHost instance from | |
| 163 // |message|. | |
| 168 void CreateLayerTreeHost( | 164 void CreateLayerTreeHost( |
| 169 const cc::proto::InitializeImpl& initialize_message); | 165 const cc::proto::InitializeImpl& initialize_message); |
| 170 | 166 |
| 171 // Helper method to destroy the internal CC compositor instance and all its | 167 // Helper method to destroy the internal CC LayerTreeHost instance and all its |
| 172 // associated state. | 168 // associated state. |
| 173 void DestroyLayerTreeHost(); | 169 void DestroyLayerTreeHost(); |
| 174 | 170 |
| 175 // Creates (if necessary) and returns a TaskRunner for a thread meant to run | |
| 176 // compositor rendering. | |
| 177 void HandlePendingOutputSurfaceRequest(); | |
| 178 | |
| 179 // The unique identifier for the render widget for this compositor. | 171 // The unique identifier for the render widget for this compositor. |
| 180 const int render_widget_id_; | 172 const int render_widget_id_; |
| 181 | 173 |
| 182 BlimpCompositorClient* client_; | 174 BlimpCompositorClient* client_; |
| 183 | 175 |
| 184 std::unique_ptr<cc::LayerTreeHost> host_; | 176 std::unique_ptr<cc::LayerTreeHost> host_; |
| 185 | 177 |
| 186 gfx::AcceleratedWidget window_; | |
| 187 | |
| 188 // Whether or not |host_| should be visible. This is stored in case |host_| | 178 // Whether or not |host_| should be visible. This is stored in case |host_| |
| 189 // is null when SetVisible() is called or if we don't have a | 179 // is null when SetVisible() is called. |
| 190 // gfx::AcceleratedWidget to build an output surface from. | |
| 191 bool host_should_be_visible_; | 180 bool host_should_be_visible_; |
| 192 | 181 |
| 193 // Whether there is an OutputSurface request pending from the current | 182 // The SurfaceFactory is bound to the lifetime of the |
| 194 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| | 183 // OutputSurfaceProxyClient. When detached, the surface factory will be |
| 195 // if |host_| is deleted or we succeed in creating *and* initializing an | 184 // destroyed. |
| 196 // OutputSurface (which is essentially the contract with cc). | 185 std::unique_ptr<cc::SurfaceFactory> surface_factory_; |
| 197 bool output_surface_request_pending_; | 186 base::WeakPtr<OutputSurfaceProxyClient> output_surface_proxy_client_; |
| 187 | |
| 188 // Data for the current frame. | |
| 189 cc::SurfaceId surface_id_; | |
| 190 gfx::Size current_surface_size_; | |
| 191 | |
| 192 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
| 193 | |
| 194 base::ThreadChecker thread_checker_; | |
| 195 | |
| 196 // Surfaces related stuff and layer which holds the delegated content from the | |
| 197 // compositor. | |
| 198 cc::SurfaceManager* surface_manager_; | |
| 199 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | |
| 200 scoped_refptr<cc::Layer> layer_; | |
| 198 | 201 |
| 199 // To be notified of any incoming compositor protos that are specifically sent | 202 // To be notified of any incoming compositor protos that are specifically sent |
| 200 // to |render_widget_id_|. | 203 // to |render_widget_id_|. |
| 201 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; | 204 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; |
| 202 | 205 |
| 203 // Handles input events for the current render widget. The lifetime of the | 206 // Handles input events for the current render widget. The lifetime of the |
| 204 // input manager is tied to the lifetime of the |host_| which owns the | 207 // input manager is tied to the lifetime of the |host_| which owns the |
| 205 // cc::InputHandler. The input events are forwarded to this input handler by | 208 // cc::InputHandler. The input events are forwarded to this input handler by |
| 206 // the manager to be handled by the client compositor for the current render | 209 // the manager to be handled by the client compositor for the current render |
| 207 // widget. | 210 // widget. |
| 208 std::unique_ptr<BlimpInputManager> input_manager_; | 211 std::unique_ptr<BlimpInputManager> input_manager_; |
| 209 | 212 |
| 213 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; | |
| 214 | |
| 210 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 215 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 211 }; | 216 }; |
| 212 | 217 |
| 213 } // namespace client | 218 } // namespace client |
| 214 } // namespace blimp | 219 } // namespace blimp |
| 215 | 220 |
| 216 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 221 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| OLD | NEW |