diff options
author | loyso <loyso@chromium.org> | 2016-03-17 17:36:09 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-18 00:37:31 +0000 |
commit | b8634c4d77f7d4017bf69832ca191d09b7cf3ad3 (patch) | |
tree | 3e3eba6b6f1409a7912045847498db59fa6bdc13 /cc | |
parent | 953caf1fc83c06ef7a4da9661f3350faec8a82f6 (diff) | |
download | chromium_src-b8634c4d77f7d4017bf69832ca191d09b7cf3ad3.zip chromium_src-b8634c4d77f7d4017bf69832ca191d09b7cf3ad3.tar.gz chromium_src-b8634c4d77f7d4017bf69832ca191d09b7cf3ad3.tar.bz2 |
CC Animation: Use bitset instead of unordered_set in LayerAnimationController
A performance optimization. This avoids any heap allocations.
BUG=595584
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1806223002
Cr-Commit-Position: refs/heads/master@{#381850}
Diffstat (limited to 'cc')
-rw-r--r-- | cc/animation/layer_animation_controller.cc | 42 | ||||
-rw-r--r-- | cc/animation/layer_animation_controller.h | 7 | ||||
-rw-r--r-- | cc/animation/target_property.h | 3 |
3 files changed, 33 insertions, 19 deletions
diff --git a/cc/animation/layer_animation_controller.cc b/cc/animation/layer_animation_controller.cc index 3a34b32..f18a4ce 100644 --- a/cc/animation/layer_animation_controller.cc +++ b/cc/animation/layer_animation_controller.cc @@ -796,12 +796,13 @@ void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { if (animations_[i]->run_state() == Animation::STARTING || animations_[i]->run_state() == Animation::RUNNING) { if (animations_[i]->affects_active_observers()) { - blocked_properties_for_active_observers.insert( - animations_[i]->target_property()); + blocked_properties_for_active_observers[animations_[i] + ->target_property()] = true; } if (animations_[i]->affects_pending_observers()) { - blocked_properties_for_pending_observers.insert( - animations_[i]->target_property()); + blocked_properties_for_pending_observers[animations_[i] + ->target_property()] = + true; } } else if (animations_[i]->run_state() == Animation::WAITING_FOR_TARGET_AVAILABILITY) { @@ -825,11 +826,11 @@ void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { animation_waiting_for_target->affects_active_observers(); bool affects_pending_observers = animation_waiting_for_target->affects_pending_observers(); - enqueued_properties.insert( - animation_waiting_for_target->target_property()); + enqueued_properties[animation_waiting_for_target->target_property()] = + true; 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()); + enqueued_properties[animations_[j]->target_property()] = true; affects_active_observers |= animations_[j]->affects_active_observers(); affects_pending_observers |= @@ -843,15 +844,24 @@ void LayerAnimationController::StartAnimations(base::TimeTicks monotonic_time) { // case, the group's target properties need to be added to the lists of // blocked properties. bool null_intersection = true; - for (TargetProperties::iterator p_iter = enqueued_properties.begin(); - p_iter != enqueued_properties.end(); - ++p_iter) { - if (affects_active_observers && - !blocked_properties_for_active_observers.insert(*p_iter).second) - null_intersection = false; - if (affects_pending_observers && - !blocked_properties_for_pending_observers.insert(*p_iter).second) - null_intersection = false; + static_assert(TargetProperty::FIRST_TARGET_PROPERTY == 0, + "TargetProperty must be 0-based enum"); + for (int property = TargetProperty::FIRST_TARGET_PROPERTY; + property <= TargetProperty::LAST_TARGET_PROPERTY; ++property) { + if (enqueued_properties[property]) { + if (affects_active_observers) { + if (blocked_properties_for_active_observers[property]) + null_intersection = false; + else + blocked_properties_for_active_observers[property] = true; + } + if (affects_pending_observers) { + if (blocked_properties_for_pending_observers[property]) + null_intersection = false; + else + blocked_properties_for_pending_observers[property] = true; + } + } } // If the intersection is null, then we are free to start the animations diff --git a/cc/animation/layer_animation_controller.h b/cc/animation/layer_animation_controller.h index c6cc506..2676d81 100644 --- a/cc/animation/layer_animation_controller.h +++ b/cc/animation/layer_animation_controller.h @@ -5,7 +5,7 @@ #ifndef CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ #define CC_ANIMATION_LAYER_ANIMATION_CONTROLLER_H_ -#include <unordered_set> +#include <bitset> #include <vector> #include "base/macros.h" @@ -15,6 +15,7 @@ #include "base/time/time.h" #include "cc/animation/animation.h" #include "cc/animation/layer_animation_event_observer.h" +#include "cc/animation/target_property.h" #include "cc/base/cc_export.h" #include "ui/gfx/geometry/scroll_offset.h" #include "ui/gfx/transform.h" @@ -175,7 +176,9 @@ class CC_EXPORT LayerAnimationController explicit LayerAnimationController(int id); ~LayerAnimationController(); - using TargetProperties = std::unordered_set<int>; + // A set of target properties. TargetProperty must be 0-based enum. + using TargetProperties = + std::bitset<TargetProperty::LAST_TARGET_PROPERTY + 1>; void PushNewAnimationsToImplThread( LayerAnimationController* controller_impl) const; diff --git a/cc/animation/target_property.h b/cc/animation/target_property.h index e4658e1..4ba1e1d 100644 --- a/cc/animation/target_property.h +++ b/cc/animation/target_property.h @@ -15,7 +15,8 @@ enum Type { FILTER, SCROLL_OFFSET, BACKGROUND_COLOR, - // This sentinel must be last. + // These sentinels must be last + FIRST_TARGET_PROPERTY = TRANSFORM, LAST_TARGET_PROPERTY = BACKGROUND_COLOR }; |