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

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: Replace repeated calls to LayerImpl::render_surface 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
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() : needs_update_render_surfaces_(false) {
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,
jaydasika 2017/02/22 01:29:50 I am confused. Why do we need UpdateRenderSurfaces
ajuma 2017/02/22 22:07:00 Good catch. That was happening for a couple reason
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 needs_update_render_surfaces_ = false;
1011 }
1012
980 bool EffectTree::ContributesToDrawnSurface(int id) { 1013 bool EffectTree::ContributesToDrawnSurface(int id) {
981 // All drawn nodes contribute to drawn surface. 1014 // All drawn nodes contribute to drawn surface.
982 // Exception : Nodes that are hidden and are drawn only for the sake of 1015 // Exception : Nodes that are hidden and are drawn only for the sake of
983 // copy requests. 1016 // copy requests.
984 EffectNode* node = Node(id); 1017 EffectNode* node = Node(id);
985 EffectNode* parent_node = parent(node); 1018 EffectNode* parent_node = parent(node);
986 return node->is_drawn && (!parent_node || parent_node->is_drawn); 1019 return node->is_drawn && (!parent_node || parent_node->is_drawn);
987 } 1020 }
988 1021
989 void EffectTree::ResetChangeTracking() { 1022 void EffectTree::ResetChangeTracking() {
990 for (int id = EffectTree::kContentsRootNodeId; id < static_cast<int>(size()); 1023 for (int id = EffectTree::kContentsRootNodeId; id < static_cast<int>(size());
991 ++id) { 1024 ++id) {
992 EffectNode* node = Node(id); 1025 Node(id)->effect_changed = false;
993 node->effect_changed = false; 1026 if (render_surfaces_[id])
1027 render_surfaces_[id]->ResetPropertyChangedFlags();
994 } 1028 }
995 } 1029 }
996 1030
997 EffectTree::StableIdRenderSurfaceList 1031 void EffectTree::TakeRenderSurfaces(
998 EffectTree::CreateStableIdRenderSurfaceList() const { 1032 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) { 1033 for (int id = kContentsRootNodeId; id < static_cast<int>(size()); ++id) {
1001 const EffectNode* node = Node(id); 1034 if (render_surfaces_[id]) {
1002 if (node->render_surface) { 1035 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 } 1036 }
1006 } 1037 }
1007 std::sort(stable_id_render_surface_list.begin(),
1008 stable_id_render_surface_list.end());
1009 return stable_id_render_surface_list;
1010 } 1038 }
1011 1039
1012 void EffectTree::UpdateRenderSurfaceEffectIds( 1040 void EffectTree::ReuseRenderSurfaces(
1013 const EffectTree::StableIdRenderSurfaceList& stable_id_render_surface_list, 1041 std::vector<std::unique_ptr<RenderSurfaceImpl>>* render_surfaces) {
1014 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(render_surfaces->begin(), 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 auto surfaces_list_it = render_surfaces->begin();
1030 auto node_id_list_it = stable_id_node_id_list.begin(); 1062 auto id_list_it = stable_id_node_id_list.begin();
1031 while (surface_list_it != stable_id_render_surface_list.end() && 1063 while (surfaces_list_it != render_surfaces->end() &&
1032 node_id_list_it != stable_id_node_id_list.end()) { 1064 id_list_it != stable_id_node_id_list.end()) {
1033 if (surface_list_it->first == node_id_list_it->first) { 1065 if ((*surfaces_list_it)->id() == id_list_it->first) {
1034 RenderSurfaceImpl* surface = surface_list_it->second; 1066 int new_node_id = id_list_it->second;
1035 int node_id = node_id_list_it->second; 1067 render_surfaces_[new_node_id] = std::move(*surfaces_list_it);
1036 Node(node_id)->render_surface = surface; 1068 render_surfaces_[new_node_id]->set_effect_tree_index(new_node_id);
1037 surface->set_effect_tree_index(node_id); 1069 surfaces_list_it++;
1038 surface_list_it++; 1070 id_list_it++;
1039 node_id_list_it++;
1040 continue; 1071 continue;
1041 } 1072 }
1042 1073
1043 if (surface_list_it->first > node_id_list_it->first) { 1074 needs_update_render_surfaces_ = true;
1044 node_id_list_it++;
1045 continue;
1046 }
1047 1075
1048 // If we reach here, there's no longer an effect node with stable id 1076 if ((*surfaces_list_it)->id() > id_list_it->first)
1049 // |surface_list_it->first| that has a render surface. If there's no longer 1077 id_list_it++;
1050 // any corresponding layer either, there's nothing more to do since the 1078 else
1051 // surface owned by that layer would have been destroyed when the layer was 1079 surfaces_list_it++;
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 } 1080 }
1060 1081
1061 while (surface_list_it != stable_id_render_surface_list.end()) { 1082 if (surfaces_list_it != render_surfaces->end() ||
1062 if (LayerImpl* layer_impl = 1083 id_list_it != stable_id_node_id_list.end()) {
1063 layer_tree_impl->LayerById(surface_list_it->first)) { 1084 needs_update_render_surfaces_ = true;
1064 layer_impl->SetHasRenderSurface(false);
1065 }
1066 surface_list_it++;
1067 } 1085 }
1068 } 1086 }
1069 1087
1070 void TransformTree::UpdateNodeAndAncestorsHaveIntegerTranslations( 1088 void TransformTree::UpdateNodeAndAncestorsHaveIntegerTranslations(
1071 TransformNode* node, 1089 TransformNode* node,
1072 TransformNode* parent_node) { 1090 TransformNode* parent_node) {
1073 DCHECK(parent_node); 1091 DCHECK(parent_node);
1074 node->node_and_ancestors_have_only_integer_translation = 1092 node->node_and_ancestors_have_only_integer_translation =
1075 node->to_parent.IsIdentityOrIntegerTranslation() && 1093 node->to_parent.IsIdentityOrIntegerTranslation() &&
1076 parent_node->node_and_ancestors_have_only_integer_translation; 1094 parent_node->node_and_ancestors_have_only_integer_translation;
(...skipping 13 matching lines...) Expand all
1090 const unsigned long min_size = 1; 1108 const unsigned long min_size = 1;
1091 DCHECK_GT(size(), min_size); 1109 DCHECK_GT(size(), min_size);
1092 return Node(kViewportNodeId)->clip; 1110 return Node(kViewportNodeId)->clip;
1093 } 1111 }
1094 1112
1095 bool ClipTree::operator==(const ClipTree& other) const { 1113 bool ClipTree::operator==(const ClipTree& other) const {
1096 return PropertyTree::operator==(other); 1114 return PropertyTree::operator==(other);
1097 } 1115 }
1098 1116
1099 EffectTree& EffectTree::operator=(const EffectTree& from) { 1117 EffectTree& EffectTree::operator=(const EffectTree& from) {
1118 // Keep existing render surfaces that still have a corresponding node in the
1119 // new tree, and delete the rest.
1120 std::vector<std::unique_ptr<RenderSurfaceImpl>> old_render_surfaces;
1121 TakeRenderSurfaces(&old_render_surfaces);
1100 PropertyTree::operator=(from); 1122 PropertyTree::operator=(from);
1123 render_surfaces_.resize(size());
1124 ReuseRenderSurfaces(&old_render_surfaces);
1101 mask_layer_ids_ = from.mask_layer_ids_; 1125 mask_layer_ids_ = from.mask_layer_ids_;
1102 // copy_requests_ are omitted here, since these need to be moved rather 1126 // copy_requests_ are omitted here, since these need to be moved rather
1103 // than copied or assigned. 1127 // than copied or assigned.
1128
1104 return *this; 1129 return *this;
1105 } 1130 }
1106 1131
1107 bool EffectTree::operator==(const EffectTree& other) const { 1132 bool EffectTree::operator==(const EffectTree& other) const {
1108 return PropertyTree::operator==(other) && 1133 return PropertyTree::operator==(other) &&
1109 mask_layer_ids_ == other.mask_layer_ids_; 1134 mask_layer_ids_ == other.mask_layer_ids_;
1110 } 1135 }
1111 1136
1112 ScrollTree::ScrollTree() 1137 ScrollTree::ScrollTree()
1113 : currently_scrolling_node_id_(kInvalidNodeId), 1138 : currently_scrolling_node_id_(kInvalidNodeId),
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 2121
2097 const EffectNode* effect_node = effect_tree.Node(effect_id); 2122 const EffectNode* effect_node = effect_tree.Node(effect_id);
2098 2123
2099 bool success = GetFromTarget(transform_id, effect_id, transform); 2124 bool success = GetFromTarget(transform_id, effect_id, transform);
2100 transform->Scale(effect_node->surface_contents_scale.x(), 2125 transform->Scale(effect_node->surface_contents_scale.x(),
2101 effect_node->surface_contents_scale.y()); 2126 effect_node->surface_contents_scale.y());
2102 return success; 2127 return success;
2103 } 2128 }
2104 2129
2105 } // namespace cc 2130 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698