From 55a951769fe4a4ef14af73625d16885d67137f3d Mon Sep 17 00:00:00 2001 From: sotaro Date: Tue, 21 Nov 2023 10:45:34 +0000 Subject: [PATCH] Bug 1865426 - Enable uploading to NV12 ID3D11Texture2D with WebRender(Software D3D11) r=gfx-reviewers,lsalzman With the change, yuv BufferTexture is uploaded to D3D11 NV12 texture also if webrender supports D3D11 and NV12. Calling GpuProcessD3D11TextureMap::GetTexture() is changed from RenderDXGITextureHost::EnsureD3D11Texture2DWithGL() to RenderDXGITextureHost::EnsureD3D11Texture2D(), since the EnsureD3D11Texture2DWithGL() is not called with WebRender(Software D3D11). Differential Revision: https://phabricator.services.mozilla.com/D194171 --- gfx/layers/ipc/KnowsCompositor.h | 11 +++++-- gfx/layers/wr/WebRenderImageHost.cpp | 4 ++- .../RenderD3D11TextureHost.cpp | 30 +++++++++---------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/gfx/layers/ipc/KnowsCompositor.h b/gfx/layers/ipc/KnowsCompositor.h index 7c8c3b780ddd..0124a970d197 100644 --- a/gfx/layers/ipc/KnowsCompositor.h +++ b/gfx/layers/ipc/KnowsCompositor.h @@ -120,10 +120,15 @@ class KnowsCompositor { bool SupportsD3D11() const { auto lock = mData.Lock(); - return lock.ref().mTextureFactoryIdentifier.mParentBackend == + return SupportsD3D11(lock.ref().mTextureFactoryIdentifier); + } + + static bool SupportsD3D11( + const TextureFactoryIdentifier aTextureFactoryIdentifier) { + return aTextureFactoryIdentifier.mParentBackend == layers::LayersBackend::LAYERS_WR && - (lock.ref().mTextureFactoryIdentifier.mCompositorUseANGLE || - lock.ref().mTextureFactoryIdentifier.mWebRenderCompositor == + (aTextureFactoryIdentifier.mCompositorUseANGLE || + aTextureFactoryIdentifier.mWebRenderCompositor == layers::WebRenderCompositor::D3D11); } diff --git a/gfx/layers/wr/WebRenderImageHost.cpp b/gfx/layers/wr/WebRenderImageHost.cpp index 47f5a5948823..50d6d28d4f77 100644 --- a/gfx/layers/wr/WebRenderImageHost.cpp +++ b/gfx/layers/wr/WebRenderImageHost.cpp @@ -13,6 +13,7 @@ #include "mozilla/layers/AsyncImagePipelineManager.h" #include "mozilla/layers/CompositorThread.h" #include "mozilla/layers/CompositorVsyncScheduler.h" // for CompositorVsyncScheduler +#include "mozilla/layers/KnowsCompositor.h" #include "mozilla/layers/RemoteTextureHostWrapper.h" #include "mozilla/layers/RemoteTextureMap.h" #include "mozilla/layers/WebRenderBridgeParent.h" @@ -349,7 +350,8 @@ TextureHost* WebRenderImageHost::GetAsTextureHostForComposite( auto identifier = aAsyncImageManager->GetTextureFactoryIdentifier(); const bool convertToNV12 = StaticPrefs::gfx_video_convert_yuv_to_nv12_image_host_win() && - identifier.mCompositorUseDComp && + identifier.mSupportsD3D11NV12 && + KnowsCompositor::SupportsD3D11(identifier) && texture->GetFormat() == gfx::SurfaceFormat::YUV; if (convertToNV12) { if (!mTextureAllocator) { diff --git a/gfx/webrender_bindings/RenderD3D11TextureHost.cpp b/gfx/webrender_bindings/RenderD3D11TextureHost.cpp index 7c38678de3c9..1d157314e885 100644 --- a/gfx/webrender_bindings/RenderD3D11TextureHost.cpp +++ b/gfx/webrender_bindings/RenderD3D11TextureHost.cpp @@ -164,21 +164,6 @@ bool RenderDXGITextureHost::EnsureD3D11Texture2DWithGL() { return true; } - if (mGpuProcessTextureId.isSome()) { - auto* textureMap = layers::GpuProcessD3D11TextureMap::Get(); - if (textureMap) { - RefPtr texture; - textureMap->WaitTextureReady(mGpuProcessTextureId.ref()); - mTexture = textureMap->GetTexture(mGpuProcessTextureId.ref()); - if (mTexture) { - return true; - } else { - gfxCriticalNote << "GpuProcessTextureId is not valid"; - } - } - return false; - } - const auto& gle = gl::GLContextEGL::Cast(mGL); const auto& egl = gle->mEgl; @@ -210,6 +195,21 @@ bool RenderDXGITextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) { return true; } + if (mGpuProcessTextureId.isSome()) { + auto* textureMap = layers::GpuProcessD3D11TextureMap::Get(); + if (textureMap) { + RefPtr texture; + textureMap->WaitTextureReady(mGpuProcessTextureId.ref()); + mTexture = textureMap->GetTexture(mGpuProcessTextureId.ref()); + if (mTexture) { + return true; + } else { + gfxCriticalNote << "GpuProcessTextureId is not valid"; + } + } + return false; + } + // Get the D3D11 texture from shared handle. HRESULT hr = aDevice->OpenSharedResource( (HANDLE)mHandle, __uuidof(ID3D11Texture2D),