Chromium Code Reviews| 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 void UpdateRenderSurfacesWithEffectTree(EffectTree* effect_tree, Layer* layer) { | |
| 464 EffectNode* effect_node = effect_tree->Node(layer->effect_tree_index()); | |
| 465 if (effect_node->owner_id == layer->id() && | |
| 466 effect_node->data.has_render_surface) { | |
| 467 layer->SetHasRenderSurface(true); | |
| 468 } else { | |
| 469 layer->SetHasRenderSurface(false); | |
| 470 } | |
| 471 | |
| 472 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 473 UpdateRenderSurfacesWithEffectTree(effect_tree, layer->child_at(i)); | |
| 474 } | |
| 475 } | |
| 476 | |
| 477 void UpdateRenderSurfacesWithEffectTree(EffectTree* effect_tree, | |
| 478 bool non_root_surfaces_enabled, | |
| 479 LayerImpl* layer) { | |
| 480 EffectNode* effect_node = effect_tree->Node(layer->effect_tree_index()); | |
| 481 if (!non_root_surfaces_enabled) { | |
| 482 if (!layer->parent()) { | |
| 483 layer->SetHasRenderSurface(true); | |
| 484 } else { | |
| 485 layer->SetHasRenderSurface(false); | |
| 486 } | |
| 487 } else if (effect_node->owner_id == layer->id() && | |
|
enne (OOO)
2015/12/04 17:39:30
This bottom half of the function looks like a dupl
weiliangc
2015/12/04 20:28:12
Done.
| |
| 488 effect_node->data.has_render_surface) { | |
| 489 layer->SetHasRenderSurface(true); | |
| 490 } else { | |
| 491 layer->SetHasRenderSurface(false); | |
| 492 } | |
| 493 | |
| 494 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 495 UpdateRenderSurfacesWithEffectTree(effect_tree, non_root_surfaces_enabled, | |
| 496 layer->child_at(i)); | |
| 497 } | |
| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 float device_scale_factor, | 695 float device_scale_factor, |
| 639 const gfx::Rect& viewport, | 696 const gfx::Rect& viewport, |
| 640 const gfx::Transform& device_transform, | 697 const gfx::Transform& device_transform, |
| 641 bool can_render_to_separate_surface, | 698 bool can_render_to_separate_surface, |
| 642 PropertyTrees* property_trees, | 699 PropertyTrees* property_trees, |
| 643 LayerList* update_layer_list) { | 700 LayerList* update_layer_list) { |
| 644 PropertyTreeBuilder::BuildPropertyTrees( | 701 PropertyTreeBuilder::BuildPropertyTrees( |
| 645 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 702 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 646 outer_viewport_scroll_layer, page_scale_factor, device_scale_factor, | 703 outer_viewport_scroll_layer, page_scale_factor, device_scale_factor, |
| 647 viewport, device_transform, property_trees); | 704 viewport, device_transform, property_trees); |
| 705 UpdateRenderSurfacesWithEffectTree(&property_trees->effect_tree, root_layer); | |
| 706 ValidateRenderSurfaces(root_layer); | |
| 648 ComputeVisibleRectsUsingPropertyTrees(root_layer, property_trees, | 707 ComputeVisibleRectsUsingPropertyTrees(root_layer, property_trees, |
| 649 can_render_to_separate_surface, | 708 can_render_to_separate_surface, |
| 650 update_layer_list); | 709 update_layer_list); |
| 651 } | 710 } |
| 652 | 711 |
| 653 void BuildPropertyTreesAndComputeVisibleRects( | 712 void BuildPropertyTreesAndComputeVisibleRects( |
| 654 LayerImpl* root_layer, | 713 LayerImpl* root_layer, |
| 655 const LayerImpl* page_scale_layer, | 714 const LayerImpl* page_scale_layer, |
| 656 const LayerImpl* inner_viewport_scroll_layer, | 715 const LayerImpl* inner_viewport_scroll_layer, |
| 657 const LayerImpl* outer_viewport_scroll_layer, | 716 const LayerImpl* outer_viewport_scroll_layer, |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 678 std::vector<Layer*> visible_layer_list; | 737 std::vector<Layer*> visible_layer_list; |
| 679 ComputeVisibleRectsUsingPropertyTreesInternal( | 738 ComputeVisibleRectsUsingPropertyTreesInternal( |
| 680 root_layer, property_trees, can_render_to_separate_surface, | 739 root_layer, property_trees, can_render_to_separate_surface, |
| 681 update_layer_list, &visible_layer_list); | 740 update_layer_list, &visible_layer_list); |
| 682 } | 741 } |
| 683 | 742 |
| 684 void ComputeVisibleRectsUsingPropertyTrees(LayerImpl* root_layer, | 743 void ComputeVisibleRectsUsingPropertyTrees(LayerImpl* root_layer, |
| 685 PropertyTrees* property_trees, | 744 PropertyTrees* property_trees, |
| 686 bool can_render_to_separate_surface, | 745 bool can_render_to_separate_surface, |
| 687 LayerImplList* visible_layer_list) { | 746 LayerImplList* visible_layer_list) { |
| 747 UpdateRenderSurfacesWithEffectTree( | |
| 748 &property_trees->effect_tree, can_render_to_separate_surface, root_layer); | |
| 749 if (can_render_to_separate_surface) | |
| 750 ValidateRenderSurfaces(root_layer); | |
| 688 LayerImplList update_layer_list; | 751 LayerImplList update_layer_list; |
| 689 ComputeVisibleRectsUsingPropertyTreesInternal( | 752 ComputeVisibleRectsUsingPropertyTreesInternal( |
| 690 root_layer, property_trees, can_render_to_separate_surface, | 753 root_layer, property_trees, can_render_to_separate_surface, |
| 691 &update_layer_list, visible_layer_list); | 754 &update_layer_list, visible_layer_list); |
| 692 } | 755 } |
| 693 | 756 |
| 694 template <typename LayerType> | 757 template <typename LayerType> |
| 695 static gfx::Transform DrawTransformFromPropertyTreesInternal( | 758 static gfx::Transform DrawTransformFromPropertyTreesInternal( |
| 696 const LayerType* layer, | 759 const LayerType* layer, |
| 697 const TransformNode* node) { | 760 const TransformNode* node) { |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 const Layer* page_scale_layer, | 1134 const Layer* page_scale_layer, |
| 1072 float page_scale_factor, | 1135 float page_scale_factor, |
| 1073 float device_scale_factor, | 1136 float device_scale_factor, |
| 1074 const gfx::Transform device_transform) { | 1137 const gfx::Transform device_transform) { |
| 1075 UpdatePageScaleFactorInPropertyTreesInternal( | 1138 UpdatePageScaleFactorInPropertyTreesInternal( |
| 1076 property_trees, page_scale_layer, page_scale_factor, device_scale_factor, | 1139 property_trees, page_scale_layer, page_scale_factor, device_scale_factor, |
| 1077 device_transform); | 1140 device_transform); |
| 1078 } | 1141 } |
| 1079 | 1142 |
| 1080 } // namespace cc | 1143 } // namespace cc |
| OLD | NEW |