| 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/blimp/layer_tree_host_remote.h" | 5 #include "cc/blimp/layer_tree_host_remote.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "cc/animation/animation_host.h" | 9 #include "cc/animation/animation_host.h" |
| 10 #include "cc/blimp/compositor_proto_state.h" | 10 #include "cc/blimp/compositor_proto_state.h" |
| 11 #include "cc/blimp/remote_compositor_bridge.h" | 11 #include "cc/blimp/remote_compositor_bridge.h" |
| 12 #include "cc/output/begin_frame_args.h" | 12 #include "cc/output/begin_frame_args.h" |
| 13 #include "cc/output/compositor_frame_sink.h" | 13 #include "cc/output/compositor_frame_sink.h" |
| 14 #include "cc/proto/compositor_message.pb.h" |
| 15 #include "cc/proto/layer_tree_host.pb.h" |
| 14 #include "cc/trees/layer_tree.h" | 16 #include "cc/trees/layer_tree.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_host_common.h" | 18 #include "cc/trees/layer_tree_host_common.h" |
| 17 #include "cc/trees/task_runner_provider.h" | 19 #include "cc/trees/task_runner_provider.h" |
| 18 | 20 |
| 19 namespace cc { | 21 namespace cc { |
| 20 namespace { | 22 namespace { |
| 21 // We use a 16ms default frame interval because the rate at which the engine | 23 // We use a 16ms default frame interval because the rate at which the engine |
| 22 // produces main frames doesn't matter. | 24 // produces main frames doesn't matter. |
| 23 base::TimeDelta kDefaultFrameInterval = base::TimeDelta::FromMilliseconds(16); | 25 base::TimeDelta kDefaultFrameInterval = base::TimeDelta::FromMilliseconds(16); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 client_->UpdateLayerTreeHost(); | 344 client_->UpdateLayerTreeHost(); |
| 343 | 345 |
| 344 current_pipeline_stage_ = FramePipelineStage::UPDATE_LAYERS; | 346 current_pipeline_stage_ = FramePipelineStage::UPDATE_LAYERS; |
| 345 LayerList layer_list; | 347 LayerList layer_list; |
| 346 if (max_pipeline_stage_for_current_frame_ >= | 348 if (max_pipeline_stage_for_current_frame_ >= |
| 347 FramePipelineStage::UPDATE_LAYERS) { | 349 FramePipelineStage::UPDATE_LAYERS) { |
| 348 // Pull updates for all layers from the client. | 350 // Pull updates for all layers from the client. |
| 349 // TODO(khushalsagar): Investigate the data impact from updating all the | 351 // TODO(khushalsagar): Investigate the data impact from updating all the |
| 350 // layers. See crbug.com/650885. | 352 // layers. See crbug.com/650885. |
| 351 LayerTreeHostCommon::CallFunctionForEveryLayer( | 353 LayerTreeHostCommon::CallFunctionForEveryLayer( |
| 352 layer_tree_.get(), | 354 layer_tree_.get(), [&layer_list](Layer* layer) { |
| 353 [&layer_list](Layer* layer) { layer_list.push_back(layer); }); | 355 layer->SavePaintProperties(); |
| 356 layer_list.push_back(layer); |
| 357 }); |
| 354 | 358 |
| 355 bool content_is_suitable_for_gpu = false; | 359 bool content_is_suitable_for_gpu = false; |
| 356 bool layers_updated = | 360 bool layers_updated = |
| 357 layer_tree_->UpdateLayers(layer_list, &content_is_suitable_for_gpu); | 361 layer_tree_->UpdateLayers(layer_list, &content_is_suitable_for_gpu); |
| 358 | 362 |
| 359 // If pulling layer updates resulted in any content updates, we need to go | 363 // If pulling layer updates resulted in any content updates, we need to go |
| 360 // till the commit stage. | 364 // till the commit stage. |
| 361 if (layers_updated) | 365 if (layers_updated) |
| 362 max_pipeline_stage_for_current_frame_ = FramePipelineStage::COMMIT; | 366 max_pipeline_stage_for_current_frame_ = FramePipelineStage::COMMIT; |
| 363 } | 367 } |
| 364 | 368 |
| 365 current_pipeline_stage_ = FramePipelineStage::COMMIT; | 369 current_pipeline_stage_ = FramePipelineStage::COMMIT; |
| 366 client_->WillCommit(); | 370 client_->WillCommit(); |
| 367 | 371 |
| 368 if (max_pipeline_stage_for_current_frame_ < current_pipeline_stage_) { | 372 if (max_pipeline_stage_for_current_frame_ < current_pipeline_stage_) { |
| 369 // There is nothing to commit so break the swap promises. | 373 // There is nothing to commit so break the swap promises. |
| 370 swap_promise_manager_.BreakSwapPromises( | 374 swap_promise_manager_.BreakSwapPromises( |
| 371 SwapPromise::DidNotSwapReason::COMMIT_NO_UPDATE); | 375 SwapPromise::DidNotSwapReason::COMMIT_NO_UPDATE); |
| 372 | 376 |
| 373 // For the client, the commit was successful. | 377 // For the client, the commit was successful. |
| 374 MainFrameComplete(); | 378 MainFrameComplete(); |
| 375 return; | 379 return; |
| 376 } | 380 } |
| 377 | 381 |
| 378 // TODO(khushalsagar): Serialize current state/reset dirty state tracking and | |
| 379 // return the result to the bridge instead. | |
| 380 std::unique_ptr<CompositorProtoState> compositor_state = | 382 std::unique_ptr<CompositorProtoState> compositor_state = |
| 381 base::MakeUnique<CompositorProtoState>(); | 383 base::MakeUnique<CompositorProtoState>(); |
| 384 compositor_state->swap_promises = swap_promise_manager_.TakeSwapPromises(); |
| 385 compositor_state->compositor_message = |
| 386 base::MakeUnique<proto::CompositorMessage>(); |
| 387 SerializeCurrentState( |
| 388 compositor_state->compositor_message->mutable_layer_tree_host()); |
| 382 remote_compositor_bridge_->ProcessCompositorStateUpdate( | 389 remote_compositor_bridge_->ProcessCompositorStateUpdate( |
| 383 std::move(compositor_state)); | 390 std::move(compositor_state)); |
| 384 | 391 |
| 385 MainFrameComplete(); | 392 MainFrameComplete(); |
| 386 | 393 |
| 387 // We can not wait for updates dispatched from the client about the state of | 394 // We can not wait for updates dispatched from the client about the state of |
| 388 // drawing or swaps for frames sent. Since these calls can be used by the | 395 // drawing or swaps for frames sent. Since these calls can be used by the |
| 389 // LayerTreeHostClient to throttle further frame updates, so dispatch them | 396 // LayerTreeHostClient to throttle further frame updates, so dispatch them |
| 390 // right after the update is processed by the bridge. | 397 // right after the update is processed by the bridge. |
| 391 // TODO(khushalsagar): We can not really know what these callbacks end up | 398 // TODO(khushalsagar): We can not really know what these callbacks end up |
| (...skipping 13 matching lines...) Expand all Loading... |
| 405 | 412 |
| 406 client_->DidCommit(); | 413 client_->DidCommit(); |
| 407 client_->DidBeginMainFrame(); | 414 client_->DidBeginMainFrame(); |
| 408 } | 415 } |
| 409 | 416 |
| 410 void LayerTreeHostRemote::DispatchDrawAndSwapCallbacks() { | 417 void LayerTreeHostRemote::DispatchDrawAndSwapCallbacks() { |
| 411 client_->DidCommitAndDrawFrame(); | 418 client_->DidCommitAndDrawFrame(); |
| 412 client_->DidCompleteSwapBuffers(); | 419 client_->DidCompleteSwapBuffers(); |
| 413 } | 420 } |
| 414 | 421 |
| 422 void LayerTreeHostRemote::SerializeCurrentState( |
| 423 proto::LayerTreeHost* layer_tree_host_proto) { |
| 424 // We need to serialize only the inputs received from the embedder. |
| 425 const bool inputs_only = true; |
| 426 |
| 427 // Serialize the LayerTree. |
| 428 layer_tree_->ToProtobuf(layer_tree_host_proto->mutable_layer_tree(), |
| 429 inputs_only); |
| 430 |
| 431 // Serialize the dirty layers. |
| 432 for (auto* layer : layer_tree_->LayersThatShouldPushProperties()) |
| 433 layer->ToLayerPropertiesProto( |
| 434 layer_tree_host_proto->mutable_layer_updates(), inputs_only); |
| 435 layer_tree_->LayersThatShouldPushProperties().clear(); |
| 436 |
| 437 // TODO(khushalsagar): Deal with picture caching. |
| 438 } |
| 439 |
| 415 } // namespace cc | 440 } // namespace cc |
| OLD | NEW |