diff --git a/gfx/layers/ipc/FenceUtilsGonk.cpp b/gfx/layers/ipc/FenceUtilsGonk.cpp index e27e3b227c6c..030b5cc75962 100644 --- a/gfx/layers/ipc/FenceUtilsGonk.cpp +++ b/gfx/layers/ipc/FenceUtilsGonk.cpp @@ -29,7 +29,6 @@ ParamTraits::Write(Message* aMsg, #endif size_t nbytes = flattenable->getFlattenedSize(); size_t nfds = flattenable->getFdCount(); - char data[nbytes]; int fds[nfds]; @@ -53,10 +52,10 @@ ParamTraits::Write(Message* aMsg, aMsg->WriteSize(nfds); aMsg->WriteBytes(data, nbytes); for (size_t n = 0; n < nfds; ++n) { - // These buffers can't die in transit because they're created - // synchonously and the parent-side buffer can only be dropped if - // there's a crash. - aMsg->WriteFileDescriptor(FileDescriptor(fds[n], false)); + // Dupe the fd to make sure the fence life time and set auto-close + // for cross-process. If IPC is cross-thread, the other side will use + // the duped fd directly. + aMsg->WriteFileDescriptor(FileDescriptor(dup(fds[n]), true)); } } @@ -91,106 +90,6 @@ ParamTraits::Read(const Message* aMsg, // SCM_RIGHTS doesn't dup the fd. That's surprising, but we just // deal with it here. NB: only the "default" (master) process can // alloc gralloc buffers. - bool sameProcess = (XRE_GetProcessType() == GeckoProcessType_Default); - int dupFd = sameProcess ? dup(fd.fd) : fd.fd; - fds[n] = dupFd; - } - - sp buffer(new Fence()); -#if ANDROID_VERSION >= 19 - // Make a copy of "data" and "fds" for unflatten() to avoid casting problem - void const *pdata = (void const *)data; - int const *pfds = fds; - - if (NO_ERROR == buffer->unflatten(pdata, nbytes, pfds, nfds)) { -#else - Flattenable *flattenable = buffer.get(); - - if (NO_ERROR == flattenable->unflatten(data, nbytes, fds, nfds)) { -#endif - aResult->mFence = buffer; - return true; - } - return false; -} - -void -ParamTraits::Write(Message* aMsg, - const paramType& aParam) -{ -#if ANDROID_VERSION >= 19 - sp flattenable = aParam.mFence; -#else - Flattenable *flattenable = aParam.mFence.get(); -#endif - size_t nbytes = flattenable->getFlattenedSize(); - size_t nfds = flattenable->getFdCount(); - - char data[nbytes]; - int fds[nfds]; - -#if ANDROID_VERSION >= 19 - // Make a copy of "data" and "fds" for flatten() to avoid casting problem - void *pdata = (void *)data; - int *pfds = fds; - - flattenable->flatten(pdata, nbytes, pfds, nfds); - - // In Kitkat, flatten() will change the value of nbytes and nfds, which dues - // to multiple parcelable object consumption. The actual size and fd count - // which returned by getFlattenedSize() and getFdCount() are not changed. - // So we change nbytes and nfds back by call corresponding calls. - nbytes = flattenable->getFlattenedSize(); - nfds = flattenable->getFdCount(); -#else - flattenable->flatten(data, nbytes, fds, nfds); -#endif - aMsg->WriteSize(nbytes); - aMsg->WriteSize(nfds); - aMsg->WriteBytes(data, nbytes); - for (size_t n = 0; n < nfds; ++n) { - // If the Fence was shared cross-process, SCM_RIGHTS does - // the right thing and dup's the fd. If it's shared cross-thread, - // SCM_RIGHTS doesn't dup the fd. That's surprising, but we just - // deal with it here. NB: only the "default" (master) process can - // alloc gralloc buffers. - bool sameProcess = (XRE_GetProcessType() == GeckoProcessType_Default); - int dupFd = sameProcess ? dup(fds[n]) : fds[n]; - //int dupFd = fds[n]; - - // These buffers can't die in transit because they're created - // synchonously and the parent-side buffer can only be dropped if - // there's a crash. - aMsg->WriteFileDescriptor(FileDescriptor(dupFd, false)); - } -} - -bool -ParamTraits::Read(const Message* aMsg, - void** aIter, paramType* aResult) -{ - size_t nbytes; - size_t nfds; - const char* data; - - if (!aMsg->ReadSize(aIter, &nbytes) || - !aMsg->ReadSize(aIter, &nfds) || - !aMsg->ReadBytes(aIter, &data, nbytes)) { - return false; - } - - // Check if nfds is correct. - // aMsg->num_fds() could include fds of another ParamTraits<>s. - if (nfds > aMsg->num_fds()) { - return false; - } - int fds[nfds]; - - for (size_t n = 0; n < nfds; ++n) { - FileDescriptor fd; - if (!aMsg->ReadFileDescriptor(aIter, &fd)) { - return false; - } fds[n] = fd.fd; } @@ -217,13 +116,14 @@ ParamTraits::Read(const Message* aMsg, namespace mozilla { namespace layers { -FenceHandle::FenceHandle(const sp& aFence) - : mFence(aFence) +FenceHandle::FenceHandle() + : mFence(android::Fence::NO_FENCE) { } -FenceHandle::FenceHandle(const FenceHandleFromChild& aFenceHandle) { - mFence = aFenceHandle.mFence; +FenceHandle::FenceHandle(const sp& aFence) + : mFence(aFence) +{ } void @@ -250,10 +150,5 @@ FenceHandle::Merge(const FenceHandle& aFenceHandle) } } -FenceHandleFromChild::FenceHandleFromChild(const sp& aFence) - : mFence(aFence) -{ -} - } // namespace layers } // namespace mozilla diff --git a/gfx/layers/ipc/FenceUtilsGonk.h b/gfx/layers/ipc/FenceUtilsGonk.h index 6a82ded6ddc2..38ce45b81c17 100644 --- a/gfx/layers/ipc/FenceUtilsGonk.h +++ b/gfx/layers/ipc/FenceUtilsGonk.h @@ -16,16 +16,12 @@ namespace mozilla { namespace layers { -struct FenceHandleFromChild; - struct FenceHandle { typedef android::Fence Fence; - FenceHandle() - { } - explicit FenceHandle(const android::sp& aFence); + FenceHandle(); - explicit FenceHandle(const FenceHandleFromChild& aFenceHandle); + explicit FenceHandle(const android::sp& aFence); bool operator==(const FenceHandle& aOther) const { return mFence.get() == aOther.mFence.get(); @@ -41,33 +37,6 @@ struct FenceHandle { android::sp mFence; }; -struct FenceHandleFromChild { - typedef android::Fence Fence; - - FenceHandleFromChild() - { } - explicit FenceHandleFromChild(const android::sp& aFence); - - explicit FenceHandleFromChild(const FenceHandle& aFence) { - mFence = aFence.mFence; - } - - bool operator==(const FenceHandle& aOther) const { - return mFence.get() == aOther.mFence.get(); - } - - bool operator==(const FenceHandleFromChild& aOther) const { - return mFence.get() == aOther.mFence.get(); - } - - bool IsValid() const - { - return mFence.get() && mFence->isValid(); - } - - android::sp mFence; -}; - } // namespace layers } // namespace mozilla @@ -81,14 +50,6 @@ struct ParamTraits { static bool Read(const Message* aMsg, void** aIter, paramType* aResult); }; -template <> -struct ParamTraits { - typedef mozilla::layers::FenceHandleFromChild paramType; - - static void Write(Message* aMsg, const paramType& aParam); - static bool Read(const Message* aMsg, void** aIter, paramType* aResult); -}; - } // namespace IPC #endif // mozilla_layers_FenceUtilsGonk_h diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index dede6a288420..7b3243d8da63 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -160,7 +160,7 @@ ImageBridgeChild::SendFenceHandle(AsyncTransactionTracker* aTracker, InfallibleTArray messages; messages.AppendElement(OpDeliverFenceFromChild(aTracker->GetId(), nullptr, aTexture, - FenceHandleFromChild(aFence))); + aFence)); SendChildAsyncMessages(messages); } diff --git a/gfx/layers/ipc/LayerTransactionChild.cpp b/gfx/layers/ipc/LayerTransactionChild.cpp index 7e4bbb8f522e..b2342621fe86 100644 --- a/gfx/layers/ipc/LayerTransactionChild.cpp +++ b/gfx/layers/ipc/LayerTransactionChild.cpp @@ -129,7 +129,7 @@ LayerTransactionChild::SendFenceHandle(AsyncTransactionTracker* aTracker, InfallibleTArray messages; messages.AppendElement(OpDeliverFenceFromChild(aTracker->GetId(), nullptr, aTexture, - FenceHandleFromChild(aFence))); + aFence)); SendChildAsyncMessages(messages); } diff --git a/gfx/layers/ipc/LayersMessages.ipdlh b/gfx/layers/ipc/LayersMessages.ipdlh index fe5996e26936..ab4ce9722a59 100644 --- a/gfx/layers/ipc/LayersMessages.ipdlh +++ b/gfx/layers/ipc/LayersMessages.ipdlh @@ -41,7 +41,6 @@ using mozilla::layers::DiagnosticTypes from "mozilla/layers/CompositorTypes.h"; using struct mozilla::layers::FrameMetrics from "FrameMetrics.h"; using mozilla::layers::FrameMetrics::ViewID from "FrameMetrics.h"; using struct mozilla::layers::FenceHandle from "mozilla/layers/FenceUtils.h"; -using struct mozilla::layers::FenceHandleFromChild from "mozilla/layers/FenceUtils.h"; using std::string from "string"; namespace mozilla { @@ -409,7 +408,7 @@ struct OpDeliverFenceToTracker { struct OpDeliverFenceFromChild { uint64_t transactionId; PTexture texture; - FenceHandleFromChild fence; + FenceHandle fence; }; struct OpReplyDeliverFence {