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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "cc/animation/animation.h" | 15 #include "cc/animation/animation.h" |
16 #include "cc/animation/animation_events.h" | 16 #include "cc/animation/animation_events.h" |
17 #include "cc/animation/animation_registrar.h" | 17 #include "cc/animation/animation_registrar.h" |
18 #include "cc/animation/keyframed_animation_curve.h" | 18 #include "cc/animation/keyframed_animation_curve.h" |
19 #include "cc/animation/layer_animation_controller.h" | 19 #include "cc/animation/layer_animation_controller.h" |
20 #include "cc/base/simple_enclosed_region.h" | 20 #include "cc/base/simple_enclosed_region.h" |
21 #include "cc/debug/frame_viewer_instrumentation.h" | 21 #include "cc/debug/frame_viewer_instrumentation.h" |
22 #include "cc/layers/layer_client.h" | 22 #include "cc/layers/layer_client.h" |
23 #include "cc/layers/layer_impl.h" | 23 #include "cc/layers/layer_impl.h" |
| 24 #include "cc/layers/layer_proto_converter.h" |
24 #include "cc/layers/scrollbar_layer_interface.h" | 25 #include "cc/layers/scrollbar_layer_interface.h" |
25 #include "cc/output/copy_output_request.h" | 26 #include "cc/output/copy_output_request.h" |
26 #include "cc/output/copy_output_result.h" | 27 #include "cc/output/copy_output_result.h" |
| 28 #include "cc/proto/layer.pb.h" |
27 #include "cc/trees/draw_property_utils.h" | 29 #include "cc/trees/draw_property_utils.h" |
28 #include "cc/trees/layer_tree_host.h" | 30 #include "cc/trees/layer_tree_host.h" |
29 #include "cc/trees/layer_tree_impl.h" | 31 #include "cc/trees/layer_tree_impl.h" |
30 #include "third_party/skia/include/core/SkImageFilter.h" | 32 #include "third_party/skia/include/core/SkImageFilter.h" |
31 #include "ui/gfx/geometry/rect_conversions.h" | 33 #include "ui/gfx/geometry/rect_conversions.h" |
32 #include "ui/gfx/geometry/vector2d_conversions.h" | 34 #include "ui/gfx/geometry/vector2d_conversions.h" |
33 | 35 |
34 namespace cc { | 36 namespace cc { |
35 | 37 |
36 base::StaticAtomicSequenceNumber g_next_layer_id; | 38 base::StaticAtomicSequenceNumber g_next_layer_id; |
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 layer->SetIsAffectedByPageScale(is_page_scale_layer || parent_affected); | 1340 layer->SetIsAffectedByPageScale(is_page_scale_layer || parent_affected); |
1339 | 1341 |
1340 // Reset any state that should be cleared for the next update. | 1342 // Reset any state that should be cleared for the next update. |
1341 stacking_order_changed_ = false; | 1343 stacking_order_changed_ = false; |
1342 update_rect_ = gfx::Rect(); | 1344 update_rect_ = gfx::Rect(); |
1343 | 1345 |
1344 needs_push_properties_ = false; | 1346 needs_push_properties_ = false; |
1345 num_dependents_need_push_properties_ = 0; | 1347 num_dependents_need_push_properties_ = 0; |
1346 } | 1348 } |
1347 | 1349 |
| 1350 proto::LayerType Layer::GetTypeForProtoSerialization() const { |
| 1351 return proto::Base; |
| 1352 } |
| 1353 |
| 1354 void Layer::ToLayerNodeProto(proto::LayerNode* proto) const { |
| 1355 proto->set_id(layer_id_); |
| 1356 proto->set_type(GetTypeForProtoSerialization()); |
| 1357 |
| 1358 if (parent_) |
| 1359 proto->set_parent_id(parent_->id()); |
| 1360 |
| 1361 DCHECK_EQ(0, proto->children_size()); |
| 1362 for (const auto& child : children_) { |
| 1363 child->ToLayerNodeProto(proto->add_children()); |
| 1364 } |
| 1365 |
| 1366 if (mask_layer_) |
| 1367 mask_layer_->ToLayerNodeProto(proto->mutable_mask_layer()); |
| 1368 if (replica_layer_) |
| 1369 replica_layer_->ToLayerNodeProto(proto->mutable_replica_layer()); |
| 1370 } |
| 1371 |
| 1372 void Layer::FromLayerNodeProto(const proto::LayerNode& proto, |
| 1373 const LayerIdMap& layer_map) { |
| 1374 DCHECK(proto.has_id()); |
| 1375 layer_id_ = proto.id(); |
| 1376 |
| 1377 // Recursively remove all children. In the case of when the updated |
| 1378 // hierarchy has no children, or the children has changed, the old list |
| 1379 // of children must be removed. The whole hierarchy is always sent, so |
| 1380 // if there were no change in the children, they will be correctly added back |
| 1381 // below. |
| 1382 RemoveAllChildren(); |
| 1383 for (int i = 0; i < proto.children_size(); ++i) { |
| 1384 const proto::LayerNode& child_proto = proto.children(i); |
| 1385 DCHECK(child_proto.has_type()); |
| 1386 scoped_refptr<Layer> child = |
| 1387 LayerProtoConverter::FindOrAllocateAndConstruct(child_proto, layer_map); |
| 1388 child->FromLayerNodeProto(child_proto, layer_map); |
| 1389 AddChild(child); |
| 1390 } |
| 1391 |
| 1392 if (mask_layer_) |
| 1393 mask_layer_->RemoveFromParent(); |
| 1394 if (proto.has_mask_layer()) { |
| 1395 mask_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct( |
| 1396 proto.mask_layer(), layer_map); |
| 1397 mask_layer_->FromLayerNodeProto(proto.mask_layer(), layer_map); |
| 1398 mask_layer_->SetParent(this); |
| 1399 } else { |
| 1400 mask_layer_ = nullptr; |
| 1401 } |
| 1402 |
| 1403 if (replica_layer_) |
| 1404 replica_layer_->RemoveFromParent(); |
| 1405 if (proto.has_replica_layer()) { |
| 1406 replica_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct( |
| 1407 proto.replica_layer(), layer_map); |
| 1408 replica_layer_->FromLayerNodeProto(proto.replica_layer(), layer_map); |
| 1409 replica_layer_->SetParent(this); |
| 1410 } else { |
| 1411 replica_layer_ = nullptr; |
| 1412 } |
| 1413 } |
| 1414 |
1348 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 1415 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
1349 return LayerImpl::Create(tree_impl, layer_id_, | 1416 return LayerImpl::Create(tree_impl, layer_id_, |
1350 new LayerImpl::SyncedScrollOffset); | 1417 new LayerImpl::SyncedScrollOffset); |
1351 } | 1418 } |
1352 | 1419 |
1353 bool Layer::DrawsContent() const { | 1420 bool Layer::DrawsContent() const { |
1354 return draws_content_; | 1421 return draws_content_; |
1355 } | 1422 } |
1356 | 1423 |
1357 bool Layer::HasDrawableContent() const { | 1424 bool Layer::HasDrawableContent() const { |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 this, layer_tree_host_->property_trees()->transform_tree); | 1770 this, layer_tree_host_->property_trees()->transform_tree); |
1704 } | 1771 } |
1705 | 1772 |
1706 gfx::Transform Layer::screen_space_transform() const { | 1773 gfx::Transform Layer::screen_space_transform() const { |
1707 DCHECK_NE(transform_tree_index_, -1); | 1774 DCHECK_NE(transform_tree_index_, -1); |
1708 return ScreenSpaceTransformFromPropertyTrees( | 1775 return ScreenSpaceTransformFromPropertyTrees( |
1709 this, layer_tree_host_->property_trees()->transform_tree); | 1776 this, layer_tree_host_->property_trees()->transform_tree); |
1710 } | 1777 } |
1711 | 1778 |
1712 } // namespace cc | 1779 } // namespace cc |
OLD | NEW |