Bug 1067769 - Part 1: Avoid doing RequestRestyle and mutation batch for null target. r=birtles draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 28 Apr 2016 23:22:42 +0800
changeset 357387 2f9125f71f67a3d50f2126fed4d1b459d938de22
parent 357368 4292da9df16b220f30921100282264a34cd2ff03
child 357388 4ba2d616d6b2cdfe7985ced29e4454e818d076b8
push id16759
push userbchiou@mozilla.com
push dateThu, 28 Apr 2016 15:27:13 +0000
reviewersbirtles
bugs1067769
milestone49.0a1
Bug 1067769 - Part 1: Avoid doing RequestRestyle and mutation batch for null target. r=birtles We don't need to restyle if mTarget is nullptr, so skip it. For nsAutoAnimationMutationBatch, we also skip it if mTarget is nullptr. AnimationColletion, nsAnimationManager and nsTransitionManger are for CSS Animations and CSS Transtions, so the effect should have an effective target. Therefore, I think we don't have to revise them for nsAutoAnimationMutationBatch. MozReview-Commit-ID: Egzr1QVEa0v
dom/animation/KeyframeEffect.cpp
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -184,17 +184,17 @@ KeyframeEffectReadOnly::NotifyAnimationT
   // Bug 1216843: When we implement iteration composite modes, we need to
   // also detect if the current iteration has changed.
   if (mAnimation && GetComputedTiming().mProgress != mProgressOnLastCompose) {
     EffectCompositor::RestyleType restyleType =
       CanThrottle() ?
       EffectCompositor::RestyleType::Throttled :
       EffectCompositor::RestyleType::Standard;
     nsPresContext* presContext = GetPresContext();
-    if (presContext) {
+    if (presContext && mTarget) {
       presContext->EffectCompositor()->
         RequestRestyle(mTarget, mPseudoType, restyleType,
                        mAnimation->CascadeLevel());
     }
 
     // If we're not relevant, we will have been removed from the EffectSet.
     // As a result, when the restyle we requested above is fulfilled, our
     // ComposeStyle will not get called and mProgressOnLastCompose will not
@@ -558,25 +558,25 @@ KeyframeEffectReadOnly::UpdateProperties
       runningOnCompositorProperties.HasProperty(property.mProperty);
   }
 
   if (mTarget) {
     EffectSet* effectSet = EffectSet::GetEffectSet(mTarget, mPseudoType);
     if (effectSet) {
       effectSet->MarkCascadeNeedsUpdate();
     }
-  }
 
-  if (mAnimation) {
-    nsPresContext* presContext = GetPresContext();
-    if (presContext) {
-      presContext->EffectCompositor()->
-        RequestRestyle(mTarget, mPseudoType,
-                       EffectCompositor::RestyleType::Layer,
-                       mAnimation->CascadeLevel());
+    if (mAnimation) {
+      nsPresContext* presContext = GetPresContext();
+      if (presContext) {
+        presContext->EffectCompositor()->
+          RequestRestyle(mTarget, mPseudoType,
+                         EffectCompositor::RestyleType::Layer,
+                         mAnimation->CascadeLevel());
+      }
     }
   }
 }
 
 void
 KeyframeEffectReadOnly::ComposeStyle(RefPtr<AnimValuesStyleRule>& aStyleRule,
                                      nsCSSPropertySet& aSetProperties)
 {
@@ -1354,27 +1354,28 @@ KeyframeEffect::Constructor(
 {
   return ConstructKeyframeEffect<KeyframeEffect>(aGlobal, aTarget, aFrames,
                                                  aOptions, aRv);
 }
 
 void KeyframeEffect::NotifySpecifiedTimingUpdated()
 {
   // Use the same document for a pseudo element and its parent element.
-  nsAutoAnimationMutationBatch mb(mTarget->OwnerDoc());
+  // Use nullptr if we don't have mTarget, so disable the mutation batch.
+  nsAutoAnimationMutationBatch mb(mTarget ? mTarget->OwnerDoc() : nullptr);
 
   if (mAnimation) {
     mAnimation->NotifyEffectTimingUpdated();
 
     if (mAnimation->IsRelevant()) {
       nsNodeUtils::AnimationChanged(mAnimation);
     }
 
     nsPresContext* presContext = GetPresContext();
-    if (presContext) {
+    if (presContext && mTarget) {
       presContext->EffectCompositor()->
         RequestRestyle(mTarget, mPseudoType,
                        EffectCompositor::RestyleType::Layer,
                        mAnimation->CascadeLevel());
     }
   }
 }