Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <stack> | 12 #include <stack> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <unordered_map> | 14 #include <unordered_map> |
| 15 | 15 |
| 16 #include "base/atomic_sequence_num.h" | 16 #include "base/atomic_sequence_num.h" |
| 17 #include "base/auto_reset.h" | |
| 18 #include "base/bind.h" | 17 #include "base/bind.h" |
| 19 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 20 #include "base/location.h" | 19 #include "base/location.h" |
| 21 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 22 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
| 23 #include "base/numerics/safe_math.h" | 22 #include "base/numerics/safe_math.h" |
| 24 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 25 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
| 26 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 38 #include "cc/debug/rendering_stats_instrumentation.h" | 37 #include "cc/debug/rendering_stats_instrumentation.h" |
| 39 #include "cc/input/layer_selection_bound.h" | 38 #include "cc/input/layer_selection_bound.h" |
| 40 #include "cc/input/page_scale_animation.h" | 39 #include "cc/input/page_scale_animation.h" |
| 41 #include "cc/layers/heads_up_display_layer.h" | 40 #include "cc/layers/heads_up_display_layer.h" |
| 42 #include "cc/layers/heads_up_display_layer_impl.h" | 41 #include "cc/layers/heads_up_display_layer_impl.h" |
| 43 #include "cc/layers/layer.h" | 42 #include "cc/layers/layer.h" |
| 44 #include "cc/layers/layer_iterator.h" | 43 #include "cc/layers/layer_iterator.h" |
| 45 #include "cc/layers/layer_proto_converter.h" | 44 #include "cc/layers/layer_proto_converter.h" |
| 46 #include "cc/layers/painted_scrollbar_layer.h" | 45 #include "cc/layers/painted_scrollbar_layer.h" |
| 47 #include "cc/proto/gfx_conversions.h" | 46 #include "cc/proto/gfx_conversions.h" |
| 47 #include "cc/proto/layer_tree.pb.h" | |
| 48 #include "cc/proto/layer_tree_host.pb.h" | 48 #include "cc/proto/layer_tree_host.pb.h" |
| 49 #include "cc/resources/ui_resource_request.h" | 49 #include "cc/resources/ui_resource_request.h" |
| 50 #include "cc/scheduler/begin_frame_source.h" | 50 #include "cc/scheduler/begin_frame_source.h" |
| 51 #include "cc/trees/draw_property_utils.h" | 51 #include "cc/trees/draw_property_utils.h" |
| 52 #include "cc/trees/layer_tree_host_client.h" | 52 #include "cc/trees/layer_tree_host_client.h" |
| 53 #include "cc/trees/layer_tree_host_common.h" | 53 #include "cc/trees/layer_tree_host_common.h" |
| 54 #include "cc/trees/layer_tree_host_impl.h" | 54 #include "cc/trees/layer_tree_host_impl.h" |
| 55 #include "cc/trees/layer_tree_impl.h" | 55 #include "cc/trees/layer_tree_impl.h" |
| 56 #include "cc/trees/property_tree_builder.h" | 56 #include "cc/trees/property_tree_builder.h" |
| 57 #include "cc/trees/proxy_main.h" | 57 #include "cc/trees/proxy_main.h" |
| 58 #include "cc/trees/remote_channel_impl.h" | 58 #include "cc/trees/remote_channel_impl.h" |
| 59 #include "cc/trees/single_thread_proxy.h" | 59 #include "cc/trees/single_thread_proxy.h" |
| 60 #include "cc/trees/tree_synchronizer.h" | 60 #include "cc/trees/tree_synchronizer.h" |
| 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, | 71 Layer* UpdateAndGetLayer(Layer* current_layer, |
| 72 int layer_id, | 72 int layer_id, |
| 73 const std::unordered_map<int, Layer*>& layer_id_map) { | 73 LayerTree* layer_tree) { |
| 74 if (layer_id == Layer::INVALID_ID) { | 74 if (layer_id == Layer::INVALID_ID) { |
| 75 if (current_layer) | 75 if (current_layer) |
| 76 current_layer->SetLayerTreeHost(nullptr); | 76 current_layer->SetLayerTreeHost(nullptr); |
| 77 | 77 |
| 78 return nullptr; | 78 return nullptr; |
| 79 } | 79 } |
| 80 | 80 Layer* layer = layer_tree->LayerById(layer_id); |
| 81 auto layer_it = layer_id_map.find(layer_id); | 81 DCHECK(layer); |
| 82 DCHECK(layer_it != layer_id_map.end()); | 82 if (current_layer && current_layer != layer) |
| 83 if (current_layer && current_layer != layer_it->second) | |
| 84 current_layer->SetLayerTreeHost(nullptr); | 83 current_layer->SetLayerTreeHost(nullptr); |
| 85 | 84 |
| 86 return layer_it->second; | 85 return layer; |
| 87 } | 86 } |
| 88 | 87 |
| 89 std::unique_ptr<base::trace_event::TracedValue> | 88 std::unique_ptr<base::trace_event::TracedValue> |
| 90 ComputeLayerTreeHostProtoSizeSplitAsValue(proto::LayerTreeHost* proto) { | 89 ComputeLayerTreeHostProtoSizeSplitAsValue(proto::LayerTreeHost* proto) { |
| 91 std::unique_ptr<base::trace_event::TracedValue> value( | 90 std::unique_ptr<base::trace_event::TracedValue> value( |
| 92 new base::trace_event::TracedValue()); | 91 new base::trace_event::TracedValue()); |
| 93 base::CheckedNumeric<int> base_layer_properties_size = 0; | 92 base::CheckedNumeric<int> base_layer_properties_size = 0; |
| 94 base::CheckedNumeric<int> picture_layer_properties_size = 0; | 93 base::CheckedNumeric<int> picture_layer_properties_size = 0; |
| 95 base::CheckedNumeric<int> display_item_list_size = 0; | 94 base::CheckedNumeric<int> display_item_list_size = 0; |
| 96 base::CheckedNumeric<int> drawing_display_items_size = 0; | 95 base::CheckedNumeric<int> drawing_display_items_size = 0; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 page_scale_factor_(1.f), | 234 page_scale_factor_(1.f), |
| 236 min_page_scale_factor_(1.f), | 235 min_page_scale_factor_(1.f), |
| 237 max_page_scale_factor_(1.f), | 236 max_page_scale_factor_(1.f), |
| 238 has_gpu_rasterization_trigger_(false), | 237 has_gpu_rasterization_trigger_(false), |
| 239 content_is_suitable_for_gpu_rasterization_(true), | 238 content_is_suitable_for_gpu_rasterization_(true), |
| 240 gpu_rasterization_histogram_recorded_(false), | 239 gpu_rasterization_histogram_recorded_(false), |
| 241 background_color_(SK_ColorWHITE), | 240 background_color_(SK_ColorWHITE), |
| 242 has_transparent_background_(false), | 241 has_transparent_background_(false), |
| 243 have_scroll_event_handlers_(false), | 242 have_scroll_event_handlers_(false), |
| 244 event_listener_properties_(), | 243 event_listener_properties_(), |
| 245 animation_host_(std::move(params->animation_host)), | |
| 246 did_complete_scale_animation_(false), | 244 did_complete_scale_animation_(false), |
| 247 in_paint_layer_contents_(false), | |
| 248 id_(s_layer_tree_host_sequence_number.GetNext() + 1), | 245 id_(s_layer_tree_host_sequence_number.GetNext() + 1), |
| 249 next_commit_forces_redraw_(false), | 246 next_commit_forces_redraw_(false), |
| 250 shared_bitmap_manager_(params->shared_bitmap_manager), | 247 shared_bitmap_manager_(params->shared_bitmap_manager), |
| 251 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), | 248 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), |
| 252 task_graph_runner_(params->task_graph_runner), | 249 task_graph_runner_(params->task_graph_runner), |
| 253 image_serialization_processor_(params->image_serialization_processor), | 250 image_serialization_processor_(params->image_serialization_processor), |
| 254 surface_client_id_(0u), | 251 surface_client_id_(0u), |
| 255 next_surface_sequence_(1u) { | 252 next_surface_sequence_(1u), |
| 253 layer_tree_(std::move(params->animation_host)) { | |
| 256 DCHECK(task_graph_runner_); | 254 DCHECK(task_graph_runner_); |
| 257 | 255 |
| 258 DCHECK(animation_host_); | 256 layer_tree_.animation_host()->SetMutatorHostClient(this); |
| 259 animation_host_->SetMutatorHostClient(this); | |
| 260 | 257 |
| 261 rendering_stats_instrumentation_->set_record_rendering_stats( | 258 rendering_stats_instrumentation_->set_record_rendering_stats( |
| 262 debug_state_.RecordRenderingStats()); | 259 debug_state_.RecordRenderingStats()); |
| 263 } | 260 } |
| 264 | 261 |
| 265 void LayerTreeHost::InitializeThreaded( | 262 void LayerTreeHost::InitializeThreaded( |
| 266 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 263 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 267 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, | 264 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, |
| 268 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { | 265 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
| 269 task_runner_provider_ = | 266 task_runner_provider_ = |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 | 357 |
| 361 void LayerTreeHost::InitializeProxy( | 358 void LayerTreeHost::InitializeProxy( |
| 362 std::unique_ptr<Proxy> proxy, | 359 std::unique_ptr<Proxy> proxy, |
| 363 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { | 360 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { |
| 364 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); | 361 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); |
| 365 DCHECK(task_runner_provider_); | 362 DCHECK(task_runner_provider_); |
| 366 | 363 |
| 367 proxy_ = std::move(proxy); | 364 proxy_ = std::move(proxy); |
| 368 proxy_->Start(std::move(external_begin_frame_source)); | 365 proxy_->Start(std::move(external_begin_frame_source)); |
| 369 | 366 |
| 370 animation_host_->SetSupportsScrollAnimations(proxy_->SupportsImplScrolling()); | 367 GetLayerTree()->animation_host()->SetSupportsScrollAnimations( |
| 368 proxy_->SupportsImplScrolling()); | |
| 371 } | 369 } |
| 372 | 370 |
| 373 LayerTreeHost::~LayerTreeHost() { | 371 LayerTreeHost::~LayerTreeHost() { |
| 374 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); | 372 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); |
| 375 | 373 |
| 376 animation_host_->SetMutatorHostClient(nullptr); | 374 GetLayerTree()->animation_host()->SetMutatorHostClient(nullptr); |
| 377 | 375 |
| 378 if (root_layer_.get()) | 376 if (root_layer_.get()) |
| 379 root_layer_->SetLayerTreeHost(NULL); | 377 root_layer_->SetLayerTreeHost(NULL); |
| 380 | 378 |
| 381 DCHECK(swap_promise_monitor_.empty()); | 379 DCHECK(swap_promise_monitor_.empty()); |
| 382 | 380 |
| 383 BreakSwapPromises(SwapPromise::COMMIT_FAILS); | 381 BreakSwapPromises(SwapPromise::COMMIT_FAILS); |
| 384 | 382 |
| 385 if (proxy_) { | 383 if (proxy_) { |
| 386 DCHECK(task_runner_provider_->IsMainThread()); | 384 DCHECK(task_runner_provider_->IsMainThread()); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 ui_resource_request_queue_.clear(); | 542 ui_resource_request_queue_.clear(); |
| 545 } | 543 } |
| 546 | 544 |
| 547 DCHECK(!sync_tree->ViewportSizeInvalid()); | 545 DCHECK(!sync_tree->ViewportSizeInvalid()); |
| 548 | 546 |
| 549 sync_tree->set_has_ever_been_drawn(false); | 547 sync_tree->set_has_ever_been_drawn(false); |
| 550 | 548 |
| 551 { | 549 { |
| 552 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties"); | 550 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties"); |
| 553 | 551 |
| 554 TreeSynchronizer::PushLayerProperties(this, sync_tree); | 552 TreeSynchronizer::PushLayerProperties(GetLayerTree(), sync_tree); |
| 555 | 553 |
| 556 // This must happen after synchronizing property trees and after push | 554 // This must happen after synchronizing property trees and after push |
| 557 // properties, which updates property tree indices, but before animation | 555 // properties, which updates property tree indices, but before animation |
| 558 // host pushes properties as animation host push properties can change | 556 // host pushes properties as animation host push properties can change |
| 559 // Animation::InEffect and we want the old InEffect value for updating | 557 // Animation::InEffect and we want the old InEffect value for updating |
| 560 // property tree scrolling and animation. | 558 // property tree scrolling and animation. |
| 561 sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread(); | 559 sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread(); |
| 562 | 560 |
| 563 TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties"); | 561 TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties"); |
| 564 DCHECK(host_impl->animation_host()); | 562 DCHECK(host_impl->animation_host()); |
| 565 animation_host_->PushPropertiesTo(host_impl->animation_host()); | 563 GetLayerTree()->animation_host()->PushPropertiesTo( |
| 564 host_impl->animation_host()); | |
| 566 } | 565 } |
| 567 | 566 |
| 568 // This must happen after synchronizing property trees and after pushing | 567 // This must happen after synchronizing property trees and after pushing |
| 569 // properties, which updates the clobber_active_value flag. | 568 // properties, which updates the clobber_active_value flag. |
| 570 sync_tree->UpdatePropertyTreeScrollOffset(&property_trees_); | 569 sync_tree->UpdatePropertyTreeScrollOffset(&property_trees_); |
| 571 | 570 |
| 572 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); | 571 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); |
| 573 property_trees_.ResetAllChangeTracking(); | 572 property_trees_.ResetAllChangeTracking(); |
| 574 } | 573 } |
| 575 | 574 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 client_->DidFailToInitializeOutputSurface(); | 641 client_->DidFailToInitializeOutputSurface(); |
| 643 } | 642 } |
| 644 | 643 |
| 645 std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 644 std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
| 646 LayerTreeHostImplClient* client) { | 645 LayerTreeHostImplClient* client) { |
| 647 DCHECK(!IsRemoteServer()); | 646 DCHECK(!IsRemoteServer()); |
| 648 DCHECK(task_runner_provider_->IsImplThread()); | 647 DCHECK(task_runner_provider_->IsImplThread()); |
| 649 | 648 |
| 650 const bool supports_impl_scrolling = task_runner_provider_->HasImplThread(); | 649 const bool supports_impl_scrolling = task_runner_provider_->HasImplThread(); |
| 651 std::unique_ptr<AnimationHost> animation_host_impl = | 650 std::unique_ptr<AnimationHost> animation_host_impl = |
| 652 animation_host_->CreateImplInstance(supports_impl_scrolling); | 651 GetLayerTree()->animation_host()->CreateImplInstance( |
| 652 supports_impl_scrolling); | |
| 653 | 653 |
| 654 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( | 654 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
| 655 settings_, client, task_runner_provider_.get(), | 655 settings_, client, task_runner_provider_.get(), |
| 656 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, | 656 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, |
| 657 gpu_memory_buffer_manager_, task_graph_runner_, | 657 gpu_memory_buffer_manager_, task_graph_runner_, |
| 658 std::move(animation_host_impl), id_); | 658 std::move(animation_host_impl), id_); |
| 659 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); | 659 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); |
| 660 host_impl->SetContentIsSuitableForGpuRasterization( | 660 host_impl->SetContentIsSuitableForGpuRasterization( |
| 661 content_is_suitable_for_gpu_rasterization_); | 661 content_is_suitable_for_gpu_rasterization_); |
| 662 shared_bitmap_manager_ = NULL; | 662 shared_bitmap_manager_ = NULL; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 } | 747 } |
| 748 | 748 |
| 749 void LayerTreeHost::SetNextCommitForcesRedraw() { | 749 void LayerTreeHost::SetNextCommitForcesRedraw() { |
| 750 next_commit_forces_redraw_ = true; | 750 next_commit_forces_redraw_ = true; |
| 751 proxy_->SetNeedsUpdateLayers(); | 751 proxy_->SetNeedsUpdateLayers(); |
| 752 } | 752 } |
| 753 | 753 |
| 754 void LayerTreeHost::SetAnimationEvents( | 754 void LayerTreeHost::SetAnimationEvents( |
| 755 std::unique_ptr<AnimationEvents> events) { | 755 std::unique_ptr<AnimationEvents> events) { |
| 756 DCHECK(task_runner_provider_->IsMainThread()); | 756 DCHECK(task_runner_provider_->IsMainThread()); |
| 757 animation_host_->SetAnimationEvents(std::move(events)); | 757 GetLayerTree()->animation_host()->SetAnimationEvents(std::move(events)); |
| 758 } | 758 } |
| 759 | 759 |
| 760 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { | 760 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { |
| 761 if (root_layer_.get() == root_layer.get()) | 761 if (root_layer_.get() == root_layer.get()) |
| 762 return; | 762 return; |
| 763 | 763 |
| 764 if (root_layer_.get()) | 764 if (root_layer_.get()) |
| 765 root_layer_->SetLayerTreeHost(NULL); | 765 root_layer_->SetLayerTreeHost(NULL); |
| 766 root_layer_ = root_layer; | 766 root_layer_ = root_layer; |
| 767 if (root_layer_.get()) { | 767 if (root_layer_.get()) { |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1042 draw_property_utils::UpdatePropertyTrees(&property_trees_, | 1042 draw_property_utils::UpdatePropertyTrees(&property_trees_, |
| 1043 can_render_to_separate_surface); | 1043 can_render_to_separate_surface); |
| 1044 draw_property_utils::FindLayersThatNeedUpdates( | 1044 draw_property_utils::FindLayersThatNeedUpdates( |
| 1045 this, property_trees_.transform_tree, property_trees_.effect_tree, | 1045 this, property_trees_.transform_tree, property_trees_.effect_tree, |
| 1046 &update_layer_list); | 1046 &update_layer_list); |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 for (const auto& layer : update_layer_list) | 1049 for (const auto& layer : update_layer_list) |
| 1050 layer->SavePaintProperties(); | 1050 layer->SavePaintProperties(); |
| 1051 | 1051 |
| 1052 base::AutoReset<bool> painting(&in_paint_layer_contents_, true); | |
| 1053 bool did_paint_content = false; | |
| 1054 bool content_is_suitable_for_gpu = true; | 1052 bool content_is_suitable_for_gpu = true; |
| 1055 for (const auto& layer : update_layer_list) { | 1053 bool did_paint_content = GetLayerTree()->UpdateLayers( |
| 1056 did_paint_content |= layer->Update(); | 1054 update_layer_list, &content_is_suitable_for_gpu); |
| 1057 content_is_suitable_for_gpu &= layer->IsSuitableForGpuRasterization(); | |
| 1058 } | |
| 1059 | 1055 |
| 1060 if (content_is_suitable_for_gpu) { | 1056 if (content_is_suitable_for_gpu) { |
| 1061 ++num_consecutive_frames_suitable_for_gpu_; | 1057 ++num_consecutive_frames_suitable_for_gpu_; |
| 1062 if (num_consecutive_frames_suitable_for_gpu_ >= | 1058 if (num_consecutive_frames_suitable_for_gpu_ >= |
| 1063 kNumFramesToConsiderBeforeGpuRasterization) { | 1059 kNumFramesToConsiderBeforeGpuRasterization) { |
| 1064 content_is_suitable_for_gpu_rasterization_ = true; | 1060 content_is_suitable_for_gpu_rasterization_ = true; |
| 1065 } | 1061 } |
| 1066 } else { | 1062 } else { |
| 1067 num_consecutive_frames_suitable_for_gpu_ = 0; | 1063 num_consecutive_frames_suitable_for_gpu_ = 0; |
| 1068 content_is_suitable_for_gpu_rasterization_ = false; | 1064 content_is_suitable_for_gpu_rasterization_ = false; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1147 | 1143 |
| 1148 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 1144 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
| 1149 TopControlsState current, | 1145 TopControlsState current, |
| 1150 bool animate) { | 1146 bool animate) { |
| 1151 // Top controls are only used in threaded or remote mode. | 1147 // Top controls are only used in threaded or remote mode. |
| 1152 DCHECK(IsThreaded() || IsRemoteServer()); | 1148 DCHECK(IsThreaded() || IsRemoteServer()); |
| 1153 proxy_->UpdateTopControlsState(constraints, current, animate); | 1149 proxy_->UpdateTopControlsState(constraints, current, animate); |
| 1154 } | 1150 } |
| 1155 | 1151 |
| 1156 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { | 1152 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { |
| 1157 std::unique_ptr<AnimationEvents> events = animation_host_->CreateEvents(); | 1153 AnimationHost* animation_host = GetLayerTree()->animation_host(); |
| 1154 std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents(); | |
| 1158 | 1155 |
| 1159 if (animation_host_->AnimateLayers(monotonic_time)) | 1156 if (animation_host->AnimateLayers(monotonic_time)) |
| 1160 animation_host_->UpdateAnimationState(true, events.get()); | 1157 animation_host->UpdateAnimationState(true, events.get()); |
| 1161 | 1158 |
| 1162 if (!events->events_.empty()) | 1159 if (!events->events_.empty()) |
| 1163 property_trees_.needs_rebuild = true; | 1160 property_trees_.needs_rebuild = true; |
| 1164 } | 1161 } |
| 1165 | 1162 |
| 1166 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { | 1163 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { |
| 1167 DCHECK(client); | 1164 DCHECK(client); |
| 1168 | 1165 |
| 1169 UIResourceId next_id = next_ui_resource_id_++; | 1166 UIResourceId next_id = next_ui_resource_id_++; |
| 1170 DCHECK(ui_resource_client_map_.find(next_id) == | 1167 DCHECK(ui_resource_client_map_.find(next_id) == |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1309 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() { | 1306 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() { |
| 1310 return SurfaceSequence(surface_client_id_, next_surface_sequence_++); | 1307 return SurfaceSequence(surface_client_id_, next_surface_sequence_++); |
| 1311 } | 1308 } |
| 1312 | 1309 |
| 1313 void LayerTreeHost::SetLayerTreeMutator( | 1310 void LayerTreeHost::SetLayerTreeMutator( |
| 1314 std::unique_ptr<LayerTreeMutator> mutator) { | 1311 std::unique_ptr<LayerTreeMutator> mutator) { |
| 1315 proxy_->SetMutator(std::move(mutator)); | 1312 proxy_->SetMutator(std::move(mutator)); |
| 1316 } | 1313 } |
| 1317 | 1314 |
| 1318 Layer* LayerTreeHost::LayerById(int id) const { | 1315 Layer* LayerTreeHost::LayerById(int id) const { |
| 1319 LayerIdMap::const_iterator iter = layer_id_map_.find(id); | 1316 return GetLayerTree()->LayerById(id); |
| 1320 return iter != layer_id_map_.end() ? iter->second : nullptr; | |
| 1321 } | 1317 } |
| 1322 | 1318 |
| 1323 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const { | 1319 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const { |
| 1324 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id); | 1320 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id); |
| 1325 return iter != element_layers_map_.end() ? iter->second : nullptr; | 1321 return iter != element_layers_map_.end() ? iter->second : nullptr; |
| 1326 } | 1322 } |
| 1327 | 1323 |
| 1328 void LayerTreeHost::AddToElementMap(Layer* layer) { | 1324 void LayerTreeHost::AddToElementMap(Layer* layer) { |
| 1329 if (!layer->element_id()) | 1325 if (!layer->element_id()) |
| 1330 return; | 1326 return; |
| 1331 | 1327 |
| 1332 element_layers_map_[layer->element_id()] = layer; | 1328 element_layers_map_[layer->element_id()] = layer; |
| 1333 } | 1329 } |
| 1334 | 1330 |
| 1335 void LayerTreeHost::RemoveFromElementMap(Layer* layer) { | 1331 void LayerTreeHost::RemoveFromElementMap(Layer* layer) { |
| 1336 if (!layer->element_id()) | 1332 if (!layer->element_id()) |
| 1337 return; | 1333 return; |
| 1338 | 1334 |
| 1339 element_layers_map_.erase(layer->element_id()); | 1335 element_layers_map_.erase(layer->element_id()); |
| 1340 } | 1336 } |
| 1341 | 1337 |
| 1342 void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) { | |
| 1343 layers_that_should_push_properties_.insert(layer); | |
| 1344 } | |
| 1345 | |
| 1346 void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) { | |
| 1347 layers_that_should_push_properties_.erase(layer); | |
| 1348 } | |
| 1349 | |
| 1350 std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() { | |
| 1351 return layers_that_should_push_properties_; | |
| 1352 } | |
| 1353 | |
| 1354 bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) { | |
| 1355 return layers_that_should_push_properties_.find(layer) != | |
| 1356 layers_that_should_push_properties_.end(); | |
| 1357 } | |
| 1358 | |
| 1359 void LayerTreeHost::RegisterLayer(Layer* layer) { | |
| 1360 DCHECK(!LayerById(layer->id())); | |
| 1361 DCHECK(!in_paint_layer_contents_); | |
| 1362 layer_id_map_[layer->id()] = layer; | |
| 1363 if (layer->element_id()) { | |
| 1364 animation_host_->RegisterElement(layer->element_id(), | |
| 1365 ElementListType::ACTIVE); | |
| 1366 } | |
| 1367 } | |
| 1368 | |
| 1369 void LayerTreeHost::UnregisterLayer(Layer* layer) { | |
| 1370 DCHECK(LayerById(layer->id())); | |
| 1371 DCHECK(!in_paint_layer_contents_); | |
| 1372 if (layer->element_id()) { | |
| 1373 animation_host_->UnregisterElement(layer->element_id(), | |
| 1374 ElementListType::ACTIVE); | |
| 1375 } | |
| 1376 RemoveLayerShouldPushProperties(layer); | |
| 1377 layer_id_map_.erase(layer->id()); | |
| 1378 } | |
| 1379 | |
| 1380 bool LayerTreeHost::IsElementInList(ElementId element_id, | 1338 bool LayerTreeHost::IsElementInList(ElementId element_id, |
| 1381 ElementListType list_type) const { | 1339 ElementListType list_type) const { |
| 1382 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id); | 1340 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id); |
| 1383 } | 1341 } |
| 1384 | 1342 |
| 1385 void LayerTreeHost::SetMutatorsNeedCommit() { | 1343 void LayerTreeHost::SetMutatorsNeedCommit() { |
| 1386 SetNeedsCommit(); | 1344 SetNeedsCommit(); |
| 1387 } | 1345 } |
| 1388 | 1346 |
| 1389 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { | 1347 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1526 swap_promises->swap(swap_promise_list_); | 1484 swap_promises->swap(swap_promise_list_); |
| 1527 DCHECK(swap_promise_list_.empty()); | 1485 DCHECK(swap_promise_list_.empty()); |
| 1528 | 1486 |
| 1529 proto->set_needs_full_tree_sync(needs_full_tree_sync_); | 1487 proto->set_needs_full_tree_sync(needs_full_tree_sync_); |
| 1530 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); | 1488 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); |
| 1531 proto->set_source_frame_number(source_frame_number_); | 1489 proto->set_source_frame_number(source_frame_number_); |
| 1532 | 1490 |
| 1533 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, | 1491 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, |
| 1534 proto->mutable_root_layer()); | 1492 proto->mutable_root_layer()); |
| 1535 | 1493 |
| 1536 // layers_that_should_push_properties_ should be serialized before layer | 1494 // Serialize LayerTree before LayerTree.layers_that_should_push_properties_ |
|
Khushal
2016/07/20 23:14:10
You probably meant "Serialize the LayerTree before
| |
| 1537 // properties because it is cleared during the properties serialization. | 1495 // is cleared. |
| 1538 for (auto* layer : layers_that_should_push_properties_) | 1496 GetLayerTree()->ToProtobuf(proto->mutable_layer_tree()); |
| 1539 proto->add_layers_that_should_push_properties(layer->id()); | |
| 1540 | 1497 |
| 1541 LayerProtoConverter::SerializeLayerProperties(this, | 1498 LayerProtoConverter::SerializeLayerProperties(this, |
| 1542 proto->mutable_layer_updates()); | 1499 proto->mutable_layer_updates()); |
| 1543 | 1500 |
| 1544 std::vector<PictureData> pictures = | 1501 std::vector<PictureData> pictures = |
| 1545 engine_picture_cache_->CalculateCacheUpdateAndFlush(); | 1502 engine_picture_cache_->CalculateCacheUpdateAndFlush(); |
| 1546 proto::PictureDataVectorToSkPicturesProto(pictures, | 1503 proto::PictureDataVectorToSkPicturesProto(pictures, |
| 1547 proto->mutable_pictures()); | 1504 proto->mutable_pictures()); |
| 1548 | 1505 |
| 1549 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); | 1506 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1565 proto->set_has_transparent_background(has_transparent_background_); | 1522 proto->set_has_transparent_background(has_transparent_background_); |
| 1566 proto->set_have_scroll_event_handlers(have_scroll_event_handlers_); | 1523 proto->set_have_scroll_event_handlers(have_scroll_event_handlers_); |
| 1567 proto->set_wheel_event_listener_properties(static_cast<uint32_t>( | 1524 proto->set_wheel_event_listener_properties(static_cast<uint32_t>( |
| 1568 event_listener_properties(EventListenerClass::kMouseWheel))); | 1525 event_listener_properties(EventListenerClass::kMouseWheel))); |
| 1569 proto->set_touch_start_or_move_event_listener_properties( | 1526 proto->set_touch_start_or_move_event_listener_properties( |
| 1570 static_cast<uint32_t>( | 1527 static_cast<uint32_t>( |
| 1571 event_listener_properties(EventListenerClass::kTouchStartOrMove))); | 1528 event_listener_properties(EventListenerClass::kTouchStartOrMove))); |
| 1572 proto->set_touch_end_or_cancel_event_listener_properties( | 1529 proto->set_touch_end_or_cancel_event_listener_properties( |
| 1573 static_cast<uint32_t>( | 1530 static_cast<uint32_t>( |
| 1574 event_listener_properties(EventListenerClass::kTouchEndOrCancel))); | 1531 event_listener_properties(EventListenerClass::kTouchEndOrCancel))); |
| 1575 proto->set_in_paint_layer_contents(in_paint_layer_contents_); | |
| 1576 proto->set_id(id_); | 1532 proto->set_id(id_); |
| 1577 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); | 1533 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); |
| 1578 | 1534 |
| 1579 // Viewport layers. | 1535 // Viewport layers. |
| 1580 proto->set_overscroll_elasticity_layer_id( | 1536 proto->set_overscroll_elasticity_layer_id( |
| 1581 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id() | 1537 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id() |
| 1582 : Layer::INVALID_ID); | 1538 : Layer::INVALID_ID); |
| 1583 proto->set_page_scale_layer_id(page_scale_layer_ ? page_scale_layer_->id() | 1539 proto->set_page_scale_layer_id(page_scale_layer_ ? page_scale_layer_->id() |
| 1584 : Layer::INVALID_ID); | 1540 : Layer::INVALID_ID); |
| 1585 proto->set_inner_viewport_scroll_layer_id( | 1541 proto->set_inner_viewport_scroll_layer_id( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1596 proto->set_surface_client_id(surface_client_id_); | 1552 proto->set_surface_client_id(surface_client_id_); |
| 1597 proto->set_next_surface_sequence(next_surface_sequence_); | 1553 proto->set_next_surface_sequence(next_surface_sequence_); |
| 1598 | 1554 |
| 1599 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 1555 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 1600 "cc.remote", "LayerTreeHostProto", source_frame_number_, | 1556 "cc.remote", "LayerTreeHostProto", source_frame_number_, |
| 1601 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); | 1557 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); |
| 1602 } | 1558 } |
| 1603 | 1559 |
| 1604 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { | 1560 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { |
| 1605 DCHECK(client_picture_cache_); | 1561 DCHECK(client_picture_cache_); |
| 1606 | 1562 LayerTree* layer_tree = GetLayerTree(); |
| 1607 needs_full_tree_sync_ = proto.needs_full_tree_sync(); | 1563 needs_full_tree_sync_ = proto.needs_full_tree_sync(); |
| 1608 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); | 1564 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); |
| 1609 source_frame_number_ = proto.source_frame_number(); | 1565 source_frame_number_ = proto.source_frame_number(); |
| 1610 | 1566 |
| 1611 // Layer hierarchy. | 1567 // Layer hierarchy. |
| 1612 scoped_refptr<Layer> new_root_layer = | 1568 scoped_refptr<Layer> new_root_layer = |
| 1613 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, | 1569 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, |
| 1614 proto.root_layer(), this); | 1570 proto.root_layer(), this); |
| 1615 if (root_layer_ != new_root_layer) { | 1571 if (root_layer_ != new_root_layer) { |
| 1616 root_layer_ = new_root_layer; | 1572 root_layer_ = new_root_layer; |
| 1617 } | 1573 } |
| 1618 | 1574 |
| 1619 for (auto layer_id : proto.layers_that_should_push_properties()) | 1575 layer_tree->FromProtobuf(proto.layer_tree()); |
| 1620 layers_that_should_push_properties_.insert(layer_id_map_[layer_id]); | |
| 1621 | 1576 |
| 1622 // Ensure ClientPictureCache contains all the necessary SkPictures before | 1577 // Ensure ClientPictureCache contains all the necessary SkPictures before |
| 1623 // deserializing the properties. | 1578 // deserializing the properties. |
| 1624 proto::SkPictures proto_pictures = proto.pictures(); | 1579 proto::SkPictures proto_pictures = proto.pictures(); |
| 1625 std::vector<PictureData> pictures = | 1580 std::vector<PictureData> pictures = |
| 1626 SkPicturesProtoToPictureDataVector(proto_pictures); | 1581 SkPicturesProtoToPictureDataVector(proto_pictures); |
| 1627 client_picture_cache_->ApplyCacheUpdate(pictures); | 1582 client_picture_cache_->ApplyCacheUpdate(pictures); |
| 1628 | 1583 |
| 1629 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), | 1584 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), |
| 1630 proto.layer_updates()); | 1585 proto.layer_updates()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1654 static_cast<EventListenerProperties>( | 1609 static_cast<EventListenerProperties>( |
| 1655 proto.wheel_event_listener_properties()); | 1610 proto.wheel_event_listener_properties()); |
| 1656 event_listener_properties_[static_cast<size_t>( | 1611 event_listener_properties_[static_cast<size_t>( |
| 1657 EventListenerClass::kTouchStartOrMove)] = | 1612 EventListenerClass::kTouchStartOrMove)] = |
| 1658 static_cast<EventListenerProperties>( | 1613 static_cast<EventListenerProperties>( |
| 1659 proto.touch_start_or_move_event_listener_properties()); | 1614 proto.touch_start_or_move_event_listener_properties()); |
| 1660 event_listener_properties_[static_cast<size_t>( | 1615 event_listener_properties_[static_cast<size_t>( |
| 1661 EventListenerClass::kTouchEndOrCancel)] = | 1616 EventListenerClass::kTouchEndOrCancel)] = |
| 1662 static_cast<EventListenerProperties>( | 1617 static_cast<EventListenerProperties>( |
| 1663 proto.touch_end_or_cancel_event_listener_properties()); | 1618 proto.touch_end_or_cancel_event_listener_properties()); |
| 1664 in_paint_layer_contents_ = proto.in_paint_layer_contents(); | |
| 1665 id_ = proto.id(); | 1619 id_ = proto.id(); |
| 1666 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); | 1620 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); |
| 1667 | 1621 |
| 1668 hud_layer_ = static_cast<HeadsUpDisplayLayer*>( | 1622 hud_layer_ = static_cast<HeadsUpDisplayLayer*>( |
| 1669 UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), layer_id_map_)); | 1623 UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), layer_tree)); |
| 1670 overscroll_elasticity_layer_ = | 1624 overscroll_elasticity_layer_ = |
| 1671 UpdateAndGetLayer(overscroll_elasticity_layer_.get(), | 1625 UpdateAndGetLayer(overscroll_elasticity_layer_.get(), |
| 1672 proto.overscroll_elasticity_layer_id(), layer_id_map_); | 1626 proto.overscroll_elasticity_layer_id(), layer_tree); |
| 1673 page_scale_layer_ = UpdateAndGetLayer( | 1627 page_scale_layer_ = UpdateAndGetLayer( |
| 1674 page_scale_layer_.get(), proto.page_scale_layer_id(), layer_id_map_); | 1628 page_scale_layer_.get(), proto.page_scale_layer_id(), layer_tree); |
| 1675 inner_viewport_scroll_layer_ = | 1629 inner_viewport_scroll_layer_ = |
| 1676 UpdateAndGetLayer(inner_viewport_scroll_layer_.get(), | 1630 UpdateAndGetLayer(inner_viewport_scroll_layer_.get(), |
| 1677 proto.inner_viewport_scroll_layer_id(), layer_id_map_); | 1631 proto.inner_viewport_scroll_layer_id(), layer_tree); |
| 1678 outer_viewport_scroll_layer_ = | 1632 outer_viewport_scroll_layer_ = |
| 1679 UpdateAndGetLayer(outer_viewport_scroll_layer_.get(), | 1633 UpdateAndGetLayer(outer_viewport_scroll_layer_.get(), |
| 1680 proto.outer_viewport_scroll_layer_id(), layer_id_map_); | 1634 proto.outer_viewport_scroll_layer_id(), layer_tree); |
| 1681 | 1635 |
| 1682 LayerSelectionFromProtobuf(&selection_, proto.selection()); | 1636 LayerSelectionFromProtobuf(&selection_, proto.selection()); |
| 1683 | 1637 |
| 1684 // It is required to create new PropertyTrees before deserializing it. | 1638 // It is required to create new PropertyTrees before deserializing it. |
| 1685 property_trees_ = PropertyTrees(); | 1639 property_trees_ = PropertyTrees(); |
| 1686 property_trees_.FromProtobuf(proto.property_trees()); | 1640 property_trees_.FromProtobuf(proto.property_trees()); |
| 1687 | 1641 |
| 1688 // Forcefully override the sequence number of all layers in the tree to have | 1642 // Forcefully override the sequence number of all layers in the tree to have |
| 1689 // a valid sequence number. Changing the sequence number for a layer does not | 1643 // a valid sequence number. Changing the sequence number for a layer does not |
| 1690 // need a commit, so the value will become out of date for layers that are not | 1644 // need a commit, so the value will become out of date for layers that are not |
| 1691 // updated for other reasons. All layers that at this point are part of the | 1645 // updated for other reasons. All layers that at this point are part of the |
| 1692 // layer tree are valid, so it is OK that they have a valid sequence number. | 1646 // layer tree are valid, so it is OK that they have a valid sequence number. |
| 1693 int seq_num = property_trees_.sequence_number; | 1647 int seq_num = property_trees_.sequence_number; |
| 1694 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { | 1648 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { |
| 1695 layer->set_property_tree_sequence_number(seq_num); | 1649 layer->set_property_tree_sequence_number(seq_num); |
| 1696 }); | 1650 }); |
| 1697 | 1651 |
| 1698 surface_client_id_ = proto.surface_client_id(); | 1652 surface_client_id_ = proto.surface_client_id(); |
| 1699 next_surface_sequence_ = proto.next_surface_sequence(); | 1653 next_surface_sequence_ = proto.next_surface_sequence(); |
| 1700 } | 1654 } |
| 1701 | 1655 |
| 1656 AnimationHost* LayerTreeHost::animation_host() const { | |
| 1657 return GetLayerTree()->animation_host(); | |
| 1658 } | |
| 1659 | |
| 1702 } // namespace cc | 1660 } // namespace cc |
| OLD | NEW |