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