 Chromium Code Reviews
 Chromium Code Reviews Issue 1491033002:
  Create RenderSurface on Effect Tree  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@alwayspt
    
  
    Issue 1491033002:
  Create RenderSurface on Effect Tree  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@alwayspt| 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 #if DCHECK_IS_ON() | |
| 24 template <typename LayerType> | |
| 25 static void ValidateRenderSurfaces(LayerType* layer) { | |
| 26 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 27 ValidateRenderSurfaces(layer->child_at(i)); | |
| 28 } | |
| 29 | |
| 30 // This test verifies that there are no cases where a LayerImpl needs | |
| 31 // a render surface, but doesn't have one. | |
| 32 if (layer->has_render_surface()) | |
| 33 return; | |
| 34 | |
| 35 DCHECK(layer->filters().IsEmpty()) << "layer: " << layer->id(); | |
| 36 DCHECK(layer->background_filters().IsEmpty()) << "layer: " << layer->id(); | |
| 37 DCHECK(layer->parent()) << "layer: " << layer->id(); | |
| 38 if (layer->parent()->replica_layer() == layer) | |
| 39 return; | |
| 40 DCHECK(!layer->mask_layer()) << "layer: " << layer->id(); | |
| 41 DCHECK(!layer->replica_layer()) << "layer: " << layer->id(); | |
| 42 DCHECK(!layer->is_root_for_isolated_group()) << "layer: " << layer->id(); | |
| 43 DCHECK(!layer->HasCopyRequest()) << "layer: " << layer->id(); | |
| 44 } | |
| 45 #endif | |
| 46 | |
| 23 template <typename LayerType> | 47 template <typename LayerType> | 
| 24 void CalculateVisibleRects(const std::vector<LayerType*>& visible_layer_list, | 48 void CalculateVisibleRects(const std::vector<LayerType*>& visible_layer_list, | 
| 25 const ClipTree& clip_tree, | 49 const ClipTree& clip_tree, | 
| 26 const TransformTree& transform_tree, | 50 const TransformTree& transform_tree, | 
| 27 bool non_root_surfaces_enabled) { | 51 bool non_root_surfaces_enabled) { | 
| 28 for (auto& layer : visible_layer_list) { | 52 for (auto& layer : visible_layer_list) { | 
| 29 gfx::Size layer_bounds = layer->bounds(); | 53 gfx::Size layer_bounds = layer->bounds(); | 
| 30 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); | 54 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); | 
| 31 const bool is_unclipped = clip_node->data.resets_clip && | 55 const bool is_unclipped = clip_node->data.resets_clip && | 
| 32 !clip_node->data.applies_local_clip && | 56 !clip_node->data.applies_local_clip && | 
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 if (LayerType* mask_layer = replica_layer->mask_layer()) | 455 if (LayerType* mask_layer = replica_layer->mask_layer()) | 
| 432 update_layer_list->push_back(mask_layer); | 456 update_layer_list->push_back(mask_layer); | 
| 433 } | 457 } | 
| 434 | 458 | 
| 435 for (size_t i = 0; i < layer->children().size(); ++i) { | 459 for (size_t i = 0; i < layer->children().size(); ++i) { | 
| 436 FindLayersThatNeedUpdates(layer->child_at(i), tree, layer_is_drawn, | 460 FindLayersThatNeedUpdates(layer->child_at(i), tree, layer_is_drawn, | 
| 437 update_layer_list, visible_layer_list); | 461 update_layer_list, visible_layer_list); | 
| 438 } | 462 } | 
| 439 } | 463 } | 
| 440 | 464 | 
| 465 void UpdateRenderSurfacesWithEffectTree(EffectTree* effect_tree, | |
| 
enne (OOO)
2015/12/02 21:59:51
I'm a little confused why there needs to be an upd
 
weiliangc
2015/12/04 00:54:53
For not remembering convenient thing such as owner
 | |
| 466 Layer* layer, | |
| 467 int effect_tree_id) { | |
| 468 if (layer->effect_tree_index() != effect_tree_id) { | |
| 469 effect_tree_id = layer->effect_tree_index(); | |
| 470 layer->SetHasRenderSurface( | |
| 471 effect_tree->Node(effect_tree_id)->data.has_render_surface); | |
| 472 } else { | |
| 473 layer->SetHasRenderSurface(false); | |
| 474 } | |
| 475 | |
| 476 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 477 UpdateRenderSurfacesWithEffectTree(effect_tree, layer->child_at(i), | |
| 478 effect_tree_id); | |
| 479 } | |
| 480 } | |
| 481 | |
| 482 void UpdateRenderSurfacesWithEffectTree(EffectTree* effect_tree, | |
| 483 bool non_root_surfaces_enabled, | |
| 484 LayerImpl* layer, | |
| 485 int effect_tree_id) { | |
| 486 if (!non_root_surfaces_enabled) { | |
| 487 if (!layer->parent()) { | |
| 488 layer->SetHasRenderSurface(true); | |
| 489 } else { | |
| 490 layer->SetHasRenderSurface(false); | |
| 491 } | |
| 492 } else if (layer->effect_tree_index() != effect_tree_id) { | |
| 493 effect_tree_id = layer->effect_tree_index(); | |
| 494 layer->SetHasRenderSurface( | |
| 495 effect_tree->Node(effect_tree_id)->data.has_render_surface); | |
| 496 } else { | |
| 497 layer->SetHasRenderSurface(false); | |
| 498 } | |
| 499 | |
| 500 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 501 UpdateRenderSurfacesWithEffectTree(effect_tree, non_root_surfaces_enabled, | |
| 502 layer->child_at(i), effect_tree_id); | |
| 503 } | |
| 504 } | |
| 505 | |
| 441 } // namespace | 506 } // namespace | 
| 442 | 507 | 
| 443 static void ResetIfHasNanCoordinate(gfx::RectF* rect) { | 508 static void ResetIfHasNanCoordinate(gfx::RectF* rect) { | 
| 444 if (std::isnan(rect->x()) || std::isnan(rect->y()) || | 509 if (std::isnan(rect->x()) || std::isnan(rect->y()) || | 
| 445 std::isnan(rect->right()) || std::isnan(rect->bottom())) | 510 std::isnan(rect->right()) || std::isnan(rect->bottom())) | 
| 446 *rect = gfx::RectF(); | 511 *rect = gfx::RectF(); | 
| 447 } | 512 } | 
| 448 | 513 | 
| 449 void ComputeClips(ClipTree* clip_tree, | 514 void ComputeClips(ClipTree* clip_tree, | 
| 450 const TransformTree& transform_tree, | 515 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()); | 558 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 | 559 // 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 | 560 // of a singular transform. We won't draw in this case, so there's no need | 
| 496 // to compute clips. | 561 // to compute clips. | 
| 497 if (!success) | 562 if (!success) | 
| 498 continue; | 563 continue; | 
| 499 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( | 564 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( | 
| 500 parent_to_current, | 565 parent_to_current, | 
| 501 parent_clip_node->data.combined_clip_in_target_space); | 566 parent_clip_node->data.combined_clip_in_target_space); | 
| 502 } | 567 } | 
| 503 | |
| 504 // Only nodes affected by ancestor clips will have their clip adjusted due | 568 // 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 | 569 // 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 | 570 // 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, | 571 // need to clip using our parent clip and if we don't propagate it here, | 
| 508 // it will be lost. | 572 // it will be lost. | 
| 509 if (clip_node->data.resets_clip && non_root_surfaces_enabled) { | 573 if (clip_node->data.resets_clip && non_root_surfaces_enabled) { | 
| 510 if (clip_node->data.applies_local_clip) { | 574 if (clip_node->data.applies_local_clip) { | 
| 511 clip_node->data.clip_in_target_space = MathUtil::MapClippedRect( | 575 clip_node->data.clip_in_target_space = MathUtil::MapClippedRect( | 
| 512 transform_node->data.to_target, clip_node->data.clip); | 576 transform_node->data.to_target, clip_node->data.clip); | 
| 513 ResetIfHasNanCoordinate(&clip_node->data.clip_in_target_space); | 577 ResetIfHasNanCoordinate(&clip_node->data.clip_in_target_space); | 
| 514 clip_node->data.combined_clip_in_target_space = | 578 clip_node->data.combined_clip_in_target_space = | 
| 515 gfx::IntersectRects(clip_node->data.clip_in_target_space, | 579 gfx::IntersectRects(clip_node->data.clip_in_target_space, | 
| 516 parent_combined_clip_in_target_space); | 580 parent_combined_clip_in_target_space); | 
| 517 } else { | 581 } else { | 
| 518 DCHECK(!clip_node->data.target_is_clipped); | 582 DCHECK(!clip_node->data.target_is_clipped); | 
| 519 DCHECK(!clip_node->data.layers_are_clipped); | 583 DCHECK(!clip_node->data.layers_are_clipped); | 
| 520 clip_node->data.combined_clip_in_target_space = | 584 clip_node->data.combined_clip_in_target_space = | 
| 521 parent_combined_clip_in_target_space; | 585 parent_combined_clip_in_target_space; | 
| 522 } | 586 } | 
| 523 ResetIfHasNanCoordinate(&clip_node->data.combined_clip_in_target_space); | 587 ResetIfHasNanCoordinate(&clip_node->data.combined_clip_in_target_space); | 
| 524 continue; | 588 continue; | 
| 525 } | 589 } | 
| 526 | |
| 527 bool use_only_parent_clip = !clip_node->data.applies_local_clip; | 590 bool use_only_parent_clip = !clip_node->data.applies_local_clip; | 
| 528 if (use_only_parent_clip) { | 591 if (use_only_parent_clip) { | 
| 529 clip_node->data.combined_clip_in_target_space = | 592 clip_node->data.combined_clip_in_target_space = | 
| 530 parent_combined_clip_in_target_space; | 593 parent_combined_clip_in_target_space; | 
| 531 if (!non_root_surfaces_enabled) { | 594 if (!non_root_surfaces_enabled) { | 
| 532 clip_node->data.clip_in_target_space = | 595 clip_node->data.clip_in_target_space = | 
| 533 parent_clip_node->data.clip_in_target_space; | 596 parent_clip_node->data.clip_in_target_space; | 
| 534 } else if (!clip_node->data.target_is_clipped) { | 597 } else if (!clip_node->data.target_is_clipped) { | 
| 535 clip_node->data.clip_in_target_space = | 598 clip_node->data.clip_in_target_space = | 
| 536 parent_combined_clip_in_target_space; | 599 parent_combined_clip_in_target_space; | 
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 float device_scale_factor, | 701 float device_scale_factor, | 
| 639 const gfx::Rect& viewport, | 702 const gfx::Rect& viewport, | 
| 640 const gfx::Transform& device_transform, | 703 const gfx::Transform& device_transform, | 
| 641 bool can_render_to_separate_surface, | 704 bool can_render_to_separate_surface, | 
| 642 PropertyTrees* property_trees, | 705 PropertyTrees* property_trees, | 
| 643 LayerList* update_layer_list) { | 706 LayerList* update_layer_list) { | 
| 644 PropertyTreeBuilder::BuildPropertyTrees( | 707 PropertyTreeBuilder::BuildPropertyTrees( | 
| 645 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 708 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 
| 646 outer_viewport_scroll_layer, page_scale_factor, device_scale_factor, | 709 outer_viewport_scroll_layer, page_scale_factor, device_scale_factor, | 
| 647 viewport, device_transform, property_trees); | 710 viewport, device_transform, property_trees); | 
| 711 UpdateRenderSurfacesWithEffectTree(&property_trees->effect_tree, root_layer, | |
| 712 0); | |
| 713 #if DCHECK_IS_ON() | |
| 
enne (OOO)
2015/12/02 21:59:51
I kind of hate DCHECK_IS_ON ifdef proliferation.
 
weiliangc
2015/12/04 00:54:53
Done.
 | |
| 714 ValidateRenderSurfaces(root_layer); | |
| 715 #endif | |
| 648 ComputeVisibleRectsUsingPropertyTrees(root_layer, property_trees, | 716 ComputeVisibleRectsUsingPropertyTrees(root_layer, property_trees, | 
| 649 can_render_to_separate_surface, | 717 can_render_to_separate_surface, | 
| 650 update_layer_list); | 718 update_layer_list); | 
| 651 } | 719 } | 
| 652 | 720 | 
| 653 void BuildPropertyTreesAndComputeVisibleRects( | 721 void BuildPropertyTreesAndComputeVisibleRects( | 
| 654 LayerImpl* root_layer, | 722 LayerImpl* root_layer, | 
| 655 const LayerImpl* page_scale_layer, | 723 const LayerImpl* page_scale_layer, | 
| 656 const LayerImpl* inner_viewport_scroll_layer, | 724 const LayerImpl* inner_viewport_scroll_layer, | 
| 657 const LayerImpl* outer_viewport_scroll_layer, | 725 const LayerImpl* outer_viewport_scroll_layer, | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 678 std::vector<Layer*> visible_layer_list; | 746 std::vector<Layer*> visible_layer_list; | 
| 679 ComputeVisibleRectsUsingPropertyTreesInternal( | 747 ComputeVisibleRectsUsingPropertyTreesInternal( | 
| 680 root_layer, property_trees, can_render_to_separate_surface, | 748 root_layer, property_trees, can_render_to_separate_surface, | 
| 681 update_layer_list, &visible_layer_list); | 749 update_layer_list, &visible_layer_list); | 
| 682 } | 750 } | 
| 683 | 751 | 
| 684 void ComputeVisibleRectsUsingPropertyTrees(LayerImpl* root_layer, | 752 void ComputeVisibleRectsUsingPropertyTrees(LayerImpl* root_layer, | 
| 685 PropertyTrees* property_trees, | 753 PropertyTrees* property_trees, | 
| 686 bool can_render_to_separate_surface, | 754 bool can_render_to_separate_surface, | 
| 687 LayerImplList* visible_layer_list) { | 755 LayerImplList* visible_layer_list) { | 
| 756 UpdateRenderSurfacesWithEffectTree(&property_trees->effect_tree, | |
| 757 can_render_to_separate_surface, root_layer, | |
| 758 0); | |
| 759 #if DCHECK_IS_ON() | |
| 760 if (can_render_to_separate_surface) | |
| 761 ValidateRenderSurfaces(root_layer); | |
| 762 #endif | |
| 688 LayerImplList update_layer_list; | 763 LayerImplList update_layer_list; | 
| 689 ComputeVisibleRectsUsingPropertyTreesInternal( | 764 ComputeVisibleRectsUsingPropertyTreesInternal( | 
| 690 root_layer, property_trees, can_render_to_separate_surface, | 765 root_layer, property_trees, can_render_to_separate_surface, | 
| 691 &update_layer_list, visible_layer_list); | 766 &update_layer_list, visible_layer_list); | 
| 692 } | 767 } | 
| 693 | 768 | 
| 694 template <typename LayerType> | 769 template <typename LayerType> | 
| 695 static gfx::Transform DrawTransformFromPropertyTreesInternal( | 770 static gfx::Transform DrawTransformFromPropertyTreesInternal( | 
| 696 const LayerType* layer, | 771 const LayerType* layer, | 
| 697 const TransformNode* node) { | 772 const TransformNode* node) { | 
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 const Layer* page_scale_layer, | 1146 const Layer* page_scale_layer, | 
| 1072 float page_scale_factor, | 1147 float page_scale_factor, | 
| 1073 float device_scale_factor, | 1148 float device_scale_factor, | 
| 1074 const gfx::Transform device_transform) { | 1149 const gfx::Transform device_transform) { | 
| 1075 UpdatePageScaleFactorInPropertyTreesInternal( | 1150 UpdatePageScaleFactorInPropertyTreesInternal( | 
| 1076 property_trees, page_scale_layer, page_scale_factor, device_scale_factor, | 1151 property_trees, page_scale_layer, page_scale_factor, device_scale_factor, | 
| 1077 device_transform); | 1152 device_transform); | 
| 1078 } | 1153 } | 
| 1079 | 1154 | 
| 1080 } // namespace cc | 1155 } // namespace cc | 
| OLD | NEW |