Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: cc/trees/layer_tree_host.cc

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

Powered by Google App Engine
This is Rietveld 408576698