Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 | 43 |
| 44 namespace cc { | 44 namespace cc { |
| 45 | 45 |
| 46 base::StaticAtomicSequenceNumber g_next_layer_id; | 46 base::StaticAtomicSequenceNumber g_next_layer_id; |
| 47 | 47 |
| 48 scoped_refptr<Layer> Layer::Create(const LayerSettings& settings) { | 48 scoped_refptr<Layer> Layer::Create(const LayerSettings& settings) { |
| 49 return make_scoped_refptr(new Layer(settings)); | 49 return make_scoped_refptr(new Layer(settings)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 Layer::Layer(const LayerSettings& settings) | 52 Layer::Layer(const LayerSettings& settings) |
| 53 : needs_push_properties_(false), | 53 : // Layer IDs start from 1. |
| 54 num_dependents_need_push_properties_(0), | |
| 55 // Layer IDs start from 1. | |
| 56 layer_id_(g_next_layer_id.GetNext() + 1), | 54 layer_id_(g_next_layer_id.GetNext() + 1), |
| 57 ignore_set_needs_commit_(false), | 55 ignore_set_needs_commit_(false), |
| 58 sorting_context_id_(0), | 56 sorting_context_id_(0), |
| 59 parent_(nullptr), | 57 parent_(nullptr), |
| 60 layer_tree_host_(nullptr), | 58 layer_tree_host_(nullptr), |
| 61 scroll_clip_layer_id_(INVALID_ID), | 59 scroll_clip_layer_id_(INVALID_ID), |
| 62 num_descendants_that_draw_content_(0), | 60 num_descendants_that_draw_content_(0), |
| 63 transform_tree_index_(-1), | 61 transform_tree_index_(-1), |
| 64 effect_tree_index_(-1), | 62 effect_tree_index_(-1), |
| 65 clip_tree_index_(-1), | 63 clip_tree_index_(-1), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 141 |
| 144 if (layer_tree_host_) { | 142 if (layer_tree_host_) { |
| 145 layer_tree_host_->property_trees()->needs_rebuild = true; | 143 layer_tree_host_->property_trees()->needs_rebuild = true; |
| 146 layer_tree_host_->UnregisterLayer(this); | 144 layer_tree_host_->UnregisterLayer(this); |
| 147 } | 145 } |
| 148 if (host) { | 146 if (host) { |
| 149 host->property_trees()->needs_rebuild = true; | 147 host->property_trees()->needs_rebuild = true; |
| 150 host->RegisterLayer(this); | 148 host->RegisterLayer(this); |
| 151 } | 149 } |
| 152 | 150 |
| 151 layer_tree_host_ = host; | |
|
jaydasika
2016/03/17 23:38:37
This is to ensure that layer is added to right set
| |
| 153 InvalidatePropertyTreesIndices(); | 152 InvalidatePropertyTreesIndices(); |
| 154 | 153 |
| 155 layer_tree_host_ = host; | |
| 156 | |
| 157 // 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 |
| 158 // side for the new host. | 155 // side for the new host. |
| 159 SetNeedsPushProperties(); | 156 SetNeedsPushProperties(); |
| 160 | 157 |
| 161 for (size_t i = 0; i < children_.size(); ++i) | 158 for (size_t i = 0; i < children_.size(); ++i) |
| 162 children_[i]->SetLayerTreeHost(host); | 159 children_[i]->SetLayerTreeHost(host); |
| 163 | 160 |
| 164 if (mask_layer_.get()) | 161 if (mask_layer_.get()) |
| 165 mask_layer_->SetLayerTreeHost(host); | 162 mask_layer_->SetLayerTreeHost(host); |
| 166 if (replica_layer_.get()) | 163 if (replica_layer_.get()) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 } | 214 } |
| 218 | 215 |
| 219 void Layer::SetNextCommitWaitsForActivation() { | 216 void Layer::SetNextCommitWaitsForActivation() { |
| 220 if (!layer_tree_host_) | 217 if (!layer_tree_host_) |
| 221 return; | 218 return; |
| 222 | 219 |
| 223 layer_tree_host_->SetNextCommitWaitsForActivation(); | 220 layer_tree_host_->SetNextCommitWaitsForActivation(); |
| 224 } | 221 } |
| 225 | 222 |
| 226 void Layer::SetNeedsPushProperties() { | 223 void Layer::SetNeedsPushProperties() { |
| 227 if (needs_push_properties_) | 224 if (layer_tree_host_) |
| 228 return; | 225 layer_tree_host_->AddLayerShouldPushProperties(this); |
| 229 if (!parent_should_know_need_push_properties() && parent_) | |
| 230 parent_->AddDependentNeedsPushProperties(); | |
| 231 needs_push_properties_ = true; | |
| 232 } | |
| 233 | |
| 234 void Layer::AddDependentNeedsPushProperties() { | |
| 235 DCHECK_GE(num_dependents_need_push_properties_, 0); | |
| 236 | |
| 237 if (!parent_should_know_need_push_properties() && parent_) | |
| 238 parent_->AddDependentNeedsPushProperties(); | |
| 239 | |
| 240 num_dependents_need_push_properties_++; | |
| 241 } | |
| 242 | |
| 243 void Layer::RemoveDependentNeedsPushProperties() { | |
| 244 num_dependents_need_push_properties_--; | |
| 245 DCHECK_GE(num_dependents_need_push_properties_, 0); | |
| 246 | |
| 247 if (!parent_should_know_need_push_properties() && parent_) | |
| 248 parent_->RemoveDependentNeedsPushProperties(); | |
| 249 } | 226 } |
| 250 | 227 |
| 251 bool Layer::IsPropertyChangeAllowed() const { | 228 bool Layer::IsPropertyChangeAllowed() const { |
| 252 if (!layer_tree_host_) | 229 if (!layer_tree_host_) |
| 253 return true; | 230 return true; |
| 254 | 231 |
| 255 if (!layer_tree_host_->settings().strict_layer_property_change_checking) | 232 if (!layer_tree_host_->settings().strict_layer_property_change_checking) |
| 256 return true; | 233 return true; |
| 257 | 234 |
| 258 return !layer_tree_host_->in_paint_layer_contents(); | 235 return !layer_tree_host_->in_paint_layer_contents(); |
| 259 } | 236 } |
| 260 | 237 |
| 261 skia::RefPtr<SkPicture> Layer::GetPicture() const { | 238 skia::RefPtr<SkPicture> Layer::GetPicture() const { |
| 262 return skia::RefPtr<SkPicture>(); | 239 return skia::RefPtr<SkPicture>(); |
| 263 } | 240 } |
| 264 | 241 |
| 265 void Layer::SetParent(Layer* layer) { | 242 void Layer::SetParent(Layer* layer) { |
| 266 DCHECK(!layer || !layer->HasAncestor(this)); | 243 DCHECK(!layer || !layer->HasAncestor(this)); |
| 267 | 244 |
| 268 if (parent_should_know_need_push_properties()) { | |
| 269 if (parent_) | |
| 270 parent_->RemoveDependentNeedsPushProperties(); | |
| 271 if (layer) | |
| 272 layer->AddDependentNeedsPushProperties(); | |
| 273 } | |
| 274 | |
| 275 parent_ = layer; | 245 parent_ = layer; |
| 276 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr); | 246 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr); |
| 277 | 247 |
| 278 if (!layer_tree_host_) | 248 if (!layer_tree_host_) |
| 279 return; | 249 return; |
| 280 | 250 |
| 281 layer_tree_host_->property_trees()->needs_rebuild = true; | 251 layer_tree_host_->property_trees()->needs_rebuild = true; |
| 282 } | 252 } |
| 283 | 253 |
| 284 void Layer::AddChild(scoped_refptr<Layer> child) { | 254 void Layer::AddChild(scoped_refptr<Layer> child) { |
| (...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1389 | 1359 |
| 1390 if (frame_timing_requests_dirty_) { | 1360 if (frame_timing_requests_dirty_) { |
| 1391 layer->SetFrameTimingRequests(frame_timing_requests_); | 1361 layer->SetFrameTimingRequests(frame_timing_requests_); |
| 1392 frame_timing_requests_dirty_ = false; | 1362 frame_timing_requests_dirty_ = false; |
| 1393 } | 1363 } |
| 1394 | 1364 |
| 1395 // Reset any state that should be cleared for the next update. | 1365 // Reset any state that should be cleared for the next update. |
| 1396 subtree_property_changed_ = false; | 1366 subtree_property_changed_ = false; |
| 1397 update_rect_ = gfx::Rect(); | 1367 update_rect_ = gfx::Rect(); |
| 1398 | 1368 |
| 1399 needs_push_properties_ = false; | 1369 layer_tree_host()->RemoveLayerShouldPushProperties(this); |
| 1400 num_dependents_need_push_properties_ = 0; | |
| 1401 } | 1370 } |
| 1402 | 1371 |
| 1403 void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { | 1372 void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { |
| 1404 proto->set_type(proto::LayerNode::LAYER); | 1373 proto->set_type(proto::LayerNode::LAYER); |
| 1405 } | 1374 } |
| 1406 | 1375 |
| 1407 void Layer::ToLayerNodeProto(proto::LayerNode* proto) const { | 1376 void Layer::ToLayerNodeProto(proto::LayerNode* proto) const { |
| 1408 proto->set_id(layer_id_); | 1377 proto->set_id(layer_id_); |
| 1409 SetTypeForProtoSerialization(proto); | 1378 SetTypeForProtoSerialization(proto); |
| 1410 | 1379 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1480 replica_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct( | 1449 replica_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct( |
| 1481 proto.replica_layer(), layer_map); | 1450 proto.replica_layer(), layer_map); |
| 1482 replica_layer_->parent_ = this; | 1451 replica_layer_->parent_ = this; |
| 1483 replica_layer_->layer_tree_host_ = layer_tree_host_; | 1452 replica_layer_->layer_tree_host_ = layer_tree_host_; |
| 1484 replica_layer_->FromLayerNodeProto(proto.replica_layer(), layer_map); | 1453 replica_layer_->FromLayerNodeProto(proto.replica_layer(), layer_map); |
| 1485 } else { | 1454 } else { |
| 1486 replica_layer_ = nullptr; | 1455 replica_layer_ = nullptr; |
| 1487 } | 1456 } |
| 1488 } | 1457 } |
| 1489 | 1458 |
| 1490 bool Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update) { | 1459 void Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update) { |
| 1491 if (!needs_push_properties_ && num_dependents_need_push_properties_ == 0) | |
| 1492 return false; | |
| 1493 | |
| 1494 // Always set properties metadata for serialized layers. | 1460 // Always set properties metadata for serialized layers. |
| 1495 proto::LayerProperties* proto = layer_update->add_layers(); | 1461 proto::LayerProperties* proto = layer_update->add_layers(); |
| 1496 proto->set_id(layer_id_); | 1462 proto->set_id(layer_id_); |
| 1497 proto->set_needs_push_properties(needs_push_properties_); | 1463 LayerSpecificPropertiesToProto(proto); |
| 1498 proto->set_num_dependents_need_push_properties( | |
| 1499 num_dependents_need_push_properties_); | |
| 1500 | |
| 1501 if (needs_push_properties_) | |
| 1502 LayerSpecificPropertiesToProto(proto); | |
| 1503 | |
| 1504 needs_push_properties_ = false; | |
| 1505 | |
| 1506 bool descendant_needs_push_properties = | |
| 1507 num_dependents_need_push_properties_ > 0; | |
| 1508 num_dependents_need_push_properties_ = 0; | |
| 1509 | |
| 1510 return descendant_needs_push_properties; | |
| 1511 } | 1464 } |
| 1512 | 1465 |
| 1513 void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) { | 1466 void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) { |
| 1514 DCHECK(proto.has_id()); | 1467 DCHECK(proto.has_id()); |
| 1515 DCHECK_EQ(layer_id_, proto.id()); | 1468 DCHECK_EQ(layer_id_, proto.id()); |
| 1516 DCHECK(proto.has_needs_push_properties()); | |
| 1517 needs_push_properties_ = proto.needs_push_properties(); | |
| 1518 DCHECK(proto.has_num_dependents_need_push_properties()); | |
| 1519 num_dependents_need_push_properties_ = | |
| 1520 proto.num_dependents_need_push_properties(); | |
| 1521 | |
| 1522 if (!needs_push_properties_) | |
| 1523 return; | |
| 1524 | |
| 1525 FromLayerSpecificPropertiesProto(proto); | 1469 FromLayerSpecificPropertiesProto(proto); |
| 1526 } | 1470 } |
| 1527 | 1471 |
| 1528 void Layer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto) { | 1472 void Layer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto) { |
| 1529 proto::BaseLayerProperties* base = proto->mutable_base(); | 1473 proto::BaseLayerProperties* base = proto->mutable_base(); |
| 1530 | 1474 |
| 1531 bool use_paint_properties = layer_tree_host_ && | 1475 bool use_paint_properties = layer_tree_host_ && |
| 1532 paint_properties_.source_frame_number == | 1476 paint_properties_.source_frame_number == |
| 1533 layer_tree_host_->source_frame_number(); | 1477 layer_tree_host_->source_frame_number(); |
| 1534 | 1478 |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2088 this, layer_tree_host_->property_trees()->transform_tree); | 2032 this, layer_tree_host_->property_trees()->transform_tree); |
| 2089 } | 2033 } |
| 2090 | 2034 |
| 2091 gfx::Transform Layer::screen_space_transform() const { | 2035 gfx::Transform Layer::screen_space_transform() const { |
| 2092 DCHECK_NE(transform_tree_index_, -1); | 2036 DCHECK_NE(transform_tree_index_, -1); |
| 2093 return draw_property_utils::ScreenSpaceTransform( | 2037 return draw_property_utils::ScreenSpaceTransform( |
| 2094 this, layer_tree_host_->property_trees()->transform_tree); | 2038 this, layer_tree_host_->property_trees()->transform_tree); |
| 2095 } | 2039 } |
| 2096 | 2040 |
| 2097 } // namespace cc | 2041 } // namespace cc |
| OLD | NEW |