Bug 1041416 - Preven a race condition between the deserialization and the destruction of DXGI textures for the D3D9 backend. r=Bas

This commit is contained in:
Nicolas Silva 2014-07-29 12:15:20 +02:00
parent be683d3829
commit 031ecfeacb
2 changed files with 44 additions and 21 deletions

View File

@ -724,6 +724,9 @@ SharedTextureClientD3D9::SharedTextureClientD3D9(gfx::SurfaceFormat aFormat, Tex
SharedTextureClientD3D9::~SharedTextureClientD3D9()
{
if (mTexture && mActor) {
KeepUntilFullDeallocation(new TKeepAlive<IDirect3DTexture9>(mTexture));
}
MOZ_COUNT_DTOR(SharedTextureClientD3D9);
}
@ -918,6 +921,39 @@ DXGITextureHostD3D9::DXGITextureHostD3D9(TextureFlags aFlags,
, mIsLocked(false)
{
MOZ_ASSERT(mHandle);
OpenSharedHandle();
}
IDirect3DDevice9*
DXGITextureHostD3D9::GetDevice()
{
return mCompositor ? mCompositor->device() : nullptr;
}
void
DXGITextureHostD3D9::OpenSharedHandle()
{
MOZ_ASSERT(!mTextureSource);
if (!GetDevice()) {
return;
}
nsRefPtr<IDirect3DTexture9> texture;
HRESULT hr = GetDevice()->CreateTexture(mSize.width, mSize.height, 1,
D3DUSAGE_RENDERTARGET,
SurfaceFormatToD3D9Format(mFormat),
D3DPOOL_DEFAULT,
getter_AddRefs(texture),
(HANDLE*)&mHandle);
if (FAILED(hr)) {
NS_WARNING("Failed to open shared texture");
return;
}
mTextureSource = new DataTextureSourceD3D9(mFormat, mSize, mCompositor, texture);
return;
}
NewTextureSource*
@ -932,32 +968,16 @@ bool
DXGITextureHostD3D9::Lock()
{
MOZ_ASSERT(!mIsLocked);
DeviceManagerD3D9* deviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
if (!deviceManager) {
NS_WARNING("trying to lock a TextureHost without a D3D device");
if (!GetDevice()) {
return false;
}
if (!mTextureSource) {
nsRefPtr<IDirect3DTexture9> tex;
HRESULT hr = deviceManager->device()->CreateTexture(mSize.width,
mSize.height,
1,
D3DUSAGE_RENDERTARGET,
SurfaceFormatToD3D9Format(mFormat),
D3DPOOL_DEFAULT,
getter_AddRefs(tex),
(HANDLE*)&mHandle);
if (FAILED(hr)) {
NS_WARNING("Failed to open shared texture");
return false;
}
mTextureSource = new DataTextureSourceD3D9(mFormat, mSize, mCompositor, tex);
OpenSharedHandle();
}
mIsLocked = true;
return true;
mIsLocked = !!mTextureSource;
return mIsLocked;
}
void

View File

@ -353,6 +353,9 @@ public:
}
protected:
void OpenSharedHandle();
IDirect3DDevice9* GetDevice();
RefPtr<DataTextureSourceD3D9> mTextureSource;
RefPtr<CompositorD3D9> mCompositor;
WindowsHandle mHandle;