Chromium Code Reviews| Index: cc/layer_animation_controller.cc |
| diff --git a/cc/layer_animation_controller.cc b/cc/layer_animation_controller.cc |
| index 805f8fc264d5fbf7fae71609a0a77241a662caeb..4aaf05c7d4c774c63861b8e9bf5da0f89d29ea1e 100644 |
| --- a/cc/layer_animation_controller.cc |
| +++ b/cc/layer_animation_controller.cc |
| @@ -5,24 +5,28 @@ |
| #include "cc/layer_animation_controller.h" |
| #include "cc/active_animation.h" |
| +#include "cc/animation_registrar.h" |
| #include "cc/keyframed_animation_curve.h" |
| #include "ui/gfx/transform.h" |
| namespace cc { |
| -LayerAnimationController::LayerAnimationController(LayerAnimationControllerClient* client) |
| +LayerAnimationController::LayerAnimationController() |
| : m_forceSync(false) |
| - , m_client(client) |
| + , m_id(-1) |
| + , m_registrar(0) |
| { |
| } |
| LayerAnimationController::~LayerAnimationController() |
| { |
| + if (m_registrar) |
| + m_registrar->Unregister(this); |
| } |
| -scoped_ptr<LayerAnimationController> LayerAnimationController::create(LayerAnimationControllerClient* client) |
| +scoped_refptr<LayerAnimationController> LayerAnimationController::create() |
| { |
| - return make_scoped_ptr(new LayerAnimationController(client)); |
| + return make_scoped_refptr(new LayerAnimationController()); |
| } |
| void LayerAnimationController::pauseAnimation(int animationId, double timeOffset) |
| @@ -41,6 +45,7 @@ void LayerAnimationController::removeAnimation(int animationId) |
| else |
| i++; |
| } |
| + updateRegistration(); |
| } |
| void LayerAnimationController::removeAnimation(int animationId, ActiveAnimation::TargetProperty targetProperty) |
| @@ -51,6 +56,7 @@ void LayerAnimationController::removeAnimation(int animationId, ActiveAnimation: |
| else |
| i++; |
| } |
| + updateRegistration(); |
| } |
| // According to render layer backing, these are for testing only. |
| @@ -100,11 +106,14 @@ void LayerAnimationController::animate(double monotonicTime, AnimationEventsVect |
| tickAnimations(monotonicTime); |
| markAnimationsForDeletion(monotonicTime, events); |
| startAnimationsWaitingForTargetAvailability(monotonicTime, events); |
| + |
| + updateRegistration(); |
| } |
| void LayerAnimationController::addAnimation(scoped_ptr<ActiveAnimation> animation) |
| { |
| m_activeAnimations.append(animation.Pass()); |
| + updateRegistration(); |
| } |
| ActiveAnimation* LayerAnimationController::getActiveAnimation(int groupId, ActiveAnimation::TargetProperty targetProperty) const |
| @@ -154,9 +163,22 @@ void LayerAnimationController::notifyAnimationStarted(const AnimationEvent& even |
| } |
| } |
| -void LayerAnimationController::setClient(LayerAnimationControllerClient* client) |
| +void LayerAnimationController::setAnimationRegistrar(AnimationRegistrar* registrar) |
| +{ |
| + if (m_registrar == registrar) |
| + return; |
|
nduca
2012/12/04 05:51:13
Oh i get it nao. Thanks.
Can we split out registr
Ian Vollick
2012/12/04 19:49:06
Naming is hard. Perhaps registration is the wrong
|
| + |
| + if (m_registrar && registrar) |
| + m_registrar->Unregister(this); |
| + |
| + m_registrar = registrar; |
| + |
| + updateRegistration(); |
| +} |
| + |
| +void LayerAnimationController::setId(int id) |
| { |
| - m_client = client; |
| + m_id = id; |
| } |
| void LayerAnimationController::pushNewAnimationsToImplThread(LayerAnimationController* controllerImpl) const |
| @@ -214,7 +236,7 @@ void LayerAnimationController::startAnimationsWaitingForNextTick(double monotoni |
| if (!m_activeAnimations[i]->hasSetStartTime()) |
| m_activeAnimations[i]->setStartTime(monotonicTime); |
| if (events) |
| - events->push_back(AnimationEvent(AnimationEvent::Started, m_client->id(), m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime)); |
| + events->push_back(AnimationEvent(AnimationEvent::Started, m_id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime)); |
| } |
| } |
| } |
| @@ -225,7 +247,7 @@ void LayerAnimationController::startAnimationsWaitingForStartTime(double monoton |
| if (m_activeAnimations[i]->runState() == ActiveAnimation::WaitingForStartTime && m_activeAnimations[i]->startTime() <= monotonicTime) { |
| m_activeAnimations[i]->setRunState(ActiveAnimation::Running, monotonicTime); |
| if (events) |
| - events->push_back(AnimationEvent(AnimationEvent::Started, m_client->id(), m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime)); |
| + events->push_back(AnimationEvent(AnimationEvent::Started, m_id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime)); |
| } |
| } |
| } |
| @@ -264,7 +286,7 @@ void LayerAnimationController::startAnimationsWaitingForTargetAvailability(doubl |
| if (!m_activeAnimations[i]->hasSetStartTime()) |
| m_activeAnimations[i]->setStartTime(monotonicTime); |
| if (events) |
| - events->push_back(AnimationEvent(AnimationEvent::Started, m_client->id(), m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime)); |
| + events->push_back(AnimationEvent(AnimationEvent::Started, m_id, m_activeAnimations[i]->group(), m_activeAnimations[i]->targetProperty(), monotonicTime)); |
| for (size_t j = i + 1; j < m_activeAnimations.size(); ++j) { |
| if (m_activeAnimations[i]->group() == m_activeAnimations[j]->group()) { |
| m_activeAnimations[j]->setRunState(ActiveAnimation::Running, monotonicTime); |
| @@ -320,7 +342,7 @@ void LayerAnimationController::markAnimationsForDeletion(double monotonicTime, A |
| for (size_t j = i; j < m_activeAnimations.size(); j++) { |
| if (groupId == m_activeAnimations[j]->group()) { |
| if (events) |
| - events->push_back(AnimationEvent(AnimationEvent::Finished, m_client->id(), m_activeAnimations[j]->group(), m_activeAnimations[j]->targetProperty(), monotonicTime)); |
| + events->push_back(AnimationEvent(AnimationEvent::Finished, m_id, m_activeAnimations[j]->group(), m_activeAnimations[j]->targetProperty(), monotonicTime)); |
| m_activeAnimations[j]->setRunState(ActiveAnimation::WaitingForDeletion, monotonicTime); |
| } |
| } |
| @@ -358,6 +380,12 @@ void LayerAnimationController::replaceImplThreadAnimations(LayerAnimationControl |
| void LayerAnimationController::tickAnimations(double monotonicTime) |
| { |
| + // FIXME(vollick) we should really be using base::TimeTicks instead of |
| + // doubles throughout this class. For now, we need to recalculate now so |
| + // that we can express the last update times for opacity and floats as |
| + // base::TimeTicks. |
| + base::TimeTicks now = base::TimeTicks::Now(); |
| + |
| for (size_t i = 0; i < m_activeAnimations.size(); ++i) { |
| if (m_activeAnimations[i]->runState() == ActiveAnimation::Running || m_activeAnimations[i]->runState() == ActiveAnimation::Paused) { |
| double trimmed = m_activeAnimations[i]->trimTimeToCurrentIteration(monotonicTime); |
| @@ -371,21 +399,19 @@ void LayerAnimationController::tickAnimations(double monotonicTime) |
| case ActiveAnimation::Transform: { |
| const TransformAnimationCurve* transformAnimationCurve = m_activeAnimations[i]->curve()->toTransformAnimationCurve(); |
| - const gfx::Transform matrix = transformAnimationCurve->getValue(trimmed).toTransform(); |
| + m_transform = transformAnimationCurve->getValue(trimmed).toTransform(); |
| + m_transformLastUpdateTime = now; |
| if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) |
| m_activeAnimations[i]->setRunState(ActiveAnimation::Finished, monotonicTime); |
| - |
| - m_client->setTransformFromAnimation(matrix); |
| break; |
| } |
| case ActiveAnimation::Opacity: { |
| const FloatAnimationCurve* floatAnimationCurve = m_activeAnimations[i]->curve()->toFloatAnimationCurve(); |
| - const float opacity = floatAnimationCurve->getValue(trimmed); |
| + m_opacity = floatAnimationCurve->getValue(trimmed); |
| + m_opacityLastUpdateTime = now; |
| if (m_activeAnimations[i]->isFinishedAt(monotonicTime)) |
| m_activeAnimations[i]->setRunState(ActiveAnimation::Finished, monotonicTime); |
| - |
| - m_client->setOpacityFromAnimation(opacity); |
| break; |
| } |
| @@ -397,4 +423,14 @@ void LayerAnimationController::tickAnimations(double monotonicTime) |
| } |
| } |
| +void LayerAnimationController::updateRegistration() |
| +{ |
| + if (m_registrar) { |
| + if (hasActiveAnimation()) |
| + m_registrar->Register(this); |
| + else |
| + m_registrar->Unregister(this); |
| + } |
| +} |
| + |
| } // namespace cc |