From 364d06998b8c1865d75d1cbabce2b82f7f36b9b6 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Thu, 24 Jul 2014 21:35:34 -0700 Subject: [PATCH] Bug 996796 patch 3 - Move the knowledge of when we last updated main-thread-suppressed animation styles into the restyle manager rather than have two separate but always equal timestamps for animations and transitions. r=birtles --- layout/base/RestyleManager.cpp | 8 ++++++ layout/base/RestyleManager.h | 9 +++++- layout/base/nsPresContext.cpp | 43 +++++++--------------------- layout/base/nsPresContext.h | 8 ------ layout/style/nsAnimationManager.cpp | 8 ------ layout/style/nsTransitionManager.cpp | 10 ++----- 6 files changed, 28 insertions(+), 58 deletions(-) diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 7467f6c69670..71ea02c24595 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -52,6 +52,8 @@ RestyleManager::RestyleManager(nsPresContext* aPresContext) , mInStyleRefresh(false) , mHoverGeneration(0) , mRebuildAllExtraHint(nsChangeHint(0)) + , mLastUpdateForThrottledAnimations(aPresContext->RefreshDriver()-> + MostRecentRefresh()) , mAnimationGeneration(0) , mPendingRestyles(ELEMENT_HAS_PENDING_RESTYLE | ELEMENT_IS_POTENTIAL_RESTYLE_ROOT) @@ -1531,6 +1533,12 @@ RestyleManager::EndProcessingRestyles() void RestyleManager::UpdateOnlyAnimationStyles() { + TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh(); + if (mLastUpdateForThrottledAnimations == now) { + return; + } + mLastUpdateForThrottledAnimations = now; + mPresContext->TransitionManager()->UpdateAllThrottledStyles(); mPresContext->AnimationManager()->UpdateAllThrottledStyles(); } diff --git a/layout/base/RestyleManager.h b/layout/base/RestyleManager.h index 0dbc682f531a..f11adbad938b 100644 --- a/layout/base/RestyleManager.h +++ b/layout/base/RestyleManager.h @@ -15,9 +15,9 @@ #include "nsChangeHint.h" #include "RestyleTracker.h" #include "nsPresContext.h" +#include "nsRefreshDriver.h" class nsIFrame; -class nsRefreshDriver; class nsStyleChangeList; struct TreeMatchContext; @@ -166,6 +166,11 @@ public: // out-of-date. void UpdateOnlyAnimationStyles(); + bool ThrottledAnimationStyleIsUpToDate() const { + return mLastUpdateForThrottledAnimations == + mPresContext->RefreshDriver()->MostRecentRefresh(); + } + // 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. @@ -270,6 +275,8 @@ private: uint32_t mHoverGeneration; nsChangeHint mRebuildAllExtraHint; + mozilla::TimeStamp mLastUpdateForThrottledAnimations; + OverflowChangedTracker mOverflowChangedTracker; // The total number of animation flushes by this frame constructor. diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index ffe60141057c..f645f8590926 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -968,10 +968,9 @@ nsPresContext::Init(nsDeviceContext* aDeviceContext) mAnimationManager = new nsAnimationManager(this); - // Since there are methods in nsPresContext have the same name as the - // classes, it is necessary to prefix them with the namespace here. - mRestyleManager = new mozilla::RestyleManager(this); - + // Since CounterStyleManager is also the name of a method of + // nsPresContext, it is necessary to prefix the class with the mozilla + // namespace here. mCounterStyleManager = new mozilla::CounterStyleManager(this); if (mDocument->GetDisplayDocument()) { @@ -1017,9 +1016,13 @@ nsPresContext::Init(nsDeviceContext* aDeviceContext) } // Initialise refresh tick counters for OMTA - mLastStyleUpdateForAllAnimations = - mLastUpdateThrottledAnimationStyle = - mLastUpdateThrottledTransitionStyle = mRefreshDriver->MostRecentRefresh(); + mLastStyleUpdateForAllAnimations = mRefreshDriver->MostRecentRefresh(); + + // Initialize restyle manager after initializing the refresh driver. + // Since RestyleManager is also the name of a method of nsPresContext, + // it is necessary to prefix the class with the mozilla namespace + // here. + mRestyleManager = new mozilla::RestyleManager(this); mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); @@ -1551,32 +1554,6 @@ nsPresContext::Detach() } } -bool -nsPresContext::ThrottledTransitionStyleIsUpToDate() const -{ - return - mLastUpdateThrottledTransitionStyle == mRefreshDriver->MostRecentRefresh(); -} - -void -nsPresContext::TickLastUpdateThrottledTransitionStyle() -{ - mLastUpdateThrottledTransitionStyle = mRefreshDriver->MostRecentRefresh(); -} - -bool -nsPresContext::ThrottledAnimationStyleIsUpToDate() const -{ - return - mLastUpdateThrottledAnimationStyle == mRefreshDriver->MostRecentRefresh(); -} - -void -nsPresContext::TickLastUpdateThrottledAnimationStyle() -{ - mLastUpdateThrottledAnimationStyle = mRefreshDriver->MostRecentRefresh(); -} - bool nsPresContext::StyleUpdateForAllAnimationsIsUpToDate() { diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 036b15627a6e..5ac784adc4f4 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -688,10 +688,6 @@ public: /** * Getter and setter for OMTA time counters */ - bool ThrottledTransitionStyleIsUpToDate() const; - void TickLastUpdateThrottledTransitionStyle(); - bool ThrottledAnimationStyleIsUpToDate() const; - void TickLastUpdateThrottledAnimationStyle(); bool StyleUpdateForAllAnimationsIsUpToDate(); void TickLastStyleUpdateForAllAnimations(); @@ -1282,10 +1278,6 @@ protected: mozilla::TimeStamp mReflowStartTime; - // last time animations styles were flushed to their primary frames - mozilla::TimeStamp mLastUpdateThrottledAnimationStyle; - // last time transition styles were flushed to their primary frames - mozilla::TimeStamp mLastUpdateThrottledTransitionStyle; // last time we did a full style flush mozilla::TimeStamp mLastStyleUpdateForAllAnimations; diff --git a/layout/style/nsAnimationManager.cpp b/layout/style/nsAnimationManager.cpp index 7942ee501a99..09b68026bfb4 100644 --- a/layout/style/nsAnimationManager.cpp +++ b/layout/style/nsAnimationManager.cpp @@ -822,17 +822,9 @@ nsAnimationManager::UpdateAllThrottledStyles() { if (PR_CLIST_IS_EMPTY(&mElementCollections)) { // no throttled animations, leave early - mPresContext->TickLastUpdateThrottledAnimationStyle(); return; } - if (mPresContext->ThrottledAnimationStyleIsUpToDate()) { - // throttled transitions are up to date, leave early - return; - } - - mPresContext->TickLastUpdateThrottledAnimationStyle(); - UpdateAllThrottledStylesInternal(); } diff --git a/layout/style/nsTransitionManager.cpp b/layout/style/nsTransitionManager.cpp index 6ce548b04f3c..7eabc311b826 100644 --- a/layout/style/nsTransitionManager.cpp +++ b/layout/style/nsTransitionManager.cpp @@ -118,16 +118,9 @@ nsTransitionManager::UpdateAllThrottledStyles() { if (PR_CLIST_IS_EMPTY(&mElementCollections)) { // no throttled transitions, leave early - mPresContext->TickLastUpdateThrottledTransitionStyle(); return; } - if (mPresContext->ThrottledTransitionStyleIsUpToDate()) { - // throttled transitions are up to date, leave early - return; - } - - mPresContext->TickLastUpdateThrottledTransitionStyle(); UpdateAllThrottledStylesInternal(); } @@ -223,7 +216,8 @@ nsTransitionManager::StyleContextChanged(dom::Element *aElement, } NS_WARN_IF_FALSE(!nsLayoutUtils::AreAsyncAnimationsEnabled() || - mPresContext->ThrottledTransitionStyleIsUpToDate(), + mPresContext->RestyleManager()-> + ThrottledAnimationStyleIsUpToDate(), "throttled animations not up to date"); // Per http://lists.w3.org/Archives/Public/www-style/2009Aug/0109.html