| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/layers/layer.h" | 5 #include "cc/layers/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 mask_layer_->SetLayerTreeHost(host); | 136 mask_layer_->SetLayerTreeHost(host); |
| 137 if (replica_layer_.get()) | 137 if (replica_layer_.get()) |
| 138 replica_layer_->SetLayerTreeHost(host); | 138 replica_layer_->SetLayerTreeHost(host); |
| 139 | 139 |
| 140 if (host) { | 140 if (host) { |
| 141 RegisterForAnimations(host->animation_registrar(), host->settings()); | 141 RegisterForAnimations(host->animation_registrar(), host->settings()); |
| 142 if (host->settings().layer_transforms_should_scale_layer_contents) | 142 if (host->settings().layer_transforms_should_scale_layer_contents) |
| 143 reset_raster_scale_to_unknown(); | 143 reset_raster_scale_to_unknown(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 if (host && layer_animation_controller_->has_any_animation()) | 146 bool has_any_animation = false; |
| 147 if (layer_animation_controller_) |
| 148 has_any_animation = layer_animation_controller_->has_any_animation(); |
| 149 else if (layer_tree_host_) |
| 150 has_any_animation = layer_tree_host_->HasAnyAnimation(this); |
| 151 |
| 152 if (host && has_any_animation) |
| 147 host->SetNeedsCommit(); | 153 host->SetNeedsCommit(); |
| 148 } | 154 } |
| 149 | 155 |
| 150 void Layer::SetNeedsUpdate() { | 156 void Layer::SetNeedsUpdate() { |
| 151 if (layer_tree_host_ && !ignore_set_needs_commit_) | 157 if (layer_tree_host_ && !ignore_set_needs_commit_) |
| 152 layer_tree_host_->SetNeedsUpdateLayers(); | 158 layer_tree_host_->SetNeedsUpdateLayers(); |
| 153 } | 159 } |
| 154 | 160 |
| 155 void Layer::SetNeedsCommit() { | 161 void Layer::SetNeedsCommit() { |
| 156 if (!layer_tree_host_) | 162 if (!layer_tree_host_) |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 506 |
| 501 void Layer::SetFilters(const FilterOperations& filters) { | 507 void Layer::SetFilters(const FilterOperations& filters) { |
| 502 DCHECK(IsPropertyChangeAllowed()); | 508 DCHECK(IsPropertyChangeAllowed()); |
| 503 if (filters_ == filters) | 509 if (filters_ == filters) |
| 504 return; | 510 return; |
| 505 filters_ = filters; | 511 filters_ = filters; |
| 506 SetNeedsCommit(); | 512 SetNeedsCommit(); |
| 507 } | 513 } |
| 508 | 514 |
| 509 bool Layer::FilterIsAnimating() const { | 515 bool Layer::FilterIsAnimating() const { |
| 510 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER); | 516 DCHECK(layer_tree_host_); |
| 517 return layer_animation_controller_ |
| 518 ? layer_animation_controller_->IsAnimatingProperty( |
| 519 Animation::FILTER) |
| 520 : layer_tree_host_->IsAnimatingFilterProperty(this); |
| 511 } | 521 } |
| 512 | 522 |
| 513 void Layer::SetBackgroundFilters(const FilterOperations& filters) { | 523 void Layer::SetBackgroundFilters(const FilterOperations& filters) { |
| 514 DCHECK(IsPropertyChangeAllowed()); | 524 DCHECK(IsPropertyChangeAllowed()); |
| 515 if (background_filters_ == filters) | 525 if (background_filters_ == filters) |
| 516 return; | 526 return; |
| 517 background_filters_ = filters; | 527 background_filters_ = filters; |
| 518 SetNeedsCommit(); | 528 SetNeedsCommit(); |
| 519 } | 529 } |
| 520 | 530 |
| 521 void Layer::SetOpacity(float opacity) { | 531 void Layer::SetOpacity(float opacity) { |
| 522 DCHECK(IsPropertyChangeAllowed()); | 532 DCHECK(IsPropertyChangeAllowed()); |
| 523 if (opacity_ == opacity) | 533 if (opacity_ == opacity) |
| 524 return; | 534 return; |
| 525 opacity_ = opacity; | 535 opacity_ = opacity; |
| 526 SetNeedsCommit(); | 536 SetNeedsCommit(); |
| 527 } | 537 } |
| 528 | 538 |
| 529 bool Layer::OpacityIsAnimating() const { | 539 bool Layer::OpacityIsAnimating() const { |
| 530 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY); | 540 DCHECK(layer_tree_host_); |
| 541 return layer_animation_controller_ |
| 542 ? layer_animation_controller_->IsAnimatingProperty( |
| 543 Animation::OPACITY) |
| 544 : layer_tree_host_->IsAnimatingOpacityProperty(this); |
| 545 } |
| 546 |
| 547 bool Layer::HasPotentiallyRunningOpacityAnimation() const { |
| 548 if (layer_animation_controller_) { |
| 549 if (Animation* animation = |
| 550 layer_animation_controller()->GetAnimation(Animation::OPACITY)) { |
| 551 return !animation->is_finished(); |
| 552 } |
| 553 return false; |
| 554 } else { |
| 555 DCHECK(layer_tree_host_); |
| 556 return layer_tree_host_->HasPotentiallyRunningOpacityAnimation(this); |
| 557 } |
| 531 } | 558 } |
| 532 | 559 |
| 533 bool Layer::OpacityCanAnimateOnImplThread() const { | 560 bool Layer::OpacityCanAnimateOnImplThread() const { |
| 534 return false; | 561 return false; |
| 535 } | 562 } |
| 536 | 563 |
| 537 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) { | 564 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) { |
| 538 DCHECK(IsPropertyChangeAllowed()); | 565 DCHECK(IsPropertyChangeAllowed()); |
| 539 if (blend_mode_ == blend_mode) | 566 if (blend_mode_ == blend_mode) |
| 540 return; | 567 return; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); | 731 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true); |
| 705 SetNeedsCommitNoRebuild(); | 732 SetNeedsCommitNoRebuild(); |
| 706 return; | 733 return; |
| 707 } | 734 } |
| 708 } | 735 } |
| 709 | 736 |
| 710 SetNeedsCommit(); | 737 SetNeedsCommit(); |
| 711 } | 738 } |
| 712 | 739 |
| 713 bool Layer::AnimationsPreserveAxisAlignment() const { | 740 bool Layer::AnimationsPreserveAxisAlignment() const { |
| 714 return layer_animation_controller_->AnimationsPreserveAxisAlignment(); | 741 DCHECK(layer_tree_host_); |
| 742 return layer_animation_controller_ |
| 743 ? layer_animation_controller_->AnimationsPreserveAxisAlignment() |
| 744 : layer_tree_host_->AnimationsPreserveAxisAlignment(this); |
| 715 } | 745 } |
| 716 | 746 |
| 717 bool Layer::TransformIsAnimating() const { | 747 bool Layer::TransformIsAnimating() const { |
| 718 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM); | 748 DCHECK(layer_tree_host_); |
| 749 return layer_animation_controller_ |
| 750 ? layer_animation_controller_->IsAnimatingProperty( |
| 751 Animation::TRANSFORM) |
| 752 : layer_tree_host_->IsAnimatingTransformProperty(this); |
| 753 } |
| 754 |
| 755 bool Layer::HasPotentiallyRunningTransformAnimation() const { |
| 756 if (layer_animation_controller_) { |
| 757 if (Animation* animation = |
| 758 layer_animation_controller()->GetAnimation(Animation::TRANSFORM)) { |
| 759 return !animation->is_finished(); |
| 760 } |
| 761 return false; |
| 762 } else { |
| 763 DCHECK(layer_tree_host_); |
| 764 return layer_tree_host_->HasPotentiallyRunningTransformAnimation(this); |
| 765 } |
| 766 } |
| 767 |
| 768 bool Layer::ScrollOffsetAnimationWasInterrupted() const { |
| 769 DCHECK(layer_tree_host_); |
| 770 return layer_animation_controller_ |
| 771 ? layer_animation_controller_ |
| 772 ->scroll_offset_animation_was_interrupted() |
| 773 : layer_tree_host_->ScrollOffsetAnimationWasInterrupted(this); |
| 719 } | 774 } |
| 720 | 775 |
| 721 void Layer::SetScrollParent(Layer* parent) { | 776 void Layer::SetScrollParent(Layer* parent) { |
| 722 DCHECK(IsPropertyChangeAllowed()); | 777 DCHECK(IsPropertyChangeAllowed()); |
| 723 if (scroll_parent_ == parent) | 778 if (scroll_parent_ == parent) |
| 724 return; | 779 return; |
| 725 | 780 |
| 726 if (scroll_parent_) | 781 if (scroll_parent_) |
| 727 scroll_parent_->RemoveScrollChild(this); | 782 scroll_parent_->RemoveScrollChild(this); |
| 728 | 783 |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 } | 1189 } |
| 1135 layer->SetClipChildren(clip_children); | 1190 layer->SetClipChildren(clip_children); |
| 1136 } else { | 1191 } else { |
| 1137 layer->SetClipChildren(nullptr); | 1192 layer->SetClipChildren(nullptr); |
| 1138 } | 1193 } |
| 1139 | 1194 |
| 1140 // When a scroll offset animation is interrupted the new scroll position on | 1195 // When a scroll offset animation is interrupted the new scroll position on |
| 1141 // the pending tree will clobber any impl-side scrolling occuring on the | 1196 // the pending tree will clobber any impl-side scrolling occuring on the |
| 1142 // active tree. To do so, avoid scrolling the pending tree along with it | 1197 // active tree. To do so, avoid scrolling the pending tree along with it |
| 1143 // instead of trying to undo that scrolling later. | 1198 // instead of trying to undo that scrolling later. |
| 1144 if (layer_animation_controller_->scroll_offset_animation_was_interrupted()) | 1199 if (ScrollOffsetAnimationWasInterrupted()) |
| 1145 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_); | 1200 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_); |
| 1146 else | 1201 else |
| 1147 layer->PushScrollOffsetFromMainThread(scroll_offset_); | 1202 layer->PushScrollOffsetFromMainThread(scroll_offset_); |
| 1148 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment()); | 1203 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment()); |
| 1149 | 1204 |
| 1150 // Wrap the copy_requests_ in a PostTask to the main thread. | 1205 // Wrap the copy_requests_ in a PostTask to the main thread. |
| 1151 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests; | 1206 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests; |
| 1152 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); | 1207 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); |
| 1153 it != copy_requests_.end(); | 1208 it != copy_requests_.end(); |
| 1154 ++it) { | 1209 ++it) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1171 | 1226 |
| 1172 // If the main thread commits multiple times before the impl thread actually | 1227 // If the main thread commits multiple times before the impl thread actually |
| 1173 // draws, then damage tracking will become incorrect if we simply clobber the | 1228 // draws, then damage tracking will become incorrect if we simply clobber the |
| 1174 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. | 1229 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. |
| 1175 // union) any update changes that have occurred on the main thread. | 1230 // union) any update changes that have occurred on the main thread. |
| 1176 update_rect_.Union(layer->update_rect()); | 1231 update_rect_.Union(layer->update_rect()); |
| 1177 layer->SetUpdateRect(update_rect_); | 1232 layer->SetUpdateRect(update_rect_); |
| 1178 | 1233 |
| 1179 layer->SetStackingOrderChanged(stacking_order_changed_); | 1234 layer->SetStackingOrderChanged(stacking_order_changed_); |
| 1180 | 1235 |
| 1181 layer_animation_controller_->PushAnimationUpdatesTo( | 1236 if (layer->layer_animation_controller() && layer_animation_controller_) |
| 1182 layer->layer_animation_controller()); | 1237 layer_animation_controller_->PushAnimationUpdatesTo( |
| 1238 layer->layer_animation_controller()); |
| 1183 | 1239 |
| 1184 if (frame_timing_requests_dirty_) { | 1240 if (frame_timing_requests_dirty_) { |
| 1185 layer->PassFrameTimingRequests(&frame_timing_requests_); | 1241 layer->PassFrameTimingRequests(&frame_timing_requests_); |
| 1186 frame_timing_requests_dirty_ = false; | 1242 frame_timing_requests_dirty_ = false; |
| 1187 } | 1243 } |
| 1188 | 1244 |
| 1189 // Reset any state that should be cleared for the next update. | 1245 // Reset any state that should be cleared for the next update. |
| 1190 stacking_order_changed_ = false; | 1246 stacking_order_changed_ = false; |
| 1191 update_rect_ = gfx::Rect(); | 1247 update_rect_ = gfx::Rect(); |
| 1192 | 1248 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 return false; | 1416 return false; |
| 1361 | 1417 |
| 1362 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", | 1418 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", |
| 1363 !layer_tree_host_); | 1419 !layer_tree_host_); |
| 1364 layer_animation_controller_->AddAnimation(animation.Pass()); | 1420 layer_animation_controller_->AddAnimation(animation.Pass()); |
| 1365 SetNeedsCommit(); | 1421 SetNeedsCommit(); |
| 1366 return true; | 1422 return true; |
| 1367 } | 1423 } |
| 1368 | 1424 |
| 1369 void Layer::PauseAnimation(int animation_id, double time_offset) { | 1425 void Layer::PauseAnimation(int animation_id, double time_offset) { |
| 1426 DCHECK(layer_animation_controller_); |
| 1370 layer_animation_controller_->PauseAnimation( | 1427 layer_animation_controller_->PauseAnimation( |
| 1371 animation_id, base::TimeDelta::FromSecondsD(time_offset)); | 1428 animation_id, base::TimeDelta::FromSecondsD(time_offset)); |
| 1372 SetNeedsCommit(); | 1429 SetNeedsCommit(); |
| 1373 } | 1430 } |
| 1374 | 1431 |
| 1375 void Layer::RemoveAnimation(int animation_id) { | 1432 void Layer::RemoveAnimation(int animation_id) { |
| 1433 DCHECK(layer_animation_controller_); |
| 1376 layer_animation_controller_->RemoveAnimation(animation_id); | 1434 layer_animation_controller_->RemoveAnimation(animation_id); |
| 1377 SetNeedsCommit(); | 1435 SetNeedsCommit(); |
| 1378 } | 1436 } |
| 1379 | 1437 |
| 1380 void Layer::RemoveAnimation(int animation_id, | 1438 void Layer::RemoveAnimation(int animation_id, |
| 1381 Animation::TargetProperty property) { | 1439 Animation::TargetProperty property) { |
| 1440 DCHECK(layer_animation_controller_); |
| 1382 layer_animation_controller_->RemoveAnimation(animation_id, property); | 1441 layer_animation_controller_->RemoveAnimation(animation_id, property); |
| 1383 SetNeedsCommit(); | 1442 SetNeedsCommit(); |
| 1384 } | 1443 } |
| 1385 | 1444 |
| 1386 void Layer::SetLayerAnimationControllerForTest( | 1445 void Layer::SetLayerAnimationControllerForTest( |
| 1387 scoped_refptr<LayerAnimationController> controller) { | 1446 scoped_refptr<LayerAnimationController> controller) { |
| 1447 DCHECK(layer_animation_controller_); |
| 1388 layer_animation_controller_->RemoveValueObserver(this); | 1448 layer_animation_controller_->RemoveValueObserver(this); |
| 1389 layer_animation_controller_ = controller; | 1449 layer_animation_controller_ = controller; |
| 1390 layer_animation_controller_->AddValueObserver(this); | 1450 layer_animation_controller_->AddValueObserver(this); |
| 1391 SetNeedsCommit(); | 1451 SetNeedsCommit(); |
| 1392 } | 1452 } |
| 1393 | 1453 |
| 1394 bool Layer::HasActiveAnimation() const { | 1454 bool Layer::HasActiveAnimation() const { |
| 1395 return layer_animation_controller_->HasActiveAnimation(); | 1455 DCHECK(layer_tree_host_); |
| 1456 return layer_animation_controller_ |
| 1457 ? layer_animation_controller_->HasActiveAnimation() |
| 1458 : layer_tree_host_->HasActiveAnimation(this); |
| 1396 } | 1459 } |
| 1397 | 1460 |
| 1398 void Layer::RegisterForAnimations(AnimationRegistrar* registrar, | 1461 void Layer::RegisterForAnimations(AnimationRegistrar* registrar, |
| 1399 const LayerTreeSettings& settings) { | 1462 const LayerTreeSettings& settings) { |
| 1400 if (!layer_animation_controller_) { | 1463 if (!settings.use_compositor_animation_timelines && |
| 1464 !layer_animation_controller_) { |
| 1401 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); | 1465 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); |
| 1402 layer_animation_controller_->AddValueObserver(this); | 1466 layer_animation_controller_->AddValueObserver(this); |
| 1403 layer_animation_controller_->set_value_provider(this); | 1467 layer_animation_controller_->set_value_provider(this); |
| 1404 } | 1468 } |
| 1405 | 1469 |
| 1406 layer_animation_controller_->SetAnimationRegistrar(registrar); | 1470 if (layer_animation_controller_) |
| 1471 layer_animation_controller_->SetAnimationRegistrar(registrar); |
| 1407 } | 1472 } |
| 1408 | 1473 |
| 1409 void Layer::AddLayerAnimationEventObserver( | 1474 void Layer::AddLayerAnimationEventObserver( |
| 1410 LayerAnimationEventObserver* animation_observer) { | 1475 LayerAnimationEventObserver* animation_observer) { |
| 1411 DCHECK(layer_animation_controller_); | 1476 DCHECK(layer_animation_controller_); |
| 1412 layer_animation_controller_->AddEventObserver(animation_observer); | 1477 layer_animation_controller_->AddEventObserver(animation_observer); |
| 1413 } | 1478 } |
| 1414 | 1479 |
| 1415 void Layer::RemoveLayerAnimationEventObserver( | 1480 void Layer::RemoveLayerAnimationEventObserver( |
| 1416 LayerAnimationEventObserver* animation_observer) { | 1481 LayerAnimationEventObserver* animation_observer) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 | 1547 |
| 1483 void Layer::DidBeginTracing() { | 1548 void Layer::DidBeginTracing() { |
| 1484 // We'll be dumping layer trees as part of trace, so make sure | 1549 // We'll be dumping layer trees as part of trace, so make sure |
| 1485 // PushPropertiesTo() propagates layer debug info to the impl | 1550 // PushPropertiesTo() propagates layer debug info to the impl |
| 1486 // side -- otherwise this won't happen for the the layers that | 1551 // side -- otherwise this won't happen for the the layers that |
| 1487 // remain unchanged since tracing started. | 1552 // remain unchanged since tracing started. |
| 1488 SetNeedsPushProperties(); | 1553 SetNeedsPushProperties(); |
| 1489 } | 1554 } |
| 1490 | 1555 |
| 1491 } // namespace cc | 1556 } // namespace cc |
| OLD | NEW |