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

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: get element id's from scroll node data directly. Created 4 years, 6 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 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 } 950 }
951 951
952 void LayerTreeHost::ReportFixedRasterScaleUseCounters( 952 void LayerTreeHost::ReportFixedRasterScaleUseCounters(
953 bool has_fixed_raster_scale_blurry_content, 953 bool has_fixed_raster_scale_blurry_content,
954 bool has_fixed_raster_scale_potential_performance_regression) { 954 bool has_fixed_raster_scale_potential_performance_regression) {
955 client_->ReportFixedRasterScaleUseCounters( 955 client_->ReportFixedRasterScaleUseCounters(
956 has_fixed_raster_scale_blurry_content, 956 has_fixed_raster_scale_blurry_content,
957 has_fixed_raster_scale_potential_performance_regression); 957 has_fixed_raster_scale_potential_performance_regression);
958 } 958 }
959 959
960 static void SetElementIdForTesting(Layer* layer) {
961 layer->SetElementId(LayerIdToElementIdForTesting(layer->id()));
962 }
963
964 void LayerTreeHost::SetElementIdsForTesting() {
965 LayerTreeHostCommon::CallFunctionForEveryLayer(this, SetElementIdForTesting);
966 }
967
960 bool LayerTreeHost::UsingSharedMemoryResources() { 968 bool LayerTreeHost::UsingSharedMemoryResources() {
961 return GetRendererCapabilities().using_shared_memory_resources; 969 return GetRendererCapabilities().using_shared_memory_resources;
962 } 970 }
963 971
964 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) { 972 bool LayerTreeHost::DoUpdateLayers(Layer* root_layer) {
965 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number", 973 TRACE_EVENT1("cc", "LayerTreeHost::DoUpdateLayers", "source_frame_number",
966 source_frame_number()); 974 source_frame_number());
967 975
968 UpdateHudLayer(); 976 UpdateHudLayer();
969 977
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 return SurfaceSequence(surface_id_namespace_, next_surface_sequence_++); 1276 return SurfaceSequence(surface_id_namespace_, next_surface_sequence_++);
1269 } 1277 }
1270 1278
1271 void LayerTreeHost::SetLayerTreeMutator( 1279 void LayerTreeHost::SetLayerTreeMutator(
1272 std::unique_ptr<LayerTreeMutator> mutator) { 1280 std::unique_ptr<LayerTreeMutator> mutator) {
1273 proxy_->SetMutator(std::move(mutator)); 1281 proxy_->SetMutator(std::move(mutator));
1274 } 1282 }
1275 1283
1276 Layer* LayerTreeHost::LayerById(int id) const { 1284 Layer* LayerTreeHost::LayerById(int id) const {
1277 LayerIdMap::const_iterator iter = layer_id_map_.find(id); 1285 LayerIdMap::const_iterator iter = layer_id_map_.find(id);
1278 return iter != layer_id_map_.end() ? iter->second : NULL; 1286 return iter != layer_id_map_.end() ? iter->second : nullptr;
1287 }
1288
1289 Layer* LayerTreeHost::LayerByElementId(ElementId element_id) const {
1290 ElementLayersMap::const_iterator iter = element_layers_map_.find(element_id);
1291 return iter != element_layers_map_.end() ? iter->second : nullptr;
1292 }
1293
1294 void LayerTreeHost::AddToElementMap(Layer* layer) {
1295 if (!layer->element_id())
1296 return;
1297
1298 element_layers_map_[layer->element_id()] = layer;
1299 }
1300
1301 void LayerTreeHost::RemoveFromElementMap(Layer* layer) {
1302 if (!layer->element_id())
1303 return;
1304
1305 element_layers_map_.erase(layer->element_id());
1279 } 1306 }
1280 1307
1281 void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) { 1308 void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) {
1282 layers_that_should_push_properties_.insert(layer); 1309 layers_that_should_push_properties_.insert(layer);
1283 } 1310 }
1284 1311
1285 void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) { 1312 void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) {
1286 layers_that_should_push_properties_.erase(layer); 1313 layers_that_should_push_properties_.erase(layer);
1287 } 1314 }
1288 1315
1289 std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() { 1316 std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() {
1290 return layers_that_should_push_properties_; 1317 return layers_that_should_push_properties_;
1291 } 1318 }
1292 1319
1293 bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) { 1320 bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) {
1294 return layers_that_should_push_properties_.find(layer) != 1321 return layers_that_should_push_properties_.find(layer) !=
1295 layers_that_should_push_properties_.end(); 1322 layers_that_should_push_properties_.end();
1296 } 1323 }
1297 1324
1298 void LayerTreeHost::RegisterLayer(Layer* layer) { 1325 void LayerTreeHost::RegisterLayer(Layer* layer) {
1299 DCHECK(!LayerById(layer->id())); 1326 DCHECK(!LayerById(layer->id()));
1300 DCHECK(!in_paint_layer_contents_); 1327 DCHECK(!in_paint_layer_contents_);
1301 layer_id_map_[layer->id()] = layer; 1328 layer_id_map_[layer->id()] = layer;
1302 animation_host_->RegisterElement(layer->id(), ElementListType::ACTIVE); 1329 if (layer->element_id()) {
1330 animation_host_->RegisterElement(layer->element_id(),
1331 ElementListType::ACTIVE);
1332 }
1303 } 1333 }
1304 1334
1305 void LayerTreeHost::UnregisterLayer(Layer* layer) { 1335 void LayerTreeHost::UnregisterLayer(Layer* layer) {
1306 DCHECK(LayerById(layer->id())); 1336 DCHECK(LayerById(layer->id()));
1307 DCHECK(!in_paint_layer_contents_); 1337 DCHECK(!in_paint_layer_contents_);
1308 animation_host_->UnregisterElement(layer->id(), ElementListType::ACTIVE); 1338 if (layer->element_id()) {
1339 animation_host_->UnregisterElement(layer->element_id(),
1340 ElementListType::ACTIVE);
1341 }
1309 RemoveLayerShouldPushProperties(layer); 1342 RemoveLayerShouldPushProperties(layer);
1310 layer_id_map_.erase(layer->id()); 1343 layer_id_map_.erase(layer->id());
1311 } 1344 }
1312 1345
1313 bool LayerTreeHost::IsElementInList(ElementId element_id, 1346 bool LayerTreeHost::IsElementInList(ElementId element_id,
1314 ElementListType list_type) const { 1347 ElementListType list_type) const {
1315 return list_type == ElementListType::ACTIVE && LayerById(element_id); 1348 return list_type == ElementListType::ACTIVE && LayerByElementId(element_id);
1316 } 1349 }
1317 1350
1318 void LayerTreeHost::SetMutatorsNeedCommit() { 1351 void LayerTreeHost::SetMutatorsNeedCommit() {
1319 SetNeedsCommit(); 1352 SetNeedsCommit();
1320 } 1353 }
1321 1354
1322 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { 1355 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() {
1323 property_trees_.needs_rebuild = true; 1356 property_trees_.needs_rebuild = true;
1324 } 1357 }
1325 1358
1326 void LayerTreeHost::SetElementFilterMutated(ElementId element_id, 1359 void LayerTreeHost::SetElementFilterMutated(ElementId element_id,
1327 ElementListType list_type, 1360 ElementListType list_type,
1328 const FilterOperations& filters) { 1361 const FilterOperations& filters) {
1329 Layer* layer = LayerById(element_id); 1362 Layer* layer = LayerByElementId(element_id);
1330 DCHECK(layer); 1363 DCHECK(layer);
1331 layer->OnFilterAnimated(filters); 1364 layer->OnFilterAnimated(filters);
1332 } 1365 }
1333 1366
1334 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id, 1367 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id,
1335 ElementListType list_type, 1368 ElementListType list_type,
1336 float opacity) { 1369 float opacity) {
1337 Layer* layer = LayerById(element_id); 1370 Layer* layer = LayerByElementId(element_id);
1338 DCHECK(layer); 1371 DCHECK(layer);
1339 layer->OnOpacityAnimated(opacity); 1372 layer->OnOpacityAnimated(opacity);
1340 } 1373 }
1341 1374
1342 void LayerTreeHost::SetElementTransformMutated( 1375 void LayerTreeHost::SetElementTransformMutated(
1343 ElementId element_id, 1376 ElementId element_id,
1344 ElementListType list_type, 1377 ElementListType list_type,
1345 const gfx::Transform& transform) { 1378 const gfx::Transform& transform) {
1346 Layer* layer = LayerById(element_id); 1379 Layer* layer = LayerByElementId(element_id);
1347 DCHECK(layer); 1380 DCHECK(layer);
1348 layer->OnTransformAnimated(transform); 1381 layer->OnTransformAnimated(transform);
1349 } 1382 }
1350 1383
1351 void LayerTreeHost::SetElementScrollOffsetMutated( 1384 void LayerTreeHost::SetElementScrollOffsetMutated(
1352 ElementId element_id, 1385 ElementId element_id,
1353 ElementListType list_type, 1386 ElementListType list_type,
1354 const gfx::ScrollOffset& scroll_offset) { 1387 const gfx::ScrollOffset& scroll_offset) {
1355 Layer* layer = LayerById(element_id); 1388 Layer* layer = LayerByElementId(element_id);
1356 DCHECK(layer); 1389 DCHECK(layer);
1357 layer->OnScrollOffsetAnimated(scroll_offset); 1390 layer->OnScrollOffsetAnimated(scroll_offset);
1358 } 1391 }
1359 1392
1360 void LayerTreeHost::ElementTransformIsAnimatingChanged( 1393 void LayerTreeHost::ElementTransformIsAnimatingChanged(
1361 ElementId element_id, 1394 ElementId element_id,
1362 ElementListType list_type, 1395 ElementListType list_type,
1363 AnimationChangeType change_type, 1396 AnimationChangeType change_type,
1364 bool is_animating) { 1397 bool is_animating) {
1365 Layer* layer = LayerById(element_id); 1398 Layer* layer = LayerByElementId(element_id);
1366 if (layer) { 1399 if (layer) {
1367 switch (change_type) { 1400 switch (change_type) {
1368 case AnimationChangeType::POTENTIAL: 1401 case AnimationChangeType::POTENTIAL:
1369 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating); 1402 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1370 break; 1403 break;
1371 case AnimationChangeType::RUNNING: 1404 case AnimationChangeType::RUNNING:
1372 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating); 1405 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
1373 break; 1406 break;
1374 case AnimationChangeType::BOTH: 1407 case AnimationChangeType::BOTH:
1375 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating); 1408 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1376 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating); 1409 layer->OnTransformIsCurrentlyAnimatingChanged(is_animating);
1377 break; 1410 break;
1378 } 1411 }
1379 } 1412 }
1380 } 1413 }
1381 1414
1382 void LayerTreeHost::ElementOpacityIsAnimatingChanged( 1415 void LayerTreeHost::ElementOpacityIsAnimatingChanged(
1383 ElementId element_id, 1416 ElementId element_id,
1384 ElementListType list_type, 1417 ElementListType list_type,
1385 AnimationChangeType change_type, 1418 AnimationChangeType change_type,
1386 bool is_animating) { 1419 bool is_animating) {
1387 Layer* layer = LayerById(element_id); 1420 Layer* layer = LayerByElementId(element_id);
1388 if (layer) { 1421 if (layer) {
1389 switch (change_type) { 1422 switch (change_type) {
1390 case AnimationChangeType::POTENTIAL: 1423 case AnimationChangeType::POTENTIAL:
1391 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating); 1424 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
1392 break; 1425 break;
1393 case AnimationChangeType::RUNNING: 1426 case AnimationChangeType::RUNNING:
1394 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating); 1427 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
1395 break; 1428 break;
1396 case AnimationChangeType::BOTH: 1429 case AnimationChangeType::BOTH:
1397 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating); 1430 layer->OnOpacityIsPotentiallyAnimatingChanged(is_animating);
1398 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating); 1431 layer->OnOpacityIsCurrentlyAnimatingChanged(is_animating);
1399 break; 1432 break;
1400 } 1433 }
1401 } 1434 }
1402 } 1435 }
1403 1436
1404 gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation( 1437 gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation(
1405 ElementId element_id) const { 1438 ElementId element_id) const {
1406 Layer* layer = LayerById(element_id); 1439 Layer* layer = LayerByElementId(element_id);
1407 DCHECK(layer); 1440 DCHECK(layer);
1408 return layer->ScrollOffsetForAnimation(); 1441 return layer->ScrollOffsetForAnimation();
1409 } 1442 }
1410 1443
1411 bool LayerTreeHost::ScrollOffsetAnimationWasInterrupted( 1444 bool LayerTreeHost::ScrollOffsetAnimationWasInterrupted(
1412 const Layer* layer) const { 1445 const Layer* layer) const {
1413 return animation_host_->ScrollOffsetAnimationWasInterrupted(layer->id()); 1446 return animation_host_->ScrollOffsetAnimationWasInterrupted(
1447 layer->element_id());
1414 } 1448 }
1415 1449
1416 bool LayerTreeHost::IsAnimatingFilterProperty(const Layer* layer) const { 1450 bool LayerTreeHost::IsAnimatingFilterProperty(const Layer* layer) const {
1417 return animation_host_->IsAnimatingFilterProperty(layer->id(), 1451 return animation_host_->IsAnimatingFilterProperty(layer->element_id(),
1418 ElementListType::ACTIVE); 1452 ElementListType::ACTIVE);
1419 } 1453 }
1420 1454
1421 bool LayerTreeHost::IsAnimatingOpacityProperty(const Layer* layer) const { 1455 bool LayerTreeHost::IsAnimatingOpacityProperty(const Layer* layer) const {
1422 return animation_host_->IsAnimatingOpacityProperty(layer->id(), 1456 return animation_host_->IsAnimatingOpacityProperty(layer->element_id(),
1423 ElementListType::ACTIVE); 1457 ElementListType::ACTIVE);
1424 } 1458 }
1425 1459
1426 bool LayerTreeHost::IsAnimatingTransformProperty(const Layer* layer) const { 1460 bool LayerTreeHost::IsAnimatingTransformProperty(const Layer* layer) const {
1427 return animation_host_->IsAnimatingTransformProperty(layer->id(), 1461 return animation_host_->IsAnimatingTransformProperty(layer->element_id(),
1428 ElementListType::ACTIVE); 1462 ElementListType::ACTIVE);
1429 } 1463 }
1430 1464
1431 bool LayerTreeHost::HasPotentiallyRunningFilterAnimation( 1465 bool LayerTreeHost::HasPotentiallyRunningFilterAnimation(
1432 const Layer* layer) const { 1466 const Layer* layer) const {
1433 return animation_host_->HasPotentiallyRunningFilterAnimation( 1467 return animation_host_->HasPotentiallyRunningFilterAnimation(
1434 layer->id(), ElementListType::ACTIVE); 1468 layer->element_id(), ElementListType::ACTIVE);
1435 } 1469 }
1436 1470
1437 bool LayerTreeHost::HasPotentiallyRunningOpacityAnimation( 1471 bool LayerTreeHost::HasPotentiallyRunningOpacityAnimation(
1438 const Layer* layer) const { 1472 const Layer* layer) const {
1439 return animation_host_->HasPotentiallyRunningOpacityAnimation( 1473 return animation_host_->HasPotentiallyRunningOpacityAnimation(
1440 layer->id(), ElementListType::ACTIVE); 1474 layer->element_id(), ElementListType::ACTIVE);
1441 } 1475 }
1442 1476
1443 bool LayerTreeHost::HasPotentiallyRunningTransformAnimation( 1477 bool LayerTreeHost::HasPotentiallyRunningTransformAnimation(
1444 const Layer* layer) const { 1478 const Layer* layer) const {
1445 return animation_host_->HasPotentiallyRunningTransformAnimation( 1479 return animation_host_->HasPotentiallyRunningTransformAnimation(
1446 layer->id(), ElementListType::ACTIVE); 1480 layer->element_id(), ElementListType::ACTIVE);
1447 } 1481 }
1448 1482
1449 bool LayerTreeHost::HasOnlyTranslationTransforms(const Layer* layer) const { 1483 bool LayerTreeHost::HasOnlyTranslationTransforms(const Layer* layer) const {
1450 return animation_host_->HasOnlyTranslationTransforms(layer->id(), 1484 return animation_host_->HasOnlyTranslationTransforms(layer->element_id(),
1451 ElementListType::ACTIVE); 1485 ElementListType::ACTIVE);
1452 } 1486 }
1453 1487
1454 bool LayerTreeHost::MaximumTargetScale(const Layer* layer, 1488 bool LayerTreeHost::MaximumTargetScale(const Layer* layer,
1455 float* max_scale) const { 1489 float* max_scale) const {
1456 return animation_host_->MaximumTargetScale( 1490 return animation_host_->MaximumTargetScale(
1457 layer->id(), ElementListType::ACTIVE, max_scale); 1491 layer->element_id(), ElementListType::ACTIVE, max_scale);
1458 } 1492 }
1459 1493
1460 bool LayerTreeHost::AnimationStartScale(const Layer* layer, 1494 bool LayerTreeHost::AnimationStartScale(const Layer* layer,
1461 float* start_scale) const { 1495 float* start_scale) const {
1462 return animation_host_->AnimationStartScale( 1496 return animation_host_->AnimationStartScale(
1463 layer->id(), ElementListType::ACTIVE, start_scale); 1497 layer->element_id(), ElementListType::ACTIVE, start_scale);
1464 } 1498 }
1465 1499
1466 bool LayerTreeHost::HasAnyAnimationTargetingProperty( 1500 bool LayerTreeHost::HasAnyAnimationTargetingProperty(
1467 const Layer* layer, 1501 const Layer* layer,
1468 TargetProperty::Type property) const { 1502 TargetProperty::Type property) const {
1469 return animation_host_->HasAnyAnimationTargetingProperty(layer->id(), 1503 return animation_host_->HasAnyAnimationTargetingProperty(layer->element_id(),
1470 property); 1504 property);
1471 } 1505 }
1472 1506
1473 bool LayerTreeHost::AnimationsPreserveAxisAlignment(const Layer* layer) const { 1507 bool LayerTreeHost::AnimationsPreserveAxisAlignment(const Layer* layer) const {
1474 return animation_host_->AnimationsPreserveAxisAlignment(layer->id()); 1508 return animation_host_->AnimationsPreserveAxisAlignment(layer->element_id());
1475 } 1509 }
1476 1510
1477 bool LayerTreeHost::HasAnyAnimation(const Layer* layer) const { 1511 bool LayerTreeHost::HasAnyAnimation(const Layer* layer) const {
1478 return animation_host_->HasAnyAnimation(layer->id()); 1512 return animation_host_->HasAnyAnimation(layer->element_id());
1479 } 1513 }
1480 1514
1481 bool LayerTreeHost::HasActiveAnimationForTesting(const Layer* layer) const { 1515 bool LayerTreeHost::HasActiveAnimationForTesting(const Layer* layer) const {
1482 return animation_host_->HasActiveAnimationForTesting(layer->id()); 1516 return animation_host_->HasActiveAnimationForTesting(layer->element_id());
1483 } 1517 }
1484 1518
1485 bool LayerTreeHost::IsSingleThreaded() const { 1519 bool LayerTreeHost::IsSingleThreaded() const {
1486 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED || 1520 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
1487 !task_runner_provider_->HasImplThread()); 1521 !task_runner_provider_->HasImplThread());
1488 return compositor_mode_ == CompositorMode::SINGLE_THREADED; 1522 return compositor_mode_ == CompositorMode::SINGLE_THREADED;
1489 } 1523 }
1490 1524
1491 bool LayerTreeHost::IsThreaded() const { 1525 bool LayerTreeHost::IsThreaded() const {
1492 DCHECK(compositor_mode_ != CompositorMode::THREADED || 1526 DCHECK(compositor_mode_ != CompositorMode::THREADED ||
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 int seq_num = property_trees_.sequence_number; 1716 int seq_num = property_trees_.sequence_number;
1683 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { 1717 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) {
1684 layer->set_property_tree_sequence_number(seq_num); 1718 layer->set_property_tree_sequence_number(seq_num);
1685 }); 1719 });
1686 1720
1687 surface_id_namespace_ = proto.surface_id_namespace(); 1721 surface_id_namespace_ = proto.surface_id_namespace();
1688 next_surface_sequence_ = proto.next_surface_sequence(); 1722 next_surface_sequence_ = proto.next_surface_sequence();
1689 } 1723 }
1690 1724
1691 } // namespace cc 1725 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698