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

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: Rebase on another LTH refactor CL. 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
« no previous file with comments | « cc/trees/layer_tree_host.h ('k') | cc/trees/layer_tree_host_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 next_commit_forces_redraw_(false), 225 next_commit_forces_redraw_(false),
226 shared_bitmap_manager_(params->shared_bitmap_manager), 226 shared_bitmap_manager_(params->shared_bitmap_manager),
227 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager), 227 gpu_memory_buffer_manager_(params->gpu_memory_buffer_manager),
228 task_graph_runner_(params->task_graph_runner), 228 task_graph_runner_(params->task_graph_runner),
229 image_serialization_processor_(params->image_serialization_processor), 229 image_serialization_processor_(params->image_serialization_processor),
230 surface_client_id_(0u), 230 surface_client_id_(0u),
231 next_surface_sequence_(1u) { 231 next_surface_sequence_(1u) {
232 DCHECK(task_graph_runner_); 232 DCHECK(task_graph_runner_);
233 DCHECK(layer_tree_); 233 DCHECK(layer_tree_);
234 234
235 layer_tree_->animation_host()->SetMutatorHostClient(this);
236
237 rendering_stats_instrumentation_->set_record_rendering_stats( 235 rendering_stats_instrumentation_->set_record_rendering_stats(
238 debug_state_.RecordRenderingStats()); 236 debug_state_.RecordRenderingStats());
239 } 237 }
240 238
241 void LayerTreeHost::InitializeThreaded( 239 void LayerTreeHost::InitializeThreaded(
242 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 240 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
243 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner, 241 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner,
244 std::unique_ptr<BeginFrameSource> external_begin_frame_source) { 242 std::unique_ptr<BeginFrameSource> external_begin_frame_source) {
245 task_runner_provider_ = 243 task_runner_provider_ =
246 TaskRunnerProvider::Create(main_task_runner, impl_task_runner); 244 TaskRunnerProvider::Create(main_task_runner, impl_task_runner);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { 398 void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) {
401 DCHECK(!IsRemoteServer()); 399 DCHECK(!IsRemoteServer());
402 DCHECK(task_runner_provider_->IsImplThread()); 400 DCHECK(task_runner_provider_->IsImplThread());
403 401
404 bool is_new_trace; 402 bool is_new_trace;
405 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace); 403 TRACE_EVENT_IS_NEW_TRACE(&is_new_trace);
406 if (is_new_trace && 404 if (is_new_trace &&
407 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() && 405 frame_viewer_instrumentation::IsTracingLayerTreeSnapshots() &&
408 layer_tree_->root_layer()) { 406 layer_tree_->root_layer()) {
409 LayerTreeHostCommon::CallFunctionForEveryLayer( 407 LayerTreeHostCommon::CallFunctionForEveryLayer(
410 this, [](Layer* layer) { layer->DidBeginTracing(); }); 408 layer_tree_.get(), [](Layer* layer) { layer->DidBeginTracing(); });
411 } 409 }
412 410
413 LayerTreeImpl* sync_tree = host_impl->sync_tree(); 411 LayerTreeImpl* sync_tree = host_impl->sync_tree();
414 412
415 if (next_commit_forces_redraw_) { 413 if (next_commit_forces_redraw_) {
416 sync_tree->ForceRedrawNextActivation(); 414 sync_tree->ForceRedrawNextActivation();
417 next_commit_forces_redraw_ = false; 415 next_commit_forces_redraw_ = false;
418 } 416 }
419 417
420 sync_tree->set_source_frame_number(source_frame_number()); 418 sync_tree->set_source_frame_number(source_frame_number());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 return; 560 return;
563 561
564 output_surface_lost_ = true; 562 output_surface_lost_ = true;
565 SetNeedsCommit(); 563 SetNeedsCommit();
566 } 564 }
567 565
568 void LayerTreeHost::SetDeferCommits(bool defer_commits) { 566 void LayerTreeHost::SetDeferCommits(bool defer_commits) {
569 proxy_->SetDeferCommits(defer_commits); 567 proxy_->SetDeferCommits(defer_commits);
570 } 568 }
571 569
572 void LayerTreeHost::SetNeedsDisplayOnAllLayers() {
573 for (auto* layer : *this)
574 layer->SetNeedsDisplay();
575 }
576
577 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const { 570 const RendererCapabilities& LayerTreeHost::GetRendererCapabilities() const {
578 return proxy_->GetRendererCapabilities(); 571 return proxy_->GetRendererCapabilities();
579 } 572 }
580 573
581 void LayerTreeHost::SetNeedsAnimate() { 574 void LayerTreeHost::SetNeedsAnimate() {
582 proxy_->SetNeedsAnimate(); 575 proxy_->SetNeedsAnimate();
583 NotifySwapPromiseMonitorsOfSetNeedsCommit(); 576 NotifySwapPromiseMonitorsOfSetNeedsCommit();
584 } 577 }
585 578
586 void LayerTreeHost::SetNeedsUpdateLayers() { 579 void LayerTreeHost::SetNeedsUpdateLayers() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 bool LayerTreeHost::UpdateLayers() { 698 bool LayerTreeHost::UpdateLayers() {
706 DCHECK(!output_surface_lost_); 699 DCHECK(!output_surface_lost_);
707 if (!layer_tree_->root_layer()) 700 if (!layer_tree_->root_layer())
708 return false; 701 return false;
709 DCHECK(!layer_tree_->root_layer()->parent()); 702 DCHECK(!layer_tree_->root_layer()->parent());
710 bool result = DoUpdateLayers(layer_tree_->root_layer()); 703 bool result = DoUpdateLayers(layer_tree_->root_layer());
711 micro_benchmark_controller_.DidUpdateLayers(); 704 micro_benchmark_controller_.DidUpdateLayers();
712 return result || next_commit_forces_redraw_; 705 return result || next_commit_forces_redraw_;
713 } 706 }
714 707
715 LayerListIterator<Layer> LayerTreeHost::begin() const {
716 return LayerListIterator<Layer>(layer_tree_->root_layer());
717 }
718
719 LayerListIterator<Layer> LayerTreeHost::end() const {
720 return LayerListIterator<Layer>(nullptr);
721 }
722
723 LayerListReverseIterator<Layer> LayerTreeHost::rbegin() {
724 return LayerListReverseIterator<Layer>(layer_tree_->root_layer());
725 }
726
727 LayerListReverseIterator<Layer> LayerTreeHost::rend() {
728 return LayerListReverseIterator<Layer>(nullptr);
729 }
730
731 void LayerTreeHost::DidCompletePageScaleAnimation() { 708 void LayerTreeHost::DidCompletePageScaleAnimation() {
732 did_complete_scale_animation_ = true; 709 did_complete_scale_animation_ = true;
733 } 710 }
734 711
735 void LayerTreeHost::RecordGpuRasterizationHistogram() { 712 void LayerTreeHost::RecordGpuRasterizationHistogram() {
736 // Gpu rasterization is only supported for Renderer compositors. 713 // Gpu rasterization is only supported for Renderer compositors.
737 // Checking for IsSingleThreaded() to exclude Browser compositors. 714 // Checking for IsSingleThreaded() to exclude Browser compositors.
738 if (gpu_rasterization_histogram_recorded_ || IsSingleThreaded()) 715 if (gpu_rasterization_histogram_recorded_ || IsSingleThreaded())
739 return; 716 return;
740 717
(...skipping 23 matching lines...) Expand all
764 PropertyTreeBuilder::BuildPropertyTrees( 741 PropertyTreeBuilder::BuildPropertyTrees(
765 layer_tree_->root_layer(), layer_tree_->page_scale_layer(), 742 layer_tree_->root_layer(), layer_tree_->page_scale_layer(),
766 layer_tree_->inner_viewport_scroll_layer(), 743 layer_tree_->inner_viewport_scroll_layer(),
767 layer_tree_->outer_viewport_scroll_layer(), 744 layer_tree_->outer_viewport_scroll_layer(),
768 layer_tree_->overscroll_elasticity_layer(), elastic_overscroll_, 745 layer_tree_->overscroll_elasticity_layer(), elastic_overscroll_,
769 layer_tree_->page_scale_factor(), layer_tree_->device_scale_factor(), 746 layer_tree_->page_scale_factor(), layer_tree_->device_scale_factor(),
770 gfx::Rect(layer_tree_->device_viewport_size()), identity_transform, 747 gfx::Rect(layer_tree_->device_viewport_size()), identity_transform,
771 layer_tree_->property_trees()); 748 layer_tree_->property_trees());
772 } 749 }
773 750
774 static void SetElementIdForTesting(Layer* layer) {
775 layer->SetElementId(LayerIdToElementIdForTesting(layer->id()));
776 }
777
778 void LayerTreeHost::SetElementIdsForTesting() {
779 LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting);
780 }
781
782 bool LayerTreeHost::UsingSharedMemoryResources() { 751 bool LayerTreeHost::UsingSharedMemoryResources() {
783 return GetRendererCapabilities().using_shared_memory_resources; 752 return GetRendererCapabilities().using_shared_memory_resources;
784 } 753 }
785 754
786 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { 755 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) {
787 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number", 756 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number",
788 source_frame_number()); 757 source_frame_number());
789 758
790 layer_tree_->UpdateHudLayer(debug_state_.ShowHudInfo()); 759 layer_tree_->UpdateHudLayer(debug_state_.ShowHudInfo());
791 UpdateHudLayer(); 760 UpdateHudLayer();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 property_trees->AsTracedValue()); 798 property_trees->AsTracedValue());
830 } else { 799 } else {
831 TRACE_EVENT_INSTANT1("cc", 800 TRACE_EVENT_INSTANT1("cc",
832 "LayerTreeHost::UpdateLayers_ReceivedPropertyTrees", 801 "LayerTreeHost::UpdateLayers_ReceivedPropertyTrees",
833 TRACE_EVENT_SCOPE_THREAD, "property_trees", 802 TRACE_EVENT_SCOPE_THREAD, "property_trees",
834 property_trees->AsTracedValue()); 803 property_trees->AsTracedValue());
835 } 804 }
836 draw_property_utils::UpdatePropertyTrees(property_trees, 805 draw_property_utils::UpdatePropertyTrees(property_trees,
837 can_render_to_separate_surface); 806 can_render_to_separate_surface);
838 draw_property_utils::FindLayersThatNeedUpdates( 807 draw_property_utils::FindLayersThatNeedUpdates(
839 this, property_trees->transform_tree, property_trees->effect_tree, 808 layer_tree_.get(), property_trees->transform_tree,
840 &update_layer_list); 809 property_trees->effect_tree, &update_layer_list);
841 } 810 }
842 811
843 for (const auto& layer : update_layer_list) 812 for (const auto& layer : update_layer_list)
844 layer->SavePaintProperties(); 813 layer->SavePaintProperties();
845 814
846 bool content_is_suitable_for_gpu = true; 815 bool content_is_suitable_for_gpu = true;
847 bool did_paint_content = layer_tree_->UpdateLayers( 816 bool did_paint_content = layer_tree_->UpdateLayers(
848 update_layer_list, &content_is_suitable_for_gpu); 817 update_layer_list, &content_is_suitable_for_gpu);
849 818
850 if (content_is_suitable_for_gpu) { 819 if (content_is_suitable_for_gpu) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 TRACE_EVENT_WITH_FLOW1("input,benchmark", 864 TRACE_EVENT_WITH_FLOW1("input,benchmark",
896 "LatencyInfo.Flow", 865 "LatencyInfo.Flow",
897 TRACE_ID_DONT_MANGLE(swap_promise->TraceId()), 866 TRACE_ID_DONT_MANGLE(swap_promise->TraceId()),
898 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, 867 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
899 "step", "Main thread scroll update"); 868 "step", "Main thread scroll update");
900 QueueSwapPromise(std::move(swap_promise)); 869 QueueSwapPromise(std::move(swap_promise));
901 } 870 }
902 871
903 if (layer_tree_->root_layer()) { 872 if (layer_tree_->root_layer()) {
904 for (size_t i = 0; i < info->scrolls.size(); ++i) { 873 for (size_t i = 0; i < info->scrolls.size(); ++i) {
905 Layer* layer = LayerById(info->scrolls[i].layer_id); 874 Layer* layer = layer_tree_->LayerById(info->scrolls[i].layer_id);
906 if (!layer) 875 if (!layer)
907 continue; 876 continue;
908 layer->SetScrollOffsetFromImplSide(gfx::ScrollOffsetWithDelta( 877 layer->SetScrollOffsetFromImplSide(gfx::ScrollOffsetWithDelta(
909 layer->scroll_offset(), info->scrolls[i].scroll_delta)); 878 layer->scroll_offset(), info->scrolls[i].scroll_delta));
910 SetNeedsUpdateLayers(); 879 SetNeedsUpdateLayers();
911 } 880 }
912 } 881 }
913 882
914 // This needs to happen after scroll deltas have been sent to prevent top 883 // This needs to happen after scroll deltas have been sent to prevent top
915 // controls from clamping the layout viewport both on the compositor and 884 // controls from clamping the layout viewport both on the compositor and
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 1016
1048 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() { 1017 SurfaceSequence LayerTreeHost::CreateSurfaceSequence() {
1049 return SurfaceSequence(surface_client_id_, next_surface_sequence_++); 1018 return SurfaceSequence(surface_client_id_, next_surface_sequence_++);
1050 } 1019 }
1051 1020
1052 void LayerTreeHost::SetLayerTreeMutator( 1021 void LayerTreeHost::SetLayerTreeMutator(
1053 std::unique_ptr<LayerTreeMutator> mutator) { 1022 std::unique_ptr<LayerTreeMutator> mutator) {
1054 proxy_->SetMutator(std::move(mutator)); 1023 proxy_->SetMutator(std::move(mutator));
1055 } 1024 }
1056 1025
1057 Layer* LayerTreeHost::LayerById(int id) const {
1058 return layer_tree_->LayerById(id);
1059 }
1060
1061 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const {
1062 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id);
1063 return iter != element_layers_map_.end() ? iter->second : nullptr;
1064 }
1065
1066 void LayerTreeHost::AddToElementMap(Layer* layer) {
1067 if (!layer->element_id())
1068 return;
1069
1070 element_layers_map_[layer->element_id()] = layer;
1071 }
1072
1073 void LayerTreeHost::RemoveFromElementMap(Layer* layer) {
1074 if (!layer->element_id())
1075 return;
1076
1077 element_layers_map_.erase(layer->element_id());
1078 }
1079
1080 bool LayerTreeHost::IsElementInList(ElementId element_id,
1081 ElementListType list_type) const {
1082 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id);
1083 }
1084
1085 void LayerTreeHost::SetMutatorsNeedCommit() {
1086 SetNeedsCommit();
1087 }
1088
1089 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() {
1090 layer_tree_->property_trees()->needs_rebuild = true;
1091 }
1092
1093 void LayerTreeHost::SetElementFilterMutated(ElementId element_id,
1094 ElementListType list_type,
1095 const FilterOperations& filters) {
1096 Layer* layer = LayerByElementId(element_id);
1097 DCHECK(layer);
1098 layer->OnFilterAnimated(filters);
1099 }
1100
1101 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id,
1102 ElementListType list_type,
1103 float opacity) {
1104 Layer* layer = LayerByElementId(element_id);
1105 DCHECK(layer);
1106 layer->OnOpacityAnimated(opacity);
1107 }
1108
1109 void LayerTreeHost::SetElementTransformMutated(
1110 ElementId element_id,
1111 ElementListType list_type,
1112 const gfx::Transform& transform) {
1113 Layer* layer = LayerByElementId(element_id);
1114 DCHECK(layer);
1115 layer->OnTransformAnimated(transform);
1116 }
1117
1118 void LayerTreeHost::SetElementScrollOffsetMutated(
1119 ElementId element_id,
1120 ElementListType list_type,
1121 const gfx::ScrollOffset& scroll_offset) {
1122 Layer* layer = LayerByElementId(element_id);
1123 DCHECK(layer);
1124 layer->OnScrollOffsetAnimated(scroll_offset);
1125 }
1126
1127 void LayerTreeHost::ElementTransformIsAnimatingChanged(
1128 ElementId element_id,
1129 ElementListType list_type,
1130 AnimationChangeType change_type,
1131 bool is_animating) {
1132 Layer* layer = LayerByElementId(element_id);
1133 if (layer) {
1134 switch (change_type) {
1135 case AnimationChangeType::POTENTIAL:
1136 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1137 break;
1138 case AnimationChangeType::RUNNING:
1139 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
1140 break;
1141 case AnimationChangeType::BOTH:
1142 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1143 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
1144 break;
1145 }
1146 }
1147 }
1148
1149 void LayerTreeHost::ElementOpacityIsAnimatingChanged(
1150 ElementId element_id,
1151 ElementListType list_type,
1152 AnimationChangeType change_type,
1153 bool is_animating) {
1154 Layer* layer = LayerByElementId(element_id);
1155 if (layer) {
1156 switch (change_type) {
1157 case AnimationChangeType::POTENTIAL:
1158 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
1159 break;
1160 case AnimationChangeType::RUNNING:
1161 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
1162 break;
1163 case AnimationChangeType::BOTH:
1164 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
1165 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
1166 break;
1167 }
1168 }
1169 }
1170
1171 void LayerTreeHost::ElementFilterIsAnimatingChanged(
1172 ElementId element_id,
1173 ElementListType list_type,
1174 AnimationChangeType change_type,
1175 bool is_animating) {
1176 Layer* layer = LayerByElementId(element_id);
1177 if (layer) {
1178 switch (change_type) {
1179 case AnimationChangeType::POTENTIAL:
1180 layer->OnFilterIsPotentiallyAnimatingChanged(is_animating);
1181 break;
1182 case AnimationChangeType::RUNNING:
1183 layer->OnFilterIsCurrentlyAnimatingChanged(is_animating);
1184 break;
1185 case AnimationChangeType::BOTH:
1186 layer->OnFilterIsPotentiallyAnimatingChanged(is_animating);
1187 layer->OnFilterIsCurrentlyAnimatingChanged(is_animating);
1188 break;
1189 }
1190 }
1191 }
1192
1193 gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation(
1194 ElementId element_id) const {
1195 Layer* layer = LayerByElementId(element_id);
1196 DCHECK(layer);
1197 return layer->ScrollOffsetForAnimation();
1198 }
1199
1200 bool LayerTreeHost::IsSingleThreaded() const { 1026 bool LayerTreeHost::IsSingleThreaded() const {
1201 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED || 1027 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
1202 !task_runner_provider_->HasImplThread()); 1028 !task_runner_provider_->HasImplThread());
1203 return compositor_mode_ == CompositorMode::SINGLE_THREADED; 1029 return compositor_mode_ == CompositorMode::SINGLE_THREADED;
1204 } 1030 }
1205 1031
1206 bool LayerTreeHost::IsThreaded() const { 1032 bool LayerTreeHost::IsThreaded() const {
1207 DCHECK(compositor_mode_ != CompositorMode::THREADED || 1033 DCHECK(compositor_mode_ != CompositorMode::THREADED ||
1208 task_runner_provider_->HasImplThread()); 1034 task_runner_provider_->HasImplThread());
1209 return compositor_mode_ == CompositorMode::THREADED; 1035 return compositor_mode_ == CompositorMode::THREADED;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 1134
1309 surface_client_id_ = proto.surface_client_id(); 1135 surface_client_id_ = proto.surface_client_id();
1310 next_surface_sequence_ = proto.next_surface_sequence(); 1136 next_surface_sequence_ = proto.next_surface_sequence();
1311 } 1137 }
1312 1138
1313 AnimationHost* LayerTreeHost::animation_host() const { 1139 AnimationHost* LayerTreeHost::animation_host() const {
1314 return layer_tree_->animation_host(); 1140 return layer_tree_->animation_host();
1315 } 1141 }
1316 1142
1317 } // namespace cc 1143 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host.h ('k') | cc/trees/layer_tree_host_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698