Bug 1456003 - Don't allocate new AnimatedValue when we update AnimatedValue. r?kats draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 24 Apr 2018 15:13:10 +0900
changeset 787075 5a1c0a0d831c3733a40696e10e2843e1737bbd7e
parent 787074 ea9667541dbdb57015aa5118817554918a54d622
push id107626
push userhikezoe@mozilla.com
push dateTue, 24 Apr 2018 06:13:40 +0000
reviewerskats
bugs1456003
milestone61.0a1
Bug 1456003 - Don't allocate new AnimatedValue when we update AnimatedValue. r?kats We need to allocate new AnimatedValue only if there is no AnimatedValue corresponding to the id in the hashtable. MozReview-Commit-ID: HeRt74Tnojt
gfx/layers/AnimationHelper.cpp
--- a/gfx/layers/AnimationHelper.cpp
+++ b/gfx/layers/AnimationHelper.cpp
@@ -87,41 +87,52 @@ CompositorAnimationStorage::GetAnimation
 
 void
 CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
                                              gfx::Matrix4x4&& aTransformInDevSpace,
                                              gfx::Matrix4x4&& aFrameTransform,
                                              const TransformData& aData)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  AnimatedValue* value = new AnimatedValue(Move(aTransformInDevSpace),
-                                           Move(aFrameTransform),
-                                           aData);
-  mAnimatedValues.Put(aId, value);
+  auto count = mAnimatedValues.Count();
+  AnimatedValue* value = mAnimatedValues.LookupOrAdd(aId,
+                                                     Move(aTransformInDevSpace),
+                                                     Move(aFrameTransform),
+                                                     aData);
+  if (count == mAnimatedValues.Count()) {
+    MOZ_ASSERT(value->mType == AnimatedValue::TRANSFORM);
+    value->mTransform.mTransformInDevSpace = Move(aTransformInDevSpace);
+    value->mTransform.mFrameTransform = Move(aFrameTransform);
+    value->mTransform.mData = aData;
+  }
 }
 
 void
 CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
                                              gfx::Matrix4x4&& aTransformInDevSpace)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   const TransformData dontCare = {};
-  AnimatedValue* value = new AnimatedValue(Move(aTransformInDevSpace),
-                                           gfx::Matrix4x4(),
-                                           dontCare);
-  mAnimatedValues.Put(aId, value);
+  SetAnimatedValue(aId,
+                   Move(aTransformInDevSpace),
+                   Move(gfx::Matrix4x4()),
+                   dontCare);
 }
 
 void
 CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
                                              const float& aOpacity)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  AnimatedValue* value = new AnimatedValue(aOpacity);
-  mAnimatedValues.Put(aId, value);
+  auto count = mAnimatedValues.Count();
+  AnimatedValue* value = mAnimatedValues.LookupOrAdd(aId, aOpacity);
+  if (count == mAnimatedValues.Count()) {
+    MOZ_ASSERT(value->mType == AnimatedValue::OPACITY);
+    value->mOpacity = aOpacity;
+  }
 }
 
 AnimationArray*
 CompositorAnimationStorage::GetAnimations(const uint64_t& aId) const
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   return mAnimations.Get(aId);
 }