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

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

Issue 2690753002: cc: Move render surface ownership from layers to the effect tree (Closed)
Patch Set: Only update surfaces when can_render_to_separate_surface changes Created 3 years, 10 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/damage_tracker.cc ('k') | cc/trees/effect_node.h » ('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 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 namespace { 27 namespace {
28 28
29 static bool IsRootLayer(const Layer* layer) { 29 static bool IsRootLayer(const Layer* layer) {
30 return !layer->parent(); 30 return !layer->parent();
31 } 31 }
32 32
33 static bool IsRootLayer(const LayerImpl* layer) { 33 static bool IsRootLayer(const LayerImpl* layer) {
34 return layer->layer_tree_impl()->IsRootLayer(layer); 34 return layer->layer_tree_impl()->IsRootLayer(layer);
35 } 35 }
36 36
37 #if DCHECK_IS_ON()
38 static void ValidateRenderSurfaceForLayer(LayerImpl* layer) {
39 // This test verifies that there are no cases where a LayerImpl needs
40 // a render surface, but doesn't have one.
41 if (layer->has_render_surface())
42 return;
43
44 DCHECK(!IsRootLayer(layer)) << "layer: " << layer->id();
45 EffectNode* effect_node =
46 layer->layer_tree_impl()->property_trees()->effect_tree.Node(
47 layer->effect_tree_index());
48 if (effect_node->owning_layer_id != layer->id())
49 return;
50 DCHECK_EQ(effect_node->mask_layer_id, EffectTree::kInvalidNodeId)
51 << "layer: " << layer->id();
52 DCHECK(effect_node->filters.IsEmpty());
53 DCHECK(effect_node->background_filters.IsEmpty());
54 }
55 #endif
56
57 static const EffectNode* ContentsTargetEffectNode( 37 static const EffectNode* ContentsTargetEffectNode(
58 const int effect_tree_index, 38 const int effect_tree_index,
59 const EffectTree& effect_tree) { 39 const EffectTree& effect_tree) {
60 const EffectNode* effect_node = effect_tree.Node(effect_tree_index); 40 const EffectNode* effect_node = effect_tree.Node(effect_tree_index);
61 return effect_node->render_surface ? effect_node 41 return effect_tree.GetRenderSurface(effect_tree_index)
62 : effect_tree.Node(effect_node->target_id); 42 ? effect_node
43 : effect_tree.Node(effect_node->target_id);
63 } 44 }
64 45
65 bool ComputeClipRectInTargetSpace(const LayerImpl* layer, 46 bool ComputeClipRectInTargetSpace(const LayerImpl* layer,
66 const ClipNode* clip_node, 47 const ClipNode* clip_node,
67 const PropertyTrees* property_trees, 48 const PropertyTrees* property_trees,
68 int target_node_id, 49 int target_node_id,
69 bool for_visible_rect_calculation, 50 bool for_visible_rect_calculation,
70 gfx::RectF* clip_rect_in_target_space) { 51 gfx::RectF* clip_rect_in_target_space) {
71 DCHECK(layer->clip_tree_index() == clip_node->id); 52 DCHECK(layer->clip_tree_index() == clip_node->id);
72 DCHECK(clip_node->target_transform_id != target_node_id); 53 DCHECK(clip_node->target_transform_id != target_node_id);
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 continue; 689 continue;
709 690
710 bool layer_is_drawn = 691 bool layer_is_drawn =
711 effect_tree.Node(layer_impl->effect_tree_index())->is_drawn; 692 effect_tree.Node(layer_impl->effect_tree_index())->is_drawn;
712 693
713 if (LayerNeedsUpdate(layer_impl, layer_is_drawn, property_trees)) 694 if (LayerNeedsUpdate(layer_impl, layer_is_drawn, property_trees))
714 visible_layer_list->push_back(layer_impl); 695 visible_layer_list->push_back(layer_impl);
715 } 696 }
716 } 697 }
717 698
718 void UpdateRenderSurfaceForLayer(EffectTree* effect_tree,
719 bool non_root_surfaces_enabled,
720 LayerImpl* layer) {
721 if (!non_root_surfaces_enabled) {
722 layer->SetHasRenderSurface(IsRootLayer(layer));
723 return;
724 }
725
726 EffectNode* node = effect_tree->Node(layer->effect_tree_index());
727
728 if (node->owning_layer_id == layer->id() && node->has_render_surface)
729 layer->SetHasRenderSurface(true);
730 else
731 layer->SetHasRenderSurface(false);
732 }
733 } // namespace 699 } // namespace
734 700
735 template <typename LayerType> 701 template <typename LayerType>
736 static inline bool LayerShouldBeSkippedInternal( 702 static inline bool LayerShouldBeSkippedInternal(
737 LayerType* layer, 703 LayerType* layer,
738 const TransformTree& transform_tree, 704 const TransformTree& transform_tree,
739 const EffectTree& effect_tree) { 705 const EffectTree& effect_tree) {
740 const TransformNode* transform_node = 706 const TransformNode* transform_node =
741 transform_tree.Node(layer->transform_tree_index()); 707 transform_tree.Node(layer->transform_tree_index());
742 const EffectNode* effect_node = effect_tree.Node(layer->effect_tree_index()); 708 const EffectNode* effect_node = effect_tree.Node(layer->effect_tree_index());
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 return; 970 return;
1005 for (int i = EffectTree::kContentsRootNodeId; 971 for (int i = EffectTree::kContentsRootNodeId;
1006 i < static_cast<int>(effect_tree->size()); ++i) 972 i < static_cast<int>(effect_tree->size()); ++i)
1007 effect_tree->UpdateEffects(i); 973 effect_tree->UpdateEffects(i);
1008 effect_tree->set_needs_update(false); 974 effect_tree->set_needs_update(false);
1009 } 975 }
1010 976
1011 static void ComputeClipsWithEffectTree(PropertyTrees* property_trees) { 977 static void ComputeClipsWithEffectTree(PropertyTrees* property_trees) {
1012 EffectTree* effect_tree = &property_trees->effect_tree; 978 EffectTree* effect_tree = &property_trees->effect_tree;
1013 const ClipTree* clip_tree = &property_trees->clip_tree; 979 const ClipTree* clip_tree = &property_trees->clip_tree;
1014 EffectNode* root_effect_node = effect_tree->Node(1); 980 EffectNode* root_effect_node =
981 effect_tree->Node(EffectTree::kContentsRootNodeId);
1015 const RenderSurfaceImpl* root_render_surface = 982 const RenderSurfaceImpl* root_render_surface =
1016 root_effect_node->render_surface; 983 effect_tree->GetRenderSurface(EffectTree::kContentsRootNodeId);
1017 gfx::Rect root_clip = 984 gfx::Rect root_clip =
1018 gfx::ToEnclosingRect(clip_tree->Node(root_effect_node->clip_id)->clip); 985 gfx::ToEnclosingRect(clip_tree->Node(root_effect_node->clip_id)->clip);
1019 if (root_render_surface->is_clipped()) 986 if (root_render_surface->is_clipped())
1020 DCHECK(root_clip == root_render_surface->clip_rect()) 987 DCHECK(root_clip == root_render_surface->clip_rect())
1021 << "clip on root render surface: " 988 << "clip on root render surface: "
1022 << root_render_surface->clip_rect().ToString() 989 << root_render_surface->clip_rect().ToString()
1023 << " v.s. root effect node's clip: " << root_clip.ToString(); 990 << " v.s. root effect node's clip: " << root_clip.ToString();
1024 for (int i = 2; i < static_cast<int>(effect_tree->size()); ++i) { 991 for (int i = 2; i < static_cast<int>(effect_tree->size()); ++i) {
1025 EffectNode* effect_node = effect_tree->Node(i); 992 EffectNode* effect_node = effect_tree->Node(i);
1026 const EffectNode* target_node = effect_tree->Node(effect_node->target_id); 993 const EffectNode* target_node = effect_tree->Node(effect_node->target_id);
1027 bool include_viewport_clip = false; 994 bool include_viewport_clip = false;
1028 bool include_expanding_clips = false; 995 bool include_expanding_clips = false;
1029 ConditionalClip accumulated_clip_rect = ComputeAccumulatedClip( 996 ConditionalClip accumulated_clip_rect = ComputeAccumulatedClip(
1030 property_trees, include_viewport_clip, include_expanding_clips, 997 property_trees, include_viewport_clip, include_expanding_clips,
1031 effect_node->clip_id, target_node->id); 998 effect_node->clip_id, target_node->id);
1032 gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect; 999 gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect;
1033 const RenderSurfaceImpl* render_surface = effect_node->render_surface; 1000 const RenderSurfaceImpl* render_surface = effect_tree->GetRenderSurface(i);
1034 if (render_surface && render_surface->is_clipped()) { 1001 if (render_surface && render_surface->is_clipped()) {
1035 DCHECK(gfx::ToEnclosingRect(accumulated_clip) == 1002 DCHECK(gfx::ToEnclosingRect(accumulated_clip) ==
1036 render_surface->clip_rect()) 1003 render_surface->clip_rect())
1037 << " render surface's clip rect: " 1004 << " render surface's clip rect: "
1038 << render_surface->clip_rect().ToString() 1005 << render_surface->clip_rect().ToString()
1039 << " v.s. accumulated clip: " 1006 << " v.s. accumulated clip: "
1040 << gfx::ToEnclosingRect(accumulated_clip).ToString(); 1007 << gfx::ToEnclosingRect(accumulated_clip).ToString();
1041 } 1008 }
1042 } 1009 }
1043 } 1010 }
(...skipping 29 matching lines...) Expand all
1073 gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect; 1040 gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect;
1074 1041
1075 DCHECK(layer->clip_rect() == gfx::ToEnclosingRect(accumulated_clip)) 1042 DCHECK(layer->clip_rect() == gfx::ToEnclosingRect(accumulated_clip))
1076 << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index() 1043 << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index()
1077 << " layer clip: " << layer->clip_rect().ToString() << " v.s. " 1044 << " layer clip: " << layer->clip_rect().ToString() << " v.s. "
1078 << gfx::ToEnclosingRect(accumulated_clip).ToString() 1045 << gfx::ToEnclosingRect(accumulated_clip).ToString()
1079 << " and clip node clip: " 1046 << " and clip node clip: "
1080 << gfx::ToEnclosingRect(clip_node->clip_in_target_space).ToString(); 1047 << gfx::ToEnclosingRect(clip_node->clip_in_target_space).ToString();
1081 } 1048 }
1082 1049
1083 static void ComputeVisibleRectsInternal( 1050 void ComputeVisibleRects(LayerImpl* root_layer,
1084 LayerImpl* root_layer, 1051 PropertyTrees* property_trees,
1085 PropertyTrees* property_trees, 1052 bool can_render_to_separate_surface,
1086 bool can_render_to_separate_surface, 1053 LayerImplList* visible_layer_list) {
1087 std::vector<LayerImpl*>* visible_layer_list) { 1054 bool render_surfaces_need_update = false;
1088 if (property_trees->non_root_surfaces_enabled != 1055 if (property_trees->non_root_surfaces_enabled !=
1089 can_render_to_separate_surface) { 1056 can_render_to_separate_surface) {
1090 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; 1057 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface;
1091 property_trees->transform_tree.set_needs_update(true); 1058 property_trees->transform_tree.set_needs_update(true);
1059 render_surfaces_need_update = true;
1092 } 1060 }
1093 if (property_trees->transform_tree.needs_update()) { 1061 if (property_trees->transform_tree.needs_update()) {
1094 property_trees->clip_tree.set_needs_update(true); 1062 property_trees->clip_tree.set_needs_update(true);
1095 property_trees->effect_tree.set_needs_update(true); 1063 property_trees->effect_tree.set_needs_update(true);
1096 } 1064 }
1065
1066 if (render_surfaces_need_update) {
1067 property_trees->effect_tree.UpdateRenderSurfaces(
1068 root_layer->layer_tree_impl(),
1069 property_trees->non_root_surfaces_enabled);
1070 }
1097 UpdateRenderTarget(&property_trees->effect_tree, 1071 UpdateRenderTarget(&property_trees->effect_tree,
1098 property_trees->non_root_surfaces_enabled); 1072 property_trees->non_root_surfaces_enabled);
1099 ComputeTransforms(&property_trees->transform_tree); 1073 ComputeTransforms(&property_trees->transform_tree);
1100 // Computation of clips uses surface contents scale which is updated while 1074 // Computation of clips uses surface contents scale which is updated while
1101 // computing effects. So, ComputeEffects should be before ComputeClips. 1075 // computing effects. So, ComputeEffects should be before ComputeClips.
1102 ComputeEffects(&property_trees->effect_tree); 1076 ComputeEffects(&property_trees->effect_tree);
1103 ComputeClips(property_trees, can_render_to_separate_surface); 1077 ComputeClips(property_trees, can_render_to_separate_surface);
1104 1078
1105 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), property_trees, 1079 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), property_trees,
1106 visible_layer_list); 1080 visible_layer_list);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1127
1154 void VerifyClipTreeCalculations(const LayerImplList& layer_list, 1128 void VerifyClipTreeCalculations(const LayerImplList& layer_list,
1155 PropertyTrees* property_trees) { 1129 PropertyTrees* property_trees) {
1156 if (property_trees->non_root_surfaces_enabled) { 1130 if (property_trees->non_root_surfaces_enabled) {
1157 ComputeClipsWithEffectTree(property_trees); 1131 ComputeClipsWithEffectTree(property_trees);
1158 } 1132 }
1159 for (auto* layer : layer_list) 1133 for (auto* layer : layer_list)
1160 ComputeLayerClipRect(property_trees, layer); 1134 ComputeLayerClipRect(property_trees, layer);
1161 } 1135 }
1162 1136
1163 void ComputeVisibleRects(LayerImpl* root_layer,
1164 PropertyTrees* property_trees,
1165 bool can_render_to_separate_surface,
1166 LayerImplList* visible_layer_list) {
1167 for (auto* layer : *root_layer->layer_tree_impl()) {
1168 UpdateRenderSurfaceForLayer(&property_trees->effect_tree,
1169 can_render_to_separate_surface, layer);
1170 EffectNode* node =
1171 property_trees->effect_tree.Node(layer->effect_tree_index());
1172 if (node->owning_layer_id == layer->id()) {
1173 node->render_surface = layer->render_surface();
1174 if (node->render_surface)
1175 node->render_surface->set_effect_tree_index(node->id);
1176 }
1177 #if DCHECK_IS_ON()
1178 if (can_render_to_separate_surface)
1179 ValidateRenderSurfaceForLayer(layer);
1180 #endif
1181 }
1182 ComputeVisibleRectsInternal(root_layer, property_trees,
1183 can_render_to_separate_surface,
1184 visible_layer_list);
1185 }
1186
1187 gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees, 1137 gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees,
1188 const LayerImpl* layer) { 1138 const LayerImpl* layer) {
1189 int effect_ancestor_with_copy_request = 1139 int effect_ancestor_with_copy_request =
1190 property_trees->effect_tree.ClosestAncestorWithCopyRequest( 1140 property_trees->effect_tree.ClosestAncestorWithCopyRequest(
1191 layer->effect_tree_index()); 1141 layer->effect_tree_index());
1192 bool non_root_copy_request = 1142 bool non_root_copy_request =
1193 effect_ancestor_with_copy_request > EffectTree::kContentsRootNodeId; 1143 effect_ancestor_with_copy_request > EffectTree::kContentsRootNodeId;
1194 gfx::Rect layer_content_rect = gfx::Rect(layer->bounds()); 1144 gfx::Rect layer_content_rect = gfx::Rect(layer->bounds());
1195 gfx::RectF accumulated_clip_in_root_space; 1145 gfx::RectF accumulated_clip_in_root_space;
1196 if (non_root_copy_request) { 1146 if (non_root_copy_request) {
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 void UpdateElasticOverscroll(PropertyTrees* property_trees, 1509 void UpdateElasticOverscroll(PropertyTrees* property_trees,
1560 const Layer* overscroll_elasticity_layer, 1510 const Layer* overscroll_elasticity_layer,
1561 const gfx::Vector2dF& elastic_overscroll) { 1511 const gfx::Vector2dF& elastic_overscroll) {
1562 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, 1512 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer,
1563 elastic_overscroll); 1513 elastic_overscroll);
1564 } 1514 }
1565 1515
1566 } // namespace draw_property_utils 1516 } // namespace draw_property_utils
1567 1517
1568 } // namespace cc 1518 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/damage_tracker.cc ('k') | cc/trees/effect_node.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698