| OLD | NEW |
| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 namespace cc { | 39 namespace cc { |
| 40 | 40 |
| 41 base::StaticAtomicSequenceNumber g_next_layer_id; | 41 base::StaticAtomicSequenceNumber g_next_layer_id; |
| 42 | 42 |
| 43 scoped_refptr<Layer> Layer::Create() { | 43 scoped_refptr<Layer> Layer::Create() { |
| 44 return make_scoped_refptr(new Layer()); | 44 return make_scoped_refptr(new Layer()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 Layer::Layer() | 47 Layer::Layer() |
| 48 : needs_push_properties_(false), | 48 : // Layer IDs start from 1. |
| 49 num_dependents_need_push_properties_(0), | |
| 50 // Layer IDs start from 1. | |
| 51 layer_id_(g_next_layer_id.GetNext() + 1), | 49 layer_id_(g_next_layer_id.GetNext() + 1), |
| 52 ignore_set_needs_commit_(false), | 50 ignore_set_needs_commit_(false), |
| 53 sorting_context_id_(0), | 51 sorting_context_id_(0), |
| 54 parent_(nullptr), | 52 parent_(nullptr), |
| 55 layer_tree_host_(nullptr), | 53 layer_tree_host_(nullptr), |
| 56 scroll_clip_layer_id_(INVALID_ID), | 54 scroll_clip_layer_id_(INVALID_ID), |
| 57 num_descendants_that_draw_content_(0), | 55 num_descendants_that_draw_content_(0), |
| 58 transform_tree_index_(-1), | 56 transform_tree_index_(-1), |
| 59 effect_tree_index_(-1), | 57 effect_tree_index_(-1), |
| 60 clip_tree_index_(-1), | 58 clip_tree_index_(-1), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 125 |
| 128 if (layer_tree_host_) { | 126 if (layer_tree_host_) { |
| 129 layer_tree_host_->property_trees()->needs_rebuild = true; | 127 layer_tree_host_->property_trees()->needs_rebuild = true; |
| 130 layer_tree_host_->UnregisterLayer(this); | 128 layer_tree_host_->UnregisterLayer(this); |
| 131 } | 129 } |
| 132 if (host) { | 130 if (host) { |
| 133 host->property_trees()->needs_rebuild = true; | 131 host->property_trees()->needs_rebuild = true; |
| 134 host->RegisterLayer(this); | 132 host->RegisterLayer(this); |
| 135 } | 133 } |
| 136 | 134 |
| 135 layer_tree_host_ = host; |
| 137 InvalidatePropertyTreesIndices(); | 136 InvalidatePropertyTreesIndices(); |
| 138 | 137 |
| 139 layer_tree_host_ = host; | |
| 140 | |
| 141 // When changing hosts, the layer needs to commit its properties to the impl | 138 // When changing hosts, the layer needs to commit its properties to the impl |
| 142 // side for the new host. | 139 // side for the new host. |
| 143 SetNeedsPushProperties(); | 140 SetNeedsPushProperties(); |
| 144 | 141 |
| 145 for (size_t i = 0; i < children_.size(); ++i) | 142 for (size_t i = 0; i < children_.size(); ++i) |
| 146 children_[i]->SetLayerTreeHost(host); | 143 children_[i]->SetLayerTreeHost(host); |
| 147 | 144 |
| 148 if (mask_layer_.get()) | 145 if (mask_layer_.get()) |
| 149 mask_layer_->SetLayerTreeHost(host); | 146 mask_layer_->SetLayerTreeHost(host); |
| 150 if (replica_layer_.get()) | 147 if (replica_layer_.get()) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 192 } |
| 196 | 193 |
| 197 void Layer::SetNextCommitWaitsForActivation() { | 194 void Layer::SetNextCommitWaitsForActivation() { |
| 198 if (!layer_tree_host_) | 195 if (!layer_tree_host_) |
| 199 return; | 196 return; |
| 200 | 197 |
| 201 layer_tree_host_->SetNextCommitWaitsForActivation(); | 198 layer_tree_host_->SetNextCommitWaitsForActivation(); |
| 202 } | 199 } |
| 203 | 200 |
| 204 void Layer::SetNeedsPushProperties() { | 201 void Layer::SetNeedsPushProperties() { |
| 205 if (needs_push_properties_) | 202 if (layer_tree_host_) |
| 206 return; | 203 layer_tree_host_->AddLayerShouldPushProperties(this); |
| 207 if (!parent_should_know_need_push_properties() && parent_) | |
| 208 parent_->AddDependentNeedsPushProperties(); | |
| 209 needs_push_properties_ = true; | |
| 210 } | 204 } |
| 211 | 205 |
| 212 void Layer::AddDependentNeedsPushProperties() { | 206 void Layer::ResetNeedsPushPropertiesForTesting() { |
| 213 DCHECK_GE(num_dependents_need_push_properties_, 0); | 207 layer_tree_host_->RemoveLayerShouldPushProperties(this); |
| 214 | |
| 215 if (!parent_should_know_need_push_properties() && parent_) | |
| 216 parent_->AddDependentNeedsPushProperties(); | |
| 217 | |
| 218 num_dependents_need_push_properties_++; | |
| 219 } | |
| 220 | |
| 221 void Layer::RemoveDependentNeedsPushProperties() { | |
| 222 num_dependents_need_push_properties_--; | |
| 223 DCHECK_GE(num_dependents_need_push_properties_, 0); | |
| 224 | |
| 225 if (!parent_should_know_need_push_properties() && parent_) | |
| 226 parent_->RemoveDependentNeedsPushProperties(); | |
| 227 } | 208 } |
| 228 | 209 |
| 229 bool Layer::IsPropertyChangeAllowed() const { | 210 bool Layer::IsPropertyChangeAllowed() const { |
| 230 if (!layer_tree_host_) | 211 if (!layer_tree_host_) |
| 231 return true; | 212 return true; |
| 232 | 213 |
| 233 if (!layer_tree_host_->settings().strict_layer_property_change_checking) | 214 if (!layer_tree_host_->settings().strict_layer_property_change_checking) |
| 234 return true; | 215 return true; |
| 235 | 216 |
| 236 return !layer_tree_host_->in_paint_layer_contents(); | 217 return !layer_tree_host_->in_paint_layer_contents(); |
| 237 } | 218 } |
| 238 | 219 |
| 239 skia::RefPtr<SkPicture> Layer::GetPicture() const { | 220 skia::RefPtr<SkPicture> Layer::GetPicture() const { |
| 240 return skia::RefPtr<SkPicture>(); | 221 return skia::RefPtr<SkPicture>(); |
| 241 } | 222 } |
| 242 | 223 |
| 243 void Layer::SetParent(Layer* layer) { | 224 void Layer::SetParent(Layer* layer) { |
| 244 DCHECK(!layer || !layer->HasAncestor(this)); | 225 DCHECK(!layer || !layer->HasAncestor(this)); |
| 245 | 226 |
| 246 if (parent_should_know_need_push_properties()) { | |
| 247 if (parent_) | |
| 248 parent_->RemoveDependentNeedsPushProperties(); | |
| 249 if (layer) | |
| 250 layer->AddDependentNeedsPushProperties(); | |
| 251 } | |
| 252 | |
| 253 parent_ = layer; | 227 parent_ = layer; |
| 254 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr); | 228 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr); |
| 255 | 229 |
| 256 if (!layer_tree_host_) | 230 if (!layer_tree_host_) |
| 257 return; | 231 return; |
| 258 | 232 |
| 259 layer_tree_host_->property_trees()->needs_rebuild = true; | 233 layer_tree_host_->property_trees()->needs_rebuild = true; |
| 260 } | 234 } |
| 261 | 235 |
| 262 void Layer::AddChild(scoped_refptr<Layer> child) { | 236 void Layer::AddChild(scoped_refptr<Layer> child) { |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 | 1277 |
| 1304 if (frame_timing_requests_dirty_) { | 1278 if (frame_timing_requests_dirty_) { |
| 1305 layer->SetFrameTimingRequests(frame_timing_requests_); | 1279 layer->SetFrameTimingRequests(frame_timing_requests_); |
| 1306 frame_timing_requests_dirty_ = false; | 1280 frame_timing_requests_dirty_ = false; |
| 1307 } | 1281 } |
| 1308 | 1282 |
| 1309 // Reset any state that should be cleared for the next update. | 1283 // Reset any state that should be cleared for the next update. |
| 1310 subtree_property_changed_ = false; | 1284 subtree_property_changed_ = false; |
| 1311 update_rect_ = gfx::Rect(); | 1285 update_rect_ = gfx::Rect(); |
| 1312 | 1286 |
| 1313 needs_push_properties_ = false; | 1287 layer_tree_host()->RemoveLayerShouldPushProperties(this); |
| 1314 num_dependents_need_push_properties_ = 0; | |
| 1315 } | 1288 } |
| 1316 | 1289 |
| 1317 void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { | 1290 void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { |
| 1318 proto->set_type(proto::LayerNode::LAYER); | 1291 proto->set_type(proto::LayerNode::LAYER); |
| 1319 } | 1292 } |
| 1320 | 1293 |
| 1321 void Layer::ToLayerNodeProto(proto::LayerNode* proto) const { | 1294 void Layer::ToLayerNodeProto(proto::LayerNode* proto) const { |
| 1322 proto->set_id(layer_id_); | 1295 proto->set_id(layer_id_); |
| 1323 SetTypeForProtoSerialization(proto); | 1296 SetTypeForProtoSerialization(proto); |
| 1324 | 1297 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 replica_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct( | 1367 replica_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct( |
| 1395 proto.replica_layer(), layer_map); | 1368 proto.replica_layer(), layer_map); |
| 1396 replica_layer_->parent_ = this; | 1369 replica_layer_->parent_ = this; |
| 1397 replica_layer_->layer_tree_host_ = layer_tree_host_; | 1370 replica_layer_->layer_tree_host_ = layer_tree_host_; |
| 1398 replica_layer_->FromLayerNodeProto(proto.replica_layer(), layer_map); | 1371 replica_layer_->FromLayerNodeProto(proto.replica_layer(), layer_map); |
| 1399 } else { | 1372 } else { |
| 1400 replica_layer_ = nullptr; | 1373 replica_layer_ = nullptr; |
| 1401 } | 1374 } |
| 1402 } | 1375 } |
| 1403 | 1376 |
| 1404 bool Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update) { | 1377 void Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update) { |
| 1405 if (!needs_push_properties_ && num_dependents_need_push_properties_ == 0) | |
| 1406 return false; | |
| 1407 | |
| 1408 // Always set properties metadata for serialized layers. | 1378 // Always set properties metadata for serialized layers. |
| 1409 proto::LayerProperties* proto = layer_update->add_layers(); | 1379 proto::LayerProperties* proto = layer_update->add_layers(); |
| 1410 proto->set_id(layer_id_); | 1380 proto->set_id(layer_id_); |
| 1411 proto->set_needs_push_properties(needs_push_properties_); | 1381 LayerSpecificPropertiesToProto(proto); |
| 1412 proto->set_num_dependents_need_push_properties( | |
| 1413 num_dependents_need_push_properties_); | |
| 1414 | |
| 1415 if (needs_push_properties_) | |
| 1416 LayerSpecificPropertiesToProto(proto); | |
| 1417 | |
| 1418 needs_push_properties_ = false; | |
| 1419 | |
| 1420 bool descendant_needs_push_properties = | |
| 1421 num_dependents_need_push_properties_ > 0; | |
| 1422 num_dependents_need_push_properties_ = 0; | |
| 1423 | |
| 1424 return descendant_needs_push_properties; | |
| 1425 } | 1382 } |
| 1426 | 1383 |
| 1427 void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) { | 1384 void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) { |
| 1428 DCHECK(proto.has_id()); | 1385 DCHECK(proto.has_id()); |
| 1429 DCHECK_EQ(layer_id_, proto.id()); | 1386 DCHECK_EQ(layer_id_, proto.id()); |
| 1430 DCHECK(proto.has_needs_push_properties()); | |
| 1431 needs_push_properties_ = proto.needs_push_properties(); | |
| 1432 DCHECK(proto.has_num_dependents_need_push_properties()); | |
| 1433 num_dependents_need_push_properties_ = | |
| 1434 proto.num_dependents_need_push_properties(); | |
| 1435 | |
| 1436 if (!needs_push_properties_) | |
| 1437 return; | |
| 1438 | |
| 1439 FromLayerSpecificPropertiesProto(proto); | 1387 FromLayerSpecificPropertiesProto(proto); |
| 1440 } | 1388 } |
| 1441 | 1389 |
| 1442 void Layer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto) { | 1390 void Layer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto) { |
| 1443 proto::BaseLayerProperties* base = proto->mutable_base(); | 1391 proto::BaseLayerProperties* base = proto->mutable_base(); |
| 1444 | 1392 |
| 1445 bool use_paint_properties = layer_tree_host_ && | 1393 bool use_paint_properties = layer_tree_host_ && |
| 1446 paint_properties_.source_frame_number == | 1394 paint_properties_.source_frame_number == |
| 1447 layer_tree_host_->source_frame_number(); | 1395 layer_tree_host_->source_frame_number(); |
| 1448 | 1396 |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1925 this, layer_tree_host_->property_trees()->transform_tree); | 1873 this, layer_tree_host_->property_trees()->transform_tree); |
| 1926 } | 1874 } |
| 1927 | 1875 |
| 1928 gfx::Transform Layer::screen_space_transform() const { | 1876 gfx::Transform Layer::screen_space_transform() const { |
| 1929 DCHECK_NE(transform_tree_index_, -1); | 1877 DCHECK_NE(transform_tree_index_, -1); |
| 1930 return draw_property_utils::ScreenSpaceTransform( | 1878 return draw_property_utils::ScreenSpaceTransform( |
| 1931 this, layer_tree_host_->property_trees()->transform_tree); | 1879 this, layer_tree_host_->property_trees()->transform_tree); |
| 1932 } | 1880 } |
| 1933 | 1881 |
| 1934 } // namespace cc | 1882 } // namespace cc |
| OLD | NEW |