Bug 1237454 - Unthrottle transform animations in visibility:hidden element periodically only if the element is scrolled out. r?birtles
In the case where we throttle transform animations in visibility:hidden
element, we just need to unthrottle only if the element is scrolled out since
unlike the scrolled out element, visibility:hidden element keeps invisible
even after the element moved into view.
MozReview-Commit-ID: 7X2SsOLz4Y5
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -1453,24 +1453,28 @@ KeyframeEffectReadOnly::CanThrottle() co
// animation is paint only and the target frame is out of view or the document
// is in background tabs.
if (mInEffectOnLastAnimationTimingUpdate && CanIgnoreIfNotVisible()) {
nsIPresShell* presShell = GetPresShell();
if (presShell && !presShell->IsActive()) {
return true;
}
- if (!frame->IsVisibleOrMayHaveVisibleDescendants() ||
+ const bool isVisibilityHidden =
+ !frame->IsVisibleOrMayHaveVisibleDescendants();
+ if (isVisibilityHidden ||
frame->IsScrolledOutOfView()) {
// If there are transform change hints, unthrottle the animation
// periodically since it might affect the overflow region.
if (mCumulativeChangeHint & (nsChangeHint_UpdatePostTransformOverflow |
nsChangeHint_AddOrRemoveTransform |
nsChangeHint_UpdateTransformLayer)) {
- return CanThrottleTransformChanges(*frame);
+ return isVisibilityHidden
+ ? CanThrottleTransformChangesInScrollable(*frame)
+ : CanThrottleTransformChanges(*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
@@ -1497,17 +1501,17 @@ KeyframeEffectReadOnly::CanThrottle() co
effectSet->GetAnimationGeneration() !=
layer->GetAnimationGeneration()) {
return false;
}
// If this is a transform animation that affects the overflow region,
// we should unthrottle the animation periodically.
if (record.mProperty == eCSSProperty_transform &&
- !CanThrottleTransformChangesForCompositor(*frame)) {
+ !CanThrottleTransformChangesInScrollable(*frame)) {
return false;
}
}
for (const AnimationProperty& property : mProperties) {
if (!property.mIsRunningOnCompositor) {
return false;
}
@@ -1529,17 +1533,17 @@ KeyframeEffectReadOnly::CanThrottleTrans
" on an effect with a parent animation");
TimeStamp lastSyncTime = effectSet->LastTransformSyncTime();
// If this animation can cause overflow, we can throttle some of the ticks.
return (!lastSyncTime.IsNull() &&
(now - lastSyncTime) < OverflowRegionRefreshInterval());
}
bool
-KeyframeEffectReadOnly::CanThrottleTransformChangesForCompositor(nsIFrame& aFrame) const
+KeyframeEffectReadOnly::CanThrottleTransformChangesInScrollable(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;
}
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -465,17 +465,17 @@ private:
nsCSSPropertyID aProperty,
const AnimationValue& aValue,
const ServoStyleContext* aBaseStyleContext);
nsIFrame* GetAnimationFrame() const;
bool CanThrottle() const;
bool CanThrottleTransformChanges(const nsIFrame& aFrame) const;
- bool CanThrottleTransformChangesForCompositor(nsIFrame& aFrame) const;
+ bool CanThrottleTransformChangesInScrollable(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|.