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

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: Fix telemetry unittest problem 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
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 PreCalculateMetaInformationInternal(
jaydasika 2016/04/27 18:36:03 This should be a ForTesting function.
sunxd 2016/04/28 14:21:54 Done.
170 LayerImpl* layer,
171 PreCalculateMetaInformationRecursiveData* recursive_data) {
172 if (layer->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 PreCalculateMetaInformationInternal(child_layer, &data_for_child);
186 recursive_data->Merge(data_for_child);
187 }
188
189 if (layer->clip_children()) {
190 size_t num_clip_children = layer->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 template <typename LayerType> 214 template <typename LayerType>
84 static LayerType* GetTransformParent(const DataForRecursion<LayerType>& data, 215 static LayerType* GetTransformParent(const DataForRecursion<LayerType>& data,
85 LayerType* layer) { 216 LayerType* layer) {
86 return PositionConstraint(layer).is_fixed_position() 217 return PositionConstraint(layer).is_fixed_position()
87 ? data.transform_fixed_parent 218 ? data.transform_fixed_parent
88 : data.transform_tree_parent; 219 : data.transform_tree_parent;
89 } 220 }
90 221
91 template <typename LayerType> 222 template <typename LayerType>
92 static ClipNode* GetClipParent(const DataForRecursion<LayerType>& data, 223 static ClipNode* GetClipParent(const DataForRecursion<LayerType>& data,
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 1051
921 if (data_for_children.effect_tree->Node(data_for_children.effect_tree_parent) 1052 if (data_for_children.effect_tree->Node(data_for_children.effect_tree_parent)
922 ->owner_id == layer->id()) 1053 ->owner_id == layer->id())
923 data_for_children.effect_tree->Node(data_for_children.effect_tree_parent) 1054 data_for_children.effect_tree->Node(data_for_children.effect_tree_parent)
924 ->data.num_copy_requests_in_subtree = 1055 ->data.num_copy_requests_in_subtree =
925 data_to_parent->num_copy_requests_in_subtree; 1056 data_to_parent->num_copy_requests_in_subtree;
926 } 1057 }
927 1058
928 } // namespace 1059 } // namespace
929 1060
1061 void CC_EXPORT
1062 PropertyTreeBuilder::PreCalculateMetaInformation(Layer* root_layer) {
1063 PreCalculateMetaInformationRecursiveData recursive_data;
1064 PreCalculateMetaInformationInternal(root_layer, &recursive_data);
1065 }
1066
1067 void CC_EXPORT
1068 PropertyTreeBuilder::PreCalculateMetaInformation(LayerImpl* root_layer) {
jaydasika 2016/04/27 18:36:03 Should be a ForTesting function
sunxd 2016/04/28 14:21:54 Done.
1069 PreCalculateMetaInformationRecursiveData recursive_data;
1070 PreCalculateMetaInformationInternal(root_layer, &recursive_data);
1071 }
1072
1073 Layer* PropertyTreeBuilder::FindFirstScrollableLayer(Layer* layer) {
1074 if (!layer)
1075 return NULL;
ajuma 2016/04/27 18:03:05 nit: nullptr
sunxd 2016/04/28 14:21:54 Done.
1076
1077 if (layer->scrollable())
1078 return layer;
1079
1080 for (size_t i = 0; i < layer->children().size(); ++i) {
1081 Layer* found = FindFirstScrollableLayer(layer->children()[i].get());
1082 if (found)
1083 return found;
1084 }
1085
1086 return NULL;
ajuma 2016/04/27 18:03:05 nullptr
sunxd 2016/04/28 14:21:54 Done.
1087 }
1088
930 template <typename LayerType> 1089 template <typename LayerType>
931 void BuildPropertyTreesTopLevelInternal( 1090 void BuildPropertyTreesTopLevelInternal(
932 LayerType* root_layer, 1091 LayerType* root_layer,
933 const LayerType* page_scale_layer, 1092 const LayerType* page_scale_layer,
934 const LayerType* inner_viewport_scroll_layer, 1093 const LayerType* inner_viewport_scroll_layer,
935 const LayerType* outer_viewport_scroll_layer, 1094 const LayerType* outer_viewport_scroll_layer,
936 const LayerType* overscroll_elasticity_layer, 1095 const LayerType* overscroll_elasticity_layer,
937 const gfx::Vector2dF& elastic_overscroll, 1096 const gfx::Vector2dF& elastic_overscroll,
938 float page_scale_factor, 1097 float page_scale_factor,
939 float device_scale_factor, 1098 float device_scale_factor,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 if (SkColorGetA(color) != 255) 1217 if (SkColorGetA(color) != 255)
1059 color = SkColorSetA(color, 255); 1218 color = SkColorSetA(color, 255);
1060 BuildPropertyTreesTopLevelInternal( 1219 BuildPropertyTreesTopLevelInternal(
1061 root_layer, page_scale_layer, inner_viewport_scroll_layer, 1220 root_layer, page_scale_layer, inner_viewport_scroll_layer,
1062 outer_viewport_scroll_layer, overscroll_elasticity_layer, 1221 outer_viewport_scroll_layer, overscroll_elasticity_layer,
1063 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, 1222 elastic_overscroll, page_scale_factor, device_scale_factor, viewport,
1064 device_transform, property_trees, color); 1223 device_transform, property_trees, color);
1065 } 1224 }
1066 1225
1067 } // namespace cc 1226 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698