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_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
6 #define BLIMP_CLIENT_FEATURE_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/gtest_prod_util.h" | |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "blimp/client/feature/compositor/blimp_input_manager.h" | 14 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" |
15 #include "blimp/client/core/input/blimp_input_manager.h" | |
14 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
15 #include "cc/trees/layer_tree_host_client.h" | 17 #include "cc/trees/layer_tree_host_client.h" |
16 #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/native_widget_types.h" | |
20 | 19 |
21 namespace base { | 20 namespace base { |
22 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
23 class Thread; | 22 class Thread; |
24 } | 23 } // namespace base |
25 | 24 |
26 namespace cc { | 25 namespace cc { |
27 namespace proto { | 26 namespace proto { |
28 class CompositorMessage; | 27 class CompositorMessage; |
29 class InitializeImpl; | 28 class InitializeImpl; |
30 } | 29 } // namespace proto |
30 | |
31 class ImageSerializationProcessor; | |
31 class LayerTreeHost; | 32 class LayerTreeHost; |
32 } | 33 class LayerTreeSettings; |
34 class TaskGraphRunner; | |
35 } // namespace cc | |
36 | |
37 namespace gpu { | |
38 class GpuMemoryBufferManager; | |
39 } // namespace gpu | |
33 | 40 |
34 namespace blimp { | 41 namespace blimp { |
35 | 42 |
36 class BlimpMessage; | 43 class BlimpMessage; |
37 | 44 |
38 namespace client { | 45 namespace client { |
46 class BlimpInputManager; | |
39 | 47 |
40 // The BlimpCompositorClient provides the BlimpCompositor with the necessary | 48 // The BlimpCompositorClient provides the BlimpCompositor with the necessary |
41 // dependencies for cc::LayerTreeHost owned by this compositor and for | 49 // dependencies for communicating the compositor and input messages to the |
42 // communicating the compositor and input messages to the corresponding | 50 // corresponding render widget of this compositor on the engine. |
43 // 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 virtual ~BlimpCompositorClient() {} |
47 // this compositor. | 54 |
48 virtual cc::LayerTreeSettings* GetLayerTreeSettings() = 0; | |
49 virtual scoped_refptr<base::SingleThreadTaskRunner> | |
50 GetCompositorTaskRunner() = 0; | |
51 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; | |
52 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; | |
53 virtual cc::ImageSerializationProcessor* GetImageSerializationProcessor() = 0; | |
54 virtual void DidCompleteSwapBuffers() = 0; | 55 virtual void DidCompleteSwapBuffers() = 0; |
56 | |
57 // Called when a compositor frame update from the engine is committed. | |
58 // TODO(khushalsagar): Don't listen to commits directly once a remote | |
59 // compositor is used. This method is used for tracking the number of frame | |
60 // updates from the engine, don't want to mix that with local commits. | |
55 virtual void DidCommitAndDrawFrame() = 0; | 61 virtual void DidCommitAndDrawFrame() = 0; |
56 | 62 |
57 // Should send web gesture events which could not be handled locally by the | 63 // Should send web gesture events which could not be handled locally by the |
58 // compositor to the engine. | 64 // compositor to the engine. |
59 virtual void SendWebGestureEvent( | 65 virtual void SendWebGestureEvent( |
60 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, | |
67 const cc::proto::CompositorMessage& message) = 0; | 71 const cc::proto::CompositorMessage& message) = 0; |
68 | 72 |
69 protected: | 73 virtual void RequestOutputSurface() = 0; |
70 virtual ~BlimpCompositorClient() {} | |
71 }; | 74 }; |
72 | 75 |
73 // BlimpCompositor provides the basic framework and setup to host a | 76 // BlimpCompositor provides the basic framework and setup to host a |
74 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the | 77 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the |
75 // compositor, but the LayerTreeHost does the compositing work. The rendering | 78 // compositor, but the LayerTreeHost does the compositing work. The rendering |
76 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set | 79 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set |
77 // by SetAcceleratedWidget(). This class should only be accessed from the main | 80 // by SetAcceleratedWidget(). This class should only be accessed from the main |
78 // thread. Any interaction with the compositing thread should happen through | 81 // thread. Any interaction with the compositing thread should happen through |
79 // the LayerTreeHost. | 82 // the LayerTreeHost. |
80 // | 83 // |
81 // The Blimp compositor owns the remote client cc::LayerTreeHost, which performs | 84 // The Blimp compositor owns the remote client cc::LayerTreeHost, which performs |
82 // the compositing work for the remote server LayerTreeHost. The server | 85 // the compositing work for the remote server LayerTreeHost. The server |
83 // LayerTreeHost for a BlimpCompositor is owned by the | 86 // LayerTreeHost for a BlimpCompositor is owned by the |
84 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a | 87 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a |
85 // RenderWidget, identified by a custom |render_widget_id| generated on the | 88 // RenderWidget, identified by a custom |render_widget_id| generated on the |
86 // engine. The lifetime of this compositor is controlled by its corresponding | 89 // engine. The lifetime of this compositor is controlled by its corresponding |
87 // RenderWidget. | 90 // RenderWidget. |
88 class BlimpCompositor | 91 class BlimpCompositor : public cc::LayerTreeHostClient, |
89 : public cc::LayerTreeHostClient, | 92 public cc::RemoteProtoChannel, |
90 public cc::RemoteProtoChannel, | 93 public BlimpInputManagerClient { |
91 public BlimpInputManagerClient { | |
92 public: | 94 public: |
93 BlimpCompositor(const int render_widget_id, BlimpCompositorClient* client); | 95 BlimpCompositor( |
96 cc::TaskGraphRunner* task_graph_runner, | |
97 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
98 cc::ImageSerializationProcessor* image_serialization_processor, | |
99 cc::LayerTreeSettings* settings, | |
100 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | |
101 BlimpCompositorClient* client); | |
94 | 102 |
95 ~BlimpCompositor() override; | 103 ~BlimpCompositor() override; |
96 | 104 |
97 // Sets whether or not this compositor actually draws to the output surface. | 105 void SetVisible(bool visible); |
98 // Setting this to false will make the compositor drop all of its resources | 106 bool IsVisible() const; |
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); | |
103 | 107 |
104 // Lets this compositor know that it can draw to |widget|. This means that, | 108 void SetOutputSurface(std::unique_ptr<cc::OutputSurface> output_surface); |
105 // if this compositor is visible, it will build an output surface and GL | 109 void ReleaseOutputSurface(); |
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 | 110 |
112 // Releases the internally stored gfx::AcceleratedWidget and the associated | 111 BlimpInputManager* input_manager() const { return input_manager_.get(); } |
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_|. | |
120 // virtual for testing. | |
121 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event); | |
122 | 112 |
123 // Called to forward the compositor message from the remote server | 113 // Called to forward the compositor message from the remote server |
124 // LayerTreeHost of the render widget for this compositor. | 114 // LayerTreeHost of the render widget for this compositor. |
125 // virtual for testing. | 115 // virtual for testing. |
126 virtual void OnCompositorMessageReceived( | 116 virtual void OnCompositorMessageReceived( |
127 std::unique_ptr<cc::proto::CompositorMessage> message); | 117 std::unique_ptr<cc::proto::CompositorMessage> message); |
128 | 118 |
129 int render_widget_id() const { return render_widget_id_; } | 119 cc::LayerTreeHost* GetHostForTesting() const { return host_.get(); } |
130 | 120 |
131 private: | 121 private: |
132 friend class BlimpCompositorForTesting; | |
133 | |
134 // LayerTreeHostClient implementation. | 122 // LayerTreeHostClient implementation. |
135 void WillBeginMainFrame() override; | 123 void WillBeginMainFrame() override; |
136 void DidBeginMainFrame() override; | 124 void DidBeginMainFrame() override; |
137 void BeginMainFrame(const cc::BeginFrameArgs& args) override; | 125 void BeginMainFrame(const cc::BeginFrameArgs& args) override; |
138 void BeginMainFrameNotExpectedSoon() override; | 126 void BeginMainFrameNotExpectedSoon() override; |
139 void UpdateLayerTreeHost() override; | 127 void UpdateLayerTreeHost() override; |
140 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 128 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
141 const gfx::Vector2dF& outer_delta, | 129 const gfx::Vector2dF& outer_delta, |
142 const gfx::Vector2dF& elastic_overscroll_delta, | 130 const gfx::Vector2dF& elastic_overscroll_delta, |
143 float page_scale, | 131 float page_scale, |
144 float top_controls_delta) override; | 132 float top_controls_delta) override; |
145 void RequestNewOutputSurface() override; | 133 void RequestNewOutputSurface() override; |
146 void DidInitializeOutputSurface() override; | 134 void DidInitializeOutputSurface() override; |
147 void DidFailToInitializeOutputSurface() override; | 135 void DidFailToInitializeOutputSurface() override; |
148 void WillCommit() override; | 136 void WillCommit() override; |
149 void DidCommit() override; | 137 void DidCommit() override; |
150 void DidCommitAndDrawFrame() override; | 138 void DidCommitAndDrawFrame() override; |
151 void DidCompleteSwapBuffers() override; | 139 void DidCompleteSwapBuffers() override; |
152 void DidCompletePageScaleAnimation() override; | 140 void DidCompletePageScaleAnimation() override; |
153 | 141 |
154 // RemoteProtoChannel implementation. | 142 // RemoteProtoChannel implementation. |
155 void SetProtoReceiver(ProtoReceiver* receiver) override; | 143 void SetProtoReceiver(ProtoReceiver* receiver) override; |
156 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | 144 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
157 | 145 |
158 // BlimpInputManagerClient implementation. | 146 // BlimpInputManagerClient implementation. |
159 void SendWebGestureEvent( | 147 void SendWebGestureEvent( |
160 const blink::WebGestureEvent& gesture_event) override; | 148 const blink::WebGestureEvent& gesture_event) override; |
161 | 149 |
162 // Internal method to correctly set the visibility on the |host_|. It will | 150 // Helper method to build the internal CC compositor . |
163 // make the |host_| visible if |visible| is true and we have a valid |window_| | 151 void CreateLayerTreeHost(); |
164 // If |visible_| is false, the host will also release its output surface. | |
165 void SetVisibleInternal(bool visible); | |
166 | |
167 // Helper method to build the internal CC compositor instance from |message|. | |
168 void CreateLayerTreeHost( | |
169 const cc::proto::InitializeImpl& initialize_message); | |
170 | 152 |
171 // Helper method to destroy the internal CC compositor instance and all its | 153 // Helper method to destroy the internal CC compositor instance and all its |
172 // associated state. | 154 // associated state. |
173 void DestroyLayerTreeHost(); | 155 void DestroyLayerTreeHost(); |
174 | 156 |
175 // Creates (if necessary) and returns a TaskRunner for a thread meant to run | 157 cc::TaskGraphRunner* task_graph_runner_; |
nyquist
2016/08/12 07:34:28
It is possible to add comments for these for layme
Khushal
2016/08/13 00:03:22
Good idea. Done.
| |
176 // compositor rendering. | 158 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; |
177 void HandlePendingOutputSurfaceRequest(); | 159 cc::ImageSerializationProcessor* image_serialization_processor_; |
178 | 160 cc::LayerTreeSettings* settings_; |
179 // The unique identifier for the render widget for this compositor. | 161 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
180 const int render_widget_id_; | |
181 | |
182 BlimpCompositorClient* client_; | 162 BlimpCompositorClient* client_; |
183 | 163 |
184 std::unique_ptr<cc::LayerTreeHost> host_; | 164 std::unique_ptr<cc::LayerTreeHost> host_; |
185 | |
186 gfx::AcceleratedWidget window_; | |
187 | |
188 // 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 | |
190 // gfx::AcceleratedWidget to build an output surface from. | |
191 bool host_should_be_visible_; | 165 bool host_should_be_visible_; |
192 | 166 |
193 // Whether there is an OutputSurface request pending from the current | |
194 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| | |
195 // if |host_| is deleted or we succeed in creating *and* initializing an | |
196 // OutputSurface (which is essentially the contract with cc). | |
197 bool output_surface_request_pending_; | |
198 | |
199 // To be notified of any incoming compositor protos that are specifically sent | 167 // To be notified of any incoming compositor protos that are specifically sent |
200 // to |render_widget_id_|. | 168 // to |render_widget_id_|. |
201 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; | 169 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; |
202 | 170 |
203 // Handles input events for the current render widget. The lifetime of the | 171 // 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 | 172 // 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 | 173 // 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 | 174 // the manager to be handled by the client compositor for the current render |
207 // widget. | 175 // widget. |
176 // TODO(khushalsagar): Move this out to the render widget once the cc/blimp | |
177 // refactor work is done. | |
208 std::unique_ptr<BlimpInputManager> input_manager_; | 178 std::unique_ptr<BlimpInputManager> input_manager_; |
209 | 179 |
210 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 180 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
211 }; | 181 }; |
212 | 182 |
213 } // namespace client | 183 } // namespace client |
214 } // namespace blimp | 184 } // namespace blimp |
215 | 185 |
216 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 186 #endif // BLIMP_CLIENT_CORE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
OLD | NEW |