Issue #2393 - Part 2 - Add D3D11YCbCrImage type and related methods

Will allow to directly upload a YUV420 buffer into a D3D11 texture.
This commit is contained in:
trav90 2023-11-28 14:40:11 -06:00 committed by roytam1
commit 74a22e5c00
9 changed files with 568 additions and 69 deletions

View file

@ -34,38 +34,6 @@ IMFYCbCrImage::~IMFYCbCrImage()
}
}
struct AutoLockTexture
{
AutoLockTexture(ID3D11Texture2D* aTexture)
{
aTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mMutex));
if (!mMutex) {
return;
}
HRESULT hr = mMutex->AcquireSync(0, 10000);
if (hr == WAIT_TIMEOUT) {
MOZ_CRASH("GFX: IMFYCbCrImage timeout");
}
if (FAILED(hr)) {
NS_WARNING("Failed to lock the texture");
}
}
~AutoLockTexture()
{
if (!mMutex) {
return;
}
HRESULT hr = mMutex->ReleaseSync(0);
if (FAILED(hr)) {
NS_WARNING("Failed to unlock the texture");
}
}
RefPtr<IDXGIKeyedMutex> mMutex;
};
static already_AddRefed<IDirect3DTexture9>
InitTextures(IDirect3DDevice9* aDevice,
const IntSize &aSize,
@ -302,9 +270,9 @@ IMFYCbCrImage::GetTextureClient(KnowsCompositor* aForwarder)
// required but were added for extra security.
{
AutoLockTexture lockY(textureY);
AutoLockTexture lockCr(textureCr);
AutoLockTexture lockCb(textureCb);
AutoLockD3D11Texture lockY(textureY);
AutoLockD3D11Texture lockCr(textureCr);
AutoLockD3D11Texture lockCb(textureCb);
mt->Enter();
@ -327,9 +295,9 @@ IMFYCbCrImage::GetTextureClient(KnowsCompositor* aForwarder)
}
mTextureClient = TextureClient::CreateWithData(
DXGIYCbCrTextureData::Create(TextureFlags::DEFAULT,
textureY, textureCb, textureCr,
GetSize(), mData.mYSize, mData.mCbCrSize),
DXGIYCbCrTextureData::Create(textureY, textureCb, textureCr,
aSize, aData.mYSize, aData.mCbCrSize);
TextureFlags::DEFAULT,
aForwarder->GetTextureForwarder()
);