Bug 1430884 - Rename unthrottling transform animations stuff. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 25 Jun 2018 09:12:21 +0900
changeset 810017 e5e9a95746db9ca91b8f05288604ad246b5ccc17
parent 810016 66feb58808ee68a0bb5496e78ba825913ebc19b8
child 810018 c7487e49ecd79ef209f2e56b95c7946f7bd8ff47
child 810065 5af05ba17c1b1e5f7d3edfc2b6890182bbf54694
push id113862
push userhikezoe@mozilla.com
push dateMon, 25 Jun 2018 00:18:06 +0000
reviewersbirtles
bugs1430884
milestone62.0a1
Bug 1430884 - Rename unthrottling transform animations stuff. r?birtles In the next patch, we are going to unthrottle UpdateOverflow change hint which is also produced by non-transform properties. MozReview-Commit-ID: BrJxo32uBJO
dom/animation/EffectSet.h
dom/animation/KeyframeEffect.cpp
dom/animation/KeyframeEffect.h
--- a/dom/animation/EffectSet.h
+++ b/dom/animation/EffectSet.h
@@ -165,23 +165,23 @@ public:
   bool IsBeingEnumerated() const { return mActiveIterators != 0; }
 #endif
 
   bool IsEmpty() const { return mEffects.IsEmpty(); }
 
   size_t Count() const { return mEffects.Count(); }
 
 
-  const TimeStamp& LastTransformSyncTime() const
+  const TimeStamp& LastOverflowAnimationSyncTime() const
   {
-    return mLastTransformSyncTime;
+    return mLastOverflowAnimationSyncTime;
   }
-  void UpdateLastTransformSyncTime(const TimeStamp& aRefreshTime)
+  void UpdateLastOverflowAnimationSyncTime(const TimeStamp& aRefreshTime)
   {
-    mLastTransformSyncTime = aRefreshTime;
+    mLastOverflowAnimationSyncTime = aRefreshTime;
   }
 
   bool CascadeNeedsUpdate() const { return mCascadeNeedsUpdate; }
   void MarkCascadeNeedsUpdate() { mCascadeNeedsUpdate = true; }
   void MarkCascadeUpdated() { mCascadeNeedsUpdate = false; }
 
   void UpdateAnimationGeneration(nsPresContext* aPresContext);
   uint64_t GetAnimationGeneration() const { return mAnimationGeneration; }
@@ -202,21 +202,24 @@ public:
   }
 
 private:
   static nsAtom* GetEffectSetPropertyAtom(CSSPseudoElementType aPseudoType);
 
   OwningEffectSet mEffects;
 
 
-  // Refresh driver timestamp from the moment when transform animations in this
-  // effect set were last updated and sent to the compositor. This is used for
-  // transform animations that run on the compositor but need to be updated on
-  // the main thread periodically (e.g. so scrollbars can be updated).
-  TimeStamp mLastTransformSyncTime;
+  // Refresh driver timestamp from the moment when the animations which produce
+  // overflow change hints in this effect set were last updated.
+
+  // This is used for animations whose main-thread restyling is throttled either
+  // because they are running on the compositor or because they are not visible.
+  // We still need to update them on the main thread periodically, however (e.g.
+  // so scrollbars can be updated), so this tracks the last time we did that.
+  TimeStamp mLastOverflowAnimationSyncTime;
 
   // Dirty flag to represent when the mPropertiesWithImportantRules and
   // mPropertiesForAnimationsLevel on effects in this set might need to be
   // updated.
   //
   // Set to true any time the set of effects is changed or when
   // one the effects goes in or out of the "in effect" state.
   bool mCascadeNeedsUpdate;
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -506,30 +506,30 @@ KeyframeEffect::ComposeStyle(
     MOZ_ASSERT(segment >= prop.mSegments.Elements() &&
                size_t(segment - prop.mSegments.Elements()) <
                  prop.mSegments.Length(),
                "out of array bounds");
 
     ComposeStyleRule(aComposeResult, prop, *segment, computedTiming);
   }
 
-  // If the animation produces a transform change hint that affects the overflow
-  // region, we need to record the current time to unthrottle the animation
+  // If the animation produces a change hint that affects the overflow region,
+  // we need to record the current time to unthrottle the animation
   // periodically when the animation is being throttled because it's scrolled
   // out of view.
