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

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

Issue 2493523003: cc: Remove unused proto conversion code. (Closed)
Patch Set: test Created 4 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/atomic_sequence_num.h" 12 #include "base/atomic_sequence_num.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "cc/base/simple_enclosed_region.h" 18 #include "cc/base/simple_enclosed_region.h"
19 #include "cc/debug/frame_viewer_instrumentation.h" 19 #include "cc/debug/frame_viewer_instrumentation.h"
20 #include "cc/input/main_thread_scrolling_reason.h" 20 #include "cc/input/main_thread_scrolling_reason.h"
21 #include "cc/layers/layer_client.h" 21 #include "cc/layers/layer_client.h"
22 #include "cc/layers/layer_impl.h" 22 #include "cc/layers/layer_impl.h"
23 #include "cc/layers/layer_proto_converter.h"
24 #include "cc/layers/scrollbar_layer_interface.h" 23 #include "cc/layers/scrollbar_layer_interface.h"
25 #include "cc/output/copy_output_request.h" 24 #include "cc/output/copy_output_request.h"
26 #include "cc/output/copy_output_result.h" 25 #include "cc/output/copy_output_result.h"
27 #include "cc/proto/cc_conversions.h" 26 #include "cc/proto/cc_conversions.h"
28 #include "cc/proto/gfx_conversions.h" 27 #include "cc/proto/gfx_conversions.h"
29 #include "cc/proto/layer.pb.h" 28 #include "cc/proto/layer.pb.h"
30 #include "cc/proto/skia_conversions.h" 29 #include "cc/proto/skia_conversions.h"
31 #include "cc/trees/draw_property_utils.h" 30 #include "cc/trees/draw_property_utils.h"
32 #include "cc/trees/effect_node.h" 31 #include "cc/trees/effect_node.h"
33 #include "cc/trees/layer_tree_host.h" 32 #include "cc/trees/layer_tree_host.h"
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 1237
1239 DCHECK_EQ(0, proto->children_size()); 1238 DCHECK_EQ(0, proto->children_size());
1240 for (const auto& child : inputs_.children) { 1239 for (const auto& child : inputs_.children) {
1241 child->ToLayerNodeProto(proto->add_children()); 1240 child->ToLayerNodeProto(proto->add_children());
1242 } 1241 }
1243 1242
1244 if (inputs_.mask_layer) 1243 if (inputs_.mask_layer)
1245 inputs_.mask_layer->ToLayerNodeProto(proto->mutable_mask_layer()); 1244 inputs_.mask_layer->ToLayerNodeProto(proto->mutable_mask_layer());
1246 } 1245 }
1247 1246
1248 void Layer::ClearLayerTreePropertiesForDeserializationAndAddToMap( 1247 void Layer::ToLayerPropertiesProto(proto::LayerProperties* proto) {
1249 LayerIdMap* layer_map) { 1248 proto->set_id(inputs_.layer_id);
1250 (*layer_map)[inputs_.layer_id] = this;
1251 1249
1252 if (layer_tree_)
1253 layer_tree_->UnregisterLayer(this);
1254
1255 layer_tree_host_ = nullptr;
1256 layer_tree_ = nullptr;
1257
1258 parent_ = nullptr;
1259
1260 // Clear these properties for all the children and add them to the map.
1261 for (auto& child : inputs_.children) {
1262 child->ClearLayerTreePropertiesForDeserializationAndAddToMap(layer_map);
1263 }
1264
1265 inputs_.children.clear();
1266
1267 if (inputs_.mask_layer) {
1268 inputs_.mask_layer->ClearLayerTreePropertiesForDeserializationAndAddToMap(
1269 layer_map);
1270 inputs_.mask_layer = nullptr;
1271 }
1272 }
1273
1274 void Layer::FromLayerNodeProto(const proto::LayerNode& proto,
1275 const LayerIdMap& layer_map,
1276 LayerTreeHost* layer_tree_host) {
1277 DCHECK(!layer_tree_host_);
1278 DCHECK(inputs_.children.empty());
1279 DCHECK(!inputs_.mask_layer);
1280 DCHECK(layer_tree_host);
1281 DCHECK(proto.has_id());
1282
1283 inputs_.layer_id = proto.id();
1284
1285 layer_tree_host_ = layer_tree_host;
1286 layer_tree_ = layer_tree_host->GetLayerTree();
1287 layer_tree_->RegisterLayer(this);
1288
1289 for (int i = 0; i < proto.children_size(); ++i) {
1290 const proto::LayerNode& child_proto = proto.children(i);
1291 DCHECK(child_proto.has_type());
1292 scoped_refptr<Layer> child =
1293 LayerProtoConverter::FindOrAllocateAndConstruct(child_proto, layer_map);
1294 // The child must now refer to this layer as its parent, and must also have
1295 // the same LayerTreeHost. This must be done before deserializing children.
1296 DCHECK(!child->parent_);
1297 child->parent_ = this;
1298 child->FromLayerNodeProto(child_proto, layer_map, layer_tree_host_);
1299 inputs_.children.push_back(child);
1300 }
1301
1302 if (proto.has_mask_layer()) {
1303 inputs_.mask_layer = LayerProtoConverter::FindOrAllocateAndConstruct(
1304 proto.mask_layer(), layer_map);
1305 inputs_.mask_layer->parent_ = this;
1306 inputs_.mask_layer->FromLayerNodeProto(proto.mask_layer(), layer_map,
1307 layer_tree_host_);
1308 }
1309 }
1310
1311 void Layer::ToLayerPropertiesProto(proto::LayerUpdate* layer_update,
1312 bool inputs_only) {
1313 // Always set properties metadata for serialized layers.
1314 proto::LayerProperties* proto = layer_update->add_layers();
1315 proto->set_id(inputs_.layer_id);
1316 LayerSpecificPropertiesToProto(proto, inputs_only);
1317 }
1318
1319 void Layer::FromLayerPropertiesProto(const proto::LayerProperties& proto) {
1320 DCHECK(proto.has_id());
1321 DCHECK_EQ(inputs_.layer_id, proto.id());
1322 FromLayerSpecificPropertiesProto(proto);
1323 }
1324
1325 void Layer::LayerSpecificPropertiesToProto(proto::LayerProperties* proto,
1326 bool inputs_only) {
1327 proto::BaseLayerProperties* base = proto->mutable_base(); 1250 proto::BaseLayerProperties* base = proto->mutable_base();
1328
1329 // Layer::Inputs Serialization ---------------------------------
1330 RectToProto(inputs_.update_rect, base->mutable_update_rect()); 1251 RectToProto(inputs_.update_rect, base->mutable_update_rect());
1331 inputs_.update_rect = gfx::Rect(); 1252 inputs_.update_rect = gfx::Rect();
1332 1253
1333 bool use_paint_properties = layer_tree_host_ && 1254 bool use_paint_properties = layer_tree_host_ &&
1334 paint_properties_.source_frame_number == 1255 paint_properties_.source_frame_number ==
1335 layer_tree_host_->SourceFrameNumber(); 1256 layer_tree_host_->SourceFrameNumber();
1336 SizeToProto(use_paint_properties ? paint_properties_.bounds : inputs_.bounds, 1257 SizeToProto(use_paint_properties ? paint_properties_.bounds : inputs_.bounds,
1337 base->mutable_bounds()); 1258 base->mutable_bounds());
1338 1259
1339 base->set_masks_to_bounds(inputs_.masks_to_bounds); 1260 base->set_masks_to_bounds(inputs_.masks_to_bounds);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 int clip_parent_id = 1295 int clip_parent_id =
1375 inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID; 1296 inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID;
1376 base->set_clip_parent_id(clip_parent_id); 1297 base->set_clip_parent_id(clip_parent_id);
1377 1298
1378 base->set_has_will_change_transform_hint( 1299 base->set_has_will_change_transform_hint(
1379 inputs_.has_will_change_transform_hint); 1300 inputs_.has_will_change_transform_hint);
1380 base->set_hide_layer_and_subtree(inputs_.hide_layer_and_subtree); 1301 base->set_hide_layer_and_subtree(inputs_.hide_layer_and_subtree);
1381 1302
1382 // TODO(nyquist): Add support for serializing FilterOperations for 1303 // TODO(nyquist): Add support for serializing FilterOperations for
1383 // |filters_| and |background_filters_|. See crbug.com/541321. 1304 // |filters_| and |background_filters_|. See crbug.com/541321.
1384
1385 if (inputs_only)
1386 return;
1387 // -----------------------------------------------------------
1388
1389 // TODO(khushalsagar): Stop serializing the data below when crbug.com/648442.
1390
1391 base->set_safe_opaque_background_color(safe_opaque_background_color_);
1392 // TODO(nyquist): Figure out what to do with debug info. See crbug.com/570372.
1393 base->set_transform_free_index(transform_tree_index_);
1394 base->set_effect_tree_index(effect_tree_index_);
1395 base->set_clip_tree_index(clip_tree_index_);
1396 base->set_scroll_tree_index(scroll_tree_index_);
1397 Vector2dFToProto(offset_to_transform_parent_,
1398 base->mutable_offset_to_transform_parent());
1399 base->set_draws_content(draws_content_);
1400 base->set_may_contain_video(may_contain_video_);
1401 base->set_hide_layer_and_subtree(inputs_.hide_layer_and_subtree);
1402 base->set_subtree_property_changed(subtree_property_changed_);
1403
1404 // TODO(nyquist): Add support for serializing FilterOperations for
1405 // |filters_| and |background_filters_|. See crbug.com/541321.
1406
1407 base->set_masks_to_bounds(inputs_.masks_to_bounds);
1408 base->set_main_thread_scrolling_reasons(
1409 inputs_.main_thread_scrolling_reasons);
1410 RegionToProto(inputs_.non_fast_scrollable_region,
1411 base->mutable_non_fast_scrollable_region());
1412 RegionToProto(inputs_.touch_event_handler_region,
1413 base->mutable_touch_event_handler_region());
1414 base->set_contents_opaque(inputs_.contents_opaque);
1415 base->set_opacity(inputs_.opacity);
1416 base->set_blend_mode(SkXfermodeModeToProto(inputs_.blend_mode));
1417 base->set_is_root_for_isolated_group(inputs_.is_root_for_isolated_group);
1418 PointFToProto(inputs_.position, base->mutable_position());
1419 base->set_is_container_for_fixed_position_layers(
1420 inputs_.is_container_for_fixed_position_layers);
1421 inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint());
1422 base->set_should_flatten_transform(inputs_.should_flatten_transform);
1423 base->set_should_flatten_transform_from_property_tree(
1424 should_flatten_transform_from_property_tree_);
1425 base->set_draw_blend_mode(SkXfermodeModeToProto(draw_blend_mode_));
1426 base->set_num_descendants_that_draw_content(
1427 num_descendants_that_draw_content_);
1428 if (scroll_children_) {
1429 for (auto* child : *scroll_children_)
1430 base->add_scroll_children_ids(child->id());
1431 }
1432 if (clip_children_) {
1433 for (auto* child : *clip_children_)
1434 base->add_clip_children_ids(child->id());
1435 }
1436
1437 // TODO(nyquist): Figure out what to do with CopyRequests.
1438 // See crbug.com/570374.
1439
1440 // TODO(nyquist): Figure out what to do with ElementAnimations.
1441 // See crbug.com/570376.
1442 }
1443
1444 void Layer::FromLayerSpecificPropertiesProto(
1445 const proto::LayerProperties& proto) {
1446 DCHECK(proto.has_base());
1447 DCHECK(layer_tree_host_);
1448 const proto::BaseLayerProperties& base = proto.base();
1449
1450 inputs_.transform_origin = ProtoToPoint3F(base.transform_origin());
1451 inputs_.background_color = base.background_color();
1452 safe_opaque_background_color_ = base.safe_opaque_background_color();
1453 inputs_.bounds = ProtoToSize(base.bounds());
1454
1455 transform_tree_index_ = base.transform_free_index();
1456 effect_tree_index_ = base.effect_tree_index();
1457 clip_tree_index_ = base.clip_tree_index();
1458 scroll_tree_index_ = base.scroll_tree_index();
1459 offset_to_transform_parent_ =
1460 ProtoToVector2dF(base.offset_to_transform_parent());
1461 inputs_.double_sided = base.double_sided();
1462 draws_content_ = base.draws_content();
1463 may_contain_video_ = base.may_contain_video();
1464 inputs_.hide_layer_and_subtree = base.hide_layer_and_subtree();
1465 subtree_property_changed_ = base.subtree_property_changed();
1466 inputs_.masks_to_bounds = base.masks_to_bounds();
1467 inputs_.main_thread_scrolling_reasons = base.main_thread_scrolling_reasons();
1468 inputs_.non_fast_scrollable_region =
1469 RegionFromProto(base.non_fast_scrollable_region());
1470 inputs_.touch_event_handler_region =
1471 RegionFromProto(base.touch_event_handler_region());
1472 inputs_.contents_opaque = base.contents_opaque();
1473 inputs_.opacity = base.opacity();
1474 inputs_.blend_mode = SkXfermodeModeFromProto(base.blend_mode());
1475 inputs_.is_root_for_isolated_group = base.is_root_for_isolated_group();
1476 inputs_.position = ProtoToPointF(base.position());
1477 inputs_.is_container_for_fixed_position_layers =
1478 base.is_container_for_fixed_position_layers();
1479 inputs_.position_constraint.FromProtobuf(base.position_constraint());
1480 inputs_.should_flatten_transform = base.should_flatten_transform();
1481 should_flatten_transform_from_property_tree_ =
1482 base.should_flatten_transform_from_property_tree();
1483 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode());
1484 inputs_.use_parent_backface_visibility =
1485 base.use_parent_backface_visibility();
1486 inputs_.transform = ProtoToTransform(base.transform());
1487 inputs_.sorting_context_id = base.sorting_context_id();
1488 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content();
1489
1490 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id();
1491 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal();
1492 inputs_.user_scrollable_vertical = base.user_scrollable_vertical();
1493
1494 inputs_.scroll_parent = base.scroll_parent_id() == INVALID_ID
1495 ? nullptr
1496 : layer_tree_->LayerById(base.scroll_parent_id());
1497
1498 // If there have been scroll children entries in previous deserializations,
1499 // clear out the set. If there have been none, initialize the set of children.
1500 // After this, the set is in the correct state to only add the new children.
1501 // If the set of children has not changed, for now this code still rebuilds
1502 // the set.
1503 if (scroll_children_)
1504 scroll_children_->clear();
1505 else if (base.scroll_children_ids_size() > 0)
1506 scroll_children_.reset(new std::set<Layer*>);
1507 for (int i = 0; i < base.scroll_children_ids_size(); ++i) {
1508 int child_id = base.scroll_children_ids(i);
1509 scoped_refptr<Layer> child = layer_tree_->LayerById(child_id);
1510 scroll_children_->insert(child.get());
1511 }
1512
1513 inputs_.clip_parent = base.clip_parent_id() == INVALID_ID
1514 ? nullptr
1515 : layer_tree_->LayerById(base.clip_parent_id());
1516
1517 // If there have been clip children entries in previous deserializations,
1518 // clear out the set. If there have been none, initialize the set of children.
1519 // After this, the set is in the correct state to only add the new children.
1520 // If the set of children has not changed, for now this code still rebuilds
1521 // the set.
1522 if (clip_children_)
1523 clip_children_->clear();
1524 else if (base.clip_children_ids_size() > 0)
1525 clip_children_.reset(new std::set<Layer*>);
1526 for (int i = 0; i < base.clip_children_ids_size(); ++i) {
1527 int child_id = base.clip_children_ids(i);
1528 scoped_refptr<Layer> child = layer_tree_->LayerById(child_id);
1529 clip_children_->insert(child.get());
1530 }
1531
1532 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset());
1533
1534 inputs_.update_rect.Union(ProtoToRect(base.update_rect()));
1535
1536 inputs_.has_will_change_transform_hint =
1537 base.has_will_change_transform_hint();
1538 } 1305 }
1539 1306
1540 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { 1307 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
1541 return LayerImpl::Create(tree_impl, inputs_.layer_id); 1308 return LayerImpl::Create(tree_impl, inputs_.layer_id);
1542 } 1309 }
1543 1310
1544 bool Layer::DrawsContent() const { 1311 bool Layer::DrawsContent() const {
1545 return draws_content_; 1312 return draws_content_;
1546 } 1313 }
1547 1314
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 1664
1898 LayerTree* Layer::GetLayerTree() const { 1665 LayerTree* Layer::GetLayerTree() const {
1899 return layer_tree_; 1666 return layer_tree_;
1900 } 1667 }
1901 1668
1902 void Layer::SetLayerIdForTesting(int id) { 1669 void Layer::SetLayerIdForTesting(int id) {
1903 inputs_.layer_id = id; 1670 inputs_.layer_id = id;
1904 } 1671 }
1905 1672
1906 } // namespace cc 1673 } // 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