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

Unified Diff: ui/compositor/layer.cc

Issue 1012583002: CC Animations: Port UI Browser Compositor to use compositor animation timelines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@redirect
Patch Set: Rebase. Created 5 years 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
« no previous file with comments | « 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 2ec6de99e156908a3a4d37dfa00ef353a7c4f2f9..1e81fc0f6297b691dd532bdfc715a75e18190b3e 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -13,6 +13,10 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/trace_event/trace_event.h"
+#include "cc/animation/animation_id_provider.h"
+#include "cc/animation/animation_player.h"
+#include "cc/animation/animation_timeline.h"
+#include "cc/animation/element_animations.h"
#include "cc/layers/delegated_renderer_layer.h"
#include "cc/layers/layer_settings.h"
#include "cc/layers/nine_patch_layer.h"
@@ -26,6 +30,7 @@
#include "cc/output/filter_operations.h"
#include "cc/playback/display_item_list_settings.h"
#include "cc/resources/transferable_resource.h"
+#include "cc/trees/layer_tree_host.h"
#include "cc/trees/layer_tree_settings.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/compositor/dip_util.h"
@@ -120,7 +125,11 @@ Layer::~Layer() {
for (size_t i = 0; i < children_.size(); ++i)
children_[i]->parent_ = NULL;
- cc_layer_->RemoveLayerAnimationEventObserver(this);
+ if (animation_player_)
+ DetachPlayerLayer();
+ else
+ cc_layer_->RemoveLayerAnimationEventObserver(this);
+
cc_layer_->RemoveFromParent();
}
@@ -158,14 +167,19 @@ void Layer::SetCompositor(Compositor* compositor,
AddAnimatorsInTreeToCollection(compositor_->layer_animator_collection());
root_layer->AddChild(cc_layer_);
+ AttachAnimationPlayers(compositor->GetAnimationTimeline());
+ AttachPlayerLayer();
SendPendingThreadedAnimations();
}
void Layer::ResetCompositor() {
DCHECK(!parent_);
- if (compositor_)
+ if (compositor_) {
+ DetachPlayerLayer();
+ DetachAnimationPlayers(compositor_->GetAnimationTimeline());
RemoveAnimatorsInTreeFromCollection(
compositor_->layer_animator_collection());
+ }
compositor_ = nullptr;
}
@@ -177,8 +191,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->AttachAnimationPlayers(compositor->GetAnimationTimeline());
+ child->AttachPlayerLayer();
child->SendPendingThreadedAnimations();
+ }
LayerAnimatorCollection* collection = GetLayerAnimatorCollection();
if (collection)
child->AddAnimatorsInTreeToCollection(collection);
@@ -194,6 +212,11 @@ void Layer::Remove(Layer* child) {
if (collection)
child->RemoveAnimatorsInTreeFromCollection(collection);
+ child->DetachPlayerLayer();
+ Compositor* compositor = GetCompositor();
+ if (compositor)
+ child->DetachAnimationPlayers(compositor->GetAnimationTimeline());
+
std::vector<Layer*>::iterator i =
std::find(children_.begin(), children_.end(), child);
DCHECK(i != children_.end());
@@ -499,7 +522,12 @@ 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);
+
+ if (animation_player_)
+ DetachPlayerLayer();
+ else
+ cc_layer_->RemoveLayerAnimationEventObserver(this);
+
new_layer->SetOpacity(cc_layer_->opacity());
new_layer->SetTransform(cc_layer_->transform());
new_layer->SetPosition(cc_layer_->position());
@@ -512,7 +540,11 @@ void Layer::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) {
delegated_renderer_layer_ = NULL;
surface_layer_ = NULL;
- cc_layer_->AddLayerAnimationEventObserver(this);
+ if (animation_player_)
+ AttachPlayerLayer();
+ else
+ cc_layer_->AddLayerAnimationEventObserver(this);
+
for (size_t i = 0; i < children_.size(); ++i) {
DCHECK(children_[i]->cc_layer_);
cc_layer_->AddChild(children_[i]->cc_layer_);
@@ -981,16 +1013,19 @@ void Layer::AddThreadedAnimation(scoped_ptr<cc::Animation> animation) {
DCHECK(cc_layer_);
// Until this layer has a compositor (and hence cc_layer_ has a
// LayerTreeHost), addAnimation will fail.
- if (GetCompositor())
- cc_layer_->AddAnimation(animation.Pass());
- else
+ if (GetCompositor()) {
+ animation_player_ ? animation_player_->AddAnimation(animation.Pass())
+ : (void)cc_layer_->AddAnimation(animation.Pass());
+ } else {
pending_threaded_animations_.push_back(animation.Pass());
+ }
}
void Layer::RemoveThreadedAnimation(int animation_id) {
DCHECK(cc_layer_);
if (pending_threaded_animations_.size() == 0) {
- cc_layer_->RemoveAnimation(animation_id);
+ animation_player_ ? animation_player_->RemoveAnimation(animation_id)
+ : cc_layer_->RemoveAnimation(animation_id);
return;
}
@@ -1010,8 +1045,11 @@ LayerAnimatorCollection* Layer::GetLayerAnimatorCollection() {
}
void Layer::SendPendingThreadedAnimations() {
- for (auto& animation : pending_threaded_animations_)
- cc_layer_->AddAnimation(std::move(animation));
+ for (auto& animation : pending_threaded_animations_) {
+ animation_player_
+ ? animation_player_->AddAnimation(std::move(animation))
+ : (void)cc_layer_->AddAnimation(std::move(animation));
+ }
pending_threaded_animations_.clear();
for (auto* child : children_)
@@ -1032,11 +1070,64 @@ void Layer::CreateCcLayer() {
cc_layer_->SetTransformOrigin(gfx::Point3F());
cc_layer_->SetContentsOpaque(true);
cc_layer_->SetIsDrawable(type_ != LAYER_NOT_DRAWN);
- cc_layer_->AddLayerAnimationEventObserver(this);
+ if (UILayerSettings().use_compositor_animation_timelines)
+ animation_player_ =
+ cc::AnimationPlayer::Create(cc::AnimationIdProvider::NextPlayerId());
+ else
+ cc_layer_->AddLayerAnimationEventObserver(this);
cc_layer_->SetLayerClient(this);
RecomputePosition();
}
+void Layer::AttachPlayerLayer() {
+ DCHECK(cc_layer_);
+
+ if (animation_player_) {
+ animation_player_->AttachLayer(cc_layer_->id());
+ DCHECK(animation_player_->element_animations());
+ animation_player_->element_animations()
+ ->layer_animation_controller()
+ ->AddEventObserver(this);
+ }
+
+ for (size_t i = 0; i < children_.size(); ++i)
+ children_[i]->AttachPlayerLayer();
+}
+
+void Layer::DetachPlayerLayer() {
+ if (animation_player_) {
+ if (animation_player_->element_animations()) {
+ animation_player_->element_animations()
+ ->layer_animation_controller()
+ ->RemoveEventObserver(this);
+ animation_player_->DetachLayer();
+ }
+ }
+
+ for (size_t i = 0; i < children_.size(); ++i)
+ children_[i]->DetachPlayerLayer();
+}
+
+void Layer::AttachAnimationPlayers(cc::AnimationTimeline* timeline) {
+ if (!timeline)
+ return;
+
+ if (animation_player_)
+ timeline->AttachPlayer(animation_player_);
+ for (size_t i = 0; i < children_.size(); ++i)
+ children_[i]->AttachAnimationPlayers(timeline);
+}
+
+void Layer::DetachAnimationPlayers(cc::AnimationTimeline* timeline) {
+ if (!timeline)
+ return;
+
+ if (animation_player_)
+ timeline->DetachPlayer(animation_player_);
+ for (size_t i = 0; i < children_.size(); ++i)
+ children_[i]->DetachAnimationPlayers(timeline);
+}
+
gfx::Transform Layer::transform() const {
return cc_layer_->transform();
}
« no previous file with comments | « ui/compositor/layer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698