OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/test/layer_tree_host_remote_for_testing.h" | |
6 | |
7 #include "base/memory/ptr_util.h" | |
8 #include "cc/animation/animation_host.h" | |
9 #include "cc/blimp/compositor_proto_state.h" | |
10 #include "cc/blimp/compositor_state_deserializer.h" | |
11 #include "cc/blimp/remote_compositor_bridge.h" | |
12 #include "cc/proto/compositor_message.pb.h" | |
13 #include "cc/test/fake_image_serialization_processor.h" | |
14 #include "cc/test/remote_client_layer_factory.h" | |
15 #include "cc/trees/layer_tree_host_client.h" | |
16 #include "cc/trees/layer_tree_host_in_process.h" | |
17 | |
18 namespace cc { | |
19 | |
20 class LayerTreeHostRemoteForTesting::RemoteCompositorBridgeImpl | |
21 : public RemoteCompositorBridge { | |
22 public: | |
23 RemoteCompositorBridgeImpl( | |
24 scoped_refptr<base::SingleThreadTaskRunner> compositor_main_task_runner) | |
25 : RemoteCompositorBridge(std::move(compositor_main_task_runner)) {} | |
26 | |
27 ~RemoteCompositorBridgeImpl() override = default; | |
28 | |
29 void SetRemoteHost(LayerTreeHostRemoteForTesting* layer_tree_host_remote) { | |
30 DCHECK(layer_tree_host_remote); | |
31 layer_tree_host_remote_ = layer_tree_host_remote; | |
32 } | |
33 | |
34 // RemoteCompositorBridge implementation. | |
35 void BindToClient(RemoteCompositorBridgeClient* client) override { | |
36 DCHECK(!client_); | |
37 client_ = client; | |
38 } | |
39 void ScheduleMainFrame() override { | |
40 layer_tree_host_remote_->RemoteHostNeedsMainFrame(); | |
41 } | |
42 void ProcessCompositorStateUpdate( | |
enne (OOO)
2016/10/06 20:19:55
override?
Khushal
2016/10/06 21:09:42
Its there right?
| |
43 std::unique_ptr<CompositorProtoState> compositor_proto_state) override { | |
44 layer_tree_host_remote_->ProcessRemoteCompositorUpdate( | |
45 std::move(compositor_proto_state)); | |
46 } | |
47 | |
48 private: | |
49 LayerTreeHostRemoteForTesting* layer_tree_host_remote_ = nullptr; | |
50 RemoteCompositorBridgeClient* client_ = nullptr; | |
51 }; | |
52 | |
53 class LayerTreeHostRemoteForTesting::LayerTreeHostInProcessClient | |
54 : public LayerTreeHostClient { | |
55 public: | |
56 LayerTreeHostInProcessClient( | |
57 LayerTreeHostRemoteForTesting* layer_tree_host_remote) | |
58 : layer_tree_host_remote_(layer_tree_host_remote) {} | |
59 | |
60 ~LayerTreeHostInProcessClient() override = default; | |
61 | |
62 void WillBeginMainFrame() override {} | |
63 void BeginMainFrame(const BeginFrameArgs& args) override { | |
64 layer_tree_host_remote_->BeginMainFrame(); | |
65 } | |
66 void BeginMainFrameNotExpectedSoon() override {} | |
67 void DidBeginMainFrame() override {} | |
68 void UpdateLayerTreeHost() override { | |
69 layer_tree_host_remote_->UpdateStateOnInProcessHost(); | |
70 } | |
71 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | |
72 const gfx::Vector2dF& outer_delta, | |
73 const gfx::Vector2dF& elastic_overscroll_delta, | |
74 float page_scale, | |
75 float top_controls_delta) override { | |
76 // TODO(khushalsagar): Hook up when scroll/scale sync is added. | |
77 } | |
78 void RequestNewCompositorFrameSink() override { | |
79 layer_tree_host_remote_->client()->RequestNewCompositorFrameSink(); | |
80 } | |
81 void DidInitializeCompositorFrameSink() override { | |
82 layer_tree_host_remote_->client()->DidInitializeCompositorFrameSink(); | |
83 } | |
84 void DidFailToInitializeCompositorFrameSink() override { | |
85 layer_tree_host_remote_->client()->DidFailToInitializeCompositorFrameSink(); | |
86 } | |
87 void WillCommit() override {} | |
88 void DidCommit() override {} | |
89 void DidCommitAndDrawFrame() override { | |
90 layer_tree_host_remote_->client()->DidCommitAndDrawFrame(); | |
91 } | |
92 void DidCompleteSwapBuffers() override { | |
93 layer_tree_host_remote_->client()->DidCompleteSwapBuffers(); | |
94 } | |
95 void DidCompletePageScaleAnimation() override { | |
96 NOTREACHED() << "The remote mode doesn't support sending animations"; | |
97 } | |
98 | |
99 private: | |
100 LayerTreeHostRemoteForTesting* layer_tree_host_remote_; | |
101 }; | |
102 | |
103 // static | |
104 std::unique_ptr<RemoteCompositorBridge> | |
105 LayerTreeHostRemoteForTesting::CreateRemoteCompositorBridge( | |
106 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) { | |
107 return base::MakeUnique<RemoteCompositorBridgeImpl>( | |
108 std::move(main_task_runner)); | |
109 } | |
110 | |
111 // static | |
112 std::unique_ptr<LayerTreeHostRemoteForTesting> | |
113 LayerTreeHostRemoteForTesting::Create( | |
114 LayerTreeHostClient* client, | |
115 std::unique_ptr<AnimationHost> animation_host, | |
116 LayerTreeSettings const* settings, | |
117 SharedBitmapManager* shared_bitmap_manager, | |
118 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
119 TaskGraphRunner* task_graph_runner, | |
120 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
121 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | |
122 std::unique_ptr<FakeImageSerializationProcessor> | |
123 image_serialization_processor = | |
124 base::MakeUnique<FakeImageSerializationProcessor>(); | |
125 | |
126 LayerTreeHostRemote::InitParams params; | |
127 params.client = client; | |
128 params.main_task_runner = main_task_runner; | |
129 params.animation_host = std::move(animation_host); | |
130 params.remote_compositor_bridge = | |
131 CreateRemoteCompositorBridge(main_task_runner); | |
132 params.engine_picture_cache = | |
133 image_serialization_processor->CreateEnginePictureCache(); | |
134 params.settings = settings; | |
135 | |
136 std::unique_ptr<LayerTreeHostRemoteForTesting> layer_tree_host = | |
137 base::WrapUnique(new LayerTreeHostRemoteForTesting(¶ms)); | |
138 layer_tree_host->Initialize(shared_bitmap_manager, gpu_memory_buffer_manager, | |
139 task_graph_runner, main_task_runner, | |
140 impl_task_runner, | |
141 std::move(image_serialization_processor)); | |
142 return layer_tree_host; | |
143 } | |
144 | |
145 LayerTreeHostRemoteForTesting::LayerTreeHostRemoteForTesting(InitParams* params) | |
146 : LayerTreeHostRemote(params), | |
147 layer_tree_host_in_process_client_( | |
148 base::MakeUnique<LayerTreeHostInProcessClient>(this)) {} | |
149 | |
150 LayerTreeHostRemoteForTesting::~LayerTreeHostRemoteForTesting() { | |
151 compositor_state_deserializer_ = nullptr; | |
152 layer_tree_host_in_process_ = nullptr; | |
153 } | |
154 | |
155 void LayerTreeHostRemoteForTesting::SetVisible(bool visible) { | |
156 LayerTreeHostRemote::SetVisible(visible); | |
157 | |
158 // We need to tell the InProcessHost about visibility changes as well. | |
159 layer_tree_host_in_process_->SetVisible(visible); | |
160 } | |
161 | |
162 void LayerTreeHostRemoteForTesting::SetCompositorFrameSink( | |
163 std::unique_ptr<CompositorFrameSink> compositor_frame_sink) { | |
164 // Pass through to the InProcessHost since this should be called only in | |
165 // response to a request made by it. | |
166 layer_tree_host_in_process_->SetCompositorFrameSink( | |
167 std::move(compositor_frame_sink)); | |
168 } | |
169 | |
170 std::unique_ptr<CompositorFrameSink> | |
171 LayerTreeHostRemoteForTesting::ReleaseCompositorFrameSink() { | |
172 // Pass through to the InProcessHost since that holds the CompositorFrameSink. | |
173 return layer_tree_host_in_process_->ReleaseCompositorFrameSink(); | |
174 } | |
175 | |
176 void LayerTreeHostRemoteForTesting::SetNeedsRedraw() { | |
177 // Draw requests pass through to the InProcessHost. | |
178 layer_tree_host_in_process_->SetNeedsRedraw(); | |
179 } | |
180 | |
181 void LayerTreeHostRemoteForTesting::SetNeedsRedrawRect( | |
182 const gfx::Rect& damage_rect) { | |
183 // Draw requests pass through to the InProcessHost. | |
184 layer_tree_host_in_process_->SetNeedsRedrawRect(damage_rect); | |
185 } | |
186 | |
187 void LayerTreeHostRemoteForTesting::SetNextCommitForcesRedraw() { | |
188 // Draw requests pass through to the InProcessHost. | |
189 layer_tree_host_in_process_->SetNextCommitForcesRedraw(); | |
190 } | |
191 | |
192 void LayerTreeHostRemoteForTesting::NotifyInputThrottledUntilCommit() { | |
193 // Pass through because the InProcessHost has the input handler. | |
194 layer_tree_host_in_process_->NotifyInputThrottledUntilCommit(); | |
195 } | |
196 | |
197 const base::WeakPtr<InputHandler>& | |
198 LayerTreeHostRemoteForTesting::GetInputHandler() const { | |
199 return layer_tree_host_in_process_->GetInputHandler(); | |
200 } | |
201 | |
202 void LayerTreeHostRemoteForTesting::Initialize( | |
203 SharedBitmapManager* shared_bitmap_manager, | |
204 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
205 TaskGraphRunner* task_graph_runner, | |
206 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
207 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | |
208 std::unique_ptr<FakeImageSerializationProcessor> | |
209 image_serialization_processor) { | |
210 image_serialization_processor_ = std::move(image_serialization_processor); | |
211 RemoteCompositorBridgeImpl* remote_compositor_bridge_impl = | |
212 static_cast<RemoteCompositorBridgeImpl*>(remote_compositor_bridge()); | |
213 remote_compositor_bridge_impl->SetRemoteHost(this); | |
214 | |
215 layer_tree_host_in_process_ = CreateLayerTreeHostInProcess( | |
216 layer_tree_host_in_process_client_.get(), shared_bitmap_manager, | |
217 gpu_memory_buffer_manager, task_graph_runner, GetSettings(), | |
218 main_task_runner, impl_task_runner); | |
219 | |
220 compositor_state_deserializer_ = | |
221 base::MakeUnique<CompositorStateDeserializer>( | |
222 layer_tree_host_in_process_.get(), | |
223 image_serialization_processor_->CreateClientPictureCache(), | |
224 base::Bind(&LayerTreeHostRemoteForTesting::LayerDidScroll, | |
225 base::Unretained(this)), | |
226 this); | |
227 | |
228 // Override the LayerFactory since a lot of tests rely on the fact that Layers | |
enne (OOO)
2016/10/06 20:19:55
Why are layer ids different for Blimp?
Khushal
2016/10/06 21:09:42
Layers on the engine, and those on the client have
| |
229 // and LayerImpls have matching ids. | |
230 compositor_state_deserializer_->SetLayerFactoryForTesting( | |
231 base::MakeUnique<RemoteClientLayerFactory>()); | |
232 | |
233 // Override the TaskRunnerProvider since tests may rely on accessing the impl | |
234 // task runner using it. | |
235 SetTaskRunnerProviderForTesting( | |
236 TaskRunnerProvider::Create(main_task_runner, impl_task_runner)); | |
237 } | |
238 | |
239 std::unique_ptr<LayerTreeHostInProcess> | |
240 LayerTreeHostRemoteForTesting::CreateLayerTreeHostInProcess( | |
241 LayerTreeHostClient* client, | |
242 SharedBitmapManager* shared_bitmap_manager, | |
243 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
244 TaskGraphRunner* task_graph_runner, | |
245 const LayerTreeSettings& settings, | |
246 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
247 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { | |
248 LayerTreeHostInProcess::InitParams params; | |
249 | |
250 params.client = client; | |
251 params.shared_bitmap_manager = shared_bitmap_manager; | |
252 params.gpu_memory_buffer_manager = gpu_memory_buffer_manager; | |
253 params.task_graph_runner = task_graph_runner; | |
254 params.settings = &settings; | |
255 params.main_task_runner = main_task_runner; | |
256 params.animation_host = AnimationHost::CreateMainInstance(); | |
257 | |
258 return LayerTreeHostInProcess::CreateThreaded(impl_task_runner, ¶ms); | |
259 } | |
260 | |
261 void LayerTreeHostRemoteForTesting::DispatchDrawAndSwapCallbacks() { | |
262 // Don't dispatch callbacks right after the commit on the remote host. Since | |
263 // tests rely on CompositorFrames being swapped on the CompositorFrameSink, | |
264 // we wait for these callbacks from the LayerTreeHostInProcess. | |
265 } | |
266 | |
267 bool LayerTreeHostRemoteForTesting::ShouldRetainClientScroll( | |
268 int engine_layer_id, | |
269 const gfx::ScrollOffset& new_offset) { | |
270 return false; | |
271 } | |
272 | |
273 bool LayerTreeHostRemoteForTesting::ShouldRetainClientPageScale( | |
274 float new_page_scale) { | |
275 return false; | |
276 } | |
277 | |
278 void LayerTreeHostRemoteForTesting::LayerDidScroll(int engine_layer_id) { | |
279 // TODO(khushalsagar): Hook up when scroll/scale sync is added. | |
280 } | |
281 | |
282 void LayerTreeHostRemoteForTesting::RemoteHostNeedsMainFrame() { | |
283 layer_tree_host_in_process_->SetNeedsAnimate(); | |
284 } | |
285 | |
286 void LayerTreeHostRemoteForTesting::ProcessRemoteCompositorUpdate( | |
287 std::unique_ptr<CompositorProtoState> compositor_proto_state) { | |
288 pending_compositor_proto_state_ = std::move(compositor_proto_state); | |
289 } | |
290 | |
291 void LayerTreeHostRemoteForTesting::UpdateStateOnInProcessHost() { | |
292 // When the InProcess host asks us to update, we de-serialize the update from | |
293 // the remote host. | |
294 if (pending_compositor_proto_state_) { | |
295 const proto::LayerTreeHost& layer_tree_host_proto = | |
296 pending_compositor_proto_state_->compositor_message->layer_tree_host(); | |
297 compositor_state_deserializer_->DeserializeCompositorUpdate( | |
298 layer_tree_host_proto); | |
299 | |
300 pending_compositor_proto_state_ = nullptr; | |
301 | |
302 // The only case where the remote host would give a compositor update is if | |
303 // they wanted the main frame to go till the commit pipeline stage. So | |
304 // request one to make sure that the in process main frame also goes till | |
305 // the commit step. | |
306 layer_tree_host_in_process_->SetNeedsCommit(); | |
307 } | |
308 } | |
309 | |
310 } // namespace cc | |
OLD | NEW |