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

Side by Side Diff: cc/trees/property_tree.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/property_tree.h ('k') | cc/trees/property_tree_builder.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 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 742
743 StickyPositionNodeData* TransformTree::StickyPositionData(int node_id) { 743 StickyPositionNodeData* TransformTree::StickyPositionData(int node_id) {
744 TransformNode* node = Node(node_id); 744 TransformNode* node = Node(node_id);
745 if (node->sticky_position_constraint_id == -1) { 745 if (node->sticky_position_constraint_id == -1) {
746 node->sticky_position_constraint_id = sticky_position_data_.size(); 746 node->sticky_position_constraint_id = sticky_position_data_.size();
747 sticky_position_data_.push_back(StickyPositionNodeData()); 747 sticky_position_data_.push_back(StickyPositionNodeData());
748 } 748 }
749 return &sticky_position_data_[node->sticky_position_constraint_id]; 749 return &sticky_position_data_[node->sticky_position_constraint_id];
750 } 750 }
751 751
752 EffectTree::EffectTree() {} 752 EffectTree::EffectTree() {
753 render_surfaces_.push_back(nullptr);
754 }
753 755
754 EffectTree::~EffectTree() {} 756 EffectTree::~EffectTree() {}
755 757
758 int EffectTree::Insert(const EffectNode& tree_node, int parent_id) {
759 int node_id = PropertyTree<EffectNode>::Insert(tree_node, parent_id);
760 DCHECK_EQ(node_id, static_cast<int>(render_surfaces_.size()));
761
762 render_surfaces_.push_back(nullptr);
763 return node_id;
764 }
765
756 void EffectTree::clear() { 766 void EffectTree::clear() {
757 PropertyTree<EffectNode>::clear(); 767 PropertyTree<EffectNode>::clear();
758 mask_layer_ids_.clear(); 768 mask_layer_ids_.clear();
769 render_surfaces_.clear();
770 render_surfaces_.push_back(nullptr);
759 771
760 #if DCHECK_IS_ON() 772 #if DCHECK_IS_ON()
761 EffectTree tree; 773 EffectTree tree;
762 DCHECK(tree == *this); 774 DCHECK(tree == *this);
763 #endif 775 #endif
764 } 776 }
765 777
766 float EffectTree::EffectiveOpacity(const EffectNode* node) const { 778 float EffectTree::EffectiveOpacity(const EffectNode* node) const {
767 return node->subtree_hidden ? 0.f : node->opacity; 779 return node->subtree_hidden ? 0.f : node->opacity;
768 } 780 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 if (node->has_copy_request) 982 if (node->has_copy_request)
971 return node->id; 983 return node->id;
972 else 984 else
973 return EffectTree::kInvalidNodeId; 985 return EffectTree::kInvalidNodeId;
974 } 986 }
975 987
976 void EffectTree::AddMaskLayerId(int id) { 988 void EffectTree::AddMaskLayerId(int id) {
977 mask_layer_ids_.push_back(id); 989 mask_layer_ids_.push_back(id);
978 } 990 }
979 991
992 void EffectTree::UpdateRenderSurfaces(LayerTreeImpl* layer_tree_impl,
993 bool non_root_surfaces_enabled) {
994 for (int id = kContentsRootNodeId; id < static_cast<int>(size()); ++id) {
995 EffectNode* effect_node = Node(id);
996 bool needs_render_surface =
997 id == kContentsRootNodeId ||
998 (non_root_surfaces_enabled && effect_node->has_render_surface);
999 if (needs_render_surface == !!render_surfaces_[id])
1000 continue;
1001
1002 if (needs_render_surface) {
1003 render_surfaces_[id] = base::MakeUnique<RenderSurfaceImpl>(
1004 layer_tree_impl, effect_node->owning_layer_id);
1005 render_surfaces_[id]->set_effect_tree_index(id);
1006 } else {
1007 render_surfaces_[id].reset();
1008 }
1009 }
1010 }
1011
980 bool EffectTree::ContributesToDrawnSurface(int id) { 1012 bool EffectTree::ContributesToDrawnSurface(int id) {
981 // All drawn nodes contribute to drawn surface. 1013 // All drawn nodes contribute to drawn surface.
982 // Exception : Nodes that are hidden and are drawn only for the sake of 1014 // Exception : Nodes that are hidden and are drawn only for the sake of
983 // copy requests. 1015 // copy requests.
984 EffectNode* node = Node(id); 1016 EffectNode* node = Node(id);
985 EffectNode* parent_node = parent(node); 1017 EffectNode* parent_node = parent(node);
986 return node->is_drawn && (!parent_node || parent_node->is_drawn); 1018 return node->is_drawn && (!parent_node || parent_node->is_drawn);
987 } 1019 }
988 1020
989 void EffectTree::ResetChangeTracking() { 1021 void EffectTree::ResetChangeTracking() {
990 for (int id = EffectTree::kContentsRootNodeId; id < static_cast<int>(size()); 1022 for (int id = EffectTree::kContentsRootNodeId; id < static_cast<int>(size());
991 ++id) { 1023 ++id) {
992 EffectNode* node = Node(id); 1024 Node(id)->effect_changed = false;
993 node->effect_changed = false; 1025 if (render_surfaces_[id])
1026 render_surfaces_[id]->ResetPropertyChangedFlags();
994 } 1027 }
995 } 1028 }
996 1029
997 EffectTree::StableIdRenderSurfaceList 1030 void EffectTree::TakeRenderSurfaces(
998 EffectTree::CreateStableIdRenderSurfaceList() const { 1031 std::vector<std::unique_ptr<RenderSurfaceImpl>>* render_surfaces) {
999 StableIdRenderSurfaceList stable_id_render_surface_list;
1000 for (int id = kContentsRootNodeId; id < static_cast<int>(size()); ++id) { 1032 for (int id = kContentsRootNodeId; id < static_cast<int>(size()); ++id) {
1001 const EffectNode* node = Node(id); 1033 if (render_surfaces_[id]) {
1002 if (node->render_surface) { 1034 render_surfaces->push_back(std::move(render_surfaces_[id]));
1003 stable_id_render_surface_list.push_back(
1004 std::make_pair(node->owning_layer_id, node->render_surface));
1005 } 1035 }
1006 } 1036 }
1007 std::sort(stable_id_render_surface_list.begin(),
1008 stable_id_render_surface_list.end());
1009 return stable_id_render_surface_list;
1010 } 1037 }
1011 1038
1012 void EffectTree::UpdateRenderSurfaceEffectIds( 1039 bool EffectTree::CreateOrReuseRenderSurfaces(
1013 const EffectTree::StableIdRenderSurfaceList& stable_id_render_surface_list, 1040 std::vector<std::unique_ptr<RenderSurfaceImpl>>* old_render_surfaces,
1014 LayerTreeImpl* layer_tree_impl) { 1041 LayerTreeImpl* layer_tree_impl) {
1015 // Make a list of {stable id, node id} pairs for nodes that are supposed to 1042 // Make a list of {stable id, node id} pairs for nodes that are supposed to
1016 // have surfaces. 1043 // have surfaces.
1017 std::vector<std::pair<int, int>> stable_id_node_id_list; 1044 std::vector<std::pair<int, int>> stable_id_node_id_list;
1018 for (int id = kContentsRootNodeId; id < static_cast<int>(size()); ++id) { 1045 for (int id = kContentsRootNodeId; id < static_cast<int>(size()); ++id) {
1019 const EffectNode* node = Node(id); 1046 EffectNode* node = Node(id);
1020 if (node->has_render_surface) { 1047 if (node->has_render_surface) {
1021 stable_id_node_id_list.push_back( 1048 stable_id_node_id_list.push_back(
1022 std::make_pair(node->owning_layer_id, node->id)); 1049 std::make_pair(node->owning_layer_id, node->id));
1023 } 1050 }
1024 } 1051 }
1025 1052
1026 // Sort by stable id so that we can process the two lists cosequentially. 1053 // Sort by stable id so that we can process the two lists cosequentially.
1027 std::sort(stable_id_node_id_list.begin(), stable_id_node_id_list.end()); 1054 std::sort(stable_id_node_id_list.begin(), stable_id_node_id_list.end());
1055 std::sort(old_render_surfaces->begin(), old_render_surfaces->end(),
1056 [](const std::unique_ptr<RenderSurfaceImpl>& a,
1057 const std::unique_ptr<RenderSurfaceImpl>& b) {
1058 return a->id() < b->id();
1059 });
1028 1060
1029 auto surface_list_it = stable_id_render_surface_list.begin(); 1061 bool render_surfaces_changed = false;
1030 auto node_id_list_it = stable_id_node_id_list.begin(); 1062 auto surfaces_list_it = old_render_surfaces->begin();
1031 while (surface_list_it != stable_id_render_surface_list.end() && 1063 auto id_list_it = stable_id_node_id_list.begin();
1032 node_id_list_it != stable_id_node_id_list.end()) { 1064 while (surfaces_list_it != old_render_surfaces->end() &&
1033 if (surface_list_it->first == node_id_list_it->first) { 1065 id_list_it != stable_id_node_id_list.end()) {
1034 RenderSurfaceImpl* surface = surface_list_it->second; 1066 if ((*surfaces_list_it)->id() == id_list_it->first) {
1035 int node_id = node_id_list_it->second; 1067 int new_node_id = id_list_it->second;
1036 Node(node_id)->render_surface = surface; 1068 render_surfaces_[new_node_id] = std::move(*surfaces_list_it);
1037 surface->set_effect_tree_index(node_id); 1069 render_surfaces_[new_node_id]->set_effect_tree_index(new_node_id);
1038 surface_list_it++; 1070 surfaces_list_it++;
1039 node_id_list_it++; 1071 id_list_it++;
1040 continue; 1072 continue;
1041 } 1073 }
1042 1074
1043 if (surface_list_it->first > node_id_list_it->first) { 1075 render_surfaces_changed = true;
1044 node_id_list_it++; 1076
1045 continue; 1077 if ((*surfaces_list_it)->id() > id_list_it->first) {
1078 int new_node_id = id_list_it->second;
1079 render_surfaces_[new_node_id] = base::MakeUnique<RenderSurfaceImpl>(
1080 layer_tree_impl, id_list_it->first);
1081 render_surfaces_[new_node_id]->set_effect_tree_index(new_node_id);
1082 id_list_it++;
1083 } else {
1084 surfaces_list_it++;
1046 } 1085 }
1047
1048 // If we reach here, there's no longer an effect node with stable id
1049 // |surface_list_it->first| that has a render surface. If there's no longer
1050 // any corresponding layer either, there's nothing more to do since the
1051 // surface owned by that layer would have been destroyed when the layer was
1052 // destroyed. But if the layer still exists, we need to destroy the surface
1053 // since it now has an invalid effect node id.
1054 if (LayerImpl* layer_impl =
1055 layer_tree_impl->LayerById(surface_list_it->first)) {
1056 layer_impl->SetHasRenderSurface(false);
1057 }
1058 surface_list_it++;
1059 } 1086 }
1060 1087
1061 while (surface_list_it != stable_id_render_surface_list.end()) { 1088 if (surfaces_list_it != old_render_surfaces->end() ||
1062 if (LayerImpl* layer_impl = 1089 id_list_it != stable_id_node_id_list.end()) {
1063 layer_tree_impl->LayerById(surface_list_it->first)) { 1090 render_surfaces_changed = true;
1064 layer_impl->SetHasRenderSurface(false);
1065 }
1066 surface_list_it++;
1067 } 1091 }
1092
1093 while (id_list_it != stable_id_node_id_list.end()) {
1094 int new_node_id = id_list_it->second;
1095 render_surfaces_[new_node_id] =
1096 base::MakeUnique<RenderSurfaceImpl>(layer_tree_impl, id_list_it->first);
1097 render_surfaces_[new_node_id]->set_effect_tree_index(new_node_id);
1098 id_list_it++;
1099 }
1100
1101 return render_surfaces_changed;
1068 } 1102 }
1069 1103
1070 void TransformTree::UpdateNodeAndAncestorsHaveIntegerTranslations( 1104 void TransformTree::UpdateNodeAndAncestorsHaveIntegerTranslations(
1071 TransformNode* node, 1105 TransformNode* node,
1072 TransformNode* parent_node) { 1106 TransformNode* parent_node) {
1073 DCHECK(parent_node); 1107 DCHECK(parent_node);
1074 node->node_and_ancestors_have_only_integer_translation = 1108 node->node_and_ancestors_have_only_integer_translation =
1075 node->to_parent.IsIdentityOrIntegerTranslation() && 1109 node->to_parent.IsIdentityOrIntegerTranslation() &&
1076 parent_node->node_and_ancestors_have_only_integer_translation; 1110 parent_node->node_and_ancestors_have_only_integer_translation;
1077 } 1111 }
(...skipping 13 matching lines...) Expand all
1091 DCHECK_GT(size(), min_size); 1125 DCHECK_GT(size(), min_size);
1092 return Node(kViewportNodeId)->clip; 1126 return Node(kViewportNodeId)->clip;
1093 } 1127 }
1094 1128
1095 bool ClipTree::operator==(const ClipTree& other) const { 1129 bool ClipTree::operator==(const ClipTree& other) const {
1096 return PropertyTree::operator==(other); 1130 return PropertyTree::operator==(other);
1097 } 1131 }
1098 1132
1099 EffectTree& EffectTree::operator=(const EffectTree& from) { 1133 EffectTree& EffectTree::operator=(const EffectTree& from) {
1100 PropertyTree::operator=(from); 1134 PropertyTree::operator=(from);
1135 render_surfaces_.resize(size());
1101 mask_layer_ids_ = from.mask_layer_ids_; 1136 mask_layer_ids_ = from.mask_layer_ids_;
1102 // copy_requests_ are omitted here, since these need to be moved rather 1137 // copy_requests_ are omitted here, since these need to be moved rather
1103 // than copied or assigned. 1138 // than copied or assigned.
1139
1104 return *this; 1140 return *this;
1105 } 1141 }
1106 1142
1107 bool EffectTree::operator==(const EffectTree& other) const { 1143 bool EffectTree::operator==(const EffectTree& other) const {
1108 return PropertyTree::operator==(other) && 1144 return PropertyTree::operator==(other) &&
1109 mask_layer_ids_ == other.mask_layer_ids_; 1145 mask_layer_ids_ == other.mask_layer_ids_;
1110 } 1146 }
1111 1147
1112 ScrollTree::ScrollTree() 1148 ScrollTree::ScrollTree()
1113 : currently_scrolling_node_id_(kInvalidNodeId), 1149 : currently_scrolling_node_id_(kInvalidNodeId),
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 2132
2097 const EffectNode* effect_node = effect_tree.Node(effect_id); 2133 const EffectNode* effect_node = effect_tree.Node(effect_id);
2098 2134
2099 bool success = GetFromTarget(transform_id, effect_id, transform); 2135 bool success = GetFromTarget(transform_id, effect_id, transform);
2100 transform->Scale(effect_node->surface_contents_scale.x(), 2136 transform->Scale(effect_node->surface_contents_scale.x(),
2101 effect_node->surface_contents_scale.y()); 2137 effect_node->surface_contents_scale.y());
2102 return success; 2138 return success;
2103 } 2139 }
2104 2140
2105 } // namespace cc 2141 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/property_tree.h ('k') | cc/trees/property_tree_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698