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

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

Issue 2216203002: Refactor MutatorHostClient from LayerTreeHost to LayerTree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix call site in cc_perftest. Created 4 years, 4 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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 event_listener_properties_(), 241 event_listener_properties_(),
242 did_complete_scale_animation_(false), 242 did_complete_scale_animation_(false),
243 id_(s_layer_tree_host_sequence_number.GetNext() + 1), 243 id_(s_layer_tree_host_sequence_number.GetNext() + 1),
244 next_commit_forces_redraw_(false), 244 next_commit_forces_redraw_(false),
245 shared_bitmap_manager_(params->shared_bitmap_manager), 245 shared_bitmap_manager_(params->shared_bitmap_manager),
246 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), 246 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager),
247 task_graph_runner_(params->task_graph_runner), 247 task_graph_runner_(params->task_graph_runner),
248 image_serialization_processor_(params->image_serialization_processor), 248 image_serialization_processor_(params->image_serialization_processor),
249 surface_client_id_(0u), 249 surface_client_id_(0u),
250 next_surface_sequence_(1u), 250 next_surface_sequence_(1u),
251 layer_tree_(std::move(params->animation_host)) { 251 layer_tree_(base::WrapUnique(
252 new LayerTree(std::move(params->animation_host), this))) {
252 DCHECK(task_graph_runner_); 253 DCHECK(task_graph_runner_);
253 254
254 layer_tree_.animation_host()->SetMutatorHostClient(this);
255
256 rendering_stats_instrumentation_->set_record_rendering_stats( 255 rendering_stats_instrumentation_->set_record_rendering_stats(
257 debug_state_.RecordRenderingStats()); 256 debug_state_.RecordRenderingStats());
258 } 257 }
259 258
260 void LayerTreeHost::InitializeThreaded( 259 void LayerTreeHost::InitializeThreaded(
261 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 260 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
262 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 261 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
263 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { 262 std::unique_ptr<BeginFrameSource> external_begin_frame_source) {
264 task_runner_provider_ = 263 task_runner_provider_ =
265 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); 264 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 354
356 void LayerTreeHost::InitializeProxy( 355 void LayerTreeHost::InitializeProxy(
357 std::unique_ptr<Proxy> proxy, 356 std::unique_ptr<Proxy> proxy,
358 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { 357 std::unique_ptr<BeginFrameSource> external_begin_frame_source) {
359 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal"); 358 TRACE_EVENT0("cc", "LayerTreeHost::InitializeForReal");
360 DCHECK(task_runner_provider_); 359 DCHECK(task_runner_provider_);
361 360
362 proxy_ = std::move(proxy); 361 proxy_ = std::move(proxy);
363 proxy_->Start(std::move(external_begin_frame_source)); 362 proxy_->Start(std::move(external_begin_frame_source));
364 363
365 layer_tree_.animation_host()->SetSupportsScrollAnimations( 364 layer_tree_->animation_host()->SetSupportsScrollAnimations(
366 proxy_->SupportsImplScrolling()); 365 proxy_->SupportsImplScrolling());
367 } 366 }
368 367
369 LayerTreeHost::~LayerTreeHost() { 368 LayerTreeHost::~LayerTreeHost() {
370 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); 369 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost");
371 370
372 layer_tree_.animation_host()->SetMutatorHostClient(nullptr);
373
374 if (root_layer_.get()) 371 if (root_layer_.get())
375 root_layer_->SetLayerTreeHost(NULL); 372 root_layer_->SetLayerTreeHost(NULL);
376 373
377 DCHECK(swap_promise_monitor_.empty()); 374 DCHECK(swap_promise_monitor_.empty());
378 375
379 BreakSwapPromises(SwapPromise::COMMIT_FAILS); 376 BreakSwapPromises(SwapPromise::COMMIT_FAILS);
380 377
381 if (proxy_) { 378 if (proxy_) {
382 DCHECK(task_runner_provider_->IsMainThread()); 379 DCHECK(task_runner_provider_->IsMainThread());
383 proxy_->Stop(); 380 proxy_->Stop();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { 428 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
432 DCHECK(!IsRemoteServer()); 429 DCHECK(!IsRemoteServer());
433 DCHECK(task_runner_provider_->IsImplThread()); 430 DCHECK(task_runner_provider_->IsImplThread());
434 431
435 bool is_new_trace; 432 bool is_new_trace;
436 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); 433 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
437 if (is_new_trace && 434 if (is_new_trace &&
438 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && 435 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
439 root_layer()) { 436 root_layer()) {
440 LayerTreeHostCommon::CallFunctionForEveryLayer( 437 LayerTreeHostCommon::CallFunctionForEveryLayer(
441 this, [](Layer* layer) { layer->DidBeginTracing(); }); 438 layer_tree_.get(), [](Layer* layer) { layer->DidBeginTracing(); });
442 } 439 }
443 440
444 LayerTreeImpl* sync_tree = host_impl->sync_tree(); 441 LayerTreeImpl* sync_tree = host_impl->sync_tree();
445 442
446 if (next_commit_forces_redraw_) { 443 if (next_commit_forces_redraw_) {
447 sync_tree->ForceRedrawNextActivation(); 444 sync_tree->ForceRedrawNextActivation();
448 next_commit_forces_redraw_ = false; 445 next_commit_forces_redraw_ = false;
449 } 446 }
450 447
451 sync_tree->set_source_frame_number(source_frame_number()); 448 sync_tree->set_source_frame_number(source_frame_number());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 ui_resource_request_queue_.clear(); 537 ui_resource_request_queue_.clear();
541 } 538 }
542 539
543 DCHECK(!sync_tree->ViewportSizeInvalid()); 540 DCHECK(!sync_tree->ViewportSizeInvalid());
544 541
545 sync_tree->set_has_ever_been_drawn(false); 542 sync_tree->set_has_ever_been_drawn(false);
546 543
547 { 544 {
548 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties"); 545 TRACE_EVENT0("cc", "LayerTreeHost::PushProperties");
549 546
550 TreeSynchronizer::PushLayerProperties(&layer_tree_, sync_tree); 547 TreeSynchronizer::PushLayerProperties(layer_tree_.get(), sync_tree);
551 548
552 // This must happen after synchronizing property trees and after push 549 // This must happen after synchronizing property trees and after push
553 // properties, which updates property tree indices, but before animation 550 // properties, which updates property tree indices, but before animation
554 // host pushes properties as animation host push properties can change 551 // host pushes properties as animation host push properties can change
555 // Animation::InEffect and we want the old InEffect value for updating 552 // Animation::InEffect and we want the old InEffect value for updating
556 // property tree scrolling and animation. 553 // property tree scrolling and animation.
557 sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread(); 554 sync_tree->UpdatePropertyTreeScrollingAndAnimationFromMainThread();
558 555
559 TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties"); 556 TRACE_EVENT0("cc", "LayerTreeHost::AnimationHost::PushProperties");
560 DCHECK(host_impl->animation_host()); 557 DCHECK(host_impl->animation_host());
561 layer_tree_.animation_host()->PushPropertiesTo(host_impl->animation_host()); 558 layer_tree_->animation_host()->PushPropertiesTo(
559 host_impl->animation_host());
562 } 560 }
563 561
564 // This must happen after synchronizing property trees and after pushing 562 // This must happen after synchronizing property trees and after pushing
565 // properties, which updates the clobber_active_value flag. 563 // properties, which updates the clobber_active_value flag.
566 sync_tree->UpdatePropertyTreeScrollOffset(&property_trees_); 564 sync_tree->UpdatePropertyTreeScrollOffset(&property_trees_);
567 565
568 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl); 566 micro_benchmark_controller_.ScheduleImplBenchmarks(host_impl);
569 property_trees_.ResetAllChangeTracking(); 567 property_trees_.ResetAllChangeTracking();
570 } 568 }
571 569
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 client_->DidFailToInitializeOutputSurface(); 636 client_->DidFailToInitializeOutputSurface();
639 } 637 }
640 638
641 std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl( 639 std::unique_ptr<LayerTreeHostImpl> LayerTreeHost::CreateLayerTreeHostImpl(
642 LayerTreeHostImplClient* client) { 640 LayerTreeHostImplClient* client) {
643 DCHECK(!IsRemoteServer()); 641 DCHECK(!IsRemoteServer());
644 DCHECK(task_runner_provider_->IsImplThread()); 642 DCHECK(task_runner_provider_->IsImplThread());
645 643
646 const bool supports_impl_scrolling = task_runner_provider_->HasImplThread(); 644 const bool supports_impl_scrolling = task_runner_provider_->HasImplThread();
647 std::unique_ptr<AnimationHost> animation_host_impl = 645 std::unique_ptr<AnimationHost> animation_host_impl =
648 layer_tree_.animation_host()->CreateImplInstance(supports_impl_scrolling); 646 layer_tree_->animation_host()->CreateImplInstance(
647 supports_impl_scrolling);
649 648
650 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create( 649 std::unique_ptr<LayerTreeHostImpl> host_impl = LayerTreeHostImpl::Create(
651 settings_, client, task_runner_provider_.get(), 650 settings_, client, task_runner_provider_.get(),
652 rendering_stats_instrumentation_.get(), shared_bitmap_manager_, 651 rendering_stats_instrumentation_.get(), shared_bitmap_manager_,
653 gpu_memory_buffer_manager_, task_graph_runner_, 652 gpu_memory_buffer_manager_, task_graph_runner_,
654 std::move(animation_host_impl), id_); 653 std::move(animation_host_impl), id_);
655 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_); 654 host_impl->SetHasGpuRasterizationTrigger(has_gpu_rasterization_trigger_);
656 host_impl->SetContentIsSuitableForGpuRasterization( 655 host_impl->SetContentIsSuitableForGpuRasterization(
657 content_is_suitable_for_gpu_rasterization_); 656 content_is_suitable_for_gpu_rasterization_);
658 shared_bitmap_manager_ = NULL; 657 shared_bitmap_manager_ = NULL;
(...skipping 15 matching lines...) Expand all
674 } 673 }
675 674
676 void LayerTreeHost::FinishAllRendering() { 675 void LayerTreeHost::FinishAllRendering() {
677 proxy_->FinishAllRendering(); 676 proxy_->FinishAllRendering();
678 } 677 }
679 678
680 void LayerTreeHost::SetDeferCommits(bool defer_commits) { 679 void LayerTreeHost::SetDeferCommits(bool defer_commits) {
681 proxy_->SetDeferCommits(defer_commits); 680 proxy_->SetDeferCommits(defer_commits);
682 } 681 }
683 682
684 void LayerTreeHost::SetNeedsDisplayOnAllLayers() { 683 void LayerTreeHost::SetNeedsDisplayOnAllLayers() {
Khushal 2016/08/15 17:46:39 This method can move to the LayerTree as well.
xingliu 2016/08/15 21:29:13 Done.
685 for (auto* layer : *this) 684 for (auto* layer : *layer_tree_)
686 layer->SetNeedsDisplay(); 685 layer->SetNeedsDisplay();
687 } 686 }
688 687
689 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const { 688 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const {
690 return proxy_->GetRendererCapabilities(); 689 return proxy_->GetRendererCapabilities();
691 } 690 }
692 691
693 void LayerTreeHost::SetNeedsAnimate() { 692 void LayerTreeHost::SetNeedsAnimate() {
694 proxy_->SetNeedsAnimate(); 693 proxy_->SetNeedsAnimate();
695 NotifySwapPromiseMonitorsOfSetNeedsCommit(); 694 NotifySwapPromiseMonitorsOfSetNeedsCommit();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } 742 }
744 743
745 void LayerTreeHost::SetNextCommitForcesRedraw() { 744 void LayerTreeHost::SetNextCommitForcesRedraw() {
746 next_commit_forces_redraw_ = true; 745 next_commit_forces_redraw_ = true;
747 proxy_->SetNeedsUpdateLayers(); 746 proxy_->SetNeedsUpdateLayers();
748 } 747 }
749 748
750 void LayerTreeHost::SetAnimationEvents( 749 void LayerTreeHost::SetAnimationEvents(
751 std::unique_ptr<AnimationEvents> events) { 750 std::unique_ptr<AnimationEvents> events) {
752 DCHECK(task_runner_provider_->IsMainThread()); 751 DCHECK(task_runner_provider_->IsMainThread());
753 layer_tree_.animation_host()->SetAnimationEvents(std::move(events)); 752 layer_tree_->animation_host()->SetAnimationEvents(std::move(events));
754 } 753 }
755 754
756 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) { 755 void LayerTreeHost::SetRootLayer(scoped_refptr<Layer> root_layer) {
757 if (root_layer_.get() == root_layer.get()) 756 if (root_layer_.get() == root_layer.get())
758 return; 757 return;
759 758
760 if (root_layer_.get()) 759 if (root_layer_.get())
761 root_layer_->SetLayerTreeHost(NULL); 760 root_layer_->SetLayerTreeHost(NULL);
762 root_layer_ = root_layer; 761 root_layer_ = root_layer;
763 if (root_layer_.get()) { 762 if (root_layer_.get()) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 bool LayerTreeHost::UpdateLayers() { 912 bool LayerTreeHost::UpdateLayers() {
914 DCHECK(!output_surface_lost_); 913 DCHECK(!output_surface_lost_);
915 if (!root_layer()) 914 if (!root_layer())
916 return false; 915 return false;
917 DCHECK(!root_layer()->parent()); 916 DCHECK(!root_layer()->parent());
918 bool result = DoUpdateLayers(root_layer()); 917 bool result = DoUpdateLayers(root_layer());
919 micro_benchmark_controller_.DidUpdateLayers(); 918 micro_benchmark_controller_.DidUpdateLayers();
920 return result || next_commit_forces_redraw_; 919 return result || next_commit_forces_redraw_;
921 } 920 }
922 921
923 LayerListIterator<Layer> LayerTreeHost::begin() const {
924 return LayerListIterator<Layer>(root_layer_.get());
925 }
926
927 LayerListIterator<Layer> LayerTreeHost::end() const {
928 return LayerListIterator<Layer>(nullptr);
929 }
930
931 LayerListReverseIterator<Layer> LayerTreeHost::rbegin() {
932 return LayerListReverseIterator<Layer>(root_layer_.get());
933 }
934
935 LayerListReverseIterator<Layer> LayerTreeHost::rend() {
936 return LayerListReverseIterator<Layer>(nullptr);
937 }
938
939 void LayerTreeHost::DidCompletePageScaleAnimation() { 922 void LayerTreeHost::DidCompletePageScaleAnimation() {
940 did_complete_scale_animation_ = true; 923 did_complete_scale_animation_ = true;
941 } 924 }
942 925
943 void LayerTreeHost::RecordGpuRasterizationHistogram() { 926 void LayerTreeHost::RecordGpuRasterizationHistogram() {
944 // Gpu rasterization is only supported for Renderer compositors. 927 // Gpu rasterization is only supported for Renderer compositors.
945 // Checking for IsSingleThreaded() to exclude Browser compositors. 928 // Checking for IsSingleThreaded() to exclude Browser compositors.
946 if (gpu_rasterization_histogram_recorded_ || IsSingleThreaded()) 929 if (gpu_rasterization_histogram_recorded_ || IsSingleThreaded())
947 return; 930 return;
948 931
(...skipping 25 matching lines...) Expand all
974 inner_viewport_scroll_layer_.get(), outer_viewport_scroll_layer_.get(), 957 inner_viewport_scroll_layer_.get(), outer_viewport_scroll_layer_.get(),
975 overscroll_elasticity_layer_.get(), elastic_overscroll_, 958 overscroll_elasticity_layer_.get(), elastic_overscroll_,
976 page_scale_factor_, device_scale_factor_, 959 page_scale_factor_, device_scale_factor_,
977 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_); 960 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_);
978 } 961 }
979 962
980 static void SetElementIdForTesting(Layer* layer) { 963 static void SetElementIdForTesting(Layer* layer) {
981 layer->SetElementId(LayerIdToElementIdForTesting(layer->id())); 964 layer->SetElementId(LayerIdToElementIdForTesting(layer->id()));
982 } 965 }
983 966
984 void LayerTreeHost::SetElementIdsForTesting() { 967 void LayerTreeHost::SetElementIdsForTesting() {
Khushal 2016/08/15 17:46:39 Can move this to the LayerTree.
xingliu 2016/08/15 21:29:13 Done.
985 LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting); 968 LayerTreeHostCommon::CallFunctionForEveryLayer(layer_tree_.get(),
969 SetElementIdForTesting);
986 } 970 }
987 971
988 bool LayerTreeHost::UsingSharedMemoryResources() { 972 bool LayerTreeHost::UsingSharedMemoryResources() {
989 return GetRendererCapabilities().using_shared_memory_resources; 973 return GetRendererCapabilities().using_shared_memory_resources;
990 } 974 }
991 975
992 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { 976 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) {
993 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number", 977 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number",
994 source_frame_number()); 978 source_frame_number());
995 979
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 can_render_to_separate_surface); 1023 can_render_to_separate_surface);
1040 draw_property_utils::FindLayersThatNeedUpdates( 1024 draw_property_utils::FindLayersThatNeedUpdates(
1041 this, property_trees_.transform_tree, property_trees_.effect_tree, 1025 this, property_trees_.transform_tree, property_trees_.effect_tree,
1042 &update_layer_list); 1026 &update_layer_list);
1043 } 1027 }
1044 1028
1045 for (const auto& layer : update_layer_list) 1029 for (const auto& layer : update_layer_list)
1046 layer->SavePaintProperties(); 1030 layer->SavePaintProperties();
1047 1031
1048 bool content_is_suitable_for_gpu = true; 1032 bool content_is_suitable_for_gpu = true;
1049 bool did_paint_content = 1033 bool did_paint_content = layer_tree_->UpdateLayers(
1050 layer_tree_.UpdateLayers(update_layer_list, &content_is_suitable_for_gpu); 1034 update_layer_list, &content_is_suitable_for_gpu);
1051 1035
1052 if (content_is_suitable_for_gpu) { 1036 if (content_is_suitable_for_gpu) {
1053 ++num_consecutive_frames_suitable_for_gpu_; 1037 ++num_consecutive_frames_suitable_for_gpu_;
1054 if (num_consecutive_frames_suitable_for_gpu_ >= 1038 if (num_consecutive_frames_suitable_for_gpu_ >=
1055 kNumFramesToConsiderBeforeGpuRasterization) { 1039 kNumFramesToConsiderBeforeGpuRasterization) {
1056 content_is_suitable_for_gpu_rasterization_ = true; 1040 content_is_suitable_for_gpu_rasterization_ = true;
1057 } 1041 }
1058 } else { 1042 } else {
1059 num_consecutive_frames_suitable_for_gpu_ = 0; 1043 num_consecutive_frames_suitable_for_gpu_ = 0;
1060 content_is_suitable_for_gpu_rasterization_ = false; 1044 content_is_suitable_for_gpu_rasterization_ = false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 TRACE_EVENT_WITH_FLOW1("input,benchmark", 1081 TRACE_EVENT_WITH_FLOW1("input,benchmark",
1098 "LatencyInfo.Flow", 1082 "LatencyInfo.Flow",
1099 TRACE_ID_DONT_MANGLE(swap_promise->TraceId()), 1083 TRACE_ID_DONT_MANGLE(swap_promise->TraceId()),
1100 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, 1084 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
1101 "step", "Main thread scroll update"); 1085 "step", "Main thread scroll update");
1102 QueueSwapPromise(std::move(swap_promise)); 1086 QueueSwapPromise(std::move(swap_promise));
1103 } 1087 }
1104 1088
1105 if (root_layer_.get()) { 1089 if (root_layer_.get()) {
1106 for (size_t i = 0; i < info->scrolls.size(); ++i) { 1090 for (size_t i = 0; i < info->scrolls.size(); ++i) {
1107 Layer* layer = LayerById(info->scrolls[i].layer_id); 1091 Layer* layer = layer_tree_->LayerById(info->scrolls[i].layer_id);
1108 if (!layer) 1092 if (!layer)
1109 continue; 1093 continue;
1110 layer->SetScrollOffsetFromImplSide(gfx::ScrollOffsetWithDelta( 1094 layer->SetScrollOffsetFromImplSide(gfx::ScrollOffsetWithDelta(
1111 layer->scroll_offset(), info->scrolls[i].scroll_delta)); 1095 layer->scroll_offset(), info->scrolls[i].scroll_delta));
1112 SetNeedsUpdateLayers(); 1096 SetNeedsUpdateLayers();
1113 } 1097 }
1114 } 1098 }
1115 1099
1116 // This needs to happen after scroll deltas have been sent to prevent top 1100 // This needs to happen after scroll deltas have been sent to prevent top
1117 // controls from clamping the layout viewport both on the compositor and 1101 // controls from clamping the layout viewport both on the compositor and
(...skipping 21 matching lines...) Expand all
1139 1123
1140 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints, 1124 void LayerTreeHost::UpdateTopControlsState(TopControlsState constraints,
1141 TopControlsState current, 1125 TopControlsState current,
1142 bool animate) { 1126 bool animate) {
1143 // Top controls are only used in threaded or remote mode. 1127 // Top controls are only used in threaded or remote mode.
1144 DCHECK(IsThreaded() || IsRemoteServer()); 1128 DCHECK(IsThreaded() || IsRemoteServer());
1145 proxy_->UpdateTopControlsState(constraints, current, animate); 1129 proxy_->UpdateTopControlsState(constraints, current, animate);
1146 } 1130 }
1147 1131
1148 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { 1132 void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
1149 AnimationHost* animation_host = layer_tree_.animation_host(); 1133 AnimationHost* animation_host = layer_tree_->animation_host();
1150 std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents(); 1134 std::unique_ptr<AnimationEvents> events = animation_host->CreateEvents();
1151 1135
1152 if (animation_host->AnimateLayers(monotonic_time)) 1136 if (animation_host->AnimateLayers(monotonic_time))
1153 animation_host->UpdateAnimationState(true, events.get()); 1137 animation_host->UpdateAnimationState(true, events.get());
1154 1138
1155 if (!events->events_.empty()) 1139 if (!events->events_.empty())
1156 property_trees_.needs_rebuild = true; 1140 property_trees_.needs_rebuild = true;
1157 } 1141 }
1158 1142
1159 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) { 1143 UIResourceId LayerTreeHost::CreateUIResource(UIResourceClient* client) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 1285
1302 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() { 1286 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() {
1303 return SurfaceSequence(surface_client_id_, next_surface_sequence_++); 1287 return SurfaceSequence(surface_client_id_, next_surface_sequence_++);
1304 } 1288 }
1305 1289
1306 void LayerTreeHost::SetLayerTreeMutator( 1290 void LayerTreeHost::SetLayerTreeMutator(
1307 std::unique_ptr<LayerTreeMutator> mutator) { 1291 std::unique_ptr<LayerTreeMutator> mutator) {
1308 proxy_->SetMutator(std::move(mutator)); 1292 proxy_->SetMutator(std::move(mutator));
1309 } 1293 }
1310 1294
1311 Layer* LayerTreeHost::LayerById(int id) const {
1312 return layer_tree_.LayerById(id);
1313 }
1314
1315 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const {
1316 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id);
1317 return iter != element_layers_map_.end() ? iter->second : nullptr;
1318 }
1319
1320 void LayerTreeHost::AddToElementMap(Layer* layer) {
1321 if (!layer->element_id())
1322 return;
1323
1324 element_layers_map_[layer->element_id()] = layer;
1325 }
1326
1327 void LayerTreeHost::RemoveFromElementMap(Layer* layer) {
1328 if (!layer->element_id())
1329 return;
1330
1331 element_layers_map_.erase(layer->element_id());
1332 }
1333
1334 bool LayerTreeHost::IsElementInList(ElementId element_id,
1335 ElementListType list_type) const {
1336 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id);
1337 }
1338
1339 void LayerTreeHost::SetMutatorsNeedCommit() {
1340 SetNeedsCommit();
1341 }
1342
1343 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() {
1344 property_trees_.needs_rebuild = true;
1345 }
1346
1347 void LayerTreeHost::SetElementFilterMutated(ElementId element_id,
1348 ElementListType list_type,
1349 const FilterOperations& filters) {
1350 Layer* layer = LayerByElementId(element_id);
1351 DCHECK(layer);
1352 layer->OnFilterAnimated(filters);
1353 }
1354
1355 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id,
1356 ElementListType list_type,
1357 float opacity) {
1358 Layer* layer = LayerByElementId(element_id);
1359 DCHECK(layer);
1360 layer->OnOpacityAnimated(opacity);
1361 }
1362
1363 void LayerTreeHost::SetElementTransformMutated(
1364 ElementId element_id,
1365 ElementListType list_type,
1366 const gfx::Transform& transform) {
1367 Layer* layer = LayerByElementId(element_id);
1368 DCHECK(layer);
1369 layer->OnTransformAnimated(transform);
1370 }
1371
1372 void LayerTreeHost::SetElementScrollOffsetMutated(
1373 ElementId element_id,
1374 ElementListType list_type,
1375 const gfx::ScrollOffset& scroll_offset) {
1376 Layer* layer = LayerByElementId(element_id);
1377 DCHECK(layer);
1378 layer->OnScrollOffsetAnimated(scroll_offset);
1379 }
1380
1381 void LayerTreeHost::ElementTransformIsAnimatingChanged(
1382 ElementId element_id,
1383 ElementListType list_type,
1384 AnimationChangeType change_type,
1385 bool is_animating) {
1386 Layer* layer = LayerByElementId(element_id);
1387 if (layer) {
1388 switch (change_type) {
1389 case AnimationChangeType::POTENTIAL:
1390 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1391 break;
1392 case AnimationChangeType::RUNNING:
1393 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
1394 break;
1395 case AnimationChangeType::BOTH:
1396 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1397 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
1398 break;
1399 }
1400 }
1401 }
1402
1403 void LayerTreeHost::ElementOpacityIsAnimatingChanged(
1404 ElementId element_id,
1405 ElementListType list_type,
1406 AnimationChangeType change_type,
1407 bool is_animating) {
1408 Layer* layer = LayerByElementId(element_id);
1409 if (layer) {
1410 switch (change_type) {
1411 case AnimationChangeType::POTENTIAL:
1412 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
1413 break;
1414 case AnimationChangeType::RUNNING:
1415 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
1416 break;
1417 case AnimationChangeType::BOTH:
1418 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
1419 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
1420 break;
1421 }
1422 }
1423 }
1424
1425 void LayerTreeHost::ElementFilterIsAnimatingChanged(
1426 ElementId element_id,
1427 ElementListType list_type,
1428 AnimationChangeType change_type,
1429 bool is_animating) {
1430 Layer* layer = LayerByElementId(element_id);
1431 if (layer) {
1432 switch (change_type) {
1433 case AnimationChangeType::POTENTIAL:
1434 layer->OnFilterIsPotentiallyAnimatingChanged(is_animating);
1435 break;
1436 case AnimationChangeType::RUNNING:
1437 layer->OnFilterIsCurrentlyAnimatingChanged(is_animating);
1438 break;
1439 case AnimationChangeType::BOTH:
1440 layer->OnFilterIsPotentiallyAnimatingChanged(is_animating);
1441 layer->OnFilterIsCurrentlyAnimatingChanged(is_animating);
1442 break;
1443 }
1444 }
1445 }
1446
1447 gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation(
1448 ElementId element_id) const {
1449 Layer* layer = LayerByElementId(element_id);
1450 DCHECK(layer);
1451 return layer->ScrollOffsetForAnimation();
1452 }
1453
1454 bool LayerTreeHost::IsSingleThreaded() const { 1295 bool LayerTreeHost::IsSingleThreaded() const {
1455 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED || 1296 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
1456 !task_runner_provider_->HasImplThread()); 1297 !task_runner_provider_->HasImplThread());
1457 return compositor_mode_ == CompositorMode::SINGLE_THREADED; 1298 return compositor_mode_ == CompositorMode::SINGLE_THREADED;
1458 } 1299 }
1459 1300
1460 bool LayerTreeHost::IsThreaded() const { 1301 bool LayerTreeHost::IsThreaded() const {
1461 DCHECK(compositor_mode_ != CompositorMode::THREADED || 1302 DCHECK(compositor_mode_ != CompositorMode::THREADED ||
1462 task_runner_provider_->HasImplThread()); 1303 task_runner_provider_->HasImplThread());
1463 return compositor_mode_ == CompositorMode::THREADED; 1304 return compositor_mode_ == CompositorMode::THREADED;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 proto->set_needs_full_tree_sync(needs_full_tree_sync_); 1346 proto->set_needs_full_tree_sync(needs_full_tree_sync_);
1506 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_); 1347 proto->set_needs_meta_info_recomputation(needs_meta_info_recomputation_);
1507 proto->set_source_frame_number(source_frame_number_); 1348 proto->set_source_frame_number(source_frame_number_);
1508 1349
1509 LayerProtoConverter::SerializeLayerHierarchy(root_layer_, 1350 LayerProtoConverter::SerializeLayerHierarchy(root_layer_,
1510 proto->mutable_root_layer()); 1351 proto->mutable_root_layer());
1511 1352
1512 // Serialize the LayerTree before serializing the properties. During layer 1353 // Serialize the LayerTree before serializing the properties. During layer
1513 // property serialization, we clear the list |layer_that_should_properties_| 1354 // property serialization, we clear the list |layer_that_should_properties_|
1514 // from the LayerTree. 1355 // from the LayerTree.
1515 layer_tree_.ToProtobuf(proto->mutable_layer_tree()); 1356 layer_tree_->ToProtobuf(proto->mutable_layer_tree());
1516 1357
1517 LayerProtoConverter::SerializeLayerProperties(this, 1358 LayerProtoConverter::SerializeLayerProperties(this,
1518 proto->mutable_layer_updates()); 1359 proto->mutable_layer_updates());
1519 1360
1520 std::vector<PictureData> pictures = 1361 std::vector<PictureData> pictures =
1521 engine_picture_cache_->CalculateCacheUpdateAndFlush(); 1362 engine_picture_cache_->CalculateCacheUpdateAndFlush();
1522 proto::PictureDataVectorToSkPicturesProto(pictures, 1363 proto::PictureDataVectorToSkPicturesProto(pictures,
1523 proto->mutable_pictures()); 1364 proto->mutable_pictures());
1524 1365
1525 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID); 1366 proto->set_hud_layer_id(hud_layer_ ? hud_layer_->id() : Layer::INVALID_ID);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 source_frame_number_ = proto.source_frame_number(); 1424 source_frame_number_ = proto.source_frame_number();
1584 1425
1585 // Layer hierarchy. 1426 // Layer hierarchy.
1586 scoped_refptr<Layer> new_root_layer = 1427 scoped_refptr<Layer> new_root_layer =
1587 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_, 1428 LayerProtoConverter::DeserializeLayerHierarchy(root_layer_,
1588 proto.root_layer(), this); 1429 proto.root_layer(), this);
1589 if (root_layer_ != new_root_layer) { 1430 if (root_layer_ != new_root_layer) {
1590 root_layer_ = new_root_layer; 1431 root_layer_ = new_root_layer;
1591 } 1432 }
1592 1433
1593 layer_tree_.FromProtobuf(proto.layer_tree()); 1434 layer_tree_->FromProtobuf(proto.layer_tree());
1594 1435
1595 // Ensure ClientPictureCache contains all the necessary SkPictures before 1436 // Ensure ClientPictureCache contains all the necessary SkPictures before
1596 // deserializing the properties. 1437 // deserializing the properties.
1597 proto::SkPictures proto_pictures = proto.pictures(); 1438 proto::SkPictures proto_pictures = proto.pictures();
1598 std::vector<PictureData> pictures = 1439 std::vector<PictureData> pictures =
1599 SkPicturesProtoToPictureDataVector(proto_pictures); 1440 SkPicturesProtoToPictureDataVector(proto_pictures);
1600 client_picture_cache_->ApplyCacheUpdate(pictures); 1441 client_picture_cache_->ApplyCacheUpdate(pictures);
1601 1442
1602 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(), 1443 LayerProtoConverter::DeserializeLayerProperties(root_layer_.get(),
1603 proto.layer_updates()); 1444 proto.layer_updates());
(...skipping 26 matching lines...) Expand all
1630 EventListenerClass::kTouchStartOrMove)] = 1471 EventListenerClass::kTouchStartOrMove)] =
1631 static_cast<EventListenerProperties>( 1472 static_cast<EventListenerProperties>(
1632 proto.touch_start_or_move_event_listener_properties()); 1473 proto.touch_start_or_move_event_listener_properties());
1633 event_listener_properties_[static_cast<size_t>( 1474 event_listener_properties_[static_cast<size_t>(
1634 EventListenerClass::kTouchEndOrCancel)] = 1475 EventListenerClass::kTouchEndOrCancel)] =
1635 static_cast<EventListenerProperties>( 1476 static_cast<EventListenerProperties>(
1636 proto.touch_end_or_cancel_event_listener_properties()); 1477 proto.touch_end_or_cancel_event_listener_properties());
1637 id_ = proto.id(); 1478 id_ = proto.id();
1638 next_commit_forces_redraw_ = proto.next_commit_forces_redraw(); 1479 next_commit_forces_redraw_ = proto.next_commit_forces_redraw();
1639 1480
1640 hud_layer_ = static_cast<HeadsUpDisplayLayer*>( 1481 hud_layer_ = static_cast<HeadsUpDisplayLayer*>(UpdateAndGetLayer(
1641 UpdateAndGetLayer(hud_layer_.get(), proto.hud_layer_id(), &layer_tree_)); 1482 hud_layer_.get(), proto.hud_layer_id(), layer_tree_.get()));
1642 overscroll_elasticity_layer_ = 1483 overscroll_elasticity_layer_ = UpdateAndGetLayer(
1643 UpdateAndGetLayer(overscroll_elasticity_layer_.get(), 1484 overscroll_elasticity_layer_.get(),
1644 proto.overscroll_elasticity_layer_id(), &layer_tree_); 1485 proto.overscroll_elasticity_layer_id(), layer_tree_.get());
1645 page_scale_layer_ = UpdateAndGetLayer( 1486 page_scale_layer_ = UpdateAndGetLayer(
1646 page_scale_layer_.get(), proto.page_scale_layer_id(), &layer_tree_); 1487 page_scale_layer_.get(), proto.page_scale_layer_id(), layer_tree_.get());
1647 inner_viewport_scroll_layer_ = 1488 inner_viewport_scroll_layer_ = UpdateAndGetLayer(
1648 UpdateAndGetLayer(inner_viewport_scroll_layer_.get(), 1489 inner_viewport_scroll_layer_.get(),
1649 proto.inner_viewport_scroll_layer_id(), &layer_tree_); 1490 proto.inner_viewport_scroll_layer_id(), layer_tree_.get());
1650 outer_viewport_scroll_layer_ = 1491 outer_viewport_scroll_layer_ = UpdateAndGetLayer(
1651 UpdateAndGetLayer(outer_viewport_scroll_layer_.get(), 1492 outer_viewport_scroll_layer_.get(),
1652 proto.outer_viewport_scroll_layer_id(), &layer_tree_); 1493 proto.outer_viewport_scroll_layer_id(), layer_tree_.get());
1653 1494
1654 LayerSelectionFromProtobuf(&selection_, proto.selection()); 1495 LayerSelectionFromProtobuf(&selection_, proto.selection());
1655 1496
1656 // It is required to create new PropertyTrees before deserializing it. 1497 // It is required to create new PropertyTrees before deserializing it.
1657 property_trees_ = PropertyTrees(); 1498 property_trees_ = PropertyTrees();
1658 property_trees_.FromProtobuf(proto.property_trees()); 1499 property_trees_.FromProtobuf(proto.property_trees());
1659 1500
1660 // Forcefully override the sequence number of all layers in the tree to have 1501 // Forcefully override the sequence number of all layers in the tree to have
1661 // a valid sequence number. Changing the sequence number for a layer does not 1502 // a valid sequence number. Changing the sequence number for a layer does not
1662 // need a commit, so the value will become out of date for layers that are not 1503 // need a commit, so the value will become out of date for layers that are not
1663 // updated for other reasons. All layers that at this point are part of the 1504 // updated for other reasons. All layers that at this point are part of the
1664 // layer tree are valid, so it is OK that they have a valid sequence number. 1505 // layer tree are valid, so it is OK that they have a valid sequence number.
1665 int seq_num = property_trees_.sequence_number; 1506 int seq_num = property_trees_.sequence_number;
1666 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { 1507 LayerTreeHostCommon::CallFunctionForEveryLayer(
1667 layer->set_property_tree_sequence_number(seq_num); 1508 layer_tree_.get(), [seq_num](Layer* layer) {
1668 }); 1509 layer->set_property_tree_sequence_number(seq_num);
1510 });
1669 1511
1670 surface_client_id_ = proto.surface_client_id(); 1512 surface_client_id_ = proto.surface_client_id();
1671 next_surface_sequence_ = proto.next_surface_sequence(); 1513 next_surface_sequence_ = proto.next_surface_sequence();
1672 } 1514 }
1673
1674 AnimationHost* LayerTreeHost::animation_host() const {
1675 return layer_tree_.animation_host();
1676 }
1677
1678 } // namespace cc 1515 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698