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

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: Use per-process global variable to create LAC 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
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 cc_layer_->RemoveLayerAnimationEventObserver(this);
128
128 cc_layer_->RemoveFromParent(); 129 cc_layer_->RemoveFromParent();
129 } 130 }
130 131
131 // static 132 // static
132 bool Layer::UsingPictureLayer() { 133 bool Layer::UsingPictureLayer() {
133 return g_ui_impl_side_painting_status.Get().enabled; 134 return g_ui_impl_side_painting_status.Get().enabled;
134 } 135 }
135 136
136 const Compositor* Layer::GetCompositor() const { 137 const Compositor* Layer::GetCompositor() const {
137 return GetRoot(this)->compositor_; 138 return GetRoot(this)->compositor_;
138 } 139 }
139 140
140 float Layer::opacity() const { 141 float Layer::opacity() const {
141 return cc_layer_->opacity(); 142 return cc_layer_->opacity();
142 } 143 }
143 144
144 void Layer::SetCompositor(Compositor* compositor) { 145 void Layer::SetCompositor(Compositor* compositor,
145 // This function must only be called to set the compositor on the root layer, 146 scoped_refptr<cc::Layer> root_layer) {
146 // or to reset it. 147 // This function must only be called to set the compositor on the root ui
147 DCHECK(!compositor || !compositor_); 148 // layer.
148 DCHECK(!compositor || compositor->root_layer() == this); 149 DCHECK(compositor);
150 DCHECK(!compositor_);
151 DCHECK(compositor->root_layer() == this);
149 DCHECK(!parent_); 152 DCHECK(!parent_);
150 if (compositor_) { 153
154 compositor_ = compositor;
155 OnDeviceScaleFactorChanged(compositor->device_scale_factor());
156 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
157
158 root_layer->AddChild(cc_layer_);
159 SendPendingThreadedAnimations();
160 }
161
162 void Layer::ResetCompositor() {
163 DCHECK(!parent_);
164 if (compositor_)
151 RemoveAnimatorsInTreeFromCollection( 165 RemoveAnimatorsInTreeFromCollection(
152 compositor_->layer_animator_collection()); 166 compositor_->layer_animator_collection());
153 } 167 compositor_ = nullptr;
154 compositor_ = compositor;
155 if (compositor) {
156 OnDeviceScaleFactorChanged(compositor->device_scale_factor());
157 SendPendingThreadedAnimations();
158 AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
159 }
160 } 168 }
161 169
162 void Layer::Add(Layer* child) { 170 void Layer::Add(Layer* child) {
163 DCHECK(!child->compositor_); 171 DCHECK(!child->compositor_);
164 if (child->parent_) 172 if (child->parent_)
165 child->parent_->Remove(child); 173 child->parent_->Remove(child);
166 child->parent_ = this; 174 child->parent_ = this;
167 children_.push_back(child); 175 children_.push_back(child);
168 cc_layer_->AddChild(child->cc_layer_); 176 cc_layer_->AddChild(child->cc_layer_);
169 child->OnDeviceScaleFactorChanged(device_scale_factor_); 177 child->OnDeviceScaleFactorChanged(device_scale_factor_);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 layer_mask->children().empty() && 338 layer_mask->children().empty() &&
331 !layer_mask->layer_mask_back_link_)); 339 !layer_mask->layer_mask_back_link_));
332 DCHECK(!layer_mask_back_link_); 340 DCHECK(!layer_mask_back_link_);
333 if (layer_mask_ == layer_mask) 341 if (layer_mask_ == layer_mask)
334 return; 342 return;
335 // We need to de-reference the currently linked object so that no problem 343 // We need to de-reference the currently linked object so that no problem
336 // arises if the mask layer gets deleted before this object. 344 // arises if the mask layer gets deleted before this object.
337 if (layer_mask_) 345 if (layer_mask_)
338 layer_mask_->layer_mask_back_link_ = NULL; 346 layer_mask_->layer_mask_back_link_ = NULL;
339 layer_mask_ = layer_mask; 347 layer_mask_ = layer_mask;
340 cc_layer_->SetMaskLayer( 348 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 349 // We need to reference the linked object so that it can properly break the
343 // link to us when it gets deleted. 350 // link to us when it gets deleted.
344 if (layer_mask) { 351 if (layer_mask) {
345 layer_mask->layer_mask_back_link_ = this; 352 layer_mask->layer_mask_back_link_ = this;
346 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_); 353 layer_mask->OnDeviceScaleFactorChanged(device_scale_factor_);
347 } 354 }
348 } 355 }
349 356
350 void Layer::SetBackgroundZoom(float zoom, int inset) { 357 void Layer::SetBackgroundZoom(float zoom, int inset) {
351 zoom_ = zoom; 358 zoom_ = zoom;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 fills_bounds_opaquely_ = fills_bounds_opaquely; 475 fills_bounds_opaquely_ = fills_bounds_opaquely;
469 476
470 cc_layer_->SetContentsOpaque(fills_bounds_opaquely); 477 cc_layer_->SetContentsOpaque(fills_bounds_opaquely);
471 } 478 }
472 479
473 void Layer::SetFillsBoundsCompletely(bool fills_bounds_completely) { 480 void Layer::SetFillsBoundsCompletely(bool fills_bounds_completely) {
474 fills_bounds_completely_ = fills_bounds_completely; 481 fills_bounds_completely_ = fills_bounds_completely;
475 } 482 }
476 483
477 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { 484 void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
485 DCHECK(!new_layer->parent());
486
478 // Finish animations being handled by cc_layer_. 487 // Finish animations being handled by cc_layer_.
479 if (animator_.get()) { 488 if (animator_.get()) {
480 animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM); 489 animator_->StopAnimatingProperty(LayerAnimationElement::TRANSFORM);
481 animator_->StopAnimatingProperty(LayerAnimationElement::OPACITY); 490 animator_->StopAnimatingProperty(LayerAnimationElement::OPACITY);
482 } 491 }
483 492
484 if (texture_layer_.get()) 493 if (texture_layer_.get())
485 texture_layer_->ClearClient(); 494 texture_layer_->ClearClient();
486 // TODO(piman): delegated_renderer_layer_ cleanup. 495 // TODO(piman): delegated_renderer_layer_ cleanup.
487 496
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 children_.end(), 1094 children_.end(),
1086 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection), 1095 std::bind2nd(std::mem_fun(&Layer::RemoveAnimatorsInTreeFromCollection),
1087 collection)); 1096 collection));
1088 } 1097 }
1089 1098
1090 bool Layer::IsAnimating() const { 1099 bool Layer::IsAnimating() const {
1091 return animator_.get() && animator_->is_animating(); 1100 return animator_.get() && animator_->is_animating();
1092 } 1101 }
1093 1102
1094 } // namespace ui 1103 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698