Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: blimp/client/feature/compositor/blimp_compositor.h

Issue 2266863003: blimp: Move BlimpCompositor to use delegated rendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make gn happy Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/blimp_output_surface.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 } // namespace proto
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
40
41 namespace gpu {
42 class GpuMemoryBufferManager;
43 } // namespace gpu
33 44
34 namespace blimp { 45 namespace blimp {
35
36 class BlimpMessage; 46 class BlimpMessage;
37 47
38 namespace client { 48 namespace client {
39 49
40 // The BlimpCompositorClient provides the BlimpCompositor with the necessary 50 // The BlimpCompositorClient provides the BlimpCompositor with the necessary
41 // dependencies for cc::LayerTreeHost owned by this compositor and for 51 // dependencies for cc::LayerTreeHost owned by this compositor and for
42 // communicating the compositor and input messages to the corresponding 52 // communicating the compositor and input messages to the corresponding
43 // render widget of this compositor on the engine. 53 // render widget of this compositor on the engine.
44 class BlimpCompositorClient { 54 class BlimpCompositorClient {
45 public: 55 public:
46 // These methods should provide the dependencies for cc::LayerTreeHost for 56 // These methods should provide the dependencies for cc::LayerTreeHost for
47 // this compositor. 57 // this compositor.
48 virtual cc::LayerTreeSettings* GetLayerTreeSettings() = 0; 58 virtual cc::LayerTreeSettings* GetLayerTreeSettings() = 0;
49 virtual scoped_refptr<base::SingleThreadTaskRunner> 59 virtual scoped_refptr<base::SingleThreadTaskRunner>
50 GetCompositorTaskRunner() = 0; 60 GetCompositorTaskRunner() = 0;
51 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0; 61 virtual cc::TaskGraphRunner* GetTaskGraphRunner() = 0;
52 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; 62 virtual gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0;
53 virtual cc::ImageSerializationProcessor* GetImageSerializationProcessor() = 0; 63 virtual cc::ImageSerializationProcessor* GetImageSerializationProcessor() = 0;
54 virtual void DidCompleteSwapBuffers() = 0;
55 virtual void DidCommitAndDrawFrame() = 0;
56 64
57 // Should send web gesture events which could not be handled locally by the 65 // Should send web gesture events which could not be handled locally by the
58 // compositor to the engine. 66 // compositor to the engine.
59 virtual void SendWebGestureEvent( 67 virtual void SendWebGestureEvent(
60 int render_widget_id, 68 int render_widget_id,
61 const blink::WebGestureEvent& gesture_event) = 0; 69 const blink::WebGestureEvent& gesture_event) = 0;
62 70
63 // Should send the compositor messages from the remote client LayerTreeHost of 71 // Should send the compositor messages from the remote client LayerTreeHost of
64 // this compositor to the corresponding remote server LayerTreeHost. 72 // this compositor to the corresponding remote server LayerTreeHost.
65 virtual void SendCompositorMessage( 73 virtual void SendCompositorMessage(
66 int render_widget_id, 74 int render_widget_id,
67 const cc::proto::CompositorMessage& message) = 0; 75 const cc::proto::CompositorMessage& message) = 0;
68 76
69 protected: 77 protected:
70 virtual ~BlimpCompositorClient() {} 78 virtual ~BlimpCompositorClient() {}
71 }; 79 };
72 80
73 // BlimpCompositor provides the basic framework and setup to host a 81 // BlimpCompositor provides the basic framework and setup to host a
74 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the 82 // LayerTreeHost. This class owns the remote client cc::LayerTreeHost, which
75 // compositor, but the LayerTreeHost does the compositing work. The rendering 83 // 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 84 // LayerTreeHost for a BlimpCompositor is owned by the
84 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a 85 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a
85 // RenderWidget, identified by a custom |render_widget_id| generated on the 86 // RenderWidget, identified by a custom |render_widget_id| generated on the
86 // engine. The lifetime of this compositor is controlled by its corresponding 87 // engine. The lifetime of this compositor is controlled by its corresponding
87 // RenderWidget. 88 // RenderWidget.
88 class BlimpCompositor 89 // This class should only be accessed from the main thread.
89 : public cc::LayerTreeHostClient, 90 class BlimpCompositor : public cc::LayerTreeHostClient,
90 public cc::RemoteProtoChannel, 91 public cc::RemoteProtoChannel,
91 public BlimpInputManagerClient { 92 public BlimpInputManagerClient,
93 public BlimpOutputSurfaceClient,
94 public cc::SurfaceFactoryClient {
92 public: 95 public:
93 BlimpCompositor(const int render_widget_id, BlimpCompositorClient* client); 96 BlimpCompositor(const int render_widget_id,
97 cc::SurfaceManager* surface_manager,
98 uint32_t surface_client_id,
99 BlimpCompositorClient* client);
94 100
95 ~BlimpCompositor() override; 101 ~BlimpCompositor() override;
96 102
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); 103 virtual void SetVisible(bool visible);
103 104
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_|. 105 // Forwards the touch event to the |input_manager_|.
120 // virtual for testing. 106 // virtual for testing.
121 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event); 107 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event);
122 108
123 // Called to forward the compositor message from the remote server 109 // Called to forward the compositor message from the remote server
124 // LayerTreeHost of the render widget for this compositor. 110 // LayerTreeHost of the render widget for this compositor.
125 // virtual for testing. 111 // virtual for testing.
126 virtual void OnCompositorMessageReceived( 112 virtual void OnCompositorMessageReceived(
127 std::unique_ptr<cc::proto::CompositorMessage> message); 113 std::unique_ptr<cc::proto::CompositorMessage> message);
128 114
115 scoped_refptr<cc::Layer> layer() const { return layer_; }
116
129 int render_widget_id() const { return render_widget_id_; } 117 int render_widget_id() const { return render_widget_id_; }
130 118
131 private: 119 private:
132 friend class BlimpCompositorForTesting; 120 friend class BlimpCompositorForTesting;
133 121
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 // TODO(khushalsagar): Need to handle context initialization failures.
147 void DidFailToInitializeOutputSurface() override; 135 void DidInitializeOutputSurface() override {}
148 void WillCommit() override; 136 void DidFailToInitializeOutputSurface() override {}
149 void DidCommit() override; 137 void WillCommit() override {}
138 void DidCommit() override {}
150 void DidCommitAndDrawFrame() override; 139 void DidCommitAndDrawFrame() override;
151 void DidCompleteSwapBuffers() override; 140 void DidCompleteSwapBuffers() override {}
152 void DidCompletePageScaleAnimation() override; 141 void DidCompletePageScaleAnimation() override {}
153 142
154 // RemoteProtoChannel implementation. 143 // RemoteProtoChannel implementation.
155 void SetProtoReceiver(ProtoReceiver* receiver) override; 144 void SetProtoReceiver(ProtoReceiver* receiver) override;
156 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; 145 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override;
157 146
158 // BlimpInputManagerClient implementation. 147 // BlimpInputManagerClient implementation.
159 void SendWebGestureEvent( 148 void SendWebGestureEvent(
160 const blink::WebGestureEvent& gesture_event) override; 149 const blink::WebGestureEvent& gesture_event) override;
161 150
162 // Internal method to correctly set the visibility on the |host_|. It will 151 // BlimpOutputSurfaceClient implementation.
163 // make the |host_| visible if |visible| is true and we have a valid |window_| 152 void BindToOutputSurface(
164 // If |visible_| is false, the host will also release its output surface. 153 base::WeakPtr<BlimpOutputSurface> output_surface) override;
165 void SetVisibleInternal(bool visible); 154 void SwapCompositorFrame(cc::CompositorFrame frame) override;
155 void UnbindOutputSurface() override;
166 156
167 // Helper method to build the internal CC compositor instance from |message|. 157 // SurfaceFactoryClient implementation.
158 void ReturnResources(const cc::ReturnedResourceArray& resources) override;
159 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {}
160
161 // TODO(khushalsagar): Move all of this to the |DocumentView| or another
162 // platform specific class. So we use the DelegatedFrameHostAndroid like the
163 // RenderWidgetHostViewAndroid.
164 void DestroyDelegatedContent();
165
166 // Helper method to build the internal CC LayerTreeHost instance from
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 compositor 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 // 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. 175 // The unique identifier for the render widget for this compositor.
180 const int render_widget_id_; 176 const int render_widget_id_;
181 177
182 BlimpCompositorClient* client_; 178 BlimpCompositorClient* client_;
183 179
184 std::unique_ptr<cc::LayerTreeHost> host_; 180 std::unique_ptr<cc::LayerTreeHost> host_;
185 181
186 gfx::AcceleratedWidget window_;
187
188 // Whether or not |host_| should be visible. This is stored in case |host_| 182 // 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 183 // is null when SetVisible() is called.
190 // gfx::AcceleratedWidget to build an output surface from.
191 bool host_should_be_visible_; 184 bool host_should_be_visible_;
192 185
193 // Whether there is an OutputSurface request pending from the current 186 // The SurfaceFactory is bound to the lifetime of the BlimpOutputSurface. When
194 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| 187 // detached, the surface factory will be destroyed.
195 // if |host_| is deleted or we succeed in creating *and* initializing an 188 std::unique_ptr<cc::SurfaceFactory> surface_factory_;
196 // OutputSurface (which is essentially the contract with cc). 189 base::WeakPtr<BlimpOutputSurface> output_surface_;
197 bool output_surface_request_pending_; 190
191 // Data for the current frame.
192 cc::SurfaceId surface_id_;
193 gfx::Size current_surface_size_;
194
195 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
196 base::ThreadChecker thread_checker_;
197
198 // Surfaces related stuff and layer which holds the delegated content from the
199 // compositor.
200 cc::SurfaceManager* surface_manager_;
201 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_;
202 scoped_refptr<cc::Layer> layer_;
198 203
199 // To be notified of any incoming compositor protos that are specifically sent 204 // To be notified of any incoming compositor protos that are specifically sent
200 // to |render_widget_id_|. 205 // to |render_widget_id_|.
201 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; 206 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_;
202 207
203 // Handles input events for the current render widget. The lifetime of the 208 // 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 209 // 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 210 // 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 211 // the manager to be handled by the client compositor for the current render
207 // widget. 212 // widget.
208 std::unique_ptr<BlimpInputManager> input_manager_; 213 std::unique_ptr<BlimpInputManager> input_manager_;
209 214
215 base::WeakPtrFactory<BlimpCompositor> weak_factory_;
216
210 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); 217 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor);
211 }; 218 };
212 219
213 } // namespace client 220 } // namespace client
214 } // namespace blimp 221 } // namespace blimp
215 222
216 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ 223 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_
OLDNEW
« no previous file with comments | « blimp/client/core/compositor/delegated_output_surface_unittest.cc ('k') | blimp/client/feature/compositor/blimp_compositor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698