Bug 1167215 - Re-apply CompositeUntil calls when we get a new batch of textures. r=roc
authorBobby Holley <bobbyholley@gmail.com>
Sat, 01 Aug 2015 15:37:11 -0700
changeset 287460 e3b8e08187adea5929230c32f7cf6d8d9c84b73c
parent 287459 6d2e3f71205b0f8bf88cdf21932d2739611e8392
child 287461 e94582c6247b0fdd56b7d69a5018c60eb631787e
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1167215
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1167215 - Re-apply CompositeUntil calls when we get a new batch of textures. r=roc
gfx/layers/composite/ImageHost.cpp
--- a/gfx/layers/composite/ImageHost.cpp
+++ b/gfx/layers/composite/ImageHost.cpp
@@ -14,16 +14,18 @@
 #include "mozilla/layers/LayerManagerComposite.h"     // for TexturedEffect, Effect, etc
 #include "nsAString.h"
 #include "nsDebug.h"                    // for NS_WARNING, NS_ASSERTION
 #include "nsPrintfCString.h"            // for nsPrintfCString
 #include "nsString.h"                   // for nsAutoCString
 
 class nsIntRegion;
 
+#define BIAS_TIME_MS 1.0
+
 namespace mozilla {
 namespace gfx {
 class Matrix4x4;
 } // namespace gfx
 
 using namespace gfx;
 
 namespace layers {
@@ -97,16 +99,32 @@ ImageHost::UseTextureHost(const nsTArray
     }
     // SetCropRect() affects only on a specific platform.
     // If it is not implemented, it does nothing.
     img.mFrontBuffer->SetCropRect(img.mPictureRect);
     img.mFrontBuffer->Updated();
     img.mFrontBuffer->PrepareTextureSource(img.mTextureSource);
   }
   mImages.SwapElements(newImages);
+
+  // Video producers generally send replacement images with the same frameID but
+  // slightly different timestamps in order to sync with the audio clock. This
+  // means that any CompositeUntil() call we made in Composite() may no longer
+  // guarantee that we'll composite until the next frame is ready. Fix that here.
+  if (GetCompositor() && mLastFrameID >= 0) {
+    for (size_t i = 0; i < mImages.Length(); ++i) {
+      bool frameComesAfter = mImages[i].mFrameID > mLastFrameID ||
+                             mImages[i].mProducerID != mLastProducerID;
+      if (frameComesAfter && !mImages[i].mTimeStamp.IsNull()) {
+        GetCompositor()->CompositeUntil(mImages[i].mTimeStamp +
+                                        TimeDuration::FromMilliseconds(BIAS_TIME_MS));
+        break;
+      }
+    }
+  }
 }
 
 void
 ImageHost::RemoveTextureHost(TextureHost* aTexture)
 {
   MOZ_ASSERT(!mLocked);
 
   CompositableHost::RemoveTextureHost(aTexture);
@@ -119,19 +137,19 @@ ImageHost::RemoveTextureHost(TextureHost
   }
 }
 
 static TimeStamp
 GetBiasedTime(const TimeStamp& aInput, ImageHost::Bias aBias)
 {
   switch (aBias) {
   case ImageHost::BIAS_NEGATIVE:
-    return aInput - TimeDuration::FromMilliseconds(1.0);
+    return aInput - TimeDuration::FromMilliseconds(BIAS_TIME_MS);
   case ImageHost::BIAS_POSITIVE:
-    return aInput + TimeDuration::FromMilliseconds(1.0);
+    return aInput + TimeDuration::FromMilliseconds(BIAS_TIME_MS);
   default:
     return aInput;
   }
 }
 
 static ImageHost::Bias
 UpdateBias(const TimeStamp& aCompositionTime,
            const TimeStamp& aCompositedImageTime,
@@ -252,17 +270,17 @@ ImageHost::Composite(LayerComposite* aLa
     return;
   }
   int imageIndex = ChooseImageIndex();
   if (imageIndex < 0) {
     return;
   }
 
   if (uint32_t(imageIndex) + 1 < mImages.Length()) {
-    GetCompositor()->CompositeUntil(mImages[imageIndex + 1].mTimeStamp);
+    GetCompositor()->CompositeUntil(mImages[imageIndex + 1].mTimeStamp + TimeDuration::FromMilliseconds(BIAS_TIME_MS));
   }
 
   TimedImage* img = &mImages[imageIndex];
   // Make sure the front buffer has a compositor
   img->mFrontBuffer->SetCompositor(GetCompositor());
 
   {
     AutoLockCompositableHost autoLock(this);