Bug 1181392 part 5 - Remove use of IsFinishedTransition from AnimationCollection::HasAnimationOfProperty; r=dbaron

AnimationCollection::HasAnimationOfProperty uses IsFinishedTransition to filter
out transitions that should otherwise be ignored. This is used in the following
places:

1. nsLayoutUtils::HasAnimations

   The is only used by nsIFrame::BuildDisplayListForStackingContext to see if
   there are any opacity animations

   For this case, simply returning *current* animations would be sufficient
   (since finished but filling animations should have already filled in the
   display opacity)

2. CommonAnimationManager::GetAnimationsForCompositor

   This should really only return *current* animations--that is, animations that
   are running or scheduled to run. Finished animations never run on the
   compositor. Indeed, only *playing* animations run on the compositor but, as
   we will see in some of the cases below, it is sometimes useful to know that
   an animation *will* run on the compositor in the near future (e.g. so we can
   pre-render content).

   The places where GetAnimationsForCompositor is used are:

   - When building layers to add animations to layers in nsDisplayList--in this
     case we skip any animations that aren't playing so if
     GetAnimationsForCompositor only returned current animations that would be
     more than sufficient.

   - In nsLayoutUtils::HasAnimationsForCompositor. This in turn is used:

     - In ChooseScaleAndSetTransform to see if the transform is being animated
       on the compositor. If so, it calls
       nsLayoutUtils::ComputeSuitableScaleForAnimation (which also calls
       GetAnimationsForCompositor) and passes the result to
       GetMinAndMaxScaleForAnimationProperty which we have already adjusted in
       part 4 of this patch series to only deal with *relevant* animations

       Relevant animations include both current animations and in effect
       animations but we don't run forwards-filling animations on the compositor
       so GetAnimationsForCompositor should NOT return them. Current animations
       should be enough. In fact, playing animations should be enough but we
       might want to pre-render layers at a suitable size during their delay
       phase so returning current animations is probably ok.

     - In nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay to add a fuzz
       factor to the overflow rect for frames undergoing a transform animation
       on the compositor. In this case too current animations should be
       sufficient.

     - In nsDisplayOpacity::NeedsActiveLayer to say "yes" if we are animating
       opacity on the compositor. Presumably in this case it would be good to
       say "yes" if the animation is in the delay phase too (as it currently
       does). After the animation is finished, we should drop the layer, i.e.
       current animations should be sufficient.

     - In nsDisplayTransform::ShouldPrerenderTransformedContent. As with
       nsDisplayOpacity::NeedsActiveLayer, we only need to pre-render
       transformed content for animations that are current.

     - In nsDisplayTransform::GetLayerState. As with
       nsDisplayOpacity::NeedsActiveLayer, we only need to return active here
       for current animations.

     - In nsIFrame::IsTransformed. Here we test the display style to see if
       there is a transform and also check if transform is being animated on the
       compositor. As a result, we really only need HasAnimationsForCompositor
       to return true for animations that are playing--otherwise the display
       style will tell us if we're transformed or not. Returning true for all
       current compositor animations (which is a superset of playing), however,
       should not cause problems (we already return true for even more than
       that).

     - In nsIFrame::HasOpacityInternal which is much the same as
       nsIFrame::IsTransformed and hence current should be fine.

3. AnimationCollection::CanThrottleAnimation

   Here, HasAnimationOfProperty is used when looking for animations that would
   disqualify us from throttling the animation by having an out-of-date layer
   generation or being a transform animation that affects scroll and so requires
   that we do the occasional main thread sample to update scrollbars.

   It would seem like current animations are enough here too. One interesting
   case is where we *had* a compositor animation but it has finished or been
   cancelled. In that case, the animation won't be current and we should not
   throttle the animation since we need to take it off its layer.

   It turns out checking for current animations is still ok in this case too.
   The reasoning is as follows:

   - If the animation is newly-finished, we'll pick that up in
     Animation::CanThrottle and return false then.

   - If the animation is newly-idle then there are two cases:

     If the cancelled animation was the only compositor animation then
     AnimationCollection::CanPerformOnCompositorThread will notice that there
     are no playing compositor animations and return false and
     AnimationCollection::CanThrottleAnimation will never be called.

     If there are other compositor animations running, then
     AnimationCollection::CanThrottleAnimation will still return false because
     whatever cancelled the animation will update the animation generation and
     we'll notice the mismatch between the layer animation generation and the
     animation generation on the collection.

Based on the above analysis it appears that making
AnimationCollection::HasAnimationOfProperty return only current animations (and
simulatneously renaming it to HasCurrentAnimationOfProperty) is safe. Indeed, in
effect, we already do this for transitions but not for animations. This patch
generalizes this behavior to all animations.

This patch also updates test_animations_omta.html since it was incorrectly
testing that a finished opacity animation was still running on the compositor.
Finished animations should not run on the compositor and the changes in this
patch cause that to happen. The reason we don't just update this test to check
for RunningOn.MainThread is that for opacity animations, unlike transform
animations, we can't detect if an opacity on a layer was set by animation or
not. As a result, for opacity animations we typically test the opacity on
either the main thread or compositor in order to allow for the case where an
animation-set opacity is still lingering on the compositor.
This commit is contained in:
Brian Birtles 2015-08-07 12:29:36 +09:00
parent eb9973b07f
commit 937bc54615
6 changed files with 27 additions and 18 deletions

