Bug 1345017 - Discard the unchanged animated value during sample animations, r?kats draft
authorpeter chang <pchang@mozilla.com>
Wed, 12 Apr 2017 17:00:44 +0800
changeset 563692 76591f1bc95ef11a08d3535906152449a034a401
parent 563691 b0b57eb4499bd64c69d0267c07dfd74b6458c814
child 563693 4f7aabc5d316e79b0d610425afaf15b58547175c
push id54384
push userbmo:howareyou322@gmail.com
push dateMon, 17 Apr 2017 15:23:16 +0000
reviewerskats
bugs1345017
milestone55.0a1
Bug 1345017 - Discard the unchanged animated value during sample animations, r?kats MozReview-Commit-ID: 1CEcqBp7zS4
gfx/layers/AnimationHelper.cpp
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -493,16 +493,17 @@ AnimationHelper::SampleAnimations(Compos
 {
   MOZ_ASSERT(aStorage);
 
   // Do nothing if there are no compositor animations
   if (!aStorage->AnimationsCount()) {
     return;
   }
 
+  nsTArray<uint64_t> unchangedAnimations;
   //Sample the animations in CompositorAnimationStorage
   for (auto iter = aStorage->ConstAnimationsTableIter();
        !iter.Done(); iter.Next()) {
     bool hasInEffectAnimations = false;
     AnimationArray* animations = iter.UserData();
     StyleAnimationValue animationValue;
     InfallibleTArray<AnimData> animationData;
     AnimationHelper::SetAnimations(*animations,
@@ -517,18 +518,23 @@ AnimationHelper::SampleAnimations(Compos
     if (!hasInEffectAnimations) {
       continue;
     }
 
     // Store the AnimatedValue
     Animation& animation = animations->LastElement();
     switch (animation.property()) {
       case eCSSProperty_opacity: {
-        aStorage->SetAnimatedValue(iter.Key(),
-                                   animationValue.GetFloatValue());
+        auto lastValue = aStorage->GetAnimatedValue(iter.Key());
+        if (lastValue && lastValue->mOpacity == animationValue.GetFloatValue()) {
+          unchangedAnimations.AppendElement(iter.Key());
+        } else {
+          aStorage->SetAnimatedValue(iter.Key(),
+                                     animationValue.GetFloatValue());
+        }
         break;
       }
       case eCSSProperty_transform: {
         nsCSSValueSharedList* list = animationValue.GetCSSValueSharedListValue();
         const TransformData& transformData = animation.data().get_TransformData();
         nsPoint origin = transformData.origin();
         // we expect all our transform data to arrive in device pixels
         gfx::Point3D transformOrigin = transformData.transformOrigin();
@@ -550,22 +556,31 @@ AnimationHelper::SampleAnimations(Compos
         //   nsLayoutUtils::PostTranslate(transform, origin,
         //                                transformData.appUnitsPerDevPixel(),
         //                                true);
         // }
 
         // if (ContainerLayer* c = aLayer->AsContainerLayer()) {
         //   transform.PostScale(c->GetInheritedXScale(), c->GetInheritedYScale(), 1);
         // }
-
-        aStorage->SetAnimatedValue(iter.Key(),
-                                   Move(transform), Move(frameTransform),
-                                   transformData);
+        auto lastValue = aStorage->GetAnimatedValue(iter.Key());
+        if (lastValue &&
+            lastValue->mTransform.mTransformInDevSpace == transform) {
+          unchangedAnimations.AppendElement(iter.Key());
+        } else {
+          aStorage->SetAnimatedValue(iter.Key(), Move(transform),
+                                     Move(frameTransform), transformData);
+        }
         break;
       }
       default:
         MOZ_ASSERT_UNREACHABLE("Unhandled animated property");
     }
   }
+
+  // Clean up the unchanged animations
+  for (const uint64_t& key : unchangedAnimations) {
+    aStorage->ClearById(key);
+  }
 }
 
 } // namespace layers
 } // namespace mozilla