Bug 1762512 - Add array index handling to Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture() r=media-playback-reviewers,gfx-reviewers,lsalzman,alwu

The CreateBGRA8DataSourceSurfaceForD3D11Texture() does not handle array index yet. It is necessary for Bug 1758602.

Differential Revision: https://phabricator.services.mozilla.com/D142640
This commit is contained in:
sotaro 2022-04-05 00:30:13 +00:00
parent 631c25c933
commit c94824fb6c
5 changed files with 26 additions and 14 deletions

View File

@ -591,7 +591,7 @@ class D3D11DXVA2Manager : public DXVA2Manager {
const gfx::IntRect& aRegion,
layers::Image** aOutImage) override;
HRESULT CopyToBGRATexture(ID3D11Texture2D* aInTexture,
HRESULT CopyToBGRATexture(ID3D11Texture2D* aInTexture, uint32_t aArrayIndex,
ID3D11Texture2D** aOutTexture) override;
HRESULT ConfigureForSize(IMFMediaType* aInputType,
@ -1039,6 +1039,7 @@ HRESULT D3D11DXVA2Manager::WrapTextureWithImage(IMFSample* aVideoSample,
HRESULT
D3D11DXVA2Manager::CopyToBGRATexture(ID3D11Texture2D* aInTexture,
uint32_t aArrayIndex,
ID3D11Texture2D** aOutTexture) {
NS_ENSURE_TRUE(aInTexture, E_POINTER);
NS_ENSURE_TRUE(aOutTexture, E_POINTER);
@ -1124,8 +1125,9 @@ D3D11DXVA2Manager::CopyToBGRATexture(ID3D11Texture2D* aInTexture,
inputSample->SetSampleDuration(10000);
RefPtr<IMFMediaBuffer> inputBuffer;
hr = wmf::MFCreateDXGISurfaceBuffer(__uuidof(ID3D11Texture2D), inTexture, 0,
FALSE, getter_AddRefs(inputBuffer));
hr = wmf::MFCreateDXGISurfaceBuffer(__uuidof(ID3D11Texture2D), inTexture,
aArrayIndex, FALSE,
getter_AddRefs(inputBuffer));
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
inputSample->AddBuffer(inputBuffer);

View File

@ -50,6 +50,7 @@ class DXVA2Manager {
}
virtual HRESULT CopyToBGRATexture(ID3D11Texture2D* aInTexture,
uint32_t aArrayIndex,
ID3D11Texture2D** aOutTexture) {
// Not implemented!
MOZ_CRASH("CopyToBGRATexture not implemented on this manager.");

View File

@ -2089,13 +2089,15 @@ class GFX2D_API Factory {
static void SetSystemTextQuality(uint8_t aQuality);
static already_AddRefed<DataSourceSurface>
CreateBGRA8DataSourceSurfaceForD3D11Texture(ID3D11Texture2D* aSrcTexture);
CreateBGRA8DataSourceSurfaceForD3D11Texture(ID3D11Texture2D* aSrcTexture,
uint32_t aArrayIndex = 0);
static bool ReadbackTexture(layers::TextureData* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture);
static bool ReadbackTexture(DataSourceSurface* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture);
ID3D11Texture2D* aSrcTexture,
uint32_t aArrayIndex = 0);
private:
static StaticRefPtr<ID2D1Device> mD2D1Device;
@ -2112,7 +2114,8 @@ class GFX2D_API Factory {
// DestTextureT can be TextureData or DataSourceSurface.
template <typename DestTextureT>
static bool ConvertSourceAndRetryReadback(DestTextureT* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture);
ID3D11Texture2D* aSrcTexture,
uint32_t aArrayIndex = 0);
protected:
// This guards access to the singleton devices above, as well as the

View File

@ -1099,7 +1099,7 @@ void Factory::CopyDataSourceSurface(DataSourceSurface* aSource,
/* static */
already_AddRefed<DataSourceSurface>
Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture(
ID3D11Texture2D* aSrcTexture) {
ID3D11Texture2D* aSrcTexture, uint32_t aArrayIndex) {
D3D11_TEXTURE2D_DESC srcDesc = {0};
aSrcTexture->GetDesc(&srcDesc);
@ -1109,7 +1109,7 @@ Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture(
if (NS_WARN_IF(!destTexture)) {
return nullptr;
}
if (!ReadbackTexture(destTexture, aSrcTexture)) {
if (!ReadbackTexture(destTexture, aSrcTexture, aArrayIndex)) {
return nullptr;
}
return destTexture.forget();
@ -1118,7 +1118,8 @@ Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture(
/* static */
template <typename DestTextureT>
bool Factory::ConvertSourceAndRetryReadback(DestTextureT* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture) {
ID3D11Texture2D* aSrcTexture,
uint32_t aArrayIndex) {
RefPtr<ID3D11Device> device;
aSrcTexture->GetDevice(getter_AddRefs(device));
if (!device) {
@ -1135,8 +1136,8 @@ bool Factory::ConvertSourceAndRetryReadback(DestTextureT* aDestCpuTexture,
}
RefPtr<ID3D11Texture2D> newSrcTexture;
HRESULT hr =
manager->CopyToBGRATexture(aSrcTexture, getter_AddRefs(newSrcTexture));
HRESULT hr = manager->CopyToBGRATexture(aSrcTexture, aArrayIndex,
getter_AddRefs(newSrcTexture));
if (FAILED(hr)) {
gfxWarning() << "Failed to copy to BGRA texture.";
return false;
@ -1175,7 +1176,8 @@ bool Factory::ReadbackTexture(layers::TextureData* aDestCpuTexture,
/* static */
bool Factory::ReadbackTexture(DataSourceSurface* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture) {
ID3D11Texture2D* aSrcTexture,
uint32_t aArrayIndex) {
D3D11_TEXTURE2D_DESC srcDesc = {0};
aSrcTexture->GetDesc(&srcDesc);
@ -1183,7 +1185,8 @@ bool Factory::ReadbackTexture(DataSourceSurface* aDestCpuTexture,
// destination is B8G8R8A8 then convert the source to B8G8R8A8 and readback.
if ((srcDesc.Format != DXGIFormat(aDestCpuTexture->GetFormat())) &&
(aDestCpuTexture->GetFormat() == SurfaceFormat::B8G8R8A8)) {
return ConvertSourceAndRetryReadback(aDestCpuTexture, aSrcTexture);
return ConvertSourceAndRetryReadback(aDestCpuTexture, aSrcTexture,
aArrayIndex);
}
if ((IntSize(srcDesc.Width, srcDesc.Height) != aDestCpuTexture->GetSize()) ||
@ -1197,6 +1200,8 @@ bool Factory::ReadbackTexture(DataSourceSurface* aDestCpuTexture,
return false;
}
MOZ_ASSERT(aArrayIndex == 0);
bool ret =
ReadbackTexture(mappedSurface.mData, mappedSurface.mStride, aSrcTexture);
aDestCpuTexture->Unmap();

View File

@ -57,7 +57,8 @@ D3D11TextureIMFSampleImage::GetAsSourceSurface() {
return nullptr;
}
return gfx::Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture(src);
return gfx::Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture(src,
mArrayIndex);
}
ID3D11Texture2D* D3D11TextureIMFSampleImage::GetTexture() const {