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

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

Issue 1944623002: CC Animation: Use ElementId to attach CC animation players. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@erasedomids
Patch Set: Created 4 years, 7 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 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 void LayerTreeHost::SetAuthoritativeVSyncInterval( 1263 void LayerTreeHost::SetAuthoritativeVSyncInterval(
1264 const base::TimeDelta& interval) { 1264 const base::TimeDelta& interval) {
1265 proxy_->SetAuthoritativeVSyncInterval(interval); 1265 proxy_->SetAuthoritativeVSyncInterval(interval);
1266 } 1266 }
1267 1267
1268 Layer* LayerTreeHost::LayerById(int id) const { 1268 Layer* LayerTreeHost::LayerById(int id) const {
1269 LayerIdMap::const_iterator iter = layer_id_map_.find(id); 1269 LayerIdMap::const_iterator iter = layer_id_map_.find(id);
1270 return iter != layer_id_map_.end() ? iter->second : NULL; 1270 return iter != layer_id_map_.end() ? iter->second : NULL;
1271 } 1271 }
1272 1272
1273 Layer* LayerTreeHost::LayerForElementId(ElementId element_id) const {
1274 auto iter = element_id_to_layer_map_.find(element_id);
1275 return iter != element_id_to_layer_map_.end() ? iter->second.main : nullptr;
1276 }
1277
1278 Layer* LayerTreeHost::ScrollLayerForElementId(ElementId element_id) const {
1279 auto iter = element_id_to_layer_map_.find(element_id);
1280 return iter != element_id_to_layer_map_.end() ? iter->second.scroll : nullptr;
1281 }
1282
1273 void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) { 1283 void LayerTreeHost::AddLayerShouldPushProperties(Layer* layer) {
1274 layers_that_should_push_properties_.insert(layer); 1284 layers_that_should_push_properties_.insert(layer);
1275 } 1285 }
1276 1286
1277 void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) { 1287 void LayerTreeHost::RemoveLayerShouldPushProperties(Layer* layer) {
1278 layers_that_should_push_properties_.erase(layer); 1288 layers_that_should_push_properties_.erase(layer);
1279 } 1289 }
1280 1290
1281 std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() { 1291 std::unordered_set<Layer*>& LayerTreeHost::LayersThatShouldPushProperties() {
1282 return layers_that_should_push_properties_; 1292 return layers_that_should_push_properties_;
1283 } 1293 }
1284 1294
1285 bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) { 1295 bool LayerTreeHost::LayerNeedsPushPropertiesForTesting(Layer* layer) {
1286 return layers_that_should_push_properties_.find(layer) != 1296 return layers_that_should_push_properties_.find(layer) !=
1287 layers_that_should_push_properties_.end(); 1297 layers_that_should_push_properties_.end();
1288 } 1298 }
1289 1299
1290 void LayerTreeHost::RegisterLayer(Layer* layer) { 1300 void LayerTreeHost::RegisterLayer(Layer* layer) {
1291 DCHECK(!LayerById(layer->id())); 1301 DCHECK(!LayerById(layer->id()));
1292 DCHECK(!in_paint_layer_contents_); 1302 DCHECK(!in_paint_layer_contents_);
1293 layer_id_map_[layer->id()] = layer; 1303 layer_id_map_[layer->id()] = layer;
1294 animation_host_->RegisterElement(layer->id(), ElementListType::ACTIVE);
1295 } 1304 }
1296 1305
1297 void LayerTreeHost::UnregisterLayer(Layer* layer) { 1306 void LayerTreeHost::UnregisterLayer(Layer* layer) {
1298 DCHECK(LayerById(layer->id())); 1307 DCHECK(LayerById(layer->id()));
1299 DCHECK(!in_paint_layer_contents_); 1308 DCHECK(!in_paint_layer_contents_);
1300 animation_host_->UnregisterElement(layer->id(), ElementListType::ACTIVE);
1301 RemoveLayerShouldPushProperties(layer); 1309 RemoveLayerShouldPushProperties(layer);
1302 layer_id_map_.erase(layer->id()); 1310 layer_id_map_.erase(layer->id());
1303 } 1311 }
1304 1312
1313 void LayerTreeHost::RegisterLayerForElementId(Layer* layer) {
1314 DCHECK(layer->element_id());
1315 ElementLayers& element_layers = element_id_to_layer_map_[layer->element_id()];
1316 if (layer->scrollable()) {
1317 DCHECK(!element_layers.scroll);
1318 element_layers.scroll = layer;
1319 } else {
1320 DCHECK(!element_layers.main);
1321 element_layers.main = layer;
1322 }
1323 animation_host_->RegisterElement(layer->element_id(),
1324 ElementListType::ACTIVE);
1325 }
1326
1327 void LayerTreeHost::UnregisterLayerForElementId(Layer* layer) {
1328 DCHECK(layer->element_id());
1329 animation_host_->UnregisterElement(layer->element_id(),
1330 ElementListType::ACTIVE);
1331
1332 auto iter = element_id_to_layer_map_.find(layer->element_id());
1333 if (iter == element_id_to_layer_map_.end())
1334 return;
1335
1336 ElementLayers& element_layers = iter->second;
1337 if (layer->scrollable()) {
1338 DCHECK_EQ(element_layers.scroll, layer);
1339 element_layers.scroll = nullptr;
1340 } else {
1341 DCHECK_EQ(element_layers.main, layer);
1342 element_layers.main = nullptr;
1343 }
1344
1345 if (!element_layers.main && !element_layers.scroll)
1346 element_id_to_layer_map_.erase(layer->element_id());
1347 }
1348
1305 bool LayerTreeHost::IsElementInList(ElementId element_id, 1349 bool LayerTreeHost::IsElementInList(ElementId element_id,
1306 ElementListType list_type) const { 1350 ElementListType list_type) const {
1307 return list_type == ElementListType::ACTIVE && LayerById(element_id); 1351 return list_type == ElementListType::ACTIVE &&
1352 element_id_to_layer_map_.find(element_id) !=
1353 element_id_to_layer_map_.end();
1308 } 1354 }
1309 1355
1310 void LayerTreeHost::SetMutatorsNeedCommit() { 1356 void LayerTreeHost::SetMutatorsNeedCommit() {
1311 SetNeedsCommit(); 1357 SetNeedsCommit();
1312 } 1358 }
1313 1359
1314 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() { 1360 void LayerTreeHost::SetMutatorsNeedRebuildPropertyTrees() {
1315 property_trees_.needs_rebuild = true; 1361 property_trees_.needs_rebuild = true;
1316 } 1362 }
1317 1363
1318 void LayerTreeHost::SetElementFilterMutated(ElementId element_id, 1364 void LayerTreeHost::SetElementFilterMutated(ElementId element_id,
1319 ElementListType list_type, 1365 ElementListType list_type,
1320 const FilterOperations& filters) { 1366 const FilterOperations& filters) {
1321 Layer* layer = LayerById(element_id); 1367 Layer* layer = LayerForElementId(element_id);
1322 DCHECK(layer); 1368 DCHECK(layer);
1323 layer->OnFilterAnimated(filters); 1369 layer->OnFilterAnimated(filters);
1324 } 1370 }
1325 1371
1326 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id, 1372 void LayerTreeHost::SetElementOpacityMutated(ElementId element_id,
1327 ElementListType list_type, 1373 ElementListType list_type,
1328 float opacity) { 1374 float opacity) {
1329 Layer* layer = LayerById(element_id); 1375 Layer* layer = LayerForElementId(element_id);
1330 DCHECK(layer); 1376 DCHECK(layer);
1331 layer->OnOpacityAnimated(opacity); 1377 layer->OnOpacityAnimated(opacity);
1332 } 1378 }
1333 1379
1334 void LayerTreeHost::SetElementTransformMutated( 1380 void LayerTreeHost::SetElementTransformMutated(
1335 ElementId element_id, 1381 ElementId element_id,
1336 ElementListType list_type, 1382 ElementListType list_type,
1337 const gfx::Transform& transform) { 1383 const gfx::Transform& transform) {
1338 Layer* layer = LayerById(element_id); 1384 Layer* layer = LayerForElementId(element_id);
1339 DCHECK(layer); 1385 DCHECK(layer);
1340 layer->OnTransformAnimated(transform); 1386 layer->OnTransformAnimated(transform);
1341 } 1387 }
1342 1388
1343 void LayerTreeHost::SetElementScrollOffsetMutated( 1389 void LayerTreeHost::SetElementScrollOffsetMutated(
1344 ElementId element_id, 1390 ElementId element_id,
1345 ElementListType list_type, 1391 ElementListType list_type,
1346 const gfx::ScrollOffset& scroll_offset) { 1392 const gfx::ScrollOffset& scroll_offset) {
1347 Layer* layer = LayerById(element_id); 1393 Layer* layer = ScrollLayerForElementId(element_id);
1348 DCHECK(layer); 1394 DCHECK(layer);
1349 layer->OnScrollOffsetAnimated(scroll_offset); 1395 layer->OnScrollOffsetAnimated(scroll_offset);
1350 } 1396 }
1351 1397
1352 void LayerTreeHost::ElementTransformIsPotentiallyAnimatingChanged( 1398 void LayerTreeHost::ElementTransformIsPotentiallyAnimatingChanged(
1353 ElementId element_id, 1399 ElementId element_id,
1354 ElementListType list_type, 1400 ElementListType list_type,
1355 bool is_animating) { 1401 bool is_animating) {
1356 Layer* layer = LayerById(element_id); 1402 Layer* layer = LayerForElementId(element_id);
1357 DCHECK(layer); 1403 if (layer)
1358 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating); 1404 layer->OnTransformIsPotentiallyAnimatingChanged(is_animating);
1359 } 1405 }
1360 1406
1361 gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation( 1407 gfx::ScrollOffset LayerTreeHost::GetScrollOffsetForAnimation(
1362 ElementId element_id) const { 1408 ElementId element_id) const {
1363 Layer* layer = LayerById(element_id); 1409 Layer* layer = ScrollLayerForElementId(element_id);
1364 DCHECK(layer); 1410 DCHECK(layer);
1365 return layer->ScrollOffsetForAnimation(); 1411 return layer->ScrollOffsetForAnimation();
1366 } 1412 }
1367 1413
1368 bool LayerTreeHost::ScrollOffsetAnimationWasInterrupted( 1414 bool LayerTreeHost::ScrollOffsetAnimationWasInterrupted(
1369 const Layer* layer) const { 1415 const Layer* layer) const {
1370 return animation_host_->ScrollOffsetAnimationWasInterrupted(layer->id()); 1416 if (!layer->element_id())
1417 return false;
1418
1419 return animation_host_->ScrollOffsetAnimationWasInterrupted(
1420 layer->element_id());
1371 } 1421 }
1372 1422
1373 bool LayerTreeHost::IsAnimatingFilterProperty(const Layer* layer) const { 1423 bool LayerTreeHost::IsAnimatingFilterProperty(const Layer* layer) const {
1374 return animation_host_->IsAnimatingFilterProperty(layer->id(), 1424 if (!layer->element_id())
1425 return false;
1426
1427 return animation_host_->IsAnimatingFilterProperty(layer->element_id(),
1375 ElementListType::ACTIVE); 1428 ElementListType::ACTIVE);
1376 } 1429 }
1377 1430
1378 bool LayerTreeHost::IsAnimatingOpacityProperty(const Layer* layer) const { 1431 bool LayerTreeHost::IsAnimatingOpacityProperty(const Layer* layer) const {
1379 return animation_host_->IsAnimatingOpacityProperty(layer->id(), 1432 if (!layer->element_id())
1433 return false;
1434
1435 return animation_host_->IsAnimatingOpacityProperty(layer->element_id(),
1380 ElementListType::ACTIVE); 1436 ElementListType::ACTIVE);
1381 } 1437 }
1382 1438
1383 bool LayerTreeHost::IsAnimatingTransformProperty(const Layer* layer) const { 1439 bool LayerTreeHost::IsAnimatingTransformProperty(const Layer* layer) const {
1384 return animation_host_->IsAnimatingTransformProperty(layer->id(), 1440 if (!layer->element_id())
1441 return false;
1442
1443 return animation_host_->IsAnimatingTransformProperty(layer->element_id(),
1385 ElementListType::ACTIVE); 1444 ElementListType::ACTIVE);
1386 } 1445 }
1387 1446
1388 bool LayerTreeHost::HasPotentiallyRunningFilterAnimation( 1447 bool LayerTreeHost::HasPotentiallyRunningFilterAnimation(
1389 const Layer* layer) const { 1448 const Layer* layer) const {
1449 if (!layer->element_id())
1450 return false;
1451
1390 return animation_host_->HasPotentiallyRunningFilterAnimation( 1452 return animation_host_->HasPotentiallyRunningFilterAnimation(
1391 layer->id(), ElementListType::ACTIVE); 1453 layer->element_id(), ElementListType::ACTIVE);
1392 } 1454 }
1393 1455
1394 bool LayerTreeHost::HasPotentiallyRunningOpacityAnimation( 1456 bool LayerTreeHost::HasPotentiallyRunningOpacityAnimation(
1395 const Layer* layer) const { 1457 const Layer* layer) const {
1458 if (!layer->element_id())
1459 return false;
1460
1396 return animation_host_->HasPotentiallyRunningOpacityAnimation( 1461 return animation_host_->HasPotentiallyRunningOpacityAnimation(
1397 layer->id(), ElementListType::ACTIVE); 1462 layer->element_id(), ElementListType::ACTIVE);
1398 } 1463 }
1399 1464
1400 bool LayerTreeHost::HasPotentiallyRunningTransformAnimation( 1465 bool LayerTreeHost::HasPotentiallyRunningTransformAnimation(
1401 const Layer* layer) const { 1466 const Layer* layer) const {
1467 if (!layer->element_id())
1468 return false;
1469
1402 return animation_host_->HasPotentiallyRunningTransformAnimation( 1470 return animation_host_->HasPotentiallyRunningTransformAnimation(
1403 layer->id(), ElementListType::ACTIVE); 1471 layer->element_id(), ElementListType::ACTIVE);
1404 } 1472 }
1405 1473
1406 bool LayerTreeHost::HasOnlyTranslationTransforms(const Layer* layer) const { 1474 bool LayerTreeHost::HasOnlyTranslationTransforms(const Layer* layer) const {
1407 return animation_host_->HasOnlyTranslationTransforms(layer->id(), 1475 if (!layer->element_id())
1476 return true;
1477
1478 return animation_host_->HasOnlyTranslationTransforms(layer->element_id(),
1408 ElementListType::ACTIVE); 1479 ElementListType::ACTIVE);
1409 } 1480 }
1410 1481
1411 bool LayerTreeHost::MaximumTargetScale(const Layer* layer, 1482 bool LayerTreeHost::MaximumTargetScale(const Layer* layer,
1412 float* max_scale) const { 1483 float* max_scale) const {
1484 if (!layer->element_id())
1485 return true;
1486
1413 return animation_host_->MaximumTargetScale( 1487 return animation_host_->MaximumTargetScale(
1414 layer->id(), ElementListType::ACTIVE, max_scale); 1488 layer->element_id(), ElementListType::ACTIVE, max_scale);
1415 } 1489 }
1416 1490
1417 bool LayerTreeHost::AnimationStartScale(const Layer* layer, 1491 bool LayerTreeHost::AnimationStartScale(const Layer* layer,
1418 float* start_scale) const { 1492 float* start_scale) const {
1493 if (!layer->element_id())
1494 return true;
1495
1419 return animation_host_->AnimationStartScale( 1496 return animation_host_->AnimationStartScale(
1420 layer->id(), ElementListType::ACTIVE, start_scale); 1497 layer->element_id(), ElementListType::ACTIVE, start_scale);
1421 } 1498 }
1422 1499
1423 bool LayerTreeHost::HasAnyAnimationTargetingProperty( 1500 bool LayerTreeHost::HasAnyAnimationTargetingProperty(
1424 const Layer* layer, 1501 const Layer* layer,
1425 TargetProperty::Type property) const { 1502 TargetProperty::Type property) const {
1426 return animation_host_->HasAnyAnimationTargetingProperty(layer->id(), 1503 if (!layer->element_id())
1504 return false;
1505
1506 return animation_host_->HasAnyAnimationTargetingProperty(layer->element_id(),
1427 property); 1507 property);
1428 } 1508 }
1429 1509
1430 bool LayerTreeHost::AnimationsPreserveAxisAlignment(const Layer* layer) const { 1510 bool LayerTreeHost::AnimationsPreserveAxisAlignment(const Layer* layer) const {
1431 return animation_host_->AnimationsPreserveAxisAlignment(layer->id()); 1511 if (!layer->element_id())
1512 return true;
1513
1514 return animation_host_->AnimationsPreserveAxisAlignment(layer->element_id());
1432 } 1515 }
1433 1516
1434 bool LayerTreeHost::HasAnyAnimation(const Layer* layer) const { 1517 bool LayerTreeHost::HasAnyAnimation(const Layer* layer) const {
1435 return animation_host_->HasAnyAnimation(layer->id()); 1518 if (!layer->element_id())
1519 return false;
1520
1521 return animation_host_->HasAnyAnimation(layer->element_id());
1436 } 1522 }
1437 1523
1438 bool LayerTreeHost::HasActiveAnimationForTesting(const Layer* layer) const { 1524 bool LayerTreeHost::HasActiveAnimationForTesting(const Layer* layer) const {
1439 return animation_host_->HasActiveAnimationForTesting(layer->id()); 1525 if (!layer->element_id())
1526 return false;
1527
1528 return animation_host_->HasActiveAnimationForTesting(layer->element_id());
1440 } 1529 }
1441 1530
1442 bool LayerTreeHost::IsSingleThreaded() const { 1531 bool LayerTreeHost::IsSingleThreaded() const {
1443 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED || 1532 DCHECK(compositor_mode_ != CompositorMode::SINGLE_THREADED ||
1444 !task_runner_provider_->HasImplThread()); 1533 !task_runner_provider_->HasImplThread());
1445 return compositor_mode_ == CompositorMode::SINGLE_THREADED; 1534 return compositor_mode_ == CompositorMode::SINGLE_THREADED;
1446 } 1535 }
1447 1536
1448 bool LayerTreeHost::IsThreaded() const { 1537 bool LayerTreeHost::IsThreaded() const {
1449 DCHECK(compositor_mode_ != CompositorMode::THREADED || 1538 DCHECK(compositor_mode_ != CompositorMode::THREADED ||
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 int seq_num = property_trees_.sequence_number; 1723 int seq_num = property_trees_.sequence_number;
1635 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) { 1724 LayerTreeHostCommon::CallFunctionForEveryLayer(this, [seq_num](Layer* layer) {
1636 layer->set_property_tree_sequence_number(seq_num); 1725 layer->set_property_tree_sequence_number(seq_num);
1637 }); 1726 });
1638 1727
1639 surface_id_namespace_ = proto.surface_id_namespace(); 1728 surface_id_namespace_ = proto.surface_id_namespace();
1640 next_surface_sequence_ = proto.next_surface_sequence(); 1729 next_surface_sequence_ = proto.next_surface_sequence();
1641 } 1730 }
1642 1731
1643 } // namespace cc 1732 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698