Commit ea328be1 authored by sunnyps's avatar sunnyps Committed by Commit bot

cc: Misc animation refactoring

Make animation code conform to the style guide by using auto where
appropriate, renaming functions named incorrectly, etc. Avoid
accessing layer_animation_controller directly where possible.

Review URL: https://codereview.chromium.org/948243003

Cr-Commit-Position: refs/heads/master@{#318195}
parent 7ec58118
...@@ -256,7 +256,7 @@ void WebLayerImpl::removeAnimation(int animation_id) { ...@@ -256,7 +256,7 @@ void WebLayerImpl::removeAnimation(int animation_id) {
void WebLayerImpl::removeAnimation( void WebLayerImpl::removeAnimation(
int animation_id, int animation_id,
blink::WebCompositorAnimation::TargetProperty target_property) { blink::WebCompositorAnimation::TargetProperty target_property) {
layer_->layer_animation_controller()->RemoveAnimation( layer_->RemoveAnimation(
animation_id, static_cast<Animation::TargetProperty>(target_property)); animation_id, static_cast<Animation::TargetProperty>(target_property));
} }
......
...@@ -1204,6 +1204,12 @@ void Layer::RemoveAnimation(int animation_id) { ...@@ -1204,6 +1204,12 @@ void Layer::RemoveAnimation(int animation_id) {
SetNeedsCommit(); SetNeedsCommit();
} }
void Layer::RemoveAnimation(int animation_id,
Animation::TargetProperty property) {
layer_animation_controller_->RemoveAnimation(animation_id, property);
SetNeedsCommit();
}
void Layer::SetLayerAnimationControllerForTest( void Layer::SetLayerAnimationControllerForTest(
scoped_refptr<LayerAnimationController> controller) { scoped_refptr<LayerAnimationController> controller) {
layer_animation_controller_->RemoveValueObserver(this); layer_animation_controller_->RemoveValueObserver(this);
......
...@@ -410,6 +410,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>, ...@@ -410,6 +410,7 @@ class CC_EXPORT Layer : public base::RefCounted<Layer>,
bool AddAnimation(scoped_ptr<Animation> animation); bool AddAnimation(scoped_ptr<Animation> animation);
void PauseAnimation(int animation_id, double time_offset); void PauseAnimation(int animation_id, double time_offset);
void RemoveAnimation(int animation_id); void RemoveAnimation(int animation_id);
void RemoveAnimation(int animation_id, Animation::TargetProperty property);
LayerAnimationController* layer_animation_controller() { LayerAnimationController* layer_animation_controller() {
return layer_animation_controller_.get(); return layer_animation_controller_.get();
......
...@@ -83,7 +83,7 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, ...@@ -83,7 +83,7 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl,
DCHECK_GT(layer_id_, 0); DCHECK_GT(layer_id_, 0);
DCHECK(layer_tree_impl_); DCHECK(layer_tree_impl_);
layer_tree_impl_->RegisterLayer(this); layer_tree_impl_->RegisterLayer(this);
AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar(); AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar();
layer_animation_controller_ = layer_animation_controller_ =
registrar->GetAnimationControllerForId(layer_id_); registrar->GetAnimationControllerForId(layer_id_);
layer_animation_controller_->AddValueObserver(this); layer_animation_controller_->AddValueObserver(this);
......
...@@ -349,10 +349,9 @@ class LayerTreeHostImplForTesting : public LayerTreeHostImpl { ...@@ -349,10 +349,9 @@ class LayerTreeHostImplForTesting : public LayerTreeHostImpl {
void UpdateAnimationState(bool start_ready_animations) override { void UpdateAnimationState(bool start_ready_animations) override {
LayerTreeHostImpl::UpdateAnimationState(start_ready_animations); LayerTreeHostImpl::UpdateAnimationState(start_ready_animations);
bool has_unfinished_animation = false; bool has_unfinished_animation = false;
AnimationRegistrar::AnimationControllerMap::const_iterator iter = for (const auto& it :
active_animation_controllers().begin(); animation_registrar()->active_animation_controllers()) {
for (; iter != active_animation_controllers().end(); ++iter) { if (it.second->HasActiveAnimation()) {
if (iter->second->HasActiveAnimation()) {
has_unfinished_animation = true; has_unfinished_animation = true;
break; break;
} }
......
...@@ -558,8 +558,7 @@ void LayerTreeHost::SetAnimationEvents( ...@@ -558,8 +558,7 @@ void LayerTreeHost::SetAnimationEvents(
// controllers may still receive events for impl-only animations. // controllers may still receive events for impl-only animations.
const AnimationRegistrar::AnimationControllerMap& animation_controllers = const AnimationRegistrar::AnimationControllerMap& animation_controllers =
animation_registrar_->all_animation_controllers(); animation_registrar_->all_animation_controllers();
AnimationRegistrar::AnimationControllerMap::const_iterator iter = auto iter = animation_controllers.find(event_layer_id);
animation_controllers.find(event_layer_id);
if (iter != animation_controllers.end()) { if (iter != animation_controllers.end()) {
switch ((*events)[event_index].type) { switch ((*events)[event_index].type) {
case AnimationEvent::STARTED: case AnimationEvent::STARTED:
...@@ -1194,14 +1193,12 @@ void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) { ...@@ -1194,14 +1193,12 @@ void LayerTreeHost::AnimateLayers(base::TimeTicks monotonic_time) {
TRACE_EVENT0("cc", "LayerTreeHost::AnimateLayers"); TRACE_EVENT0("cc", "LayerTreeHost::AnimateLayers");
AnimationRegistrar::AnimationControllerMap copy = AnimationRegistrar::AnimationControllerMap active_controllers_copy =
animation_registrar_->active_animation_controllers(); animation_registrar_->active_animation_controllers();
for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); for (auto& it : active_controllers_copy) {
iter != copy.end(); it.second->Animate(monotonic_time);
++iter) {
(*iter).second->Animate(monotonic_time);
bool start_ready_animations = true; bool start_ready_animations = true;
(*iter).second->UpdateState(start_ready_animations, NULL); it.second->UpdateState(start_ready_animations, NULL);
} }
} }
......
...@@ -3134,31 +3134,26 @@ void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { ...@@ -3134,31 +3134,26 @@ void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) {
return; return;
TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers");
AnimationRegistrar::AnimationControllerMap copy = AnimationRegistrar::AnimationControllerMap controllers_copy =
animation_registrar_->active_animation_controllers(); animation_registrar_->active_animation_controllers();
for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); for (auto& it : controllers_copy)
iter != copy.end(); it.second->Animate(monotonic_time);
++iter)
(*iter).second->Animate(monotonic_time);
SetNeedsAnimate(); SetNeedsAnimate();
} }
void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) {
if (!settings_.accelerated_animation_enabled || if (!settings_.accelerated_animation_enabled || !needs_animate_layers() ||
!needs_animate_layers() ||
!active_tree_->root_layer()) !active_tree_->root_layer())
return; return;
TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState"); TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState");
scoped_ptr<AnimationEventsVector> events = scoped_ptr<AnimationEventsVector> events =
make_scoped_ptr(new AnimationEventsVector); make_scoped_ptr(new AnimationEventsVector);
AnimationRegistrar::AnimationControllerMap copy = AnimationRegistrar::AnimationControllerMap active_controllers_copy =
animation_registrar_->active_animation_controllers(); animation_registrar_->active_animation_controllers();
for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); for (auto& it : active_controllers_copy)
iter != copy.end(); it.second->UpdateState(start_ready_animations, events.get());
++iter)
(*iter).second->UpdateState(start_ready_animations, events.get());
if (!events->empty()) { if (!events->empty()) {
client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass());
...@@ -3173,12 +3168,10 @@ void LayerTreeHostImpl::ActivateAnimations() { ...@@ -3173,12 +3168,10 @@ void LayerTreeHostImpl::ActivateAnimations() {
return; return;
TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations"); TRACE_EVENT0("cc", "LayerTreeHostImpl::ActivateAnimations");
AnimationRegistrar::AnimationControllerMap copy = AnimationRegistrar::AnimationControllerMap active_controllers_copy =
animation_registrar_->active_animation_controllers(); animation_registrar_->active_animation_controllers();
for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); for (auto& it : active_controllers_copy)
iter != copy.end(); it.second->ActivateAnimations();
++iter)
(*iter).second->ActivateAnimations();
SetNeedsAnimate(); SetNeedsAnimate();
} }
......
...@@ -535,10 +535,6 @@ class CC_EXPORT LayerTreeHostImpl ...@@ -535,10 +535,6 @@ class CC_EXPORT LayerTreeHostImpl
// Virtual for testing. // Virtual for testing.
virtual void AnimateLayers(base::TimeTicks monotonic_time); virtual void AnimateLayers(base::TimeTicks monotonic_time);
const AnimationRegistrar::AnimationControllerMap&
active_animation_controllers() const {
return animation_registrar_->active_animation_controllers();
}
LayerTreeHostImplClient* client_; LayerTreeHostImplClient* client_;
Proxy* proxy_; Proxy* proxy_;
......
...@@ -195,8 +195,9 @@ class LayerTreeHostAnimationTestAnimationsGetDeleted ...@@ -195,8 +195,9 @@ class LayerTreeHostAnimationTestAnimationsGetDeleted
void AnimateLayers(LayerTreeHostImpl* host_impl, void AnimateLayers(LayerTreeHostImpl* host_impl,
base::TimeTicks monotonic_time) override { base::TimeTicks monotonic_time) override {
bool have_animations = !host_impl->animation_registrar()-> bool have_animations = !host_impl->animation_registrar()
active_animation_controllers().empty(); ->active_animation_controllers()
.empty();
if (!started_animating_ && have_animations) { if (!started_animating_ && have_animations) {
started_animating_ = true; started_animating_ = true;
return; return;
...@@ -1241,21 +1242,18 @@ class LayerTreeHostAnimationTestAddAnimationAfterAnimating ...@@ -1241,21 +1242,18 @@ class LayerTreeHostAnimationTestAddAnimationAfterAnimating
// After both animations have started, verify that they have valid // After both animations have started, verify that they have valid
// start times. // start times.
num_swap_buffers_++; num_swap_buffers_++;
AnimationRegistrar::AnimationControllerMap copy = AnimationRegistrar::AnimationControllerMap controllers_copy =
host_impl->animation_registrar()->active_animation_controllers(); host_impl->animation_registrar()->active_animation_controllers();
if (copy.size() == 2u) { if (controllers_copy.size() == 2u) {
EndTest(); EndTest();
EXPECT_GE(num_swap_buffers_, 3); EXPECT_GE(num_swap_buffers_, 3);
for (AnimationRegistrar::AnimationControllerMap::iterator iter = for (auto& it : controllers_copy) {
copy.begin(); int id = it.first;
iter != copy.end();
++iter) {
int id = ((*iter).second->id());
if (id == host_impl->RootLayer()->id()) { if (id == host_impl->RootLayer()->id()) {
Animation* anim = (*iter).second->GetAnimation(Animation::TRANSFORM); Animation* anim = it.second->GetAnimation(Animation::TRANSFORM);
EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0);
} else if (id == host_impl->RootLayer()->children()[0]->id()) { } else if (id == host_impl->RootLayer()->children()[0]->id()) {
Animation* anim = (*iter).second->GetAnimation(Animation::OPACITY); Animation* anim = it.second->GetAnimation(Animation::OPACITY);
EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0);
} }
} }
......
...@@ -984,7 +984,7 @@ void LayerTreeImpl::SetNeedsRedraw() { ...@@ -984,7 +984,7 @@ void LayerTreeImpl::SetNeedsRedraw() {
layer_tree_host_impl_->SetNeedsRedraw(); layer_tree_host_impl_->SetNeedsRedraw();
} }
AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { AnimationRegistrar* LayerTreeImpl::GetAnimationRegistrar() const {
return layer_tree_host_impl_->animation_registrar(); return layer_tree_host_impl_->animation_registrar();
} }
......
...@@ -239,7 +239,7 @@ class CC_EXPORT LayerTreeImpl { ...@@ -239,7 +239,7 @@ class CC_EXPORT LayerTreeImpl {
size_t NumLayers(); size_t NumLayers();
AnimationRegistrar* animationRegistrar() const; AnimationRegistrar* GetAnimationRegistrar() const;
void PushPersistedState(LayerTreeImpl* pending_tree); void PushPersistedState(LayerTreeImpl* pending_tree);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment