Bug 1146214 - Combine FenceHandle and FenceHandleFromChild. r=nical

This commit is contained in:
Ethan Lin 2015-04-10 02:16:00 +02:00
Родитель b8ca526d2a
Коммит ffe96d98c7
5 изменённых файлов: 14 добавлений и 159 удалений

Просмотреть файл

@ -29,7 +29,6 @@ ParamTraits<FenceHandle>::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<FenceHandle>::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<FenceHandle>::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<Fence> 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<FenceHandleFromChild>::Write(Message* aMsg,
const paramType& aParam)
{
#if ANDROID_VERSION >= 19
sp<Fence> 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<FenceHandleFromChild>::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<FenceHandleFromChild>::Read(const Message* aMsg,
namespace mozilla {
namespace layers {
FenceHandle::FenceHandle(const sp<Fence>& aFence)
: mFence(aFence)
FenceHandle::FenceHandle()
: mFence(android::Fence::NO_FENCE)
{
}
FenceHandle::FenceHandle(const FenceHandleFromChild& aFenceHandle) {
mFence = aFenceHandle.mFence;
FenceHandle::FenceHandle(const sp<Fence>& aFence)
: mFence(aFence)
{
}
void
@ -250,10 +150,5 @@ FenceHandle::Merge(const FenceHandle& aFenceHandle)
}
}
FenceHandleFromChild::FenceHandleFromChild(const sp<Fence>& aFence)
: mFence(aFence)
{
}
} // namespace layers
} // namespace mozilla

Просмотреть файл

@ -16,16 +16,12 @@
namespace mozilla {
namespace layers {
struct FenceHandleFromChild;
struct FenceHandle {
typedef android::Fence Fence;
FenceHandle()
{ }
explicit FenceHandle(const android::sp<Fence>& aFence);
FenceHandle();
explicit FenceHandle(const FenceHandleFromChild& aFenceHandle);
explicit FenceHandle(const android::sp<Fence>& aFence);
bool operator==(const FenceHandle& aOther) const {
return mFence.get() == aOther.mFence.get();
@ -41,33 +37,6 @@ struct FenceHandle {
android::sp<Fence> mFence;
};
struct FenceHandleFromChild {
typedef android::Fence Fence;
FenceHandleFromChild()
{ }
explicit FenceHandleFromChild(const android::sp<Fence>& 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<Fence> mFence;
};
} // namespace layers
} // namespace mozilla
@ -81,14 +50,6 @@ struct ParamTraits<mozilla::layers::FenceHandle> {
static bool Read(const Message* aMsg, void** aIter, paramType* aResult);
};
template <>
struct ParamTraits<mozilla::layers::FenceHandleFromChild> {
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

Просмотреть файл

@ -160,7 +160,7 @@ ImageBridgeChild::SendFenceHandle(AsyncTransactionTracker* aTracker,
InfallibleTArray<AsyncChildMessageData> messages;
messages.AppendElement(OpDeliverFenceFromChild(aTracker->GetId(),
nullptr, aTexture,
FenceHandleFromChild(aFence)));
aFence));
SendChildAsyncMessages(messages);
}

Просмотреть файл

@ -129,7 +129,7 @@ LayerTransactionChild::SendFenceHandle(AsyncTransactionTracker* aTracker,
InfallibleTArray<AsyncChildMessageData> messages;
messages.AppendElement(OpDeliverFenceFromChild(aTracker->GetId(),
nullptr, aTexture,
FenceHandleFromChild(aFence)));
aFence));
SendChildAsyncMessages(messages);
}

Просмотреть файл

@ -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 {