Bug 1458457 - Move the logic that we use whether the previous time stamp or the last compose time stamp into SampleAnimationForEachNode. r=birtles

So that we can do an additional check depending on each animation in a subsequent
patch in this patch series.

MozReview-Commit-ID: C1ZJMdwraVk

--HG--
extra : rebase_source : baa71d25e45fbc1db20312788251bcced692b6cf
This commit is contained in:
Hiroyuki Ikezoe 2018-05-08 12:58:42 +09:00
Родитель 54c649077a
Коммит f389ab6b3a
4 изменённых файлов: 35 добавлений и 20 удалений

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

@ -148,7 +148,8 @@ CompositorAnimationStorage::SetAnimations(uint64_t aId, const AnimationArray& aV
AnimationHelper::SampleResult AnimationHelper::SampleResult
AnimationHelper::SampleAnimationForEachNode( AnimationHelper::SampleAnimationForEachNode(
TimeStamp aTime, TimeStamp aPreviousFrameTime,
TimeStamp aCurrentFrameTime,
AnimationArray& aAnimations, AnimationArray& aAnimations,
InfallibleTArray<AnimData>& aAnimationData, InfallibleTArray<AnimData>& aAnimationData,
RefPtr<RawServoAnimationValue>& aAnimationValue) RefPtr<RawServoAnimationValue>& aAnimationValue)
@ -175,13 +176,23 @@ AnimationHelper::SampleAnimationForEachNode(
animation.isNotPlaying(), animation.isNotPlaying(),
"If we are playing, we should have an origin time and a start" "If we are playing, we should have an origin time and a start"
" time"); " time");
// Use a previous vsync time to make main thread animations and compositor
// more in sync with each other.
// On the initial frame we use the current frame time here so the timestamp
// on the second frame are the same as the initial frame, but it does not
// matter.
const TimeStamp& timeStamp = !aPreviousFrameTime.IsNull()
? aPreviousFrameTime
: aCurrentFrameTime;
// If the animation is not currently playing, e.g. paused or // If the animation is not currently playing, e.g. paused or
// finished, then use the hold time to stay at the same position. // finished, then use the hold time to stay at the same position.
TimeDuration elapsedDuration = TimeDuration elapsedDuration =
animation.isNotPlaying() || animation.isNotPlaying() ||
animation.startTime().type() != MaybeTimeDuration::TTimeDuration animation.startTime().type() != MaybeTimeDuration::TTimeDuration
? animation.holdTime() ? animation.holdTime()
: (aTime - animation.originTime() - : (timeStamp - animation.originTime() -
animation.startTime().get_TimeDuration()) animation.startTime().get_TimeDuration())
.MultDouble(animation.playbackRate()); .MultDouble(animation.playbackRate());
@ -571,7 +582,8 @@ AnimationHelper::GetNextCompositorAnimationsId()
void void
AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage, AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage,
TimeStamp aTime) TimeStamp aPreviousFrameTime,
TimeStamp aCurrentFrameTime)
{ {
MOZ_ASSERT(aStorage); MOZ_ASSERT(aStorage);
@ -594,7 +606,8 @@ AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage,
animationData, animationData,
animationValue); animationValue);
AnimationHelper::SampleResult sampleResult = AnimationHelper::SampleResult sampleResult =
AnimationHelper::SampleAnimationForEachNode(aTime, AnimationHelper::SampleAnimationForEachNode(aPreviousFrameTime,
aCurrentFrameTime,
*animations, *animations,
animationData, animationData,
animationValue); animationValue);

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

@ -214,6 +214,9 @@ public:
/** /**
* Sample animations based on a given time stamp for a element(layer) with * Sample animations based on a given time stamp for a element(layer) with
* its animation data. * its animation data.
* Generally |aPreviousFrameTimeStamp| is used for the sampling if it's
* supplied to make the animation more in sync with other animations on the
* main-thread.
* *
* Returns SampleResult::None if none of the animations are producing a result * Returns SampleResult::None if none of the animations are producing a result
* (e.g. they are in the delay phase with no backwards fill), * (e.g. they are in the delay phase with no backwards fill),
@ -222,7 +225,8 @@ public:
* SampleResult::Sampled if the animation output was updated. * SampleResult::Sampled if the animation output was updated.
*/ */
static SampleResult static SampleResult
SampleAnimationForEachNode(TimeStamp aTime, SampleAnimationForEachNode(TimeStamp aPreviousFrameTime,
TimeStamp aCurrentFrameTime,
AnimationArray& aAnimations, AnimationArray& aAnimations,
InfallibleTArray<AnimData>& aAnimationData, InfallibleTArray<AnimData>& aAnimationData,
RefPtr<RawServoAnimationValue>& aAnimationValue); RefPtr<RawServoAnimationValue>& aAnimationValue);
@ -251,7 +255,8 @@ public:
*/ */
static void static void
SampleAnimations(CompositorAnimationStorage* aStorage, SampleAnimations(CompositorAnimationStorage* aStorage,
TimeStamp aTime); TimeStamp aPreviousFrameTime,
TimeStamp aCurrentFrameTime);
}; };
} // namespace layers } // namespace layers

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

