From 7b18f355cb944a0db4f0887f8ae7841b6fa63a50 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Tue, 2 Aug 2016 17:53:06 +1200 Subject: [PATCH] Bug 1289640 - Part 2: Stop using the D3D11 immediate context to upload texture data in IMFYCbCrImage and stick to threadsafe APIs so that we can use the content device. r=Bas --HG-- extra : rebase_source : 1186b758656f07ef786f7d182a6474b050b9367e --- gfx/layers/IMFYCbCrImage.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/gfx/layers/IMFYCbCrImage.cpp b/gfx/layers/IMFYCbCrImage.cpp index 7b367a36fb42..6bd8243e1733 100644 --- a/gfx/layers/IMFYCbCrImage.cpp +++ b/gfx/layers/IMFYCbCrImage.cpp @@ -226,7 +226,7 @@ IMFYCbCrImage::GetTextureClient(CompositableClient* aClient) } RefPtr device = - gfx::DeviceManagerD3D11::Get()->GetImageBridgeDevice(); + gfx::DeviceManagerD3D11::Get()->GetContentDevice(); LayersBackend backend = aClient->GetForwarder()->GetCompositorBackendType(); if (!device || backend != LayersBackend::LAYERS_D3D11) { @@ -237,8 +237,10 @@ IMFYCbCrImage::GetTextureClient(CompositableClient* aClient) return nullptr; } - RefPtr ctx; - device->GetImmediateContext(getter_AddRefs(ctx)); + if (mData.mYStride < 0 || mData.mCbCrStride < 0) { + // D3D11 only supports unsigned stride values. + return nullptr; + } CD3D11_TEXTURE2D_DESC newDesc(DXGI_FORMAT_R8_UNORM, mData.mYSize.width, mData.mYSize.height, 1, 1); @@ -246,31 +248,29 @@ IMFYCbCrImage::GetTextureClient(CompositableClient* aClient) newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX; RefPtr textureY; - HRESULT hr = device->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(textureY)); + D3D11_SUBRESOURCE_DATA yData = { mData.mYChannel, (UINT)mData.mYStride, 0 }; + HRESULT hr = device->CreateTexture2D(&newDesc, &yData, getter_AddRefs(textureY)); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); newDesc.Width = mData.mCbCrSize.width; newDesc.Height = mData.mCbCrSize.height; RefPtr textureCb; - hr = device->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(textureCb)); + D3D11_SUBRESOURCE_DATA cbData = { mData.mCbChannel, (UINT)mData.mCbCrStride, 0 }; + hr = device->CreateTexture2D(&newDesc, &cbData, getter_AddRefs(textureCb)); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); RefPtr textureCr; - hr = device->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(textureCr)); + D3D11_SUBRESOURCE_DATA crData = { mData.mCrChannel, (UINT)mData.mCbCrStride, 0 }; + hr = device->CreateTexture2D(&newDesc, &crData, getter_AddRefs(textureCr)); NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr); + // Even though the textures we created are meant to be protected by a keyed mutex, + // it appears that D3D doesn't include the initial memory upload within this + // synchronization. Add an empty lock/unlock pair since that appears to + // be sufficient to make sure we synchronize. { - AutoLockTexture lockY(textureY); - AutoLockTexture lockCb(textureCb); AutoLockTexture lockCr(textureCr); - - ctx->UpdateSubresource(textureY, 0, nullptr, mData.mYChannel, - mData.mYStride, mData.mYStride * mData.mYSize.height); - ctx->UpdateSubresource(textureCb, 0, nullptr, mData.mCbChannel, - mData.mCbCrStride, mData.mCbCrStride * mData.mCbCrSize.height); - ctx->UpdateSubresource(textureCr, 0, nullptr, mData.mCrChannel, - mData.mCbCrStride, mData.mCbCrStride * mData.mCbCrSize.height); } mTextureClient = TextureClient::CreateWithData(