View File

@ -381,20 +381,20 @@ nsLayoutUtils::HasAnimationsForCompositor(const nsIFrame* aFrame,
}
bool
nsLayoutUtils::HasAnimations(const nsIFrame* aFrame,
nsCSSProperty aProperty)
nsLayoutUtils::HasCurrentAnimationOfProperty(const nsIFrame* aFrame,
nsCSSProperty aProperty)
{
nsPresContext* presContext = aFrame->PresContext();
AnimationCollection* collection =
presContext->AnimationManager()->GetAnimationCollection(aFrame);
if (collection &&
collection->HasAnimationOfProperty(aProperty)) {
collection->HasCurrentAnimationOfProperty(aProperty)) {
return true;
}
collection =
presContext->TransitionManager()->GetAnimationCollection(aFrame);
if (collection &&
collection->HasAnimationOfProperty(aProperty)) {
collection->HasCurrentAnimationOfProperty(aProperty)) {
return true;
}
return false;

View File

@ -2160,10 +2160,11 @@ public:
nsCSSProperty aProperty);
/**
* Returns true if the frame has animations or transitions for the
* property.
* Returns true if the frame has current (i.e. running or scheduled-to-run)
* animations or transitions for the property.
*/
static bool HasAnimations(const nsIFrame* aFrame, nsCSSProperty aProperty);
static bool HasCurrentAnimationOfProperty(const nsIFrame* aFrame,
nsCSSProperty aProperty);
/**
* Returns true if the frame has any current animations.

View File

@ -1946,7 +1946,8 @@ nsIFrame::BuildDisplayListForStackingContext(nsDisplayListBuilder* aBuilder,
if (disp->mOpacity == 0.0 && aBuilder->IsForPainting() &&
!aBuilder->WillComputePluginGeometry() &&
!(disp->mWillChangeBitField & NS_STYLE_WILL_CHANGE_OPACITY) &&
!nsLayoutUtils::HasAnimations(this, eCSSProperty_opacity) &&
!nsLayoutUtils::HasCurrentAnimationOfProperty(this,
eCSSProperty_opacity) &&
!needEventRegions) {
return;
}

View File

@ -173,7 +173,7 @@ CommonAnimationManager::GetAnimationsForCompositor(const nsIFrame* aFrame,
{
AnimationCollection* collection = GetAnimationCollection(aFrame);
if (!collection ||
!collection->HasAnimationOfProperty(aProperty) ||
!collection->HasCurrentAnimationOfProperty(aProperty) ||
!collection->CanPerformOnCompositorThread(
AnimationCollection::CanAnimate_AllowPartial)) {
return nullptr;
@ -708,12 +708,12 @@ AnimationCollection::PostUpdateLayerAnimations()
}
bool
AnimationCollection::HasAnimationOfProperty(nsCSSProperty aProperty) const
AnimationCollection::HasCurrentAnimationOfProperty(nsCSSProperty
aProperty) const
{
for (size_t animIdx = mAnimations.Length(); animIdx-- != 0; ) {
const KeyframeEffectReadOnly* effect = mAnimations[animIdx]->GetEffect();
if (effect && effect->HasAnimationOfProperty(aProperty) &&
!effect->IsFinishedTransition()) {
for (Animation* animation : mAnimations) {
if (animation->HasCurrentEffect() &&
animation->GetEffect()->HasAnimationOfProperty(aProperty)) {
return true;
}
}
@ -934,11 +934,18 @@ AnimationCollection::CanThrottleAnimation(TimeStamp aTime)
return false;
}
const auto& info = CommonAnimationManager::sLayerAnimationInfo;
for (size_t i = 0; i < ArrayLength(info); i++) {
auto record = info[i];
if (!HasAnimationOfProperty(record.mProperty)) {
// We only need to worry about *current* animations here.
// - If we have a newly-finished animation, Animation::CanThrottle will
// detect that and force an unthrottled sample.
// - If we have a newly-idle animation, then whatever caused the animation
// to be idle will update the animation generation so we'll return false
// from the layer generation check below for any other running compositor
// animations (and if no other compositor animations exist we won't get
// this far).
if (!HasCurrentAnimationOfProperty(record.mProperty)) {
continue;
}

View File

@ -320,7 +320,7 @@ public:
void PostUpdateLayerAnimations();
bool HasAnimationOfProperty(nsCSSProperty aProperty) const;
bool HasCurrentAnimationOfProperty(nsCSSProperty aProperty) const;
bool IsForElement() const { // rather than for a pseudo-element
return mElementProperty == nsGkAtoms::animationsProperty ||

View File

@ -951,7 +951,7 @@ addAsyncAnimTest(function *() {
RunningOn.Compositor,
"animation-iteration-count test 3 at 24s");
advance_clock(200);
omta_is("opacity", 1, RunningOn.Compositor,
omta_is("opacity", 1, RunningOn.Either,
"animation-iteration-count test 2 at 25s");
omta_is_approx("transform", { ty: 100 * gTF.ease_out(0.8) }, 0.01,
RunningOn.Compositor,