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

Side by Side Diff: cc/trees/layer_tree_host.cc

Issue 1973083002: Use element id's for animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.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 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer_.get()); 973 PropertyTreeBuilder::PreCalculateMetaInformation(root_layer_.get());
974 gfx::Transform identity_transform; 974 gfx::Transform identity_transform;
975 PropertyTreeBuilder::BuildPropertyTrees( 975 PropertyTreeBuilder::BuildPropertyTrees(
976 root_layer_.get(), page_scale_layer_.get(), 976 root_layer_.get(), page_scale_layer_.get(),
977 inner_viewport_scroll_layer_.get(), outer_viewport_scroll_layer_.get(), 977 inner_viewport_scroll_layer_.get(), outer_viewport_scroll_layer_.get(),
978 overscroll_elasticity_layer_.get(), elastic_overscroll_, 978 overscroll_elasticity_layer_.get(), elastic_overscroll_,
979 page_scale_factor_, device_scale_factor_, 979 page_scale_factor_, device_scale_factor_,
980 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_); 980 gfx::Rect(device_viewport_size_), identity_transform, &property_trees_);
981 } 981 }
982 982
983 static void SetElementIdForTesting(Layer* layer) {
984 layer->SetElementId(LayerIdToElementIdForTesting(layer->id()));
985 }
986
987 void LayerTreeHost::SetElementIdsForTesting() {
988 LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting);
989 }
990
983 bool LayerTreeHost::UsingSharedMemoryResources() { 991 bool LayerTreeHost::UsingSharedMemoryResources() {
984 return GetRendererCapabilities().using_shared_memory_resources; 992 return GetRendererCapabilities().using_shared_memory_resources;
985 } 993 }
986 994
987 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { 995 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) {
988 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number", 996 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number",
989 source_frame_number()); 997 source_frame_number());
990 998
991 UpdateHudLayer(); 999 UpdateHudLayer();
992 1000
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 return SurfaceSequence(surface_id_namespace_, next_surface_sequence_++); 1299 return SurfaceSequence(surface_id_namespace_, next_surface_sequence_++);
1292 } 1300 }
1293 1301
1294 void LayerTreeHost::SetLayerTreeMutator( 1302 void LayerTreeHost::SetLayerTreeMutator(
1295 std::unique_ptr<LayerTreeMutator> mutator) { 1303 std::unique_ptr<LayerTreeMutator> mutator) {
1296 proxy_->SetMutator(std::move(mutator)); 1304 proxy_->SetMutator(std::move(mutator));
1297 } 1305 }
1298 1306
1299 Layer* LayerTreeHost::LayerById(int id) const { 1307 Layer* LayerTreeHost::LayerById(int id) const {
1300 LayerIdMap::const_iterator iter = layer_id_map_.find(id); 1308 LayerIdMap::const_iterator iter = layer_id_map_.find(id);
1301 return iter != layer_id_map_.end() ? iter->second : NULL; 1309 return iter != layer_id_map_.end() ? iter->second : nullptr;
1310 }
1311
1312 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const {
1313 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id);
1314 return iter != element_layers_map_.end() ? iter->second : nullptr;
1315 }
1316
1317 void LayerTreeHost::AddToElementMap(Layer* layer) {
1318 if (!layer->element_id())
1319 return;
1320
1321 element_layers_map_[layer->element_id()] = layer;
1322 }
1323
1324 void LayerTreeHost::RemoveFromElementMap(Layer* layer) {
1325 if (!layer->element_id())
1326 return;
1327
1328 element_layers_map_.erase(layer->element_id());
1302 } 1329 }
1303 1330
1304 void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) { 1331 void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) {
1305 layers_that_should_push_properties_.insert(layer); 1332 layers_that_should_push_properties_.insert(layer);
1306 } 1333 }
1307 1334
1308 void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) { 1335 void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) {
1309 layers_that_should_push_properties_.erase(layer); 1336 layers_that_should_push_properties_.erase(layer);
1310 } 1337 }
1311 1338
1312 std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() { 1339 std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() {
1313 return layers_that_should_push_properties_; 1340 return layers_that_should_push_properties_;
1314 } 1341 }
1315 1342
1316 bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) { 1343 bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) {
1317 return layers_that_should_push_properties_.find(layer) != 1344 return layers_that_should_push_properties_.find(layer) !=
1318 layers_that_should_push_properties_.end(); 1345 layers_that_should_push_properties_.end();
1319 } 1346 }
1320 1347
1321 void LayerTreeHost::RegisterLayer(Layer* layer) { 1348 void LayerTreeHost::RegisterLayer(Layer* layer) {
1322 DCHECK(!LayerById(layer->id())); 1349 DCHECK(!LayerById(layer->id()));
1323 DCHECK(!in_paint_layer_contents_); 1350 DCHECK(!in_paint_layer_contents_);
1324 layer_id_map_[layer->id()] = layer; 1351 layer_id_map_[layer->id()] = layer;
1325 animation_host_->RegisterElement(layer->id(), ElementListType::ACTIVE); 1352 if (layer->element_id()) {
1353 animation_host_->RegisterElement(layer->element_id(),
1354 ElementListType::ACTIVE);
1355 }
1326 } 1356 }
1327 1357
1328 void LayerTreeHost::UnregisterLayer(Layer* layer) { 1358 void LayerTreeHost::UnregisterLayer(Layer* layer) {
1329 DCHECK(LayerById(layer->id())); 1359 DCHECK(LayerById(layer->id()));
1330 DCHECK(!in_paint_layer_contents_); 1360 DCHECK(!in_paint_layer_contents_);
1331 animation_host_->UnregisterElement(layer->id(), ElementListType::ACTIVE); 1361 if (layer->element_id()) {
1362 animation_host_->UnregisterElement(layer->element_id(),
1363 ElementListType::ACTIVE);
1364 }
1332 RemoveLayerShouldPushProperties(layer); 1365 RemoveLayerShouldPushProperties(layer);
1333 layer_id_map_.erase(layer->id()); 1366 layer_id_map_.erase(layer->id());
1334 } 1367 }
1335 1368
1336 bool LayerTreeHost::IsElementInList(ElementId element_id, 1369 bool LayerTreeHost::IsElementInList(ElementId element_id,
1337 ElementListType list_type) const { 1370 ElementListType list_type) const {
1338 return list_type == ElementListType::ACTIVE && LayerById(element_id); 1371 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id);
1339 } 1372 }
1340 1373
1341 void LayerTreeHost::SetMutatorsNeedCommit() { 1374 void LayerTreeHost::SetMutatorsNeedCommit() {
1342 SetNeedsCommit(); 1375 SetNeedsCommit();
1343 } 1376 }
1344 1377
1345 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { 1378 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() {
1346 property_trees_.needs_rebuild = true; 1379 property_trees_.needs_rebuild = true;
1347 } 1380 }
1348 1381
1349 void LayerTreeHost::SetElementFilterMutated(ElementId element_id, 1382 void LayerTreeHost::SetElementFilterMutated(ElementId element_id,
1350 ElementListType list_type, 1383 ElementListType list_type,
1351 const FilterOperations& filters) { 1384 const FilterOperations& filters) {
1352 Layer* layer = LayerById(element_id); 1385 Layer* layer = LayerByElementId(element_id);
1353 DCHECK(layer); 1386 DCHECK(layer);
1354 layer->OnFilterAnimated(filters); 1387 layer->OnFilterAnimated(filters);
1355 } 1388 }
1356 1389
1357 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id, 1390 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id,
1358 ElementListType list_type, 1391 ElementListType list_type,
1359 float opacity) { 1392 float opacity) {
1360 Layer* layer = LayerById(element_id); 1393 Layer* layer = LayerByElementId(element_id);
1361 DCHECK(layer); 1394 DCHECK(layer);
1362 layer->OnOpacityAnimated(opacity); 1395 layer->OnOpacityAnimated(opacity);
1363 } 1396 }
1364 1397
1365 void LayerTreeHost::SetElementTransformMutated( 1398 void LayerTreeHost::SetElementTransformMutated(
1366 ElementId element_id, 1399 ElementId element_id,
1367 ElementListType list_type, 1400 ElementListType list_type,
1368 const gfx::Transform& transform) { 1401 const gfx::Transform& transform) {
1369 Layer* layer = LayerById(element_id); 1402 Layer* layer = LayerByElementId(element_id);
1370 DCHECK(layer); 1403 DCHECK(layer);
1371 layer->OnTransformAnimated(transform); 1404 layer->OnTransformAnimated(transform);
1372 } 1405 }
1373 1406
1374 void LayerTreeHost::SetElementScrollOffsetMutated( 1407 void LayerTreeHost::SetElementScrollOffsetMutated(
1375 ElementId element_id, 1408 ElementId element_id,
1376 ElementListType list_type, 1409 ElementListType list_type,
1377 const gfx::ScrollOffset& scroll_offset) { 1410 const gfx::ScrollOffset& scroll_offset) {
1378 Layer* layer = LayerById(element_id); 1411 Layer* layer = LayerByElementId(element_id);
1379 DCHECK(layer); 1412 DCHECK(layer);
1380 layer->OnScrollOffsetAnimated(scroll_offset); 1413 layer->OnScrollOffsetAnimated(scroll_offset);
1381 } 1414 }
1382 1415
1383 void LayerTreeHost::ElementTransformIsAnimatingChanged( 1416 void LayerTreeHost::ElementTransformIsAnimatingChanged(
1384 ElementId element_id, 1417 ElementId element_id,
1385 ElementListType list_type, 1418 ElementListType list_type,
1386 AnimationChangeType change_type, 1419 AnimationChangeType change_type,
1387 bool is_animating) { 1420 bool is_animating) {
1388 Layer* layer = LayerById(element_id); 1421 Layer* layer = LayerByElementId(element_id);
1389 if (layer) { 1422 if (layer) {
1390 switch (change_type) { 1423 switch (change_type) {
1391 case AnimationChangeType::POTENTIAL: 1424 case AnimationChangeType::POTENTIAL:
1392 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating); 1425 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1393 break; 1426 break;
1394 case AnimationChangeType::RUNNING: 1427 case AnimationChangeType::RUNNING:
1395 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating); 1428 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
1396 break; 1429 break;
1397 case AnimationChangeType::BOTH: 1430 case AnimationChangeType::BOTH:
1398 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating); 1431 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1399 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating); 1432 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
1400 break; 1433 break;
1401 } 1434 }
1402 } 1435 }
1403 } 1436 }
1404 1437
1405 void LayerTreeHost::ElementOpacityIsAnimatingChanged( 1438 void LayerTreeHost::ElementOpacityIsAnimatingChanged(
1406 ElementId element_id, 1439 ElementId element_id,
1407 ElementListType list_type, 1440 ElementListType list_type,
1408 AnimationChangeType change_type, 1441 AnimationChangeType change_type,
1409 bool is_animating) { 1442 bool is_animating) {
1410 Layer* layer = LayerById(element_id); 1443 Layer* layer = LayerByElementId(element_id);
1411 if (layer) { 1444 if (layer) {
1412 switch (change_type) { 1445 switch (change_type) {
1413 case AnimationChangeType::POTENTIAL: 1446 case AnimationChangeType::POTENTIAL:
1414 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating); 1447 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
1415 break; 1448 break;
1416 case AnimationChangeType::RUNNING: 1449 case AnimationChangeType::RUNNING:
1417 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating); 1450 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
1418 break; 1451 break;
1419 case AnimationChangeType::BOTH: 1452 case AnimationChangeType::BOTH:
1420 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating); 1453 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
1421 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating); 1454 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
1422 break; 1455 break;
1423 } 1456 }
1424 } 1457 }
1425 } 1458 }
1426 1459
1427 gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation( 1460 gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation(
1428 ElementId element_id) const { 1461 ElementId element_id) const {
1429 Layer* layer = LayerById(element_id); 1462 Layer* layer = LayerByElementId(element_id);
1430 DCHECK(layer); 1463 DCHECK(layer);
1431 return layer->ScrollOffsetForAnimation(); 1464 return layer->ScrollOffsetForAnimation();
1432 } 1465 }
1433 1466
1434 bool LayerTreeHost::ScrollOffsetAnimationWasInterrupted( 1467 bool LayerTreeHost::ScrollOffsetAnimationWasInterrupted(
1435 const Layer* layer) const { 1468 const Layer* layer) const {
1436 return animation_host_->ScrollOffsetAnimationWasInterrupted(layer->id()); 1469 return animation_host_->ScrollOffsetAnimationWasInterrupted(
1470 layer->element_id());
1437 } 1471 }
1438 1472
1439 bool LayerTreeHost::IsAnimatingFilterProperty(const Layer* layer) const { 1473 bool LayerTreeHost::IsAnimatingFilterProperty(const Layer* layer) const {
1440 return animation_host_->IsAnimatingFilterProperty(layer->id(), 1474 return animation_host_->IsAnimatingFilterProperty(layer->element_id(),
1441 ElementListType::ACTIVE); 1475 ElementListType::ACTIVE);
1442 } 1476 }
1443 1477
1444 bool LayerTreeHost::IsAnimatingOpacityProperty(const Layer* layer) const { 1478 bool LayerTreeHost::IsAnimatingOpacityProperty(const Layer* layer) const {
1445 return animation_host_->IsAnimatingOpacityProperty(layer->id(), 1479 return animation_host_->IsAnimatingOpacityProperty(layer->element_id(),
1446 ElementListType::ACTIVE); 1480 ElementListType::ACTIVE);
1447 } 1481 }
1448 1482
1449 bool LayerTreeHost::IsAnimatingTransformProperty(const Layer* layer) const { 1483 bool LayerTreeHost::IsAnimatingTransformProperty(const Layer* layer) const {
1450 return animation_host_->IsAnimatingTransformProperty(layer->id(), 1484 return animation_host_->IsAnimatingTransformProperty(layer->element_id(),
1451 ElementListType::ACTIVE); 1485 ElementListType::ACTIVE);
1452 } 1486 }
1453 1487
1454 bool LayerTreeHost::HasPotentiallyRunningFilterAnimation( 1488 bool LayerTreeHost::HasPotentiallyRunningFilterAnimation(
1455 const Layer* layer) const { 1489 const Layer* layer) const {
1456 return animation_host_->HasPotentiallyRunningFilterAnimation( 1490 return animation_host_->HasPotentiallyRunningFilterAnimation(
1457 layer->id(), ElementListType::ACTIVE); 1491 layer->element_id(), ElementListType::ACTIVE);
1458 } 1492 }
1459 1493
1460 bool LayerTreeHost::HasPotentiallyRunningOpacityAnimation( 1494 bool LayerTreeHost::HasPotentiallyRunningOpacityAnimation(
1461 const Layer* layer) const { 1495 const Layer* layer) const {
1462 return animation_host_->HasPotentiallyRunningOpacityAnimation( 1496 return animation_host_->HasPotentiallyRunningOpacityAnimation(
1463 layer->id(), ElementListType::ACTIVE); 1497 layer->element_id(), ElementListType::ACTIVE);
1464 } 1498 }
1465 1499
1466 bool LayerTreeHost::HasPotentiallyRunningTransformAnimation( 1500 bool LayerTreeHost::HasPotentiallyRunningTransformAnimation(
1467 const Layer* layer) const { 1501 const Layer* layer) const {
1468 return animation_host_->HasPotentiallyRunningTransformAnimation( 1502 return animation_host_->HasPotentiallyRunningTransformAnimation(
1469 layer->id(), ElementListType::ACTIVE); 1503 layer->element_id(), ElementListType::ACTIVE);
1470 } 1504 }
1471 1505
1472 bool LayerTreeHost::HasOnlyTranslationTransforms(const Layer* layer) const { 1506 bool LayerTreeHost::HasOnlyTranslationTransforms(const Layer* layer) const {
1473 return animation_host_->HasOnlyTranslationTransforms(layer->id(), 1507 return animation_host_->HasOnlyTranslationTransforms(layer->element_id(),
1474 ElementListType::ACTIVE); 1508 ElementListType::ACTIVE);
1475 } 1509 }
1476 1510
1477 bool LayerTreeHost::MaximumTargetScale(const Layer* layer, 1511 bool LayerTreeHost::MaximumTargetScale(const Layer* layer,
1478 float* max_scale) const { 1512 float* max_scale) const {
1479 return animation_host_->MaximumTargetScale( 1513 return animation_host_->MaximumTargetScale(
1480 layer->id(), ElementListType::ACTIVE, max_scale); 1514 layer->element_id(), ElementListType::ACTIVE, max_scale);
1481 } 1515 }
1482 1516
1483 bool LayerTreeHost::AnimationStartScale(const Layer* layer, 1517 bool LayerTreeHost::AnimationStartScale(const Layer* layer,
1484 float* start_scale) const { 1518 float* start_scale) const {
1485 return animation_host_->AnimationStartScale( 1519 return animation_host_->AnimationStartScale(
1486 layer->id(), ElementListType::ACTIVE, start_scale); 1520 layer->element_id(), ElementListType::ACTIVE, start_scale);
1487 } 1521 }
1488 1522
1489 bool LayerTreeHost::HasAnyAnimationTargetingProperty( 1523 bool LayerTreeHost::HasAnyAnimationTargetingProperty(
1490 const Layer* layer, 1524 const Layer* layer,
1491 TargetProperty::Type property) const { 1525 TargetProperty::Type property) const {
1492 return animation_host_->HasAnyAnimationTargetingProperty(layer->id(), 1526 return animation_host_->HasAnyAnimationTargetingProperty(layer->element_id(),
1493 property); 1527 property);
1494 } 1528 }
1495 1529
1496 bool LayerTreeHost::AnimationsPreserveAxisAlignment(const Layer* layer) const { 1530 bool LayerTreeHost::AnimationsPreserveAxisAlignment(const Layer* layer) const {
1497 return animation_host_->AnimationsPreserveAxisAlignment(layer->id()); 1531 return animation_host_->AnimationsPreserveAxisAlignment(layer->element_id());
1498 } 1532 }
1499 1533
1500 bool LayerTreeHost::HasAnyAnimation(const Layer* layer) const { 1534 bool LayerTreeHost::HasAnyAnimation(const Layer* layer) const {
1501 return animation_host_->HasAnyAnimation(layer->id()); 1535 return animation_host_->HasAnyAnimation(layer->element_id());
1502 } 1536 }
1503 1537
1504 bool LayerTreeHost::HasActiveAnimationForTesting(const Layer* layer) const { 1538 bool LayerTreeHost::HasActiveAnimationForTesting(const Layer* layer) const {
1505 return animation_host_->HasActiveAnimationForTesting(layer->id()); 1539 return animation_host_->HasActiveAnimationForTesting(layer->element_id());
1506 } 1540 }
1507 1541
1508 bool LayerTreeHost::IsSingleThreaded() const { 1542 bool LayerTreeHost::IsSingleThreaded() const {
1509 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED || 1543 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
1510 !task_runner_provider_->HasImplThread()); 1544 !task_runner_provider_->HasImplThread());
1511 return compositor_mode_ == CompositorMode::SINGLE_THREADED; 1545 return compositor_mode_ == CompositorMode::SINGLE_THREADED;
1512 } 1546 }
1513 1547
1514 bool LayerTreeHost::IsThreaded() const { 1548 bool LayerTreeHost::IsThreaded() const {
1515 DCHECK(compositor_mode_ != CompositorMode::THREADED || 1549 DCHECK(compositor_mode_ != CompositorMode::THREADED ||
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 int seq_num = property_trees_.sequence_number; 1757 int seq_num = property_trees_.sequence_number;
1724 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { 1758 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) {
1725 layer->set_property_tree_sequence_number(seq_num); 1759 layer->set_property_tree_sequence_number(seq_num);
1726 }); 1760 });
1727 1761
1728 surface_id_namespace_ = proto.surface_id_namespace(); 1762 surface_id_namespace_ = proto.surface_id_namespace();
1729 next_surface_sequence_ = proto.next_surface_sequence(); 1763 next_surface_sequence_ = proto.next_surface_sequence();
1730 } 1764 }
1731 1765
1732 } // namespace cc 1766 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698