@ -673,7 +673,8 @@ ApplyAnimatedValue(Layer* aLayer,
static bool static bool
SampleAnimations(Layer* aLayer, SampleAnimations(Layer* aLayer,
CompositorAnimationStorage* aStorage, CompositorAnimationStorage* aStorage,
TimeStamp aTime) TimeStamp aPreviousFrameTime,
TimeStamp aCurrentFrameTime)
{ {
bool isAnimating = false; bool isAnimating = false;
@ -689,7 +690,8 @@ SampleAnimations(Layer* aLayer,
RefPtr<RawServoAnimationValue> animationValue = RefPtr<RawServoAnimationValue> animationValue =
layer->GetBaseAnimationStyle(); layer->GetBaseAnimationStyle();
AnimationHelper::SampleResult sampleResult = AnimationHelper::SampleResult sampleResult =
AnimationHelper::SampleAnimationForEachNode(aTime, AnimationHelper::SampleAnimationForEachNode(aPreviousFrameTime,
aCurrentFrameTime,
animations, animations,
layer->GetAnimationData(), layer->GetAnimationData(),
animationValue); animationValue);
@ -1259,15 +1261,11 @@ AsyncCompositionManager::TransformShadowTree(TimeStamp aCurrentFrame,
// First, compute and set the shadow transforms from OMT animations. // First, compute and set the shadow transforms from OMT animations.
// NB: we must sample animations *before* sampling pan/zoom // NB: we must sample animations *before* sampling pan/zoom
// transforms. // transforms.
// Use a previous vsync time to make main thread animations and compositor
// more in sync with each other.
// On the initial frame we use aVsyncTimestamp here so the timestamp on the
// second frame are the same as the initial frame, but it does not matter.
bool wantNextFrame = bool wantNextFrame =
SampleAnimations(root, SampleAnimations(root,
storage, storage,
!mPreviousFrameTimeStamp.IsNull() ? mPreviousFrameTimeStamp,
mPreviousFrameTimeStamp : aCurrentFrame); aCurrentFrame);
if (!wantNextFrame) { if (!wantNextFrame) {
// Clean up the CompositorAnimationStorage because // Clean up the CompositorAnimationStorage because

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

@ -1222,18 +1222,17 @@ WebRenderBridgeParent::AdvanceAnimations()
// refresh mode, on the testing mode animations on the compositor are // refresh mode, on the testing mode animations on the compositor are
// synchronously composed, so we don't need to worry about the time gap // synchronously composed, so we don't need to worry about the time gap
// between the main thread and compositor thread. // between the main thread and compositor thread.
AnimationHelper::SampleAnimations(mAnimStorage, *testingTimeStamp); AnimationHelper::SampleAnimations(mAnimStorage,
*testingTimeStamp,
*testingTimeStamp);
return; return;
} }
} }
TimeStamp lastComposeTime = mCompositorScheduler->GetLastComposeTime(); TimeStamp lastComposeTime = mCompositorScheduler->GetLastComposeTime();
// if we have already mPreviousTimeStamp, use it since on the compositor the
// time in the previous tick is more closer to the main-thread tick time.
AnimationHelper::SampleAnimations(mAnimStorage, AnimationHelper::SampleAnimations(mAnimStorage,
!mPreviousFrameTimeStamp.IsNull() mPreviousFrameTimeStamp,
? mPreviousFrameTimeStamp lastComposeTime);
: lastComposeTime);
// Reset the previous time stamp if we don't already have any running // Reset the previous time stamp if we don't already have any running
// animations to avoid using the time which is far behind for newly // animations to avoid using the time which is far behind for newly