Bug 1430884 - Throttle transform animations without %0 or 100% keyframe. r=birtles

MozReview-Commit-ID: 3vLAlSkLz97

--HG--
extra : rebase_source : 424a94ace113c3383fd91300802973ba60da5f7d
This commit is contained in:
Hiroyuki Ikezoe 2018-06-25 11:51:06 +09:00
Родитель 2ae0dce721
Коммит 6d104540fb
3 изменённых файлов: 44 добавлений и 2 удалений

Просмотреть файл

@ -1617,9 +1617,25 @@ KeyframeEffect::CalculateCumulativeChangeHint(const ComputedStyle* aComputedStyl
// on invisible elements because we can't calculate the change hint for // on invisible elements because we can't calculate the change hint for
// such properties until we compose it. // such properties until we compose it.
if (!segment.HasReplaceableValues()) { if (!segment.HasReplaceableValues()) {
mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible; if (property.mProperty != eCSSProperty_transform) {
return; mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
return;
}
// We try a little harder to optimize transform animations simply
// because they are so common (the second-most commonly animated
// property at the time of writing). So if we encounter a transform
// segment that needs composing with the underlying value, we just add
// all the change hints a transform animation is known to be able to
// generate.
mCumulativeChangeHint |= nsChangeHint_AddOrRemoveTransform |
nsChangeHint_RepaintFrame |
nsChangeHint_UpdateContainingBlock |
nsChangeHint_UpdateOverflow |
nsChangeHint_UpdatePostTransformOverflow |
nsChangeHint_UpdateTransformLayer;
continue;
} }
RefPtr<ComputedStyle> fromContext = RefPtr<ComputedStyle> fromContext =
CreateComputedStyleForAnimationValue(property.mProperty, CreateComputedStyleForAnimationValue(property.mProperty,
segment.mFromValue, segment.mFromValue,

Просмотреть файл

@ -1774,6 +1774,25 @@ waitForAllPaints(() => {
await ensureElementRemoval(div); await ensureElementRemoval(div);
}); });
add_task(async function restyling_transform_aimations_on_invisible_element() {
// 'opacity: 0' prevents transform animations to be sent to the compositor.
const div = addDiv(null, { style: 'visibility: hidden; opacity: 0' });
const animation =
div.animate([ { transform: 'rotate(360deg)' } ],
{ duration: 100 * MS_PER_SEC,
iterations: Infinity });
await waitForAnimationReadyToRestyle(animation);
const markers = await observeStyling(5);
is(markers.length, 0,
'Transform animations without 100% keyframe on visibility hidden ' +
'element should be throttled');
await ensureElementRemoval(div);
});
}); });
</script> </script>

Просмотреть файл

@ -3694,6 +3694,9 @@ CompareTransformValues(const RefPtr<nsCSSValueSharedList>& aList,
const RefPtr<nsCSSValueSharedList>& aNewList) const RefPtr<nsCSSValueSharedList>& aNewList)
{ {
nsChangeHint result = nsChangeHint(0); nsChangeHint result = nsChangeHint(0);
// Note: If we add a new change hint for transform changes here, we have to
// modify KeyframeEffect::CalculateCumulativeChangeHint too!
if (!aList != !aNewList || (aList && *aList != *aNewList)) { if (!aList != !aNewList || (aList && *aList != *aNewList)) {
result |= nsChangeHint_UpdateTransformLayer; result |= nsChangeHint_UpdateTransformLayer;
if (aList && aNewList) { if (aList && aNewList) {
@ -3818,6 +3821,10 @@ nsStyleDisplay::CalcDifference(const nsStyleDisplay& aNewData) const
// We do not need to apply nsChangeHint_UpdateTransformLayer since // We do not need to apply nsChangeHint_UpdateTransformLayer since
// nsChangeHint_RepaintFrame will forcibly invalidate the frame area and // nsChangeHint_RepaintFrame will forcibly invalidate the frame area and
// ensure layers are rebuilt (or removed). // ensure layers are rebuilt (or removed).
//
// Note: If we add a new change hint for transform changes here or in
// CompareTransformValues(), we have to modify
// KeyframeEffect::CalculateCumulativeChangeHint too!
hint |= nsChangeHint_UpdateContainingBlock | hint |= nsChangeHint_UpdateContainingBlock |
nsChangeHint_AddOrRemoveTransform | nsChangeHint_AddOrRemoveTransform |
nsChangeHint_UpdateOverflow | nsChangeHint_UpdateOverflow |