Skip to content

Commit

Permalink
cc: Move filters to the effect tree
Browse files Browse the repository at this point in the history
This removes filters from LayerImpl, and adds them to the
effect tree and to LayerImplTestProperties.

BUG=622410
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review-Url: https://codereview.chromium.org/2110683004
Cr-Commit-Position: refs/heads/master@{#406927}
  • Loading branch information
alijuma authored and Commit bot committed Jul 21, 2016
1 parent 55ffa56 commit cb2b744
Show file tree
Hide file tree
Showing 31 changed files with 632 additions and 98 deletions.
132 changes: 90 additions & 42 deletions cc/animation/element_animations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,19 @@ void ElementAnimations::PushPropertiesTo(
void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) {
DCHECK(!animation->is_impl_only() ||
animation->target_property() == TargetProperty::SCROLL_OFFSET);
bool added_transform_animation =
animation->target_property() == TargetProperty::TRANSFORM;
bool added_opacity_animation =
animation->target_property() == TargetProperty::OPACITY;
TargetProperty::Type target_property = animation->target_property();
animations_.push_back(std::move(animation));
needs_to_start_animations_ = true;
UpdateActivation(NORMAL_ACTIVATION);
if (added_transform_animation)
UpdateClientAnimationState(TargetProperty::TRANSFORM);
if (added_opacity_animation)
UpdateClientAnimationState(TargetProperty::OPACITY);
switch (target_property) {
case TargetProperty::TRANSFORM:
case TargetProperty::OPACITY:
case TargetProperty::FILTER:
UpdateClientAnimationState(target_property);
break;
default:
break;
}
}

void ElementAnimations::Animate(base::TimeTicks monotonic_time) {
Expand All @@ -174,6 +176,7 @@ void ElementAnimations::Animate(base::TimeTicks monotonic_time) {
last_tick_time_ = monotonic_time;
UpdateClientAnimationState(TargetProperty::OPACITY);
UpdateClientAnimationState(TargetProperty::TRANSFORM);
UpdateClientAnimationState(TargetProperty::FILTER);
}

void ElementAnimations::UpdateState(bool start_ready_animations,
Expand Down Expand Up @@ -203,13 +206,16 @@ void ElementAnimations::UpdateState(bool start_ready_animations,
void ElementAnimations::ActivateAnimations() {
bool changed_transform_animation = false;
bool changed_opacity_animation = false;
bool changed_filter_animation = false;
for (size_t i = 0; i < animations_.size(); ++i) {
if (animations_[i]->affects_active_elements() !=
animations_[i]->affects_pending_elements()) {
if (animations_[i]->target_property() == TargetProperty::TRANSFORM)
changed_transform_animation = true;
else if (animations_[i]->target_property() == TargetProperty::OPACITY)
changed_opacity_animation = true;
else if (animations_[i]->target_property() == TargetProperty::FILTER)
changed_filter_animation = true;
}
animations_[i]->set_affects_active_elements(
animations_[i]->affects_pending_elements());
Expand All @@ -227,6 +233,8 @@ void ElementAnimations::ActivateAnimations() {
UpdateClientAnimationState(TargetProperty::TRANSFORM);
if (changed_opacity_animation)
UpdateClientAnimationState(TargetProperty::OPACITY);
if (changed_filter_animation)
UpdateClientAnimationState(TargetProperty::FILTER);
}

void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) {
Expand Down Expand Up @@ -282,26 +290,25 @@ void ElementAnimations::NotifyAnimationTakeover(const AnimationEvent& event) {
}

void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) {
bool aborted_transform_animation = false;
bool aborted_opacity_animation = false;
for (size_t i = 0; i < animations_.size(); ++i) {
if (animations_[i]->group() == event.group_id &&
animations_[i]->target_property() == event.target_property) {
animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time);
animations_[i]->set_received_finished_event(true);
NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property,
event.group_id);
if (event.target_property == TargetProperty::TRANSFORM)
aborted_transform_animation = true;
else if (event.target_property == TargetProperty::OPACITY)
aborted_opacity_animation = true;
break;
}
}
if (aborted_transform_animation)
UpdateClientAnimationState(TargetProperty::TRANSFORM);
if (aborted_opacity_animation)
UpdateClientAnimationState(TargetProperty::OPACITY);
switch (event.target_property) {
case TargetProperty::TRANSFORM:
case TargetProperty::OPACITY:
case TargetProperty::FILTER:
UpdateClientAnimationState(event.target_property);
break;
default:
break;
}
}

void ElementAnimations::NotifyAnimationPropertyUpdate(
Expand Down Expand Up @@ -560,6 +567,7 @@ void ElementAnimations::RemoveAnimationsCompletedOnMainThread(
ElementAnimations* element_animations_impl) const {
bool removed_transform_animation = false;
bool removed_opacity_animation = false;
bool removed_filter_animation = false;
// Animations removed on the main thread should no longer affect pending
// elements, and should stop affecting active elements after the next call
// to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed
Expand All @@ -572,6 +580,8 @@ void ElementAnimations::RemoveAnimationsCompletedOnMainThread(
removed_transform_animation = true;
else if (animation->target_property() == TargetProperty::OPACITY)
removed_opacity_animation = true;
else if (animation->target_property() == TargetProperty::FILTER)
removed_filter_animation = true;
}
}
auto affects_active_only_and_is_waiting_for_deletion =
Expand All @@ -584,12 +594,17 @@ void ElementAnimations::RemoveAnimationsCompletedOnMainThread(
affects_active_only_and_is_waiting_for_deletion),
animations.end());

if (removed_transform_animation)
if (removed_transform_animation) {
element_animations_impl->UpdateClientAnimationState(
TargetProperty::TRANSFORM);
if (removed_opacity_animation)
}
if (removed_opacity_animation) {
element_animations_impl->UpdateClientAnimationState(
TargetProperty::OPACITY);
}
if (removed_filter_animation) {
element_animations_impl->UpdateClientAnimationState(TargetProperty::FILTER);
}
}

void ElementAnimations::PushPropertiesToImplThread(
Expand Down Expand Up @@ -733,6 +748,7 @@ void ElementAnimations::PromoteStartedAnimations(base::TimeTicks monotonic_time,
void ElementAnimations::MarkFinishedAnimations(base::TimeTicks monotonic_time) {
bool finished_transform_animation = false;
bool finished_opacity_animation = false;
bool finished_filter_animation = false;
for (size_t i = 0; i < animations_.size(); ++i) {
if (!animations_[i]->is_finished() &&
animations_[i]->IsFinishedAt(monotonic_time)) {
Expand All @@ -741,12 +757,16 @@ void ElementAnimations::MarkFinishedAnimations(base::TimeTicks monotonic_time) {
finished_transform_animation = true;
else if (animations_[i]->target_property() == TargetProperty::OPACITY)
finished_opacity_animation = true;
else if (animations_[i]->target_property() == TargetProperty::FILTER)
finished_filter_animation = true;
}
}
if (finished_transform_animation)
UpdateClientAnimationState(TargetProperty::TRANSFORM);
if (finished_opacity_animation)
UpdateClientAnimationState(TargetProperty::OPACITY);
if (finished_filter_animation)
UpdateClientAnimationState(TargetProperty::FILTER);
}

void ElementAnimations::MarkAnimationsForDeletion(
Expand Down Expand Up @@ -879,6 +899,7 @@ void ElementAnimations::MarkAbortedAnimationsForDeletion(
ElementAnimations* element_animations_impl) const {
bool aborted_transform_animation = false;
bool aborted_opacity_animation = false;
bool aborted_filter_animation = false;
auto& animations_impl = element_animations_impl->animations_;
for (const auto& animation_impl : animations_impl) {
// If the animation has been aborted on the main thread, mark it for
Expand All @@ -893,16 +914,23 @@ void ElementAnimations::MarkAbortedAnimationsForDeletion(
aborted_transform_animation = true;
else if (animation_impl->target_property() == TargetProperty::OPACITY)
aborted_opacity_animation = true;
else if (animation_impl->target_property() == TargetProperty::FILTER)
aborted_filter_animation = true;
}
}
}

if (aborted_transform_animation)
if (aborted_transform_animation) {
element_animations_impl->UpdateClientAnimationState(
TargetProperty::TRANSFORM);
if (aborted_opacity_animation)
}
if (aborted_opacity_animation) {
element_animations_impl->UpdateClientAnimationState(
TargetProperty::OPACITY);
}
if (aborted_filter_animation) {
element_animations_impl->UpdateClientAnimationState(TargetProperty::FILTER);
}
}

void ElementAnimations::PurgeAnimationsMarkedForDeletion() {
Expand Down Expand Up @@ -1056,6 +1084,9 @@ void ElementAnimations::NotifyClientAnimationChanged(
case TargetProperty::TRANSFORM:
animation_state = &transform_animation_state_;
break;
case TargetProperty::FILTER:
animation_state = &filter_animation_state_;
break;
default:
NOTREACHED();
break;
Expand Down Expand Up @@ -1100,6 +1131,9 @@ void ElementAnimations::UpdateClientAnimationState(
case TargetProperty::TRANSFORM:
animation_state = &transform_animation_state_;
break;
case TargetProperty::FILTER:
animation_state = &filter_animation_state_;
break;
default:
NOTREACHED();
break;
Expand Down Expand Up @@ -1218,6 +1252,7 @@ void ElementAnimations::PauseAnimation(int animation_id,
void ElementAnimations::RemoveAnimation(int animation_id) {
bool removed_transform_animation = false;
bool removed_opacity_animation = false;
bool removed_filter_animation = false;
// Since we want to use the animations that we're going to remove, we need to
// use a stable_parition here instead of remove_if. Remove_if leaves the
// removed items in an unspecified state.
Expand All @@ -1235,6 +1270,9 @@ void ElementAnimations::RemoveAnimation(int animation_id) {
} else if ((*it)->target_property() == TargetProperty::OPACITY &&
!(*it)->is_finished()) {
removed_opacity_animation = true;
} else if ((*it)->target_property() == TargetProperty::FILTER &&
!(*it)->is_finished()) {
removed_filter_animation = true;
}
}

Expand All @@ -1244,33 +1282,33 @@ void ElementAnimations::RemoveAnimation(int animation_id) {
UpdateClientAnimationState(TargetProperty::TRANSFORM);
if (removed_opacity_animation)
UpdateClientAnimationState(TargetProperty::OPACITY);
if (removed_filter_animation)
UpdateClientAnimationState(TargetProperty::FILTER);
}

void ElementAnimations::AbortAnimation(int animation_id) {
bool aborted_transform_animation = false;
bool aborted_opacity_animation = false;
if (Animation* animation = GetAnimationById(animation_id)) {
if (!animation->is_finished()) {
animation->SetRunState(Animation::ABORTED, last_tick_time_);
if (animation->target_property() == TargetProperty::TRANSFORM)
aborted_transform_animation = true;
else if (animation->target_property() == TargetProperty::OPACITY)
aborted_opacity_animation = true;
switch (animation->target_property()) {
case TargetProperty::TRANSFORM:
case TargetProperty::OPACITY:
case TargetProperty::FILTER:
UpdateClientAnimationState(animation->target_property());
break;
default:
break;
}
}
}
if (aborted_transform_animation)
UpdateClientAnimationState(TargetProperty::TRANSFORM);
if (aborted_opacity_animation)
UpdateClientAnimationState(TargetProperty::OPACITY);
}

void ElementAnimations::AbortAnimations(TargetProperty::Type target_property,
bool needs_completion) {
if (needs_completion)
DCHECK(target_property == TargetProperty::SCROLL_OFFSET);

bool aborted_transform_animation = false;
bool aborted_opacity_animation = false;
bool aborted_animation = false;
for (size_t i = 0; i < animations_.size(); ++i) {
if (animations_[i]->target_property() == target_property &&
!animations_[i]->is_finished()) {
Expand All @@ -1282,16 +1320,20 @@ void ElementAnimations::AbortAnimations(TargetProperty::Type target_property,
} else {
animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_);
}
if (target_property == TargetProperty::TRANSFORM)
aborted_transform_animation = true;
else if (target_property == TargetProperty::OPACITY)
aborted_opacity_animation = true;
aborted_animation = true;
}
}
if (aborted_animation) {
switch (target_property) {
case TargetProperty::TRANSFORM:
case TargetProperty::OPACITY:
case TargetProperty::FILTER:
UpdateClientAnimationState(target_property);
break;
default:
break;
}
}
if (aborted_transform_animation)
UpdateClientAnimationState(TargetProperty::TRANSFORM);
if (aborted_opacity_animation)
UpdateClientAnimationState(TargetProperty::OPACITY);
}

Animation* ElementAnimations::GetAnimation(
Expand Down Expand Up @@ -1376,6 +1418,12 @@ void ElementAnimations::IsAnimatingChanged(ElementListType list_type,
->ElementTransformIsAnimatingChanged(element_id(), list_type,
change_type, is_animating);
break;
case TargetProperty::FILTER:
animation_host()
->mutator_host_client()
->ElementFilterIsAnimatingChanged(element_id(), list_type,
change_type, is_animating);
break;
default:
NOTREACHED();
break;
Expand Down
1 change: 1 addition & 0 deletions cc/animation/element_animations.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class CC_EXPORT ElementAnimations : public base::RefCounted<ElementAnimations> {
}
};

struct PropertyAnimationState filter_animation_state_;
struct PropertyAnimationState opacity_animation_state_;
struct PropertyAnimationState transform_animation_state_;

Expand Down
Loading

0 comments on commit cb2b744

Please sign in to comment.