Bug 1024144 - Deliver acquire fence to HwComposer. r=sushil, r=nical, a=2.0+
authorSotaro Ikeda <sikeda@mozilla.com>
Thu, 12 Jun 2014 18:46:25 -0700
changeset 207644 befee2ec3a8245c665e90328243308e1ce999510
parent 207643 9886da8086bc4ae936924a2f657ae36e959090bd
child 207645 272e865ade290eda483ee077ad676b72e29cc41c
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssushil, nical, 2
bugs1024144
milestone32.0a2
Bug 1024144 - Deliver acquire fence to HwComposer. r=sushil, r=nical, a=2.0+
gfx/layers/opengl/GrallocTextureHost.cpp
gfx/layers/opengl/TextureHostOGL.cpp
gfx/layers/opengl/TextureHostOGL.h
widget/gonk/HwcComposer2D.cpp
--- a/gfx/layers/opengl/GrallocTextureHost.cpp
+++ b/gfx/layers/opengl/GrallocTextureHost.cpp
@@ -139,16 +139,23 @@ GrallocTextureSourceOGL::BindTexture(GLe
     // only in Lock().
     if (!mEGLImage) {
       mEGLImage = EGLImageCreateFromNativeBuffer(gl(), mGraphicBuffer->getNativeBuffer());
     }
     BindEGLImage();
   }
 
   ApplyFilterToBoundTexture(gl(), aFilter, textureTarget);
+
+#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
+  if (mTextureHost) {
+    // Wait until it's ready.
+    mTextureHost->WaitAcquireFenceSyncComplete();
+  }
+#endif
 }
 
 void GrallocTextureSourceOGL::Lock()
 {
   if (mCompositableBackendData) return;
 
   MOZ_ASSERT(IsValid());
 
@@ -438,22 +445,16 @@ GrallocTextureSourceOGL::GetGLTexture()
   }
 
   return mTexture;
 }
 
 void
 GrallocTextureSourceOGL::BindEGLImage()
 {
-#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
-  if (mTextureHost) {
-    mTextureHost->WaitAcquireFenceSyncComplete();
-  }
-#endif
-
   if (mCompositableBackendData) {
     CompositableDataGonkOGL* backend = static_cast<CompositableDataGonkOGL*>(mCompositableBackendData.get());
     backend->BindEGLImage(GetTextureTarget(), mEGLImage);
   } else {
     gl()->fEGLImageTargetTexture2D(GetTextureTarget(), mEGLImage);
   }
 }
 
--- a/gfx/layers/opengl/TextureHostOGL.cpp
+++ b/gfx/layers/opengl/TextureHostOGL.cpp
@@ -224,19 +224,22 @@ TextureHostOGL::GetAndResetReleaseFence(
 
 void
 TextureHostOGL::SetAcquireFence(const android::sp<android::Fence>& aAcquireFence)
 {
   mAcquireFence = aAcquireFence;
 }
 
 android::sp<android::Fence>
-TextureHostOGL::GetAcquireFence()
+TextureHostOGL::GetAndResetAcquireFence()
 {
-  return mAcquireFence;
+  android::sp<android::Fence> fence = mAcquireFence;
+  // Reset current AcquireFence.
+  mAcquireFence = android::Fence::NO_FENCE;
+  return fence;
 }
 
 void
 TextureHostOGL::WaitAcquireFenceSyncComplete()
 {
   if (!mAcquireFence.get() || !mAcquireFence->isValid()) {
     return;
   }
--- a/gfx/layers/opengl/TextureHostOGL.h
+++ b/gfx/layers/opengl/TextureHostOGL.h
@@ -169,17 +169,20 @@ public:
 
   /**
    * Return a releaseFence's Fence and clear a reference to the Fence.
    */
   virtual android::sp<android::Fence> GetAndResetReleaseFence();
 
   virtual void SetAcquireFence(const android::sp<android::Fence>& aAcquireFence);
 
-  virtual android::sp<android::Fence> GetAcquireFence();
+  /**
+   * Return a acquireFence's Fence and clear a reference to the Fence.
+   */
+  virtual android::sp<android::Fence> GetAndResetAcquireFence();
 
   virtual void WaitAcquireFenceSyncComplete();
 
 protected:
   android::sp<android::Fence> mReleaseFence;
 
   android::sp<android::Fence> mAcquireFence;
 
--- a/widget/gonk/HwcComposer2D.cpp
+++ b/widget/gonk/HwcComposer2D.cpp
@@ -686,16 +686,35 @@ HwcComposer2D::Prepare(buffer_handle_t f
 }
 
 bool
 HwcComposer2D::Commit()
 {
     hwc_display_contents_1_t *displays[HWC_NUM_DISPLAY_TYPES] = { nullptr };
     displays[HWC_DISPLAY_PRIMARY] = mList;
 
+    for (uint32_t j=0; j < (mList->numHwLayers - 1); j++) {
+        if (!mHwcLayerMap[j] ||
+            (mList->hwLayers[j].compositionType == HWC_FRAMEBUFFER)) {
+            continue;
+        }
+        LayerRenderState state = mHwcLayerMap[j]->GetLayer()->GetRenderState();
+        if (!state.mTexture) {
+            continue;
+        }
+        TextureHostOGL* texture = state.mTexture->AsHostOGL();
+        if (!texture) {
+            continue;
+        }
+        sp<Fence> fence = texture->GetAndResetAcquireFence();
+        if (fence.get() && fence->isValid()) {
+            mList->hwLayers[j].acquireFenceFd = fence->dup();
+        }
+    }
+
     int err = mHwc->set(mHwc, HWC_NUM_DISPLAY_TYPES, displays);
 
     mPrevDisplayFence = mPrevRetireFence;
     mPrevRetireFence = Fence::NO_FENCE;
 
     for (uint32_t j=0; j < (mList->numHwLayers - 1); j++) {
         if (mList->hwLayers[j].releaseFenceFd >= 0) {
             int fd = mList->hwLayers[j].releaseFenceFd;