Bug 1371450 - Rename TraversalRestyleBehavior::ForAnimationOnly to TraversalRestyleBehavior::ForThrottledAnimationFlush. r?birtles,emilio
ForAnimationOnly is somewhat misleading, it means actually we process
*only* animation-only restyle without normal restyle. The purpose of
ForAnimationOnly is for updating throttled animations to get correct position
of the animations when we need to handle events. Currently we do also update
unthrottled animations though.
MozReview-Commit-ID: HBCCluKrZs9
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -761,49 +761,50 @@ ServoRestyleManager::DoProcessPendingRes
// Create a AnimationsWithDestroyedFrame during restyling process to
// stop animations and transitions on elements that have no frame at the end
// of the restyling process.
AnimationsWithDestroyedFrame animationsWithDestroyedFrame(this);
ServoStyleSet* styleSet = StyleSet();
nsIDocument* doc = PresContext()->Document();
- bool animationOnly = aRestyleBehavior ==
- TraversalRestyleBehavior::ForAnimationOnly;
+ bool forThrottledAnimationFlush =
+ aRestyleBehavior == TraversalRestyleBehavior::ForThrottledAnimationFlush;
// Ensure the refresh driver is active during traversal to avoid mutating
// mActiveTimer and mMostRecentRefresh time.
PresContext()->RefreshDriver()->MostRecentRefresh();
// Perform the Servo traversal, and the post-traversal if required. We do this
// in a loop because certain rare paths in the frame constructor (like
// uninstalling XBL bindings) can trigger additional style validations.
mInStyleRefresh = true;
- if (mHaveNonAnimationRestyles && !animationOnly) {
+ if (mHaveNonAnimationRestyles && !forThrottledAnimationFlush) {
++mAnimationGeneration;
}
TraversalRestyleBehavior restyleBehavior = mRestyleForCSSRuleChanges
? TraversalRestyleBehavior::ForCSSRuleChanges
: TraversalRestyleBehavior::Normal;
- while (animationOnly ? styleSet->StyleDocumentForAnimationOnly()
- : styleSet->StyleDocument(restyleBehavior)) {
- if (!animationOnly) {
+ while (forThrottledAnimationFlush
+ ? styleSet->StyleDocumentForThrottledAnimationFlush()
+ : styleSet->StyleDocument(restyleBehavior)) {
+ if (!forThrottledAnimationFlush) {
ClearSnapshots();
}
nsStyleChangeList currentChanges(StyleBackendType::Servo);
bool anyStyleChanged = false;
// Recreate style contexts, and queue up change hints (which also handle
// lazy frame construction).
{
AutoRestyleTimelineMarker marker(
- mPresContext->GetDocShell(), animationOnly);
+ mPresContext->GetDocShell(), forThrottledAnimationFlush);
DocumentStyleRootIterator iter(doc);
while (Element* root = iter.GetNextStyleRoot()) {
ServoRestyleState state(*styleSet, currentChanges);
anyStyleChanged |= ProcessPostTraversal(root, nullptr, state);
}
}
// Process the change hints.
@@ -846,17 +847,17 @@ ServoRestyleManager::DoProcessPendingRes
// In any case, we don't need to increment the restyle generation in that
// case.
IncrementRestyleGeneration();
}
}
FlushOverflowChangedTracker();
- if (!animationOnly) {
+ if (!forThrottledAnimationFlush) {
ClearSnapshots();
styleSet->AssertTreeIsClean();
mHaveNonAnimationRestyles = false;
}
mRestyleForCSSRuleChanges = false;
mInStyleRefresh = false;
// Now that everything has settled, see if we have enough free rule nodes in
@@ -879,17 +880,17 @@ void
ServoRestyleManager::UpdateOnlyAnimationStyles()
{
// Bug 1365855: We also need to implement this for SMIL.
bool doCSS = PresContext()->EffectCompositor()->HasPendingStyleUpdates();
if (!doCSS) {
return;
}
- DoProcessPendingRestyles(TraversalRestyleBehavior::ForAnimationOnly);
+ DoProcessPendingRestyles(TraversalRestyleBehavior::ForThrottledAnimationFlush);
}
void
ServoRestyleManager::ContentStateChanged(nsIContent* aContent,
EventStates aChangedBits)
{
MOZ_ASSERT(!mInStyleRefresh);
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -355,21 +355,21 @@ ServoStyleSet::PreTraverse(Element* aRoo
}
bool
ServoStyleSet::PrepareAndTraverseSubtree(
RawGeckoElementBorrowed aRoot,
TraversalRootBehavior aRootBehavior,
TraversalRestyleBehavior aRestyleBehavior)
{
- bool forAnimationOnly =
- aRestyleBehavior == TraversalRestyleBehavior::ForAnimationOnly;
+ bool forThrottledAnimationFlush =
+ aRestyleBehavior == TraversalRestyleBehavior::ForThrottledAnimationFlush;
AutoRestyleTimelineMarker marker(
- mPresContext->GetDocShell(), forAnimationOnly);
+ mPresContext->GetDocShell(), forThrottledAnimationFlush);
// Get the Document's root element to ensure that the cache is valid before
// calling into the (potentially-parallel) Servo traversal, where a cache hit
// is necessary to avoid a data race when updating the cache.
mozilla::Unused << aRoot->OwnerDoc()->GetRootElement();
MOZ_ASSERT(!StylistNeedsUpdate());
AutoSetInServoTraversal guard(this);
@@ -383,19 +383,22 @@ ServoStyleSet::PrepareAndTraverseSubtree
bool forNewlyBoundElement =
aRestyleBehavior == TraversalRestyleBehavior::ForNewlyBoundElement;
#endif
bool postTraversalRequired = Servo_TraverseSubtree(
aRoot, mRawSet.get(), &snapshots, aRootBehavior, aRestyleBehavior);
MOZ_ASSERT(!(isInitial || forReconstruct || forNewlyBoundElement) ||
!postTraversalRequired);
- // Don't need to trigger a second traversal if this restyle only needs
- // animation-only restyle.
- if (forAnimationOnly) {
+ // We don't need to trigger a second traversal if this restyle only for
+ // flushing throttled animations. That's because the first traversal only
+ // performs the animation-only restyle, skipping the normal restyle, and so
+ // will not generate any SequentialTask that could update animation state
+ // requiring a subsequent traversal.
+ if (forThrottledAnimationFlush) {
return postTraversalRequired;
}
auto root = const_cast<Element*>(aRoot);
// If there are still animation restyles needed, trigger a second traversal to
// update CSS animations or transitions' styles.
//
@@ -916,26 +919,27 @@ ServoStyleSet::StyleDocument(TraversalRe
aRestyleBehavior)) {
postTraversalRequired = true;
}
}
return postTraversalRequired;
}
bool
-ServoStyleSet::StyleDocumentForAnimationOnly()
+ServoStyleSet::StyleDocumentForThrottledAnimationFlush()
{
PreTraverse(nullptr, EffectCompositor::AnimationRestyleType::Full);
bool postTraversalRequired = false;
DocumentStyleRootIterator iter(mPresContext->Document());
while (Element* root = iter.GetNextStyleRoot()) {
- if (PrepareAndTraverseSubtree(root,
- TraversalRootBehavior::Normal,
- TraversalRestyleBehavior::ForAnimationOnly)) {
+ if (PrepareAndTraverseSubtree(
+ root,
+ TraversalRootBehavior::Normal,
+ TraversalRestyleBehavior::ForThrottledAnimationFlush)) {
postTraversalRequired = true;
}
}
return postTraversalRequired;
}
void
ServoStyleSet::StyleNewSubtree(Element* aRoot)
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -275,17 +275,17 @@ public:
/**
* Performs a Servo animation-only traversal to compute style for all nodes
* with the animation-only dirty bit in the document.
*
* This will traverse all of the document's style roots (that is, its document
* element, and the roots of the document-level native anonymous content).
*/
- bool StyleDocumentForAnimationOnly();
+ bool StyleDocumentForThrottledAnimationFlush();
/**
* Eagerly styles a subtree of unstyled nodes that was just appended to the
* tree. This is used in situations where we need the style immediately and
* cannot wait for a future batch restyle.
*/
void StyleNewSubtree(dom::Element* aRoot);
--- a/layout/style/ServoTypes.h
+++ b/layout/style/ServoTypes.h
@@ -66,18 +66,22 @@ enum class TraversalRestyleBehavior {
// Normal processing, but tolerant to calls to restyle elements in unstyled
// or display:none subtrees (which can occur when styling elements with
// newly applied XBL bindings).
ForNewlyBoundElement,
// Traverses in a mode that doesn't generate any change hints, which is what's
// required when handling frame reconstruction. The change hints in this case
// are unneeded, since the old frames have already been destroyed.
ForReconstruct,
- // Processes animation-only restyle.
- ForAnimationOnly,
+ // Processes just the traversal for animation-only restyles and skips the
+ // normal traversal for other restyles unrelated to animations.
+ // This is used to bring throttled animations up-to-date such as when we need
+ // to get correct position for transform animations that are throttled because
+ // they are running on the compositor.
+ ForThrottledAnimationFlush,
// Traverses as normal mode but tries to update all CSS animations.
ForCSSRuleChanges,
};
// Indicates which rules should be included when performing selecting matching
// on an element. DefaultOnly is used to exclude all rules except for those
// that come from UA style sheets, and is used to implemented
// getDefaultComputedStyle.