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

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

Powered by Google App Engine
This is Rietveld 408576698