| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include "cc/test/layer_tree_host_remote_for_testing.h" | 5 #include "cc/test/layer_tree_host_remote_for_testing.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
| 9 #include "cc/blimp/compositor_proto_state.h" | 9 #include "cc/blimp/compositor_proto_state.h" |
| 10 #include "cc/blimp/compositor_state_deserializer.h" | 10 #include "cc/blimp/compositor_state_deserializer.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 : public LayerTreeHostClient { | 55 : public LayerTreeHostClient { |
| 56 public: | 56 public: |
| 57 LayerTreeHostInProcessClient( | 57 LayerTreeHostInProcessClient( |
| 58 LayerTreeHostRemoteForTesting* layer_tree_host_remote) | 58 LayerTreeHostRemoteForTesting* layer_tree_host_remote) |
| 59 : layer_tree_host_remote_(layer_tree_host_remote) {} | 59 : layer_tree_host_remote_(layer_tree_host_remote) {} |
| 60 | 60 |
| 61 ~LayerTreeHostInProcessClient() override = default; | 61 ~LayerTreeHostInProcessClient() override = default; |
| 62 | 62 |
| 63 void WillBeginMainFrame() override {} | 63 void WillBeginMainFrame() override {} |
| 64 void BeginMainFrame(const BeginFrameArgs& args) override { | 64 void BeginMainFrame(const BeginFrameArgs& args) override { |
| 65 // Send any scroll/scale updates first. | 65 layer_tree_host_remote_->BeginRemoteMainFrame(); |
| 66 layer_tree_host_remote_->ApplyUpdatesFromInProcessHost(); | |
| 67 layer_tree_host_remote_->BeginMainFrame(); | |
| 68 } | 66 } |
| 69 void BeginMainFrameNotExpectedSoon() override {} | 67 void BeginMainFrameNotExpectedSoon() override {} |
| 70 void DidBeginMainFrame() override {} | 68 void DidBeginMainFrame() override {} |
| 71 void UpdateLayerTreeHost() override {} | 69 void UpdateLayerTreeHost() override {} |
| 72 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 70 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 73 const gfx::Vector2dF& outer_delta, | 71 const gfx::Vector2dF& outer_delta, |
| 74 const gfx::Vector2dF& elastic_overscroll_delta, | 72 const gfx::Vector2dF& elastic_overscroll_delta, |
| 75 float page_scale, | 73 float page_scale, |
| 76 float top_controls_delta) override {} | 74 float top_controls_delta) override {} |
| 77 void RequestNewCompositorFrameSink() override { | 75 void RequestNewCompositorFrameSink() override { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 remote_compositor_bridge_impl->SetRemoteHost(this); | 205 remote_compositor_bridge_impl->SetRemoteHost(this); |
| 208 | 206 |
| 209 layer_tree_host_in_process_ = CreateLayerTreeHostInProcess( | 207 layer_tree_host_in_process_ = CreateLayerTreeHostInProcess( |
| 210 layer_tree_host_in_process_client_.get(), shared_bitmap_manager, | 208 layer_tree_host_in_process_client_.get(), shared_bitmap_manager, |
| 211 gpu_memory_buffer_manager, task_graph_runner, GetSettings(), | 209 gpu_memory_buffer_manager, task_graph_runner, GetSettings(), |
| 212 main_task_runner, impl_task_runner); | 210 main_task_runner, impl_task_runner); |
| 213 | 211 |
| 214 compositor_state_deserializer_ = | 212 compositor_state_deserializer_ = |
| 215 base::MakeUnique<CompositorStateDeserializer>( | 213 base::MakeUnique<CompositorStateDeserializer>( |
| 216 layer_tree_host_in_process_.get(), | 214 layer_tree_host_in_process_.get(), |
| 217 image_serialization_processor_->CreateClientPictureCache(), | 215 image_serialization_processor_->CreateClientPictureCache(), this); |
| 218 base::Bind(&LayerTreeHostRemoteForTesting::LayerDidScroll, | |
| 219 base::Unretained(this)), | |
| 220 this); | |
| 221 | 216 |
| 222 // Override the LayerFactory since a lot of tests rely on the fact that Layers | 217 // Override the LayerFactory since a lot of tests rely on the fact that Layers |
| 223 // and LayerImpls have matching ids. | 218 // and LayerImpls have matching ids. |
| 224 compositor_state_deserializer_->SetLayerFactoryForTesting( | 219 compositor_state_deserializer_->SetLayerFactoryForTesting( |
| 225 base::MakeUnique<RemoteClientLayerFactory>()); | 220 base::MakeUnique<RemoteClientLayerFactory>()); |
| 226 | 221 |
| 227 // Override the TaskRunnerProvider since tests may rely on accessing the impl | 222 // Override the TaskRunnerProvider since tests may rely on accessing the impl |
| 228 // task runner using it. | 223 // task runner using it. |
| 229 SetTaskRunnerProviderForTesting( | 224 SetTaskRunnerProviderForTesting( |
| 230 TaskRunnerProvider::Create(main_task_runner, impl_task_runner)); | 225 TaskRunnerProvider::Create(main_task_runner, impl_task_runner)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 245 params.shared_bitmap_manager = shared_bitmap_manager; | 240 params.shared_bitmap_manager = shared_bitmap_manager; |
| 246 params.gpu_memory_buffer_manager = gpu_memory_buffer_manager; | 241 params.gpu_memory_buffer_manager = gpu_memory_buffer_manager; |
| 247 params.task_graph_runner = task_graph_runner; | 242 params.task_graph_runner = task_graph_runner; |
| 248 params.settings = &settings; | 243 params.settings = &settings; |
| 249 params.main_task_runner = main_task_runner; | 244 params.main_task_runner = main_task_runner; |
| 250 params.animation_host = AnimationHost::CreateMainInstance(); | 245 params.animation_host = AnimationHost::CreateMainInstance(); |
| 251 | 246 |
| 252 return LayerTreeHostInProcess::CreateThreaded(impl_task_runner, ¶ms); | 247 return LayerTreeHostInProcess::CreateThreaded(impl_task_runner, ¶ms); |
| 253 } | 248 } |
| 254 | 249 |
| 250 void LayerTreeHostRemoteForTesting::DidUpdateLocalState() { |
| 251 client_state_dirty_ = true; |
| 252 } |
| 253 |
| 255 void LayerTreeHostRemoteForTesting::DispatchDrawAndSubmitCallbacks() { | 254 void LayerTreeHostRemoteForTesting::DispatchDrawAndSubmitCallbacks() { |
| 256 // Don't dispatch callbacks right after the commit on the remote host. Since | 255 // Don't dispatch callbacks right after the commit on the remote host. Since |
| 257 // tests rely on CompositorFrames being swapped on the CompositorFrameSink, | 256 // tests rely on CompositorFrames being swapped on the CompositorFrameSink, |
| 258 // we wait for these callbacks from the LayerTreeHostInProcess. | 257 // we wait for these callbacks from the LayerTreeHostInProcess. |
| 259 } | 258 } |
| 260 | 259 |
| 261 bool LayerTreeHostRemoteForTesting::ShouldRetainClientScroll( | 260 void LayerTreeHostRemoteForTesting::RemoteHostNeedsMainFrame() { |
| 262 int engine_layer_id, | 261 layer_tree_host_in_process_->SetNeedsAnimate(); |
| 263 const gfx::ScrollOffset& new_offset) { | |
| 264 return false; | |
| 265 } | 262 } |
| 266 | 263 |
| 267 bool LayerTreeHostRemoteForTesting::ShouldRetainClientPageScale( | 264 void LayerTreeHostRemoteForTesting::BeginRemoteMainFrame() { |
| 268 float new_page_scale) { | 265 // Send scroll/scale updates first if modified on the impl thread. |
| 269 return false; | 266 if (client_state_dirty_) { |
| 270 } | 267 proto::ClientStateUpdate client_state_update; |
| 268 compositor_state_deserializer_->PullClientStateUpdate(&client_state_update); |
| 269 ApplyStateUpdateFromClient(client_state_update); |
| 270 client_state_dirty_ = false; |
| 271 } |
| 271 | 272 |
| 272 void LayerTreeHostRemoteForTesting::LayerDidScroll(int engine_layer_id) { | 273 BeginMainFrame(); |
| 273 layers_scrolled_[engine_layer_id] = | |
| 274 compositor_state_deserializer_->GetLayerForEngineId(engine_layer_id) | |
| 275 ->scroll_offset(); | |
| 276 } | |
| 277 | |
| 278 void LayerTreeHostRemoteForTesting::ApplyUpdatesFromInProcessHost() { | |
| 279 ApplyScrollAndScaleUpdateFromClient( | |
| 280 layers_scrolled_, | |
| 281 layer_tree_host_in_process_->GetLayerTree()->page_scale_factor()); | |
| 282 layers_scrolled_.clear(); | |
| 283 } | |
| 284 | |
| 285 void LayerTreeHostRemoteForTesting::RemoteHostNeedsMainFrame() { | |
| 286 layer_tree_host_in_process_->SetNeedsAnimate(); | |
| 287 } | 274 } |
| 288 | 275 |
| 289 void LayerTreeHostRemoteForTesting::ProcessRemoteCompositorUpdate( | 276 void LayerTreeHostRemoteForTesting::ProcessRemoteCompositorUpdate( |
| 290 std::unique_ptr<CompositorProtoState> compositor_proto_state) { | 277 std::unique_ptr<CompositorProtoState> compositor_proto_state) { |
| 291 DCHECK(layer_tree_host_in_process_->CommitRequested()); | 278 DCHECK(layer_tree_host_in_process_->CommitRequested()); |
| 279 |
| 292 // Deserialize the update from the remote host into client side LTH in | 280 // Deserialize the update from the remote host into client side LTH in |
| 293 // process. This bypasses the network layer. | 281 // process. This bypasses the network layer. |
| 294 const proto::LayerTreeHost& layer_tree_host_proto = | 282 const proto::LayerTreeHost& layer_tree_host_proto = |
| 295 compositor_proto_state->compositor_message->layer_tree_host(); | 283 compositor_proto_state->compositor_message->layer_tree_host(); |
| 296 compositor_state_deserializer_->DeserializeCompositorUpdate( | 284 compositor_state_deserializer_->DeserializeCompositorUpdate( |
| 297 layer_tree_host_proto); | 285 layer_tree_host_proto); |
| 298 | 286 |
| 299 const proto::LayerUpdate& layer_updates = | 287 const proto::LayerUpdate& layer_updates = |
| 300 compositor_proto_state->compositor_message->layer_tree_host() | 288 compositor_proto_state->compositor_message->layer_tree_host() |
| 301 .layer_updates(); | 289 .layer_updates(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 313 } | 301 } |
| 314 | 302 |
| 315 // The only case where the remote host would give a compositor update is if | 303 // The only case where the remote host would give a compositor update is if |
| 316 // they wanted the main frame to go till the commit pipeline stage. So | 304 // they wanted the main frame to go till the commit pipeline stage. So |
| 317 // request one to make sure that the in process main frame also goes till | 305 // request one to make sure that the in process main frame also goes till |
| 318 // the commit step. | 306 // the commit step. |
| 319 layer_tree_host_in_process_->SetNeedsCommit(); | 307 layer_tree_host_in_process_->SetNeedsCommit(); |
| 320 } | 308 } |
| 321 | 309 |
| 322 } // namespace cc | 310 } // namespace cc |
| OLD | NEW |