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

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

Issue 1855373003: cc : Use same layer skipping functions in DrawPropertyUtils and LTHC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + typo in comment Created 4 years, 8 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/draw_property_utils.cc ('k') | cc/trees/layer_tree_host_common_unittest.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 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 static inline bool IsRootLayer(const Layer* layer) { 246 static inline bool IsRootLayer(const Layer* layer) {
247 return !layer->parent(); 247 return !layer->parent();
248 } 248 }
249 249
250 static inline bool IsRootLayer(const LayerImpl* layer) { 250 static inline bool IsRootLayer(const LayerImpl* layer) {
251 return layer->layer_tree_impl()->IsRootLayer(layer); 251 return layer->layer_tree_impl()->IsRootLayer(layer);
252 } 252 }
253 253
254 template <typename LayerType> 254 template <typename LayerType>
255 static inline bool LayerIsInExisting3DRenderingContext(LayerType* layer) {
256 return layer->Is3dSorted() && layer->parent() &&
257 layer->parent()->Is3dSorted() &&
258 (layer->parent()->sorting_context_id() == layer->sorting_context_id());
259 }
260
261 static bool IsLayerBackFaceVisible(LayerImpl* layer,
262 const TransformTree& transform_tree) {
263 // The current W3C spec on CSS transforms says that backface visibility should
264 // be determined differently depending on whether the layer is in a "3d
265 // rendering context" or not. For Chromium code, we can determine whether we
266 // are in a 3d rendering context by checking if the parent preserves 3d.
267
268 if (LayerIsInExisting3DRenderingContext(layer)) {
269 return draw_property_utils::DrawTransform(layer, transform_tree)
270 .IsBackFaceVisible();
271 }
272
273 // In this case, either the layer establishes a new 3d rendering context, or
274 // is not in a 3d rendering context at all.
275 return layer->transform().IsBackFaceVisible();
276 }
277
278 static bool IsSurfaceBackFaceVisible(LayerImpl* layer,
279 const gfx::Transform& draw_transform) {
280 return layer->layer_tree_impl()
281 ->property_trees()
282 ->effect_tree.Node(layer->effect_tree_index())
283 ->data.hidden_by_backface_visibility;
284 }
285
286 static bool LayerShouldBeSkipped(LayerImpl* layer,
287 bool layer_is_drawn,
288 const TransformTree& transform_tree) {
289 // Layers can be skipped if any of these conditions are met.
290 // - is not drawn due to it or one of its ancestors being hidden (or having
291 // no copy requests).
292 // - does not draw content.
293 // - is transparent.
294 // - has empty bounds
295 // - the layer is not double-sided, but its back face is visible.
296 //
297 // Some additional conditions need to be computed at a later point after the
298 // recursion is finished.
299 // - the intersection of render_surface content and layer clip_rect is empty
300 // - the visible_layer_rect is empty
301 //
302 // Note, if the layer should not have been drawn due to being fully
303 // transparent, we would have skipped the entire subtree and never made it
304 // into this function, so it is safe to omit this check here.
305
306 if (!layer_is_drawn)
307 return true;
308
309 if (!layer->DrawsContent() || layer->bounds().IsEmpty())
310 return true;
311
312 LayerImpl* backface_test_layer = layer;
313 if (layer->use_parent_backface_visibility()) {
314 DCHECK(!IsRootLayer(layer));
315 DCHECK(!layer->parent()->use_parent_backface_visibility());
316 backface_test_layer = layer->parent();
317 }
318
319 // The layer should not be drawn if (1) it is not double-sided and (2) the
320 // back of the layer is known to be facing the screen.
321 if (!backface_test_layer->double_sided() &&
322 IsLayerBackFaceVisible(backface_test_layer, transform_tree))
323 return true;
324
325 return false;
326 }
327
328 template <typename LayerType>
329 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) { 255 static bool HasInvertibleOrAnimatedTransform(LayerType* layer) {
330 return layer->transform_is_invertible() || 256 return layer->transform_is_invertible() ||
331 layer->HasPotentiallyRunningTransformAnimation(); 257 layer->HasPotentiallyRunningTransformAnimation();
332 } 258 }
333 259
334 static inline bool SubtreeShouldBeSkipped(LayerImpl* layer,
335 bool layer_is_drawn) {
336 // If the layer transform is not invertible, it should not be drawn.
337 // TODO(ajuma): Correctly process subtrees with singular transform for the
338 // case where we may animate to a non-singular transform and wish to
339 // pre-raster.
340 TransformNode* node =
341 layer->layer_tree_impl()->property_trees()->transform_tree.Node(
342 layer->transform_tree_index());
343 bool has_invertible_transform =
344 node->data.is_invertible && node->data.ancestors_are_invertible;
345 if (!(has_invertible_transform ||
346 layer->HasPotentiallyRunningTransformAnimation()))
347 return true;
348
349 // When we need to do a readback/copy of a layer's output, we can not skip
350 // it or any of its ancestors.
351 if (layer->num_copy_requests_in_target_subtree() > 0)
352 return false;
353
354 // We cannot skip the the subtree if a descendant has a touch handler
355 // or the hit testing code will break (it requires fresh transforms, etc).
356 if (layer->layer_or_descendant_has_touch_handler())
357 return false;
358
359 // If the layer is not drawn, then skip it and its subtree.
360 if (!layer_is_drawn)
361 return true;
362
363 // If layer is on the pending tree and opacity is being animated then
364 // this subtree can't be skipped as we need to create, prioritize and
365 // include tiles for this layer when deciding if tree can be activated.
366 if (layer->layer_tree_impl()->IsPendingTree() &&
367 layer->HasPotentiallyRunningOpacityAnimation())
368 return false;
369
370 // If layer has a background filter, don't skip the layer, even it the
371 // opacity is 0.
372 if (!layer->background_filters().IsEmpty())
373 return false;
374
375 // The opacity of a layer always applies to its children (either implicitly
376 // via a render surface or explicitly if the parent preserves 3D), so the
377 // entire subtree can be skipped if this layer is fully transparent.
378 return !layer->EffectiveOpacity();
379 }
380
381 static inline void MarkLayerWithRenderSurfaceLayerListId( 260 static inline void MarkLayerWithRenderSurfaceLayerListId(
382 LayerImpl* layer, 261 LayerImpl* layer,
383 int current_render_surface_layer_list_id) { 262 int current_render_surface_layer_list_id) {
384 layer->draw_properties().last_drawn_render_surface_layer_list_id = 263 layer->draw_properties().last_drawn_render_surface_layer_list_id =
385 current_render_surface_layer_list_id; 264 current_render_surface_layer_list_id;
386 layer->set_layer_or_descendant_is_drawn( 265 layer->set_layer_or_descendant_is_drawn(
387 !!current_render_surface_layer_list_id); 266 !!current_render_surface_layer_list_id);
388 } 267 }
389 268
390 static inline void MarkMasksWithRenderSurfaceLayerListId( 269 static inline void MarkMasksWithRenderSurfaceLayerListId(
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 void CalculateRenderTarget(LayerImpl* layer, 529 void CalculateRenderTarget(LayerImpl* layer,
651 PropertyTrees* property_trees, 530 PropertyTrees* property_trees,
652 bool subtree_visible_from_ancestor, 531 bool subtree_visible_from_ancestor,
653 bool can_render_to_separate_surface) { 532 bool can_render_to_separate_surface) {
654 bool layer_is_drawn; 533 bool layer_is_drawn;
655 DCHECK_GE(layer->effect_tree_index(), 0); 534 DCHECK_GE(layer->effect_tree_index(), 0);
656 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) 535 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index())
657 ->data.is_drawn; 536 ->data.is_drawn;
658 537
659 // The root layer cannot be skipped. 538 // The root layer cannot be skipped.
660 if (!IsRootLayer(layer) && SubtreeShouldBeSkipped(layer, layer_is_drawn)) { 539 if (!IsRootLayer(layer) &&
540 draw_property_utils::LayerShouldBeSkipped(
541 layer, layer_is_drawn, property_trees->transform_tree)) {
661 layer->draw_properties().render_target = nullptr; 542 layer->draw_properties().render_target = nullptr;
662 return; 543 return;
663 } 544 }
664 545
665 bool render_to_separate_surface = 546 bool render_to_separate_surface =
666 IsRootLayer(layer) || 547 IsRootLayer(layer) ||
667 (can_render_to_separate_surface && layer->render_surface()); 548 (can_render_to_separate_surface && layer->render_surface());
668 549
669 if (render_to_separate_surface) { 550 if (render_to_separate_surface) {
670 DCHECK(layer->render_surface()) << IsRootLayer(layer) 551 DCHECK(layer->render_surface()) << IsRootLayer(layer)
671 << can_render_to_separate_surface 552 << can_render_to_separate_surface
672 << layer->has_render_surface(); 553 << layer->has_render_surface();
673 layer->draw_properties().render_target = layer; 554 layer->draw_properties().render_target = layer;
674 555
675 if (layer->mask_layer()) 556 if (layer->mask_layer())
676 layer->mask_layer()->draw_properties().render_target = layer; 557 layer->mask_layer()->draw_properties().render_target = layer;
677 558
678 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) 559 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
679 layer->replica_layer()->mask_layer()->draw_properties().render_target = 560 layer->replica_layer()->mask_layer()->draw_properties().render_target =
680 layer; 561 layer;
681 562
682 } else { 563 } else {
683 DCHECK(!IsRootLayer(layer)); 564 DCHECK(!IsRootLayer(layer));
684 layer->draw_properties().render_target = layer->parent()->render_target(); 565 layer->draw_properties().render_target = layer->parent()->render_target();
685 } 566 }
686
687 for (size_t i = 0; i < layer->children().size(); ++i) { 567 for (size_t i = 0; i < layer->children().size(); ++i) {
688 CalculateRenderTarget( 568 CalculateRenderTarget(
689 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i), 569 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i),
690 property_trees, layer_is_drawn, can_render_to_separate_surface); 570 property_trees, layer_is_drawn, can_render_to_separate_surface);
691 } 571 }
692 } 572 }
693 573
694 void CalculateRenderSurfaceLayerList( 574 void CalculateRenderSurfaceLayerList(
695 LayerImpl* layer, 575 LayerImpl* layer,
696 PropertyTrees* property_trees, 576 PropertyTrees* property_trees,
(...skipping 18 matching lines...) Expand all
715 // layer's subtree. 595 // layer's subtree.
716 596
717 // |can_render_to_separate_surface| and |current_render_surface_layer_list_id| 597 // |can_render_to_separate_surface| and |current_render_surface_layer_list_id|
718 // are settings that should stay the same during recursion. 598 // are settings that should stay the same during recursion.
719 bool layer_is_drawn = false; 599 bool layer_is_drawn = false;
720 DCHECK_GE(layer->effect_tree_index(), 0); 600 DCHECK_GE(layer->effect_tree_index(), 0);
721 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) 601 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index())
722 ->data.is_drawn; 602 ->data.is_drawn;
723 603
724 // The root layer cannot be skipped. 604 // The root layer cannot be skipped.
725 if (!IsRootLayer(layer) && SubtreeShouldBeSkipped(layer, layer_is_drawn)) { 605 if (!IsRootLayer(layer) &&
606 draw_property_utils::LayerShouldBeSkipped(
607 layer, layer_is_drawn, property_trees->transform_tree)) {
726 if (layer->render_surface()) 608 if (layer->render_surface())
727 layer->ClearRenderSurfaceLayerList(); 609 layer->ClearRenderSurfaceLayerList();
728 layer->draw_properties().render_target = nullptr; 610 layer->draw_properties().render_target = nullptr;
729 return; 611 return;
730 } 612 }
731 613
732 bool render_to_separate_surface = 614 bool render_to_separate_surface =
733 IsRootLayer(layer) || 615 IsRootLayer(layer) ||
734 (can_render_to_separate_surface && layer->render_surface()); 616 (can_render_to_separate_surface && layer->render_surface());
735 617
736 if (render_to_separate_surface) { 618 if (render_to_separate_surface) {
737 DCHECK(layer->render_surface()); 619 DCHECK(layer->render_surface());
738 draw_property_utils::ComputeSurfaceDrawProperties(property_trees, 620 draw_property_utils::ComputeSurfaceDrawProperties(property_trees,
739 layer->render_surface()); 621 layer->render_surface());
740 622
741 if (!layer->double_sided() &&
742 IsSurfaceBackFaceVisible(layer,
743 layer->render_surface()->draw_transform())) {
744 layer->ClearRenderSurfaceLayerList();
745 layer->draw_properties().render_target = nullptr;
746 return;
747 }
748 623
749 if (IsRootLayer(layer)) { 624 if (IsRootLayer(layer)) {
750 // The root surface does not contribute to any other surface, it has no 625 // The root surface does not contribute to any other surface, it has no
751 // target. 626 // target.
752 layer->render_surface()->set_contributes_to_drawn_surface(false); 627 layer->render_surface()->set_contributes_to_drawn_surface(false);
753 } else { 628 } else {
754 bool contributes_to_drawn_surface = 629 bool contributes_to_drawn_surface =
755 property_trees->effect_tree.ContributesToDrawnSurface( 630 property_trees->effect_tree.ContributesToDrawnSurface(
756 layer->effect_tree_index()); 631 layer->effect_tree_index());
757 layer->render_surface()->set_contributes_to_drawn_surface( 632 layer->render_surface()->set_contributes_to_drawn_surface(
(...skipping 16 matching lines...) Expand all
774 nearest_occlusion_immune_ancestor); 649 nearest_occlusion_immune_ancestor);
775 layer->ClearRenderSurfaceLayerList(); 650 layer->ClearRenderSurfaceLayerList();
776 651
777 render_surface_layer_list->push_back(layer); 652 render_surface_layer_list->push_back(layer);
778 653
779 descendants = &(layer->render_surface()->layer_list()); 654 descendants = &(layer->render_surface()->layer_list());
780 } 655 }
781 656
782 size_t descendants_size = descendants->size(); 657 size_t descendants_size = descendants->size();
783 658
784 bool layer_should_be_skipped = LayerShouldBeSkipped( 659 bool layer_should_be_skipped = !draw_property_utils::LayerNeedsUpdate(
785 layer, layer_is_drawn, property_trees->transform_tree); 660 layer, layer_is_drawn, property_trees->transform_tree);
786 if (!layer_should_be_skipped) { 661 if (!layer_should_be_skipped) {
787 MarkLayerWithRenderSurfaceLayerListId(layer, 662 MarkLayerWithRenderSurfaceLayerListId(layer,
788 current_render_surface_layer_list_id); 663 current_render_surface_layer_list_id);
789 descendants->push_back(layer); 664 descendants->push_back(layer);
790 } 665 }
791 666
792 667
793 // Clear the old accumulated content rect of surface. 668 // Clear the old accumulated content rect of surface.
794 if (render_to_separate_surface) 669 if (render_to_separate_surface)
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 } 865 }
991 866
992 if (should_measure_property_tree_performance) { 867 if (should_measure_property_tree_performance) {
993 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), 868 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"),
994 "LayerTreeHostCommon::CalculateDrawProperties"); 869 "LayerTreeHostCommon::CalculateDrawProperties");
995 } 870 }
996 871
997 DCHECK(inputs->can_render_to_separate_surface == 872 DCHECK(inputs->can_render_to_separate_surface ==
998 inputs->property_trees->non_root_surfaces_enabled); 873 inputs->property_trees->non_root_surfaces_enabled);
999 const bool subtree_visible_from_ancestor = true; 874 const bool subtree_visible_from_ancestor = true;
875 for (auto* layer : *inputs->root_layer->layer_tree_impl())
876 layer->draw_properties().render_target = nullptr;
1000 CalculateRenderTarget(inputs->root_layer, inputs->property_trees, 877 CalculateRenderTarget(inputs->root_layer, inputs->property_trees,
1001 subtree_visible_from_ancestor, 878 subtree_visible_from_ancestor,
1002 inputs->can_render_to_separate_surface); 879 inputs->can_render_to_separate_surface);
1003 for (LayerImpl* layer : visible_layer_list) { 880 for (LayerImpl* layer : visible_layer_list) {
1004 draw_property_utils::ComputeLayerDrawProperties( 881 draw_property_utils::ComputeLayerDrawProperties(
1005 layer, inputs->property_trees, inputs->layers_always_allowed_lcd_text, 882 layer, inputs->property_trees, inputs->layers_always_allowed_lcd_text,
1006 inputs->can_use_lcd_text); 883 inputs->can_use_lcd_text);
1007 if (layer->mask_layer()) 884 if (layer->mask_layer())
1008 ComputeMaskLayerDrawProperties(layer, layer->mask_layer()); 885 ComputeMaskLayerDrawProperties(layer, layer->mask_layer());
1009 LayerImpl* replica_mask_layer = 886 LayerImpl* replica_mask_layer =
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 984
1108 PropertyTrees* GetPropertyTrees(Layer* layer) { 985 PropertyTrees* GetPropertyTrees(Layer* layer) {
1109 return layer->layer_tree_host()->property_trees(); 986 return layer->layer_tree_host()->property_trees();
1110 } 987 }
1111 988
1112 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { 989 PropertyTrees* GetPropertyTrees(LayerImpl* layer) {
1113 return layer->layer_tree_impl()->property_trees(); 990 return layer->layer_tree_impl()->property_trees();
1114 } 991 }
1115 992
1116 } // namespace cc 993 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698