Bug 1043929 - Ensure that a locked TextureHost can give access to a valid TextureSource for some of the texture types. r=Bas

This commit is contained in:
Nicolas Silva 2014-07-28 14:58:38 +02:00
parent c0638f4f0a
commit 580c75e9e0
3 changed files with 25 additions and 9 deletions

View File

@ -397,23 +397,26 @@ BufferTextureHost::DeallocateDeviceData()
bool
BufferTextureHost::Lock()
{
mLocked = true;
return true;
MOZ_ASSERT(!mLocked);
if (!MaybeUpload(mPartialUpdate ? &mMaybeUpdatedRegion : nullptr)) {
return false;
}
mLocked = !!mFirstSource;
return mLocked;
}
void
BufferTextureHost::Unlock()
{
MOZ_ASSERT(mLocked);
mLocked = false;
}
NewTextureSource*
BufferTextureHost::GetTextureSources()
{
MOZ_ASSERT(mLocked, "should never be called while not locked");
if (!MaybeUpload(mPartialUpdate ? &mMaybeUpdatedRegion : nullptr)) {
return nullptr;
}
MOZ_ASSERT(mLocked);
MOZ_ASSERT(mFirstSource);
return mFirstSource;
}
@ -442,6 +445,7 @@ BufferTextureHost::MaybeUpload(nsIntRegion *aRegion)
if (!Upload(aRegion)) {
return false;
}
// If upload returns true we know mFirstSource is not null
mFirstSource->SetUpdateSerial(mUpdateSerial);
return true;
}
@ -546,6 +550,7 @@ BufferTextureHost::Upload(nsIntRegion *aRegion)
return false;
}
}
MOZ_ASSERT(mFirstSource);
return true;
}

View File

@ -394,6 +394,9 @@ DXGITextureHostD3D11::Unlock()
NewTextureSource*
DXGITextureHostD3D11::GetTextureSources()
{
MOZ_ASSERT(mIsLocked);
// If Lock was successful we must have a valid TextureSource.
MOZ_ASSERT(mTextureSource);
return mTextureSource.get();
}

View File

@ -763,6 +763,7 @@ TextureHostD3D9::TextureHostD3D9(TextureFlags aFlags,
, mIsLocked(false)
{
mTexture = reinterpret_cast<IDirect3DTexture9*>(aDescriptor.texture());
MOZ_ASSERT(mTexture);
mTexture->Release(); // see AddRef in CairoTextureClientD3D9::ToSurfaceDescriptor
MOZ_ASSERT(mTexture);
D3DSURFACE_DESC desc;
@ -848,6 +849,7 @@ DataTextureSourceD3D9::UpdateFromTexture(IDirect3DTexture9* aTexture,
void
TextureHostD3D9::Updated(const nsIntRegion* aRegion)
{
MOZ_ASSERT(mTexture);
if (!mTexture) {
return;
}
@ -879,6 +881,7 @@ NewTextureSource*
TextureHostD3D9::GetTextureSources()
{
MOZ_ASSERT(mIsLocked);
MOZ_ASSERT(mTextureSource);
return mTextureSource;
}
@ -886,8 +889,11 @@ bool
TextureHostD3D9::Lock()
{
MOZ_ASSERT(!mIsLocked);
mIsLocked = true;
return true;
// XXX - Currently if a TextureHostD3D9 is created but Update is never called,
// it will not have a TextureSource although it could since it has a valid
// D3D9 texture.
mIsLocked = !!mTextureSource;
return mIsLocked;
}
void
@ -917,12 +923,15 @@ DXGITextureHostD3D9::DXGITextureHostD3D9(TextureFlags aFlags,
NewTextureSource*
DXGITextureHostD3D9::GetTextureSources()
{
MOZ_ASSERT(mIsLocked);
MOZ_ASSERT(mTextureSource);
return mTextureSource;
}
bool
DXGITextureHostD3D9::Lock()
{
MOZ_ASSERT(!mIsLocked);
DeviceManagerD3D9* deviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
if (!deviceManager) {
NS_WARNING("trying to lock a TextureHost without a D3D device");
@ -947,7 +956,6 @@ DXGITextureHostD3D9::Lock()
mTextureSource = new DataTextureSourceD3D9(mFormat, mSize, mCompositor, tex);
}
MOZ_ASSERT(!mIsLocked);
mIsLocked = true;
return true;
}