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

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

Issue 1398443008: Add support for (de)serializing cc::Layer hierarchy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@review-1394353002
Patch Set: Reorderded TODO Created 5 years, 1 month 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
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_proto_converter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 layer->SetIsAffectedByPageScale(is_page_scale_layer || parent_affected); 1344 layer->SetIsAffectedByPageScale(is_page_scale_layer || parent_affected);
1343 1345
1344 // Reset any state that should be cleared for the next update. 1346 // Reset any state that should be cleared for the next update.
1345 stacking_order_changed_ = false; 1347 stacking_order_changed_ = false;
1346 update_rect_ = gfx::Rect(); 1348 update_rect_ = gfx::Rect();
1347 1349
1348 needs_push_properties_ = false; 1350 needs_push_properties_ = false;
1349 num_dependents_need_push_properties_ = 0; 1351 num_dependents_need_push_properties_ = 0;
1350 } 1352 }
1351 1353
1354 void Layer::SetTypeForProtoSerialization(proto::LayerNode* proto) const {
1355 proto->set_type(proto::LayerType::Base);
1356 }
1357
1358 void Layer::ToLayerNodeProto(proto::LayerNode* proto) const {
1359 proto->set_id(layer_id_);
1360 SetTypeForProtoSerialization(proto);
1361
1362 if (parent_)
1363 proto->set_parent_id(parent_->id());
1364
1365 DCHECK_EQ(0, proto->children_size());
1366 for (const auto& child : children_) {
1367 child->ToLayerNodeProto(proto->add_children());
1368 }
1369
1370 if (mask_layer_)
1371 mask_layer_->ToLayerNodeProto(proto->mutable_mask_layer());
1372 if (replica_layer_)
1373 replica_layer_->ToLayerNodeProto(proto->mutable_replica_layer());
1374 }
1375
1376 void Layer::FromLayerNodeProto(const proto::LayerNode& proto,
1377 const LayerIdMap& layer_map) {
1378 DCHECK(proto.has_id());
1379 layer_id_ = proto.id();
1380
1381 // Recursively remove all children. In the case of when the updated
1382 // hierarchy has no children, or the children has changed, the old list
1383 // of children must be removed. The whole hierarchy is always sent, so
1384 // if there were no change in the children, they will be correctly added back
1385 // below.
1386 RemoveAllChildren();
1387 for (int i = 0; i < proto.children_size(); ++i) {
1388 const proto::LayerNode& child_proto = proto.children(i);
1389 DCHECK(child_proto.has_type());
1390 scoped_refptr<Layer> child =
1391 LayerProtoConverter::FindOrAllocateAndConstruct(child_proto, layer_map);
1392 child->FromLayerNodeProto(child_proto, layer_map);
1393 AddChild(child);
1394 }
1395
1396 if (mask_layer_)
1397 mask_layer_->RemoveFromParent();
1398 if (proto.has_mask_layer()) {
1399 mask_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct(
1400 proto.mask_layer(), layer_map);
1401 mask_layer_->FromLayerNodeProto(proto.mask_layer(), layer_map);
1402 mask_layer_->SetParent(this);
1403 // SetIsMask() is only ever called with true, so no need to reset flag.
1404 mask_layer_->SetIsMask(true);
1405 } else {
1406 mask_layer_ = nullptr;
1407 }
1408
1409 if (replica_layer_)
1410 replica_layer_->RemoveFromParent();
1411 if (proto.has_replica_layer()) {
1412 replica_layer_ = LayerProtoConverter::FindOrAllocateAndConstruct(
1413 proto.replica_layer(), layer_map);
1414 replica_layer_->FromLayerNodeProto(proto.replica_layer(), layer_map);
1415 replica_layer_->SetParent(this);
1416 } else {
1417 replica_layer_ = nullptr;
1418 }
1419 }
1420
1352 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { 1421 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
1353 return LayerImpl::Create(tree_impl, layer_id_, 1422 return LayerImpl::Create(tree_impl, layer_id_,
1354 new LayerImpl::SyncedScrollOffset); 1423 new LayerImpl::SyncedScrollOffset);
1355 } 1424 }
1356 1425
1357 bool Layer::DrawsContent() const { 1426 bool Layer::DrawsContent() const {
1358 return draws_content_; 1427 return draws_content_;
1359 } 1428 }
1360 1429
1361 bool Layer::HasDrawableContent() const { 1430 bool Layer::HasDrawableContent() const {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 this, layer_tree_host_->property_trees()->transform_tree); 1776 this, layer_tree_host_->property_trees()->transform_tree);
1708 } 1777 }
1709 1778
1710 gfx::Transform Layer::screen_space_transform() const { 1779 gfx::Transform Layer::screen_space_transform() const {
1711 DCHECK_NE(transform_tree_index_, -1); 1780 DCHECK_NE(transform_tree_index_, -1);
1712 return ScreenSpaceTransformFromPropertyTrees( 1781 return ScreenSpaceTransformFromPropertyTrees(
1713 this, layer_tree_host_->property_trees()->transform_tree); 1782 this, layer_tree_host_->property_trees()->transform_tree);
1714 } 1783 }
1715 1784
1716 } // namespace cc 1785 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_proto_converter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698