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 }
void TextureClientD3D11::Unlock() { MOZ_ASSERT(mIsLocked, "Unlocked called while the texture is not locked!"); if (!mIsLocked) { return; } if (mDrawTarget) { // see the comment on TextureClient::BorrowDrawTarget. // This DrawTarget is internal to the TextureClient and is only exposed to the // outside world between Lock() and Unlock(). This assertion checks that no outside // reference remains by the time Unlock() is called. MOZ_ASSERT(mDrawTarget->refCount() == 1); mDrawTarget->Flush(); } if (mReadbackSink && mTexture10) { ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device(); D3D10_TEXTURE2D_DESC desc; mTexture10->GetDesc(&desc); desc.BindFlags = 0; desc.Usage = D3D10_USAGE_STAGING; desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; desc.MiscFlags = 0; RefPtr<ID3D10Texture2D> tex; HRESULT hr = device->CreateTexture2D(&desc, nullptr, byRef(tex)); if (FAILED(hr)) { gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(mSize))) << "[D3D11] CreateTexture2D failure " << mSize << " Code: " << gfx::hexa(hr); return; } if (SUCCEEDED(hr)) { device->CopyResource(tex, mTexture10); gfxWindowsPlatform::GetPlatform()->GetReadbackManager()->PostTask(tex, mReadbackSink); } else { mReadbackSink->ProcessReadback(nullptr); } } // The DrawTarget is created only once, and is only usable between calls // to Lock and Unlock. if (mTexture) { UnlockD3DTexture(mTexture.get()); } else { UnlockD3DTexture(mTexture10.get()); } mIsLocked = false; }
void DXGITextureHostD3D11::Unlock() { MOZ_ASSERT(mIsLocked); UnlockD3DTexture(mTextureSource->GetD3D11Texture()); mIsLocked = false; }
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 }