TextureClientD3D11::~TextureClientD3D11() { if (mActor) { if (mTexture) { KeepUntilFullDeallocation(MakeUnique<TKeepAlive<ID3D10Texture2D>>(mTexture10)); } else if (mTexture10) { KeepUntilFullDeallocation(MakeUnique<TKeepAlive<ID3D11Texture2D>>(mTexture)); } } #ifdef DEBUG // An Azure DrawTarget needs to be locked when it gets nullptr'ed as this is // when it calls EndDraw. This EndDraw should not execute anything so it // shouldn't -really- need the lock but the debug layer chokes on this. if (mDrawTarget) { MOZ_ASSERT(!mIsLocked); MOZ_ASSERT(mTexture || mTexture10); MOZ_ASSERT(mDrawTarget->refCount() == 1); if (mTexture) { LockD3DTexture(mTexture.get()); } else { LockD3DTexture(mTexture10.get()); } mDrawTarget = nullptr; if (mTexture) { UnlockD3DTexture(mTexture.get()); } else { UnlockD3DTexture(mTexture10.get()); } } #endif }
bool TextureClientD3D11::Lock(OpenMode aMode) { if (!IsAllocated()) { return false; } MOZ_ASSERT(!mIsLocked, "The Texture is already locked!"); if (mTexture) { MOZ_ASSERT(!mTexture10); mIsLocked = LockD3DTexture(mTexture.get()); } else { MOZ_ASSERT(!mTexture); mIsLocked = LockD3DTexture(mTexture10.get()); } if (!mIsLocked) { return false; } if (NS_IsMainThread()) { // 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(); if (!mDrawTarget) { Unlock(); return false; } mDrawTarget->ClearRect(Rect(0, 0, GetSize().width, GetSize().height)); mNeedsClear = false; } if (mNeedsClearWhite) { mDrawTarget = BorrowDrawTarget(); if (!mDrawTarget) { Unlock(); return false; } mDrawTarget->FillRect(Rect(0, 0, GetSize().width, GetSize().height), ColorPattern(Color(1.0, 1.0, 1.0, 1.0))); mNeedsClearWhite = false; } } return true; }
TextureClientD3D11::~TextureClientD3D11() { #ifdef DEBUG // An Azure DrawTarget needs to be locked when it gets nullptr'ed as this is // when it calls EndDraw. This EndDraw should not execute anything so it // shouldn't -really- need the lock but the debug layer chokes on this. if (mDrawTarget) { MOZ_ASSERT(!mIsLocked); MOZ_ASSERT(mTexture || mTexture10); MOZ_ASSERT(mDrawTarget->refCount() == 1); if (mTexture) { LockD3DTexture(mTexture.get()); } else { LockD3DTexture(mTexture10.get()); } mDrawTarget = nullptr; if (mTexture) { UnlockD3DTexture(mTexture.get()); } else { UnlockD3DTexture(mTexture10.get()); } } #endif }
bool DXGITextureHostD3D11::Lock() { if (!GetDevice()) { NS_WARNING("trying to lock a TextureHost without a D3D device"); return false; } if (!mTextureSource) { if (!mTexture && !OpenSharedHandle()) { return false; } mTextureSource = new DataTextureSourceD3D11(mFormat, mCompositor, mTexture); } mIsLocked = LockD3DTexture(mTextureSource->GetD3D11Texture()); return mIsLocked; }