Bug 1388692 - Check that there are throttled animations instead of all type of animations for event handling. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 10 Aug 2017 06:43:43 +0900
changeset 645233 3de7a6517ef431320bccc3f8422844d0ec5e6047
parent 645232 4396a38627c265466b13be45368ff4ebca9c5baa
child 725864 a5217710bba2cff8ecf3c241c4c08667cb504ef9
push id73711
push userhikezoe@mozilla.com
push dateSat, 12 Aug 2017 01:34:00 +0000
reviewersbirtles
bugs1388692
milestone57.0a1
Bug 1388692 - Check that there are throttled animations instead of all type of animations for event handling. r?birtles MozReview-Commit-ID: BM9RzCfsJgR
layout/base/GeckoRestyleManager.cpp
layout/base/GeckoRestyleManager.h
layout/base/RestyleManager.h
layout/base/ServoRestyleManager.cpp
--- a/layout/base/GeckoRestyleManager.cpp
+++ b/layout/base/GeckoRestyleManager.cpp
@@ -675,16 +675,42 @@ GeckoRestyleManager::UpdateOnlyAnimation
   }
 
   ProcessRestyles(tracker);
 
   transitionManager->SetInAnimationOnlyStyleUpdate(false);
 }
 
 void
+GeckoRestyleManager::UpdateOnlyThrottledAnimationStyles()
+{
+  bool doCSS = PresContext()->EffectCompositor()->HasThrottledStyleUpdates();
+
+  if (!doCSS) {
+    return;
+  }
+
+  nsTransitionManager* transitionManager = PresContext()->TransitionManager();
+
+  transitionManager->SetInAnimationOnlyStyleUpdate(true);
+
+  RestyleTracker tracker(ELEMENT_HAS_PENDING_ANIMATION_ONLY_RESTYLE |
+                         ELEMENT_IS_POTENTIAL_ANIMATION_ONLY_RESTYLE_ROOT);
+  tracker.Init(this);
+
+  if (doCSS) {
+    PresContext()->EffectCompositor()->AddStyleUpdatesTo(tracker);
+  }
+
+  ProcessRestyles(tracker);
+
+  transitionManager->SetInAnimationOnlyStyleUpdate(false);
+}
+
+void
 GeckoRestyleManager::PostRestyleEventInternal()
 {
   // Make sure we're not in a style refresh; if we are, we still have
   // a call to ProcessPendingRestyles coming and there's no need to
   // add ourselves as a refresh observer until then.
   nsIPresShell* presShell = PresContext()->PresShell();
   if (!mInStyleRefresh) {
     presShell->ObserveStyleFlushes();
--- a/layout/base/GeckoRestyleManager.h
+++ b/layout/base/GeckoRestyleManager.h
@@ -238,22 +238,19 @@ private:
   // style for all throttled transitions and animations to the current
   // animation state without making any other updates, so that when we
   // process the queued style updates we'll have correct old data to
   // compare against.  When we do this, we don't bother touching frames
   // other than primary frames.
   void UpdateOnlyAnimationStyles();
 
 public:
-  void UpdateOnlyThrottledAnimationStyles()
-  {
-    // FIXME: For throttled animation flush, we don't need to flush all
-    // pending animations and SMIL animations.
-    UpdateOnlyAnimationStyles();
-  }
+  // Similar to UpdateOnlyAnimationStyles() but only update throtteld
+  // animations.
+  void UpdateOnlyThrottledAnimationStyles();
 
   // Rebuilds all style data by throwing out the old rule tree and
   // building a new one, and additionally applying aExtraHint (which
   // must not contain nsChangeHint_ReconstructFrame) to the root frame.
   //
   // aRestyleHint says which restyle hint to use for the computation;
   // the only sensible values to use are eRestyle_Subtree (which says
   // that the rebuild must run selector matching) and nsRestyleHint(0)
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -187,16 +187,19 @@ public:
                                   const nsAttrValue* aNewValue);
   inline void AttributeChanged(dom::Element* aElement,
                                int32_t aNameSpaceID,
                                nsIAtom* aAttribute,
                                int32_t aModType,
                                const nsAttrValue* aOldValue);
   inline nsresult ReparentStyleContext(nsIFrame* aFrame);
 
+  // The only one purpose of this function is to get correct elements' position
+  // which might be far from the positions that we know on the main-thread
+  // because of animations running on the compositor.
   inline void UpdateOnlyThrottledAnimationStyles();
 
   // Get a counter that increments on every style change, that we use to
   // track whether off-main-thread animations are up-to-date.
   uint64_t GetAnimationGeneration() const { return mAnimationGeneration; }
 
   static uint64_t GetAnimationGenerationForFrame(nsIFrame* aFrame);
 
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -1184,17 +1184,17 @@ ServoRestyleManager::ProcessPendingResty
 {
   DoProcessPendingRestyles(ServoTraversalFlags::Empty);
 }
 
 void
 ServoRestyleManager::UpdateOnlyThrottledAnimationStyles()
 {
   // Bug 1365855: We also need to implement this for SMIL.
-  bool doCSS = PresContext()->EffectCompositor()->HasPendingStyleUpdates();
+  bool doCSS = PresContext()->EffectCompositor()->HasThrottledStyleUpdates();
   if (!doCSS) {
     return;
   }
 
   DoProcessPendingRestyles(ServoTraversalFlags::AnimationOnly);
 }
 
 void