Bug 1454550 - Call AnimationHelper::SampleAnimationForEachNode only for layers that have animations. r=kats
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 17 Apr 2018 13:20:33 +0900
changeset 467666 7197059eb99c95e33f7b6bf5f102e81a4fe7437d
parent 467665 baf6063071b523d291fb61e8974034f1767c4c26
child 467667 734ac146303fb18aaae3e6334b9ee19adf351370
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1454550
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);
         }
       });