Bug 1430884 - Factor out checking the animation on the given frame can be throttled if the frame is not visible. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 22 Jun 2018 13:27:20 +0900
changeset 809447 7ff1a1cc8ab7eaba6509249a949e9f00b1f418dc
parent 809446 81a5920f558d833eee437e25ba064fcf0be46b63
child 809448 de2debd37de01bf29005642823b807e63b773afe
push id113680
push userhikezoe@mozilla.com
push dateFri, 22 Jun 2018 04:33:20 +0000
reviewersbirtles
bugs1430884
milestone62.0a1
Bug 1430884 - Factor out checking the animation on the given frame can be throttled if the frame is not visible. r?birtles MozReview-Commit-ID: Kl7qYFXiVqr
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffect.h
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -1189,16 +1189,51 @@ KeyframeEffect::OverflowRegionRefreshInt
   // on the main thread that influence the overflow region.
   static const TimeDuration kOverflowRegionRefreshInterval =
     TimeDuration::FromMilliseconds(200);
 
   return kOverflowRegionRefreshInterval;
 }
 
 bool
+KeyframeEffect::CanThrottleIfNotVisible(nsIFrame& aFrame) const
+{
+  // Unless we are newly in-effect, we can throttle the animation if the
+  // animation is paint only and the target frame is out of view or the document
+  // is in background tabs.
+  if (mInEffectOnLastAnimationTimingUpdate && CanIgnoreIfNotVisible()) {
+    nsIPresShell* presShell = GetPresShell();
+    if (presShell && !presShell->IsActive()) {
+      return true;
+    }
+
+    const bool isVisibilityHidden =
+      !aFrame.IsVisibleOrMayHaveVisibleDescendants();
+    if ((isVisibilityHidden && !HasVisibilityChange()) ||
+        aFrame.IsScrolledOutOfView()) {
+      // Unthrottle the animation if there is a change hint that might affect
+      // the overflow region.
+      if (HasPropertiesThatMightAffectOverflow()) {
+        // Don't throttle finite animations since the animation might suddenly
+        // come into view and if it was throttled it will be out-of-sync.
+        if (HasFiniteActiveDuration()) {
+          return false;
+        }
+
+        return isVisibilityHidden
+          ? CanThrottleOverflowChangesInScrollable(aFrame)
+          : CanThrottleOverflowChanges(aFrame);
+      }
+      return true;
+    }
+  }
+  return false;
+}
+
+bool
 KeyframeEffect::CanThrottle() const
 {
   // Unthrottle if we are not in effect or current. This will be the case when
   // our owning animation has finished, is idle, or when we are in the delay
   // phase (but without a backwards fill). In each case the computed progress
   // value produced on each tick will be the same so we will skip requesting
   // unnecessary restyles in NotifyAnimationTimingUpdated. Any calls we *do* get
   // here will be because of a change in state (e.g. we are newly finished or
@@ -1213,44 +1248,18 @@ KeyframeEffect::CanThrottle() const
     // a) No target element
     // b) The target element has no frame, e.g. because it is in a display:none
     //    subtree.
     // In either case we can throttle the animation because there is no
     // need to update on the main thread.
     return true;
   }
 
-  // Unless we are newly in-effect, we can throttle the animation if the
-  // animation is paint only and the target frame is out of view or the document
-  // is in background tabs.
-  if (mInEffectOnLastAnimationTimingUpdate && CanIgnoreIfNotVisible()) {
-    nsIPresShell* presShell = GetPresShell();
-    if (presShell && !presShell->IsActive()) {
-      return true;
-    }
-
-    const bool isVisibilityHidden =
-      !frame->IsVisibleOrMayHaveVisibleDescendants();
-    if ((isVisibilityHidden && !HasVisibilityChange()) ||
-        frame->IsScrolledOutOfView()) {
-      // Unthrottle the animation if there is a change hint that might affect
-      // the overflow region.
-      if (HasPropertiesThatMightAffectOverflow()) {
-        // Don't throttle finite animations since the animation might suddenly
-        // come into view and if it was throttled it will be out-of-sync.
-        if (HasFiniteActiveDuration()) {
-          return false;
-        }
-
-        return isVisibilityHidden
-          ? CanThrottleOverflowChangesInScrollable(*frame)
-          : CanThrottleOverflowChanges(*frame);
-      }
-      return true;
-    }
+  if (CanThrottleIfNotVisible(*frame)) {
+    return true;
   }
 
   // First we need to check layer generation and transform overflow
   // prior to the property.mIsRunningOnCompositor check because we should
   // occasionally unthrottle these animations even if the animations are
   // already running on compositor.
   for (const LayerAnimationInfo::Record& record :
         LayerAnimationInfo::sRecords) {
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -418,16 +418,17 @@ private:
   // Return the primary frame for the target (pseudo-)element.
   nsIFrame* GetPrimaryFrame() const;
   // Returns the frame which is used for styling.
   nsIFrame* GetStyleFrame() const;
 
   bool CanThrottle() const;
   bool CanThrottleOverflowChanges(const nsIFrame& aFrame) const;
   bool CanThrottleOverflowChangesInScrollable(nsIFrame& aFrame) const;
+  bool CanThrottleIfNotVisible(nsIFrame& aFrame) const;
 
   // Returns true if the computedTiming has changed since the last
   // composition.
   bool HasComputedTimingChanged() const;
 
   // Returns true unless Gecko limitations prevent performing transform
   // animations for |aFrame|. When returning true, the reason for the
   // limitation is stored in |aOutPerformanceWarning|.