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

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

Issue 1010663002: CC Animations: Redirect all compositor animation requests to AnimationHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@introduce
Patch Set: Add ported unittests. Created 5 years, 8 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 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE), 76 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
77 background_color_(0), 77 background_color_(0),
78 opacity_(1.f), 78 opacity_(1.f),
79 blend_mode_(SkXfermode::kSrcOver_Mode), 79 blend_mode_(SkXfermode::kSrcOver_Mode),
80 scroll_parent_(nullptr), 80 scroll_parent_(nullptr),
81 clip_parent_(nullptr), 81 clip_parent_(nullptr),
82 replica_layer_(nullptr), 82 replica_layer_(nullptr),
83 raster_scale_(0.f), 83 raster_scale_(0.f),
84 client_(nullptr), 84 client_(nullptr),
85 frame_timing_requests_dirty_(false) { 85 frame_timing_requests_dirty_(false) {
86 // TODO(loyso): Do not create LayerAnimationController once systems migrated.
86 layer_animation_controller_ = LayerAnimationController::Create(layer_id_); 87 layer_animation_controller_ = LayerAnimationController::Create(layer_id_);
87 layer_animation_controller_->AddValueObserver(this); 88 layer_animation_controller_->AddValueObserver(this);
88 layer_animation_controller_->set_value_provider(this); 89 layer_animation_controller_->set_value_provider(this);
89 } 90 }
90 91
91 Layer::~Layer() { 92 Layer::~Layer() {
92 // Our parent should be holding a reference to us so there should be no 93 // Our parent should be holding a reference to us so there should be no
93 // way for us to be destroyed while we still have a parent. 94 // way for us to be destroyed while we still have a parent.
94 DCHECK(!parent()); 95 DCHECK(!parent());
95 // Similarly we shouldn't have a layer tree host since it also keeps a 96 // Similarly we shouldn't have a layer tree host since it also keeps a
96 // reference to us. 97 // reference to us.
97 DCHECK(!layer_tree_host()); 98 DCHECK(!layer_tree_host());
98 99
99 layer_animation_controller_->RemoveValueObserver(this); 100 if (layer_animation_controller_) {
100 layer_animation_controller_->remove_value_provider(this); 101 layer_animation_controller_->RemoveValueObserver(this);
102 layer_animation_controller_->remove_value_provider(this);
103 }
101 104
102 RemoveFromScrollTree(); 105 RemoveFromScrollTree();
103 RemoveFromClipTree(); 106 RemoveFromClipTree();
104 107
105 // Remove the parent reference from all children and dependents. 108 // Remove the parent reference from all children and dependents.
106 RemoveAllChildren(); 109 RemoveAllChildren();
107 if (mask_layer_.get()) { 110 if (mask_layer_.get()) {
108 DCHECK_EQ(this, mask_layer_->parent()); 111 DCHECK_EQ(this, mask_layer_->parent());
109 mask_layer_->RemoveFromParent(); 112 mask_layer_->RemoveFromParent();
110 } 113 }
(...skipping 19 matching lines...) Expand all
130 133
131 for (size_t i = 0; i < children_.size(); ++i) 134 for (size_t i = 0; i < children_.size(); ++i)
132 children_[i]->SetLayerTreeHost(host); 135 children_[i]->SetLayerTreeHost(host);
133 136
134 if (mask_layer_.get()) 137 if (mask_layer_.get())
135 mask_layer_->SetLayerTreeHost(host); 138 mask_layer_->SetLayerTreeHost(host);
136 if (replica_layer_.get()) 139 if (replica_layer_.get())
137 replica_layer_->SetLayerTreeHost(host); 140 replica_layer_->SetLayerTreeHost(host);
138 141
139 if (host) { 142 if (host) {
140 layer_animation_controller_->SetAnimationRegistrar( 143 RegisterForAnimations(host->animation_registrar(), host->settings());
141 host->animation_registrar());
142
143 if (host->settings().layer_transforms_should_scale_layer_contents) 144 if (host->settings().layer_transforms_should_scale_layer_contents)
144 reset_raster_scale_to_unknown(); 145 reset_raster_scale_to_unknown();
145 } 146 }
146 147
147 if (host && layer_animation_controller_->has_any_animation()) 148 bool has_any_animation = false;
149 if (layer_animation_controller_)
150 has_any_animation = layer_animation_controller_->has_any_animation();
151 else if (layer_tree_host_)
152 has_any_animation = layer_tree_host_->HasAnyAnimation(this);
153
154 if (host && has_any_animation)
148 host->SetNeedsCommit(); 155 host->SetNeedsCommit();
149 } 156 }
150 157
151 void Layer::SetNeedsUpdate() { 158 void Layer::SetNeedsUpdate() {
152 if (layer_tree_host_ && !ignore_set_needs_commit_) 159 if (layer_tree_host_ && !ignore_set_needs_commit_)
153 layer_tree_host_->SetNeedsUpdateLayers(); 160 layer_tree_host_->SetNeedsUpdateLayers();
154 } 161 }
155 162
156 void Layer::SetNeedsCommit() { 163 void Layer::SetNeedsCommit() {
157 if (!layer_tree_host_) 164 if (!layer_tree_host_)
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 484
478 void Layer::SetFilters(const FilterOperations& filters) { 485 void Layer::SetFilters(const FilterOperations& filters) {
479 DCHECK(IsPropertyChangeAllowed()); 486 DCHECK(IsPropertyChangeAllowed());
480 if (filters_ == filters) 487 if (filters_ == filters)
481 return; 488 return;
482 filters_ = filters; 489 filters_ = filters;
483 SetNeedsCommit(); 490 SetNeedsCommit();
484 } 491 }
485 492
486 bool Layer::FilterIsAnimating() const { 493 bool Layer::FilterIsAnimating() const {
487 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER); 494 DCHECK(layer_tree_host_);
495 return layer_animation_controller_
496 ? layer_animation_controller_->IsAnimatingProperty(
497 Animation::FILTER)
498 : layer_tree_host_->IsAnimatingFilterProperty(this);
488 } 499 }
489 500
490 void Layer::SetBackgroundFilters(const FilterOperations& filters) { 501 void Layer::SetBackgroundFilters(const FilterOperations& filters) {
491 DCHECK(IsPropertyChangeAllowed()); 502 DCHECK(IsPropertyChangeAllowed());
492 if (background_filters_ == filters) 503 if (background_filters_ == filters)
493 return; 504 return;
494 background_filters_ = filters; 505 background_filters_ = filters;
495 SetNeedsCommit(); 506 SetNeedsCommit();
496 } 507 }
497 508
498 void Layer::SetOpacity(float opacity) { 509 void Layer::SetOpacity(float opacity) {
499 DCHECK(IsPropertyChangeAllowed()); 510 DCHECK(IsPropertyChangeAllowed());
500 if (opacity_ == opacity) 511 if (opacity_ == opacity)
501 return; 512 return;
502 opacity_ = opacity; 513 opacity_ = opacity;
503 SetNeedsCommit(); 514 SetNeedsCommit();
504 } 515 }
505 516
506 bool Layer::OpacityIsAnimating() const { 517 bool Layer::OpacityIsAnimating() const {
507 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY); 518 DCHECK(layer_tree_host_);
519 return layer_animation_controller_
520 ? layer_animation_controller_->IsAnimatingProperty(
521 Animation::OPACITY)
522 : layer_tree_host_->IsAnimatingOpacityProperty(this);
508 } 523 }
509 524
510 bool Layer::OpacityCanAnimateOnImplThread() const { 525 bool Layer::OpacityCanAnimateOnImplThread() const {
511 return false; 526 return false;
512 } 527 }
513 528
514 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) { 529 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) {
515 DCHECK(IsPropertyChangeAllowed()); 530 DCHECK(IsPropertyChangeAllowed());
516 if (blend_mode_ == blend_mode) 531 if (blend_mode_ == blend_mode)
517 return; 532 return;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 618
604 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) { 619 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) {
605 DCHECK(IsPropertyChangeAllowed()); 620 DCHECK(IsPropertyChangeAllowed());
606 if (transform_origin_ == transform_origin) 621 if (transform_origin_ == transform_origin)
607 return; 622 return;
608 transform_origin_ = transform_origin; 623 transform_origin_ = transform_origin;
609 SetNeedsCommit(); 624 SetNeedsCommit();
610 } 625 }
611 626
612 bool Layer::AnimationsPreserveAxisAlignment() const { 627 bool Layer::AnimationsPreserveAxisAlignment() const {
613 return layer_animation_controller_->AnimationsPreserveAxisAlignment(); 628 DCHECK(layer_tree_host_);
629 return layer_animation_controller_
630 ? layer_animation_controller_->AnimationsPreserveAxisAlignment()
631 : layer_tree_host_->AnimationsPreserveAxisAlignment(this);
614 } 632 }
615 633
616 bool Layer::TransformIsAnimating() const { 634 bool Layer::TransformIsAnimating() const {
617 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM); 635 DCHECK(layer_tree_host_);
636 return layer_animation_controller_
637 ? layer_animation_controller_->IsAnimatingProperty(
638 Animation::TRANSFORM)
639 : layer_tree_host_->IsAnimatingTransformProperty(this);
618 } 640 }
619 641
620 void Layer::SetScrollParent(Layer* parent) { 642 void Layer::SetScrollParent(Layer* parent) {
621 DCHECK(IsPropertyChangeAllowed()); 643 DCHECK(IsPropertyChangeAllowed());
622 if (scroll_parent_ == parent) 644 if (scroll_parent_ == parent)
623 return; 645 return;
624 646
625 if (scroll_parent_) 647 if (scroll_parent_)
626 scroll_parent_->RemoveScrollChild(this); 648 scroll_parent_->RemoveScrollChild(this);
627 649
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 } 1015 }
994 layer->SetClipChildren(clip_children); 1016 layer->SetClipChildren(clip_children);
995 } else { 1017 } else {
996 layer->SetClipChildren(nullptr); 1018 layer->SetClipChildren(nullptr);
997 } 1019 }
998 1020
999 // When a scroll offset animation is interrupted the new scroll position on 1021 // When a scroll offset animation is interrupted the new scroll position on
1000 // the pending tree will clobber any impl-side scrolling occuring on the 1022 // the pending tree will clobber any impl-side scrolling occuring on the
1001 // active tree. To do so, avoid scrolling the pending tree along with it 1023 // active tree. To do so, avoid scrolling the pending tree along with it
1002 // instead of trying to undo that scrolling later. 1024 // instead of trying to undo that scrolling later.
1003 if (layer_animation_controller_->scroll_offset_animation_was_interrupted()) 1025 if (layer_animation_controller_ &&
1026 layer_animation_controller_->scroll_offset_animation_was_interrupted())
ajuma 2015/04/21 17:57:57 This will need an equivalent in the new system.
loyso (OOO) 2015/04/22 01:08:11 Acknowledged.
loyso (OOO) 2015/04/30 07:06:01 Done.
1004 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_); 1027 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_);
1005 else 1028 else
1006 layer->PushScrollOffsetFromMainThread(scroll_offset_); 1029 layer->PushScrollOffsetFromMainThread(scroll_offset_);
1007 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment()); 1030 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1008 1031
1009 // Wrap the copy_requests_ in a PostTask to the main thread. 1032 // Wrap the copy_requests_ in a PostTask to the main thread.
1010 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests; 1033 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests;
1011 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); 1034 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin();
1012 it != copy_requests_.end(); 1035 it != copy_requests_.end();
1013 ++it) { 1036 ++it) {
(...skipping 14 matching lines...) Expand all
1028 1051
1029 // If the main thread commits multiple times before the impl thread actually 1052 // If the main thread commits multiple times before the impl thread actually
1030 // draws, then damage tracking will become incorrect if we simply clobber the 1053 // draws, then damage tracking will become incorrect if we simply clobber the
1031 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. 1054 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1032 // union) any update changes that have occurred on the main thread. 1055 // union) any update changes that have occurred on the main thread.
1033 update_rect_.Union(layer->update_rect()); 1056 update_rect_.Union(layer->update_rect());
1034 layer->SetUpdateRect(update_rect_); 1057 layer->SetUpdateRect(update_rect_);
1035 1058
1036 layer->SetStackingOrderChanged(stacking_order_changed_); 1059 layer->SetStackingOrderChanged(stacking_order_changed_);
1037 1060
1038 layer_animation_controller_->PushAnimationUpdatesTo( 1061 if (layer->layer_animation_controller() && layer_animation_controller_)
1039 layer->layer_animation_controller()); 1062 layer_animation_controller_->PushAnimationUpdatesTo(
1063 layer->layer_animation_controller());
1040 1064
1041 if (frame_timing_requests_dirty_) { 1065 if (frame_timing_requests_dirty_) {
1042 layer->PassFrameTimingRequests(&frame_timing_requests_); 1066 layer->PassFrameTimingRequests(&frame_timing_requests_);
1043 frame_timing_requests_dirty_ = false; 1067 frame_timing_requests_dirty_ = false;
1044 } 1068 }
1045 1069
1046 // Reset any state that should be cleared for the next update. 1070 // Reset any state that should be cleared for the next update.
1047 stacking_order_changed_ = false; 1071 stacking_order_changed_ = false;
1048 update_rect_ = gfx::Rect(); 1072 update_rect_ = gfx::Rect();
1049 1073
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 void Layer::OnAnimationWaitingForDeletion() { 1203 void Layer::OnAnimationWaitingForDeletion() {
1180 // Animations are only deleted during PushProperties. 1204 // Animations are only deleted during PushProperties.
1181 SetNeedsPushProperties(); 1205 SetNeedsPushProperties();
1182 } 1206 }
1183 1207
1184 bool Layer::IsActive() const { 1208 bool Layer::IsActive() const {
1185 return true; 1209 return true;
1186 } 1210 }
1187 1211
1188 bool Layer::AddAnimation(scoped_ptr <Animation> animation) { 1212 bool Layer::AddAnimation(scoped_ptr <Animation> animation) {
1189 if (!layer_animation_controller_->animation_registrar()) 1213 if (!layer_animation_controller_ ||
1214 !layer_animation_controller_->animation_registrar())
1190 return false; 1215 return false;
1191 1216
1192 if (animation->target_property() == Animation::SCROLL_OFFSET && 1217 if (animation->target_property() == Animation::SCROLL_OFFSET &&
1193 !layer_animation_controller_->animation_registrar() 1218 !layer_animation_controller_->animation_registrar()
1194 ->supports_scroll_animations()) 1219 ->supports_scroll_animations())
1195 return false; 1220 return false;
1196 1221
1197 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer", 1222 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1198 !layer_tree_host_); 1223 !layer_tree_host_);
1199 layer_animation_controller_->AddAnimation(animation.Pass()); 1224 layer_animation_controller_->AddAnimation(animation.Pass());
1200 SetNeedsCommit(); 1225 SetNeedsCommit();
1201 return true; 1226 return true;
1202 } 1227 }
1203 1228
1204 void Layer::PauseAnimation(int animation_id, double time_offset) { 1229 void Layer::PauseAnimation(int animation_id, double time_offset) {
1230 DCHECK(layer_animation_controller_);
1205 layer_animation_controller_->PauseAnimation( 1231 layer_animation_controller_->PauseAnimation(
1206 animation_id, base::TimeDelta::FromSecondsD(time_offset)); 1232 animation_id, base::TimeDelta::FromSecondsD(time_offset));
1207 SetNeedsCommit(); 1233 SetNeedsCommit();
1208 } 1234 }
1209 1235
1210 void Layer::RemoveAnimation(int animation_id) { 1236 void Layer::RemoveAnimation(int animation_id) {
1237 DCHECK(layer_animation_controller_);
1211 layer_animation_controller_->RemoveAnimation(animation_id); 1238 layer_animation_controller_->RemoveAnimation(animation_id);
1212 SetNeedsCommit(); 1239 SetNeedsCommit();
1213 } 1240 }
1214 1241
1215 void Layer::RemoveAnimation(int animation_id, 1242 void Layer::RemoveAnimation(int animation_id,
1216 Animation::TargetProperty property) { 1243 Animation::TargetProperty property) {
1244 DCHECK(layer_animation_controller_);
1217 layer_animation_controller_->RemoveAnimation(animation_id, property); 1245 layer_animation_controller_->RemoveAnimation(animation_id, property);
1218 SetNeedsCommit(); 1246 SetNeedsCommit();
1219 } 1247 }
1220 1248
1221 void Layer::SetLayerAnimationControllerForTest( 1249 void Layer::SetLayerAnimationControllerForTest(
1222 scoped_refptr<LayerAnimationController> controller) { 1250 scoped_refptr<LayerAnimationController> controller) {
1251 DCHECK(layer_animation_controller_);
1223 layer_animation_controller_->RemoveValueObserver(this); 1252 layer_animation_controller_->RemoveValueObserver(this);
1224 layer_animation_controller_ = controller; 1253 layer_animation_controller_ = controller;
1225 layer_animation_controller_->AddValueObserver(this); 1254 layer_animation_controller_->AddValueObserver(this);
1226 SetNeedsCommit(); 1255 SetNeedsCommit();
1227 } 1256 }
1228 1257
1229 bool Layer::HasActiveAnimation() const { 1258 bool Layer::HasActiveAnimation() const {
1230 return layer_animation_controller_->HasActiveAnimation(); 1259 DCHECK(layer_tree_host_);
1260 return layer_animation_controller_
1261 ? layer_animation_controller_->HasActiveAnimation()
1262 : layer_tree_host_->HasActiveAnimation(this);
1263 }
1264
1265 void Layer::RegisterForAnimations(AnimationRegistrar* registrar,
1266 const LayerTreeSettings& settings) {
1267 if (!settings.use_compositor_animation_timelines &&
1268 !layer_animation_controller_) {
1269 layer_animation_controller_ = LayerAnimationController::Create(layer_id_);
1270 layer_animation_controller_->AddValueObserver(this);
1271 layer_animation_controller_->set_value_provider(this);
1272 }
1273
1274 if (layer_animation_controller_)
ajuma 2015/04/21 17:57:57 This will always be true if we're constructing a c
loyso (OOO) 2015/04/22 01:08:11 Yes, that's correct statement. The problem is that
ajuma 2015/04/22 14:36:37 I think I'd prefer that the creation of LACs be mo
loyso (OOO) 2015/04/23 07:58:20 That's not that simple with ui::Layers. See the hi
1275 layer_animation_controller_->SetAnimationRegistrar(registrar);
1231 } 1276 }
1232 1277
1233 void Layer::AddLayerAnimationEventObserver( 1278 void Layer::AddLayerAnimationEventObserver(
1234 LayerAnimationEventObserver* animation_observer) { 1279 LayerAnimationEventObserver* animation_observer) {
1280 DCHECK(layer_animation_controller_);
1235 layer_animation_controller_->AddEventObserver(animation_observer); 1281 layer_animation_controller_->AddEventObserver(animation_observer);
1236 } 1282 }
1237 1283
1238 void Layer::RemoveLayerAnimationEventObserver( 1284 void Layer::RemoveLayerAnimationEventObserver(
1239 LayerAnimationEventObserver* animation_observer) { 1285 LayerAnimationEventObserver* animation_observer) {
1286 DCHECK(layer_animation_controller_);
1240 layer_animation_controller_->RemoveEventObserver(animation_observer); 1287 layer_animation_controller_->RemoveEventObserver(animation_observer);
1241 } 1288 }
1242 1289
1243 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const { 1290 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const {
1244 if (contents_opaque()) 1291 if (contents_opaque())
1245 return SimpleEnclosedRegion(visible_content_rect()); 1292 return SimpleEnclosedRegion(visible_content_rect());
1246 return SimpleEnclosedRegion(); 1293 return SimpleEnclosedRegion();
1247 } 1294 }
1248 1295
1249 ScrollbarLayerInterface* Layer::ToScrollbarLayer() { 1296 ScrollbarLayerInterface* Layer::ToScrollbarLayer() {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 1426
1380 void Layer::DidBeginTracing() { 1427 void Layer::DidBeginTracing() {
1381 // We'll be dumping layer trees as part of trace, so make sure 1428 // We'll be dumping layer trees as part of trace, so make sure
1382 // PushPropertiesTo() propagates layer debug info to the impl 1429 // PushPropertiesTo() propagates layer debug info to the impl
1383 // side -- otherwise this won't happen for the the layers that 1430 // side -- otherwise this won't happen for the the layers that
1384 // remain unchanged since tracing started. 1431 // remain unchanged since tracing started.
1385 SetNeedsPushProperties(); 1432 SetNeedsPushProperties();
1386 } 1433 }
1387 1434
1388 } // namespace cc 1435 } // namespace cc
OLDNEW
« cc/animation/animation_host.cc ('K') | « 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