Bug 1454550 - Call AnimationHelper::SampleAnimationForEachNode only for layers that have animations. r?kats draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 17 Apr 2018 13:20:33 +0900
changeset 783355 16b85ece8f8c343c7654d77398f9360957f8797b
parent 783184 6a87ef9c1acc5f6af848c00b8b9f608444ff8a72
push id106680
push userhikezoe@mozilla.com
push dateTue, 17 Apr 2018 04:20:52 +0000
reviewerskats
bugs1454550
milestone61.0a1
Bug 1454550 - Call AnimationHelper::SampleAnimationForEachNode only for layers that have animations. r?kats This is slightly efficient since we don't need to call GetBaseAnimationStyle() or we do skip allocating animation data for such case. MozReview-Commit-ID: BYFNwZsZ1oE
gfx/layers/AnimationHelper.cpp
gfx/layers/AnimationHelper.h
gfx/layers/composite/AsyncCompositionManager.cpp
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -129,37 +129,31 @@ void
 CompositorAnimationStorage::SetAnimations(uint64_t aId, const AnimationArray& aValue)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   AnimationArray* value = new AnimationArray(aValue);
   mAnimations.Put(aId, value);
 }
 
 
-bool
+void
 AnimationHelper::SampleAnimationForEachNode(
   TimeStamp aTime,
   AnimationArray& aAnimations,
   InfallibleTArray<AnimData>& aAnimationData,
   AnimationValue& aAnimationValue,
   bool& aHasInEffectAnimations)
 {
-  bool activeAnimations = false;
-
-  if (aAnimations.IsEmpty()) {
-    return activeAnimations;
-  }
+  MOZ_ASSERT(!aAnimations.IsEmpty(), "Should be called with animations");
 
   // Process in order, since later aAnimations override earlier ones.
   for (size_t i = 0, iEnd = aAnimations.Length(); i < iEnd; ++i) {
     Animation& animation = aAnimations[i];
     AnimData& animData = aAnimationData[i];
 
-    activeAnimations = true;
-
     MOZ_ASSERT((!animation.originTime().IsNull() &&
                 animation.startTime().type() ==
                   MaybeTimeDuration::TTimeDuration) ||
                animation.isNotPlaying(),
                "If we are playing, we should have an origin time and a start"
                " time");
     // If the animation is not currently playing, e.g. paused or
     // finished, then use the hold time to stay at the same position.
@@ -253,17 +247,16 @@ AnimationHelper::SampleAnimationForEachN
                transformData.transformOrigin() ==
                  lastTransformData.transformOrigin() &&
                transformData.bounds() == lastTransformData.bounds() &&
                transformData.appUnitsPerDevPixel() ==
                  lastTransformData.appUnitsPerDevPixel(),
                "All of members of TransformData should be the same");
   }
 #endif
-  return activeAnimations;
 }
 
 struct BogusAnimation {};
 
 static inline Result<Ok, BogusAnimation>
 SetCSSAngle(const CSSAngle& aAngle, nsCSSValue& aValue)
 {
   aValue.SetFloatValue(aAngle.value(), nsCSSUnit(aAngle.unit()));
@@ -509,16 +502,20 @@ AnimationHelper::SampleAnimations(Compos
     return;
   }
 
   //Sample the animations in CompositorAnimationStorage
   for (auto iter = aStorage->ConstAnimationsTableIter();
        !iter.Done(); iter.Next()) {
     bool hasInEffectAnimations = false;
     AnimationArray* animations = iter.UserData();
+    if (animations->IsEmpty()) {
+      continue;
+    }
+
     AnimationValue animationValue;
     InfallibleTArray<AnimData> animationData;
     AnimationHelper::SetAnimations(*animations,
                                    animationData,
                                    animationValue);
     AnimationHelper::SampleAnimationForEachNode(aTime,
                                                 *animations,
                                                 animationData,
--- a/gfx/layers/AnimationHelper.h
+++ b/gfx/layers/AnimationHelper.h
@@ -191,20 +191,18 @@ private:
  */
 class AnimationHelper
 {
 public:
 
   /**
    * Sample animations based on a given time stamp for a element(layer) with
    * its animation data.
-   * Returns true if there exists compositor animation, and stores corresponding
-   * animated value in |aAnimationValue|.
    */
-  static bool
+  static void
   SampleAnimationForEachNode(TimeStamp aTime,
                              AnimationArray& aAnimations,
                              InfallibleTArray<AnimData>& aAnimationData,
                              AnimationValue& aAnimationValue,
                              bool& aHasInEffectAnimations);
   /**
    * Populates AnimData stuctures into |aAnimData| and |aBaseAnimationStyle|
    * based on |aAnimations|.
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -644,27 +644,30 @@ SampleAnimations(Layer* aLayer,
                  TimeStamp aTime)
 {
   bool isAnimating = false;
 
   ForEachNode<ForwardIterator>(
       aLayer,
       [&] (Layer* layer)
       {
+        AnimationArray& animations = layer->GetAnimations();
+        if (animations.IsEmpty()) {
+          return;
+        }
+        isAnimating = true;
         bool hasInEffectAnimations = false;
         AnimationValue animationValue = layer->GetBaseAnimationStyle();
-        if (AnimationHelper::SampleAnimationForEachNode(aTime,
-                                                        layer->GetAnimations(),
-                                                        layer->GetAnimationData(),
-                                                        animationValue,
-                                                        hasInEffectAnimations)) {
-          isAnimating = true;
-        }
+        AnimationHelper::SampleAnimationForEachNode(aTime,
+                                                    animations,
+                                                    layer->GetAnimationData(),
+                                                    animationValue,
+                                                    hasInEffectAnimations);
         if (hasInEffectAnimations) {
-          Animation& animation = layer->GetAnimations().LastElement();
+          Animation& animation = animations.LastElement();
           ApplyAnimatedValue(layer,
                              aStorage,
                              animation.property(),
                              animation.data(),
                              animationValue);
         }
       });