Bug 1419339 - Unthrottle transform animations periodically if there is any IntersectionObservers. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 07 Feb 2018 10:46:15 +0900
changeset 751922 43a14041905e5f764a54a7fe6ffe4c6223d92c02
parent 751903 e1954b02d9e39bdb7c1f17aa95ca9cad5d5c14ae
push id98088
push userhikezoe@mozilla.com
push dateWed, 07 Feb 2018 03:03:59 +0000
reviewersbirtles
bugs1419339
milestone60.0a1
Bug 1419339 - Unthrottle transform animations periodically if there is any IntersectionObservers. r?birtles MozReview-Commit-ID: CBFQva02HUc
dom/animation/KeyframeEffectReadOnly.cpp
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -1529,28 +1529,45 @@ KeyframeEffectReadOnly::CanThrottleTrans
   // If this animation can cause overflow, we can throttle some of the ticks.
   return (!lastSyncTime.IsNull() &&
     (now - lastSyncTime) < OverflowRegionRefreshInterval());
 }
 
 bool
 KeyframeEffectReadOnly::CanThrottleTransformChangesForCompositor(nsIFrame& aFrame) const
 {
+  // If the target element is not associated with any documents, we don't care
+  // it.
+  nsIDocument* doc = GetRenderedDocument();
+  if (!doc) {
+    return true;
+  }
+
+  bool hasIntersectionObservers = doc->HasIntersectionObservers();
+
   // If we know that the animation cannot cause overflow,
   // we can just disable flushes for this animation.
 
-  // If we don't show scrollbars, we don't care about overflow.
-  if (LookAndFeel::GetInt(LookAndFeel::eIntID_ShowHideScrollbars) == 0) {
+  // If we don't show scrollbars and have no intersection observers, we don't
+  // care about overflow.
+  if (LookAndFeel::GetInt(LookAndFeel::eIntID_ShowHideScrollbars) == 0 &&
+      !hasIntersectionObservers) {
     return true;
   }
 
   if (CanThrottleTransformChanges(aFrame)) {
     return true;
   }
 
+  // If we have any intersection observers, we unthrottle this transform
+  // animation periodically.
+  if (hasIntersectionObservers) {
+    return false;
+  }
+
   // If the nearest scrollable ancestor has overflow:hidden,
   // we don't care about overflow.
   nsIScrollableFrame* scrollable =
     nsLayoutUtils::GetNearestScrollableFrame(&aFrame);
   if (!scrollable) {
     return true;
   }