Bug 1019000 - Ensure that successfully write-locked D3D TextureClients provide a valid DrawTarget. r=mattwoodrow

This commit is contained in:
Nicolas Silva 2014-07-04 10:26:14 +02:00
parent 53c7044efa
commit 1a0d677506
2 changed files with 34 additions and 9 deletions

View File

@ -100,14 +100,16 @@ DataTextureSourceD3D11::~DataTextureSourceD3D11()
template<typename T> // ID3D10Texture2D or ID3D11Texture2D
static void LockD3DTexture(T* aTexture)
static bool LockD3DTexture(T* aTexture)
{
MOZ_ASSERT(aTexture);
RefPtr<IDXGIKeyedMutex> mutex;
aTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
if (mutex) {
mutex->AcquireSync(0, INFINITE);
if (!mutex) {
return false;
}
mutex->AcquireSync(0, INFINITE);
return true;
}
template<typename T> // ID3D10Texture2D or ID3D11Texture2D
@ -180,8 +182,21 @@ TextureClientD3D11::Lock(OpenMode aMode)
return false;
}
MOZ_ASSERT(!mIsLocked, "The Texture is already locked!");
LockD3DTexture(mTexture.get());
mIsLocked = true;
mIsLocked = LockD3DTexture(mTexture.get());
if (!mIsLocked) {
return false;
}
// Make sure that successful write-lock means we will have a DrawTarget to
// write into.
if (aMode & OpenMode::OPEN_WRITE) {
mDrawTarget = BorrowDrawTarget();
if (!mDrawTarget) {
Unlock();
return false;
}
}
if (mNeedsClear) {
mDrawTarget = BorrowDrawTarget();
@ -230,6 +245,7 @@ TextureClientD3D11::BorrowDrawTarget()
return mDrawTarget;
}
// This may return a null DrawTarget
mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, mFormat);
return mDrawTarget;
}
@ -324,10 +340,9 @@ DXGITextureHostD3D11::Lock()
mSize = IntSize(desc.Width, desc.Height);
}
LockD3DTexture(mTextureSource->GetD3D11Texture());
mIsLocked = LockD3DTexture(mTextureSource->GetD3D11Texture());
mIsLocked = true;
return true;
return mIsLocked;
}
void

View File

@ -563,7 +563,7 @@ CairoTextureClientD3D9::~CairoTextureClientD3D9()
}
bool
CairoTextureClientD3D9::Lock(OpenMode)
CairoTextureClientD3D9::Lock(OpenMode aMode)
{
MOZ_ASSERT(!mIsLocked);
if (!IsValid() || !IsAllocated()) {
@ -587,6 +587,16 @@ CairoTextureClientD3D9::Lock(OpenMode)
mIsLocked = true;
// Make sure that successful write-lock means we will have a DrawTarget to
// write into.
if (aMode & OpenMode::OPEN_WRITE) {
mDrawTarget = BorrowDrawTarget();
if (!mDrawTarget) {
Unlock();
return false;
}
}
if (mNeedsClear) {
mDrawTarget = BorrowDrawTarget();
mDrawTarget->ClearRect(Rect(0, 0, GetSize().width, GetSize().height));