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

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

Powered by Google App Engine
This is Rietveld 408576698