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