Bug 1343753 - Part 6: Move mAnimationGeneration into RestyleManager.
So stylo can also use mAnimationGeneration.
MozReview-Commit-ID: KTc8vs2RKMm
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -277,24 +277,19 @@ EffectCompositor::RequestRestyle(dom::El
if (!hasPendingRestyle) {
PostRestyleForAnimation(aElement, aPseudoType, aCascadeLevel);
}
elementsToRestyle.Put(key, true);
}
if (aRestyleType == RestyleType::Layer) {
// FIXME: Bug 1334036: we call RequestRestyle for both stylo and gecko,
- // so we should fix this after supporting animations on the compositor.
- if (mPresContext->RestyleManager()->IsServo()) {
- NS_WARNING("stylo: RequestRestyle to layer, but Servo-backed style "
- "system haven't supported compositor-driven animations yet");
- return;
- }
+ // so we should make sure we use mAnimationGecneration properly on OMTA.
// Prompt layers to re-sync their animations.
- mPresContext->RestyleManager()->AsGecko()->IncrementAnimationGeneration();
+ mPresContext->RestyleManager()->IncrementAnimationGeneration();
EffectSet* effectSet =
EffectSet::GetEffectSet(aElement, aPseudoType);
if (effectSet) {
effectSet->UpdateAnimationGeneration(mPresContext);
}
}
}
--- a/dom/animation/EffectSet.cpp
+++ b/dom/animation/EffectSet.cpp
@@ -106,21 +106,18 @@ EffectSet::DestroyEffectSet(dom::Element
effectSet = nullptr;
aElement->DeleteProperty(propName);
}
void
EffectSet::UpdateAnimationGeneration(nsPresContext* aPresContext)
{
- MOZ_ASSERT(aPresContext->RestyleManager()->IsGecko(),
- "stylo: Servo-backed style system should not be using "
- "EffectSet");
mAnimationGeneration =
- aPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration();
+ aPresContext->RestyleManager()->GetAnimationGeneration();
}
/* static */ nsIAtom**
EffectSet::GetEffectSetPropertyAtoms()
{
static nsIAtom* effectSetPropertyAtoms[] =
{
nsGkAtoms::animationEffectsProperty,
--- a/layout/base/GeckoRestyleManager.cpp
+++ b/layout/base/GeckoRestyleManager.cpp
@@ -86,17 +86,16 @@ ElementTagToString(dom::Element* aElemen
GeckoRestyleManager::GeckoRestyleManager(nsPresContext* aPresContext)
: RestyleManager(StyleBackendType::Gecko, aPresContext)
, mDoRebuildAllStyleData(false)
, mInRebuildAllStyleData(false)
, mSkipAnimationRules(false)
, mHavePendingNonAnimationRestyles(false)
, mRebuildAllExtraHint(nsChangeHint(0))
, mRebuildAllRestyleHint(nsRestyleHint(0))
- , mAnimationGeneration(0)
, mReframingStyleContexts(nullptr)
, mPendingRestyles(ELEMENT_HAS_PENDING_RESTYLE |
ELEMENT_IS_POTENTIAL_RESTYLE_ROOT |
ELEMENT_IS_CONDITIONAL_RESTYLE_ANCESTOR)
, mIsProcessingRestyles(false)
#ifdef RESTYLE_LOGGING
, mLoggingDepth(0)
#endif
@@ -328,23 +327,16 @@ GeckoRestyleManager::AttributeChanged(El
aAttribute,
aModType,
true,
aOldValue,
rsdata);
PostRestyleEvent(aElement, rshint, hint, &rsdata);
}
-/* static */ uint64_t
-GeckoRestyleManager::GetAnimationGenerationForFrame(nsIFrame* aFrame)
-{
- EffectSet* effectSet = EffectSet::GetEffectSet(aFrame);
- return effectSet ? effectSet->GetAnimationGeneration() : 0;
-}
-
void
GeckoRestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
nsRestyleHint aRestyleHint)
{
NS_ASSERTION(!(aExtraHint & nsChangeHint_ReconstructFrame),
"Should not reconstruct the root of the frame tree. "
"Use ReconstructDocElementHierarchy instead.");
MOZ_ASSERT(!(aRestyleHint & ~(eRestyle_Subtree | eRestyle_ForceDescendants)),
--- a/layout/base/GeckoRestyleManager.h
+++ b/layout/base/GeckoRestyleManager.h
@@ -66,37 +66,16 @@ public:
// Forwarded nsIMutationObserver method, to handle restyling (and
// passing the notification to the frame).
void AttributeChanged(Element* aElement,
int32_t aNameSpaceID,
nsIAtom* aAttribute,
int32_t aModType,
const nsAttrValue* aOldValue);
- // 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);
-
- // Update the animation generation count to mark that animation state
- // has changed.
- //
- // This is normally performed automatically by ProcessPendingRestyles
- // but it is also called when we have out-of-band changes to animations
- // such as changes made through the Web Animations API.
- void IncrementAnimationGeneration() {
- // We update the animation generation at start of each call to
- // ProcessPendingRestyles so we should ignore any subsequent (redundant)
- // calls that occur while we are still processing restyles.
- if (!mIsProcessingRestyles) {
- ++mAnimationGeneration;
- }
- }
-
// Whether rule matching should skip styles associated with animation
bool SkipAnimationRules() const { return mSkipAnimationRules; }
void SetSkipAnimationRules(bool aSkipAnimationRules) {
mSkipAnimationRules = aSkipAnimationRules;
}
/**
@@ -350,16 +329,18 @@ public:
// function returns a bitfield of the structs named in the
// environment variable.
static uint32_t StructsToLog();
static nsCString StructNamesToString(uint32_t aSIDs);
int32_t& LoggingDepth() { return mLoggingDepth; }
#endif
+ bool IsProcessingRestyles() { return mIsProcessingRestyles; }
+
private:
inline nsStyleSet* StyleSet() const {
MOZ_ASSERT(PresContext()->StyleSet()->IsGecko(),
"GeckoRestyleManager should only be used with a Gecko-flavored "
"style backend");
return PresContext()->StyleSet()->AsGecko();
}
@@ -399,20 +380,16 @@ private:
bool mInRebuildAllStyleData : 1;
// Whether rule matching should skip styles associated with animation
bool mSkipAnimationRules : 1;
bool mHavePendingNonAnimationRestyles : 1;
nsChangeHint mRebuildAllExtraHint;
nsRestyleHint mRebuildAllRestyleHint;
- // The total number of animation flushes by this frame constructor.
- // Used to keep the layer and animation manager in sync.
- uint64_t mAnimationGeneration;
-
ReframingStyleContexts* mReframingStyleContexts;
RestyleTracker mPendingRestyles;
// Are we currently in the middle of a call to ProcessRestyles?
// This flag is used both as a debugging aid to assert that we are not
// performing nested calls to ProcessPendingRestyles, as well as to ignore
// redundant calls to IncrementAnimationGeneration.
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -14,16 +14,17 @@ namespace mozilla {
RestyleManager::RestyleManager(StyleBackendType aType,
nsPresContext* aPresContext)
: mPresContext(aPresContext)
, mRestyleGeneration(1)
, mHoverGeneration(0)
, mType(aType)
, mInStyleRefresh(false)
+ , mAnimationGeneration(0)
{
MOZ_ASSERT(mPresContext);
}
void
RestyleManager::ContentInserted(nsINode* aContainer, nsIContent* aChild)
{
RestyleForInsertOrChange(aContainer, aChild);
@@ -1690,16 +1691,35 @@ RestyleManager::ProcessRestyledFrames(ns
"(and not a viewport frame)");
}
#endif
}
aChangeList.Clear();
}
+/* static */ uint64_t
+RestyleManager::GetAnimationGenerationForFrame(nsIFrame* aFrame)
+{
+ EffectSet* effectSet = EffectSet::GetEffectSet(aFrame);
+ return effectSet ? effectSet->GetAnimationGeneration() : 0;
+}
+
+void
+RestyleManager::IncrementAnimationGeneration()
+{
+ // We update the animation generation at start of each call to
+ // ProcessPendingRestyles so we should ignore any subsequent (redundant)
+ // calls that occur while we are still processing restyles.
+ if ((IsGecko() && !AsGecko()->IsProcessingRestyles()) ||
+ (IsServo() && !mInStyleRefresh)) {
+ ++mAnimationGeneration;
+ }
+}
+
RestyleManager::AnimationsWithDestroyedFrame::AnimationsWithDestroyedFrame(
RestyleManager* aRestyleManager)
: mRestyleManager(aRestyleManager)
, mRestorePointer(mRestyleManager->mAnimationsWithDestroyedFrame)
{
MOZ_ASSERT(!mRestyleManager->mAnimationsWithDestroyedFrame,
"shouldn't construct recursively");
mRestyleManager->mAnimationsWithDestroyedFrame = this;
--- a/layout/base/RestyleManager.h
+++ b/layout/base/RestyleManager.h
@@ -175,16 +175,30 @@ 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);
+ // 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);
+
+ // Update the animation generation count to mark that animation state
+ // has changed.
+ //
+ // This is normally performed automatically by ProcessPendingRestyles
+ // but it is also called when we have out-of-band changes to animations
+ // such as changes made through the Web Animations API.
+ void IncrementAnimationGeneration();
+
protected:
RestyleManager(StyleBackendType aType, nsPresContext* aPresContext);
virtual ~RestyleManager()
{
MOZ_ASSERT(!mAnimationsWithDestroyedFrame,
"leaving dangling pointers from AnimationsWithDestroyedFrame");
}
@@ -226,16 +240,20 @@ private:
uint32_t mHoverGeneration;
const StyleBackendType mType;
protected:
// True if we're in the middle of a nsRefreshDriver refresh
bool mInStyleRefresh;
+ // The total number of animation flushes by this frame constructor.
+ // Used to keep the layer and animation manager in sync.
+ uint64_t mAnimationGeneration;
+
OverflowChangedTracker mOverflowChangedTracker;
/**
* These are protected static methods that help with the change hint
* processing bits of the restyle managers.
*/
static nsIFrame*
GetNearestAncestorFrame(nsIContent* aContent);
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -778,17 +778,17 @@ nsDisplayListBuilder::AddAnimationsAndTr
}
// Update the animation generation on the layer. We need to do this before
// any early returns since even if we don't add any animations to the
// layer, we still need to mark it as up-to-date with regards to animations.
// Otherwise, in RestyleManager we'll notice the discrepancy between the
// animation generation numbers and update the layer indefinitely.
uint64_t animationGeneration =
- GeckoRestyleManager::GetAnimationGenerationForFrame(aFrame);
+ RestyleManager::GetAnimationGenerationForFrame(aFrame);
aLayer->SetAnimationGeneration(animationGeneration);
EffectCompositor::ClearIsRunningOnCompositor(aFrame, aProperty);
nsTArray<RefPtr<dom::Animation>> compositorAnimations =
EffectCompositor::GetAnimationsForCompositor(aFrame, aProperty);
if (compositorAnimations.IsEmpty()) {
return;
}
--- a/layout/style/AnimationCollection.cpp
+++ b/layout/style/AnimationCollection.cpp
@@ -133,22 +133,17 @@ AnimationCollection<AnimationType>::Pseu
}
}
template <class AnimationType>
void
AnimationCollection<AnimationType>::UpdateCheckGeneration(
nsPresContext* aPresContext)
{
- if (aPresContext->RestyleManager()->IsServo()) {
- // stylo: ServoRestyleManager does not support animations yet.
- return;
- }
- mCheckGeneration =
- aPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration();
+ mCheckGeneration = aPresContext->RestyleManager()->GetAnimationGeneration();
}
template<class AnimationType>
/*static*/ nsIAtom*
AnimationCollection<AnimationType>::GetPropertyAtomForPseudoType(
CSSPseudoElementType aPseudoType)
{
nsIAtom* propName = nullptr;
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -536,17 +536,17 @@ nsTransitionManager::StyleContextChanged
return;
}
MOZ_ASSERT(mPresContext->RestyleManager()->IsGecko(),
"ServoRestyleManager should not use nsTransitionManager "
"for transitions");
if (collection &&
collection->mCheckGeneration ==
- mPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration()) {
+ mPresContext->RestyleManager()->GetAnimationGeneration()) {
// When we start a new transition, we immediately post a restyle.
// If the animation generation on the collection is current, that
// means *this* is that restyle, since we bump the animation
// generation on the restyle manager whenever there's a real style
// change (i.e., one where mInAnimationOnlyStyleUpdate isn't true,
// which causes us to return above). Thus we shouldn't do anything.
return;
}
@@ -993,17 +993,17 @@ nsTransitionManager::ConsiderInitiatingT
"for transitions");
RefPtr<CSSTransition> animation =
new CSSTransition(mPresContext->Document()->GetScopeObject());
animation->SetOwningElement(
OwningElementRef(*aElement, aNewStyleContext->GetPseudoType()));
animation->SetTimelineNoUpdate(timeline);
animation->SetCreationSequence(
- mPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration());
+ mPresContext->RestyleManager()->GetAnimationGeneration());
animation->SetEffectFromStyle(pt);
animation->PlayFromStyle();
if (!aElementTransitions) {
bool createdCollection = false;
aElementTransitions =
CSSTransitionCollection::GetOrCreateAnimationCollection(
aElement, aNewStyleContext->GetPseudoType(), &createdCollection);