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

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

Powered by Google App Engine
This is Rietveld 408576698