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

Side by Side Diff: ui/compositor/layer.cc

Issue 1101823002: CC Animations: Make LayerAnimationController creation optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address observers attach/detach. 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 | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_element.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer.h" 5 #include "ui/compositor/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (compositor_) 117 if (compositor_)
118 compositor_->SetRootLayer(NULL); 118 compositor_->SetRootLayer(NULL);
119 if (parent_) 119 if (parent_)
120 parent_->Remove(this); 120 parent_->Remove(this);
121 if (layer_mask_) 121 if (layer_mask_)
122 SetMaskLayer(NULL); 122 SetMaskLayer(NULL);
123 if (layer_mask_back_link_) 123 if (layer_mask_back_link_)
124 layer_mask_back_link_->SetMaskLayer(NULL); 124 layer_mask_back_link_->SetMaskLayer(NULL);
125 for (size_t i = 0; i < children_.size(); ++i) 125 for (size_t i = 0; i < children_.size(); ++i)
126 children_[i]->parent_ = NULL; 126 children_[i]->parent_ = NULL;
127 cc_layer_->RemoveLayerAnimationEventObserver(this); 127
128 if (cc_layer_->layer_animation_controller())
129 cc_layer_->RemoveLayerAnimationEventObserver(this);
130
128 cc_layer_->RemoveFromParent(); 131 cc_layer_->RemoveFromParent();
129 } 132 }
130 133
131 // static 134 // static
132 bool Layer::UsingPictureLayer() { 135 bool Layer::UsingPictureLayer() {
133 return g_ui_impl_side_painting_status.Get().enabled; 136 return g_ui_impl_side_painting_status.Get().enabled;
134 } 137 }
135 138
136 const Compositor* Layer::GetCompositor() const { 139 const Compositor* Layer::GetCompositor() const {
137 return GetRoot(this)->compositor_; 140 return GetRoot(this)->compositor_;
138 } 141 }
139 142
140 float Layer::opacity() const { 143 float Layer::opacity() const {
141 return cc_layer_->opacity(); 144 return cc_layer_->opacity();
142 } 145 }
143 146
144 void Layer::SetCompositor(Compositor* compositor) { 147 void Layer::SetCompositor(Compositor* compositor,
145 // This function must only be called to set the compositor on the root layer, 148 scoped_refptr<cc::Layer> root_layer) {
146 // or to reset it. 149 // This function must only be called to set the compositor on the root ui
147 DCHECK(!compositor || !compositor_); 150 // layer.
148 DCHECK(!compositor || compositor->root_layer() == this); 151 DCHECK(compositor);
152 DCHECK(!compositor_);
153 DCHECK(compositor->root_layer() == this);
149 DCHECK(!parent_); 154 DCHECK(!parent_);
150 if (compositor_) { 155
156 compositor_ = compositor;
157 OnDeviceScaleFactorChanged(compositor->device_scale_factor());
158 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
159
160 root_layer->AddChild(cc_layer_);
161 SendPendingThreadedAnimations();
162 }
163
164 void Layer::ResetCompositor() {
165 DCHECK(!parent_);
166 if (compositor_)
151 RemoveAnimatorsInTreeFromCollection( 167 RemoveAnimatorsInTreeFromCollection(
152 compositor_->layer_animator_collection()); 168 compositor_->layer_animator_collection());
153 } 169 compositor_ = nullptr;
154 compositor_ = compositor;
155 if (compositor) {
156 OnDeviceScaleFactorChanged(compositor->device_scale_factor());
157 SendPendingThreadedAnimations();
158 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
159 }
160 } 170 }
161 171
162 void Layer::Add(Layer* child) { 172 void Layer::Add(Layer* child) {
163 DCHECK(!child->compositor_); 173 DCHECK(!child->compositor_);
164 if (child->parent_) 174 if (child->parent_)
165 child->parent_->Remove(child); 175 child->parent_->Remove(child);
166 child->parent_ = this; 176 child->parent_ = this;
167 children_.push_back(child); 177 children_.push_back(child);
168 cc_layer_->AddChild(child->cc_layer_); 178 cc_layer_->AddChild(child->cc_layer_);
169 child->OnDeviceScaleFactorChanged(device_scale_factor_); 179 child->OnDeviceScaleFactorChanged(device_scale_factor_);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 layer_mask->children().empty() && 340 layer_mask->children().empty() &&
331 !layer_mask->layer_mask_back_link_)); 341 !layer_mask->layer_mask_back_link_));
332 DCHECK(!layer_mask_back_link_); 342 DCHECK(!layer_mask_back_link_);
333 if (layer_mask_ == layer_mask) 343 if (layer_mask_ == layer_mask)
334 return; 344 return;
335 // We need to de-reference the currently linked object so that no problem 345 // We need to de-reference the currently linked object so that no problem
336 // arises if the mask layer gets deleted before this object. 346 // arises if the mask layer gets deleted before this object.
337 if (layer_mask_) 347 if (layer_mask_)
338 layer_mask_->layer_mask_back_link_ = NULL; 348 layer_mask_->layer_mask_back_link_ = NULL;
339 layer_mask_ = layer_mask; 349 layer_mask_ = layer_mask;
340 cc_layer_->SetMaskLayer( 350 cc_layer_->SetMaskLayer(layer_mask ? layer_mask->cc_layer_ : NULL);
341 layer_mask ? layer_mask->cc_layer() : NULL);
342 // We need to reference the linked object so that it can properly break the 351 // We need to reference the linked object so that it can properly break the
343 // link to us when it gets deleted. 352 // link to us when it gets deleted.
344 if (layer_mask) { 353 if (layer_mask) {
345 layer_mask->layer_mask_back_link_ = this; 354 layer_mask->layer_mask_back_link_ = this;
346 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); 355 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_);
347 } 356 }
348 } 357 }
349 358
350 void Layer::SetBackgroundZoom(float zoom, int inset) { 359 void Layer::SetBackgroundZoom(float zoom, int inset) {
351 zoom_ = zoom; 360 zoom_ = zoom;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 fills_bounds_opaquely_ = fills_bounds_opaquely; 477 fills_bounds_opaquely_ = fills_bounds_opaquely;
469 478
470 cc_layer_->SetContentsOpaque(fills_bounds_opaquely); 479 cc_layer_->SetContentsOpaque(fills_bounds_opaquely);
471 } 480 }
472 481
473 void Layer::SetFillsBoundsCompletely(bool fills_bounds_completely) { 482 void Layer::SetFillsBoundsCompletely(bool fills_bounds_completely) {
474 fills_bounds_completely_ = fills_bounds_completely; 483 fills_bounds_completely_ = fills_bounds_completely;
475 } 484 }
476 485
477 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { 486 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
487 DCHECK(!new_layer->parent());
488 DCHECK(!new_layer->layer_animation_controller());
489
478 // Finish animations being handled by cc_layer_. 490 // Finish animations being handled by cc_layer_.
479 if (animator_.get()) { 491 if (animator_.get()) {
480 animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM); 492 animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM);
481 animator_->StopAnimatingProperty(LayerAnimationElement::OPACITY); 493 animator_->StopAnimatingProperty(LayerAnimationElement::OPACITY);
482 } 494 }
483 495
484 if (texture_layer_.get()) 496 if (texture_layer_.get())
485 texture_layer_->ClearClient(); 497 texture_layer_->ClearClient();
486 // TODO(piman): delegated_renderer_layer_ cleanup. 498 // TODO(piman): delegated_renderer_layer_ cleanup.
487 499
488 cc_layer_->RemoveAllChildren(); 500 cc_layer_->RemoveAllChildren();
489 if (cc_layer_->parent()) { 501 if (cc_layer_->parent()) {
490 cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer); 502 cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer);
491 } 503 }
492 cc_layer_->SetLayerClient(NULL); 504 cc_layer_->SetLayerClient(NULL);
493 cc_layer_->RemoveLayerAnimationEventObserver(this); 505 if (cc_layer_->layer_animation_controller())
506 cc_layer_->RemoveLayerAnimationEventObserver(this);
494 new_layer->SetOpacity(cc_layer_->opacity()); 507 new_layer->SetOpacity(cc_layer_->opacity());
495 new_layer->SetTransform(cc_layer_->transform()); 508 new_layer->SetTransform(cc_layer_->transform());
496 new_layer->SetPosition(cc_layer_->position()); 509 new_layer->SetPosition(cc_layer_->position());
497 new_layer->SetBackgroundColor(cc_layer_->background_color()); 510 new_layer->SetBackgroundColor(cc_layer_->background_color());
498 511
499 cc_layer_ = new_layer.get(); 512 cc_layer_ = new_layer.get();
500 content_layer_ = NULL; 513 content_layer_ = NULL;
501 solid_color_layer_ = NULL; 514 solid_color_layer_ = NULL;
502 texture_layer_ = NULL; 515 texture_layer_ = NULL;
503 delegated_renderer_layer_ = NULL; 516 delegated_renderer_layer_ = NULL;
504 surface_layer_ = NULL; 517 surface_layer_ = NULL;
505 518
506 cc_layer_->AddLayerAnimationEventObserver(this); 519 if (cc_layer_->layer_animation_controller())
520 cc_layer_->AddLayerAnimationEventObserver(this);
521
507 for (size_t i = 0; i < children_.size(); ++i) { 522 for (size_t i = 0; i < children_.size(); ++i) {
508 DCHECK(children_[i]->cc_layer_); 523 DCHECK(children_[i]->cc_layer_);
509 cc_layer_->AddChild(children_[i]->cc_layer_); 524 cc_layer_->AddChild(children_[i]->cc_layer_);
510 } 525 }
511 cc_layer_->SetLayerClient(this); 526 cc_layer_->SetLayerClient(this);
512 cc_layer_->SetTransformOrigin(gfx::Point3F()); 527 cc_layer_->SetTransformOrigin(gfx::Point3F());
513 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_); 528 cc_layer_->SetContentsOpaque(fills_bounds_opaquely_);
514 cc_layer_->SetForceRenderSurface(force_render_surface_); 529 cc_layer_->SetForceRenderSurface(force_render_surface_);
515 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); 530 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN);
516 cc_layer_->SetHideLayerAndSubtree(!visible_); 531 cc_layer_->SetHideLayerAndSubtree(!visible_);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 HasAnimationId(animation_id)), 1013 HasAnimationId(animation_id)),
999 pending_threaded_animations_.end()); 1014 pending_threaded_animations_.end());
1000 } 1015 }
1001 1016
1002 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() { 1017 LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() {
1003 Compositor* compositor = GetCompositor(); 1018 Compositor* compositor = GetCompositor();
1004 return compositor ? compositor->layer_animator_collection() : NULL; 1019 return compositor ? compositor->layer_animator_collection() : NULL;
1005 } 1020 }
1006 1021
1007 void Layer::SendPendingThreadedAnimations() { 1022 void Layer::SendPendingThreadedAnimations() {
1023 DCHECK(cc_layer_->layer_animation_controller());
piman 2015/04/30 00:40:38 Is this DCHECK valid? SendPendingThreadedAnimation
loyso (OOO) 2015/04/30 01:03:04 SendPendingThreadedAnimations is only called after
loyso (OOO) 2015/04/30 01:04:03 * Remove - I meant duplicate DCHECK.
1024 cc_layer_->AddLayerAnimationEventObserver(this);
piman 2015/04/30 00:40:38 Is this idempotent? SendPendingThreadedAnimations
loyso (OOO) 2015/04/30 01:03:04 Yes, it's idempotent. Apart from SwithToLayer case
loyso (OOO) 2015/05/01 03:46:21 We call SendPendingThreadedAnimations at two place
1025
1008 for (cc::ScopedPtrVector<cc::Animation>::iterator it = 1026 for (cc::ScopedPtrVector<cc::Animation>::iterator it =
1009 pending_threaded_animations_.begin(); 1027 pending_threaded_animations_.begin();
1010 it != pending_threaded_animations_.end(); 1028 it != pending_threaded_animations_.end();
1011 ++it) 1029 ++it)
1012 cc_layer_->AddAnimation(pending_threaded_animations_.take(it)); 1030 cc_layer_->AddAnimation(pending_threaded_animations_.take(it));
1013 1031
1014 pending_threaded_animations_.clear(); 1032 pending_threaded_animations_.clear();
1015 1033
1016 for (size_t i = 0; i < children_.size(); ++i) 1034 for (size_t i = 0; i < children_.size(); ++i)
1017 children_[i]->SendPendingThreadedAnimations(); 1035 children_[i]->SendPendingThreadedAnimations();
1018 } 1036 }
1019 1037
1020 void Layer::CreateCcLayer() { 1038 void Layer::CreateCcLayer() {
1021 if (type_ == LAYER_SOLID_COLOR) { 1039 if (type_ == LAYER_SOLID_COLOR) {
1022 solid_color_layer_ = cc::SolidColorLayer::Create(); 1040 solid_color_layer_ = cc::SolidColorLayer::Create();
1023 cc_layer_ = solid_color_layer_.get(); 1041 cc_layer_ = solid_color_layer_.get();
1024 } else if (type_ == LAYER_NINE_PATCH) { 1042 } else if (type_ == LAYER_NINE_PATCH) {
1025 nine_patch_layer_ = cc::NinePatchLayer::Create(); 1043 nine_patch_layer_ = cc::NinePatchLayer::Create();
1026 cc_layer_ = nine_patch_layer_.get(); 1044 cc_layer_ = nine_patch_layer_.get();
1027 } else { 1045 } else {
1028 if (Layer::UsingPictureLayer()) 1046 if (Layer::UsingPictureLayer())
1029 content_layer_ = cc::PictureLayer::Create(this); 1047 content_layer_ = cc::PictureLayer::Create(this);
1030 else 1048 else
1031 content_layer_ = cc::ContentLayer::Create(this); 1049 content_layer_ = cc::ContentLayer::Create(this);
1032 cc_layer_ = content_layer_.get(); 1050 cc_layer_ = content_layer_.get();
1033 } 1051 }
1034 cc_layer_->SetTransformOrigin(gfx::Point3F()); 1052 cc_layer_->SetTransformOrigin(gfx::Point3F());
1035 cc_layer_->SetContentsOpaque(true); 1053 cc_layer_->SetContentsOpaque(true);
1036 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN); 1054 cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN);
1037 cc_layer_->AddLayerAnimationEventObserver(this);
1038 cc_layer_->SetLayerClient(this); 1055 cc_layer_->SetLayerClient(this);
1039 RecomputePosition(); 1056 RecomputePosition();
1040 } 1057 }
1041 1058
1042 gfx::Transform Layer::transform() const { 1059 gfx::Transform Layer::transform() const {
1043 return cc_layer_->transform(); 1060 return cc_layer_->transform();
1044 } 1061 }
1045 1062
1046 void Layer::RecomputeDrawsContentAndUVRect() { 1063 void Layer::RecomputeDrawsContentAndUVRect() {
1047 DCHECK(cc_layer_); 1064 DCHECK(cc_layer_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 children_.end(), 1102 children_.end(),
1086 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), 1103 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection),
1087 collection)); 1104 collection));
1088 } 1105 }
1089 1106
1090 bool Layer::IsAnimating() const { 1107 bool Layer::IsAnimating() const {
1091 return animator_.get() && animator_->is_animating(); 1108 return animator_.get() && animator_->is_animating();
1092 } 1109 }
1093 1110
1094 } // namespace ui 1111 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer.h ('k') | ui/compositor/layer_animation_element.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698