From 72a269999d0bf9e66c9688bd53d612bafc1b0ff7 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Thu, 14 May 2020 19:01:01 +0000 Subject: [PATCH] Bug 1637808 - Make SampleAnimations a member function of AsyncCompositionManager. r=boris Differential Revision: https://phabricator.services.mozilla.com/D75225 --- .../composite/AsyncCompositionManager.cpp | 37 +++++++++---------- .../composite/AsyncCompositionManager.h | 2 + 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/gfx/layers/composite/AsyncCompositionManager.cpp b/gfx/layers/composite/AsyncCompositionManager.cpp index 5ce62a4f4537..dfed40e90e86 100644 --- a/gfx/layers/composite/AsyncCompositionManager.cpp +++ b/gfx/layers/composite/AsyncCompositionManager.cpp @@ -10,6 +10,7 @@ #include "Layers.h" // for Layer, ContainerLayer, etc #include "gfxPoint.h" // for gfxPoint, gfxSize #include "mozilla/ServoBindings.h" // for Servo_AnimationValue_GetOpacity, etc +#include "mozilla/ScopeExit.h" // for MakeScopeExit #include "mozilla/StaticPrefs_apz.h" #include "mozilla/StaticPrefs_gfx.h" #include "mozilla/WidgetUtils.h" // for ComputeTransformForRotation @@ -641,11 +642,19 @@ static void ApplyAnimatedValue( } } -static bool SampleAnimations(Layer* aLayer, - CompositorAnimationStorage* aStorage, - TimeStamp aPreviousFrameTime, - TimeStamp aCurrentFrameTime) { +bool AsyncCompositionManager::SampleAnimations(Layer* aLayer, + TimeStamp aCurrentFrameTime) { bool isAnimating = false; + CompositorAnimationStorage* storage = + mCompositorBridge->GetAnimationStorage(); + + auto autoClearAnimationStorage = MakeScopeExit([&] { + if (!isAnimating) { + // Clean up the CompositorAnimationStorage because + // there are no active animations running + storage->Clear(); + } + }); ForEachNode(aLayer, [&](Layer* layer) { auto& propertyAnimationGroups = layer->GetPropertyAnimationGroups(); @@ -655,12 +664,12 @@ static bool SampleAnimations(Layer* aLayer, isAnimating = true; AnimatedValue* previousValue = - aStorage->GetAnimatedValue(layer->GetCompositorAnimationsId()); + storage->GetAnimatedValue(layer->GetCompositorAnimationsId()); nsTArray> animationValues; AnimationHelper::SampleResult sampleResult = AnimationHelper::SampleAnimationForEachNode( - aPreviousFrameTime, aCurrentFrameTime, previousValue, + mPreviousFrameTimeStamp, aCurrentFrameTime, previousValue, propertyAnimationGroups, animationValues); const PropertyAnimationGroup& lastPropertyAnimationGroup = @@ -671,8 +680,7 @@ static bool SampleAnimations(Layer* aLayer, // We assume all transform like properties (on the same frame) live in // a single same layer, so using the transform data of the last element // should be fine. - ApplyAnimatedValue(layer, aStorage, - lastPropertyAnimationGroup.mProperty, + ApplyAnimatedValue(layer, storage, lastPropertyAnimationGroup.mProperty, animationValues); break; case AnimationHelper::SampleResult::Skipped: @@ -687,7 +695,7 @@ static bool SampleAnimations(Layer* aLayer, // 1459775. // MOZ_ASSERT(FuzzyEqualsMultiplicative( // Servo_AnimationValue_GetOpacity(animationValue), - // *(aStorage->GetAnimationOpacity(layer->GetCompositorAnimationsId())))); + // *(storage->GetAnimationOpacity(layer->GetCompositorAnimationsId())))); #endif } // Even if opacity or background-color animation value has @@ -1425,19 +1433,10 @@ bool AsyncCompositionManager::TransformShadowTree( return false; } - CompositorAnimationStorage* storage = - mCompositorBridge->GetAnimationStorage(); // First, compute and set the shadow transforms from OMT animations. // NB: we must sample animations *before* sampling pan/zoom // transforms. - bool wantNextFrame = - SampleAnimations(root, storage, mPreviousFrameTimeStamp, aCurrentFrame); - - if (!wantNextFrame) { - // Clean up the CompositorAnimationStorage because - // there are no active animations running - storage->Clear(); - } + bool wantNextFrame = SampleAnimations(root, aCurrentFrame); // Advance animations to the next expected vsync timestamp, if we can // get it. diff --git a/gfx/layers/composite/AsyncCompositionManager.h b/gfx/layers/composite/AsyncCompositionManager.h index 2deeed6e7c00..3886229c4afb 100644 --- a/gfx/layers/composite/AsyncCompositionManager.h +++ b/gfx/layers/composite/AsyncCompositionManager.h @@ -220,6 +220,8 @@ class AsyncCompositionManager final { // layer void RecordShadowTransforms(Layer* aLayer); + bool SampleAnimations(Layer* aLayer, TimeStamp aCurrentFrameTime); + TargetConfig mTargetConfig; CSSRect mContentRect;