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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« cc/layers/layer.cc ('K') | « ui/compositor/layer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/layer.cc
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index 34c11e3f7482729acd4225ead015b8a08ecefacd..f413daebba3c9eb73259acd76eb632ac5466b5d8 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -26,6 +26,7 @@
#include "cc/output/filter_operation.h"
#include "cc/output/filter_operations.h"
#include "cc/resources/transferable_resource.h"
+#include "cc/trees/layer_tree_host.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer_animator.h"
@@ -124,7 +125,9 @@ Layer::~Layer() {
layer_mask_back_link_->SetMaskLayer(NULL);
for (size_t i = 0; i < children_.size(); ++i)
children_[i]->parent_ = NULL;
- cc_layer_->RemoveLayerAnimationEventObserver(this);
+
+ DetachObservers();
+
cc_layer_->RemoveFromParent();
}
@@ -142,17 +145,22 @@ float Layer::opacity() const {
}
void Layer::SetCompositor(Compositor* compositor) {
ajuma 2015/04/23 15:09:15 This only gets called on the root layer, and only
loyso (OOO) 2015/04/24 03:44:52 Done.
+ if (compositor)
+ RegisterForAnimations(compositor);
+
// This function must only be called to set the compositor on the root layer,
// or to reset it.
DCHECK(!compositor || !compositor_);
DCHECK(!compositor || compositor->root_layer() == this);
DCHECK(!parent_);
if (compositor_) {
+ DetachObservers();
RemoveAnimatorsInTreeFromCollection(
compositor_->layer_animator_collection());
}
compositor_ = compositor;
if (compositor) {
+ AttachObservers();
OnDeviceScaleFactorChanged(compositor->device_scale_factor());
SendPendingThreadedAnimations();
AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
@@ -167,8 +175,12 @@ void Layer::Add(Layer* child) {
children_.push_back(child);
cc_layer_->AddChild(child->cc_layer_);
child->OnDeviceScaleFactorChanged(device_scale_factor_);
- if (GetCompositor())
+ Compositor* compositor = GetCompositor();
+ if (compositor) {
+ child->RegisterForAnimations(compositor);
ajuma 2015/04/23 15:09:15 The call to cc_layer_->AddChild(child->cc_layer_)
loyso (OOO) 2015/04/24 03:44:52 Done.
+ child->AttachObservers();
child->SendPendingThreadedAnimations();
+ }
LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
if (collection)
child->AddAnimatorsInTreeToCollection(collection);
@@ -184,6 +196,8 @@ void Layer::Remove(Layer* child) {
if (collection)
child->RemoveAnimatorsInTreeFromCollection(collection);
+ child->DetachObservers();
+
std::vector<Layer*>::iterator i =
std::find(children_.begin(), children_.end(), child);
DCHECK(i != children_.end());
@@ -490,7 +504,9 @@ void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
cc_layer_->parent()->ReplaceChild(cc_layer_, new_layer);
}
cc_layer_->SetLayerClient(NULL);
- cc_layer_->RemoveLayerAnimationEventObserver(this);
+
+ DetachObservers();
+
new_layer->SetOpacity(cc_layer_->opacity());
new_layer->SetTransform(cc_layer_->transform());
new_layer->SetPosition(cc_layer_->position());
@@ -503,7 +519,8 @@ void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
delegated_renderer_layer_ = NULL;
surface_layer_ = NULL;
- cc_layer_->AddLayerAnimationEventObserver(this);
+ AttachObservers();
+
for (size_t i = 0; i < children_.size(); ++i) {
DCHECK(children_[i]->cc_layer_);
cc_layer_->AddChild(children_[i]->cc_layer_);
@@ -1041,11 +1058,36 @@ void Layer::CreateCcLayer() {
cc_layer_->SetTransformOrigin(gfx::Point3F());
cc_layer_->SetContentsOpaque(true);
cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN);
- cc_layer_->AddLayerAnimationEventObserver(this);
cc_layer_->SetLayerClient(this);
RecomputePosition();
}
+void Layer::RegisterForAnimations(Compositor* compositor) {
+ DCHECK(compositor);
+ const cc::LayerTreeHost& host = compositor->GetLayerTreeHost();
+
+ cc_layer_->RegisterForAnimations(host.animation_registrar(), host.settings());
+
+ for (size_t i = 0; i < children_.size(); ++i)
+ children_[i]->RegisterForAnimations(compositor);
+}
+
+void Layer::AttachObservers() {
+ if (cc_layer_->layer_animation_controller())
+ cc_layer_->AddLayerAnimationEventObserver(this);
+
+ for (size_t i = 0; i < children_.size(); ++i)
+ children_[i]->AttachObservers();
+}
+
+void Layer::DetachObservers() {
+ if (cc_layer_->layer_animation_controller())
+ cc_layer_->RemoveLayerAnimationEventObserver(this);
+
+ for (size_t i = 0; i < children_.size(); ++i)
+ children_[i]->DetachObservers();
+}
+
gfx::Transform Layer::transform() const {
return cc_layer_->transform();
}
« cc/layers/layer.cc ('K') | « ui/compositor/layer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698