From a837628695f370ba1c7f712366d731fa8e0b378d Mon Sep 17 00:00:00 2001 From: Ethan Lin Date: Fri, 10 Apr 2015 02:19:00 +0200 Subject: [PATCH] Bug 1146214 - Implement fence delivery. Combine ipc messages and remove reply fence delivery message. r=nical --- gfx/layers/composite/TextureHost.cpp | 12 ------ gfx/layers/composite/TextureHost.h | 2 +- .../ipc/CompositableTransactionParent.cpp | 19 ++++++++-- gfx/layers/ipc/ImageBridgeChild.cpp | 38 +++---------------- gfx/layers/ipc/ImageBridgeParent.cpp | 33 +++------------- gfx/layers/ipc/LayerTransactionChild.cpp | 17 +-------- gfx/layers/ipc/LayerTransactionParent.cpp | 28 +++----------- gfx/layers/ipc/LayersMessages.ipdlh | 16 +++----- gfx/layers/ipc/ShadowLayers.cpp | 21 +++------- gfx/layers/opengl/GrallocTextureHost.cpp | 13 +++++++ gfx/layers/opengl/GrallocTextureHost.h | 2 + 11 files changed, 58 insertions(+), 143 deletions(-) diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index 2f7d4dda64bc..66bff22a0511 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -149,18 +149,6 @@ TextureHost::GetIPDLActor() FenceHandle TextureHost::GetAndResetReleaseFenceHandle() { -#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 - TextureHostOGL* hostOGL = this->AsHostOGL(); - if (!hostOGL) { - return FenceHandle(); - } - - android::sp fence = hostOGL->GetAndResetReleaseFence(); - if (fence.get() && fence->isValid()) { - FenceHandle handle = FenceHandle(fence); - return handle; - } -#endif return FenceHandle(); } diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h index 5a3d10993ac9..ec8e639a1e02 100644 --- a/gfx/layers/composite/TextureHost.h +++ b/gfx/layers/composite/TextureHost.h @@ -473,7 +473,7 @@ public: */ PTextureParent* GetIPDLActor(); - FenceHandle GetAndResetReleaseFenceHandle(); + virtual FenceHandle GetAndResetReleaseFenceHandle(); /** * Specific to B2G's Composer2D diff --git a/gfx/layers/ipc/CompositableTransactionParent.cpp b/gfx/layers/ipc/CompositableTransactionParent.cpp index c8e4a0d0314e..f1840c289795 100644 --- a/gfx/layers/ipc/CompositableTransactionParent.cpp +++ b/gfx/layers/ipc/CompositableTransactionParent.cpp @@ -156,15 +156,13 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation // Send message back via PImageBridge. ImageBridgeParent::ReplyRemoveTexture( GetChildProcessId(), - OpReplyRemoveTexture(true, // isMain - op.holderId(), + OpReplyRemoveTexture(op.holderId(), op.transactionId())); } else { // send FenceHandle if present. SendFenceHandleIfPresent(op.textureParent(), compositable); - ReplyRemoveTexture(OpReplyRemoveTexture(false, // isMain - op.holderId(), + ReplyRemoveTexture(OpReplyRemoveTexture(op.holderId(), op.transactionId())); } break; @@ -177,6 +175,19 @@ CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation MOZ_ASSERT(tex.get()); compositable->UseTextureHost(tex); + MaybeFence maybeFence = op.fence(); + if (maybeFence.type() == MaybeFence::TFenceHandle) { + FenceHandle fence = maybeFence.get_FenceHandle(); + if (fence.IsValid() && tex) { +#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 + TextureHostOGL* hostOGL = tex->AsHostOGL(); + if (hostOGL) { + hostOGL->SetAcquireFence(fence.mFence); + } +#endif + } + } + if (IsAsync() && compositable->GetLayer()) { ScheduleComposition(op); // Async layer updates don't trigger invalidation, manually tell the layer diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index 7b3243d8da63..e59e4a50912e 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -113,15 +113,11 @@ ImageBridgeChild::UseTexture(CompositableClient* aCompositable, MOZ_ASSERT(aTexture); MOZ_ASSERT(aCompositable->GetIPDLActor()); MOZ_ASSERT(aTexture->GetIPDLActor()); -#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 - FenceHandle handle = aTexture->GetAcquireFenceHandle(); - if (handle.IsValid()) { - RefPtr tracker = new FenceDeliveryTracker(handle); - SendFenceHandle(tracker, aTexture->GetIPDLActor(), handle); - } -#endif + + FenceHandle fence = aTexture->GetAcquireFenceHandle(); mTxn->AddNoSwapEdit(OpUseTexture(nullptr, aCompositable->GetIPDLActor(), - nullptr, aTexture->GetIPDLActor())); + nullptr, aTexture->GetIPDLActor(), + fence.IsValid() ? MaybeFence(fence) : MaybeFence(null_t()))); } void @@ -156,10 +152,8 @@ ImageBridgeChild::SendFenceHandle(AsyncTransactionTracker* aTracker, PTextureChild* aTexture, const FenceHandle& aFence) { - HoldUntilComplete(aTracker); InfallibleTArray messages; - messages.AppendElement(OpDeliverFenceFromChild(aTracker->GetId(), - nullptr, aTexture, + messages.AppendElement(OpDeliverFenceFromChild(nullptr, aTexture, aFence)); SendChildAsyncMessages(messages); } @@ -835,7 +829,6 @@ ImageBridgeChild::RecvParentAsyncMessages(InfallibleTArraySetReleaseFenceHandle(fence); } - HoldTransactionsToRespond(op.transactionId()); break; } case AsyncParentMessageData::TOpDeliverFenceToTracker: { @@ -845,15 +838,6 @@ ImageBridgeChild::RecvParentAsyncMessages(InfallibleTArray replies; - replies.AppendElement(OpReplyDeliverFence(op.transactionId())); - SendChildAsyncMessages(replies); - break; - } - case AsyncParentMessageData::TOpReplyDeliverFence: { - const OpReplyDeliverFence& op = message.get_OpReplyDeliverFence(); - TransactionCompleteted(op.transactionId()); break; } case AsyncParentMessageData::TOpReplyRemoveTexture: { @@ -948,18 +932,6 @@ bool ImageBridgeChild::IsSameProcess() const void ImageBridgeChild::SendPendingAsyncMessges() { - if (!IsCreated() || - mTransactionsToRespond.empty()) { - return; - } - // Send OpReplyDeliverFence messages - InfallibleTArray replies; - replies.SetCapacity(mTransactionsToRespond.size()); - for (size_t i = 0; i < mTransactionsToRespond.size(); i++) { - replies.AppendElement(OpReplyDeliverFence(mTransactionsToRespond[i])); - } - mTransactionsToRespond.clear(); - SendChildAsyncMessages(replies); } } // layers diff --git a/gfx/layers/ipc/ImageBridgeParent.cpp b/gfx/layers/ipc/ImageBridgeParent.cpp index abc0106f15dd..e7d566f92384 100644 --- a/gfx/layers/ipc/ImageBridgeParent.cpp +++ b/gfx/layers/ipc/ImageBridgeParent.cpp @@ -247,10 +247,8 @@ ImageBridgeParent::SendFenceHandle(AsyncTransactionTracker* aTracker, PTextureParent* aTexture, const FenceHandle& aFence) { - HoldUntilComplete(aTracker); InfallibleTArray messages; - messages.AppendElement(OpDeliverFence(aTracker->GetId(), - aTexture, nullptr, + messages.AppendElement(OpDeliverFence(aTexture, nullptr, aFence)); mozilla::unused << SendParentAsyncMessages(messages); } @@ -283,15 +281,6 @@ ImageBridgeParent::RecvChildAsyncMessages(InfallibleTArraySetAcquireFence(fence.mFence); } #endif - // Send back a response. - InfallibleTArray replies; - replies.AppendElement(OpReplyDeliverFence(op.transactionId())); - mozilla::unused << SendParentAsyncMessages(replies); - break; - } - case AsyncChildMessageData::TOpReplyDeliverFence: { - const OpReplyDeliverFence& op = message.get_OpReplyDeliverFence(); - TransactionCompleteted(op.transactionId()); break; } default: @@ -373,10 +362,7 @@ ImageBridgeParent::SendFenceHandleIfPresent(PTextureParent* aTexture, if (aCompositableHost && aCompositableHost->GetCompositor()) { FenceHandle fence = aCompositableHost->GetCompositor()->GetReleaseFence(); if (fence.IsValid()) { - RefPtr tracker = new FenceDeliveryTracker(fence); - HoldUntilComplete(tracker); - mPendingAsyncMessage.push_back(OpDeliverFence(tracker->GetId(), - aTexture, nullptr, + mPendingAsyncMessage.push_back(OpDeliverFence(aTexture, nullptr, fence)); } } @@ -384,10 +370,7 @@ ImageBridgeParent::SendFenceHandleIfPresent(PTextureParent* aTexture, // Send a ReleaseFence that is set by HwcComposer2D. FenceHandle fence = texture->GetAndResetReleaseFenceHandle(); if (fence.IsValid()) { - RefPtr tracker = new FenceDeliveryTracker(fence); - HoldUntilComplete(tracker); - mPendingAsyncMessage.push_back(OpDeliverFence(tracker->GetId(), - aTexture, nullptr, + mPendingAsyncMessage.push_back(OpDeliverFence(aTexture, nullptr, fence)); } } @@ -407,10 +390,7 @@ ImageBridgeParent::SendFenceHandleToTrackerIfPresent(uint64_t aDestHolderId, if (aCompositableHost && aCompositableHost->GetCompositor()) { FenceHandle fence = aCompositableHost->GetCompositor()->GetReleaseFence(); if (fence.IsValid()) { - RefPtr tracker = new FenceDeliveryTracker(fence); - HoldUntilComplete(tracker); - mPendingAsyncMessage.push_back(OpDeliverFenceToTracker(tracker->GetId(), - aDestHolderId, + mPendingAsyncMessage.push_back(OpDeliverFenceToTracker(aDestHolderId, aTransactionId, fence)); } @@ -419,10 +399,7 @@ ImageBridgeParent::SendFenceHandleToTrackerIfPresent(uint64_t aDestHolderId, // Send a ReleaseFence that is set by HwcComposer2D. FenceHandle fence = texture->GetAndResetReleaseFenceHandle(); if (fence.IsValid()) { - RefPtr tracker = new FenceDeliveryTracker(fence); - HoldUntilComplete(tracker); - mPendingAsyncMessage.push_back(OpDeliverFenceToTracker(tracker->GetId(), - aDestHolderId, + mPendingAsyncMessage.push_back(OpDeliverFenceToTracker(aDestHolderId, aTransactionId, fence)); } diff --git a/gfx/layers/ipc/LayerTransactionChild.cpp b/gfx/layers/ipc/LayerTransactionChild.cpp index b2342621fe86..53e563639448 100644 --- a/gfx/layers/ipc/LayerTransactionChild.cpp +++ b/gfx/layers/ipc/LayerTransactionChild.cpp @@ -90,19 +90,6 @@ LayerTransactionChild::RecvParentAsyncMessages(InfallibleTArraySetReleaseFenceHandle(fence); } - if (mForwarder) { - mForwarder->HoldTransactionsToRespond(op.transactionId()); - } else { - // Send back a response. - InfallibleTArray replies; - replies.AppendElement(OpReplyDeliverFence(op.transactionId())); - SendChildAsyncMessages(replies); - } - break; - } - case AsyncParentMessageData::TOpReplyDeliverFence: { - const OpReplyDeliverFence& op = message.get_OpReplyDeliverFence(); - TransactionCompleteted(op.transactionId()); break; } case AsyncParentMessageData::TOpReplyRemoveTexture: { @@ -125,10 +112,8 @@ LayerTransactionChild::SendFenceHandle(AsyncTransactionTracker* aTracker, PTextureChild* aTexture, const FenceHandle& aFence) { - HoldUntilComplete(aTracker); InfallibleTArray messages; - messages.AppendElement(OpDeliverFenceFromChild(aTracker->GetId(), - nullptr, aTexture, + messages.AppendElement(OpDeliverFenceFromChild(nullptr, aTexture, aFence)); SendChildAsyncMessages(messages); } diff --git a/gfx/layers/ipc/LayerTransactionParent.cpp b/gfx/layers/ipc/LayerTransactionParent.cpp index 8b51f210c782..8cdb09cbfa15 100644 --- a/gfx/layers/ipc/LayerTransactionParent.cpp +++ b/gfx/layers/ipc/LayerTransactionParent.cpp @@ -929,15 +929,6 @@ LayerTransactionParent::RecvChildAsyncMessages(InfallibleTArraySetAcquireFence(fence.mFence); } #endif - // Send back a response. - InfallibleTArray replies; - replies.AppendElement(OpReplyDeliverFence(op.transactionId())); - mozilla::unused << SendParentAsyncMessages(replies); - break; - } - case AsyncChildMessageData::TOpReplyDeliverFence: { - const OpReplyDeliverFence& op = message.get_OpReplyDeliverFence(); - TransactionCompleteted(op.transactionId()); break; } case AsyncChildMessageData::TOpRemoveTextureAsync: { @@ -960,9 +951,8 @@ LayerTransactionParent::RecvChildAsyncMessages(InfallibleTArrayGetCompositor()) { FenceHandle fence = aCompositableHost->GetCompositor()->GetReleaseFence(); if (fence.IsValid()) { - RefPtr tracker = new FenceDeliveryTracker(fence); - HoldUntilComplete(tracker); - mPendingAsyncMessage.push_back(OpDeliverFence(tracker->GetId(), - aTexture, nullptr, + mPendingAsyncMessage.push_back(OpDeliverFence(aTexture, nullptr, fence)); } } @@ -1011,10 +998,7 @@ LayerTransactionParent::SendFenceHandleIfPresent(PTextureParent* aTexture, // Send a ReleaseFence that is set by HwcComposer2D. FenceHandle fence = texture->GetAndResetReleaseFenceHandle(); if (fence.IsValid()) { - RefPtr tracker = new FenceDeliveryTracker(fence); - HoldUntilComplete(tracker); - mPendingAsyncMessage.push_back(OpDeliverFence(tracker->GetId(), - aTexture, nullptr, + mPendingAsyncMessage.push_back(OpDeliverFence(aTexture, nullptr, fence)); } } @@ -1024,10 +1008,8 @@ LayerTransactionParent::SendFenceHandle(AsyncTransactionTracker* aTracker, PTextureParent* aTexture, const FenceHandle& aFence) { - HoldUntilComplete(aTracker); InfallibleTArray messages; - messages.AppendElement(OpDeliverFence(aTracker->GetId(), - aTexture, nullptr, + messages.AppendElement(OpDeliverFence(aTexture, nullptr, aFence)); mozilla::unused << SendParentAsyncMessages(messages); } diff --git a/gfx/layers/ipc/LayersMessages.ipdlh b/gfx/layers/ipc/LayersMessages.ipdlh index ab4ce9722a59..822fb0a4eddf 100644 --- a/gfx/layers/ipc/LayersMessages.ipdlh +++ b/gfx/layers/ipc/LayersMessages.ipdlh @@ -367,11 +367,15 @@ struct OpRemoveTextureAsync { }; struct OpReplyRemoveTexture { - bool isMain; uint64_t holderId; uint64_t transactionId; }; +union MaybeFence { + FenceHandle; + null_t; +}; + /** * Tells the compositor-side which texture to use (for example, as front buffer * if there is several textures for double buffering) @@ -379,6 +383,7 @@ struct OpReplyRemoveTexture { struct OpUseTexture { PCompositable compositable; PTexture texture; + MaybeFence fence; }; struct OpUseComponentAlphaTextures { @@ -393,28 +398,21 @@ union MaybeRegion { }; struct OpDeliverFence { - uint64_t transactionId; PTexture texture; FenceHandle fence; }; struct OpDeliverFenceToTracker { - uint64_t transactionId; uint64_t destHolderId; uint64_t destTransactionId; FenceHandle fence; }; struct OpDeliverFenceFromChild { - uint64_t transactionId; PTexture texture; FenceHandle fence; }; -struct OpReplyDeliverFence { - uint64_t transactionId; -}; - union CompositableOperation { OpUpdatePictureRect; @@ -480,13 +478,11 @@ union EditReply { union AsyncParentMessageData { OpDeliverFence; OpDeliverFenceToTracker; - OpReplyDeliverFence; OpReplyRemoveTexture; }; union AsyncChildMessageData { OpDeliverFenceFromChild; - OpReplyDeliverFence; OpRemoveTextureAsync; }; diff --git a/gfx/layers/ipc/ShadowLayers.cpp b/gfx/layers/ipc/ShadowLayers.cpp index 6cfc9d39ca66..b676cb6eec7d 100644 --- a/gfx/layers/ipc/ShadowLayers.cpp +++ b/gfx/layers/ipc/ShadowLayers.cpp @@ -369,15 +369,11 @@ ShadowLayerForwarder::UseTexture(CompositableClient* aCompositable, MOZ_ASSERT(aTexture); MOZ_ASSERT(aCompositable->GetIPDLActor()); MOZ_ASSERT(aTexture->GetIPDLActor()); -#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 - FenceHandle handle = aTexture->GetAcquireFenceHandle(); - if (handle.IsValid()) { - RefPtr tracker = new FenceDeliveryTracker(handle); - SendFenceHandle(tracker, aTexture->GetIPDLActor(), handle); - } -#endif + + FenceHandle fence = aTexture->GetAcquireFenceHandle(); mTxn->AddEdit(OpUseTexture(nullptr, aCompositable->GetIPDLActor(), - nullptr, aTexture->GetIPDLActor())); + nullptr, aTexture->GetIPDLActor(), + fence.IsValid() ? MaybeFence(fence) : MaybeFence(null_t()))); if (aTexture->GetFlags() & TextureFlags::IMMEDIATE_UPLOAD && aTexture->HasInternalBuffer()) { // We use IMMEDIATE_UPLOAD when we want to be sure that the upload cannot @@ -855,22 +851,15 @@ void ShadowLayerForwarder::SendPendingAsyncMessges() { if (!HasShadowManager() || !mShadowManager->IPCOpen()) { - mTransactionsToRespond.clear(); mPendingAsyncMessages.clear(); return; } - if (mTransactionsToRespond.empty() && mPendingAsyncMessages.empty()) { + if (mPendingAsyncMessages.empty()) { return; } InfallibleTArray replies; - replies.SetCapacity(mTransactionsToRespond.size()); - // Prepare OpReplyDeliverFence messages. - for (size_t i = 0; i < mTransactionsToRespond.size(); i++) { - replies.AppendElement(OpReplyDeliverFence(mTransactionsToRespond[i])); - } - mTransactionsToRespond.clear(); // Prepare pending messages. for (size_t i = 0; i < mPendingAsyncMessages.size(); i++) { replies.AppendElement(mPendingAsyncMessages[i]); diff --git a/gfx/layers/opengl/GrallocTextureHost.cpp b/gfx/layers/opengl/GrallocTextureHost.cpp index 0c4c4a1bbef3..ec2a9df0c7b5 100644 --- a/gfx/layers/opengl/GrallocTextureHost.cpp +++ b/gfx/layers/opengl/GrallocTextureHost.cpp @@ -260,6 +260,19 @@ GrallocTextureHostOGL::UnbindTextureSource() mGLTextureSource = nullptr; } +FenceHandle +GrallocTextureHostOGL::GetAndResetReleaseFenceHandle() +{ +#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 + android::sp fence = GetAndResetReleaseFence(); + if (fence.get() && fence->isValid()) { + FenceHandle handle = FenceHandle(fence); + return handle; + } +#endif + return FenceHandle(); +} + GLenum GetTextureTarget(gl::GLContext* aGL, android::PixelFormat aFormat) { MOZ_ASSERT(aGL); if (aGL->Renderer() == gl::GLRenderer::SGX530 || diff --git a/gfx/layers/opengl/GrallocTextureHost.h b/gfx/layers/opengl/GrallocTextureHost.h index 037df6634c5b..1fb54e463094 100644 --- a/gfx/layers/opengl/GrallocTextureHost.h +++ b/gfx/layers/opengl/GrallocTextureHost.h @@ -53,6 +53,8 @@ public: virtual void UnbindTextureSource() override; + virtual FenceHandle GetAndResetReleaseFenceHandle() override; + #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 virtual TextureHostOGL* AsHostOGL() override {