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

Side by Side Diff: cc/layers/layer.cc

Issue 1130043003: [Sketch] CC Animations: Torpedo the old intrusive animation system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@implscroll
Patch Set: Delete more (headers and animation_registrar_ leftover) Created 5 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
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "cc/animation/animation.h"
16 #include "cc/animation/animation_events.h"
17 #include "cc/animation/animation_registrar.h"
18 #include "cc/animation/keyframed_animation_curve.h"
19 #include "cc/animation/layer_animation_controller.h"
20 #include "cc/base/simple_enclosed_region.h" 15 #include "cc/base/simple_enclosed_region.h"
21 #include "cc/debug/frame_viewer_instrumentation.h" 16 #include "cc/debug/frame_viewer_instrumentation.h"
22 #include "cc/layers/layer_client.h" 17 #include "cc/layers/layer_client.h"
23 #include "cc/layers/layer_impl.h" 18 #include "cc/layers/layer_impl.h"
24 #include "cc/layers/scrollbar_layer_interface.h" 19 #include "cc/layers/scrollbar_layer_interface.h"
25 #include "cc/output/copy_output_request.h" 20 #include "cc/output/copy_output_request.h"
26 #include "cc/output/copy_output_result.h" 21 #include "cc/output/copy_output_result.h"
27 #include "cc/trees/layer_tree_host.h" 22 #include "cc/trees/layer_tree_host.h"
28 #include "cc/trees/layer_tree_impl.h" 23 #include "cc/trees/layer_tree_impl.h"
29 #include "third_party/skia/include/core/SkImageFilter.h" 24 #include "third_party/skia/include/core/SkImageFilter.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 81 }
87 82
88 Layer::~Layer() { 83 Layer::~Layer() {
89 // Our parent should be holding a reference to us so there should be no 84 // Our parent should be holding a reference to us so there should be no
90 // way for us to be destroyed while we still have a parent. 85 // way for us to be destroyed while we still have a parent.
91 DCHECK(!parent()); 86 DCHECK(!parent());
92 // Similarly we shouldn't have a layer tree host since it also keeps a 87 // Similarly we shouldn't have a layer tree host since it also keeps a
93 // reference to us. 88 // reference to us.
94 DCHECK(!layer_tree_host()); 89 DCHECK(!layer_tree_host());
95 90
96 if (layer_animation_controller_) {
97 layer_animation_controller_->RemoveValueObserver(this);
98 layer_animation_controller_->remove_value_provider(this);
99 }
100
101 RemoveFromScrollTree(); 91 RemoveFromScrollTree();
102 RemoveFromClipTree(); 92 RemoveFromClipTree();
103 93
104 // Remove the parent reference from all children and dependents. 94 // Remove the parent reference from all children and dependents.
105 RemoveAllChildren(); 95 RemoveAllChildren();
106 if (mask_layer_.get()) { 96 if (mask_layer_.get()) {
107 DCHECK_EQ(this, mask_layer_->parent()); 97 DCHECK_EQ(this, mask_layer_->parent());
108 mask_layer_->RemoveFromParent(); 98 mask_layer_->RemoveFromParent();
109 } 99 }
110 if (replica_layer_.get()) { 100 if (replica_layer_.get()) {
(...skipping 20 matching lines...) Expand all
131 121
132 for (size_t i = 0; i < children_.size(); ++i) 122 for (size_t i = 0; i < children_.size(); ++i)
133 children_[i]->SetLayerTreeHost(host); 123 children_[i]->SetLayerTreeHost(host);
134 124
135 if (mask_layer_.get()) 125 if (mask_layer_.get())
136 mask_layer_->SetLayerTreeHost(host); 126 mask_layer_->SetLayerTreeHost(host);
137 if (replica_layer_.get()) 127 if (replica_layer_.get())
138 replica_layer_->SetLayerTreeHost(host); 128 replica_layer_->SetLayerTreeHost(host);
139 129
140 if (host) { 130 if (host) {
141 RegisterForAnimations(host->animation_registrar(), host->settings());
142 if (host->settings().layer_transforms_should_scale_layer_contents) 131 if (host->settings().layer_transforms_should_scale_layer_contents)
143 reset_raster_scale_to_unknown(); 132 reset_raster_scale_to_unknown();
144 } 133 }
145 134
146 bool has_any_animation = false; 135 bool has_any_animation = false;
147 if (layer_animation_controller_) 136 if (layer_tree_host_)
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); 137 has_any_animation = layer_tree_host_->HasAnyAnimation(this);
151 138
152 if (host && has_any_animation) 139 if (host && has_any_animation)
153 host->SetNeedsCommit(); 140 host->SetNeedsCommit();
154 } 141 }
155 142
156 void Layer::SetNeedsUpdate() { 143 void Layer::SetNeedsUpdate() {
157 if (layer_tree_host_ && !ignore_set_needs_commit_) 144 if (layer_tree_host_ && !ignore_set_needs_commit_)
158 layer_tree_host_->SetNeedsUpdateLayers(); 145 layer_tree_host_->SetNeedsUpdateLayers();
159 } 146 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 void Layer::SetFilters(const FilterOperations& filters) { 494 void Layer::SetFilters(const FilterOperations& filters) {
508 DCHECK(IsPropertyChangeAllowed()); 495 DCHECK(IsPropertyChangeAllowed());
509 if (filters_ == filters) 496 if (filters_ == filters)
510 return; 497 return;
511 filters_ = filters; 498 filters_ = filters;
512 SetNeedsCommit(); 499 SetNeedsCommit();
513 } 500 }
514 501
515 bool Layer::FilterIsAnimating() const { 502 bool Layer::FilterIsAnimating() const {
516 DCHECK(layer_tree_host_); 503 DCHECK(layer_tree_host_);
517 return layer_animation_controller_ 504 return layer_tree_host_->IsAnimatingFilterProperty(this);
518 ? layer_animation_controller_->IsAnimatingProperty(
519 Animation::FILTER)
520 : layer_tree_host_->IsAnimatingFilterProperty(this);
521 } 505 }
522 506
523 void Layer::SetBackgroundFilters(const FilterOperations& filters) { 507 void Layer::SetBackgroundFilters(const FilterOperations& filters) {
524 DCHECK(IsPropertyChangeAllowed()); 508 DCHECK(IsPropertyChangeAllowed());
525 if (background_filters_ == filters) 509 if (background_filters_ == filters)
526 return; 510 return;
527 background_filters_ = filters; 511 background_filters_ = filters;
528 SetNeedsCommit(); 512 SetNeedsCommit();
529 } 513 }
530 514
531 void Layer::SetOpacity(float opacity) { 515 void Layer::SetOpacity(float opacity) {
532 DCHECK(IsPropertyChangeAllowed()); 516 DCHECK(IsPropertyChangeAllowed());
533 if (opacity_ == opacity) 517 if (opacity_ == opacity)
534 return; 518 return;
535 opacity_ = opacity; 519 opacity_ = opacity;
536 SetNeedsCommit(); 520 SetNeedsCommit();
537 } 521 }
538 522
539 bool Layer::OpacityIsAnimating() const { 523 bool Layer::OpacityIsAnimating() const {
540 DCHECK(layer_tree_host_); 524 DCHECK(layer_tree_host_);
541 return layer_animation_controller_ 525 return layer_tree_host_->IsAnimatingOpacityProperty(this);
542 ? layer_animation_controller_->IsAnimatingProperty(
543 Animation::OPACITY)
544 : layer_tree_host_->IsAnimatingOpacityProperty(this);
545 } 526 }
546 527
547 bool Layer::HasPotentiallyRunningOpacityAnimation() const { 528 bool Layer::HasPotentiallyRunningOpacityAnimation() const {
548 if (layer_animation_controller_) { 529 DCHECK(layer_tree_host_);
549 if (Animation* animation = 530 return layer_tree_host_->HasPotentiallyRunningOpacityAnimation(this);
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 }
558 } 531 }
559 532
560 bool Layer::OpacityCanAnimateOnImplThread() const { 533 bool Layer::OpacityCanAnimateOnImplThread() const {
561 return false; 534 return false;
562 } 535 }
563 536
564 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) { 537 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) {
565 DCHECK(IsPropertyChangeAllowed()); 538 DCHECK(IsPropertyChangeAllowed());
566 if (blend_mode_ == blend_mode) 539 if (blend_mode_ == blend_mode)
567 return; 540 return;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 SetNeedsCommitNoRebuild(); 705 SetNeedsCommitNoRebuild();
733 return; 706 return;
734 } 707 }
735 } 708 }
736 709
737 SetNeedsCommit(); 710 SetNeedsCommit();
738 } 711 }
739 712
740 bool Layer::AnimationsPreserveAxisAlignment() const { 713 bool Layer::AnimationsPreserveAxisAlignment() const {
741 DCHECK(layer_tree_host_); 714 DCHECK(layer_tree_host_);
742 return layer_animation_controller_ 715 return layer_tree_host_->AnimationsPreserveAxisAlignment(this);
743 ? layer_animation_controller_->AnimationsPreserveAxisAlignment()
744 : layer_tree_host_->AnimationsPreserveAxisAlignment(this);
745 } 716 }
746 717
747 bool Layer::TransformIsAnimating() const { 718 bool Layer::TransformIsAnimating() const {
748 DCHECK(layer_tree_host_); 719 DCHECK(layer_tree_host_);
749 return layer_animation_controller_ 720 return layer_tree_host_->IsAnimatingTransformProperty(this);
750 ? layer_animation_controller_->IsAnimatingProperty(
751 Animation::TRANSFORM)
752 : layer_tree_host_->IsAnimatingTransformProperty(this);
753 } 721 }
754 722
755 bool Layer::HasPotentiallyRunningTransformAnimation() const { 723 bool Layer::HasPotentiallyRunningTransformAnimation() const {
756 if (layer_animation_controller_) { 724 DCHECK(layer_tree_host_);
757 if (Animation* animation = 725 return layer_tree_host_->HasPotentiallyRunningTransformAnimation(this);
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 } 726 }
767 727
768 bool Layer::ScrollOffsetAnimationWasInterrupted() const { 728 bool Layer::ScrollOffsetAnimationWasInterrupted() const {
769 DCHECK(layer_tree_host_); 729 DCHECK(layer_tree_host_);
770 return layer_animation_controller_ 730 return layer_tree_host_->ScrollOffsetAnimationWasInterrupted(this);
771 ? layer_animation_controller_
772 ->scroll_offset_animation_was_interrupted()
773 : layer_tree_host_->ScrollOffsetAnimationWasInterrupted(this);
774 } 731 }
775 732
776 void Layer::SetScrollParent(Layer* parent) { 733 void Layer::SetScrollParent(Layer* parent) {
777 DCHECK(IsPropertyChangeAllowed()); 734 DCHECK(IsPropertyChangeAllowed());
778 if (scroll_parent_ == parent) 735 if (scroll_parent_ == parent)
779 return; 736 return;
780 737
781 if (scroll_parent_) 738 if (scroll_parent_)
782 scroll_parent_->RemoveScrollChild(this); 739 scroll_parent_->RemoveScrollChild(this);
783 740
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 1183
1227 // If the main thread commits multiple times before the impl thread actually 1184 // If the main thread commits multiple times before the impl thread actually
1228 // draws, then damage tracking will become incorrect if we simply clobber the 1185 // draws, then damage tracking will become incorrect if we simply clobber the
1229 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. 1186 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1230 // union) any update changes that have occurred on the main thread. 1187 // union) any update changes that have occurred on the main thread.
1231 update_rect_.Union(layer->update_rect()); 1188 update_rect_.Union(layer->update_rect());
1232 layer->SetUpdateRect(update_rect_); 1189 layer->SetUpdateRect(update_rect_);
1233 1190
1234 layer->SetStackingOrderChanged(stacking_order_changed_); 1191 layer->SetStackingOrderChanged(stacking_order_changed_);
1235 1192
1236 if (layer->layer_animation_controller() && layer_animation_controller_)
1237 layer_animation_controller_->PushAnimationUpdatesTo(
1238 layer->layer_animation_controller());
1239
1240 if (frame_timing_requests_dirty_) { 1193 if (frame_timing_requests_dirty_) {
1241 layer->PassFrameTimingRequests(&frame_timing_requests_); 1194 layer->PassFrameTimingRequests(&frame_timing_requests_);
1242 frame_timing_requests_dirty_ = false; 1195 frame_timing_requests_dirty_ = false;
1243 } 1196 }
1244 1197
1245 // Reset any state that should be cleared for the next update. 1198 // Reset any state that should be cleared for the next update.
1246 stacking_order_changed_ = false; 1199 stacking_order_changed_ = false;
1247 update_rect_ = gfx::Rect(); 1200 update_rect_ = gfx::Rect();
1248 1201
1249 needs_push_properties_ = false; 1202 needs_push_properties_ = false;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 node->data.local = transform; 1336 node->data.local = transform;
1384 node->data.needs_local_transform_update = true; 1337 node->data.needs_local_transform_update = true;
1385 node->data.is_animated = true; 1338 node->data.is_animated = true;
1386 layer_tree_host_->property_trees()->transform_tree.set_needs_update( 1339 layer_tree_host_->property_trees()->transform_tree.set_needs_update(
1387 true); 1340 true);
1388 } 1341 }
1389 } 1342 }
1390 } 1343 }
1391 } 1344 }
1392 1345
1393 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
1394 // Do nothing. Scroll deltas will be sent from the compositor thread back
1395 // to the main thread in the same manner as during non-animated
1396 // compositor-driven scrolling.
1397 }
1398
1399 void Layer::OnAnimationWaitingForDeletion() {
1400 // Animations are only deleted during PushProperties.
1401 SetNeedsPushProperties();
1402 }
1403
1404 bool Layer::IsActive() const {
1405 return true;
1406 }
1407
1408 bool Layer::AddAnimation(scoped_ptr <Animation> animation) {
1409 if (!layer_animation_controller_ ||
1410 !layer_animation_controller_->animation_registrar())
1411 return false;
1412
1413 if (animation->target_property() == Animation::SCROLL_OFFSET &&
1414 !layer_animation_controller_->animation_registrar()
1415 ->supports_scroll_animations())
1416 return false;
1417
1418 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1419 !layer_tree_host_);
1420 layer_animation_controller_->AddAnimation(animation.Pass());
1421 SetNeedsCommit();
1422 return true;
1423 }
1424
1425 void Layer::PauseAnimation(int animation_id, double time_offset) {
1426 DCHECK(layer_animation_controller_);
1427 layer_animation_controller_->PauseAnimation(
1428 animation_id, base::TimeDelta::FromSecondsD(time_offset));
1429 SetNeedsCommit();
1430 }
1431
1432 void Layer::RemoveAnimation(int animation_id) {
1433 DCHECK(layer_animation_controller_);
1434 layer_animation_controller_->RemoveAnimation(animation_id);
1435 SetNeedsCommit();
1436 }
1437
1438 void Layer::RemoveAnimation(int animation_id,
1439 Animation::TargetProperty property) {
1440 DCHECK(layer_animation_controller_);
1441 layer_animation_controller_->RemoveAnimation(animation_id, property);
1442 SetNeedsCommit();
1443 }
1444
1445 void Layer::SetLayerAnimationControllerForTest(
1446 scoped_refptr<LayerAnimationController> controller) {
1447 DCHECK(layer_animation_controller_);
1448 layer_animation_controller_->RemoveValueObserver(this);
1449 layer_animation_controller_ = controller;
1450 layer_animation_controller_->AddValueObserver(this);
1451 SetNeedsCommit();
1452 }
1453
1454 bool Layer::HasActiveAnimation() const { 1346 bool Layer::HasActiveAnimation() const {
1455 DCHECK(layer_tree_host_); 1347 DCHECK(layer_tree_host_);
1456 return layer_animation_controller_ 1348 return layer_tree_host_->HasActiveAnimation(this);
1457 ? layer_animation_controller_->HasActiveAnimation()
1458 : layer_tree_host_->HasActiveAnimation(this);
1459 }
1460
1461 void Layer::RegisterForAnimations(AnimationRegistrar* registrar,
1462 const LayerTreeSettings& settings) {
1463 if (!settings.use_compositor_animation_timelines &&
1464 !layer_animation_controller_) {
1465 layer_animation_controller_ = LayerAnimationController::Create(layer_id_);
1466 layer_animation_controller_->AddValueObserver(this);
1467 layer_animation_controller_->set_value_provider(this);
1468 }
1469
1470 if (layer_animation_controller_)
1471 layer_animation_controller_->SetAnimationRegistrar(registrar);
1472 }
1473
1474 void Layer::AddLayerAnimationEventObserver(
1475 LayerAnimationEventObserver* animation_observer) {
1476 DCHECK(layer_animation_controller_);
1477 layer_animation_controller_->AddEventObserver(animation_observer);
1478 }
1479
1480 void Layer::RemoveLayerAnimationEventObserver(
1481 LayerAnimationEventObserver* animation_observer) {
1482 DCHECK(layer_animation_controller_);
1483 layer_animation_controller_->RemoveEventObserver(animation_observer);
1484 } 1349 }
1485 1350
1486 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { 1351 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const {
1487 if (contents_opaque()) 1352 if (contents_opaque())
1488 return SimpleEnclosedRegion(visible_content_rect()); 1353 return SimpleEnclosedRegion(visible_content_rect());
1489 return SimpleEnclosedRegion(); 1354 return SimpleEnclosedRegion();
1490 } 1355 }
1491 1356
1492 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { 1357 ScrollbarLayerInterface* Layer::ToScrollbarLayer() {
1493 return nullptr; 1358 return nullptr;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 1412
1548 void Layer::DidBeginTracing() { 1413 void Layer::DidBeginTracing() {
1549 // We'll be dumping layer trees as part of trace, so make sure 1414 // We'll be dumping layer trees as part of trace, so make sure
1550 // PushPropertiesTo() propagates layer debug info to the impl 1415 // PushPropertiesTo() propagates layer debug info to the impl
1551 // side -- otherwise this won't happen for the the layers that 1416 // side -- otherwise this won't happen for the the layers that
1552 // remain unchanged since tracing started. 1417 // remain unchanged since tracing started.
1553 SetNeedsPushProperties(); 1418 SetNeedsPushProperties();
1554 } 1419 }
1555 1420
1556 } // namespace cc 1421 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698