Skip to content

Commit

Permalink
cc: Optimize search in LayerAnimationController::StartAnimations
Browse files Browse the repository at this point in the history
During StartAnimation first it does a search for all animations which are
running and starting. After that it again searches the entire animation
list for animations waiting for target availability.

This patch reduces this search (for loops) by keeping track of the
animations waiting for target availability in the first search itself.


BUG=396562

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285561 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
shreyas.g@samsung.com committed Jul 25, 2014
1 parent 86f1205 commit ca9e2b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ Shez Baig <sbaig1@bloomberg.net>
Shiliu Wang <aofdwsl@gmail.com>
Shiliu Wang <shiliu.wang@intel.com>
Shouqun Liu <shouqun.liu@intel.com>
Shreyas Gopal <shreyas.g@samsung.com>
Shreyas VA <v.a.shreyas@gmail.com>
Simon Arlott <simon.arlott@gmail.com>
Siva Kumar Gunturi <siva.gunturi@samsung.com>
Expand Down
36 changes: 25 additions & 11 deletions cc/animation/layer_animation_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) {
// First collect running properties affecting each type of observer.
TargetProperties blocked_properties_for_active_observers;
TargetProperties blocked_properties_for_pending_observers;
std::vector<size_t> animations_waiting_for_target;

animations_waiting_for_target.reserve(animations_.size());
for (size_t i = 0; i < animations_.size(); ++i) {
if (animations_[i]->run_state() == Animation::Starting ||
animations_[i]->run_state() == Animation::Running) {
Expand All @@ -613,22 +616,31 @@ void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) {
blocked_properties_for_pending_observers.insert(
animations_[i]->target_property());
}
} else if (animations_[i]->run_state() ==
Animation::WaitingForTargetAvailability) {
animations_waiting_for_target.push_back(i);
}
}

for (size_t i = 0; i < animations_.size(); ++i) {
if (animations_[i]->run_state() ==
Animation::WaitingForTargetAvailability) {
for (size_t i = 0; i < animations_waiting_for_target.size(); ++i) {
// Collect all properties for animations with the same group id (they
// should all also be in the list of animations).
size_t animation_index = animations_waiting_for_target[i];
Animation* animation_waiting_for_target = animations_[animation_index];
// Check for the run state again even though the animation was waiting
// for target because it might have changed the run state while handling
// previous animation in this loop (if they belong to same group).
if (animation_waiting_for_target->run_state() ==
Animation::WaitingForTargetAvailability) {
TargetProperties enqueued_properties;
bool affects_active_observers =
animations_[i]->affects_active_observers();
animation_waiting_for_target->affects_active_observers();
bool affects_pending_observers =
animations_[i]->affects_pending_observers();
enqueued_properties.insert(animations_[i]->target_property());
for (size_t j = i + 1; j < animations_.size(); ++j) {
if (animations_[i]->group() == animations_[j]->group()) {
animation_waiting_for_target->affects_pending_observers();
enqueued_properties.insert(
animation_waiting_for_target->target_property());
for (size_t j = animation_index + 1; j < animations_.size(); ++j) {
if (animation_waiting_for_target->group() == animations_[j]->group()) {
enqueued_properties.insert(animations_[j]->target_property());
affects_active_observers |=
animations_[j]->affects_active_observers();
Expand Down Expand Up @@ -657,9 +669,11 @@ void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) {
// If the intersection is null, then we are free to start the animations
// in the group.
if (null_intersection) {
animations_[i]->SetRunState(Animation::Starting, monotonic_time);
for (size_t j = i + 1; j < animations_.size(); ++j) {
if (animations_[i]->group() == animations_[j]->group()) {
animation_waiting_for_target->SetRunState(Animation::Starting,
monotonic_time);
for (size_t j = animation_index + 1; j < animations_.size(); ++j) {
if (animation_waiting_for_target->group() ==
animations_[j]->group()) {
animations_[j]->SetRunState(Animation::Starting, monotonic_time);
}
}
Expand Down

0 comments on commit ca9e2b3

Please sign in to comment.