diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index 46032a5a163..72914e09411 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -100,14 +100,16 @@ DataTextureSourceD3D11::~DataTextureSourceD3D11() template // ID3D10Texture2D or ID3D11Texture2D -static void LockD3DTexture(T* aTexture) +static bool LockD3DTexture(T* aTexture) { MOZ_ASSERT(aTexture); RefPtr mutex; aTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex)); - if (mutex) { - mutex->AcquireSync(0, INFINITE); + if (!mutex) { + return false; } + mutex->AcquireSync(0, INFINITE); + return true; } template // 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 diff --git a/gfx/layers/d3d9/TextureD3D9.cpp b/gfx/layers/d3d9/TextureD3D9.cpp index d15bd52cb5d..189ff4e5e7e 100644 --- a/gfx/layers/d3d9/TextureD3D9.cpp +++ b/gfx/layers/d3d9/TextureD3D9.cpp @@ -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));