Bug 1208411 - Delay vsync timestamps on the compositor to make async animations more sync. r?mstange,mchang
MozReview-Commit-ID: Aes0jyOnojn
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -1454,17 +1454,28 @@ AsyncCompositionManager::TransformShadow
Layer* root = mLayerManager->GetRoot();
if (!root) {
return false;
}
// First, compute and set the shadow transforms from OMT animations.
// NB: we must sample animations *before* sampling pan/zoom
// transforms.
- bool wantNextFrame = SampleAnimations(root, aCurrentFrame);
+ // 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 = SampleAnimations(root,
+ !mPreviousFrameTimeStamp.IsNull() ?
+ mPreviousFrameTimeStamp : aCurrentFrame);
+
+ // 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
+ // started animations.
+ mPreviousFrameTimeStamp = wantNextFrame ? aCurrentFrame : TimeStamp();
if (!(aSkip & TransformsToSkip::APZ)) {
// FIXME/bug 775437: unify this interface with the ~native-fennec
// derived code
//
// Attempt to apply an async content transform to any layer that has
// an async pan zoom controller (which means that it is rendered
// async using Gecko). If this fails, fall back to transforming the
--- a/gfx/layers/composite/AsyncCompositionManager.h
+++ b/gfx/layers/composite/AsyncCompositionManager.h
@@ -238,16 +238,18 @@ private:
int32_t mPaintSyncId;
bool mReadyForCompose;
gfx::Matrix mWorldTransform;
LayerTransformRecorder mLayerTransformRecorder;
+ TimeStamp mPreviousFrameTimeStamp;
+
#ifdef MOZ_ANDROID_APZ
// The following two fields are only needed on Fennec with C++ APZ, because
// then we need to reposition the gecko scrollbar to deal with the
// dynamic toolbar shifting content around.
FrameMetrics::ViewID mRootScrollableId;
ScreenMargin mFixedLayerMargins;
#endif
};