OLD | NEW |
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/draw_property_utils.h" | 5 #include "cc/trees/draw_property_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
10 #include "cc/layers/draw_properties.h" | 10 #include "cc/layers/draw_properties.h" |
11 #include "cc/layers/layer.h" | 11 #include "cc/layers/layer.h" |
12 #include "cc/layers/layer_impl.h" | 12 #include "cc/layers/layer_impl.h" |
13 #include "cc/layers/render_surface_draw_properties.h" | 13 #include "cc/layers/render_surface_draw_properties.h" |
14 #include "cc/trees/layer_tree_impl.h" | 14 #include "cc/trees/layer_tree_impl.h" |
15 #include "cc/trees/property_tree.h" | 15 #include "cc/trees/property_tree.h" |
16 #include "cc/trees/property_tree_builder.h" | 16 #include "cc/trees/property_tree_builder.h" |
17 #include "ui/gfx/geometry/rect_conversions.h" | 17 #include "ui/gfx/geometry/rect_conversions.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 template <typename LayerType> | 23 template <typename LayerType> |
| 24 static void ValidateRenderSurfaces(LayerType* layer) { |
| 25 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 26 ValidateRenderSurfaces(layer->child_at(i)); |
| 27 } |
| 28 |
| 29 // This test verifies that there are no cases where a LayerImpl needs |
| 30 // a render surface, but doesn't have one. |
| 31 if (layer->has_render_surface()) |
| 32 return; |
| 33 |
| 34 DCHECK(layer->filters().IsEmpty()) << "layer: " << layer->id(); |
| 35 DCHECK(layer->background_filters().IsEmpty()) << "layer: " << layer->id(); |
| 36 DCHECK(layer->parent()) << "layer: " << layer->id(); |
| 37 if (layer->parent()->replica_layer() == layer) |
| 38 return; |
| 39 DCHECK(!layer->mask_layer()) << "layer: " << layer->id(); |
| 40 DCHECK(!layer->replica_layer()) << "layer: " << layer->id(); |
| 41 DCHECK(!layer->is_root_for_isolated_group()) << "layer: " << layer->id(); |
| 42 DCHECK(!layer->HasCopyRequest()) << "layer: " << layer->id(); |
| 43 } |
| 44 |
| 45 template <typename LayerType> |
24 void CalculateVisibleRects(const std::vector<LayerType*>& visible_layer_list, | 46 void CalculateVisibleRects(const std::vector<LayerType*>& visible_layer_list, |
25 const ClipTree& clip_tree, | 47 const ClipTree& clip_tree, |
26 const TransformTree& transform_tree, | 48 const TransformTree& transform_tree, |
27 bool non_root_surfaces_enabled) { | 49 bool non_root_surfaces_enabled) { |
28 for (auto& layer : visible_layer_list) { | 50 for (auto& layer : visible_layer_list) { |
29 gfx::Size layer_bounds = layer->bounds(); | 51 gfx::Size layer_bounds = layer->bounds(); |
30 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); | 52 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); |
31 const bool is_unclipped = clip_node->data.resets_clip && | 53 const bool is_unclipped = clip_node->data.resets_clip && |
32 !clip_node->data.applies_local_clip && | 54 !clip_node->data.applies_local_clip && |
33 non_root_surfaces_enabled; | 55 non_root_surfaces_enabled; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 if (LayerType* mask_layer = replica_layer->mask_layer()) | 453 if (LayerType* mask_layer = replica_layer->mask_layer()) |
432 update_layer_list->push_back(mask_layer); | 454 update_layer_list->push_back(mask_layer); |
433 } | 455 } |
434 | 456 |
435 for (size_t i = 0; i < layer->children().size(); ++i) { | 457 for (size_t i = 0; i < layer->children().size(); ++i) { |
436 FindLayersThatNeedUpdates(layer->child_at(i), tree, layer_is_drawn, | 458 FindLayersThatNeedUpdates(layer->child_at(i), tree, layer_is_drawn, |
437 update_layer_list, visible_layer_list); | 459 update_layer_list, visible_layer_list); |
438 } | 460 } |
439 } | 461 } |
440 | 462 |
| 463 template <typename LayerType> |
| 464 void UpdateRenderSurfacesWithEffectTreeInternal(EffectTree* effect_tree, |
| 465 LayerType* layer) { |
| 466 EffectNode* node = effect_tree->Node(layer->effect_tree_index()); |
| 467 |
| 468 if (node->owner_id == layer->id() && node->data.has_render_surface) |
| 469 layer->SetHasRenderSurface(true); |
| 470 else |
| 471 layer->SetHasRenderSurface(false); |
| 472 |
| 473 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 474 UpdateRenderSurfacesWithEffectTreeInternal<LayerType>(effect_tree, |
| 475 layer->child_at(i)); |
| 476 } |
| 477 } |
| 478 |
| 479 void UpdateRenderSurfacesWithEffectTree(EffectTree* effect_tree, Layer* layer) { |
| 480 UpdateRenderSurfacesWithEffectTreeInternal<Layer>(effect_tree, layer); |
| 481 } |
| 482 |
| 483 void UpdateRenderSurfacesNonRootSurfacesDisabled(LayerImpl* layer) { |
| 484 // Only root layer has render surface, all other layers don't. |
| 485 layer->SetHasRenderSurface(!layer->parent()); |
| 486 |
| 487 for (size_t i = 0; i < layer->children().size(); ++i) |
| 488 UpdateRenderSurfacesNonRootSurfacesDisabled(layer->child_at(i)); |
| 489 } |
| 490 |
| 491 void UpdateRenderSurfacesWithEffectTree(EffectTree* effect_tree, |
| 492 bool non_root_surfaces_enabled, |
| 493 LayerImpl* layer) { |
| 494 if (!non_root_surfaces_enabled) |
| 495 UpdateRenderSurfacesNonRootSurfacesDisabled(layer); |
| 496 else |
| 497 UpdateRenderSurfacesWithEffectTreeInternal<LayerImpl>(effect_tree, layer); |
| 498 } |
| 499 |
441 } // namespace | 500 } // namespace |
442 | 501 |
443 static void ResetIfHasNanCoordinate(gfx::RectF* rect) { | 502 static void ResetIfHasNanCoordinate(gfx::RectF* rect) { |
444 if (std::isnan(rect->x()) || std::isnan(rect->y()) || | 503 if (std::isnan(rect->x()) || std::isnan(rect->y()) || |
445 std::isnan(rect->right()) || std::isnan(rect->bottom())) | 504 std::isnan(rect->right()) || std::isnan(rect->bottom())) |
446 *rect = gfx::RectF(); | 505 *rect = gfx::RectF(); |
447 } | 506 } |
448 | 507 |
449 void ComputeClips(ClipTree* clip_tree, | 508 void ComputeClips(ClipTree* clip_tree, |
450 const TransformTree& transform_tree, | 509 const TransformTree& transform_tree, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 1.f / parent_transform_node->data.sublayer_scale.y()); | 552 1.f / parent_transform_node->data.sublayer_scale.y()); |
494 // If we can't compute a transform, it's because we had to use the inverse | 553 // If we can't compute a transform, it's because we had to use the inverse |
495 // of a singular transform. We won't draw in this case, so there's no need | 554 // of a singular transform. We won't draw in this case, so there's no need |
496 // to compute clips. | 555 // to compute clips. |
497 if (!success) | 556 if (!success) |
498 continue; | 557 continue; |
499 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( | 558 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( |
500 parent_to_current, | 559 parent_to_current, |
501 parent_clip_node->data.combined_clip_in_target_space); | 560 parent_clip_node->data.combined_clip_in_target_space); |
502 } | 561 } |
503 | |
504 // Only nodes affected by ancestor clips will have their clip adjusted due | 562 // Only nodes affected by ancestor clips will have their clip adjusted due |
505 // to intersecting with an ancestor clip. But, we still need to propagate | 563 // to intersecting with an ancestor clip. But, we still need to propagate |
506 // the combined clip to our children because if they are clipped, they may | 564 // the combined clip to our children because if they are clipped, they may |
507 // need to clip using our parent clip and if we don't propagate it here, | 565 // need to clip using our parent clip and if we don't propagate it here, |
508 // it will be lost. | 566 // it will be lost. |
509 if (clip_node->data.resets_clip && non_root_surfaces_enabled) { | 567 if (clip_node->data.resets_clip && non_root_surfaces_enabled) { |
510 if (clip_node->data.applies_local_clip) { | 568 if (clip_node->data.applies_local_clip) { |
511 clip_node->data.clip_in_target_space = MathUtil::MapClippedRect( | 569 clip_node->data.clip_in_target_space = MathUtil::MapClippedRect( |
512 transform_node->data.to_target, clip_node->data.clip); | 570 transform_node->data.to_target, clip_node->data.clip); |
513 ResetIfHasNanCoordinate(&clip_node->data.clip_in_target_space); | 571 ResetIfHasNanCoordinate(&clip_node->data.clip_in_target_space); |
514 clip_node->data.combined_clip_in_target_space = | 572 clip_node->data.combined_clip_in_target_space = |
515 gfx::IntersectRects(clip_node->data.clip_in_target_space, | 573 gfx::IntersectRects(clip_node->data.clip_in_target_space, |
516 parent_combined_clip_in_target_space); | 574 parent_combined_clip_in_target_space); |
517 } else { | 575 } else { |
518 DCHECK(!clip_node->data.target_is_clipped); | 576 DCHECK(!clip_node->data.target_is_clipped); |
519 DCHECK(!clip_node->data.layers_are_clipped); | 577 DCHECK(!clip_node->data.layers_are_clipped); |
520 clip_node->data.combined_clip_in_target_space = | 578 clip_node->data.combined_clip_in_target_space = |
521 parent_combined_clip_in_target_space; | 579 parent_combined_clip_in_target_space; |
522 } | 580 } |
523 ResetIfHasNanCoordinate(&clip_node->data.combined_clip_in_target_space); | 581 ResetIfHasNanCoordinate(&clip_node->data.combined_clip_in_target_space); |
524 continue; | 582 continue; |
525 } | 583 } |
526 | |
527 bool use_only_parent_clip = !clip_node->data.applies_local_clip; | 584 bool use_only_parent_clip = !clip_node->data.applies_local_clip; |
528 if (use_only_parent_clip) { | 585 if (use_only_parent_clip) { |
529 clip_node->data.combined_clip_in_target_space = | 586 clip_node->data.combined_clip_in_target_space = |
530 parent_combined_clip_in_target_space; | 587 parent_combined_clip_in_target_space; |
531 if (!non_root_surfaces_enabled) { | 588 if (!non_root_surfaces_enabled) { |
532 clip_node->data.clip_in_target_space = | 589 clip_node->data.clip_in_target_space = |
533 parent_clip_node->data.clip_in_target_space; | 590 parent_clip_node->data.clip_in_target_space; |
534 } else if (!clip_node->data.target_is_clipped) { | 591 } else if (!clip_node->data.target_is_clipped) { |
535 clip_node->data.clip_in_target_space = | 592 clip_node->data.clip_in_target_space = |
536 parent_combined_clip_in_target_space; | 593 parent_combined_clip_in_target_space; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 const gfx::Rect& viewport, | 698 const gfx::Rect& viewport, |
642 const gfx::Transform& device_transform, | 699 const gfx::Transform& device_transform, |
643 bool can_render_to_separate_surface, | 700 bool can_render_to_separate_surface, |
644 PropertyTrees* property_trees, | 701 PropertyTrees* property_trees, |
645 LayerList* update_layer_list) { | 702 LayerList* update_layer_list) { |
646 PropertyTreeBuilder::BuildPropertyTrees( | 703 PropertyTreeBuilder::BuildPropertyTrees( |
647 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 704 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
648 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 705 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
649 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, | 706 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, |
650 device_transform, property_trees); | 707 device_transform, property_trees); |
| 708 UpdateRenderSurfacesWithEffectTree(&property_trees->effect_tree, root_layer); |
| 709 ValidateRenderSurfaces(root_layer); |
651 ComputeVisibleRectsUsingPropertyTrees(root_layer, property_trees, | 710 ComputeVisibleRectsUsingPropertyTrees(root_layer, property_trees, |
652 can_render_to_separate_surface, | 711 can_render_to_separate_surface, |
653 update_layer_list); | 712 update_layer_list); |
654 } | 713 } |
655 | 714 |
656 void BuildPropertyTreesAndComputeVisibleRects( | 715 void BuildPropertyTreesAndComputeVisibleRects( |
657 LayerImpl* root_layer, | 716 LayerImpl* root_layer, |
658 const LayerImpl* page_scale_layer, | 717 const LayerImpl* page_scale_layer, |
659 const LayerImpl* inner_viewport_scroll_layer, | 718 const LayerImpl* inner_viewport_scroll_layer, |
660 const LayerImpl* outer_viewport_scroll_layer, | 719 const LayerImpl* outer_viewport_scroll_layer, |
(...skipping 23 matching lines...) Expand all Loading... |
684 std::vector<Layer*> visible_layer_list; | 743 std::vector<Layer*> visible_layer_list; |
685 ComputeVisibleRectsUsingPropertyTreesInternal( | 744 ComputeVisibleRectsUsingPropertyTreesInternal( |
686 root_layer, property_trees, can_render_to_separate_surface, | 745 root_layer, property_trees, can_render_to_separate_surface, |
687 update_layer_list, &visible_layer_list); | 746 update_layer_list, &visible_layer_list); |
688 } | 747 } |
689 | 748 |
690 void ComputeVisibleRectsUsingPropertyTrees(LayerImpl* root_layer, | 749 void ComputeVisibleRectsUsingPropertyTrees(LayerImpl* root_layer, |
691 PropertyTrees* property_trees, | 750 PropertyTrees* property_trees, |
692 bool can_render_to_separate_surface, | 751 bool can_render_to_separate_surface, |
693 LayerImplList* visible_layer_list) { | 752 LayerImplList* visible_layer_list) { |
| 753 UpdateRenderSurfacesWithEffectTree( |
| 754 &property_trees->effect_tree, can_render_to_separate_surface, root_layer); |
| 755 if (can_render_to_separate_surface) |
| 756 ValidateRenderSurfaces(root_layer); |
694 LayerImplList update_layer_list; | 757 LayerImplList update_layer_list; |
695 ComputeVisibleRectsUsingPropertyTreesInternal( | 758 ComputeVisibleRectsUsingPropertyTreesInternal( |
696 root_layer, property_trees, can_render_to_separate_surface, | 759 root_layer, property_trees, can_render_to_separate_surface, |
697 &update_layer_list, visible_layer_list); | 760 &update_layer_list, visible_layer_list); |
698 } | 761 } |
699 | 762 |
700 template <typename LayerType> | 763 template <typename LayerType> |
701 static gfx::Transform DrawTransformFromPropertyTreesInternal( | 764 static gfx::Transform DrawTransformFromPropertyTreesInternal( |
702 const LayerType* layer, | 765 const LayerType* layer, |
703 const TransformNode* node) { | 766 const TransformNode* node) { |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 | 1176 |
1114 void UpdateElasticOverscrollInPropertyTrees( | 1177 void UpdateElasticOverscrollInPropertyTrees( |
1115 PropertyTrees* property_trees, | 1178 PropertyTrees* property_trees, |
1116 const Layer* overscroll_elasticity_layer, | 1179 const Layer* overscroll_elasticity_layer, |
1117 const gfx::Vector2dF& elastic_overscroll) { | 1180 const gfx::Vector2dF& elastic_overscroll) { |
1118 UpdateElasticOverscrollInPropertyTreesInternal( | 1181 UpdateElasticOverscrollInPropertyTreesInternal( |
1119 property_trees, overscroll_elasticity_layer, elastic_overscroll); | 1182 property_trees, overscroll_elasticity_layer, elastic_overscroll); |
1120 } | 1183 } |
1121 | 1184 |
1122 } // namespace cc | 1185 } // namespace cc |
OLD | NEW |