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

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

Issue 2375363002: cc/blimp: Set up the framework for state serialization. (Closed)
Patch Set: test update Created 4 years, 2 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
« 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 25 matching lines...) Expand all
36 #include "cc/trees/layer_tree_impl.h" 36 #include "cc/trees/layer_tree_impl.h"
37 #include "cc/trees/transform_node.h" 37 #include "cc/trees/transform_node.h"
38 #include "third_party/skia/include/core/SkImageFilter.h" 38 #include "third_party/skia/include/core/SkImageFilter.h"
39 #include "ui/gfx/geometry/rect_conversions.h" 39 #include "ui/gfx/geometry/rect_conversions.h"
40 #include "ui/gfx/geometry/vector2d_conversions.h" 40 #include "ui/gfx/geometry/vector2d_conversions.h"
41 41
42 namespace cc { 42 namespace cc {
43 43
44 base::StaticAtomicSequenceNumber g_next_layer_id; 44 base::StaticAtomicSequenceNumber g_next_layer_id;
45 45
46 Layer::Inputs::Inputs() 46 Layer::Inputs::Inputs(int layer_id)
47 : // Layer IDs start from 1. 47 : layer_id(layer_id),
48 layer_id(g_next_layer_id.GetNext() + 1),
49 masks_to_bounds(false), 48 masks_to_bounds(false),
50 mask_layer(nullptr), 49 mask_layer(nullptr),
51 opacity(1.f), 50 opacity(1.f),
52 blend_mode(SkXfermode::kSrcOver_Mode), 51 blend_mode(SkXfermode::kSrcOver_Mode),
53 is_root_for_isolated_group(false), 52 is_root_for_isolated_group(false),
54 contents_opaque(false), 53 contents_opaque(false),
55 is_drawable(false), 54 is_drawable(false),
56 double_sided(true), 55 double_sided(true),
57 should_flatten_transform(true), 56 should_flatten_transform(true),
58 sorting_context_id(0), 57 sorting_context_id(0),
(...skipping 12 matching lines...) Expand all
71 hide_layer_and_subtree(false), 70 hide_layer_and_subtree(false),
72 client(nullptr) {} 71 client(nullptr) {}
73 72
74 Layer::Inputs::~Inputs() {} 73 Layer::Inputs::~Inputs() {}
75 74
76 scoped_refptr<Layer> Layer::Create() { 75 scoped_refptr<Layer> Layer::Create() {
77 return make_scoped_refptr(new Layer()); 76 return make_scoped_refptr(new Layer());
78 } 77 }
79 78
80 Layer::Layer() 79 Layer::Layer()
80 // Layer IDs start from 1.
81 : Layer(g_next_layer_id.GetNext() + 1) {}
82
83 Layer::Layer(int layer_id)
81 : ignore_set_needs_commit_(false), 84 : ignore_set_needs_commit_(false),
82 parent_(nullptr), 85 parent_(nullptr),
83 layer_tree_host_(nullptr), 86 layer_tree_host_(nullptr),
84 layer_tree_(nullptr), 87 layer_tree_(nullptr),
88 inputs_(layer_id),
85 num_descendants_that_draw_content_(0), 89 num_descendants_that_draw_content_(0),
86 transform_tree_index_(TransformTree::kInvalidNodeId), 90 transform_tree_index_(TransformTree::kInvalidNodeId),
87 effect_tree_index_(EffectTree::kInvalidNodeId), 91 effect_tree_index_(EffectTree::kInvalidNodeId),
88 clip_tree_index_(ClipTree::kInvalidNodeId), 92 clip_tree_index_(ClipTree::kInvalidNodeId),
89 scroll_tree_index_(ScrollTree::kInvalidNodeId), 93 scroll_tree_index_(ScrollTree::kInvalidNodeId),
90 property_tree_sequence_number_(-1), 94 property_tree_sequence_number_(-1),
91 should_flatten_transform_from_property_tree_(false), 95 should_flatten_transform_from_property_tree_(false),
92 draws_content_(false), 96 draws_content_(false),
93 use_local_transform_for_backface_visibility_(false), 97 use_local_transform_for_backface_visibility_(false),
94 should_check_backface_visibility_(false), 98 should_check_backface_visibility_(false),
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 1292
1289 if (proto.has_mask_layer()) { 1293 if (proto.has_mask_layer()) {
1290 inputs_.mask_layer = LayerProtoConverter::FindOrAllocateAndConstruct( 1294 inputs_.mask_layer = LayerProtoConverter::FindOrAllocateAndConstruct(
1291 proto.mask_layer(), layer_map); 1295 proto.mask_layer(), layer_map);
1292 inputs_.mask_layer->parent_ = this; 1296 inputs_.mask_layer->parent_ = this;
1293 inputs_.mask_layer->FromLayerNodeProto(proto.mask_layer(), layer_map, 1297 inputs_.mask_layer->FromLayerNodeProto(proto.mask_layer(), layer_map,
1294 layer_tree_host_); 1298 layer_tree_host_);
1295 } 1299 }
1296 } 1300 }
1297 1301
1298 void Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update) { 1302 void Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update,
1303 bool inputs_only) {
1299 // Always set properties metadata for serialized layers. 1304 // Always set properties metadata for serialized layers.
1300 proto::LayerProperties* proto = layer_update->add_layers(); 1305 proto::LayerProperties* proto = layer_update->add_layers();
1301 proto->set_id(inputs_.layer_id); 1306 proto->set_id(inputs_.layer_id);
1302 LayerSpecificPropertiesToProto(proto); 1307 LayerSpecificPropertiesToProto(proto, inputs_only);
1303 } 1308 }
1304 1309
1305 void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) { 1310 void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) {
1306 DCHECK(proto.has_id()); 1311 DCHECK(proto.has_id());
1307 DCHECK_EQ(inputs_.layer_id, proto.id()); 1312 DCHECK_EQ(inputs_.layer_id, proto.id());
1308 FromLayerSpecificPropertiesProto(proto); 1313 FromLayerSpecificPropertiesProto(proto);
1309 } 1314 }
1310 1315
1311 void Layer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto) { 1316 void Layer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto,
1317 bool inputs_only) {
1312 proto::BaseLayerProperties* base = proto->mutable_base(); 1318 proto::BaseLayerProperties* base = proto->mutable_base();
1313 1319
1320 // Layer::Inputs Serialization ---------------------------------
1321 RectToProto(inputs_.update_rect, base->mutable_update_rect());
1322 inputs_.update_rect = gfx::Rect();
1323
1314 bool use_paint_properties = layer_tree_host_ && 1324 bool use_paint_properties = layer_tree_host_ &&
1315 paint_properties_.source_frame_number == 1325 paint_properties_.source_frame_number ==
1316 layer_tree_host_->SourceFrameNumber(); 1326 layer_tree_host_->SourceFrameNumber();
1317
1318 Point3FToProto(inputs_.transform_origin, base->mutable_transform_origin());
1319 base->set_background_color(inputs_.background_color);
1320 base->set_safe_opaque_background_color(safe_opaque_background_color_);
1321 SizeToProto(use_paint_properties ? paint_properties_.bounds : inputs_.bounds, 1327 SizeToProto(use_paint_properties ? paint_properties_.bounds : inputs_.bounds,
1322 base->mutable_bounds()); 1328 base->mutable_bounds());
1323 1329
1330 base->set_masks_to_bounds(inputs_.masks_to_bounds);
1331 base->set_opacity(inputs_.opacity);
1332 base->set_blend_mode(SkXfermodeModeToProto(inputs_.blend_mode));
1333 base->set_is_root_for_isolated_group(inputs_.is_root_for_isolated_group);
1334 base->set_contents_opaque(inputs_.contents_opaque);
1335 PointFToProto(inputs_.position, base->mutable_position());
1336 TransformToProto(inputs_.transform, base->mutable_transform());
1337 Point3FToProto(inputs_.transform_origin, base->mutable_transform_origin());
1338 base->set_is_drawable(inputs_.is_drawable);
1339 base->set_double_sided(inputs_.double_sided);
1340 base->set_should_flatten_transform(inputs_.should_flatten_transform);
1341 base->set_sorting_context_id(inputs_.sorting_context_id);
1342 base->set_use_parent_backface_visibility(
1343 inputs_.use_parent_backface_visibility);
1344 base->set_background_color(inputs_.background_color);
1345 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset());
1346 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id);
1347 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal);
1348 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical);
1349 base->set_main_thread_scrolling_reasons(
1350 inputs_.main_thread_scrolling_reasons);
1351 RegionToProto(inputs_.non_fast_scrollable_region,
1352 base->mutable_non_fast_scrollable_region());
1353 RegionToProto(inputs_.touch_event_handler_region,
1354 base->mutable_touch_event_handler_region());
1355 base->set_is_container_for_fixed_position_layers(
1356 inputs_.is_container_for_fixed_position_layers);
1357 inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint());
1358 inputs_.sticky_position_constraint.ToProtobuf(
1359 base->mutable_sticky_position_constraint());
1360
1361 int scroll_parent_id =
1362 inputs_.scroll_parent ? inputs_.scroll_parent->id() : INVALID_ID;
1363 base->set_scroll_parent_id(scroll_parent_id);
1364
1365 int clip_parent_id =
1366 inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID;
1367 base->set_clip_parent_id(clip_parent_id);
1368
1369 base->set_has_will_change_transform_hint(
1370 inputs_.has_will_change_transform_hint);
1371 base->set_hide_layer_and_subtree(inputs_.hide_layer_and_subtree);
1372
1373 // TODO(nyquist): Add support for serializing FilterOperations for
1374 // |filters_| and |background_filters_|. See crbug.com/541321.
1375
1376 if (inputs_only)
1377 return;
1378 // -----------------------------------------------------------
1379
1380 // TODO(khushalsagar): Stop serializing the data below when crbug.com/648442.
1381
1382 base->set_safe_opaque_background_color(safe_opaque_background_color_);
1324 // TODO(nyquist): Figure out what to do with debug info. See crbug.com/570372. 1383 // TODO(nyquist): Figure out what to do with debug info. See crbug.com/570372.
1325
1326 base->set_transform_free_index(transform_tree_index_); 1384 base->set_transform_free_index(transform_tree_index_);
1327 base->set_effect_tree_index(effect_tree_index_); 1385 base->set_effect_tree_index(effect_tree_index_);
1328 base->set_clip_tree_index(clip_tree_index_); 1386 base->set_clip_tree_index(clip_tree_index_);
1329 base->set_scroll_tree_index(scroll_tree_index_); 1387 base->set_scroll_tree_index(scroll_tree_index_);
1330 Vector2dFToProto(offset_to_transform_parent_, 1388 Vector2dFToProto(offset_to_transform_parent_,
1331 base->mutable_offset_to_transform_parent()); 1389 base->mutable_offset_to_transform_parent());
1332 base->set_double_sided(inputs_.double_sided);
1333 base->set_draws_content(draws_content_); 1390 base->set_draws_content(draws_content_);
1334 base->set_may_contain_video(may_contain_video_); 1391 base->set_may_contain_video(may_contain_video_);
1335 base->set_hide_layer_and_subtree(inputs_.hide_layer_and_subtree); 1392 base->set_hide_layer_and_subtree(inputs_.hide_layer_and_subtree);
1336 base->set_subtree_property_changed(subtree_property_changed_); 1393 base->set_subtree_property_changed(subtree_property_changed_);
1337 1394
1338 // TODO(nyquist): Add support for serializing FilterOperations for 1395 // TODO(nyquist): Add support for serializing FilterOperations for
1339 // |filters_| and |background_filters_|. See crbug.com/541321. 1396 // |filters_| and |background_filters_|. See crbug.com/541321.
1340 1397
1341 base->set_masks_to_bounds(inputs_.masks_to_bounds); 1398 base->set_masks_to_bounds(inputs_.masks_to_bounds);
1342 base->set_main_thread_scrolling_reasons( 1399 base->set_main_thread_scrolling_reasons(
1343 inputs_.main_thread_scrolling_reasons); 1400 inputs_.main_thread_scrolling_reasons);
1344 RegionToProto(inputs_.non_fast_scrollable_region, 1401 RegionToProto(inputs_.non_fast_scrollable_region,
1345 base->mutable_non_fast_scrollable_region()); 1402 base->mutable_non_fast_scrollable_region());
1346 RegionToProto(inputs_.touch_event_handler_region, 1403 RegionToProto(inputs_.touch_event_handler_region,
1347 base->mutable_touch_event_handler_region()); 1404 base->mutable_touch_event_handler_region());
1348 base->set_contents_opaque(inputs_.contents_opaque); 1405 base->set_contents_opaque(inputs_.contents_opaque);
1349 base->set_opacity(inputs_.opacity); 1406 base->set_opacity(inputs_.opacity);
1350 base->set_blend_mode(SkXfermodeModeToProto(inputs_.blend_mode)); 1407 base->set_blend_mode(SkXfermodeModeToProto(inputs_.blend_mode));
1351 base->set_is_root_for_isolated_group(inputs_.is_root_for_isolated_group); 1408 base->set_is_root_for_isolated_group(inputs_.is_root_for_isolated_group);
1352 PointFToProto(inputs_.position, base->mutable_position()); 1409 PointFToProto(inputs_.position, base->mutable_position());
1353 base->set_is_container_for_fixed_position_layers( 1410 base->set_is_container_for_fixed_position_layers(
1354 inputs_.is_container_for_fixed_position_layers); 1411 inputs_.is_container_for_fixed_position_layers);
1355 inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint()); 1412 inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint());
1356 base->set_should_flatten_transform(inputs_.should_flatten_transform); 1413 base->set_should_flatten_transform(inputs_.should_flatten_transform);
1357 base->set_should_flatten_transform_from_property_tree( 1414 base->set_should_flatten_transform_from_property_tree(
1358 should_flatten_transform_from_property_tree_); 1415 should_flatten_transform_from_property_tree_);
1359 base->set_draw_blend_mode(SkXfermodeModeToProto(draw_blend_mode_)); 1416 base->set_draw_blend_mode(SkXfermodeModeToProto(draw_blend_mode_));
1360 base->set_use_parent_backface_visibility(
1361 inputs_.use_parent_backface_visibility);
1362 TransformToProto(inputs_.transform, base->mutable_transform());
1363 base->set_sorting_context_id(inputs_.sorting_context_id);
1364 base->set_num_descendants_that_draw_content( 1417 base->set_num_descendants_that_draw_content(
1365 num_descendants_that_draw_content_); 1418 num_descendants_that_draw_content_);
1366
1367 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id);
1368 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal);
1369 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical);
1370
1371 int scroll_parent_id =
1372 inputs_.scroll_parent ? inputs_.scroll_parent->id() : INVALID_ID;
1373 base->set_scroll_parent_id(scroll_parent_id);
1374
1375 if (scroll_children_) { 1419 if (scroll_children_) {
1376 for (auto* child : *scroll_children_) 1420 for (auto* child : *scroll_children_)
1377 base->add_scroll_children_ids(child->id()); 1421 base->add_scroll_children_ids(child->id());
1378 } 1422 }
1379
1380 int clip_parent_id =
1381 inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID;
1382 base->set_clip_parent_id(clip_parent_id);
1383
1384 if (clip_children_) { 1423 if (clip_children_) {
1385 for (auto* child : *clip_children_) 1424 for (auto* child : *clip_children_)
1386 base->add_clip_children_ids(child->id()); 1425 base->add_clip_children_ids(child->id());
1387 } 1426 }
1388 1427
1389 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset());
1390
1391 // TODO(nyquist): Figure out what to do with CopyRequests. 1428 // TODO(nyquist): Figure out what to do with CopyRequests.
1392 // See crbug.com/570374. 1429 // See crbug.com/570374.
1393 1430
1394 RectToProto(inputs_.update_rect, base->mutable_update_rect());
1395
1396 // TODO(nyquist): Figure out what to do with ElementAnimations. 1431 // TODO(nyquist): Figure out what to do with ElementAnimations.
1397 // See crbug.com/570376. 1432 // See crbug.com/570376.
1398
1399 inputs_.update_rect = gfx::Rect();
1400
1401 base->set_has_will_change_transform_hint(
1402 inputs_.has_will_change_transform_hint);
1403 } 1433 }
1404 1434
1405 void Layer::FromLayerSpecificPropertiesProto( 1435 void Layer::FromLayerSpecificPropertiesProto(
1406 const proto::LayerProperties& proto) { 1436 const proto::LayerProperties& proto) {
1407 DCHECK(proto.has_base()); 1437 DCHECK(proto.has_base());
1408 DCHECK(layer_tree_host_); 1438 DCHECK(layer_tree_host_);
1409 const proto::BaseLayerProperties& base = proto.base(); 1439 const proto::BaseLayerProperties& base = proto.base();
1410 1440
1411 inputs_.transform_origin = ProtoToPoint3F(base.transform_origin()); 1441 inputs_.transform_origin = ProtoToPoint3F(base.transform_origin());
1412 inputs_.background_color = base.background_color(); 1442 inputs_.background_color = base.background_color();
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId); 1861 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId);
1832 return draw_property_utils::ScreenSpaceTransform( 1862 return draw_property_utils::ScreenSpaceTransform(
1833 this, layer_tree_->property_trees()->transform_tree); 1863 this, layer_tree_->property_trees()->transform_tree);
1834 } 1864 }
1835 1865
1836 LayerTree* Layer::GetLayerTree() const { 1866 LayerTree* Layer::GetLayerTree() const {
1837 return layer_tree_; 1867 return layer_tree_;
1838 } 1868 }
1839 1869
1840 } // namespace cc 1870 } // 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