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

Unified Diff: cc/animation/layer_animation_controller.cc

Issue 13465014: LayerTreeHost::SetAnimationEvents should use AnimationRegistrar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
Index: cc/animation/layer_animation_controller.cc
diff --git a/cc/animation/layer_animation_controller.cc b/cc/animation/layer_animation_controller.cc
index a213ba7f76bfaa67350b69fb5a7fd41c7049e63f..53d799c0bfa9ee18d1eda689cb82700de2341140 100644
--- a/cc/animation/layer_animation_controller.cc
+++ b/cc/animation/layer_animation_controller.cc
@@ -11,6 +11,7 @@
#include "cc/animation/keyframed_animation_curve.h"
#include "cc/animation/layer_animation_value_observer.h"
#include "cc/base/scoped_ptr_algorithm.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebAnimationDelegate.h"
#include "ui/gfx/transform.h"
namespace cc {
@@ -20,7 +21,8 @@ LayerAnimationController::LayerAnimationController(int id)
registrar_(0),
id_(id),
is_active_(false),
- last_tick_time_(0) {}
+ last_tick_time_(0),
+ layer_animation_delegate_(NULL) {}
LayerAnimationController::~LayerAnimationController() {
if (registrar_)
@@ -109,6 +111,7 @@ void LayerAnimationController::ResumeAnimations(double monotonic_time) {
// thread are kept in sync.
void LayerAnimationController::PushAnimationUpdatesTo(
LayerAnimationController* controller_impl) {
+ DCHECK(this != controller_impl);
if (force_sync_) {
ReplaceImplThreadAnimations(controller_impl);
force_sync_ = false;
@@ -127,6 +130,16 @@ void LayerAnimationController::PushAnimationUpdatesTo(
UpdateActivation(NormalActivation);
}
+void LayerAnimationController::TransferAnimationsTo(
+ LayerAnimationController* other_controller) {
+ other_controller->active_animations_.clear();
+ active_animations_.swap(other_controller->active_animations_);
+ UpdateActivation(NormalActivation);
+ set_force_sync();
Ian Vollick 2013/04/04 18:38:58 other_controller->UpdateActivation(NormalActivatio
ajuma 2013/04/05 14:38:18 Done.
+ other_controller->set_force_sync();
+ other_controller->SetAnimationRegistrar(registrar_);
+}
+
void LayerAnimationController::Animate(double monotonic_time) {
if (!HasActiveObserver())
return;
@@ -225,27 +238,13 @@ bool LayerAnimationController::HasActiveAnimation() const {
bool LayerAnimationController::IsAnimatingProperty(
Animation::TargetProperty target_property) const {
for (size_t i = 0; i < active_animations_.size(); ++i) {
- if (active_animations_[i]->run_state() != Animation::Finished &&
- active_animations_[i]->run_state() != Animation::Aborted &&
+ if (!active_animations_[i]->is_finished() &&
active_animations_[i]->target_property() == target_property)
return true;
}
return false;
}
-void LayerAnimationController::OnAnimationStarted(
- const AnimationEvent& event) {
- for (size_t i = 0; i < active_animations_.size(); ++i) {
- if (active_animations_[i]->group() == event.group_id &&
- active_animations_[i]->target_property() == event.target_property &&
- active_animations_[i]->needs_synchronized_start_time()) {
- active_animations_[i]->set_needs_synchronized_start_time(false);
- active_animations_[i]->set_start_time(event.monotonic_time);
- return;
- }
- }
-}
-
void LayerAnimationController::SetAnimationRegistrar(
AnimationRegistrar* registrar) {
if (registrar_ == registrar)
@@ -261,15 +260,75 @@ void LayerAnimationController::SetAnimationRegistrar(
UpdateActivation(ForceActivation);
}
-void LayerAnimationController::AddObserver(
+void LayerAnimationController::NotifyAnimationStarted(
+ const AnimationEvent& event,
+ double wall_clock_time) {
+ for (size_t i = 0; i < active_animations_.size(); ++i) {
+ if (active_animations_[i]->group() == event.group_id &&
+ active_animations_[i]->target_property() == event.target_property &&
+ active_animations_[i]->needs_synchronized_start_time()) {
+ active_animations_[i]->set_needs_synchronized_start_time(false);
+ active_animations_[i]->set_start_time(event.monotonic_time);
+
+ FOR_EACH_OBSERVER(LayerAnimationEventObserver, event_observers_,
+ OnAnimationStarted(event));
+ if (layer_animation_delegate_)
+ layer_animation_delegate_->notifyAnimationStarted(wall_clock_time);
+
+ return;
+ }
+ }
+}
+
+void LayerAnimationController::NotifyAnimationFinished(
+ const AnimationEvent& event,
+ double wall_clock_time) {
+ for (size_t i = 0; i < active_animations_.size(); ++i) {
+ if (active_animations_[i]->group() == event.group_id &&
+ active_animations_[i]->target_property() == event.target_property) {
+ active_animations_[i]->set_received_finished_event(true);
+ if (layer_animation_delegate_)
+ layer_animation_delegate_->notifyAnimationFinished(wall_clock_time);
+
+ return;
+ }
+ }
+}
+
+void LayerAnimationController::NotifyAnimationPropertyUpdate(
+ const AnimationEvent& event) {
+ switch (event.target_property) {
+ case Animation::Opacity:
+ NotifyObserversOpacityAnimated(event.opacity);
+ break;
+ case Animation::Transform:
+ NotifyObserversTransformAnimated(event.transform);
+ break;
+ default:
+ NOTREACHED();
+ }
+}
+
+void LayerAnimationController::AddValueObserver(
LayerAnimationValueObserver* observer) {
- if (!observers_.HasObserver(observer))
- observers_.AddObserver(observer);
+ if (!value_observers_.HasObserver(observer))
+ value_observers_.AddObserver(observer);
}
-void LayerAnimationController::RemoveObserver(
+void LayerAnimationController::RemoveValueObserver(
LayerAnimationValueObserver* observer) {
- observers_.RemoveObserver(observer);
+ value_observers_.RemoveObserver(observer);
+}
+
+void LayerAnimationController::AddEventObserver(
+ LayerAnimationEventObserver* observer) {
+ if (!event_observers_.HasObserver(observer))
+ event_observers_.AddObserver(observer);
+}
+
+void LayerAnimationController::RemoveEventObserver(
+ LayerAnimationEventObserver* observer) {
+ event_observers_.RemoveObserver(observer);
}
void LayerAnimationController::PushNewAnimationsToImplThread(
@@ -307,10 +366,13 @@ struct IsCompleted {
explicit IsCompleted(const LayerAnimationController& main_thread_controller)
: main_thread_controller_(main_thread_controller) {}
bool operator()(Animation* animation) const {
- if (animation->is_impl_only())
- return false;
- return !main_thread_controller_.GetAnimation(animation->group(),
- animation->target_property());
+ if (animation->is_impl_only()) {
Ian Vollick 2013/04/04 18:38:58 nit: no braces.
ajuma 2013/04/05 14:38:18 Since the 'else' requires braces, so does the 'if'
+ return (animation->run_state() == Animation::WaitingForDeletion);
+ } else {
+ return !main_thread_controller_.GetAnimation(
+ animation->group(),
+ animation->target_property());
+ }
}
private:
@@ -367,8 +429,7 @@ void LayerAnimationController::StartAnimationsWaitingForTargetAvailability(
TargetProperties blocked_properties;
for (size_t i = 0; i < active_animations_.size(); ++i) {
if (active_animations_[i]->run_state() == Animation::Starting ||
- active_animations_[i]->run_state() == Animation::Running ||
- active_animations_[i]->run_state() == Animation::Finished)
+ active_animations_[i]->run_state() == Animation::Running)
blocked_properties.insert(active_animations_[i]->target_property());
}
@@ -435,7 +496,8 @@ void LayerAnimationController::PromoteStartedAnimations(
void LayerAnimationController::MarkFinishedAnimations(double monotonic_time) {
for (size_t i = 0; i < active_animations_.size(); ++i) {
- if (active_animations_[i]->IsFinishedAt(monotonic_time))
+ if (active_animations_[i]->IsFinishedAt(monotonic_time) &&
+ active_animations_[i]->run_state() != Animation::WaitingForDeletion)
active_animations_[i]->SetRunState(Animation::Finished, monotonic_time);
}
}
@@ -470,17 +532,25 @@ void LayerAnimationController::ResolveConflicts(double monotonic_time) {
void LayerAnimationController::MarkAnimationsForDeletion(
double monotonic_time, AnimationEventsVector* events) {
+ // Non-aborted animations are marked for deletion after a corresponding
+ // AnimationEvent::Finished event is sent or received. This means that if
+ // we don't have an events vector, we must ensure that non-aborted animations
+ // have received a finished event before marking them for deletion.
for (size_t i = 0; i < active_animations_.size(); i++) {
int group_id = active_animations_[i]->group();
bool all_anims_with_same_id_are_finished = false;
// If an animation is finished, and not already marked for deletion,
- // Find out if all other animations in the same group are also finished.
- if (active_animations_[i]->is_finished() &&
- active_animations_[i]->run_state() != Animation::WaitingForDeletion) {
+ // find out if all other animations in the same group are also finished.
+ if (active_animations_[i]->run_state() == Animation::Aborted ||
+ (active_animations_[i]->run_state() == Animation::Finished &&
+ (events || active_animations_[i]->received_finished_event()))) {
Ian Vollick 2013/04/04 18:38:58 Please put (events || active_animations_[i]->recei
ajuma 2013/04/05 14:38:18 Done.
all_anims_with_same_id_are_finished = true;
for (size_t j = 0; j < active_animations_.size(); ++j) {
if (group_id == active_animations_[j]->group() &&
- !active_animations_[j]->is_finished()) {
+ (!active_animations_[j]->is_finished() ||
+ (active_animations_[j]->run_state() == Animation::Finished &&
+ !events &&
+ !active_animations_[j]->received_finished_event()))) {
Ian Vollick 2013/04/04 18:38:58 Same thing here (these complicated conditions are
ajuma 2013/04/05 14:38:18 Done.
all_anims_with_same_id_are_finished = false;
break;
}
@@ -601,20 +671,21 @@ void LayerAnimationController::UpdateActivation(UpdateActivationType type) {
void LayerAnimationController::NotifyObserversOpacityAnimated(float opacity) {
FOR_EACH_OBSERVER(LayerAnimationValueObserver,
- observers_,
+ value_observers_,
OnOpacityAnimated(opacity));
}
void LayerAnimationController::NotifyObserversTransformAnimated(
const gfx::Transform& transform) {
FOR_EACH_OBSERVER(LayerAnimationValueObserver,
- observers_,
+ value_observers_,
OnTransformAnimated(transform));
}
bool LayerAnimationController::HasActiveObserver() {
Ian Vollick 2013/04/04 18:38:58 HasActiveValueObserver
ajuma 2013/04/05 14:38:18 Done.
- if (observers_.might_have_observers()) {
- ObserverListBase<LayerAnimationValueObserver>::Iterator it(observers_);
+ if (value_observers_.might_have_observers()) {
+ ObserverListBase<LayerAnimationValueObserver>::Iterator it(
+ value_observers_);
LayerAnimationValueObserver* obs;
while ((obs = it.GetNext()) != NULL)
if (obs->IsActive())

Powered by Google App Engine
This is Rietveld 408576698