-  if (HasTransformThatMightAffectOverflow()) {
+  if (HasPropertiesThatMightAffectOverflow()) {
     nsPresContext* presContext =
       nsContentUtils::GetContextForContent(mTarget->mElement);
     if (presContext) {
       TimeStamp now = presContext->RefreshDriver()->MostRecentRefresh();
       EffectSet* effectSet =
         EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
       MOZ_ASSERT(effectSet, "ComposeStyle should only be called on an effect "
                             "that is part of an effect set");
-      effectSet->UpdateLastTransformSyncTime(now);
+      effectSet->UpdateLastOverflowAnimationSyncTime(now);
     }
   }
 }
 
 bool
 KeyframeEffect::IsRunningOnCompositor() const
 {
   // We consider animation is running on compositor if there is at least
@@ -1226,29 +1226,28 @@ KeyframeEffect::CanThrottle() const
     if (presShell && !presShell->IsActive()) {
       return true;
     }
 
     const bool isVisibilityHidden =
       !frame->IsVisibleOrMayHaveVisibleDescendants();
     if ((isVisibilityHidden && !HasVisibilityChange()) ||
         frame->IsScrolledOutOfView()) {
-      // If there are transform change hints, unthrottle the animation
-      // periodically since it might affect the overflow region.
-      if (HasTransformThatMightAffectOverflow()) {
-        // Don't throttle finite transform animations since the animation might
-        // suddenly come into view and if it was throttled it will be
-        // out-of-sync.
+      // 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
-          ? CanThrottleTransformChangesInScrollable(*frame)
-          : CanThrottleTransformChanges(*frame);
+          ? CanThrottleOverflowChangesInScrollable(*frame)
+          : CanThrottleOverflowChanges(*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
@@ -1274,50 +1273,50 @@ KeyframeEffect::CanThrottle() const
         GetPrimaryFrame(), record.mLayerType);
     // Unthrottle if the animation needs to be brought up to date
     if (!generation || effectSet->GetAnimationGeneration() != *generation) {
       return false;
     }
 
     // If this is a transform animation that affects the overflow region,
     // we should unthrottle the animation periodically.
-    if (HasTransformThatMightAffectOverflow() &&
-        !CanThrottleTransformChangesInScrollable(*frame)) {
+    if (HasPropertiesThatMightAffectOverflow() &&
+        !CanThrottleOverflowChangesInScrollable(*frame)) {
       return false;
     }
   }
 
   for (const AnimationProperty& property : mProperties) {
     if (!property.mIsRunningOnCompositor) {
       return false;
     }
   }
 
   return true;
 }
 
 bool
-KeyframeEffect::CanThrottleTransformChanges(const nsIFrame& aFrame) const
+KeyframeEffect::CanThrottleOverflowChanges(const nsIFrame& aFrame) const
 {
   TimeStamp now = aFrame.PresContext()->RefreshDriver()->MostRecentRefresh();
 
   EffectSet* effectSet = EffectSet::GetEffectSet(mTarget->mElement,
                                                  mTarget->mPseudoType);
-  MOZ_ASSERT(effectSet, "CanThrottleTransformChanges is expected to be called"
+  MOZ_ASSERT(effectSet, "CanOverflowTransformChanges is expected to be called"
                         " on an effect in an effect set");
-  MOZ_ASSERT(mAnimation, "CanThrottleTransformChanges is expected to be called"
+  MOZ_ASSERT(mAnimation, "CanOverflowTransformChanges is expected to be called"
                          " on an effect with a parent animation");
-  TimeStamp lastSyncTime = effectSet->LastTransformSyncTime();
+  TimeStamp lastSyncTime = effectSet->LastOverflowAnimationSyncTime();
   // If this animation can cause overflow, we can throttle some of the ticks.
   return (!lastSyncTime.IsNull() &&
     (now - lastSyncTime) < OverflowRegionRefreshInterval());
 }
 
 bool
-KeyframeEffect::CanThrottleTransformChangesInScrollable(nsIFrame& aFrame) const
+KeyframeEffect::CanThrottleOverflowChangesInScrollable(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;
   }
 
@@ -1328,17 +1327,17 @@ KeyframeEffect::CanThrottleTransformChan
 
   // 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)) {
+  if (CanThrottleOverflowChanges(aFrame)) {
     return true;
   }
 
   // If we have any intersection observers, we unthrottle this transform
   // animation periodically.
   if (hasIntersectionObservers) {
     return false;
   }
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -416,18 +416,18 @@ private:
     const ComputedStyle* aBaseComputedStyle);
 
   // 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 CanThrottleTransformChanges(const nsIFrame& aFrame) const;
-  bool CanThrottleTransformChangesInScrollable(nsIFrame& aFrame) const;
+  bool CanThrottleOverflowChanges(const nsIFrame& aFrame) const;
+  bool CanThrottleOverflowChangesInScrollable(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|.
@@ -435,21 +435,21 @@ private:
     const nsIFrame* aFrame,
     AnimationPerformanceWarning::Type& aPerformanceWarning);
   static bool IsGeometricProperty(const nsCSSPropertyID aProperty);
 
   static const TimeDuration OverflowRegionRefreshInterval();
 
   void UpdateEffectSet(mozilla::EffectSet* aEffectSet = nullptr) const;
 
-  // Returns true if this effect has transform and the transform might affect
-  // the overflow region.
+  // Returns true if this effect has properties that might affect the overflow
+  // region.
   // This function is used for updating scroll bars or notifying intersection
   // observers reflected by the transform.
-  bool HasTransformThatMightAffectOverflow() const
+  bool HasPropertiesThatMightAffectOverflow() const
   {
     return mCumulativeChangeHint & (nsChangeHint_UpdatePostTransformOverflow |
                                     nsChangeHint_AddOrRemoveTransform |
                                     nsChangeHint_UpdateTransformLayer);
   }
 
   // Returns true if this effect causes visibility change.
   // (i.e. 'visibility: hidden' -> 'visibility: visible' and vice versa.)