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

Side by Side Diff: cc/layers/layer.cc

Issue 2159513003: Setup LayerTree class, refactor 2 functions from LayerTreeHost to it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Layer GetLayerTree now directly uses LayerTree pointer. Created 4 years, 4 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 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/layers/layer.h" 5 #include "cc/layers/layer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 Layer::Inputs::~Inputs() {} 75 Layer::Inputs::~Inputs() {}
76 76
77 scoped_refptr<Layer> Layer::Create() { 77 scoped_refptr<Layer> Layer::Create() {
78 return make_scoped_refptr(new Layer()); 78 return make_scoped_refptr(new Layer());
79 } 79 }
80 80
81 Layer::Layer() 81 Layer::Layer()
82 : ignore_set_needs_commit_(false), 82 : ignore_set_needs_commit_(false),
83 parent_(nullptr), 83 parent_(nullptr),
84 layer_tree_host_(nullptr), 84 layer_tree_host_(nullptr),
85 layer_tree_(nullptr),
85 num_descendants_that_draw_content_(0), 86 num_descendants_that_draw_content_(0),
86 transform_tree_index_(TransformTree::kInvalidNodeId), 87 transform_tree_index_(TransformTree::kInvalidNodeId),
87 effect_tree_index_(EffectTree::kInvalidNodeId), 88 effect_tree_index_(EffectTree::kInvalidNodeId),
88 clip_tree_index_(ClipTree::kInvalidNodeId), 89 clip_tree_index_(ClipTree::kInvalidNodeId),
89 scroll_tree_index_(ScrollTree::kInvalidNodeId), 90 scroll_tree_index_(ScrollTree::kInvalidNodeId),
90 property_tree_sequence_number_(-1), 91 property_tree_sequence_number_(-1),
91 should_flatten_transform_from_property_tree_(false), 92 should_flatten_transform_from_property_tree_(false),
92 draws_content_(false), 93 draws_content_(false),
93 use_local_transform_for_backface_visibility_(false), 94 use_local_transform_for_backface_visibility_(false),
94 should_check_backface_visibility_(false), 95 should_check_backface_visibility_(false),
(...skipping 27 matching lines...) Expand all
122 } 123 }
123 } 124 }
124 125
125 void Layer::SetLayerTreeHost(LayerTreeHost* host) { 126 void Layer::SetLayerTreeHost(LayerTreeHost* host) {
126 if (layer_tree_host_ == host) 127 if (layer_tree_host_ == host)
127 return; 128 return;
128 129
129 if (layer_tree_host_) { 130 if (layer_tree_host_) {
130 layer_tree_host_->property_trees()->RemoveIdFromIdToIndexMaps(id()); 131 layer_tree_host_->property_trees()->RemoveIdFromIdToIndexMaps(id());
131 layer_tree_host_->property_trees()->needs_rebuild = true; 132 layer_tree_host_->property_trees()->needs_rebuild = true;
132 layer_tree_host_->UnregisterLayer(this); 133 layer_tree_->UnregisterLayer(this);
133 if (inputs_.element_id) { 134 if (inputs_.element_id) {
134 layer_tree_host_->animation_host()->UnregisterElement( 135 layer_tree_host_->animation_host()->UnregisterElement(
135 inputs_.element_id, ElementListType::ACTIVE); 136 inputs_.element_id, ElementListType::ACTIVE);
136 layer_tree_host_->RemoveFromElementMap(this); 137 layer_tree_host_->RemoveFromElementMap(this);
137 } 138 }
138 } 139 }
139 if (host) { 140 if (host) {
140 host->property_trees()->needs_rebuild = true; 141 host->property_trees()->needs_rebuild = true;
141 host->RegisterLayer(this); 142 host->GetLayerTree()->RegisterLayer(this);
142 if (inputs_.element_id) { 143 if (inputs_.element_id) {
143 host->AddToElementMap(this); 144 host->AddToElementMap(this);
144 host->animation_host()->RegisterElement(inputs_.element_id, 145 host->animation_host()->RegisterElement(inputs_.element_id,
145 ElementListType::ACTIVE); 146 ElementListType::ACTIVE);
146 } 147 }
147 } 148 }
148 149
149 layer_tree_host_ = host; 150 layer_tree_host_ = host;
151 layer_tree_ = host ? host->GetLayerTree() : nullptr;
150 InvalidatePropertyTreesIndices(); 152 InvalidatePropertyTreesIndices();
151 153
152 // When changing hosts, the layer needs to commit its properties to the impl 154 // When changing hosts, the layer needs to commit its properties to the impl
153 // side for the new host. 155 // side for the new host.
154 SetNeedsPushProperties(); 156 SetNeedsPushProperties();
155 157
156 for (size_t i = 0; i < inputs_.children.size(); ++i) 158 for (size_t i = 0; i < inputs_.children.size(); ++i)
157 inputs_.children[i]->SetLayerTreeHost(host); 159 inputs_.children[i]->SetLayerTreeHost(host);
158 160
159 if (inputs_.mask_layer.get()) 161 if (inputs_.mask_layer.get())
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 209 }
208 210
209 void Layer::SetNextCommitWaitsForActivation() { 211 void Layer::SetNextCommitWaitsForActivation() {
210 if (!layer_tree_host_) 212 if (!layer_tree_host_)
211 return; 213 return;
212 214
213 layer_tree_host_->SetNextCommitWaitsForActivation(); 215 layer_tree_host_->SetNextCommitWaitsForActivation();
214 } 216 }
215 217
216 void Layer::SetNeedsPushProperties() { 218 void Layer::SetNeedsPushProperties() {
217 if (layer_tree_host_) 219 if (layer_tree_)
218 layer_tree_host_->AddLayerShouldPushProperties(this); 220 layer_tree_->AddLayerShouldPushProperties(this);
219 } 221 }
220 222
221 void Layer::ResetNeedsPushPropertiesForTesting() { 223 void Layer::ResetNeedsPushPropertiesForTesting() {
222 layer_tree_host_->RemoveLayerShouldPushProperties(this); 224 if (layer_tree_)
225 layer_tree_->RemoveLayerShouldPushProperties(this);
223 } 226 }
224 227
225 bool Layer::IsPropertyChangeAllowed() const { 228 bool Layer::IsPropertyChangeAllowed() const {
226 if (!layer_tree_host_) 229 if (!layer_tree_)
227 return true; 230 return true;
228 231
229 return !layer_tree_host_->in_paint_layer_contents(); 232 return !layer_tree_->in_paint_layer_contents();
230 } 233 }
231 234
232 sk_sp<SkPicture> Layer::GetPicture() const { 235 sk_sp<SkPicture> Layer::GetPicture() const {
233 return nullptr; 236 return nullptr;
234 } 237 }
235 238
236 void Layer::SetParent(Layer* layer) { 239 void Layer::SetParent(Layer* layer) {
237 DCHECK(!layer || !layer->HasAncestor(this)); 240 DCHECK(!layer || !layer->HasAncestor(this));
238 241
239 parent_ = layer; 242 parent_ = layer;
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 layer->SetUpdateRect(inputs_.update_rect); 1197 layer->SetUpdateRect(inputs_.update_rect);
1195 1198
1196 layer->SetHasWillChangeTransformHint(has_will_change_transform_hint()); 1199 layer->SetHasWillChangeTransformHint(has_will_change_transform_hint());
1197 layer->SetNeedsPushProperties(); 1200 layer->SetNeedsPushProperties();
1198 1201
1199 // Reset any state that should be cleared for the next update. 1202 // Reset any state that should be cleared for the next update.
1200 subtree_property_changed_ = false; 1203 subtree_property_changed_ = false;
1201 layer_property_changed_ = false; 1204 layer_property_changed_ = false;
1202 inputs_.update_rect = gfx::Rect(); 1205 inputs_.update_rect = gfx::Rect();
1203 1206
1204 layer_tree_host()->RemoveLayerShouldPushProperties(this); 1207 layer_tree_->RemoveLayerShouldPushProperties(this);
1205 } 1208 }
1206 1209
1207 void Layer::TakeCopyRequests( 1210 void Layer::TakeCopyRequests(
1208 std::vector<std::unique_ptr<CopyOutputRequest>>* requests) { 1211 std::vector<std::unique_ptr<CopyOutputRequest>>* requests) {
1209 for (auto& it : inputs_.copy_requests) { 1212 for (auto& it : inputs_.copy_requests) {
1210 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner = 1213 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner =
1211 layer_tree_host()->task_runner_provider()->MainThreadTaskRunner(); 1214 layer_tree_host()->task_runner_provider()->MainThreadTaskRunner();
1212 std::unique_ptr<CopyOutputRequest> original_request = std::move(it); 1215 std::unique_ptr<CopyOutputRequest> original_request = std::move(it);
1213 const CopyOutputRequest& original_request_ref = *original_request; 1216 const CopyOutputRequest& original_request_ref = *original_request;
1214 std::unique_ptr<CopyOutputRequest> main_thread_request = 1217 std::unique_ptr<CopyOutputRequest> main_thread_request =
(...skipping 30 matching lines...) Expand all
1245 if (inputs_.mask_layer) 1248 if (inputs_.mask_layer)
1246 inputs_.mask_layer->ToLayerNodeProto(proto->mutable_mask_layer()); 1249 inputs_.mask_layer->ToLayerNodeProto(proto->mutable_mask_layer());
1247 if (inputs_.replica_layer) 1250 if (inputs_.replica_layer)
1248 inputs_.replica_layer->ToLayerNodeProto(proto->mutable_replica_layer()); 1251 inputs_.replica_layer->ToLayerNodeProto(proto->mutable_replica_layer());
1249 } 1252 }
1250 1253
1251 void Layer::ClearLayerTreePropertiesForDeserializationAndAddToMap( 1254 void Layer::ClearLayerTreePropertiesForDeserializationAndAddToMap(
1252 LayerIdMap* layer_map) { 1255 LayerIdMap* layer_map) {
1253 (*layer_map)[inputs_.layer_id] = this; 1256 (*layer_map)[inputs_.layer_id] = this;
1254 1257
1255 if (layer_tree_host_) 1258 if (layer_tree_)
1256 layer_tree_host_->UnregisterLayer(this); 1259 layer_tree_->UnregisterLayer(this);
1257 1260
1258 layer_tree_host_ = nullptr; 1261 layer_tree_host_ = nullptr;
1262 layer_tree_ = nullptr;
1263
1259 parent_ = nullptr; 1264 parent_ = nullptr;
1260 1265
1261 // Clear these properties for all the children and add them to the map. 1266 // Clear these properties for all the children and add them to the map.
1262 for (auto& child : inputs_.children) { 1267 for (auto& child : inputs_.children) {
1263 child->ClearLayerTreePropertiesForDeserializationAndAddToMap(layer_map); 1268 child->ClearLayerTreePropertiesForDeserializationAndAddToMap(layer_map);
1264 } 1269 }
1265 1270
1266 inputs_.children.clear(); 1271 inputs_.children.clear();
1267 1272
1268 if (inputs_.mask_layer) { 1273 if (inputs_.mask_layer) {
(...skipping 15 matching lines...) Expand all
1284 DCHECK(!layer_tree_host_); 1289 DCHECK(!layer_tree_host_);
1285 DCHECK(inputs_.children.empty()); 1290 DCHECK(inputs_.children.empty());
1286 DCHECK(!inputs_.mask_layer); 1291 DCHECK(!inputs_.mask_layer);
1287 DCHECK(!inputs_.replica_layer); 1292 DCHECK(!inputs_.replica_layer);
1288 DCHECK(layer_tree_host); 1293 DCHECK(layer_tree_host);
1289 DCHECK(proto.has_id()); 1294 DCHECK(proto.has_id());
1290 1295
1291 inputs_.layer_id = proto.id(); 1296 inputs_.layer_id = proto.id();
1292 1297
1293 layer_tree_host_ = layer_tree_host; 1298 layer_tree_host_ = layer_tree_host;
1294 layer_tree_host_->RegisterLayer(this); 1299 layer_tree_ = layer_tree_host ? layer_tree_host->GetLayerTree() : nullptr;
1300 layer_tree_->RegisterLayer(this);
1295 1301
1296 for (int i = 0; i < proto.children_size(); ++i) { 1302 for (int i = 0; i < proto.children_size(); ++i) {
1297 const proto::LayerNode& child_proto = proto.children(i); 1303 const proto::LayerNode& child_proto = proto.children(i);
1298 DCHECK(child_proto.has_type()); 1304 DCHECK(child_proto.has_type());
1299 scoped_refptr<Layer> child = 1305 scoped_refptr<Layer> child =
1300 LayerProtoConverter::FindOrAllocateAndConstruct(child_proto, layer_map); 1306 LayerProtoConverter::FindOrAllocateAndConstruct(child_proto, layer_map);
1301 // The child must now refer to this layer as its parent, and must also have 1307 // The child must now refer to this layer as its parent, and must also have
1302 // the same LayerTreeHost. This must be done before deserializing children. 1308 // the same LayerTreeHost. This must be done before deserializing children.
1303 DCHECK(!child->parent_); 1309 DCHECK(!child->parent_);
1304 child->parent_ = this; 1310 child->parent_ = this;
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 } 1773 }
1768 1774
1769 void Layer::SetHasWillChangeTransformHint(bool has_will_change) { 1775 void Layer::SetHasWillChangeTransformHint(bool has_will_change) {
1770 if (inputs_.has_will_change_transform_hint == has_will_change) 1776 if (inputs_.has_will_change_transform_hint == has_will_change)
1771 return; 1777 return;
1772 inputs_.has_will_change_transform_hint = has_will_change; 1778 inputs_.has_will_change_transform_hint = has_will_change;
1773 SetNeedsCommit(); 1779 SetNeedsCommit();
1774 } 1780 }
1775 1781
1776 AnimationHost* Layer::GetAnimationHost() const { 1782 AnimationHost* Layer::GetAnimationHost() const {
1777 return layer_tree_host_ ? layer_tree_host_->animation_host() : nullptr; 1783 return layer_tree_ ? layer_tree_->animation_host() : nullptr;
1778 } 1784 }
1779 1785
1780 ElementListType Layer::GetElementTypeForAnimation() const { 1786 ElementListType Layer::GetElementTypeForAnimation() const {
1781 return ElementListType::ACTIVE; 1787 return ElementListType::ACTIVE;
1782 } 1788 }
1783 1789
1784 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { 1790 ScrollbarLayerInterface* Layer::ToScrollbarLayer() {
1785 return nullptr; 1791 return nullptr;
1786 } 1792 }
1787 1793
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 ->effect_tree.Node(effect_tree_index()) 1875 ->effect_tree.Node(effect_tree_index())
1870 ->num_copy_requests_in_subtree; 1876 ->num_copy_requests_in_subtree;
1871 } 1877 }
1872 1878
1873 gfx::Transform Layer::screen_space_transform() const { 1879 gfx::Transform Layer::screen_space_transform() const {
1874 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId); 1880 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId);
1875 return draw_property_utils::ScreenSpaceTransform( 1881 return draw_property_utils::ScreenSpaceTransform(
1876 this, layer_tree_host_->property_trees()->transform_tree); 1882 this, layer_tree_host_->property_trees()->transform_tree);
1877 } 1883 }
1878 1884
1885 LayerTree* Layer::GetLayerTree() const {
1886 return layer_tree_;
1887 }
1888
1879 } // namespace cc 1889 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_proto_converter.cc » ('j') | cc/proto/layer_tree.proto » ('J')

Powered by Google App Engine
This is Rietveld 408576698