Bug 1341496 - Part 1: Don't try to serialize read locks that aren't valid. r?nical
MozReview-Commit-ID: 4CNlzWPlQMo
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -582,23 +582,24 @@ TextureClient::EnableReadLock()
bool
TextureClient::SerializeReadLock(ReadLockDescriptor& aDescriptor)
{
if (mReadLock && mUpdated) {
// Take a read lock on behalf of the TextureHost. The latter will unlock
// after the shared data is available again for drawing.
mReadLock->ReadLock();
- mReadLock->Serialize(aDescriptor, GetAllocator()->GetParentPid());
mUpdated = false;
- return true;
- } else {
- aDescriptor = null_t();
- return false;
+ if (mReadLock->Serialize(aDescriptor, GetAllocator()->GetParentPid())) {
+ return true;
+ }
}
+
+ aDescriptor = null_t();
+ return false;
}
TextureClient::~TextureClient()
{
mReadLock = nullptr;
Destroy();
}
@@ -1441,24 +1442,33 @@ public:
: mSemaphore("TextureReadLock", 1)
{}
explicit CrossProcessSemaphoreReadLock(CrossProcessSemaphoreHandle aHandle)
: mSemaphore(aHandle)
{}
virtual bool ReadLock() override
{
+ if (!IsValid()) {
+ return false;
+ }
return mSemaphore.Wait();
}
virtual bool TryReadLock(TimeDuration aTimeout) override
{
+ if (!IsValid()) {
+ return false;
+ }
return mSemaphore.Wait(Some(aTimeout));
}
virtual int32_t ReadUnlock() override
{
+ if (!IsValid()) {
+ return 1;
+ }
mSemaphore.Signal();
return 1;
}
virtual bool IsValid() const override { return true; }
virtual bool Serialize(ReadLockDescriptor& aOutput, base::ProcessId aOther) override;
virtual LockType GetType() override { return TYPE_CROSS_PROCESS_SEMAPHORE; }
@@ -1640,18 +1650,22 @@ ShmemTextureReadLock::GetReadCount() {
}
ShmReadLockInfo* info = GetShmReadLockInfoPtr();
return info->readCount;
}
bool
CrossProcessSemaphoreReadLock::Serialize(ReadLockDescriptor& aOutput, base::ProcessId aOther)
{
- aOutput = ReadLockDescriptor(CrossProcessSemaphoreDescriptor(mSemaphore.ShareToProcess(aOther)));
- return true;
+ if (IsValid()) {
+ aOutput = ReadLockDescriptor(CrossProcessSemaphoreDescriptor(mSemaphore.ShareToProcess(aOther)));
+ return true;
+ } else {
+ return false;
+ }
}
void
TextureClient::EnableBlockingReadLock()
{
if (!mReadLock) {
mReadLock = new CrossProcessSemaphoreReadLock();
}