From 580c75e9e0565957e8c6868bad2ab3cb087740c8 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Mon, 28 Jul 2014 14:58:38 +0200 Subject: [PATCH] Bug 1043929 - Ensure that a locked TextureHost can give access to a valid TextureSource for some of the texture types. r=Bas --- gfx/layers/composite/TextureHost.cpp | 17 +++++++++++------ gfx/layers/d3d11/TextureD3D11.cpp | 3 +++ gfx/layers/d3d9/TextureD3D9.cpp | 14 +++++++++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index d5006f87a29..ed22f1fa7da 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -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; } diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index 8e4f91977ef..db3bddd0f91 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -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(); } diff --git a/gfx/layers/d3d9/TextureD3D9.cpp b/gfx/layers/d3d9/TextureD3D9.cpp index 185ec87a997..f11e0dc045b 100644 --- a/gfx/layers/d3d9/TextureD3D9.cpp +++ b/gfx/layers/d3d9/TextureD3D9.cpp @@ -763,6 +763,7 @@ TextureHostD3D9::TextureHostD3D9(TextureFlags aFlags, , mIsLocked(false) { mTexture = reinterpret_cast(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; }