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

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

Issue 1921503005: cc: Move main thread hierarchy dependencies into PropertyTreeBuilder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 7 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/property_tree_builder.h ('k') | content/renderer/gpu/gpu_benchmarking_extension.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/property_tree_builder.h" 5 #include "cc/trees/property_tree_builder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 }; 73 };
74 74
75 static LayerPositionConstraint PositionConstraint(Layer* layer) { 75 static LayerPositionConstraint PositionConstraint(Layer* layer) {
76 return layer->position_constraint(); 76 return layer->position_constraint();
77 } 77 }
78 78
79 static LayerPositionConstraint PositionConstraint(LayerImpl* layer) { 79 static LayerPositionConstraint PositionConstraint(LayerImpl* layer) {
80 return layer->test_properties()->position_constraint; 80 return layer->test_properties()->position_constraint;
81 } 81 }
82 82
83 struct PreCalculateMetaInformationRecursiveData {
84 size_t num_unclipped_descendants;
85 int num_layer_or_descendants_with_copy_request;
86 int num_layer_or_descendants_with_touch_handler;
87 int num_descendants_that_draw_content;
88
89 PreCalculateMetaInformationRecursiveData()
90 : num_unclipped_descendants(0),
91 num_layer_or_descendants_with_copy_request(0),
92 num_layer_or_descendants_with_touch_handler(0),
93 num_descendants_that_draw_content(0) {}
94
95 void Merge(const PreCalculateMetaInformationRecursiveData& data) {
96 num_layer_or_descendants_with_copy_request +=
97 data.num_layer_or_descendants_with_copy_request;
98 num_layer_or_descendants_with_touch_handler +=
99 data.num_layer_or_descendants_with_touch_handler;
100 num_unclipped_descendants += data.num_unclipped_descendants;
101 num_descendants_that_draw_content += data.num_descendants_that_draw_content;
102 }
103 };
104
105 static inline bool IsRootLayer(const Layer* layer) {
106 return !layer->parent();
107 }
108
109 static bool HasInvertibleOrAnimatedTransform(Layer* layer) {
110 return layer->transform_is_invertible() ||
111 layer->HasPotentiallyRunningTransformAnimation();
112 }
113
114 static bool HasInvertibleOrAnimatedTransformForTesting(LayerImpl* layer) {
115 return layer->transform().IsInvertible() ||
116 layer->HasPotentiallyRunningTransformAnimation();
117 }
118
119 static bool IsMetaInformationRecomputationNeeded(Layer* layer) {
120 return layer->layer_tree_host()->needs_meta_info_recomputation();
121 }
122
123 // Recursively walks the layer tree(if needed) to compute any information
124 // that is needed before doing the main recursion.
125 static void PreCalculateMetaInformationInternal(
126 Layer* layer,
127 PreCalculateMetaInformationRecursiveData* recursive_data) {
128 if (!IsMetaInformationRecomputationNeeded(layer)) {
129 DCHECK(IsRootLayer(layer));
130 return;
131 }
132
133 if (layer->clip_parent())
134 recursive_data->num_unclipped_descendants++;
135
136 if (!HasInvertibleOrAnimatedTransform(layer)) {
137 // Layers with singular transforms should not be drawn, the whole subtree
138 // can be skipped.
139 return;
140 }
141
142 for (size_t i = 0; i < layer->children().size(); ++i) {
143 Layer* child_layer = layer->child_at(i);
144
145 PreCalculateMetaInformationRecursiveData data_for_child;
146 PreCalculateMetaInformationInternal(child_layer, &data_for_child);
147 recursive_data->Merge(data_for_child);
148 }
149
150 if (layer->clip_children()) {
151 size_t num_clip_children = layer->clip_children()->size();
152 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children);
153 recursive_data->num_unclipped_descendants -= num_clip_children;
154 }
155
156 if (layer->HasCopyRequest())
157 recursive_data->num_layer_or_descendants_with_copy_request++;
158
159 if (!layer->touch_event_handler_region().IsEmpty())
160 recursive_data->num_layer_or_descendants_with_touch_handler++;
161
162 layer->set_num_unclipped_descendants(
163 recursive_data->num_unclipped_descendants);
164
165 if (IsRootLayer(layer))
166 layer->layer_tree_host()->SetNeedsMetaInfoRecomputation(false);
167 }
168
169 static void PreCalculateMetaInformationInternalForTesting(
170 LayerImpl* layer,
171 PreCalculateMetaInformationRecursiveData* recursive_data) {
172 if (layer->test_properties()->clip_parent)
173 recursive_data->num_unclipped_descendants++;
174
175 if (!HasInvertibleOrAnimatedTransformForTesting(layer)) {
176 // Layers with singular transforms should not be drawn, the whole subtree
177 // can be skipped.
178 return;
179 }
180
181 for (size_t i = 0; i < layer->children().size(); ++i) {
182 LayerImpl* child_layer = layer->child_at(i);
183
184 PreCalculateMetaInformationRecursiveData data_for_child;
185 PreCalculateMetaInformationInternalForTesting(child_layer, &data_for_child);
186 recursive_data->Merge(data_for_child);
187 }
188
189 if (layer->test_properties()->clip_children) {
190 size_t num_clip_children = layer->test_properties()->clip_children->size();
191 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children);
192 recursive_data->num_unclipped_descendants -= num_clip_children;
193 }
194
195 if (layer->HasCopyRequest())
196 recursive_data->num_layer_or_descendants_with_copy_request++;
197
198 if (!layer->touch_event_handler_region().IsEmpty())
199 recursive_data->num_layer_or_descendants_with_touch_handler++;
200
201 layer->draw_properties().num_unclipped_descendants =
202 recursive_data->num_unclipped_descendants;
203 layer->set_layer_or_descendant_has_touch_handler(
204 (recursive_data->num_layer_or_descendants_with_touch_handler != 0));
205 // TODO(enne): this should be synced from the main thread, so is only
206 // for tests constructing layers on the compositor thread.
207 layer->test_properties()->num_descendants_that_draw_content =
208 recursive_data->num_descendants_that_draw_content;
209
210 if (layer->DrawsContent())
211 recursive_data->num_descendants_that_draw_content++;
212 }
213
83 static Layer* ScrollParent(Layer* layer) { 214 static Layer* ScrollParent(Layer* layer) {
84 return layer->scroll_parent(); 215 return layer->scroll_parent();
85 } 216 }
86 217
87 static LayerImpl* ScrollParent(LayerImpl* layer) { 218 static LayerImpl* ScrollParent(LayerImpl* layer) {
88 return layer->test_properties()->scroll_parent; 219 return layer->test_properties()->scroll_parent;
89 } 220 }
90 221
91 static std::set<Layer*>* ScrollChildren(Layer* layer) { 222 static std::set<Layer*>* ScrollChildren(Layer* layer) {
92 return layer->scroll_children(); 223 return layer->scroll_children();
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 1075
945 if (data_for_children.effect_tree->Node(data_for_children.effect_tree_parent) 1076 if (data_for_children.effect_tree->Node(data_for_children.effect_tree_parent)
946 ->owner_id == layer->id()) 1077 ->owner_id == layer->id())
947 data_for_children.effect_tree->Node(data_for_children.effect_tree_parent) 1078 data_for_children.effect_tree->Node(data_for_children.effect_tree_parent)
948 ->data.num_copy_requests_in_subtree = 1079 ->data.num_copy_requests_in_subtree =
949 data_to_parent->num_copy_requests_in_subtree; 1080 data_to_parent->num_copy_requests_in_subtree;
950 } 1081 }
951 1082
952 } // namespace 1083 } // namespace
953 1084
1085 void CC_EXPORT
1086 PropertyTreeBuilder::PreCalculateMetaInformation(Layer* root_layer) {
1087 PreCalculateMetaInformationRecursiveData recursive_data;
1088 PreCalculateMetaInformationInternal(root_layer, &recursive_data);
1089 }
1090
1091 void CC_EXPORT PropertyTreeBuilder::PreCalculateMetaInformationForTesting(
1092 LayerImpl* root_layer) {
1093 PreCalculateMetaInformationRecursiveData recursive_data;
1094 PreCalculateMetaInformationInternalForTesting(root_layer, &recursive_data);
1095 }
1096
1097 Layer* PropertyTreeBuilder::FindFirstScrollableLayer(Layer* layer) {
1098 if (!layer)
1099 return nullptr;
1100
1101 if (layer->scrollable())
1102 return layer;
1103
1104 for (size_t i = 0; i < layer->children().size(); ++i) {
1105 Layer* found = FindFirstScrollableLayer(layer->children()[i].get());
1106 if (found)
1107 return found;
1108 }
1109
1110 return nullptr;
1111 }
1112
954 template <typename LayerType> 1113 template <typename LayerType>
955 void BuildPropertyTreesTopLevelInternal( 1114 void BuildPropertyTreesTopLevelInternal(
956 LayerType* root_layer, 1115 LayerType* root_layer,
957 const LayerType* page_scale_layer, 1116 const LayerType* page_scale_layer,
958 const LayerType* inner_viewport_scroll_layer, 1117 const LayerType* inner_viewport_scroll_layer,
959 const LayerType* outer_viewport_scroll_layer, 1118 const LayerType* outer_viewport_scroll_layer,
960 const LayerType* overscroll_elasticity_layer, 1119 const LayerType* overscroll_elasticity_layer,
961 const gfx::Vector2dF& elastic_overscroll, 1120 const gfx::Vector2dF& elastic_overscroll,
962 float page_scale_factor, 1121 float page_scale_factor,
963 float device_scale_factor, 1122 float device_scale_factor,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 if (SkColorGetA(color) != 255) 1266 if (SkColorGetA(color) != 255)
1108 color = SkColorSetA(color, 255); 1267 color = SkColorSetA(color, 255);
1109 BuildPropertyTreesTopLevelInternal( 1268 BuildPropertyTreesTopLevelInternal(
1110 root_layer, page_scale_layer, inner_viewport_scroll_layer, 1269 root_layer, page_scale_layer, inner_viewport_scroll_layer,
1111 outer_viewport_scroll_layer, overscroll_elasticity_layer, 1270 outer_viewport_scroll_layer, overscroll_elasticity_layer,
1112 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, 1271 elastic_overscroll, page_scale_factor, device_scale_factor, viewport,
1113 device_transform, property_trees, color); 1272 device_transform, property_trees, color);
1114 } 1273 }
1115 1274
1116 } // namespace cc 1275 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/property_tree_builder.h ('k') | content/renderer/gpu/gpu_benchmarking_extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698