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 layer_tree_.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 layer_tree_.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(&layer_tree_, 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 layer_tree_.animation_host()->PushPropertiesTo(host_impl->animation_host()); |
566 } | 564 } |
567 | 565 |
568 // This must happen after synchronizing property trees and after pushing | 566 // This must happen after synchronizing property trees and after pushing |
569 // properties, which updates the clobber_active_value flag. | 567 // properties, which updates the clobber_active_value flag. |
570 sync_tree->UpdatePropertyTreeScrollOffset(&property_trees_); | 568 sync_tree->UpdatePropertyTreeScrollOffset(&property_trees_); |
571 | 569 |
572 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); | 570 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); |
573 property_trees_.ResetAllChangeTracking(); | 571 property_trees_.ResetAllChangeTracking(); |
574 } | 572 } |
575 | 573 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 client_->DidFailToInitializeOutputSurface(); | 640 client_->DidFailToInitializeOutputSurface(); |
643 } | 641 } |
644 | 642 |
645 std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( | 643 std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( |
646 LayerTreeHostImplClient* client) { | 644 LayerTreeHostImplClient* client) { |
647 DCHECK(!IsRemoteServer()); | 645 DCHECK(!IsRemoteServer()); |
648 DCHECK(task_runner_provider_->IsImplThread()); | 646 DCHECK(task_runner_provider_->IsImplThread()); |
649 | 647 |
650 const bool supports_impl_scrolling = task_runner_provider_->HasImplThread(); | 648 const bool supports_impl_scrolling = task_runner_provider_->HasImplThread(); |
651 std::unique_ptr<AnimationHost> animation_host_impl = | 649 std::unique_ptr<AnimationHost> animation_host_impl = |
652 animation_host_->CreateImplInstance(supports_impl_scrolling); | 650 layer_tree_.animation_host()->CreateImplInstance(supports_impl_scrolling); |
653 | 651 |
654 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( | 652 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( |
655 settings_, client, task_runner_provider_.get(), | 653 settings_, client, task_runner_provider_.get(), |
656 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, | 654 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, |
657 gpu_memory_buffer_manager_, task_graph_runner_, | 655 gpu_memory_buffer_manager_, task_graph_runner_, |
658 std::move(animation_host_impl), id_); | 656 std::move(animation_host_impl), id_); |
659 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); | 657 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); |
660 host_impl->SetContentIsSuitableForGpuRasterization( | 658 host_impl->SetContentIsSuitableForGpuRasterization( |
661 content_is_suitable_for_gpu_rasterization_); | 659 content_is_suitable_for_gpu_rasterization_); |
662 shared_bitmap_manager_ = NULL; | 660 shared_bitmap_manager_ = NULL; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 } | 745 } |
748 | 746 |
749 void LayerTreeHost::SetNextCommitForcesRedraw() { | 747 void LayerTreeHost::SetNextCommitForcesRedraw() { |
750 next_commit_forces_redraw_ = true; | 748 next_commit_forces_redraw_ = true; |
751 proxy_->SetNeedsUpdateLayers(); | 749 proxy_->SetNeedsUpdateLayers(); |
752 } | 750 } |
753 | 751 |
754 void LayerTreeHost::SetAnimationEvents( | 752 void LayerTreeHost::SetAnimationEvents( |
755 std::unique_ptr<AnimationEvents> events) { | 753 std::unique_ptr<AnimationEvents> events) { |
756 DCHECK(task_runner_provider_->IsMainThread()); | 754 DCHECK(task_runner_provider_->IsMainThread()); |
757 animation_host_->SetAnimationEvents(std::move(events)); | 755 layer_tree_.animation_host()->SetAnimationEvents(std::move(events)); |
758 } | 756 } |
759 | 757 |
760 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { | 758 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { |
761 if (root_layer_.get() == root_layer.get()) | 759 if (root_layer_.get() == root_layer.get()) |
762 return; | 760 return; |
763 | 761 |
764 if (root_layer_.get()) | 762 if (root_layer_.get()) |
765 root_layer_->SetLayerTreeHost(NULL); | 763 root_layer_->SetLayerTreeHost(NULL); |
766 root_layer_ = root_layer; | 764 root_layer_ = root_layer; |
767 if (root_layer_.get()) { | 765 if (root_layer_.get()) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 draw_property_utils::UpdatePropertyTrees(&property_trees_, | 1040 draw_property_utils::UpdatePropertyTrees(&property_trees_, |
1043 can_render_to_separate_surface); | 1041 can_render_to_separate_surface); |
1044 draw_property_utils::FindLayersThatNeedUpdates( | 1042 draw_property_utils::FindLayersThatNeedUpdates( |
1045 this, property_trees_.transform_tree, property_trees_.effect_tree, | 1043 this, property_trees_.transform_tree, property_trees_.effect_tree, |
1046 &update_layer_list); | 1044 &update_layer_list); |
1047 } | 1045 } |
1048 | 1046 |
1049 for (const auto& layer : update_layer_list) | 1047 for (const auto& layer : update_layer_list) |
1050 layer->SavePaintProperties(); | 1048 layer->SavePaintProperties(); |
1051 | 1049 |
1052 base::AutoReset<bool> painting(&in_paint_layer_contents_, true); | |
1053 bool did_paint_content = false; | |
1054 bool content_is_suitable_for_gpu = true; | 1050 bool content_is_suitable_for_gpu = true; |
1055 for (const auto& layer : update_layer_list) { | 1051 bool did_paint_content = |
1056 did_paint_content |= layer->Update(); | 1052 layer_tree_.UpdateLayers(update_layer_list, &content_is_suitable_for_gpu); |
1057 content_is_suitable_for_gpu &= layer->IsSuitableForGpuRasterization(); | |
1058 } | |
1059 | 1053 |
1060 if (content_is_suitable_for_gpu) { | 1054 if (content_is_suitable_for_gpu) { |
1061 ++num_consecutive_frames_suitable_for_gpu_; | 1055 ++num_consecutive_frames_suitable_for_gpu_; |
1062 if (num_consecutive_frames_suitable_for_gpu_ >= | 1056 if (num_consecutive_frames_suitable_for_gpu_ >= |
1063 kNumFramesToConsiderBeforeGpuRasterization) { | 1057 kNumFramesToConsiderBeforeGpuRasterization) { |
1064 content_is_suitable_for_gpu_rasterization_ = true; | 1058 content_is_suitable_for_gpu_rasterization_ = true; |
1065 } | 1059 } |
1066 } else { | 1060 } else { |
1067 num_consecutive_frames_suitable_for_gpu_ = 0; | 1061 num_consecutive_frames_suitable_for_gpu_ = 0; |
1068 content_is_suitable_for_gpu_rasterization_ = false; | 1062 content_is_suitable_for_gpu_rasterization_ = false; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 | 1141 |
1148 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, | 1142 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, |
1149 TopControlsState current, | 1143 TopControlsState current, |
1150 bool animate) { | 1144 bool animate) { |
1151 // Top controls are only used in threaded or remote mode. | 1145 // Top controls are only used in threaded or remote mode. |
1152 DCHECK(IsThreaded() || IsRemoteServer()); | 1146 DCHECK(IsThreaded() || IsRemoteServer()); |
1153 proxy_->UpdateTopControlsState(constraints, current, animate); | 1147 proxy_->UpdateTopControlsState(constraints, current, animate); |
1154 } | 1148 } |
1155 | 1149 |
1156 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { | 1150 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { |
1157 std::unique_ptr<AnimationEvents> events = animation_host_->CreateEvents(); | 1151 AnimationHost* animation_host = layer_tree_.animation_host(); |
| 1152 std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents(); |
1158 | 1153 |
1159 if (animation_host_->AnimateLayers(monotonic_time)) | 1154 if (animation_host->AnimateLayers(monotonic_time)) |
1160 animation_host_->UpdateAnimationState(true, events.get()); | 1155 animation_host->UpdateAnimationState(true, events.get()); |
1161 | 1156 |
1162 if (!events->events_.empty()) | 1157 if (!events->events_.empty()) |
1163 property_trees_.needs_rebuild = true; | 1158 property_trees_.needs_rebuild = true; |
1164 } | 1159 } |
1165 | 1160 |
1166 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { | 1161 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { |
1167 DCHECK(client); | 1162 DCHECK(client); |
1168 | 1163 |
1169 UIResourceId next_id = next_ui_resource_id_++; | 1164 UIResourceId next_id = next_ui_resource_id_++; |
1170 DCHECK(ui_resource_client_map_.find(next_id) == | 1165 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() { | 1304 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() { |
1310 return SurfaceSequence(surface_client_id_, next_surface_sequence_++); | 1305 return SurfaceSequence(surface_client_id_, next_surface_sequence_++); |
1311 } | 1306 } |
1312 | 1307 |
1313 void LayerTreeHost::SetLayerTreeMutator( | 1308 void LayerTreeHost::SetLayerTreeMutator( |
1314 std::unique_ptr<LayerTreeMutator> mutator) { | 1309 std::unique_ptr<LayerTreeMutator> mutator) { |
1315 proxy_->SetMutator(std::move(mutator)); | 1310 proxy_->SetMutator(std::move(mutator)); |
1316 } | 1311 } |
1317 | 1312 |
1318 Layer* LayerTreeHost::LayerById(int id) const { | 1313 Layer* LayerTreeHost::LayerById(int id) const { |
1319 LayerIdMap::const_iterator iter = layer_id_map_.find(id); | 1314 return layer_tree_.LayerById(id); |
1320 return iter != layer_id_map_.end() ? iter->second : nullptr; | |
1321 } | 1315 } |
1322 | 1316 |
1323 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const { | 1317 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const { |
1324 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id); | 1318 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id); |
1325 return iter != element_layers_map_.end() ? iter->second : nullptr; | 1319 return iter != element_layers_map_.end() ? iter->second : nullptr; |
1326 } | 1320 } |
1327 | 1321 |
1328 void LayerTreeHost::AddToElementMap(Layer* layer) { | 1322 void LayerTreeHost::AddToElementMap(Layer* layer) { |
1329 if (!layer->element_id()) | 1323 if (!layer->element_id()) |
1330 return; | 1324 return; |
1331 | 1325 |
1332 element_layers_map_[layer->element_id()] = layer; | 1326 element_layers_map_[layer->element_id()] = layer; |
1333 } | 1327 } |
1334 | 1328 |
1335 void LayerTreeHost::RemoveFromElementMap(Layer* layer) { | 1329 void LayerTreeHost::RemoveFromElementMap(Layer* layer) { |
1336 if (!layer->element_id()) | 1330 if (!layer->element_id()) |
1337 return; | 1331 return; |
1338 | 1332 |
1339 element_layers_map_.erase(layer->element_id()); | 1333 element_layers_map_.erase(layer->element_id()); |
1340 } | 1334 } |
1341 | 1335 |
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, | 1336 bool LayerTreeHost::IsElementInList(ElementId element_id, |
1381 ElementListType list_type) const { | 1337 ElementListType list_type) const { |
1382 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id); | 1338 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id); |
1383 } | 1339 } |
1384 | 1340 |
1385 void LayerTreeHost::SetMutatorsNeedCommit() { | 1341 void LayerTreeHost::SetMutatorsNeedCommit() { |
1386 SetNeedsCommit(); | 1342 SetNeedsCommit(); |
1387 } | 1343 } |
1388 | 1344 |
1389 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { | 1345 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 swap_promises->swap(swap_promise_list_); | 1504 swap_promises->swap(swap_promise_list_); |
1549 DCHECK(swap_promise_list_.empty()); | 1505 DCHECK(swap_promise_list_.empty()); |
1550 | 1506 |
1551 proto->set_needs_full_tree_sync(needs_full_tree_sync_); | 1507 proto->set_needs_full_tree_sync(needs_full_tree_sync_); |
1552 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); | 1508 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); |
1553 proto->set_source_frame_number(source_frame_number_); | 1509 proto->set_source_frame_number(source_frame_number_); |
1554 | 1510 |
1555 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, | 1511 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, |
1556 proto->mutable_root_layer()); | 1512 proto->mutable_root_layer()); |
1557 | 1513 |
1558 // layers_that_should_push_properties_ should be serialized before layer | 1514 // Serialize the LayerTree before serializing the properties. During layer |
1559 // properties because it is cleared during the properties serialization. | 1515 // property serialization, we clear the list |layer_that_should_properties_| |
1560 for (auto* layer : layers_that_should_push_properties_) | 1516 // from the LayerTree. |
1561 proto->add_layers_that_should_push_properties(layer->id()); | 1517 layer_tree_.ToProtobuf(proto->mutable_layer_tree()); |
1562 | 1518 |
1563 LayerProtoConverter::SerializeLayerProperties(this, | 1519 LayerProtoConverter::SerializeLayerProperties(this, |
1564 proto->mutable_layer_updates()); | 1520 proto->mutable_layer_updates()); |
1565 | 1521 |
1566 std::vector<PictureData> pictures = | 1522 std::vector<PictureData> pictures = |
1567 engine_picture_cache_->CalculateCacheUpdateAndFlush(); | 1523 engine_picture_cache_->CalculateCacheUpdateAndFlush(); |
1568 proto::PictureDataVectorToSkPicturesProto(pictures, | 1524 proto::PictureDataVectorToSkPicturesProto(pictures, |
1569 proto->mutable_pictures()); | 1525 proto->mutable_pictures()); |
1570 | 1526 |
1571 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); | 1527 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); |
(...skipping 15 matching lines...) Expand all Loading... |
1587 proto->set_has_transparent_background(has_transparent_background_); | 1543 proto->set_has_transparent_background(has_transparent_background_); |
1588 proto->set_have_scroll_event_handlers(have_scroll_event_handlers_); | 1544 proto->set_have_scroll_event_handlers(have_scroll_event_handlers_); |
1589 proto->set_wheel_event_listener_properties(static_cast<uint32_t>( | 1545 proto->set_wheel_event_listener_properties(static_cast<uint32_t>( |
1590 event_listener_properties(EventListenerClass::kMouseWheel))); | 1546 event_listener_properties(EventListenerClass::kMouseWheel))); |
1591 proto->set_touch_start_or_move_event_listener_properties( | 1547 proto->set_touch_start_or_move_event_listener_properties( |
1592 static_cast<uint32_t>( | 1548 static_cast<uint32_t>( |
1593 event_listener_properties(EventListenerClass::kTouchStartOrMove))); | 1549 event_listener_properties(EventListenerClass::kTouchStartOrMove))); |
1594 proto->set_touch_end_or_cancel_event_listener_properties( | 1550 proto->set_touch_end_or_cancel_event_listener_properties( |
1595 static_cast<uint32_t>( | 1551 static_cast<uint32_t>( |
1596 event_listener_properties(EventListenerClass::kTouchEndOrCancel))); | 1552 event_listener_properties(EventListenerClass::kTouchEndOrCancel))); |
1597 proto->set_in_paint_layer_contents(in_paint_layer_contents_); | |
1598 proto->set_id(id_); | 1553 proto->set_id(id_); |
1599 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); | 1554 proto->set_next_commit_forces_redraw(next_commit_forces_redraw_); |
1600 | 1555 |
1601 // Viewport layers. | 1556 // Viewport layers. |
1602 proto->set_overscroll_elasticity_layer_id( | 1557 proto->set_overscroll_elasticity_layer_id( |
1603 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id() | 1558 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id() |
1604 : Layer::INVALID_ID); | 1559 : Layer::INVALID_ID); |
1605 proto->set_page_scale_layer_id(page_scale_layer_ ? page_scale_layer_->id() | 1560 proto->set_page_scale_layer_id(page_scale_layer_ ? page_scale_layer_->id() |
1606 : Layer::INVALID_ID); | 1561 : Layer::INVALID_ID); |
1607 proto->set_inner_viewport_scroll_layer_id( | 1562 proto->set_inner_viewport_scroll_layer_id( |
(...skipping 10 matching lines...) Expand all Loading... |
1618 proto->set_surface_client_id(surface_client_id_); | 1573 proto->set_surface_client_id(surface_client_id_); |
1619 proto->set_next_surface_sequence(next_surface_sequence_); | 1574 proto->set_next_surface_sequence(next_surface_sequence_); |
1620 | 1575 |
1621 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 1576 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
1622 "cc.remote", "LayerTreeHostProto", source_frame_number_, | 1577 "cc.remote", "LayerTreeHostProto", source_frame_number_, |
1623 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); | 1578 ComputeLayerTreeHostProtoSizeSplitAsValue(proto)); |
1624 } | 1579 } |
1625 | 1580 |
1626 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { | 1581 void LayerTreeHost::FromProtobufForCommit(const proto::LayerTreeHost& proto) { |
1627 DCHECK(client_picture_cache_); | 1582 DCHECK(client_picture_cache_); |
1628 | |
1629 needs_full_tree_sync_ = proto.needs_full_tree_sync(); | 1583 needs_full_tree_sync_ = proto.needs_full_tree_sync(); |
1630 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); | 1584 needs_meta_info_recomputation_ = proto.needs_meta_info_recomputation(); |
1631 source_frame_number_ = proto.source_frame_number(); | 1585 source_frame_number_ = proto.source_frame_number(); |
1632 | 1586 |
1633 // Layer hierarchy. | 1587 // Layer hierarchy. |
1634 scoped_refptr<Layer> new_root_layer = | 1588 scoped_refptr<Layer> new_root_layer = |
1635 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, | 1589 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, |
1636 proto.root_layer(), this); | 1590 proto.root_layer(), this); |
1637 if (root_layer_ != new_root_layer) { | 1591 if (root_layer_ != new_root_layer) { |
1638 root_layer_ = new_root_layer; | 1592 root_layer_ = new_root_layer; |
1639 } | 1593 } |
1640 | 1594 |
1641 for (auto layer_id : proto.layers_that_should_push_properties()) | 1595 layer_tree_.FromProtobuf(proto.layer_tree()); |
1642 layers_that_should_push_properties_.insert(layer_id_map_[layer_id]); | |
1643 | 1596 |
1644 // Ensure ClientPictureCache contains all the necessary SkPictures before | 1597 // Ensure ClientPictureCache contains all the necessary SkPictures before |
1645 // deserializing the properties. | 1598 // deserializing the properties. |
1646 proto::SkPictures proto_pictures = proto.pictures(); | 1599 proto::SkPictures proto_pictures = proto.pictures(); |
1647 std::vector<PictureData> pictures = | 1600 std::vector<PictureData> pictures = |
1648 SkPicturesProtoToPictureDataVector(proto_pictures); | 1601 SkPicturesProtoToPictureDataVector(proto_pictures); |
1649 client_picture_cache_->ApplyCacheUpdate(pictures); | 1602 client_picture_cache_->ApplyCacheUpdate(pictures); |
1650 | 1603 |
1651 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), | 1604 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), |
1652 proto.layer_updates()); | 1605 proto.layer_updates()); |
(...skipping 23 matching lines...) Expand all Loading... |
1676 static_cast<EventListenerProperties>( | 1629 static_cast<EventListenerProperties>( |
1677 proto.wheel_event_listener_properties()); | 1630 proto.wheel_event_listener_properties()); |
1678 event_listener_properties_[static_cast<size_t>( | 1631 event_listener_properties_[static_cast<size_t>( |
1679 EventListenerClass::kTouchStartOrMove)] = | 1632 EventListenerClass::kTouchStartOrMove)] = |
1680 static_cast<EventListenerProperties>( | 1633 static_cast<EventListenerProperties>( |
1681 proto.touch_start_or_move_event_listener_properties()); | 1634 proto.touch_start_or_move_event_listener_properties()); |
1682 event_listener_properties_[static_cast<size_t>( | 1635 event_listener_properties_[static_cast<size_t>( |
1683 EventListenerClass::kTouchEndOrCancel)] = | 1636 EventListenerClass::kTouchEndOrCancel)] = |
1684 static_cast<EventListenerProperties>( | 1637 static_cast<EventListenerProperties>( |
1685 proto.touch_end_or_cancel_event_listener_properties()); | 1638 proto.touch_end_or_cancel_event_listener_properties()); |
1686 in_paint_layer_contents_ = proto.in_paint_layer_contents(); | |
1687 id_ = proto.id(); | 1639 id_ = proto.id(); |
1688 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); | 1640 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); |
1689 | 1641 |
1690 hud_layer_ = static_cast<HeadsUpDisplayLayer*>( | 1642 hud_layer_ = static_cast<HeadsUpDisplayLayer*>( |
1691 UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), layer_id_map_)); | 1643 UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), &layer_tree_)); |
1692 overscroll_elasticity_layer_ = | 1644 overscroll_elasticity_layer_ = |
1693 UpdateAndGetLayer(overscroll_elasticity_layer_.get(), | 1645 UpdateAndGetLayer(overscroll_elasticity_layer_.get(), |
1694 proto.overscroll_elasticity_layer_id(), layer_id_map_); | 1646 proto.overscroll_elasticity_layer_id(), &layer_tree_); |
1695 page_scale_layer_ = UpdateAndGetLayer( | 1647 page_scale_layer_ = UpdateAndGetLayer( |
1696 page_scale_layer_.get(), proto.page_scale_layer_id(), layer_id_map_); | 1648 page_scale_layer_.get(), proto.page_scale_layer_id(), &layer_tree_); |
1697 inner_viewport_scroll_layer_ = | 1649 inner_viewport_scroll_layer_ = |
1698 UpdateAndGetLayer(inner_viewport_scroll_layer_.get(), | 1650 UpdateAndGetLayer(inner_viewport_scroll_layer_.get(), |
1699 proto.inner_viewport_scroll_layer_id(), layer_id_map_); | 1651 proto.inner_viewport_scroll_layer_id(), &layer_tree_); |
1700 outer_viewport_scroll_layer_ = | 1652 outer_viewport_scroll_layer_ = |
1701 UpdateAndGetLayer(outer_viewport_scroll_layer_.get(), | 1653 UpdateAndGetLayer(outer_viewport_scroll_layer_.get(), |
1702 proto.outer_viewport_scroll_layer_id(), layer_id_map_); | 1654 proto.outer_viewport_scroll_layer_id(), &layer_tree_); |
1703 | 1655 |
1704 LayerSelectionFromProtobuf(&selection_, proto.selection()); | 1656 LayerSelectionFromProtobuf(&selection_, proto.selection()); |
1705 | 1657 |
1706 // It is required to create new PropertyTrees before deserializing it. | 1658 // It is required to create new PropertyTrees before deserializing it. |
1707 property_trees_ = PropertyTrees(); | 1659 property_trees_ = PropertyTrees(); |
1708 property_trees_.FromProtobuf(proto.property_trees()); | 1660 property_trees_.FromProtobuf(proto.property_trees()); |
1709 | 1661 |
1710 // Forcefully override the sequence number of all layers in the tree to have | 1662 // Forcefully override the sequence number of all layers in the tree to have |
1711 // a valid sequence number. Changing the sequence number for a layer does not | 1663 // a valid sequence number. Changing the sequence number for a layer does not |
1712 // need a commit, so the value will become out of date for layers that are not | 1664 // need a commit, so the value will become out of date for layers that are not |
1713 // updated for other reasons. All layers that at this point are part of the | 1665 // updated for other reasons. All layers that at this point are part of the |
1714 // layer tree are valid, so it is OK that they have a valid sequence number. | 1666 // layer tree are valid, so it is OK that they have a valid sequence number. |
1715 int seq_num = property_trees_.sequence_number; | 1667 int seq_num = property_trees_.sequence_number; |
1716 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { | 1668 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { |
1717 layer->set_property_tree_sequence_number(seq_num); | 1669 layer->set_property_tree_sequence_number(seq_num); |
1718 }); | 1670 }); |
1719 | 1671 |
1720 surface_client_id_ = proto.surface_client_id(); | 1672 surface_client_id_ = proto.surface_client_id(); |
1721 next_surface_sequence_ = proto.next_surface_sequence(); | 1673 next_surface_sequence_ = proto.next_surface_sequence(); |
1722 } | 1674 } |
1723 | 1675 |
| 1676 AnimationHost* LayerTreeHost::animation_host() const { |
| 1677 return layer_tree_.animation_host(); |
| 1678 } |
| 1679 |
1724 } // namespace cc | 1680 } // namespace cc |
OLD | NEW |