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

Unified Diff: cc/animation/animation_player.cc

Issue 2966793002: NOT FOR REVIEW - convert to cc animation
Patch Set: switch to transform operations Created 3 years, 6 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
« no previous file with comments | « cc/animation/animation_player.h ('k') | cc/animation/element_animations.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/animation/animation_player.cc
diff --git a/cc/animation/animation_player.cc b/cc/animation/animation_player.cc
index 3174dcbdab096b0c5b8c3269e6a638372bdbfa47..3a747544a677eb319dea24b44bca5b55865617ee 100644
--- a/cc/animation/animation_player.cc
+++ b/cc/animation/animation_player.cc
@@ -10,8 +10,10 @@
#include "cc/animation/animation_delegate.h"
#include "cc/animation/animation_events.h"
#include "cc/animation/animation_host.h"
+#include "cc/animation/animation_observer.h"
#include "cc/animation/animation_timeline.h"
#include "cc/animation/scroll_offset_animation_curve.h"
+#include "cc/animation/transform_operations.h"
#include "cc/trees/property_animation_state.h"
namespace cc {
@@ -108,6 +110,7 @@ void AnimationPlayer::BindElementAnimations() {
DCHECK(!element_animations_);
element_animations_ =
animation_host_->GetElementAnimationsForElementId(element_id_);
+ observers_.AddObserver(element_animations_.get());
DCHECK(element_animations_);
if (!animations_.empty())
@@ -118,6 +121,9 @@ void AnimationPlayer::BindElementAnimations() {
void AnimationPlayer::UnbindElementAnimations() {
SetNeedsPushProperties();
+ if (element_animations_) {
+ observers_.RemoveObserver(element_animations_.get());
+ }
element_animations_ = nullptr;
}
@@ -128,20 +134,20 @@ void AnimationPlayer::AddAnimation(std::unique_ptr<Animation> animation) {
animation->target_property() == TargetProperty::SCROLL_OFFSET);
animations_.push_back(std::move(animation));
+ AnimationAdded();
if (element_animations_) {
- AnimationAdded();
SetNeedsPushProperties();
}
}
void AnimationPlayer::AnimationAdded() {
- DCHECK(element_animations_);
-
- SetNeedsCommit();
+ if (element_animations_)
+ SetNeedsCommit();
needs_to_start_animations_ = true;
-
- UpdateTickingState(UpdateTickingType::NORMAL);
- element_animations_->UpdateClientAnimationState();
+ if (element_animations_) {
+ UpdateTickingState(UpdateTickingType::NORMAL);
+ element_animations_->UpdateClientAnimationState();
+ }
}
void AnimationPlayer::PauseAnimation(int animation_id, double time_offset) {
@@ -268,9 +274,8 @@ void AnimationPlayer::PushPropertiesTo(AnimationPlayer* player_impl) {
void AnimationPlayer::Tick(base::TimeTicks monotonic_time) {
DCHECK(!monotonic_time.is_null());
- DCHECK(element_animations_);
- if (!element_animations_->has_element_in_any_list())
+ if (element_animations_ && !element_animations_->has_element_in_any_list())
return;
if (needs_to_start_animations())
@@ -279,13 +284,13 @@ void AnimationPlayer::Tick(base::TimeTicks monotonic_time) {
TickAnimations(monotonic_time);
last_tick_time_ = monotonic_time;
- element_animations_->UpdateClientAnimationState();
+ if (element_animations_)
+ element_animations_->UpdateClientAnimationState();
}
void AnimationPlayer::UpdateState(bool start_ready_animations,
AnimationEvents* events) {
- DCHECK(element_animations_);
- if (!element_animations_->has_element_in_active_list())
+ if (element_animations_ && !element_animations_->has_element_in_active_list())
return;
// Animate hasn't been called, this happens if an element has been added
@@ -723,8 +728,6 @@ void AnimationPlayer::MarkAnimationsForDeletion(base::TimeTicks monotonic_time,
}
void AnimationPlayer::TickAnimations(base::TimeTicks monotonic_time) {
- DCHECK(element_animations_);
-
for (size_t i = 0; i < animations_.size(); ++i) {
if (animations_[i]->run_state() == Animation::STARTING ||
animations_[i]->run_state() == Animation::RUNNING ||
@@ -739,11 +742,13 @@ void AnimationPlayer::TickAnimations(base::TimeTicks monotonic_time) {
case TargetProperty::TRANSFORM: {
const TransformAnimationCurve* transform_animation_curve =
animations_[i]->curve()->ToTransformAnimationCurve();
- const gfx::Transform transform =
+ const TransformOperations operations =
transform_animation_curve->GetValue(trimmed);
- element_animations_->NotifyClientTransformAnimated(
- transform, animations_[i]->affects_active_elements(),
- animations_[i]->affects_pending_elements());
+ for (auto& observer : observers_) {
+ observer.NotifyClientTransformOperationsAnimated(
+ operations, animations_[i]->affects_active_elements(),
+ animations_[i]->affects_pending_elements());
+ }
break;
}
@@ -752,9 +757,11 @@ void AnimationPlayer::TickAnimations(base::TimeTicks monotonic_time) {
animations_[i]->curve()->ToFloatAnimationCurve();
const float opacity = std::max(
std::min(float_animation_curve->GetValue(trimmed), 1.0f), 0.f);
- element_animations_->NotifyClientOpacityAnimated(
- opacity, animations_[i]->affects_active_elements(),
- animations_[i]->affects_pending_elements());
+ for (auto& observer : observers_) {
+ observer.NotifyClientOpacityAnimated(
+ opacity, animations_[i]->affects_active_elements(),
+ animations_[i]->affects_pending_elements());
+ }
break;
}
@@ -763,9 +770,11 @@ void AnimationPlayer::TickAnimations(base::TimeTicks monotonic_time) {
animations_[i]->curve()->ToFilterAnimationCurve();
const FilterOperations filter =
filter_animation_curve->GetValue(trimmed);
- element_animations_->NotifyClientFilterAnimated(
- filter, animations_[i]->affects_active_elements(),
- animations_[i]->affects_pending_elements());
+ for (auto& observer : observers_) {
+ observer.NotifyClientFilterAnimated(
+ filter, animations_[i]->affects_active_elements(),
+ animations_[i]->affects_pending_elements());
+ }
break;
}
@@ -779,9 +788,23 @@ void AnimationPlayer::TickAnimations(base::TimeTicks monotonic_time) {
animations_[i]->curve()->ToScrollOffsetAnimationCurve();
const gfx::ScrollOffset scroll_offset =
scroll_offset_animation_curve->GetValue(trimmed);
- element_animations_->NotifyClientScrollOffsetAnimated(
- scroll_offset, animations_[i]->affects_active_elements(),
- animations_[i]->affects_pending_elements());
+ for (auto& observer : observers_) {
+ observer.NotifyClientScrollOffsetAnimated(
+ scroll_offset, animations_[i]->affects_active_elements(),
+ animations_[i]->affects_pending_elements());
+ }
+ break;
+ }
+
+ case TargetProperty::BOUNDS: {
+ const SizeAnimationCurve* size_animation_curve =
+ animations_[i]->curve()->ToSizeAnimationCurve();
+ const gfx::SizeF size = size_animation_curve->GetValue(trimmed);
+ for (auto& observer : observers_) {
+ observer.NotifyClientBoundsAnimated(
+ size, animations_[i]->affects_active_elements(),
+ animations_[i]->affects_pending_elements());
+ }
break;
}
}
@@ -799,7 +822,9 @@ void AnimationPlayer::MarkFinishedAnimations(base::TimeTicks monotonic_time) {
animations_[i]->IsFinishedAt(monotonic_time)) {
animations_[i]->SetRunState(Animation::FINISHED, monotonic_time);
animation_finished = true;
- SetNeedsPushProperties();
+ if (element_animations_) {
+ SetNeedsPushProperties();
+ }
}
if (!animations_[i]->affects_active_elements() &&
!animations_[i]->affects_pending_elements()) {
@@ -817,8 +842,7 @@ void AnimationPlayer::MarkFinishedAnimations(base::TimeTicks monotonic_time) {
}
}
- DCHECK(element_animations_);
- if (animation_finished)
+ if (element_animations_ && animation_finished)
element_animations_->UpdateClientAnimationState();
}
@@ -1211,4 +1235,12 @@ void AnimationPlayer::PushPropertiesToImplThread(
scroll_offset_animation_was_interrupted_ = false;
}
+void AnimationPlayer::AddObserver(AnimationObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void AnimationPlayer::RemoveObserver(AnimationObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
} // namespace cc
« no previous file with comments | « cc/animation/animation_player.h ('k') | cc/animation/element_animations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698