diff --git a/gfx/layers/opengl/GrallocTextureHost.cpp b/gfx/layers/opengl/GrallocTextureHost.cpp index 782bbc61c938..ebeae564be11 100644 --- a/gfx/layers/opengl/GrallocTextureHost.cpp +++ b/gfx/layers/opengl/GrallocTextureHost.cpp @@ -144,6 +144,13 @@ GrallocTextureSourceOGL::BindTexture(GLenum aTextureUnit, gfx::Filter aFilter) } 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() @@ -443,12 +450,6 @@ GrallocTextureSourceOGL::GetGLTexture() void GrallocTextureSourceOGL::BindEGLImage() { -#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 - if (mTextureHost) { - mTextureHost->WaitAcquireFenceSyncComplete(); - } -#endif - if (mCompositableBackendData) { CompositableDataGonkOGL* backend = static_cast(mCompositableBackendData.get()); backend->BindEGLImage(GetTextureTarget(), mEGLImage); diff --git a/gfx/layers/opengl/TextureHostOGL.cpp b/gfx/layers/opengl/TextureHostOGL.cpp index b1ac90882be4..fc770166c0a0 100644 --- a/gfx/layers/opengl/TextureHostOGL.cpp +++ b/gfx/layers/opengl/TextureHostOGL.cpp @@ -229,9 +229,12 @@ TextureHostOGL::SetAcquireFence(const android::sp& aAcquireFence } android::sp -TextureHostOGL::GetAcquireFence() +TextureHostOGL::GetAndResetAcquireFence() { - return mAcquireFence; + android::sp fence = mAcquireFence; + // Reset current AcquireFence. + mAcquireFence = android::Fence::NO_FENCE; + return fence; } void diff --git a/gfx/layers/opengl/TextureHostOGL.h b/gfx/layers/opengl/TextureHostOGL.h index 3c3b07dcf09d..32d6388b608b 100644 --- a/gfx/layers/opengl/TextureHostOGL.h +++ b/gfx/layers/opengl/TextureHostOGL.h @@ -174,7 +174,10 @@ public: virtual void SetAcquireFence(const android::sp& aAcquireFence); - virtual android::sp GetAcquireFence(); + /** + * Return a acquireFence's Fence and clear a reference to the Fence. + */ + virtual android::sp GetAndResetAcquireFence(); virtual void WaitAcquireFenceSyncComplete(); diff --git a/widget/gonk/HwcComposer2D.cpp b/widget/gonk/HwcComposer2D.cpp index 2d62c4937bad..7c99263afb49 100644 --- a/widget/gonk/HwcComposer2D.cpp +++ b/widget/gonk/HwcComposer2D.cpp @@ -682,6 +682,25 @@ 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 = 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;