| 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/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
| 11 #include "cc/blimp/compositor_proto_state.h" | 11 #include "cc/blimp/compositor_proto_state.h" |
| 12 #include "cc/blimp/engine_picture_cache.h" | 12 #include "cc/blimp/engine_picture_cache.h" |
| 13 #include "cc/blimp/picture_data_conversions.h" | 13 #include "cc/blimp/picture_data_conversions.h" |
| 14 #include "cc/blimp/remote_compositor_bridge.h" | 14 #include "cc/blimp/remote_compositor_bridge.h" |
| 15 #include "cc/output/begin_frame_args.h" | 15 #include "cc/output/begin_frame_args.h" |
| 16 #include "cc/output/compositor_frame_sink.h" | 16 #include "cc/output/compositor_frame_sink.h" |
| 17 #include "cc/proto/compositor_message.pb.h" | 17 #include "cc/proto/compositor_message.pb.h" |
| 18 #include "cc/proto/gfx_conversions.h" |
| 18 #include "cc/proto/layer_tree_host.pb.h" | 19 #include "cc/proto/layer_tree_host.pb.h" |
| 19 #include "cc/trees/layer_tree.h" | 20 #include "cc/trees/layer_tree.h" |
| 20 #include "cc/trees/layer_tree_host_client.h" | 21 #include "cc/trees/layer_tree_host_client.h" |
| 21 #include "cc/trees/layer_tree_host_common.h" | 22 #include "cc/trees/layer_tree_host_common.h" |
| 22 #include "cc/trees/task_runner_provider.h" | 23 #include "cc/trees/task_runner_provider.h" |
| 23 #include "ui/gfx/geometry/scroll_offset.h" | 24 #include "ui/gfx/geometry/scroll_offset.h" |
| 24 | 25 |
| 25 namespace cc { | 26 namespace cc { |
| 26 namespace { | 27 namespace { |
| 27 // We use a 16ms default frame interval because the rate at which the engine | 28 // We use a 16ms default frame interval because the rate at which the engine |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // used here. | 216 // used here. |
| 216 // TODO(khushalsagar): The caller could be waiting for an Ack for this redraw. | 217 // TODO(khushalsagar): The caller could be waiting for an Ack for this redraw. |
| 217 // We need a better solution for this. See crbug.com/651141. | 218 // We need a better solution for this. See crbug.com/651141. |
| 218 NOTIMPLEMENTED(); | 219 NOTIMPLEMENTED(); |
| 219 } | 220 } |
| 220 | 221 |
| 221 void LayerTreeHostRemote::SetNextCommitForcesRedraw() { | 222 void LayerTreeHostRemote::SetNextCommitForcesRedraw() { |
| 222 // Ideally the engine shouldn't need to care about draw requests at all. The | 223 // Ideally the engine shouldn't need to care about draw requests at all. The |
| 223 // compositor that produces CompositorFrames is on the client and draw | 224 // compositor that produces CompositorFrames is on the client and draw |
| 224 // requests should be made directly to it on the client itself. | 225 // requests should be made directly to it on the client itself. |
| 225 NOTREACHED(); | 226 NOTIMPLEMENTED(); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void LayerTreeHostRemote::NotifyInputThrottledUntilCommit() { | 229 void LayerTreeHostRemote::NotifyInputThrottledUntilCommit() { |
| 229 // This notification is used in the case where the renderer handles an input | 230 // This notification is used in the case where the renderer handles an input |
| 230 // event, and needs to send an Ack to the browser when the resulting main | 231 // event, and needs to send an Ack to the browser when the resulting main |
| 231 // frame is committed. If the compositor is taking too long on the pending | 232 // frame is committed. If the compositor is taking too long on the pending |
| 232 // tree, the commit processing will be delayed blocking all input as a result. | 233 // tree, the commit processing will be delayed blocking all input as a result. |
| 233 // So this is used to have the compositor activate the pending tree faster, so | 234 // So this is used to have the compositor activate the pending tree faster, so |
| 234 // the pending commit can be processed. | 235 // the pending commit can be processed. |
| 235 // In remote mode, we don't send such notifications to the client because the | 236 // In remote mode, we don't send such notifications to the client because the |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 // right after the update is processed by the bridge. | 436 // right after the update is processed by the bridge. |
| 436 // TODO(khushalsagar): We can not really know what these callbacks end up | 437 // TODO(khushalsagar): We can not really know what these callbacks end up |
| 437 // being used for. Consider migrating clients to understand/cope with the fact | 438 // being used for. Consider migrating clients to understand/cope with the fact |
| 438 // that there is no actual compositing happening here. | 439 // that there is no actual compositing happening here. |
| 439 task_runner_provider_->MainThreadTaskRunner()->PostTask( | 440 task_runner_provider_->MainThreadTaskRunner()->PostTask( |
| 440 FROM_HERE, | 441 FROM_HERE, |
| 441 base::Bind(&LayerTreeHostRemote::DispatchDrawAndSubmitCallbacks, | 442 base::Bind(&LayerTreeHostRemote::DispatchDrawAndSubmitCallbacks, |
| 442 weak_factory_.GetWeakPtr())); | 443 weak_factory_.GetWeakPtr())); |
| 443 } | 444 } |
| 444 | 445 |
| 445 bool LayerTreeHostRemote::ApplyScrollAndScaleUpdateFromClient( | 446 void LayerTreeHostRemote::ApplyStateUpdateFromClient( |
| 446 const ScrollOffsetMap& client_scroll_map, | 447 const proto::ClientStateUpdate& client_state_update) { |
| 447 float client_page_scale) { | |
| 448 DCHECK(!synchronizing_client_updates_); | 448 DCHECK(!synchronizing_client_updates_); |
| 449 | |
| 450 base::AutoReset<bool> synchronizing_updates(&synchronizing_client_updates_, | 449 base::AutoReset<bool> synchronizing_updates(&synchronizing_client_updates_, |
| 451 true); | 450 true); |
| 452 bool layer_sync_successful = true; | |
| 453 | 451 |
| 454 gfx::Vector2dF inner_viewport_scroll_delta; | 452 gfx::Vector2dF inner_viewport_delta; |
| 455 Layer* inner_viewport_scroll_layer = | 453 for (int i = 0; i < client_state_update.scroll_updates_size(); ++i) { |
| 456 layer_tree_->inner_viewport_scroll_layer(); | 454 const proto::ScrollUpdate& scroll_update = |
| 457 for (const auto& client_scroll : client_scroll_map) { | 455 client_state_update.scroll_updates(i); |
| 458 Layer* layer = layer_tree_->LayerById(client_scroll.first); | 456 int layer_id = scroll_update.layer_id(); |
| 459 const gfx::ScrollOffset& scroll_offset = client_scroll.second; | 457 Layer* layer = layer_tree_->LayerById(layer_id); |
| 458 gfx::Vector2dF scroll_delta = |
| 459 ProtoToVector2dF(scroll_update.scroll_delta()); |
| 460 | 460 |
| 461 // Note the inner viewport scroll delta to report separately. | 461 if (!layer) |
| 462 if (layer == inner_viewport_scroll_layer) { | 462 continue; |
| 463 inner_viewport_scroll_delta = | 463 |
| 464 scroll_offset.DeltaFrom(layer->scroll_offset()); | 464 if (layer == layer_tree_->inner_viewport_scroll_layer()) { |
| 465 inner_viewport_delta = scroll_delta; |
| 466 } else { |
| 467 layer->SetScrollOffsetFromImplSide( |
| 468 gfx::ScrollOffsetWithDelta(layer->scroll_offset(), scroll_delta)); |
| 469 SetNeedsUpdateLayers(); |
| 465 } | 470 } |
| 471 } |
| 466 | 472 |
| 467 if (layer) | 473 if (!inner_viewport_delta.IsZero()) { |
| 468 layer->SetScrollOffsetFromImplSide(scroll_offset); | 474 layer_tree_->inner_viewport_scroll_layer()->SetScrollOffsetFromImplSide( |
| 469 else | 475 gfx::ScrollOffsetWithDelta( |
| 470 layer_sync_successful = false; | 476 layer_tree_->inner_viewport_scroll_layer()->scroll_offset(), |
| 477 inner_viewport_delta)); |
| 471 } | 478 } |
| 472 | 479 |
| 473 float page_scale_delta = 1.0f; | 480 float page_scale_delta = 1.0f; |
| 474 if (client_page_scale != layer_tree_->page_scale_factor()) { | 481 if (client_state_update.has_page_scale_delta()) { |
| 475 page_scale_delta = client_page_scale / layer_tree_->page_scale_factor(); | 482 page_scale_delta = client_state_update.page_scale_delta(); |
| 476 layer_tree_->SetPageScaleFromImplSide(client_page_scale); | 483 layer_tree_->SetPageScaleFromImplSide(layer_tree_->page_scale_factor() * |
| 484 page_scale_delta); |
| 477 } | 485 } |
| 478 | 486 |
| 479 if (!inner_viewport_scroll_delta.IsZero() || page_scale_delta != 1.0f) { | 487 if (!inner_viewport_delta.IsZero() || page_scale_delta != 1.0f) { |
| 480 client_->ApplyViewportDeltas(inner_viewport_scroll_delta, gfx::Vector2dF(), | 488 client_->ApplyViewportDeltas(inner_viewport_delta, gfx::Vector2dF(), |
| 481 gfx::Vector2dF(), page_scale_delta, 1.0f); | 489 gfx::Vector2dF(), page_scale_delta, 0.0f); |
| 490 SetNeedsUpdateLayers(); |
| 482 } | 491 } |
| 483 | |
| 484 return layer_sync_successful; | |
| 485 } | 492 } |
| 486 | 493 |
| 487 void LayerTreeHostRemote::MainFrameComplete() { | 494 void LayerTreeHostRemote::MainFrameComplete() { |
| 488 DCHECK_EQ(current_pipeline_stage_, FramePipelineStage::COMMIT); | 495 DCHECK_EQ(current_pipeline_stage_, FramePipelineStage::COMMIT); |
| 489 | 496 |
| 490 current_pipeline_stage_ = FramePipelineStage::NONE; | 497 current_pipeline_stage_ = FramePipelineStage::NONE; |
| 491 max_pipeline_stage_for_current_frame_ = FramePipelineStage::NONE; | 498 max_pipeline_stage_for_current_frame_ = FramePipelineStage::NONE; |
| 492 source_frame_number_++; | 499 source_frame_number_++; |
| 493 | 500 |
| 494 client_->DidCommit(); | 501 client_->DidCommit(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 523 layer->ToLayerPropertiesProto( | 530 layer->ToLayerPropertiesProto( |
| 524 layer_tree_host_proto->mutable_layer_updates(), inputs_only); | 531 layer_tree_host_proto->mutable_layer_updates(), inputs_only); |
| 525 | 532 |
| 526 std::vector<PictureData> pictures = | 533 std::vector<PictureData> pictures = |
| 527 engine_picture_cache_->CalculateCacheUpdateAndFlush(); | 534 engine_picture_cache_->CalculateCacheUpdateAndFlush(); |
| 528 proto::PictureDataVectorToSkPicturesProto( | 535 proto::PictureDataVectorToSkPicturesProto( |
| 529 pictures, layer_tree_host_proto->mutable_pictures()); | 536 pictures, layer_tree_host_proto->mutable_pictures()); |
| 530 } | 537 } |
| 531 | 538 |
| 532 } // namespace cc | 539 } // namespace cc |
| OLD | NEW |