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

Side by Side Diff: cc/trees/layer_tree_host_common.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 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_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 DCHECK_EQ(scrolls.size(), 0u); 188 DCHECK_EQ(scrolls.size(), 0u);
189 for (int i = 0; i < proto.scrolls_size(); ++i) { 189 for (int i = 0; i < proto.scrolls_size(); ++i) {
190 scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo()); 190 scrolls.push_back(LayerTreeHostCommon::ScrollUpdateInfo());
191 scrolls[i].FromProtobuf(proto.scrolls(i)); 191 scrolls[i].FromProtobuf(proto.scrolls(i));
192 } 192 }
193 page_scale_delta = proto.page_scale_delta(); 193 page_scale_delta = proto.page_scale_delta();
194 elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta()); 194 elastic_overscroll_delta = ProtoToVector2dF(proto.elastic_overscroll_delta());
195 top_controls_delta = proto.top_controls_delta(); 195 top_controls_delta = proto.top_controls_delta();
196 } 196 }
197 197
198 static inline bool IsRootLayer(const Layer* layer) {
199 return !layer->parent();
200 }
201
202 static bool HasInvertibleOrAnimatedTransform(Layer* layer) {
203 return layer->transform_is_invertible() ||
204 layer->HasPotentiallyRunningTransformAnimation();
205 }
206
207 static bool HasInvertibleOrAnimatedTransformForTesting(LayerImpl* layer) {
208 return layer->transform().IsInvertible() ||
209 layer->HasPotentiallyRunningTransformAnimation();
210 }
211
212 static inline void MarkLayerWithRenderSurfaceLayerListId( 198 static inline void MarkLayerWithRenderSurfaceLayerListId(
213 LayerImpl* layer, 199 LayerImpl* layer,
214 int current_render_surface_layer_list_id) { 200 int current_render_surface_layer_list_id) {
215 layer->draw_properties().last_drawn_render_surface_layer_list_id = 201 layer->draw_properties().last_drawn_render_surface_layer_list_id =
216 current_render_surface_layer_list_id; 202 current_render_surface_layer_list_id;
217 } 203 }
218 204
219 static inline void MarkMasksWithRenderSurfaceLayerListId( 205 static inline void MarkMasksWithRenderSurfaceLayerListId(
220 LayerImpl* layer, 206 LayerImpl* layer,
221 int current_render_surface_layer_list_id) { 207 int current_render_surface_layer_list_id) {
(...skipping 18 matching lines...) Expand all
240 scroll_tree->Node(layer->scroll_tree_index()) 226 scroll_tree->Node(layer->scroll_tree_index())
241 ->data.num_drawn_descendants--; 227 ->data.num_drawn_descendants--;
242 } 228 }
243 MarkLayerWithRenderSurfaceLayerListId(layer, 229 MarkLayerWithRenderSurfaceLayerListId(layer,
244 cleared_render_surface_layer_list_id); 230 cleared_render_surface_layer_list_id);
245 MarkMasksWithRenderSurfaceLayerListId(layer, 231 MarkMasksWithRenderSurfaceLayerListId(layer,
246 cleared_render_surface_layer_list_id); 232 cleared_render_surface_layer_list_id);
247 } 233 }
248 } 234 }
249 235
250 struct PreCalculateMetaInformationRecursiveData {
251 size_t num_unclipped_descendants;
252 int num_layer_or_descendants_with_copy_request;
253 int num_layer_or_descendants_with_touch_handler;
254 int num_descendants_that_draw_content;
255
256 PreCalculateMetaInformationRecursiveData()
257 : num_unclipped_descendants(0),
258 num_layer_or_descendants_with_copy_request(0),
259 num_layer_or_descendants_with_touch_handler(0),
260 num_descendants_that_draw_content(0) {}
261
262 void Merge(const PreCalculateMetaInformationRecursiveData& data) {
263 num_layer_or_descendants_with_copy_request +=
264 data.num_layer_or_descendants_with_copy_request;
265 num_layer_or_descendants_with_touch_handler +=
266 data.num_layer_or_descendants_with_touch_handler;
267 num_unclipped_descendants += data.num_unclipped_descendants;
268 num_descendants_that_draw_content += data.num_descendants_that_draw_content;
269 }
270 };
271
272 static bool IsMetaInformationRecomputationNeeded(Layer* layer) {
273 return layer->layer_tree_host()->needs_meta_info_recomputation();
274 }
275
276 static void UpdateMetaInformationSequenceNumber(Layer* root_layer) {
277 root_layer->layer_tree_host()->IncrementMetaInformationSequenceNumber();
278 }
279
280 // Recursively walks the layer tree(if needed) to compute any information
281 // that is needed before doing the main recursion.
282 static void PreCalculateMetaInformationInternal(
283 Layer* layer,
284 PreCalculateMetaInformationRecursiveData* recursive_data) {
285 if (!IsMetaInformationRecomputationNeeded(layer)) {
286 DCHECK(IsRootLayer(layer));
287 return;
288 }
289
290 if (layer->clip_parent())
291 recursive_data->num_unclipped_descendants++;
292
293 if (!HasInvertibleOrAnimatedTransform(layer)) {
294 // Layers with singular transforms should not be drawn, the whole subtree
295 // can be skipped.
296 return;
297 }
298
299 for (size_t i = 0; i < layer->children().size(); ++i) {
300 Layer* child_layer = layer->child_at(i);
301
302 PreCalculateMetaInformationRecursiveData data_for_child;
303 PreCalculateMetaInformationInternal(child_layer, &data_for_child);
304 recursive_data->Merge(data_for_child);
305 }
306
307 if (layer->clip_children()) {
308 size_t num_clip_children = layer->clip_children()->size();
309 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children);
310 recursive_data->num_unclipped_descendants -= num_clip_children;
311 }
312
313 if (layer->HasCopyRequest())
314 recursive_data->num_layer_or_descendants_with_copy_request++;
315
316 if (!layer->touch_event_handler_region().IsEmpty())
317 recursive_data->num_layer_or_descendants_with_touch_handler++;
318
319 layer->set_num_unclipped_descendants(
320 recursive_data->num_unclipped_descendants);
321
322 if (IsRootLayer(layer))
323 layer->layer_tree_host()->SetNeedsMetaInfoRecomputation(false);
324 }
325
326 static void PreCalculateMetaInformationInternalForTesting(
327 LayerImpl* layer,
328 PreCalculateMetaInformationRecursiveData* recursive_data) {
329 if (layer->clip_parent())
330 recursive_data->num_unclipped_descendants++;
331
332 if (!HasInvertibleOrAnimatedTransformForTesting(layer)) {
333 // Layers with singular transforms should not be drawn, the whole subtree
334 // can be skipped.
335 return;
336 }
337
338 for (size_t i = 0; i < layer->children().size(); ++i) {
339 LayerImpl* child_layer = layer->child_at(i);
340
341 PreCalculateMetaInformationRecursiveData data_for_child;
342 PreCalculateMetaInformationInternalForTesting(child_layer, &data_for_child);
343 recursive_data->Merge(data_for_child);
344 }
345
346 if (layer->clip_children()) {
347 size_t num_clip_children = layer->clip_children()->size();
348 DCHECK_GE(recursive_data->num_unclipped_descendants, num_clip_children);
349 recursive_data->num_unclipped_descendants -= num_clip_children;
350 }
351
352 if (layer->HasCopyRequest())
353 recursive_data->num_layer_or_descendants_with_copy_request++;
354
355 if (!layer->touch_event_handler_region().IsEmpty())
356 recursive_data->num_layer_or_descendants_with_touch_handler++;
357
358 layer->draw_properties().num_unclipped_descendants =
359 recursive_data->num_unclipped_descendants;
360 layer->set_layer_or_descendant_has_touch_handler(
361 (recursive_data->num_layer_or_descendants_with_touch_handler != 0));
362 // TODO(enne): this should be synced from the main thread, so is only
363 // for tests constructing layers on the compositor thread.
364 layer->test_properties()->num_descendants_that_draw_content =
365 recursive_data->num_descendants_that_draw_content;
366
367 if (layer->DrawsContent())
368 recursive_data->num_descendants_that_draw_content++;
369 }
370
371 void LayerTreeHostCommon::PreCalculateMetaInformation(Layer* root_layer) {
372 PreCalculateMetaInformationRecursiveData recursive_data;
373 PreCalculateMetaInformationInternal(root_layer, &recursive_data);
374 }
375
376 void LayerTreeHostCommon::PreCalculateMetaInformationForTesting(
377 LayerImpl* root_layer) {
378 PreCalculateMetaInformationRecursiveData recursive_data;
379 PreCalculateMetaInformationInternalForTesting(root_layer, &recursive_data);
380 }
381
382 void LayerTreeHostCommon::PreCalculateMetaInformationForTesting(
383 Layer* root_layer) {
384 UpdateMetaInformationSequenceNumber(root_layer);
385 PreCalculateMetaInformationRecursiveData recursive_data;
386 PreCalculateMetaInformationInternal(root_layer, &recursive_data);
387 }
388
389 static bool CdpPerfTracingEnabled() { 236 static bool CdpPerfTracingEnabled() {
390 bool tracing_enabled; 237 bool tracing_enabled;
391 TRACE_EVENT_CATEGORY_GROUP_ENABLED("cdp.perf", &tracing_enabled); 238 TRACE_EVENT_CATEGORY_GROUP_ENABLED("cdp.perf", &tracing_enabled);
392 return tracing_enabled; 239 return tracing_enabled;
393 } 240 }
394 241
395 static float TranslationFromActiveTreeLayerScreenSpaceTransform( 242 static float TranslationFromActiveTreeLayerScreenSpaceTransform(
396 LayerImpl* pending_tree_layer) { 243 LayerImpl* pending_tree_layer) {
397 LayerTreeImpl* layer_tree_impl = pending_tree_layer->layer_tree_impl(); 244 LayerTreeImpl* layer_tree_impl = pending_tree_layer->layer_tree_impl();
398 if (layer_tree_impl) { 245 if (layer_tree_impl) {
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 TRACE_EVENT_ASYNC_END1( 699 TRACE_EVENT_ASYNC_END1(
853 "cdp.perf", "jitter", 700 "cdp.perf", "jitter",
854 inputs->root_layer->layer_tree_impl()->source_frame_number(), "value", 701 inputs->root_layer->layer_tree_impl()->source_frame_number(), "value",
855 jitter); 702 jitter);
856 } 703 }
857 } 704 }
858 } 705 }
859 706
860 void LayerTreeHostCommon::CalculateDrawProperties( 707 void LayerTreeHostCommon::CalculateDrawProperties(
861 CalcDrawPropsImplInputsForTesting* inputs) { 708 CalcDrawPropsImplInputsForTesting* inputs) {
862 PreCalculateMetaInformationRecursiveData recursive_data; 709 PropertyTreeBuilder::PreCalculateMetaInformation(inputs->root_layer);
863 PreCalculateMetaInformationInternalForTesting(inputs->root_layer,
864 &recursive_data);
865 CalculateDrawPropertiesInternal(inputs, BUILD_PROPERTY_TREES_IF_NEEDED); 710 CalculateDrawPropertiesInternal(inputs, BUILD_PROPERTY_TREES_IF_NEEDED);
866 } 711 }
867 712
868 PropertyTrees* GetPropertyTrees(Layer* layer) { 713 PropertyTrees* GetPropertyTrees(Layer* layer) {
869 return layer->layer_tree_host()->property_trees(); 714 return layer->layer_tree_host()->property_trees();
870 } 715 }
871 716
872 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { 717 PropertyTrees* GetPropertyTrees(LayerImpl* layer) {
873 return layer->layer_tree_impl()->property_trees(); 718 return layer->layer_tree_impl()->property_trees();
874 } 719 }
875 720
876 } // namespace cc 721 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698