Bug 1208411 - Delay vsync timestamps on the compositor to make async animations more sync. r?mstange,mchang draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Thu, 23 Jun 2016 06:24:39 +0900
changeset 380719 7df18967339dd9629cc45b50490512fb35119195
parent 380643 c9edfe35619f69f7785776ebd19a3140684024dc
child 523796 d6f3f277fce3edb91b5f2c9819458812265df3ff
push id21300
push userbmo:hiikezoe@mozilla-japan.org
push dateWed, 22 Jun 2016 21:45:15 +0000
reviewersmstange, mchang
bugs1208411
milestone50.0a1
Bug 1208411 - Delay vsync timestamps on the compositor to make async animations more sync. r?mstange,mchang MozReview-Commit-ID: Aes0jyOnojn
gfx/layers/composite/AsyncCompositionManager.cpp
gfx/layers/composite/AsyncCompositionManager.h
--- 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
 };