Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 #include "ui/gfx/geometry/size_conversions.h" | 61 #include "ui/gfx/geometry/size_conversions.h" |
| 62 #include "ui/gfx/geometry/vector2d_conversions.h" | 62 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 63 | 63 |
| 64 namespace { | 64 namespace { |
| 65 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; | 65 static base::StaticAtomicSequenceNumber s_layer_tree_host_sequence_number; |
| 66 } | 66 } |
| 67 | 67 |
| 68 namespace cc { | 68 namespace cc { |
| 69 namespace { | 69 namespace { |
| 70 | 70 |
| 71 Layer* UpdateAndGetLayer(Layer* current_layer, | |
| 72 int layer_id, | |
| 73 LayerTree* layer_tree) { | |
| 74 if (layer_id == Layer::INVALID_ID) { | |
| 75 if (current_layer) | |
| 76 current_layer->SetLayerTreeHost(nullptr); | |
| 77 | |
| 78 return nullptr; | |
| 79 } | |
| 80 Layer* layer = layer_tree->LayerById(layer_id); | |
| 81 DCHECK(layer); | |
| 82 if (current_layer && current_layer != layer) | |
| 83 current_layer->SetLayerTreeHost(nullptr); | |
| 84 | |
| 85 return layer; | |
| 86 } | |
| 87 | |
| 88 std::unique_ptr<base::trace_event::TracedValue> | 71 std::unique_ptr<base::trace_event::TracedValue> |
| 89 ComputeLayerTreeHostProtoSizeSplitAsValue(proto::LayerTreeHost* proto) { | 72 ComputeLayerTreeHostProtoSizeSplitAsValue(proto::LayerTreeHost* proto) { |
| 90 std::unique_ptr<base::trace_event::TracedValue> value( | 73 std::unique_ptr<base::trace_event::TracedValue> value( |
| 91 new base::trace_event::TracedValue()); | 74 new base::trace_event::TracedValue()); |
| 92 base::CheckedNumeric<int> base_layer_properties_size = 0; | 75 base::CheckedNumeric<int> base_layer_properties_size = 0; |
| 93 base::CheckedNumeric<int> picture_layer_properties_size = 0; | 76 base::CheckedNumeric<int> picture_layer_properties_size = 0; |
| 94 base::CheckedNumeric<int> display_item_list_size = 0; | 77 base::CheckedNumeric<int> display_item_list_size = 0; |
| 95 base::CheckedNumeric<int> drawing_display_items_size = 0; | 78 base::CheckedNumeric<int> drawing_display_items_size = 0; |
| 96 | 79 |
| 97 const proto::LayerUpdate& layer_update_proto = proto->layer_updates(); | 80 const proto::LayerUpdate& layer_update_proto = proto->layer_updates(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 111 | 94 |
| 112 for (int j = 0; j < display_list_proto.items_size(); ++j) { | 95 for (int j = 0; j < display_list_proto.items_size(); ++j) { |
| 113 const proto::DisplayItem& display_item = display_list_proto.items(j); | 96 const proto::DisplayItem& display_item = display_list_proto.items(j); |
| 114 if (display_item.type() == proto::DisplayItem::Type_Drawing) | 97 if (display_item.type() == proto::DisplayItem::Type_Drawing) |
| 115 drawing_display_items_size += display_item.ByteSize(); | 98 drawing_display_items_size += display_item.ByteSize(); |
| 116 } | 99 } |
| 117 } | 100 } |
| 118 } | 101 } |
| 119 | 102 |
| 120 value->SetInteger("TotalLayerTreeHostProtoSize", proto->ByteSize()); | 103 value->SetInteger("TotalLayerTreeHostProtoSize", proto->ByteSize()); |
| 121 value->SetInteger("LayerTreeHierarchySize", proto->root_layer().ByteSize()); | 104 value->SetInteger("LayerTreeHierarchySize", |
| 105 proto->layer_tree().root_layer().ByteSize()); | |
| 122 value->SetInteger("LayerUpdatesSize", proto->layer_updates().ByteSize()); | 106 value->SetInteger("LayerUpdatesSize", proto->layer_updates().ByteSize()); |
| 123 value->SetInteger("PropertyTreesSize", proto->property_trees().ByteSize()); | 107 value->SetInteger("PropertyTreesSize", |
| 108 proto->layer_tree().property_trees().ByteSize()); | |
| 124 | 109 |
| 125 // LayerUpdate size breakdown. | 110 // LayerUpdate size breakdown. |
| 126 value->SetInteger("TotalBasePropertiesSize", | 111 value->SetInteger("TotalBasePropertiesSize", |
| 127 base_layer_properties_size.ValueOrDefault(-1)); | 112 base_layer_properties_size.ValueOrDefault(-1)); |
| 128 value->SetInteger("PictureLayerPropertiesSize", | 113 value->SetInteger("PictureLayerPropertiesSize", |
| 129 picture_layer_properties_size.ValueOrDefault(-1)); | 114 picture_layer_properties_size.ValueOrDefault(-1)); |
| 130 value->SetInteger("DisplayItemListSize", | 115 value->SetInteger("DisplayItemListSize", |
| 131 display_item_list_size.ValueOrDefault(-1)); | 116 display_item_list_size.ValueOrDefault(-1)); |
| 132 value->SetInteger("DrawingDisplayItemsSize", | 117 value->SetInteger("DrawingDisplayItemsSize", |
| 133 drawing_display_items_size.ValueOrDefault(-1)); | 118 drawing_display_items_size.ValueOrDefault(-1)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 DCHECK(params->image_serialization_processor); | 190 DCHECK(params->image_serialization_processor); |
| 206 | 191 |
| 207 std::unique_ptr<LayerTreeHost> layer_tree_host( | 192 std::unique_ptr<LayerTreeHost> layer_tree_host( |
| 208 new LayerTreeHost(params, CompositorMode::REMOTE)); | 193 new LayerTreeHost(params, CompositorMode::REMOTE)); |
| 209 layer_tree_host->InitializeRemoteClient( | 194 layer_tree_host->InitializeRemoteClient( |
| 210 remote_proto_channel, params->main_task_runner, impl_task_runner); | 195 remote_proto_channel, params->main_task_runner, impl_task_runner); |
| 211 return layer_tree_host; | 196 return layer_tree_host; |
| 212 } | 197 } |
| 213 | 198 |
| 214 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) | 199 LayerTreeHost::LayerTreeHost(InitParams* params, CompositorMode mode) |
| 200 : LayerTreeHost( | |
| 201 params, | |
| 202 mode, | |
| 203 base::MakeUnique<LayerTree>(std::move(params->animation_host), | |
| 204 this)) {} | |
| 205 | |
| 206 LayerTreeHost::LayerTreeHost(InitParams* params, | |
| 207 CompositorMode mode, | |
| 208 std::unique_ptr<LayerTree> layer_tree) | |
| 215 : micro_benchmark_controller_(this), | 209 : micro_benchmark_controller_(this), |
| 210 layer_tree_(std::move(layer_tree)), | |
| 216 next_ui_resource_id_(1), | 211 next_ui_resource_id_(1), |
| 217 compositor_mode_(mode), | 212 compositor_mode_(mode), |
| 218 needs_full_tree_sync_(true), | |
| 219 needs_meta_info_recomputation_(true), | |
| 220 client_(params->client), | 213 client_(params->client), |
| 221 source_frame_number_(0), | 214 source_frame_number_(0), |
| 222 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), | 215 rendering_stats_instrumentation_(RenderingStatsInstrumentation::Create()), |
| 223 output_surface_lost_(true), | 216 output_surface_lost_(true), |
| 224 settings_(*params->settings), | 217 settings_(*params->settings), |
| 225 debug_state_(settings_.initial_debug_state), | 218 debug_state_(settings_.initial_debug_state), |
| 226 top_controls_shrink_blink_size_(false), | |
| 227 top_controls_height_(0.f), | |
| 228 top_controls_shown_ratio_(0.f), | |
| 229 device_scale_factor_(1.f), | |
| 230 painted_device_scale_factor_(1.f), | |
| 231 visible_(false), | 219 visible_(false), |
| 232 page_scale_factor_(1.f), | |
| 233 min_page_scale_factor_(1.f), | |
| 234 max_page_scale_factor_(1.f), | |
| 235 has_gpu_rasterization_trigger_(false), | 220 has_gpu_rasterization_trigger_(false), |
| 236 content_is_suitable_for_gpu_rasterization_(true), | 221 content_is_suitable_for_gpu_rasterization_(true), |
| 237 gpu_rasterization_histogram_recorded_(false), | 222 gpu_rasterization_histogram_recorded_(false), |
| 238 background_color_(SK_ColorWHITE), | |
| 239 has_transparent_background_(false), | |
| 240 have_scroll_event_handlers_(false), | |
| 241 event_listener_properties_(), | |
| 242 did_complete_scale_animation_(false), | 223 did_complete_scale_animation_(false), |
| 243 id_(s_layer_tree_host_sequence_number.GetNext() + 1), | 224 id_(s_layer_tree_host_sequence_number.GetNext() + 1), |
| 244 next_commit_forces_redraw_(false), | 225 next_commit_forces_redraw_(false), |
| 245 shared_bitmap_manager_(params->shared_bitmap_manager), | 226 shared_bitmap_manager_(params->shared_bitmap_manager), |
| 246 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), | 227 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), |
| 247 task_graph_runner_(params->task_graph_runner), | 228 task_graph_runner_(params->task_graph_runner), |
| 248 image_serialization_processor_(params->image_serialization_processor), | 229 image_serialization_processor_(params->image_serialization_processor), |
| 249 surface_client_id_(0u), | 230 surface_client_id_(0u), |
| 250 next_surface_sequence_(1u), | 231 next_surface_sequence_(1u) { |
| 251 layer_tree_(std::move(params->animation_host)) { | |
| 252 DCHECK(task_graph_runner_); | 232 DCHECK(task_graph_runner_); |
| 233 DCHECK(layer_tree_); | |
| 253 | 234 |
| 254 layer_tree_.animation_host()->SetMutatorHostClient(this); | 235 layer_tree_->animation_host()->SetMutatorHostClient(this); |
| 255 | 236 |
| 256 rendering_stats_instrumentation_->set_record_rendering_stats( | 237 rendering_stats_instrumentation_->set_record_rendering_stats( |
| 257 debug_state_.RecordRenderingStats()); | 238 debug_state_.RecordRenderingStats()); |
| 258 } | 239 } |
| 259 | 240 |
| 260 void LayerTreeHost::InitializeThreaded( | 241 void LayerTreeHost::InitializeThreaded( |
| 261 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 242 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 262 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | 243 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 263 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { | 244 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
| 264 task_runner_provider_ = | 245 task_runner_provider_ = |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 | 336 |
| 356 void LayerTreeHost::InitializeProxy( | 337 void LayerTreeHost::InitializeProxy( |
| 357 std::unique_ptr<Proxy> proxy, | 338 std::unique_ptr<Proxy> proxy, |
| 358 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { | 339 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
| 359 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); | 340 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); |
| 360 DCHECK(task_runner_provider_); | 341 DCHECK(task_runner_provider_); |
| 361 | 342 |
| 362 proxy_ = std::move(proxy); | 343 proxy_ = std::move(proxy); |
| 363 proxy_->Start(std::move(external_begin_frame_source)); | 344 proxy_->Start(std::move(external_begin_frame_source)); |
| 364 | 345 |
| 365 layer_tree_.animation_host()->SetSupportsScrollAnimations( | 346 layer_tree_->animation_host()->SetSupportsScrollAnimations( |
| 366 proxy_->SupportsImplScrolling()); | 347 proxy_->SupportsImplScrolling()); |
| 367 } | 348 } |
| 368 | 349 |
| 369 LayerTreeHost::~LayerTreeHost() { | 350 LayerTreeHost::~LayerTreeHost() { |
| 370 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); | 351 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); |
| 371 | 352 |
| 372 layer_tree_.animation_host()->SetMutatorHostClient(nullptr); | 353 // Clear any references into the LayerTreeHost. |
| 373 | 354 layer_tree_.reset(); |
| 374 if (root_layer_.get()) | |
| 375 root_layer_->SetLayerTreeHost(NULL); | |
| 376 | 355 |
| 377 DCHECK(swap_promise_monitor_.empty()); | 356 DCHECK(swap_promise_monitor_.empty()); |
| 378 | 357 |
| 379 BreakSwapPromises(SwapPromise::COMMIT_FAILS); | 358 BreakSwapPromises(SwapPromise::COMMIT_FAILS); |
| 380 | 359 |
| 381 if (proxy_) { | 360 if (proxy_) { |
| 382 DCHECK(task_runner_provider_->IsMainThread()); | 361 DCHECK(task_runner_provider_->IsMainThread()); |
| 383 proxy_->Stop(); | 362 proxy_->Stop(); |
| 384 | 363 |
| 385 // Proxy must be destroyed before the Task Runner Provider. | 364 // Proxy must be destroyed before the Task Runner Provider. |
| 386 proxy_ = nullptr; | 365 proxy_ = nullptr; |
| 387 } | 366 } |
| 388 | |
| 389 // We must clear any pointers into the layer tree prior to destroying it. | |
| 390 RegisterViewportLayers(NULL, NULL, NULL, NULL); | |
| 391 | |
| 392 if (root_layer_.get()) { | |
| 393 // The layer tree must be destroyed before the layer tree host. We've | |
| 394 // made a contract with our animation controllers that the animation_host | |
| 395 // will outlive them, and we must make good. | |
| 396 root_layer_ = NULL; | |
| 397 } | |
| 398 } | 367 } |
| 399 | 368 |
| 400 void LayerTreeHost::WillBeginMainFrame() { | 369 void LayerTreeHost::WillBeginMainFrame() { |
| 401 devtools_instrumentation::WillBeginMainThreadFrame(id(), | 370 devtools_instrumentation::WillBeginMainThreadFrame(id(), |
| 402 source_frame_number()); | 371 source_frame_number()); |
| 403 client_->WillBeginMainFrame(); | 372 client_->WillBeginMainFrame(); |
| 404 } | 373 } |
| 405 | 374 |
| 406 void LayerTreeHost::DidBeginMainFrame() { | 375 void LayerTreeHost::DidBeginMainFrame() { |
| 407 client_->DidBeginMainFrame(); | 376 client_->DidBeginMainFrame(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 429 // should be delayed until the LayerTreeHost::CommitComplete, which will run | 398 // should be delayed until the LayerTreeHost::CommitComplete, which will run |
| 430 // after the commit, but on the main thread. | 399 // after the commit, but on the main thread. |
| 431 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { | 400 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { |
| 432 DCHECK(!IsRemoteServer()); | 401 DCHECK(!IsRemoteServer()); |
| 433 DCHECK(task_runner_provider_->IsImplThread()); | 402 DCHECK(task_runner_provider_->IsImplThread()); |
| 434 | 403 |
| 435 bool is_new_trace; | 404 bool is_new_trace; |
| 436 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); | 405 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); |
| 437 if (is_new_trace && | 406 if (is_new_trace && |
| 438 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && | 407 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && |
| 439 root_layer()) { | 408 layer_tree_->root_layer()) { |
| 440 LayerTreeHostCommon::CallFunctionForEveryLayer( | 409 LayerTreeHostCommon::CallFunctionForEveryLayer( |
| 441 this, [](Layer* layer) { layer->DidBeginTracing(); }); | 410 this, [](Layer* layer) { layer->DidBeginTracing(); }); |
| 442 } | 411 } |
| 443 | 412 |
| 444 LayerTreeImpl* sync_tree = host_impl->sync_tree(); | 413 LayerTreeImpl* sync_tree = host_impl->sync_tree(); |
| 445 | 414 |
| 446 if (next_commit_forces_redraw_) { | 415 if (next_commit_forces_redraw_) { |
| 447 sync_tree->ForceRedrawNextActivation(); | 416 sync_tree->ForceRedrawNextActivation(); |
| 448 next_commit_forces_redraw_ = false; | 417 next_commit_forces_redraw_ = false; |
| 449 } | 418 } |
| 450 | 419 |
| 451 sync_tree->set_source_frame_number(source_frame_number()); | 420 sync_tree->set_source_frame_number(source_frame_number()); |
| 452 | 421 |
| 453 if (needs_full_tree_sync_) | 422 if (layer_tree_->needs_full_tree_sync()) |
| 454 TreeSynchronizer::SynchronizeTrees(root_layer(), sync_tree); | 423 TreeSynchronizer::SynchronizeTrees(layer_tree_->root_layer(), sync_tree); |
| 455 | 424 |
| 456 sync_tree->set_needs_full_tree_sync(needs_full_tree_sync_); | 425 layer_tree_->PushPropertiesTo(sync_tree); |
| 457 needs_full_tree_sync_ = false; | |
| 458 | |
| 459 if (hud_layer_.get()) { | |
| 460 LayerImpl* hud_impl = sync_tree->LayerById(hud_layer_->id()); | |
| 461 sync_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(hud_impl)); | |
| 462 } else { | |
| 463 sync_tree->set_hud_layer(NULL); | |
| 464 } | |
| 465 | |
| 466 sync_tree->set_background_color(background_color_); | |
| 467 sync_tree->set_has_transparent_background(has_transparent_background_); | |
| 468 sync_tree->set_have_scroll_event_handlers(have_scroll_event_handlers_); | |
| 469 sync_tree->set_event_listener_properties( | |
| 470 EventListenerClass::kTouchStartOrMove, | |
| 471 event_listener_properties(EventListenerClass::kTouchStartOrMove)); | |
| 472 sync_tree->set_event_listener_properties( | |
| 473 EventListenerClass::kMouseWheel, | |
| 474 event_listener_properties(EventListenerClass::kMouseWheel)); | |
| 475 sync_tree->set_event_listener_properties( | |
| 476 EventListenerClass::kTouchEndOrCancel, | |
| 477 event_listener_properties(EventListenerClass::kTouchEndOrCancel)); | |
| 478 | |
| 479 if (page_scale_layer_.get() && inner_viewport_scroll_layer_.get()) { | |
| 480 sync_tree->SetViewportLayersFromIds( | |
| 481 overscroll_elasticity_layer_.get() ? overscroll_elasticity_layer_->id() | |
| 482 : Layer::INVALID_ID, | |
| 483 page_scale_layer_->id(), inner_viewport_scroll_layer_->id(), | |
| 484 outer_viewport_scroll_layer_.get() ? outer_viewport_scroll_layer_->id() | |
| 485 : Layer::INVALID_ID); | |
| 486 DCHECK(inner_viewport_scroll_layer_->IsContainerForFixedPositionLayers()); | |
| 487 } else { | |
| 488 sync_tree->ClearViewportLayers(); | |
| 489 } | |
| 490 | |
| 491 sync_tree->RegisterSelection(selection_); | |
| 492 | |
| 493 bool property_trees_changed_on_active_tree = | |
| 494 sync_tree->IsActiveTree() && sync_tree->property_trees()->changed; | |
| 495 // Property trees may store damage status. We preserve the sync tree damage | |
| 496 // status by pushing the damage status from sync tree property trees to main | |
| 497 // thread property trees or by moving it onto the layers. | |
| 498 if (root_layer_ && property_trees_changed_on_active_tree) { | |
| 499 if (property_trees_.sequence_number == | |
| 500 sync_tree->property_trees()->sequence_number) | |
| 501 sync_tree->property_trees()->PushChangeTrackingTo(&property_trees_); | |
| 502 else | |
| 503 sync_tree->MoveChangeTrackingToLayers(); | |
| 504 } | |
| 505 // Setting property trees must happen before pushing the page scale. | |
| 506 sync_tree->SetPropertyTrees(&property_trees_); | |
| 507 | |
| 508 sync_tree->PushPageScaleFromMainThread( | |
| 509 page_scale_factor_, min_page_scale_factor_, max_page_scale_factor_); | |
| 510 sync_tree->elastic_overscroll()->PushFromMainThread(elastic_overscroll_); | |
| 511 if (sync_tree->IsActiveTree()) | |
| 512 sync_tree->elastic_overscroll()->PushPendingToActive(); | |
| 513 | 426 |
| 514 sync_tree->PassSwapPromises(std::move(swap_promise_list_)); | 427 sync_tree->PassSwapPromises(std::move(swap_promise_list_)); |
| 515 | 428 |
| 516 sync_tree->set_top_controls_shrink_blink_size( | |
| 517 top_controls_shrink_blink_size_); | |
| 518 sync_tree->set_top_controls_height(top_controls_height_); | |
| 519 sync_tree->PushTopControlsFromMainThread(top_controls_shown_ratio_); | |
| 520 | |
| 521 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); | 429 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); |
| 522 host_impl->SetContentIsSuitableForGpuRasterization( | 430 host_impl->SetContentIsSuitableForGpuRasterization( |
| 523 content_is_suitable_for_gpu_rasterization_); | 431 content_is_suitable_for_gpu_rasterization_); |
| 524 RecordGpuRasterizationHistogram(); | 432 RecordGpuRasterizationHistogram(); |
| 525 | 433 |
| 526 host_impl->SetViewportSize(device_viewport_size_); | 434 host_impl->SetViewportSize(layer_tree_->device_viewport_size()); |
| 527 // TODO(senorblanco): Move this up so that it happens before GPU rasterization | 435 // TODO(senorblanco): Move this to LayerTree::PushPropertiesTo so that it |
| 528 // properties are set, since those trigger an update of GPU rasterization | 436 // happens before GPU rasterization properties are set, since those trigger an |
| 529 // status, which depends on the device scale factor. (crbug.com/535700) | 437 // update of GPU rasterization status, which depends on the device scale |
| 530 sync_tree->SetDeviceScaleFactor(device_scale_factor_); | 438 // factor. (crbug.com/535700) |
| 531 sync_tree->set_painted_device_scale_factor(painted_device_scale_factor_); | 439 sync_tree->SetDeviceScaleFactor(layer_tree_->device_scale_factor()); |
| 532 host_impl->SetDebugState(debug_state_); | 440 host_impl->SetDebugState(debug_state_); |
| 533 if (pending_page_scale_animation_) { | |
| 534 sync_tree->SetPendingPageScaleAnimation( | |
| 535 std::move(pending_page_scale_animation_)); | |
| 536 } | |
| 537 | 441 |
| 538 if (!ui_resource_request_queue_.empty()) { | 442 if (!ui_resource_request_queue_.empty()) { |
| 539 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue_); | 443 sync_tree->set_ui_resource_request_queue(ui_resource_request_queue_); |
| 540 ui_resource_request_queue_.clear(); | 444 ui_resource_request_queue_.clear(); |
| 541 } | 445 } |
| 542 | 446 |
| 543 DCHECK(!sync_tree->ViewportSizeInvalid()); | |
| 544 | |
| 545 sync_tree->set_has_ever_been_drawn(false); | |
| 546 | |
| 547 { | 447 { |
| 548 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties"); | 448 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties"); |
| 549 | 449 |
| 550 TreeSynchronizer::PushLayerProperties(&layer_tree_, sync_tree); | 450 TreeSynchronizer::PushLayerProperties(layer_tree_.get(), sync_tree); |
| 551 | 451 |
| 552 // This must happen after synchronizing property trees and after push | 452 // This must happen after synchronizing property trees and after push |
| 553 // properties, which updates property tree indices, but before animation | 453 // properties, which updates property tree indices, but before animation |
| 554 // host pushes properties as animation host push properties can change | 454 // host pushes properties as animation host push properties can change |
| 555 // Animation::InEffect and we want the old InEffect value for updating | 455 // Animation::InEffect and we want the old InEffect value for updating |
| 556 // property tree scrolling and animation. | 456 // property tree scrolling and animation. |
| 557 sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread(); | 457 sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread(); |
| 558 | 458 |
| 559 TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties"); | 459 TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties"); |
| 560 DCHECK(host_impl->animation_host()); | 460 DCHECK(host_impl->animation_host()); |
| 561 layer_tree_.animation_host()->PushPropertiesTo(host_impl->animation_host()); | 461 layer_tree_->animation_host()->PushPropertiesTo( |
|
loyso (OOO)
2016/08/16 02:55:41
Notice that AnimationHost is owned by LayerTree, b
Khushal
2016/08/16 04:28:53
It can be done there too, we can just pass the imp
Khushal
2016/08/16 21:47:36
I'll land this now because this change is mostly m
| |
| 462 host_impl->animation_host()); | |
| 562 } | 463 } |
| 563 | 464 |
| 564 // This must happen after synchronizing property trees and after pushing | 465 // This must happen after synchronizing property trees and after pushing |
| 565 // properties, which updates the clobber_active_value flag. | 466 // properties, which updates the clobber_active_value flag. |
| 566 sync_tree->UpdatePropertyTreeScrollOffset(&property_trees_); | 467 sync_tree->UpdatePropertyTreeScrollOffset(layer_tree_->property_trees()); |
| 567 | 468 |
| 568 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); | 469 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); |
| 569 property_trees_.ResetAllChangeTracking(); | 470 layer_tree_->property_trees()->ResetAllChangeTracking(); |
| 570 } | 471 } |
| 571 | 472 |
| 572 void LayerTreeHost::WillCommit() { | 473 void LayerTreeHost::WillCommit() { |
| 573 OnCommitForSwapPromises(); | 474 OnCommitForSwapPromises(); |
| 574 client_->WillCommit(); | 475 client_->WillCommit(); |
| 575 } | 476 } |
| 576 | 477 |
| 577 void LayerTreeHost::UpdateHudLayer() { | 478 void LayerTreeHost::UpdateHudLayer() { |
| 578 if (debug_state_.ShowHudInfo()) { | |
| 579 if (!hud_layer_.get()) { | |
| 580 hud_layer_ = HeadsUpDisplayLayer::Create(); | |
| 581 } | |
| 582 | |
| 583 if (root_layer_.get() && !hud_layer_->parent()) | |
| 584 root_layer_->AddChild(hud_layer_); | |
| 585 } else if (hud_layer_.get()) { | |
| 586 hud_layer_->RemoveFromParent(); | |
| 587 hud_layer_ = NULL; | |
| 588 } | |
| 589 } | 479 } |
| 590 | 480 |
| 591 void LayerTreeHost::CommitComplete() { | 481 void LayerTreeHost::CommitComplete() { |
| 592 source_frame_number_++; | 482 source_frame_number_++; |
| 593 client_->DidCommit(); | 483 client_->DidCommit(); |
| 594 if (did_complete_scale_animation_) { | 484 if (did_complete_scale_animation_) { |
| 595 client_->DidCompletePageScaleAnimation(); | 485 client_->DidCompletePageScaleAnimation(); |
| 596 did_complete_scale_animation_ = false; | 486 did_complete_scale_animation_ = false; |
| 597 } | 487 } |
| 598 } | 488 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 client_->DidFailToInitializeOutputSurface(); | 528 client_->DidFailToInitializeOutputSurface(); |
| 639 } | 529 } |
| 640 | 530 |
| 641 std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 531 std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
| 642 LayerTreeHostImplClient* client) { | 532 LayerTreeHostImplClient* client) { |
| 643 DCHECK(!IsRemoteServer()); | 533 DCHECK(!IsRemoteServer()); |
| 644 DCHECK(task_runner_provider_->IsImplThread()); | 534 DCHECK(task_runner_provider_->IsImplThread()); |
| 645 | 535 |
| 646 const bool supports_impl_scrolling = task_runner_provider_->HasImplThread(); | 536 const bool supports_impl_scrolling = task_runner_provider_->HasImplThread(); |
| 647 std::unique_ptr<AnimationHost> animation_host_impl = | 537 std::unique_ptr<AnimationHost> animation_host_impl = |
| 648 layer_tree_.animation_host()->CreateImplInstance(supports_impl_scrolling); | 538 layer_tree_->animation_host()->CreateImplInstance( |
| 539 supports_impl_scrolling); | |
| 649 | 540 |
| 650 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( | 541 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
| 651 settings_, client, task_runner_provider_.get(), | 542 settings_, client, task_runner_provider_.get(), |
| 652 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, | 543 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, |
| 653 gpu_memory_buffer_manager_, task_graph_runner_, | 544 gpu_memory_buffer_manager_, task_graph_runner_, |
| 654 std::move(animation_host_impl), id_); | 545 std::move(animation_host_impl), id_); |
| 655 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); | 546 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); |
| 656 host_impl->SetContentIsSuitableForGpuRasterization( | 547 host_impl->SetContentIsSuitableForGpuRasterization( |
| 657 content_is_suitable_for_gpu_rasterization_); | 548 content_is_suitable_for_gpu_rasterization_); |
| 658 shared_bitmap_manager_ = NULL; | 549 shared_bitmap_manager_ = NULL; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 void LayerTreeHost::SetNeedsAnimate() { | 584 void LayerTreeHost::SetNeedsAnimate() { |
| 694 proxy_->SetNeedsAnimate(); | 585 proxy_->SetNeedsAnimate(); |
| 695 NotifySwapPromiseMonitorsOfSetNeedsCommit(); | 586 NotifySwapPromiseMonitorsOfSetNeedsCommit(); |
| 696 } | 587 } |
| 697 | 588 |
| 698 void LayerTreeHost::SetNeedsUpdateLayers() { | 589 void LayerTreeHost::SetNeedsUpdateLayers() { |
| 699 proxy_->SetNeedsUpdateLayers(); | 590 proxy_->SetNeedsUpdateLayers(); |
| 700 NotifySwapPromiseMonitorsOfSetNeedsCommit(); | 591 NotifySwapPromiseMonitorsOfSetNeedsCommit(); |
| 701 } | 592 } |
| 702 | 593 |
| 703 void LayerTreeHost::SetPropertyTreesNeedRebuild() { | |
| 704 property_trees_.needs_rebuild = true; | |
| 705 SetNeedsUpdateLayers(); | |
| 706 } | |
| 707 | |
| 708 void LayerTreeHost::SetNeedsCommit() { | 594 void LayerTreeHost::SetNeedsCommit() { |
| 709 proxy_->SetNeedsCommit(); | 595 proxy_->SetNeedsCommit(); |
| 710 NotifySwapPromiseMonitorsOfSetNeedsCommit(); | 596 NotifySwapPromiseMonitorsOfSetNeedsCommit(); |
| 711 } | 597 } |
| 712 | 598 |
| 713 void LayerTreeHost::SetNeedsFullTreeSync() { | |
| 714 needs_full_tree_sync_ = true; | |
| 715 needs_meta_info_recomputation_ = true; | |
| 716 | |
| 717 property_trees_.needs_rebuild = true; | |
| 718 SetNeedsCommit(); | |
| 719 } | |
| 720 | |
| 721 void LayerTreeHost::SetNeedsMetaInfoRecomputation(bool needs_recomputation) { | |
| 722 needs_meta_info_recomputation_ = needs_recomputation; | |
| 723 } | |
| 724 | |
| 725 void LayerTreeHost::SetNeedsRedraw() { | 599 void LayerTreeHost::SetNeedsRedraw() { |
| 726 SetNeedsRedrawRect(gfx::Rect(device_viewport_size_)); | 600 SetNeedsRedrawRect(gfx::Rect(layer_tree_->device_viewport_size())); |
| 727 } | 601 } |
| 728 | 602 |
| 729 void LayerTreeHost::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 603 void LayerTreeHost::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
| 730 proxy_->SetNeedsRedraw(damage_rect); | 604 proxy_->SetNeedsRedraw(damage_rect); |
| 731 } | 605 } |
| 732 | 606 |
| 733 bool LayerTreeHost::CommitRequested() const { | 607 bool LayerTreeHost::CommitRequested() const { |
| 734 return proxy_->CommitRequested(); | 608 return proxy_->CommitRequested(); |
| 735 } | 609 } |
| 736 | 610 |
| 737 bool LayerTreeHost::BeginMainFrameRequested() const { | 611 bool LayerTreeHost::BeginMainFrameRequested() const { |
| 738 return proxy_->BeginMainFrameRequested(); | 612 return proxy_->BeginMainFrameRequested(); |
| 739 } | 613 } |
| 740 | 614 |
| 741 void LayerTreeHost::SetNextCommitWaitsForActivation() { | 615 void LayerTreeHost::SetNextCommitWaitsForActivation() { |
| 742 proxy_->SetNextCommitWaitsForActivation(); | 616 proxy_->SetNextCommitWaitsForActivation(); |
| 743 } | 617 } |
| 744 | 618 |
| 745 void LayerTreeHost::SetNextCommitForcesRedraw() { | 619 void LayerTreeHost::SetNextCommitForcesRedraw() { |
| 746 next_commit_forces_redraw_ = true; | 620 next_commit_forces_redraw_ = true; |
| 747 proxy_->SetNeedsUpdateLayers(); | 621 proxy_->SetNeedsUpdateLayers(); |
| 748 } | 622 } |
| 749 | 623 |
| 750 void LayerTreeHost::SetAnimationEvents( | 624 void LayerTreeHost::SetAnimationEvents( |
| 751 std::unique_ptr<AnimationEvents> events) { | 625 std::unique_ptr<AnimationEvents> events) { |
| 752 DCHECK(task_runner_provider_->IsMainThread()); | 626 DCHECK(task_runner_provider_->IsMainThread()); |
| 753 layer_tree_.animation_host()->SetAnimationEvents(std::move(events)); | 627 layer_tree_->animation_host()->SetAnimationEvents(std::move(events)); |
| 754 } | |
| 755 | |
| 756 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { | |
| 757 if (root_layer_.get() == root_layer.get()) | |
| 758 return; | |
| 759 | |
| 760 if (root_layer_.get()) | |
| 761 root_layer_->SetLayerTreeHost(NULL); | |
| 762 root_layer_ = root_layer; | |
| 763 if (root_layer_.get()) { | |
| 764 DCHECK(!root_layer_->parent()); | |
| 765 root_layer_->SetLayerTreeHost(this); | |
| 766 } | |
| 767 | |
| 768 if (hud_layer_.get()) | |
| 769 hud_layer_->RemoveFromParent(); | |
| 770 | |
| 771 // Reset gpu rasterization flag. | |
| 772 // This flag is sticky until a new tree comes along. | |
| 773 content_is_suitable_for_gpu_rasterization_ = true; | |
| 774 gpu_rasterization_histogram_recorded_ = false; | |
| 775 | |
| 776 SetNeedsFullTreeSync(); | |
| 777 } | 628 } |
| 778 | 629 |
| 779 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) { | 630 void LayerTreeHost::SetDebugState(const LayerTreeDebugState& debug_state) { |
| 780 LayerTreeDebugState new_debug_state = | 631 LayerTreeDebugState new_debug_state = |
| 781 LayerTreeDebugState::Unite(settings_.initial_debug_state, debug_state); | 632 LayerTreeDebugState::Unite(settings_.initial_debug_state, debug_state); |
| 782 | 633 |
| 783 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) | 634 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) |
| 784 return; | 635 return; |
| 785 | 636 |
| 786 debug_state_ = new_debug_state; | 637 debug_state_ = new_debug_state; |
| 787 | 638 |
| 788 rendering_stats_instrumentation_->set_record_rendering_stats( | 639 rendering_stats_instrumentation_->set_record_rendering_stats( |
| 789 debug_state_.RecordRenderingStats()); | 640 debug_state_.RecordRenderingStats()); |
| 790 | 641 |
| 791 SetNeedsCommit(); | 642 SetNeedsCommit(); |
| 792 } | 643 } |
| 793 | 644 |
| 645 void LayerTreeHost::ResetGpuRasterizationTracking() { | |
| 646 content_is_suitable_for_gpu_rasterization_ = true; | |
| 647 gpu_rasterization_histogram_recorded_ = false; | |
| 648 } | |
| 649 | |
| 794 void LayerTreeHost::SetHasGpuRasterizationTrigger(bool has_trigger) { | 650 void LayerTreeHost::SetHasGpuRasterizationTrigger(bool has_trigger) { |
| 795 if (has_trigger == has_gpu_rasterization_trigger_) | 651 if (has_trigger == has_gpu_rasterization_trigger_) |
| 796 return; | 652 return; |
| 797 | 653 |
| 798 has_gpu_rasterization_trigger_ = has_trigger; | 654 has_gpu_rasterization_trigger_ = has_trigger; |
| 799 TRACE_EVENT_INSTANT1("cc", | 655 TRACE_EVENT_INSTANT1("cc", |
| 800 "LayerTreeHost::SetHasGpuRasterizationTrigger", | 656 "LayerTreeHost::SetHasGpuRasterizationTrigger", |
| 801 TRACE_EVENT_SCOPE_THREAD, | 657 TRACE_EVENT_SCOPE_THREAD, |
| 802 "has_trigger", | 658 "has_trigger", |
| 803 has_gpu_rasterization_trigger_); | 659 has_gpu_rasterization_trigger_); |
| 804 } | 660 } |
| 805 | 661 |
| 806 void LayerTreeHost::SetViewportSize(const gfx::Size& device_viewport_size) { | |
| 807 if (device_viewport_size == device_viewport_size_) | |
| 808 return; | |
| 809 | |
| 810 device_viewport_size_ = device_viewport_size; | |
| 811 | |
| 812 SetPropertyTreesNeedRebuild(); | |
| 813 SetNeedsCommit(); | |
| 814 } | |
| 815 | |
| 816 void LayerTreeHost::SetTopControlsHeight(float height, bool shrink) { | |
| 817 if (top_controls_height_ == height && | |
| 818 top_controls_shrink_blink_size_ == shrink) | |
| 819 return; | |
| 820 | |
| 821 top_controls_height_ = height; | |
| 822 top_controls_shrink_blink_size_ = shrink; | |
| 823 SetNeedsCommit(); | |
| 824 } | |
| 825 | |
| 826 void LayerTreeHost::SetTopControlsShownRatio(float ratio) { | |
| 827 if (top_controls_shown_ratio_ == ratio) | |
| 828 return; | |
| 829 | |
| 830 top_controls_shown_ratio_ = ratio; | |
| 831 SetNeedsCommit(); | |
| 832 } | |
| 833 | |
| 834 void LayerTreeHost::ApplyPageScaleDeltaFromImplSide(float page_scale_delta) { | 662 void LayerTreeHost::ApplyPageScaleDeltaFromImplSide(float page_scale_delta) { |
| 835 DCHECK(CommitRequested()); | 663 DCHECK(CommitRequested()); |
| 836 if (page_scale_delta == 1.f) | 664 if (page_scale_delta == 1.f) |
| 837 return; | 665 return; |
| 838 page_scale_factor_ *= page_scale_delta; | 666 float page_scale = layer_tree_->page_scale_factor() * page_scale_delta; |
| 839 SetPropertyTreesNeedRebuild(); | 667 layer_tree_->SetPageScaleFromImplSide(page_scale); |
| 840 } | |
| 841 | |
| 842 void LayerTreeHost::SetPageScaleFactorAndLimits(float page_scale_factor, | |
| 843 float min_page_scale_factor, | |
| 844 float max_page_scale_factor) { | |
| 845 if (page_scale_factor == page_scale_factor_ && | |
| 846 min_page_scale_factor == min_page_scale_factor_ && | |
| 847 max_page_scale_factor == max_page_scale_factor_) | |
| 848 return; | |
| 849 | |
| 850 page_scale_factor_ = page_scale_factor; | |
| 851 min_page_scale_factor_ = min_page_scale_factor; | |
| 852 max_page_scale_factor_ = max_page_scale_factor; | |
| 853 SetPropertyTreesNeedRebuild(); | |
| 854 SetNeedsCommit(); | |
| 855 } | 668 } |
| 856 | 669 |
| 857 void LayerTreeHost::SetVisible(bool visible) { | 670 void LayerTreeHost::SetVisible(bool visible) { |
| 858 if (visible_ == visible) | 671 if (visible_ == visible) |
| 859 return; | 672 return; |
| 860 visible_ = visible; | 673 visible_ = visible; |
| 861 proxy_->SetVisible(visible); | 674 proxy_->SetVisible(visible); |
| 862 } | 675 } |
| 863 | 676 |
| 864 void LayerTreeHost::StartPageScaleAnimation(const gfx::Vector2d& target_offset, | |
| 865 bool use_anchor, | |
| 866 float scale, | |
| 867 base::TimeDelta duration) { | |
| 868 pending_page_scale_animation_.reset( | |
| 869 new PendingPageScaleAnimation( | |
| 870 target_offset, | |
| 871 use_anchor, | |
| 872 scale, | |
| 873 duration)); | |
| 874 | |
| 875 SetNeedsCommit(); | |
| 876 } | |
| 877 | |
| 878 bool LayerTreeHost::HasPendingPageScaleAnimation() const { | |
| 879 return !!pending_page_scale_animation_.get(); | |
| 880 } | |
| 881 | |
| 882 void LayerTreeHost::NotifyInputThrottledUntilCommit() { | 677 void LayerTreeHost::NotifyInputThrottledUntilCommit() { |
| 883 proxy_->NotifyInputThrottledUntilCommit(); | 678 proxy_->NotifyInputThrottledUntilCommit(); |
| 884 } | 679 } |
| 885 | 680 |
| 886 void LayerTreeHost::LayoutAndUpdateLayers() { | 681 void LayerTreeHost::LayoutAndUpdateLayers() { |
| 887 DCHECK(IsSingleThreaded()); | 682 DCHECK(IsSingleThreaded()); |
| 888 // This function is only valid when not using the scheduler. | 683 // This function is only valid when not using the scheduler. |
| 889 DCHECK(!settings_.single_thread_proxy_scheduler); | 684 DCHECK(!settings_.single_thread_proxy_scheduler); |
| 890 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); | 685 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); |
| 891 | 686 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 905 DCHECK(IsSingleThreaded()); | 700 DCHECK(IsSingleThreaded()); |
| 906 // This function is only valid when not using the scheduler. | 701 // This function is only valid when not using the scheduler. |
| 907 DCHECK(!settings_.single_thread_proxy_scheduler); | 702 DCHECK(!settings_.single_thread_proxy_scheduler); |
| 908 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); | 703 SingleThreadProxy* proxy = static_cast<SingleThreadProxy*>(proxy_.get()); |
| 909 | 704 |
| 910 proxy->CompositeImmediately(frame_begin_time); | 705 proxy->CompositeImmediately(frame_begin_time); |
| 911 } | 706 } |
| 912 | 707 |
| 913 bool LayerTreeHost::UpdateLayers() { | 708 bool LayerTreeHost::UpdateLayers() { |
| 914 DCHECK(!output_surface_lost_); | 709 DCHECK(!output_surface_lost_); |
| 915 if (!root_layer()) | 710 if (!layer_tree_->root_layer()) |
| 916 return false; | 711 return false; |
| 917 DCHECK(!root_layer()->parent()); | 712 DCHECK(!layer_tree_->root_layer()->parent()); |
| 918 bool result = DoUpdateLayers(root_layer()); | 713 bool result = DoUpdateLayers(layer_tree_->root_layer()); |
| 919 micro_benchmark_controller_.DidUpdateLayers(); | 714 micro_benchmark_controller_.DidUpdateLayers(); |
| 920 return result || next_commit_forces_redraw_; | 715 return result || next_commit_forces_redraw_; |
| 921 } | 716 } |
| 922 | 717 |
| 923 LayerListIterator<Layer> LayerTreeHost::begin() const { | 718 LayerListIterator<Layer> LayerTreeHost::begin() const { |
| 924 return LayerListIterator<Layer>(root_layer_.get()); | 719 return LayerListIterator<Layer>(layer_tree_->root_layer()); |
| 925 } | 720 } |
| 926 | 721 |
| 927 LayerListIterator<Layer> LayerTreeHost::end() const { | 722 LayerListIterator<Layer> LayerTreeHost::end() const { |
| 928 return LayerListIterator<Layer>(nullptr); | 723 return LayerListIterator<Layer>(nullptr); |
| 929 } | 724 } |
| 930 | 725 |
| 931 LayerListReverseIterator<Layer> LayerTreeHost::rbegin() { | 726 LayerListReverseIterator<Layer> LayerTreeHost::rbegin() { |
| 932 return LayerListReverseIterator<Layer>(root_layer_.get()); | 727 return LayerListReverseIterator<Layer>(layer_tree_->root_layer()); |
| 933 } | 728 } |
| 934 | 729 |
| 935 LayerListReverseIterator<Layer> LayerTreeHost::rend() { | 730 LayerListReverseIterator<Layer> LayerTreeHost::rend() { |
| 936 return LayerListReverseIterator<Layer>(nullptr); | 731 return LayerListReverseIterator<Layer>(nullptr); |
| 937 } | 732 } |
| 938 | 733 |
| 939 void LayerTreeHost::DidCompletePageScaleAnimation() { | 734 void LayerTreeHost::DidCompletePageScaleAnimation() { |
| 940 did_complete_scale_animation_ = true; | 735 did_complete_scale_animation_ = true; |
| 941 } | 736 } |
| 942 | 737 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 960 // Record how many pages actually get gpu rasterization when enabled. | 755 // Record how many pages actually get gpu rasterization when enabled. |
| 961 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationUsed", | 756 UMA_HISTOGRAM_BOOLEAN("Renderer4.GpuRasterizationUsed", |
| 962 (has_gpu_rasterization_trigger_ && | 757 (has_gpu_rasterization_trigger_ && |
| 963 content_is_suitable_for_gpu_rasterization_)); | 758 content_is_suitable_for_gpu_rasterization_)); |
| 964 } | 759 } |
| 965 | 760 |
| 966 gpu_rasterization_histogram_recorded_ = true; | 761 gpu_rasterization_histogram_recorded_ = true; |
| 967 } | 762 } |
| 968 | 763 |
| 969 void LayerTreeHost::BuildPropertyTreesForTesting() { | 764 void LayerTreeHost::BuildPropertyTreesForTesting() { |
| 970 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer_.get()); | 765 PropertyTreeBuilder::PreCalculateMetaInformation(layer_tree_->root_layer()); |
| 971 gfx::Transform identity_transform; | 766 gfx::Transform identity_transform; |
| 972 PropertyTreeBuilder::BuildPropertyTrees( | 767 PropertyTreeBuilder::BuildPropertyTrees( |
| 973 root_layer_.get(), page_scale_layer_.get(), | 768 layer_tree_->root_layer(), layer_tree_->page_scale_layer(), |
| 974 inner_viewport_scroll_layer_.get(), outer_viewport_scroll_layer_.get(), | 769 layer_tree_->inner_viewport_scroll_layer(), |
| 975 overscroll_elasticity_layer_.get(), elastic_overscroll_, | 770 layer_tree_->outer_viewport_scroll_layer(), |
| 976 page_scale_factor_, device_scale_factor_, | 771 layer_tree_->overscroll_elasticity_layer(), elastic_overscroll_, |
| 977 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_); | 772 layer_tree_->page_scale_factor(), layer_tree_->device_scale_factor(), |
| 773 gfx::Rect(layer_tree_->device_viewport_size()), identity_transform, | |
| 774 layer_tree_->property_trees()); | |
| 978 } | 775 } |
| 979 | 776 |
| 980 static void SetElementIdForTesting(Layer* layer) { | 777 static void SetElementIdForTesting(Layer* layer) { |
| 981 layer->SetElementId(LayerIdToElementIdForTesting(layer->id())); | 778 layer->SetElementId(LayerIdToElementIdForTesting(layer->id())); |
| 982 } | 779 } |
| 983 | 780 |
| 984 void LayerTreeHost::SetElementIdsForTesting() { | 781 void LayerTreeHost::SetElementIdsForTesting() { |
| 985 LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting); | 782 LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting); |
| 986 } | 783 } |
| 987 | 784 |
| 988 bool LayerTreeHost::UsingSharedMemoryResources() { | 785 bool LayerTreeHost::UsingSharedMemoryResources() { |
| 989 return GetRendererCapabilities().using_shared_memory_resources; | 786 return GetRendererCapabilities().using_shared_memory_resources; |
| 990 } | 787 } |
| 991 | 788 |
| 992 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { | 789 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { |
| 993 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number", | 790 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number", |
| 994 source_frame_number()); | 791 source_frame_number()); |
| 995 | 792 |
| 793 layer_tree_->UpdateHudLayer(debug_state_.ShowHudInfo()); | |
| 996 UpdateHudLayer(); | 794 UpdateHudLayer(); |
| 997 | 795 |
| 998 Layer* root_scroll = | 796 Layer* root_scroll = |
| 999 PropertyTreeBuilder::FindFirstScrollableLayer(root_layer); | 797 PropertyTreeBuilder::FindFirstScrollableLayer(root_layer); |
| 1000 Layer* page_scale_layer = page_scale_layer_.get(); | 798 Layer* page_scale_layer = layer_tree_->page_scale_layer(); |
| 1001 if (!page_scale_layer && root_scroll) | 799 if (!page_scale_layer && root_scroll) |
| 1002 page_scale_layer = root_scroll->parent(); | 800 page_scale_layer = root_scroll->parent(); |
| 1003 | 801 |
| 1004 if (hud_layer_.get()) { | 802 if (layer_tree_->hud_layer()) { |
| 1005 hud_layer_->PrepareForCalculateDrawProperties(device_viewport_size(), | 803 layer_tree_->hud_layer()->PrepareForCalculateDrawProperties( |
| 1006 device_scale_factor_); | 804 layer_tree_->device_viewport_size(), |
| 805 layer_tree_->device_scale_factor()); | |
| 1007 } | 806 } |
| 1008 | 807 |
| 1009 gfx::Transform identity_transform; | 808 gfx::Transform identity_transform; |
| 1010 LayerList update_layer_list; | 809 LayerList update_layer_list; |
| 1011 | 810 |
| 1012 { | 811 { |
| 1013 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::BuildPropertyTrees"); | 812 TRACE_EVENT0("cc", "LayerTreeHost::UpdateLayers::BuildPropertyTrees"); |
| 1014 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 813 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
| 1015 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees"); | 814 "LayerTreeHostCommon::ComputeVisibleRectsWithPropertyTrees"); |
| 1016 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); | 815 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer); |
| 1017 bool can_render_to_separate_surface = true; | 816 bool can_render_to_separate_surface = true; |
| 817 PropertyTrees* property_trees = layer_tree_->property_trees(); | |
| 1018 if (!settings_.use_layer_lists) { | 818 if (!settings_.use_layer_lists) { |
| 1019 // If use_layer_lists is set, then the property trees should have been | 819 // If use_layer_lists is set, then the property trees should have been |
| 1020 // built by the client already. | 820 // built by the client already. |
| 1021 PropertyTreeBuilder::BuildPropertyTrees( | 821 PropertyTreeBuilder::BuildPropertyTrees( |
| 1022 root_layer, page_scale_layer, inner_viewport_scroll_layer_.get(), | 822 root_layer, page_scale_layer, |
| 1023 outer_viewport_scroll_layer_.get(), | 823 layer_tree_->inner_viewport_scroll_layer(), |
| 1024 overscroll_elasticity_layer_.get(), elastic_overscroll_, | 824 layer_tree_->outer_viewport_scroll_layer(), |
| 1025 page_scale_factor_, device_scale_factor_, | 825 layer_tree_->overscroll_elasticity_layer(), elastic_overscroll_, |
| 1026 gfx::Rect(device_viewport_size_), identity_transform, | 826 layer_tree_->page_scale_factor(), layer_tree_->device_scale_factor(), |
| 1027 &property_trees_); | 827 gfx::Rect(layer_tree_->device_viewport_size()), identity_transform, |
| 828 property_trees); | |
| 1028 TRACE_EVENT_INSTANT1("cc", | 829 TRACE_EVENT_INSTANT1("cc", |
| 1029 "LayerTreeHost::UpdateLayers_BuiltPropertyTrees", | 830 "LayerTreeHost::UpdateLayers_BuiltPropertyTrees", |
| 1030 TRACE_EVENT_SCOPE_THREAD, "property_trees", | 831 TRACE_EVENT_SCOPE_THREAD, "property_trees", |
| 1031 property_trees_.AsTracedValue()); | 832 property_trees->AsTracedValue()); |
| 1032 } else { | 833 } else { |
| 1033 TRACE_EVENT_INSTANT1("cc", | 834 TRACE_EVENT_INSTANT1("cc", |
| 1034 "LayerTreeHost::UpdateLayers_ReceivedPropertyTrees", | 835 "LayerTreeHost::UpdateLayers_ReceivedPropertyTrees", |
| 1035 TRACE_EVENT_SCOPE_THREAD, "property_trees", | 836 TRACE_EVENT_SCOPE_THREAD, "property_trees", |
| 1036 property_trees_.AsTracedValue()); | 837 property_trees->AsTracedValue()); |
| 1037 } | 838 } |
| 1038 draw_property_utils::UpdatePropertyTrees(&property_trees_, | 839 draw_property_utils::UpdatePropertyTrees(property_trees, |
| 1039 can_render_to_separate_surface); | 840 can_render_to_separate_surface); |
| 1040 draw_property_utils::FindLayersThatNeedUpdates( | 841 draw_property_utils::FindLayersThatNeedUpdates( |
| 1041 this, property_trees_.transform_tree, property_trees_.effect_tree, | 842 this, property_trees->transform_tree, property_trees->effect_tree, |
| 1042 &update_layer_list); | 843 &update_layer_list); |
| 1043 } | 844 } |
| 1044 | 845 |
| 1045 for (const auto& layer : update_layer_list) | 846 for (const auto& layer : update_layer_list) |
| 1046 layer->SavePaintProperties(); | 847 layer->SavePaintProperties(); |
| 1047 | 848 |
| 1048 bool content_is_suitable_for_gpu = true; | 849 bool content_is_suitable_for_gpu = true; |
| 1049 bool did_paint_content = | 850 bool did_paint_content = layer_tree_->UpdateLayers( |
| 1050 layer_tree_.UpdateLayers(update_layer_list, &content_is_suitable_for_gpu); | 851 update_layer_list, &content_is_suitable_for_gpu); |
| 1051 | 852 |
| 1052 if (content_is_suitable_for_gpu) { | 853 if (content_is_suitable_for_gpu) { |
| 1053 ++num_consecutive_frames_suitable_for_gpu_; | 854 ++num_consecutive_frames_suitable_for_gpu_; |
| 1054 if (num_consecutive_frames_suitable_for_gpu_ >= | 855 if (num_consecutive_frames_suitable_for_gpu_ >= |
| 1055 kNumFramesToConsiderBeforeGpuRasterization) { | 856 kNumFramesToConsiderBeforeGpuRasterization) { |
| 1056 content_is_suitable_for_gpu_rasterization_ = true; | 857 content_is_suitable_for_gpu_rasterization_ = true; |
| 1057 } | 858 } |
| 1058 } else { | 859 } else { |
| 1059 num_consecutive_frames_suitable_for_gpu_ = 0; | 860 num_consecutive_frames_suitable_for_gpu_ = 0; |
| 1060 content_is_suitable_for_gpu_rasterization_ = false; | 861 content_is_suitable_for_gpu_rasterization_ = false; |
| 1061 } | 862 } |
| 1062 return did_paint_content; | 863 return did_paint_content; |
| 1063 } | 864 } |
| 1064 | 865 |
| 1065 void LayerTreeHost::ApplyViewportDeltas(ScrollAndScaleSet* info) { | 866 void LayerTreeHost::ApplyViewportDeltas(ScrollAndScaleSet* info) { |
| 1066 gfx::Vector2dF inner_viewport_scroll_delta; | 867 gfx::Vector2dF inner_viewport_scroll_delta; |
| 1067 if (info->inner_viewport_scroll.layer_id != Layer::INVALID_ID) | 868 if (info->inner_viewport_scroll.layer_id != Layer::INVALID_ID) |
| 1068 inner_viewport_scroll_delta = info->inner_viewport_scroll.scroll_delta; | 869 inner_viewport_scroll_delta = info->inner_viewport_scroll.scroll_delta; |
| 1069 | 870 |
| 1070 if (inner_viewport_scroll_delta.IsZero() && info->page_scale_delta == 1.f && | 871 if (inner_viewport_scroll_delta.IsZero() && info->page_scale_delta == 1.f && |
| 1071 info->elastic_overscroll_delta.IsZero() && !info->top_controls_delta) | 872 info->elastic_overscroll_delta.IsZero() && !info->top_controls_delta) |
| 1072 return; | 873 return; |
| 1073 | 874 |
| 1074 // Preemptively apply the scroll offset and scale delta here before sending | 875 // Preemptively apply the scroll offset and scale delta here before sending |
| 1075 // it to the client. If the client comes back and sets it to the same | 876 // it to the client. If the client comes back and sets it to the same |
| 1076 // value, then the layer can early out without needing a full commit. | 877 // value, then the layer can early out without needing a full commit. |
| 1077 if (inner_viewport_scroll_layer_.get()) { | 878 if (layer_tree_->inner_viewport_scroll_layer()) { |
| 1078 inner_viewport_scroll_layer_->SetScrollOffsetFromImplSide( | 879 layer_tree_->inner_viewport_scroll_layer()->SetScrollOffsetFromImplSide( |
| 1079 gfx::ScrollOffsetWithDelta( | 880 gfx::ScrollOffsetWithDelta( |
| 1080 inner_viewport_scroll_layer_->scroll_offset(), | 881 layer_tree_->inner_viewport_scroll_layer()->scroll_offset(), |
| 1081 inner_viewport_scroll_delta)); | 882 inner_viewport_scroll_delta)); |
| 1082 } | 883 } |
| 1083 | 884 |
| 1084 ApplyPageScaleDeltaFromImplSide(info->page_scale_delta); | 885 ApplyPageScaleDeltaFromImplSide(info->page_scale_delta); |
| 1085 elastic_overscroll_ += info->elastic_overscroll_delta; | 886 elastic_overscroll_ += info->elastic_overscroll_delta; |
| 1086 // TODO(ccameron): pass the elastic overscroll here so that input events | 887 // TODO(ccameron): pass the elastic overscroll here so that input events |
| 1087 // may be translated appropriately. | 888 // may be translated appropriately. |
| 1088 client_->ApplyViewportDeltas(inner_viewport_scroll_delta, gfx::Vector2dF(), | 889 client_->ApplyViewportDeltas(inner_viewport_scroll_delta, gfx::Vector2dF(), |
| 1089 info->elastic_overscroll_delta, | 890 info->elastic_overscroll_delta, |
| 1090 info->page_scale_delta, | 891 info->page_scale_delta, |
| 1091 info->top_controls_delta); | 892 info->top_controls_delta); |
| 1092 SetNeedsUpdateLayers(); | 893 SetNeedsUpdateLayers(); |
| 1093 } | 894 } |
| 1094 | 895 |
| 1095 void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) { | 896 void LayerTreeHost::ApplyScrollAndScale(ScrollAndScaleSet* info) { |
| 1096 for (auto& swap_promise : info->swap_promises) { | 897 for (auto& swap_promise : info->swap_promises) { |
| 1097 TRACE_EVENT_WITH_FLOW1("input,benchmark", | 898 TRACE_EVENT_WITH_FLOW1("input,benchmark", |
| 1098 "LatencyInfo.Flow", | 899 "LatencyInfo.Flow", |
| 1099 TRACE_ID_DONT_MANGLE(swap_promise->TraceId()), | 900 TRACE_ID_DONT_MANGLE(swap_promise->TraceId()), |
| 1100 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, | 901 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
| 1101 "step", "Main thread scroll update"); | 902 "step", "Main thread scroll update"); |
| 1102 QueueSwapPromise(std::move(swap_promise)); | 903 QueueSwapPromise(std::move(swap_promise)); |
| 1103 } | 904 } |
| 1104 | 905 |
| 1105 if (root_layer_.get()) { | 906 if (layer_tree_->root_layer()) { |
| 1106 for (size_t i = 0; i < info->scrolls.size(); ++i) { | 907 for (size_t i = 0; i < info->scrolls.size(); ++i) { |
| 1107 Layer* layer = LayerById(info->scrolls[i].layer_id); | 908 Layer* layer = LayerById(info->scrolls[i].layer_id); |
| 1108 if (!layer) | 909 if (!layer) |
| 1109 continue; | 910 continue; |
| 1110 layer->SetScrollOffsetFromImplSide(gfx::ScrollOffsetWithDelta( | 911 layer->SetScrollOffsetFromImplSide(gfx::ScrollOffsetWithDelta( |
| 1111 layer->scroll_offset(), info->scrolls[i].scroll_delta)); | 912 layer->scroll_offset(), info->scrolls[i].scroll_delta)); |
| 1112 SetNeedsUpdateLayers(); | 913 SetNeedsUpdateLayers(); |
| 1113 } | 914 } |
| 1114 } | 915 } |
| 1115 | 916 |
| 1116 // This needs to happen after scroll deltas have been sent to prevent top | 917 // This needs to happen after scroll deltas have been sent to prevent top |
| 1117 // controls from clamping the layout viewport both on the compositor and | 918 // controls from clamping the layout viewport both on the compositor and |
| 1118 // on the main thread. | 919 // on the main thread. |
| 1119 ApplyViewportDeltas(info); | 920 ApplyViewportDeltas(info); |
| 1120 } | 921 } |
| 1121 | 922 |
| 1122 void LayerTreeHost::SetDeviceScaleFactor(float device_scale_factor) { | |
| 1123 if (device_scale_factor == device_scale_factor_) | |
| 1124 return; | |
| 1125 device_scale_factor_ = device_scale_factor; | |
| 1126 | |
| 1127 property_trees_.needs_rebuild = true; | |
| 1128 SetNeedsCommit(); | |
| 1129 } | |
| 1130 | |
| 1131 void LayerTreeHost::SetPaintedDeviceScaleFactor( | |
| 1132 float painted_device_scale_factor) { | |
| 1133 if (painted_device_scale_factor == painted_device_scale_factor_) | |
| 1134 return; | |
| 1135 painted_device_scale_factor_ = painted_device_scale_factor; | |
| 1136 | |
| 1137 SetNeedsCommit(); | |
| 1138 } | |
| 1139 | |
| 1140 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 923 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
| 1141 TopControlsState current, | 924 TopControlsState current, |
| 1142 bool animate) { | 925 bool animate) { |
| 1143 // Top controls are only used in threaded or remote mode. | 926 // Top controls are only used in threaded or remote mode. |
| 1144 DCHECK(IsThreaded() || IsRemoteServer()); | 927 DCHECK(IsThreaded() || IsRemoteServer()); |
| 1145 proxy_->UpdateTopControlsState(constraints, current, animate); | 928 proxy_->UpdateTopControlsState(constraints, current, animate); |
| 1146 } | 929 } |
| 1147 | 930 |
| 1148 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { | 931 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { |
| 1149 AnimationHost* animation_host = layer_tree_.animation_host(); | 932 AnimationHost* animation_host = layer_tree_->animation_host(); |
| 1150 std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents(); | 933 std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents(); |
| 1151 | 934 |
| 1152 if (animation_host->AnimateLayers(monotonic_time)) | 935 if (animation_host->AnimateLayers(monotonic_time)) |
| 1153 animation_host->UpdateAnimationState(true, events.get()); | 936 animation_host->UpdateAnimationState(true, events.get()); |
| 1154 | 937 |
| 1155 if (!events->events_.empty()) | 938 if (!events->events_.empty()) |
| 1156 property_trees_.needs_rebuild = true; | 939 layer_tree_->property_trees()->needs_rebuild = true; |
| 1157 } | 940 } |
| 1158 | 941 |
| 1159 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { | 942 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { |
| 1160 DCHECK(client); | 943 DCHECK(client); |
| 1161 | 944 |
| 1162 UIResourceId next_id = next_ui_resource_id_++; | 945 UIResourceId next_id = next_ui_resource_id_++; |
| 1163 DCHECK(ui_resource_client_map_.find(next_id) == | 946 DCHECK(ui_resource_client_map_.find(next_id) == |
| 1164 ui_resource_client_map_.end()); | 947 ui_resource_client_map_.end()); |
| 1165 | 948 |
| 1166 bool resource_lost = false; | 949 bool resource_lost = false; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 // Returns the size of a resource given its id. | 986 // Returns the size of a resource given its id. |
| 1204 gfx::Size LayerTreeHost::GetUIResourceSize(UIResourceId uid) const { | 987 gfx::Size LayerTreeHost::GetUIResourceSize(UIResourceId uid) const { |
| 1205 UIResourceClientMap::const_iterator iter = ui_resource_client_map_.find(uid); | 988 UIResourceClientMap::const_iterator iter = ui_resource_client_map_.find(uid); |
| 1206 if (iter == ui_resource_client_map_.end()) | 989 if (iter == ui_resource_client_map_.end()) |
| 1207 return gfx::Size(); | 990 return gfx::Size(); |
| 1208 | 991 |
| 1209 const UIResourceClientData& data = iter->second; | 992 const UIResourceClientData& data = iter->second; |
| 1210 return data.size; | 993 return data.size; |
| 1211 } | 994 } |
| 1212 | 995 |
| 1213 void LayerTreeHost::RegisterViewportLayers( | |
| 1214 scoped_refptr<Layer> overscroll_elasticity_layer, | |
| 1215 scoped_refptr<Layer> page_scale_layer, | |
| 1216 scoped_refptr<Layer> inner_viewport_scroll_layer, | |
| 1217 scoped_refptr<Layer> outer_viewport_scroll_layer) { | |
| 1218 DCHECK(!inner_viewport_scroll_layer || | |
| 1219 inner_viewport_scroll_layer != outer_viewport_scroll_layer); | |
| 1220 overscroll_elasticity_layer_ = overscroll_elasticity_layer; | |
| 1221 page_scale_layer_ = page_scale_layer; | |
| 1222 inner_viewport_scroll_layer_ = inner_viewport_scroll_layer; | |
| 1223 outer_viewport_scroll_layer_ = outer_viewport_scroll_layer; | |
| 1224 } | |
| 1225 | |
| 1226 void LayerTreeHost::RegisterSelection(const LayerSelection& selection) { | |
| 1227 if (selection_ == selection) | |
| 1228 return; | |
| 1229 | |
| 1230 selection_ = selection; | |
| 1231 SetNeedsCommit(); | |
| 1232 } | |
| 1233 | |
| 1234 void LayerTreeHost::SetHaveScrollEventHandlers(bool have_event_handlers) { | |
| 1235 if (have_scroll_event_handlers_ == have_event_handlers) | |
| 1236 return; | |
| 1237 | |
| 1238 have_scroll_event_handlers_ = have_event_handlers; | |
| 1239 SetNeedsCommit(); | |
| 1240 } | |
| 1241 | |
| 1242 void LayerTreeHost::SetEventListenerProperties( | |
| 1243 EventListenerClass event_class, | |
| 1244 EventListenerProperties properties) { | |
| 1245 const size_t index = static_cast<size_t>(event_class); | |
| 1246 if (event_listener_properties_[index] == properties) | |
| 1247 return; | |
| 1248 | |
| 1249 event_listener_properties_[index] = properties; | |
| 1250 SetNeedsCommit(); | |
| 1251 } | |
| 1252 | |
| 1253 int LayerTreeHost::ScheduleMicroBenchmark( | 996 int LayerTreeHost::ScheduleMicroBenchmark( |
| 1254 const std::string& benchmark_name, | 997 const std::string& benchmark_name, |
| 1255 std::unique_ptr<base::Value> value, | 998 std::unique_ptr<base::Value> value, |
| 1256 const MicroBenchmark::DoneCallback& callback) { | 999 const MicroBenchmark::DoneCallback& callback) { |
| 1257 return micro_benchmark_controller_.ScheduleRun(benchmark_name, | 1000 return micro_benchmark_controller_.ScheduleRun(benchmark_name, |
| 1258 std::move(value), callback); | 1001 std::move(value), callback); |
| 1259 } | 1002 } |
| 1260 | 1003 |
| 1261 bool LayerTreeHost::SendMessageToMicroBenchmark( | 1004 bool LayerTreeHost::SendMessageToMicroBenchmark( |
| 1262 int id, | 1005 int id, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1308 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() { | 1051 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() { |
| 1309 return SurfaceSequence(surface_client_id_, next_surface_sequence_++); | 1052 return SurfaceSequence(surface_client_id_, next_surface_sequence_++); |
| 1310 } | 1053 } |
| 1311 | 1054 |
| 1312 void LayerTreeHost::SetLayerTreeMutator( | 1055 void LayerTreeHost::SetLayerTreeMutator( |
| 1313 std::unique_ptr<LayerTreeMutator> mutator) { | 1056 std::unique_ptr<LayerTreeMutator> mutator) { |
| 1314 proxy_->SetMutator(std::move(mutator)); | 1057 proxy_->SetMutator(std::move(mutator)); |
| 1315 } | 1058 } |
| 1316 | 1059 |
| 1317 Layer* LayerTreeHost::LayerById(int id) const { | 1060 Layer* LayerTreeHost::LayerById(int id) const { |
| 1318 return layer_tree_.LayerById(id); | 1061 return layer_tree_->LayerById(id); |
| 1319 } | 1062 } |
| 1320 | 1063 |
| 1321 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const { | 1064 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const { |
| 1322 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id); | 1065 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id); |
| 1323 return iter != element_layers_map_.end() ? iter->second : nullptr; | 1066 return iter != element_layers_map_.end() ? iter->second : nullptr; |
| 1324 } | 1067 } |
| 1325 | 1068 |
| 1326 void LayerTreeHost::AddToElementMap(Layer* layer) { | 1069 void LayerTreeHost::AddToElementMap(Layer* layer) { |
| 1327 if (!layer->element_id()) | 1070 if (!layer->element_id()) |
| 1328 return; | 1071 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1340 bool LayerTreeHost::IsElementInList(ElementId element_id, | 1083 bool LayerTreeHost::IsElementInList(ElementId element_id, |
| 1341 ElementListType list_type) const { | 1084 ElementListType list_type) const { |
| 1342 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id); | 1085 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id); |
| 1343 } | 1086 } |
| 1344 | 1087 |
| 1345 void LayerTreeHost::SetMutatorsNeedCommit() { | 1088 void LayerTreeHost::SetMutatorsNeedCommit() { |
| 1346 SetNeedsCommit(); | 1089 SetNeedsCommit(); |
| 1347 } | 1090 } |
| 1348 | 1091 |
| 1349 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { | 1092 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { |
| 1350 property_trees_.needs_rebuild = true; | 1093 layer_tree_->property_trees()->needs_rebuild = true; |
| 1351 } | 1094 } |
| 1352 | 1095 |
| 1353 void LayerTreeHost::SetElementFilterMutated(ElementId element_id, | 1096 void LayerTreeHost::SetElementFilterMutated(ElementId element_id, |
| 1354 ElementListType list_type, | 1097 ElementListType list_type, |
| 1355 const FilterOperations& filters) { | 1098 const FilterOperations& filters) { |
| 1356 Layer* layer = LayerByElementId(element_id); | 1099 Layer* layer = LayerByElementId(element_id); |
| 1357 DCHECK(layer); | 1100 DCHECK(layer); |
| 1358 layer->OnFilterAnimated(filters); | 1101 layer->OnFilterAnimated(filters); |
| 1359 } | 1102 } |
| 1360 | 1103 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1501 // LayerTreeHost, so they are serialized outside of the LayerTreeHost | 1244 // LayerTreeHost, so they are serialized outside of the LayerTreeHost |
| 1502 // serialization. | 1245 // serialization. |
| 1503 // - The |visible_| flag will be controlled from the client separately and | 1246 // - The |visible_| flag will be controlled from the client separately and |
| 1504 // will need special handling outside of the serialization of the | 1247 // will need special handling outside of the serialization of the |
| 1505 // LayerTreeHost. | 1248 // LayerTreeHost. |
| 1506 // TODO(nyquist): Figure out how to support animations. See crbug.com/570376. | 1249 // TODO(nyquist): Figure out how to support animations. See crbug.com/570376. |
| 1507 TRACE_EVENT0("cc.remote", "LayerTreeHost::ToProtobufForCommit"); | 1250 TRACE_EVENT0("cc.remote", "LayerTreeHost::ToProtobufForCommit"); |
| 1508 swap_promises->swap(swap_promise_list_); | 1251 swap_promises->swap(swap_promise_list_); |
| 1509 DCHECK(swap_promise_list_.empty()); | 1252 DCHECK(swap_promise_list_.empty()); |
| 1510 | 1253 |
| 1511 proto->set_needs_full_tree_sync(needs_full_tree_sync_); | |
| 1512 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); | |
| 1513 proto->set_source_frame_number(source_frame_number_); | 1254 proto->set_source_frame_number(source_frame_number_); |
| 1514 | 1255 |
| 1515 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, | |
| 1516 proto->mutable_root_layer()); | |
| 1517 | |
| 1518 // Serialize the LayerTree before serializing the properties. During layer | 1256 // Serialize the LayerTree before serializing the properties. During layer |
| 1519 // property serialization, we clear the list |layer_that_should_properties_| | 1257 // property serialization, we clear the list |layer_that_should_properties_| |
| 1520 // from the LayerTree. | 1258 // from the LayerTree. |
| 1521 layer_tree_.ToProtobuf(proto->mutable_layer_tree()); | 1259 layer_tree_->ToProtobuf(proto->mutable_layer_tree()); |
| 1522 | 1260 |
| 1523 LayerProtoConverter::SerializeLayerProperties(this, | 1261 LayerProtoConverter::SerializeLayerProperties(this, |
| 1524 proto->mutable_layer_updates()); | 1262 proto->mutable_layer_updates()); |
| 1525 | 1263 |
| 1526 std::vector<PictureData> pictures = | 1264 std::vector<PictureData> pictures = |
| 1527 engine_picture_cache_->CalculateCacheUpdateAndFlush(); | 1265 engine_picture_cache_->CalculateCacheUpdateAndFlush(); |
| 1528 proto::PictureDataVectorToSkPicturesProto(pictures, | 1266 proto::PictureDataVectorToSkPicturesProto(pictures, |
| 1529 proto->mutable_pictures()); | 1267 proto->mutable_pictures()); |
| 1530 | 1268 |
| 1531 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); | |
| 1532 debug_state_.ToProtobuf(proto->mutable_debug_state()); | 1269 debug_state_.ToProtobuf(proto->mutable_debug_state()); |
| 1533 SizeToProto(device_viewport_size_, proto->mutable_device_viewport_size()); | |
| 1534 proto->set_top_controls_shrink_blink_size(top_controls_shrink_blink_size_); | |
| 1535 proto->set_top_controls_height(top_controls_height_); | |
| 1536 proto->set_top_controls_shown_ratio(top_controls_shown_ratio_); | |
| 1537 proto->set_device_scale_factor(device_scale_factor_); | |
| 1538 proto->set_painted_device_scale_factor(painted_device_scale_factor_); | |
| 1539 proto->set_page_scale_factor(page_scale_factor_); | |
| 1540 proto->set_min_page_scale_factor(min_page_scale_factor_); | |
| 1541 proto->set_max_page_scale_factor(max_page_scale_factor_); | |
| 1542 Vector2dFToProto(elastic_overscroll_, proto->mutable_elastic_overscroll()); | 1270 Vector2dFToProto(elastic_overscroll_, proto->mutable_elastic_overscroll()); |
| 1543 proto->set_has_gpu_rasterization_trigger(has_gpu_rasterization_trigger_); | 1271 proto->set_has_gpu_rasterization_trigger(has_gpu_rasterization_trigger_); |
| 1544 proto->set_content_is_suitable_for_gpu_rasterization( | 1272 proto->set_content_is_suitable_for_gpu_rasterization( |
| 1545 content_is_suitable_for_gpu_rasterization_); | 1273 content_is_suitable_for_gpu_rasterization_); |
| 1546 proto->set_background_color(background_color_); | |
| 1547 proto->set_has_transparent_background(has_transparent_background_); | |
| 1548 proto->set_have_scroll_event_handlers(have_scroll_event_handlers_); | |
| 1549 proto->set_wheel_event_listener_properties(static_cast<uint32_t>( | |
| 1550 event_listener_properties(EventListenerClass::kMouseWheel))); | |
| 1551 proto->set_touch_start_or_move_event_listener_properties( | |
| 1552 static_cast<uint32_t>( | |
| 1553 event_listener_properties(EventListenerClass::kTouchStartOrMove))); | |
| 1554 proto->set_touch_end_or_cancel_event_listener_properties( | |
| 1555 static_cast<uint32_t>( | |
| 1556 event_listener_properties(EventListenerClass::kTouchEndOrCancel))); | |
| 1557 proto->set_id(id_); | 1274 proto->set_id(id_); |
| 1558 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); | 1275 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); |
| 1559 | 1276 |
| 1560 // Viewport layers. | |
| 1561 proto->set_overscroll_elasticity_layer_id( | |
| 1562 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id() | |
| 1563 : Layer::INVALID_ID); | |
| 1564 proto->set_page_scale_layer_id(page_scale_layer_ ? page_scale_layer_->id() | |
| 1565 : Layer::INVALID_ID); | |
| 1566 proto->set_inner_viewport_scroll_layer_id( | |
| 1567 inner_viewport_scroll_layer_ ? inner_viewport_scroll_layer_->id() | |
| 1568 : Layer::INVALID_ID); | |
| 1569 proto->set_outer_viewport_scroll_layer_id( | |
| 1570 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() | |
| 1571 : Layer::INVALID_ID); | |
| 1572 | |
| 1573 LayerSelectionToProtobuf(selection_, proto->mutable_selection()); | |
| 1574 | |
| 1575 property_trees_.ToProtobuf(proto->mutable_property_trees()); | |
| 1576 | |
| 1577 proto->set_surface_client_id(surface_client_id_); | 1277 proto->set_surface_client_id(surface_client_id_); |
| 1578 proto->set_next_surface_sequence(next_surface_sequence_); | 1278 proto->set_next_surface_sequence(next_surface_sequence_); |
| 1579 | 1279 |
| 1580 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 1280 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 1581 "cc.remote", "LayerTreeHostProto", source_frame_number_, | 1281 "cc.remote", "LayerTreeHostProto", source_frame_number_, |
| 1582 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); | 1282 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); |
| 1583 } | 1283 } |
| 1584 | 1284 |
| 1585 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { | 1285 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { |
| 1586 DCHECK(client_picture_cache_); | 1286 DCHECK(client_picture_cache_); |
| 1587 needs_full_tree_sync_ = proto.needs_full_tree_sync(); | |
| 1588 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); | |
| 1589 source_frame_number_ = proto.source_frame_number(); | 1287 source_frame_number_ = proto.source_frame_number(); |
| 1590 | 1288 |
| 1591 // Layer hierarchy. | 1289 layer_tree_->FromProtobuf(proto.layer_tree()); |
| 1592 scoped_refptr<Layer> new_root_layer = | |
| 1593 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, | |
| 1594 proto.root_layer(), this); | |
| 1595 if (root_layer_ != new_root_layer) { | |
| 1596 root_layer_ = new_root_layer; | |
| 1597 } | |
| 1598 | |
| 1599 layer_tree_.FromProtobuf(proto.layer_tree()); | |
| 1600 | 1290 |
| 1601 // Ensure ClientPictureCache contains all the necessary SkPictures before | 1291 // Ensure ClientPictureCache contains all the necessary SkPictures before |
| 1602 // deserializing the properties. | 1292 // deserializing the properties. |
| 1603 proto::SkPictures proto_pictures = proto.pictures(); | 1293 proto::SkPictures proto_pictures = proto.pictures(); |
| 1604 std::vector<PictureData> pictures = | 1294 std::vector<PictureData> pictures = |
| 1605 SkPicturesProtoToPictureDataVector(proto_pictures); | 1295 SkPicturesProtoToPictureDataVector(proto_pictures); |
| 1606 client_picture_cache_->ApplyCacheUpdate(pictures); | 1296 client_picture_cache_->ApplyCacheUpdate(pictures); |
| 1607 | 1297 |
| 1608 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), | 1298 LayerProtoConverter::DeserializeLayerProperties(layer_tree_->root_layer(), |
| 1609 proto.layer_updates()); | 1299 proto.layer_updates()); |
| 1610 | 1300 |
| 1611 // The deserialization is finished, so now clear the cache. | 1301 // The deserialization is finished, so now clear the cache. |
| 1612 client_picture_cache_->Flush(); | 1302 client_picture_cache_->Flush(); |
| 1613 | 1303 |
| 1614 debug_state_.FromProtobuf(proto.debug_state()); | 1304 debug_state_.FromProtobuf(proto.debug_state()); |
| 1615 device_viewport_size_ = ProtoToSize(proto.device_viewport_size()); | |
| 1616 top_controls_shrink_blink_size_ = proto.top_controls_shrink_blink_size(); | |
| 1617 top_controls_height_ = proto.top_controls_height(); | |
| 1618 top_controls_shown_ratio_ = proto.top_controls_shown_ratio(); | |
| 1619 device_scale_factor_ = proto.device_scale_factor(); | |
| 1620 painted_device_scale_factor_ = proto.painted_device_scale_factor(); | |
| 1621 page_scale_factor_ = proto.page_scale_factor(); | |
| 1622 min_page_scale_factor_ = proto.min_page_scale_factor(); | |
| 1623 max_page_scale_factor_ = proto.max_page_scale_factor(); | |
| 1624 elastic_overscroll_ = ProtoToVector2dF(proto.elastic_overscroll()); | 1305 elastic_overscroll_ = ProtoToVector2dF(proto.elastic_overscroll()); |
| 1625 has_gpu_rasterization_trigger_ = proto.has_gpu_rasterization_trigger(); | 1306 has_gpu_rasterization_trigger_ = proto.has_gpu_rasterization_trigger(); |
| 1626 content_is_suitable_for_gpu_rasterization_ = | 1307 content_is_suitable_for_gpu_rasterization_ = |
| 1627 proto.content_is_suitable_for_gpu_rasterization(); | 1308 proto.content_is_suitable_for_gpu_rasterization(); |
| 1628 background_color_ = proto.background_color(); | |
| 1629 has_transparent_background_ = proto.has_transparent_background(); | |
| 1630 have_scroll_event_handlers_ = proto.have_scroll_event_handlers(); | |
| 1631 event_listener_properties_[static_cast<size_t>( | |
| 1632 EventListenerClass::kMouseWheel)] = | |
| 1633 static_cast<EventListenerProperties>( | |
| 1634 proto.wheel_event_listener_properties()); | |
| 1635 event_listener_properties_[static_cast<size_t>( | |
| 1636 EventListenerClass::kTouchStartOrMove)] = | |
| 1637 static_cast<EventListenerProperties>( | |
| 1638 proto.touch_start_or_move_event_listener_properties()); | |
| 1639 event_listener_properties_[static_cast<size_t>( | |
| 1640 EventListenerClass::kTouchEndOrCancel)] = | |
| 1641 static_cast<EventListenerProperties>( | |
| 1642 proto.touch_end_or_cancel_event_listener_properties()); | |
| 1643 id_ = proto.id(); | 1309 id_ = proto.id(); |
| 1644 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); | 1310 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); |
| 1645 | 1311 |
| 1646 hud_layer_ = static_cast<HeadsUpDisplayLayer*>( | |
| 1647 UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), &layer_tree_)); | |
| 1648 overscroll_elasticity_layer_ = | |
| 1649 UpdateAndGetLayer(overscroll_elasticity_layer_.get(), | |
| 1650 proto.overscroll_elasticity_layer_id(), &layer_tree_); | |
| 1651 page_scale_layer_ = UpdateAndGetLayer( | |
| 1652 page_scale_layer_.get(), proto.page_scale_layer_id(), &layer_tree_); | |
| 1653 inner_viewport_scroll_layer_ = | |
| 1654 UpdateAndGetLayer(inner_viewport_scroll_layer_.get(), | |
| 1655 proto.inner_viewport_scroll_layer_id(), &layer_tree_); | |
| 1656 outer_viewport_scroll_layer_ = | |
| 1657 UpdateAndGetLayer(outer_viewport_scroll_layer_.get(), | |
| 1658 proto.outer_viewport_scroll_layer_id(), &layer_tree_); | |
| 1659 | |
| 1660 LayerSelectionFromProtobuf(&selection_, proto.selection()); | |
| 1661 | |
| 1662 // It is required to create new PropertyTrees before deserializing it. | |
| 1663 property_trees_ = PropertyTrees(); | |
| 1664 property_trees_.FromProtobuf(proto.property_trees()); | |
| 1665 | |
| 1666 // Forcefully override the sequence number of all layers in the tree to have | |
| 1667 // a valid sequence number. Changing the sequence number for a layer does not | |
| 1668 // need a commit, so the value will become out of date for layers that are not | |
| 1669 // updated for other reasons. All layers that at this point are part of the | |
| 1670 // layer tree are valid, so it is OK that they have a valid sequence number. | |
| 1671 int seq_num = property_trees_.sequence_number; | |
| 1672 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { | |
| 1673 layer->set_property_tree_sequence_number(seq_num); | |
| 1674 }); | |
| 1675 | |
| 1676 surface_client_id_ = proto.surface_client_id(); | 1312 surface_client_id_ = proto.surface_client_id(); |
| 1677 next_surface_sequence_ = proto.next_surface_sequence(); | 1313 next_surface_sequence_ = proto.next_surface_sequence(); |
| 1678 } | 1314 } |
| 1679 | 1315 |
| 1680 AnimationHost* LayerTreeHost::animation_host() const { | 1316 AnimationHost* LayerTreeHost::animation_host() const { |
| 1681 return layer_tree_.animation_host(); | 1317 return layer_tree_->animation_host(); |
| 1682 } | 1318 } |
| 1683 | 1319 |
| 1684 } // namespace cc | 1320 } // namespace cc |
| OLD | NEW |