mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1861605 - Use IDXGIResource1::CreateSharedHandle() instead of IDXGIResource::GetSharedHandle() r=gfx-reviewers,lsalzman
gecko uses IDXGIResource::GetSharedHandle(). But it is recommend not to use anymore to retrieve the handle to a shared resource. IDXGIResource1::CreateSharedHandle() with D3D11_RESOURCE_MISC_SHARED_NTHANDLE flag should be used instead of the GetSharedHandle(). The CreateSharedHandle() could be called only once for a shared resource. Later calls fail. HANDLEs of ID3D11Texture2D are replaced by gfx::FileHandleWrappers. Differential Revision: https://phabricator.services.mozilla.com/D192173
This commit is contained in:
parent
f2f1573ae0
commit
7d06300567
@ -38,7 +38,8 @@ UniquePtr<ExternalTextureD3D11> ExternalTextureD3D11::Create(
|
|||||||
desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS;
|
desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
|
desc.MiscFlags =
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_NTHANDLE | D3D11_RESOURCE_MISC_SHARED;
|
||||||
|
|
||||||
RefPtr<ID3D11Texture2D> texture;
|
RefPtr<ID3D11Texture2D> texture;
|
||||||
HRESULT hr =
|
HRESULT hr =
|
||||||
@ -47,41 +48,55 @@ UniquePtr<ExternalTextureD3D11> ExternalTextureD3D11::Create(
|
|||||||
gfxCriticalNoteOnce << "CreateTexture2D failed: " << gfx::hexa(hr);
|
gfxCriticalNoteOnce << "CreateTexture2D failed: " << gfx::hexa(hr);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return MakeUnique<ExternalTextureD3D11>(aWidth, aHeight, aFormat, aUsage,
|
|
||||||
texture);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExternalTextureD3D11::ExternalTextureD3D11(
|
RefPtr<IDXGIResource1> resource;
|
||||||
const uint32_t aWidth, const uint32_t aHeight,
|
texture->QueryInterface((IDXGIResource1**)getter_AddRefs(resource));
|
||||||
const struct ffi::WGPUTextureFormat aFormat,
|
|
||||||
const ffi::WGPUTextureUsages aUsage, RefPtr<ID3D11Texture2D> aTexture)
|
|
||||||
: ExternalTexture(aWidth, aHeight, aFormat, aUsage), mTexture(aTexture) {
|
|
||||||
MOZ_ASSERT(mTexture);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExternalTextureD3D11::~ExternalTextureD3D11() {}
|
|
||||||
|
|
||||||
void* ExternalTextureD3D11::GetExternalTextureHandle() {
|
|
||||||
RefPtr<IDXGIResource> resource;
|
|
||||||
mTexture->QueryInterface((IDXGIResource**)getter_AddRefs(resource));
|
|
||||||
if (!resource) {
|
if (!resource) {
|
||||||
gfxCriticalNoteOnce << "Failed to get IDXGIResource";
|
gfxCriticalNoteOnce << "Failed to get IDXGIResource";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE sharedHandle;
|
HANDLE sharedHandle;
|
||||||
HRESULT hr = resource->GetSharedHandle(&sharedHandle);
|
hr = resource->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
|
&sharedHandle);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
gfxCriticalNoteOnce << "GetSharedHandle failed: " << gfx::hexa(hr);
|
gfxCriticalNoteOnce << "GetSharedHandle failed: " << gfx::hexa(hr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return sharedHandle;
|
|
||||||
|
RefPtr<gfx::FileHandleWrapper> handle =
|
||||||
|
new gfx::FileHandleWrapper(UniqueFileHandle(sharedHandle));
|
||||||
|
|
||||||
|
return MakeUnique<ExternalTextureD3D11>(aWidth, aHeight, aFormat, aUsage,
|
||||||
|
texture, std::move(handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
ExternalTextureD3D11::ExternalTextureD3D11(
|
||||||
|
const uint32_t aWidth, const uint32_t aHeight,
|
||||||
|
const struct ffi::WGPUTextureFormat aFormat,
|
||||||
|
const ffi::WGPUTextureUsages aUsage, const RefPtr<ID3D11Texture2D> aTexture,
|
||||||
|
RefPtr<gfx::FileHandleWrapper>&& aSharedHandle)
|
||||||
|
: ExternalTexture(aWidth, aHeight, aFormat, aUsage),
|
||||||
|
mTexture(aTexture),
|
||||||
|
mSharedHandle(std::move(aSharedHandle)) {
|
||||||
|
MOZ_ASSERT(mTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExternalTextureD3D11::~ExternalTextureD3D11() {}
|
||||||
|
|
||||||
|
void* ExternalTextureD3D11::GetExternalTextureHandle() {
|
||||||
|
if (!mSharedHandle) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mSharedHandle->GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe<layers::SurfaceDescriptor> ExternalTextureD3D11::ToSurfaceDescriptor() {
|
Maybe<layers::SurfaceDescriptor> ExternalTextureD3D11::ToSurfaceDescriptor() {
|
||||||
const auto format = gfx::SurfaceFormat::B8G8R8A8;
|
const auto format = gfx::SurfaceFormat::B8G8R8A8;
|
||||||
return Some(layers::SurfaceDescriptorD3D10(
|
return Some(layers::SurfaceDescriptorD3D10(
|
||||||
(WindowsHandle)GetExternalTextureHandle(),
|
mSharedHandle,
|
||||||
/* gpuProcessTextureId */ Nothing(),
|
/* gpuProcessTextureId */ Nothing(),
|
||||||
/* arrayIndex */ 0, format, gfx::IntSize(mWidth, mHeight),
|
/* arrayIndex */ 0, format, gfx::IntSize(mWidth, mHeight),
|
||||||
gfx::ColorSpace2::SRGB, gfx::ColorRange::FULL,
|
gfx::ColorSpace2::SRGB, gfx::ColorRange::FULL,
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#ifndef GPU_ExternalTextureD3D11_H_
|
#ifndef GPU_ExternalTextureD3D11_H_
|
||||||
#define GPU_ExternalTextureD3D11_H_
|
#define GPU_ExternalTextureD3D11_H_
|
||||||
|
|
||||||
|
#include "mozilla/gfx/FileHandleWrapper.h"
|
||||||
#include "mozilla/webgpu/ExternalTexture.h"
|
#include "mozilla/webgpu/ExternalTexture.h"
|
||||||
|
|
||||||
struct ID3D11Texture2D;
|
struct ID3D11Texture2D;
|
||||||
@ -24,7 +25,8 @@ class ExternalTextureD3D11 final : public ExternalTexture {
|
|||||||
ExternalTextureD3D11(const uint32_t aWidth, const uint32_t aHeight,
|
ExternalTextureD3D11(const uint32_t aWidth, const uint32_t aHeight,
|
||||||
const struct ffi::WGPUTextureFormat aFormat,
|
const struct ffi::WGPUTextureFormat aFormat,
|
||||||
const ffi::WGPUTextureUsages aUsage,
|
const ffi::WGPUTextureUsages aUsage,
|
||||||
RefPtr<ID3D11Texture2D> aTexture);
|
const RefPtr<ID3D11Texture2D> aTexture,
|
||||||
|
RefPtr<gfx::FileHandleWrapper>&& aSharedHandle);
|
||||||
virtual ~ExternalTextureD3D11();
|
virtual ~ExternalTextureD3D11();
|
||||||
|
|
||||||
void* GetExternalTextureHandle() override;
|
void* GetExternalTextureHandle() override;
|
||||||
@ -35,7 +37,8 @@ class ExternalTextureD3D11 final : public ExternalTexture {
|
|||||||
const gfx::IntSize& aSize) override;
|
const gfx::IntSize& aSize) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RefPtr<ID3D11Texture2D> mTexture;
|
const RefPtr<ID3D11Texture2D> mTexture;
|
||||||
|
const RefPtr<gfx::FileHandleWrapper> mSharedHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webgpu
|
} // namespace webgpu
|
||||||
|
@ -50,12 +50,24 @@ extern void* wgpu_server_get_external_texture_handle(void* aParam,
|
|||||||
WGPUTextureId aId) {
|
WGPUTextureId aId) {
|
||||||
auto* parent = static_cast<WebGPUParent*>(aParam);
|
auto* parent = static_cast<WebGPUParent*>(aParam);
|
||||||
|
|
||||||
auto externalTexture = parent->GetExternalTexture(aId);
|
auto texture = parent->GetExternalTexture(aId);
|
||||||
if (!externalTexture) {
|
if (!texture) {
|
||||||
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return externalTexture->GetExternalTextureHandle();
|
|
||||||
|
void* sharedHandle = nullptr;
|
||||||
|
#ifdef XP_WIN
|
||||||
|
sharedHandle = texture->GetExternalTextureHandle();
|
||||||
|
if (!sharedHandle) {
|
||||||
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
||||||
|
gfxCriticalNoteOnce << "Failed to get shared handle";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
||||||
|
#endif
|
||||||
|
return sharedHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ffi
|
} // namespace ffi
|
||||||
@ -1462,13 +1474,6 @@ std::shared_ptr<ExternalTexture> WebGPUParent::CreateExternalTexture(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* sharedHandle = texture->GetExternalTextureHandle();
|
|
||||||
if (!sharedHandle) {
|
|
||||||
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
||||||
gfxCriticalNoteOnce << "Failed to get shared handle";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<ExternalTexture> shared(texture.release());
|
std::shared_ptr<ExternalTexture> shared(texture.release());
|
||||||
mExternalTextures.emplace(aTextureId, shared);
|
mExternalTextures.emplace(aTextureId, shared);
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "GLBlitHelper.h"
|
#include "GLBlitHelper.h"
|
||||||
|
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
|
#include <d3d11_1.h>
|
||||||
|
|
||||||
#include "GLContextEGL.h"
|
#include "GLContextEGL.h"
|
||||||
#include "GLLibraryEGL.h"
|
#include "GLLibraryEGL.h"
|
||||||
@ -59,12 +60,19 @@ static EGLStreamKHR StreamFromD3DTexture(EglDisplay* const egl,
|
|||||||
|
|
||||||
static RefPtr<ID3D11Texture2D> OpenSharedTexture(ID3D11Device* const d3d,
|
static RefPtr<ID3D11Texture2D> OpenSharedTexture(ID3D11Device* const d3d,
|
||||||
const WindowsHandle handle) {
|
const WindowsHandle handle) {
|
||||||
|
RefPtr<ID3D11Device1> device1;
|
||||||
|
d3d->QueryInterface((ID3D11Device1**)getter_AddRefs(device1));
|
||||||
|
if (!device1) {
|
||||||
|
gfxCriticalNoteOnce << "Failed to get ID3D11Device1";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<ID3D11Texture2D> tex;
|
RefPtr<ID3D11Texture2D> tex;
|
||||||
auto hr =
|
auto hr = device1->OpenSharedResource1(
|
||||||
d3d->OpenSharedResource((HANDLE)handle, __uuidof(ID3D11Texture2D),
|
(HANDLE)handle, __uuidof(ID3D11Texture2D),
|
||||||
(void**)(ID3D11Texture2D**)getter_AddRefs(tex));
|
(void**)(ID3D11Texture2D**)getter_AddRefs(tex));
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
gfxCriticalError() << "Error code from OpenSharedResource: "
|
gfxCriticalError() << "Error code from OpenSharedResource1: "
|
||||||
<< gfx::hexa(hr);
|
<< gfx::hexa(hr);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -231,9 +239,13 @@ bool GLBlitHelper::BlitImage(layers::D3D11YCbCrImage* const srcImage,
|
|||||||
const auto& data = srcImage->GetData();
|
const auto& data = srcImage->GetData();
|
||||||
if (!data) return false;
|
if (!data) return false;
|
||||||
|
|
||||||
const WindowsHandle handles[3] = {(WindowsHandle)data->mHandles[0],
|
const WindowsHandle handles[3] = {
|
||||||
(WindowsHandle)data->mHandles[1],
|
(WindowsHandle)(data->mHandles[0] ? data->mHandles[0]->GetHandle()
|
||||||
(WindowsHandle)data->mHandles[2]};
|
: nullptr),
|
||||||
|
(WindowsHandle)(data->mHandles[1] ? data->mHandles[1]->GetHandle()
|
||||||
|
: nullptr),
|
||||||
|
(WindowsHandle)(data->mHandles[2] ? data->mHandles[2]->GetHandle()
|
||||||
|
: nullptr)};
|
||||||
return BlitAngleYCbCr(handles, srcImage->mPictureRect, srcImage->GetYSize(),
|
return BlitAngleYCbCr(handles, srcImage->mPictureRect, srcImage->GetYSize(),
|
||||||
srcImage->GetCbCrSize(), srcImage->mColorSpace,
|
srcImage->GetCbCrSize(), srcImage->mColorSpace,
|
||||||
destSize, destOrigin);
|
destSize, destOrigin);
|
||||||
@ -247,7 +259,6 @@ bool GLBlitHelper::BlitDescriptor(const layers::SurfaceDescriptorD3D10& desc,
|
|||||||
const auto& d3d = GetD3D11();
|
const auto& d3d = GetD3D11();
|
||||||
if (!d3d) return false;
|
if (!d3d) return false;
|
||||||
|
|
||||||
const auto& handle = desc.handle();
|
|
||||||
const auto& gpuProcessTextureId = desc.gpuProcessTextureId();
|
const auto& gpuProcessTextureId = desc.gpuProcessTextureId();
|
||||||
const auto& arrayIndex = desc.arrayIndex();
|
const auto& arrayIndex = desc.arrayIndex();
|
||||||
const auto& format = desc.format();
|
const auto& format = desc.format();
|
||||||
@ -275,11 +286,11 @@ bool GLBlitHelper::BlitDescriptor(const layers::SurfaceDescriptorD3D10& desc,
|
|||||||
tex = OpenSharedTexture(d3d, (WindowsHandle)handle.ref());
|
tex = OpenSharedTexture(d3d, (WindowsHandle)handle.ref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (desc.handle()) {
|
||||||
tex = OpenSharedTexture(d3d, handle);
|
tex = OpenSharedTexture(d3d, (WindowsHandle)desc.handle()->GetHandle());
|
||||||
}
|
}
|
||||||
if (!tex) {
|
if (!tex) {
|
||||||
MOZ_GL_ASSERT(mGL, false); // Get a nullptr from OpenSharedResource.
|
MOZ_GL_ASSERT(mGL, false); // Get a nullptr from OpenSharedResource1.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const RefPtr<ID3D11Texture2D> texList[2] = {tex, tex};
|
const RefPtr<ID3D11Texture2D> texList[2] = {tex, tex};
|
||||||
@ -349,8 +360,12 @@ bool GLBlitHelper::BlitDescriptor(
|
|||||||
|
|
||||||
const gfx::IntRect clipRect(0, 0, clipSize.width, clipSize.height);
|
const gfx::IntRect clipRect(0, 0, clipSize.width, clipSize.height);
|
||||||
|
|
||||||
const WindowsHandle handles[3] = {desc.handleY(), desc.handleCb(),
|
auto handleY = desc.handleY() ? desc.handleY()->GetHandle() : nullptr;
|
||||||
desc.handleCr()};
|
auto handleCb = desc.handleCb() ? desc.handleCb()->GetHandle() : nullptr;
|
||||||
|
auto handleCr = desc.handleCr() ? desc.handleCr()->GetHandle() : nullptr;
|
||||||
|
|
||||||
|
const WindowsHandle handles[3] = {
|
||||||
|
(WindowsHandle)handleY, (WindowsHandle)handleCb, (WindowsHandle)handleCr};
|
||||||
return BlitAngleYCbCr(handles, clipRect, ySize, uvSize, colorSpace, destSize,
|
return BlitAngleYCbCr(handles, clipRect, ySize, uvSize, colorSpace, destSize,
|
||||||
destOrigin);
|
destOrigin);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "GLLibraryEGL.h"
|
#include "GLLibraryEGL.h"
|
||||||
#include "mozilla/gfx/D3D11Checks.h"
|
#include "mozilla/gfx/D3D11Checks.h"
|
||||||
#include "mozilla/gfx/DeviceManagerDx.h"
|
#include "mozilla/gfx/DeviceManagerDx.h"
|
||||||
|
#include "mozilla/gfx/FileHandleWrapper.h"
|
||||||
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
|
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
@ -75,7 +76,8 @@ SharedSurface_ANGLEShareHandle::Create(const SharedSurfaceDesc& desc) {
|
|||||||
CD3D11_TEXTURE2D_DESC texDesc(
|
CD3D11_TEXTURE2D_DESC texDesc(
|
||||||
format, desc.size.width, desc.size.height, 1, 1,
|
format, desc.size.width, desc.size.height, 1, 1,
|
||||||
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET);
|
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET);
|
||||||
texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
||||||
|
|
||||||
RefPtr<ID3D11Texture2D> texture2D;
|
RefPtr<ID3D11Texture2D> texture2D;
|
||||||
auto hr =
|
auto hr =
|
||||||
@ -84,18 +86,20 @@ SharedSurface_ANGLEShareHandle::Create(const SharedSurfaceDesc& desc) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE shareHandle = nullptr;
|
RefPtr<IDXGIResource1> texDXGI;
|
||||||
RefPtr<IDXGIResource> texDXGI;
|
hr = texture2D->QueryInterface(__uuidof(IDXGIResource1),
|
||||||
hr = texture2D->QueryInterface(__uuidof(IDXGIResource),
|
|
||||||
getter_AddRefs(texDXGI));
|
getter_AddRefs(texDXGI));
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = texDXGI->GetSharedHandle(&shareHandle);
|
HANDLE sharedHandle = nullptr;
|
||||||
if (FAILED(hr)) {
|
texDXGI->CreateSharedHandle(
|
||||||
return nullptr;
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
}
|
&sharedHandle);
|
||||||
|
|
||||||
|
RefPtr<gfx::FileHandleWrapper> handle =
|
||||||
|
new gfx::FileHandleWrapper(UniqueFileHandle(sharedHandle));
|
||||||
|
|
||||||
RefPtr<IDXGIKeyedMutex> keyedMutex;
|
RefPtr<IDXGIKeyedMutex> keyedMutex;
|
||||||
texture2D->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(keyedMutex));
|
texture2D->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(keyedMutex));
|
||||||
@ -110,18 +114,18 @@ SharedSurface_ANGLEShareHandle::Create(const SharedSurfaceDesc& desc) {
|
|||||||
CreatePBufferSurface(egl.get(), config, desc.size, texture2D);
|
CreatePBufferSurface(egl.get(), config, desc.size, texture2D);
|
||||||
if (!pbuffer) return nullptr;
|
if (!pbuffer) return nullptr;
|
||||||
|
|
||||||
return AsUnique(new SharedSurface_ANGLEShareHandle(desc, egl, pbuffer,
|
return AsUnique(new SharedSurface_ANGLEShareHandle(
|
||||||
shareHandle, keyedMutex));
|
desc, egl, pbuffer, std::move(handle), keyedMutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedSurface_ANGLEShareHandle::SharedSurface_ANGLEShareHandle(
|
SharedSurface_ANGLEShareHandle::SharedSurface_ANGLEShareHandle(
|
||||||
const SharedSurfaceDesc& desc, const std::weak_ptr<EglDisplay>& egl,
|
const SharedSurfaceDesc& desc, const std::weak_ptr<EglDisplay>& egl,
|
||||||
EGLSurface pbuffer, HANDLE shareHandle,
|
EGLSurface pbuffer, RefPtr<gfx::FileHandleWrapper>&& aSharedHandle,
|
||||||
const RefPtr<IDXGIKeyedMutex>& keyedMutex)
|
const RefPtr<IDXGIKeyedMutex>& keyedMutex)
|
||||||
: SharedSurface(desc, nullptr),
|
: SharedSurface(desc, nullptr),
|
||||||
mEGL(egl),
|
mEGL(egl),
|
||||||
mPBuffer(pbuffer),
|
mPBuffer(pbuffer),
|
||||||
mShareHandle(shareHandle),
|
mSharedHandle(std::move(aSharedHandle)),
|
||||||
mKeyedMutex(keyedMutex) {}
|
mKeyedMutex(keyedMutex) {}
|
||||||
|
|
||||||
SharedSurface_ANGLEShareHandle::~SharedSurface_ANGLEShareHandle() {
|
SharedSurface_ANGLEShareHandle::~SharedSurface_ANGLEShareHandle() {
|
||||||
@ -169,7 +173,7 @@ Maybe<layers::SurfaceDescriptor>
|
|||||||
SharedSurface_ANGLEShareHandle::ToSurfaceDescriptor() {
|
SharedSurface_ANGLEShareHandle::ToSurfaceDescriptor() {
|
||||||
const auto format = gfx::SurfaceFormat::B8G8R8A8;
|
const auto format = gfx::SurfaceFormat::B8G8R8A8;
|
||||||
return Some(layers::SurfaceDescriptorD3D10(
|
return Some(layers::SurfaceDescriptorD3D10(
|
||||||
(WindowsHandle)mShareHandle, /* gpuProcessTextureId */ Nothing(),
|
mSharedHandle, /* gpuProcessTextureId */ Nothing(),
|
||||||
/* arrayIndex */ 0, format, mDesc.size, mDesc.colorSpace,
|
/* arrayIndex */ 0, format, mDesc.size, mDesc.colorSpace,
|
||||||
gfx::ColorRange::FULL, /* hasKeyedMutex */ true,
|
gfx::ColorRange::FULL, /* hasKeyedMutex */ true,
|
||||||
/* fenceInfo */ Nothing()));
|
/* fenceInfo */ Nothing()));
|
||||||
|
@ -14,6 +14,11 @@ struct IDXGIKeyedMutex;
|
|||||||
struct ID3D11Texture2D;
|
struct ID3D11Texture2D;
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
|
namespace gfx {
|
||||||
|
class FileHandleWrapper;
|
||||||
|
} // namespace gfx
|
||||||
|
|
||||||
namespace gl {
|
namespace gl {
|
||||||
|
|
||||||
class GLContext;
|
class GLContext;
|
||||||
@ -23,7 +28,7 @@ class SharedSurface_ANGLEShareHandle final : public SharedSurface {
|
|||||||
public:
|
public:
|
||||||
const std::weak_ptr<EglDisplay> mEGL;
|
const std::weak_ptr<EglDisplay> mEGL;
|
||||||
const EGLSurface mPBuffer;
|
const EGLSurface mPBuffer;
|
||||||
const HANDLE mShareHandle;
|
const RefPtr<gfx::FileHandleWrapper> mSharedHandle;
|
||||||
const RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
const RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
||||||
|
|
||||||
static UniquePtr<SharedSurface_ANGLEShareHandle> Create(
|
static UniquePtr<SharedSurface_ANGLEShareHandle> Create(
|
||||||
@ -32,7 +37,8 @@ class SharedSurface_ANGLEShareHandle final : public SharedSurface {
|
|||||||
private:
|
private:
|
||||||
SharedSurface_ANGLEShareHandle(const SharedSurfaceDesc&,
|
SharedSurface_ANGLEShareHandle(const SharedSurfaceDesc&,
|
||||||
const std::weak_ptr<EglDisplay>& egl,
|
const std::weak_ptr<EglDisplay>& egl,
|
||||||
EGLSurface pbuffer, HANDLE shareHandle,
|
EGLSurface pbuffer,
|
||||||
|
RefPtr<gfx::FileHandleWrapper>&& aSharedHandle,
|
||||||
const RefPtr<IDXGIKeyedMutex>& keyedMutex);
|
const RefPtr<IDXGIKeyedMutex>& keyedMutex);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "WGLLibrary.h"
|
#include "WGLLibrary.h"
|
||||||
#include "nsPrintfCString.h"
|
#include "nsPrintfCString.h"
|
||||||
#include "mozilla/gfx/DeviceManagerDx.h"
|
#include "mozilla/gfx/DeviceManagerDx.h"
|
||||||
|
#include "mozilla/gfx/FileHandleWrapper.h"
|
||||||
#include "mozilla/gfx/Logging.h"
|
#include "mozilla/gfx/Logging.h"
|
||||||
#include "mozilla/layers/LayersSurfaces.h"
|
#include "mozilla/layers/LayersSurfaces.h"
|
||||||
#include "mozilla/StaticPrefs_webgl.h"
|
#include "mozilla/StaticPrefs_webgl.h"
|
||||||
@ -324,7 +325,8 @@ UniquePtr<SharedSurface_D3D11Interop> SharedSurface_D3D11Interop::Create(
|
|||||||
// Create a texture in case we need to readback.
|
// Create a texture in case we need to readback.
|
||||||
const DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
const DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||||
CD3D11_TEXTURE2D_DESC texDesc(format, size.width, size.height, 1, 1);
|
CD3D11_TEXTURE2D_DESC texDesc(format, size.width, size.height, 1, 1);
|
||||||
texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
texDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
||||||
|
|
||||||
auto hr =
|
auto hr =
|
||||||
d3d->CreateTexture2D(&texDesc, nullptr, getter_AddRefs(data.texD3D));
|
d3d->CreateTexture2D(&texDesc, nullptr, getter_AddRefs(data.texD3D));
|
||||||
@ -333,15 +335,20 @@ UniquePtr<SharedSurface_D3D11Interop> SharedSurface_D3D11Interop::Create(
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<IDXGIResource> texDXGI;
|
RefPtr<IDXGIResource1> texDXGI;
|
||||||
hr = data.texD3D->QueryInterface(__uuidof(IDXGIResource),
|
hr = data.texD3D->QueryInterface(__uuidof(IDXGIResource1),
|
||||||
getter_AddRefs(texDXGI));
|
getter_AddRefs(texDXGI));
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
NS_WARNING("Failed to open texture for sharing!");
|
NS_WARNING("Failed to open texture for sharing!");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
texDXGI->GetSharedHandle(&data.dxgiHandle);
|
HANDLE sharedHandle = nullptr;
|
||||||
|
texDXGI->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
|
&sharedHandle);
|
||||||
|
|
||||||
|
data.dxgiHandle = new gfx::FileHandleWrapper(UniqueFileHandle(sharedHandle));
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
@ -441,7 +448,7 @@ Maybe<layers::SurfaceDescriptor>
|
|||||||
SharedSurface_D3D11Interop::ToSurfaceDescriptor() {
|
SharedSurface_D3D11Interop::ToSurfaceDescriptor() {
|
||||||
const auto format = gfx::SurfaceFormat::B8G8R8A8;
|
const auto format = gfx::SurfaceFormat::B8G8R8A8;
|
||||||
return Some(layers::SurfaceDescriptorD3D10(
|
return Some(layers::SurfaceDescriptorD3D10(
|
||||||
WindowsHandle(mData.dxgiHandle), /* gpuProcessTextureId */ Nothing(),
|
mData.dxgiHandle, /* gpuProcessTextureId */ Nothing(),
|
||||||
/* arrayIndex */ 0, format, mDesc.size, mDesc.colorSpace,
|
/* arrayIndex */ 0, format, mDesc.size, mDesc.colorSpace,
|
||||||
gfx::ColorRange::FULL, /* hasKeyedMutex */ true,
|
gfx::ColorRange::FULL, /* hasKeyedMutex */ true,
|
||||||
/* fenceInfo */ Nothing()));
|
/* fenceInfo */ Nothing()));
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
#include "SharedSurface.h"
|
#include "SharedSurface.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
|
namespace gfx {
|
||||||
|
class FileHandleWrapper;
|
||||||
|
} // namespace gfx
|
||||||
|
|
||||||
namespace gl {
|
namespace gl {
|
||||||
|
|
||||||
class DXInterop2Device;
|
class DXInterop2Device;
|
||||||
@ -23,7 +28,7 @@ class SharedSurface_D3D11Interop final : public SharedSurface {
|
|||||||
const RefPtr<DXInterop2Device> interop;
|
const RefPtr<DXInterop2Device> interop;
|
||||||
HANDLE lockHandle;
|
HANDLE lockHandle;
|
||||||
RefPtr<ID3D11Texture2D> texD3D;
|
RefPtr<ID3D11Texture2D> texD3D;
|
||||||
HANDLE dxgiHandle;
|
RefPtr<gfx::FileHandleWrapper> dxgiHandle;
|
||||||
UniquePtr<Renderbuffer> interopRb;
|
UniquePtr<Renderbuffer> interopRb;
|
||||||
UniquePtr<MozFramebuffer> interopFbIfNeedsIndirect;
|
UniquePtr<MozFramebuffer> interopFbIfNeedsIndirect;
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include "FileHandleWrapper.h"
|
#include "FileHandleWrapper.h"
|
||||||
|
|
||||||
|
#include "mozilla/ipc/FileDescriptor.h"
|
||||||
|
|
||||||
namespace mozilla::gfx {
|
namespace mozilla::gfx {
|
||||||
|
|
||||||
FileHandleWrapper::FileHandleWrapper(mozilla::UniqueFileHandle&& aHandle)
|
FileHandleWrapper::FileHandleWrapper(mozilla::UniqueFileHandle&& aHandle)
|
||||||
@ -17,4 +19,9 @@ mozilla::detail::FileHandleType FileHandleWrapper::GetHandle() {
|
|||||||
return mHandle.get();
|
return mHandle.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mozilla::UniqueFileHandle FileHandleWrapper::ClonePlatformHandle() {
|
||||||
|
auto handle = ipc::FileDescriptor(GetHandle());
|
||||||
|
return handle.TakePlatformHandle();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mozilla::gfx
|
} // namespace mozilla::gfx
|
||||||
|
@ -35,6 +35,8 @@ class FileHandleWrapper {
|
|||||||
|
|
||||||
mozilla::detail::FileHandleType GetHandle();
|
mozilla::detail::FileHandleType GetHandle();
|
||||||
|
|
||||||
|
mozilla::UniqueFileHandle ClonePlatformHandle();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~FileHandleWrapper();
|
~FileHandleWrapper();
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "LayersTypes.h" // for LayersBackend, etc
|
#include "LayersTypes.h" // for LayersBackend, etc
|
||||||
#include "nsXULAppAPI.h" // for GeckoProcessType, etc
|
#include "nsXULAppAPI.h" // for GeckoProcessType, etc
|
||||||
#include "mozilla/gfx/Types.h"
|
#include "mozilla/gfx/Types.h"
|
||||||
|
#include "mozilla/layers/SyncObject.h"
|
||||||
#include "mozilla/EnumSet.h"
|
#include "mozilla/EnumSet.h"
|
||||||
|
|
||||||
#include "mozilla/TypedEnumBits.h"
|
#include "mozilla/TypedEnumBits.h"
|
||||||
@ -147,12 +148,6 @@ enum class CompositableType : uint8_t {
|
|||||||
COUNT
|
COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef XP_WIN
|
|
||||||
typedef void* SyncHandle;
|
|
||||||
#else
|
|
||||||
typedef uintptr_t SyncHandle;
|
|
||||||
#endif // XP_WIN
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sent from the compositor to the content-side LayerManager, includes
|
* Sent from the compositor to the content-side LayerManager, includes
|
||||||
* properties of the compositor and should (in the future) include information
|
* properties of the compositor and should (in the future) include information
|
||||||
@ -180,7 +175,7 @@ struct TextureFactoryIdentifier {
|
|||||||
bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
|
bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
|
||||||
bool aSupportsTextureBlitting = false,
|
bool aSupportsTextureBlitting = false,
|
||||||
bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
|
bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
|
||||||
bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = 0)
|
bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = {})
|
||||||
: mParentBackend(aLayersBackend),
|
: mParentBackend(aLayersBackend),
|
||||||
mWebRenderBackend(WebRenderBackend::HARDWARE),
|
mWebRenderBackend(WebRenderBackend::HARDWARE),
|
||||||
mWebRenderCompositor(WebRenderCompositor::DRAW),
|
mWebRenderCompositor(WebRenderCompositor::DRAW),
|
||||||
@ -203,7 +198,7 @@ struct TextureFactoryIdentifier {
|
|||||||
bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
|
bool aCompositorUseDComp = false, bool aUseCompositorWnd = false,
|
||||||
bool aSupportsTextureBlitting = false,
|
bool aSupportsTextureBlitting = false,
|
||||||
bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
|
bool aSupportsPartialUploads = false, bool aSupportsComponentAlpha = true,
|
||||||
bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = 0)
|
bool aSupportsD3D11NV12 = false, SyncHandle aSyncHandle = {})
|
||||||
: mParentBackend(LayersBackend::LAYERS_WR),
|
: mParentBackend(LayersBackend::LAYERS_WR),
|
||||||
mWebRenderBackend(aWebRenderBackend),
|
mWebRenderBackend(aWebRenderBackend),
|
||||||
mWebRenderCompositor(aWebRenderCompositor),
|
mWebRenderCompositor(aWebRenderCompositor),
|
||||||
|
@ -184,7 +184,8 @@ bool D3D11ShareHandleImage::AllocateTexture(D3D11RecycleAllocator* aAllocator,
|
|||||||
CD3D11_TEXTURE2D_DESC newDesc(
|
CD3D11_TEXTURE2D_DESC newDesc(
|
||||||
DXGI_FORMAT_B8G8R8A8_UNORM, mSize.width, mSize.height, 1, 1,
|
DXGI_FORMAT_B8G8R8A8_UNORM, mSize.width, mSize.height, 1, 1,
|
||||||
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
|
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
|
||||||
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
|
newDesc.MiscFlags =
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_NTHANDLE | D3D11_RESOURCE_MISC_SHARED;
|
||||||
|
|
||||||
HRESULT hr =
|
HRESULT hr =
|
||||||
aDevice->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(mTexture));
|
aDevice->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(mTexture));
|
||||||
@ -346,7 +347,7 @@ RefPtr<ID3D11Texture2D> D3D11RecycleAllocator::GetStagingTextureNV12(
|
|||||||
desc.Usage = D3D11_USAGE_STAGING;
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
desc.BindFlags = 0;
|
desc.BindFlags = 0;
|
||||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||||
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
desc.MiscFlags = 0;
|
||||||
desc.SampleDesc.Count = 1;
|
desc.SampleDesc.Count = 1;
|
||||||
|
|
||||||
HRESULT hr = mDevice->CreateTexture2D(&desc, nullptr,
|
HRESULT hr = mDevice->CreateTexture2D(&desc, nullptr,
|
||||||
|
@ -418,7 +418,8 @@ already_AddRefed<TextureClient> DXGIYCbCrTextureAllocationHelper::Allocate(
|
|||||||
? DXGI_FORMAT_R8_UNORM
|
? DXGI_FORMAT_R8_UNORM
|
||||||
: DXGI_FORMAT_R16_UNORM,
|
: DXGI_FORMAT_R16_UNORM,
|
||||||
ySize.width, ySize.height, 1, 1);
|
ySize.width, ySize.height, 1, 1);
|
||||||
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
||||||
|
|
||||||
RefPtr<ID3D10Multithread> mt;
|
RefPtr<ID3D10Multithread> mt;
|
||||||
HRESULT hr = mDevice->QueryInterface((ID3D10Multithread**)getter_AddRefs(mt));
|
HRESULT hr = mDevice->QueryInterface((ID3D10Multithread**)getter_AddRefs(mt));
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#ifndef MOZILLA_GFX_LAYERS_SYNCOBJECT_H
|
#ifndef MOZILLA_GFX_LAYERS_SYNCOBJECT_H
|
||||||
#define MOZILLA_GFX_LAYERS_SYNCOBJECT_H
|
#define MOZILLA_GFX_LAYERS_SYNCOBJECT_H
|
||||||
|
|
||||||
|
#include "mozilla/gfx/FileHandleWrapper.h"
|
||||||
#include "mozilla/RefCounted.h"
|
#include "mozilla/RefCounted.h"
|
||||||
|
|
||||||
struct ID3D11Device;
|
struct ID3D11Device;
|
||||||
@ -15,7 +16,7 @@ namespace mozilla {
|
|||||||
namespace layers {
|
namespace layers {
|
||||||
|
|
||||||
#ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
typedef void* SyncHandle;
|
typedef RefPtr<gfx::FileHandleWrapper> SyncHandle;
|
||||||
#else
|
#else
|
||||||
typedef uintptr_t SyncHandle;
|
typedef uintptr_t SyncHandle;
|
||||||
#endif // XP_WIN
|
#endif // XP_WIN
|
||||||
|
@ -99,8 +99,8 @@ Maybe<HANDLE> GpuProcessD3D11TextureMap::GetSharedHandleOfCopiedTexture(
|
|||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it->second.mCopiedTextureSharedHandle.isSome()) {
|
if (it->second.mCopiedTextureSharedHandle) {
|
||||||
return it->second.mCopiedTextureSharedHandle;
|
return Some(it->second.mCopiedTextureSharedHandle->GetHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
holder = it->second;
|
holder = it->second;
|
||||||
@ -121,7 +121,8 @@ Maybe<HANDLE> GpuProcessD3D11TextureMap::GetSharedHandleOfCopiedTexture(
|
|||||||
CD3D11_TEXTURE2D_DESC newDesc(
|
CD3D11_TEXTURE2D_DESC newDesc(
|
||||||
DXGI_FORMAT_NV12, holder.mSize.width, holder.mSize.height, 1, 1,
|
DXGI_FORMAT_NV12, holder.mSize.width, holder.mSize.height, 1, 1,
|
||||||
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
|
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE);
|
||||||
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
|
newDesc.MiscFlags =
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_NTHANDLE | D3D11_RESOURCE_MISC_SHARED;
|
||||||
|
|
||||||
RefPtr<ID3D11Texture2D> copiedTexture;
|
RefPtr<ID3D11Texture2D> copiedTexture;
|
||||||
HRESULT hr =
|
HRESULT hr =
|
||||||
@ -143,18 +144,23 @@ Maybe<HANDLE> GpuProcessD3D11TextureMap::GetSharedHandleOfCopiedTexture(
|
|||||||
context->CopySubresourceRegion(copiedTexture, 0, 0, 0, 0, holder.mTexture,
|
context->CopySubresourceRegion(copiedTexture, 0, 0, 0, 0, holder.mTexture,
|
||||||
holder.mArrayIndex, &srcBox);
|
holder.mArrayIndex, &srcBox);
|
||||||
|
|
||||||
RefPtr<IDXGIResource> resource;
|
RefPtr<IDXGIResource1> resource;
|
||||||
copiedTexture->QueryInterface((IDXGIResource**)getter_AddRefs(resource));
|
copiedTexture->QueryInterface((IDXGIResource1**)getter_AddRefs(resource));
|
||||||
if (!resource) {
|
if (!resource) {
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE sharedHandle;
|
HANDLE sharedHandle;
|
||||||
hr = resource->GetSharedHandle(&sharedHandle);
|
hr = resource->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
|
&sharedHandle);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
return Nothing();
|
return Nothing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<gfx::FileHandleWrapper> handle =
|
||||||
|
new gfx::FileHandleWrapper(UniqueFileHandle(sharedHandle));
|
||||||
|
|
||||||
RefPtr<ID3D11Query> query;
|
RefPtr<ID3D11Query> query;
|
||||||
CD3D11_QUERY_DESC desc(D3D11_QUERY_EVENT);
|
CD3D11_QUERY_DESC desc(D3D11_QUERY_EVENT);
|
||||||
hr = device->CreateQuery(&desc, getter_AddRefs(query));
|
hr = device->CreateQuery(&desc, getter_AddRefs(query));
|
||||||
@ -187,10 +193,10 @@ Maybe<HANDLE> GpuProcessD3D11TextureMap::GetSharedHandleOfCopiedTexture(
|
|||||||
}
|
}
|
||||||
|
|
||||||
it->second.mCopiedTexture = copiedTexture;
|
it->second.mCopiedTexture = copiedTexture;
|
||||||
it->second.mCopiedTextureSharedHandle = Some(sharedHandle);
|
it->second.mCopiedTextureSharedHandle = handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(sharedHandle);
|
return Some(handle->GetHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GpuProcessD3D11TextureMap::GetWaitingTextureCount() const {
|
size_t GpuProcessD3D11TextureMap::GetWaitingTextureCount() const {
|
||||||
|
@ -75,7 +75,7 @@ class GpuProcessD3D11TextureMap {
|
|||||||
gfx::IntSize mSize;
|
gfx::IntSize mSize;
|
||||||
RefPtr<IMFSampleUsageInfo> mIMFSampleUsageInfo;
|
RefPtr<IMFSampleUsageInfo> mIMFSampleUsageInfo;
|
||||||
RefPtr<ID3D11Texture2D> mCopiedTexture;
|
RefPtr<ID3D11Texture2D> mCopiedTexture;
|
||||||
Maybe<HANDLE> mCopiedTextureSharedHandle;
|
RefPtr<gfx::FileHandleWrapper> mCopiedTextureSharedHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UpdatingTextureHolder {
|
struct UpdatingTextureHolder {
|
||||||
|
@ -16,8 +16,10 @@
|
|||||||
#include "mozilla/Telemetry.h"
|
#include "mozilla/Telemetry.h"
|
||||||
#include "mozilla/gfx/DataSurfaceHelpers.h"
|
#include "mozilla/gfx/DataSurfaceHelpers.h"
|
||||||
#include "mozilla/gfx/DeviceManagerDx.h"
|
#include "mozilla/gfx/DeviceManagerDx.h"
|
||||||
|
#include "mozilla/gfx/FileHandleWrapper.h"
|
||||||
#include "mozilla/gfx/Logging.h"
|
#include "mozilla/gfx/Logging.h"
|
||||||
#include "mozilla/gfx/gfxVars.h"
|
#include "mozilla/gfx/gfxVars.h"
|
||||||
|
#include "mozilla/ipc/FileDescriptor.h"
|
||||||
#include "mozilla/layers/CompositorBridgeChild.h"
|
#include "mozilla/layers/CompositorBridgeChild.h"
|
||||||
#include "mozilla/layers/D3D11TextureIMFSampleImage.h"
|
#include "mozilla/layers/D3D11TextureIMFSampleImage.h"
|
||||||
#include "mozilla/layers/GpuProcessD3D11TextureMap.h"
|
#include "mozilla/layers/GpuProcessD3D11TextureMap.h"
|
||||||
@ -289,7 +291,9 @@ static void UnlockD3DTexture(
|
|||||||
}
|
}
|
||||||
|
|
||||||
D3D11TextureData::D3D11TextureData(ID3D11Texture2D* aTexture,
|
D3D11TextureData::D3D11TextureData(ID3D11Texture2D* aTexture,
|
||||||
uint32_t aArrayIndex, gfx::IntSize aSize,
|
uint32_t aArrayIndex,
|
||||||
|
RefPtr<gfx::FileHandleWrapper> aSharedHandle,
|
||||||
|
gfx::IntSize aSize,
|
||||||
gfx::SurfaceFormat aFormat,
|
gfx::SurfaceFormat aFormat,
|
||||||
TextureAllocationFlags aFlags)
|
TextureAllocationFlags aFlags)
|
||||||
: mSize(aSize),
|
: mSize(aSize),
|
||||||
@ -297,6 +301,7 @@ D3D11TextureData::D3D11TextureData(ID3D11Texture2D* aTexture,
|
|||||||
mNeedsClear(aFlags & ALLOC_CLEAR_BUFFER),
|
mNeedsClear(aFlags & ALLOC_CLEAR_BUFFER),
|
||||||
mHasKeyedMutex(HasKeyedMutex(aTexture)),
|
mHasKeyedMutex(HasKeyedMutex(aTexture)),
|
||||||
mTexture(aTexture),
|
mTexture(aTexture),
|
||||||
|
mSharedHandle(std::move(aSharedHandle)),
|
||||||
mArrayIndex(aArrayIndex),
|
mArrayIndex(aArrayIndex),
|
||||||
mAllocationFlags(aFlags) {
|
mAllocationFlags(aFlags) {
|
||||||
MOZ_ASSERT(aTexture);
|
MOZ_ASSERT(aTexture);
|
||||||
@ -392,22 +397,11 @@ void D3D11TextureData::SyncWithObject(RefPtr<SyncObjectClient> aSyncObject) {
|
|||||||
|
|
||||||
bool D3D11TextureData::SerializeSpecific(
|
bool D3D11TextureData::SerializeSpecific(
|
||||||
SurfaceDescriptorD3D10* const aOutDesc) {
|
SurfaceDescriptorD3D10* const aOutDesc) {
|
||||||
RefPtr<IDXGIResource> resource;
|
|
||||||
GetDXGIResource((IDXGIResource**)getter_AddRefs(resource));
|
|
||||||
if (!resource) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
HANDLE sharedHandle = 0;
|
|
||||||
if (mGpuProcessTextureId.isNothing()) {
|
if (mGpuProcessTextureId.isNothing()) {
|
||||||
HRESULT hr = resource->GetSharedHandle(&sharedHandle);
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
LOGD3D11("Error getting shared handle for texture.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*aOutDesc = SurfaceDescriptorD3D10(
|
*aOutDesc = SurfaceDescriptorD3D10(
|
||||||
(WindowsHandle)sharedHandle, mGpuProcessTextureId, mArrayIndex, mFormat,
|
mSharedHandle, mGpuProcessTextureId, mArrayIndex, mFormat, mSize,
|
||||||
mSize, mColorSpace, mColorRange, /* hasKeyedMutex */ mHasKeyedMutex,
|
mColorSpace, mColorRange, /* hasKeyedMutex */ mHasKeyedMutex,
|
||||||
/* fenceInfo */ Nothing());
|
/* fenceInfo */ Nothing());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -435,7 +429,7 @@ already_AddRefed<TextureClient> D3D11TextureData::CreateTextureClient(
|
|||||||
gfx::ColorRange aColorRange, KnowsCompositor* aKnowsCompositor,
|
gfx::ColorRange aColorRange, KnowsCompositor* aKnowsCompositor,
|
||||||
RefPtr<IMFSampleUsageInfo> aUsageInfo) {
|
RefPtr<IMFSampleUsageInfo> aUsageInfo) {
|
||||||
D3D11TextureData* data = new D3D11TextureData(
|
D3D11TextureData* data = new D3D11TextureData(
|
||||||
aTexture, aIndex, aSize, aFormat,
|
aTexture, aIndex, nullptr, aSize, aFormat,
|
||||||
TextureAllocationFlags::ALLOC_MANUAL_SYNCHRONIZATION);
|
TextureAllocationFlags::ALLOC_MANUAL_SYNCHRONIZATION);
|
||||||
data->mColorSpace = aColorSpace;
|
data->mColorSpace = aColorSpace;
|
||||||
data->SetColorRange(aColorRange);
|
data->SetColorRange(aColorRange);
|
||||||
@ -500,11 +494,13 @@ D3D11TextureData* D3D11TextureData::Create(IntSize aSize, SurfaceFormat aFormat,
|
|||||||
newDesc.Format = DXGI_FORMAT_P016;
|
newDesc.Format = DXGI_FORMAT_P016;
|
||||||
}
|
}
|
||||||
|
|
||||||
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
|
newDesc.MiscFlags =
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_NTHANDLE | D3D11_RESOURCE_MISC_SHARED;
|
||||||
if (!NS_IsMainThread()) {
|
if (!NS_IsMainThread()) {
|
||||||
// On the main thread we use the syncobject to handle synchronization.
|
// On the main thread we use the syncobject to handle synchronization.
|
||||||
if (!(aFlags & ALLOC_MANUAL_SYNCHRONIZATION)) {
|
if (!(aFlags & ALLOC_MANUAL_SYNCHRONIZATION)) {
|
||||||
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,10 +571,33 @@ D3D11TextureData* D3D11TextureData::Create(IntSize aSize, SurfaceFormat aFormat,
|
|||||||
}
|
}
|
||||||
UnlockD3DTexture(texture11.get(), SerializeWithMoz2D::Yes);
|
UnlockD3DTexture(texture11.get(), SerializeWithMoz2D::Yes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<IDXGIResource1> resource;
|
||||||
|
texture11->QueryInterface((IDXGIResource1**)getter_AddRefs(resource));
|
||||||
|
if (!resource) {
|
||||||
|
gfxCriticalNoteOnce << "Failed to get IDXGIResource";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE sharedHandle;
|
||||||
|
HRESULT hr = resource->GetSharedHandle(&sharedHandle);
|
||||||
|
hr = resource->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
|
&sharedHandle);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
gfxCriticalNoteOnce << "GetSharedHandle failed: " << gfx::hexa(hr);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
texture11->SetPrivateDataInterface(
|
texture11->SetPrivateDataInterface(
|
||||||
sD3D11TextureUsage,
|
sD3D11TextureUsage,
|
||||||
new TextureMemoryMeasurer(newDesc.Width * newDesc.Height * 4));
|
new TextureMemoryMeasurer(newDesc.Width * newDesc.Height * 4));
|
||||||
return new D3D11TextureData(texture11, 0, aSize, aFormat, aFlags);
|
|
||||||
|
RefPtr<gfx::FileHandleWrapper> handle =
|
||||||
|
new gfx::FileHandleWrapper(UniqueFileHandle(sharedHandle));
|
||||||
|
|
||||||
|
return new D3D11TextureData(texture11, 0, std::move(handle), aSize, aFormat,
|
||||||
|
aFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D11TextureData::Deallocate(LayersIPCChannel* aAllocator) {
|
void D3D11TextureData::Deallocate(LayersIPCChannel* aAllocator) {
|
||||||
@ -592,10 +611,6 @@ TextureData* D3D11TextureData::CreateSimilar(
|
|||||||
return D3D11TextureData::Create(mSize, mFormat, aAllocFlags);
|
return D3D11TextureData::Create(mSize, mFormat, aAllocFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D11TextureData::GetDXGIResource(IDXGIResource** aOutResource) {
|
|
||||||
mTexture->QueryInterface(aOutResource);
|
|
||||||
}
|
|
||||||
|
|
||||||
TextureFlags D3D11TextureData::GetTextureFlags() const {
|
TextureFlags D3D11TextureData::GetTextureFlags() const {
|
||||||
// With WebRender, resource open happens asynchronously on RenderThread.
|
// With WebRender, resource open happens asynchronously on RenderThread.
|
||||||
// During opening the resource on host side, TextureClient needs to be alive.
|
// During opening the resource on host side, TextureClient needs to be alive.
|
||||||
@ -623,35 +638,47 @@ DXGIYCbCrTextureData* DXGIYCbCrTextureData::Create(
|
|||||||
sD3D11TextureUsage,
|
sD3D11TextureUsage,
|
||||||
new TextureMemoryMeasurer(aSizeCbCr.width * aSizeCbCr.height));
|
new TextureMemoryMeasurer(aSizeCbCr.width * aSizeCbCr.height));
|
||||||
|
|
||||||
RefPtr<IDXGIResource> resource;
|
RefPtr<IDXGIResource1> resource;
|
||||||
|
|
||||||
aTextureY->QueryInterface((IDXGIResource**)getter_AddRefs(resource));
|
aTextureY->QueryInterface((IDXGIResource1**)getter_AddRefs(resource));
|
||||||
|
|
||||||
HANDLE handleY;
|
HANDLE handleY;
|
||||||
HRESULT hr = resource->GetSharedHandle(&handleY);
|
HRESULT hr = resource->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
|
&handleY);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
const RefPtr<gfx::FileHandleWrapper> sharedHandleY =
|
||||||
|
new gfx::FileHandleWrapper(UniqueFileHandle(handleY));
|
||||||
|
|
||||||
aTextureCb->QueryInterface((IDXGIResource**)getter_AddRefs(resource));
|
aTextureCb->QueryInterface((IDXGIResource1**)getter_AddRefs(resource));
|
||||||
|
|
||||||
HANDLE handleCb;
|
HANDLE handleCb;
|
||||||
hr = resource->GetSharedHandle(&handleCb);
|
hr = resource->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
|
&handleCb);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
const RefPtr<gfx::FileHandleWrapper> sharedHandleCb =
|
||||||
|
new gfx::FileHandleWrapper(UniqueFileHandle(handleCb));
|
||||||
|
|
||||||
aTextureCr->QueryInterface((IDXGIResource**)getter_AddRefs(resource));
|
aTextureCr->QueryInterface((IDXGIResource1**)getter_AddRefs(resource));
|
||||||
HANDLE handleCr;
|
HANDLE handleCr;
|
||||||
hr = resource->GetSharedHandle(&handleCr);
|
hr = resource->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
|
&handleCr);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
const RefPtr<gfx::FileHandleWrapper> sharedHandleCr =
|
||||||
|
new gfx::FileHandleWrapper(UniqueFileHandle(handleCr));
|
||||||
|
|
||||||
DXGIYCbCrTextureData* texture = new DXGIYCbCrTextureData();
|
DXGIYCbCrTextureData* texture = new DXGIYCbCrTextureData();
|
||||||
texture->mHandles[0] = handleY;
|
texture->mHandles[0] = sharedHandleY;
|
||||||
texture->mHandles[1] = handleCb;
|
texture->mHandles[1] = sharedHandleCb;
|
||||||
texture->mHandles[2] = handleCr;
|
texture->mHandles[2] = sharedHandleCr;
|
||||||
texture->mD3D11Textures[0] = aTextureY;
|
texture->mD3D11Textures[0] = aTextureY;
|
||||||
texture->mD3D11Textures[1] = aTextureCb;
|
texture->mD3D11Textures[1] = aTextureCb;
|
||||||
texture->mD3D11Textures[2] = aTextureCr;
|
texture->mD3D11Textures[2] = aTextureCr;
|
||||||
@ -674,9 +701,8 @@ void DXGIYCbCrTextureData::FillInfo(TextureData::Info& aInfo) const {
|
|||||||
|
|
||||||
void DXGIYCbCrTextureData::SerializeSpecific(
|
void DXGIYCbCrTextureData::SerializeSpecific(
|
||||||
SurfaceDescriptorDXGIYCbCr* const aOutDesc) {
|
SurfaceDescriptorDXGIYCbCr* const aOutDesc) {
|
||||||
*aOutDesc = SurfaceDescriptorDXGIYCbCr(
|
*aOutDesc = SurfaceDescriptorDXGIYCbCr(mHandles[0], mHandles[1], mHandles[2],
|
||||||
(WindowsHandle)mHandles[0], (WindowsHandle)mHandles[1],
|
mSize, mSizeY, mSizeCbCr, mColorDepth,
|
||||||
(WindowsHandle)mHandles[2], mSize, mSizeY, mSizeCbCr, mColorDepth,
|
|
||||||
mYUVColorSpace, mColorRange);
|
mYUVColorSpace, mColorRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,7 +789,7 @@ DXGITextureHostD3D11::DXGITextureHostD3D11(
|
|||||||
mGpuProcessTextureId(aDescriptor.gpuProcessTextureId()),
|
mGpuProcessTextureId(aDescriptor.gpuProcessTextureId()),
|
||||||
mArrayIndex(aDescriptor.arrayIndex()),
|
mArrayIndex(aDescriptor.arrayIndex()),
|
||||||
mSize(aDescriptor.size()),
|
mSize(aDescriptor.size()),
|
||||||
mHandle((HANDLE)aDescriptor.handle()),
|
mHandle(aDescriptor.handle()),
|
||||||
mFormat(aDescriptor.format()),
|
mFormat(aDescriptor.format()),
|
||||||
mHasKeyedMutex(aDescriptor.hasKeyedMutex()),
|
mHasKeyedMutex(aDescriptor.hasKeyedMutex()),
|
||||||
mAcquireFenceInfo(aDescriptor.fenceInfo().isSome()
|
mAcquireFenceInfo(aDescriptor.fenceInfo().isSome()
|
||||||
@ -794,8 +820,15 @@ bool DXGITextureHostD3D11::EnsureTexture() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT hr = device->OpenSharedResource(
|
RefPtr<ID3D11Device1> device1;
|
||||||
(HANDLE)mHandle, __uuidof(ID3D11Texture2D),
|
device->QueryInterface((ID3D11Device1**)getter_AddRefs(device1));
|
||||||
|
if (!device1) {
|
||||||
|
gfxCriticalNoteOnce << "Failed to get ID3D11Device1";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT hr = device1->OpenSharedResource1(
|
||||||
|
(HANDLE)mHandle.get(), __uuidof(ID3D11Texture2D),
|
||||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mTexture));
|
(void**)(ID3D11Texture2D**)getter_AddRefs(mTexture));
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
MOZ_ASSERT(false, "Failed to open shared texture");
|
MOZ_ASSERT(false, "Failed to open shared texture");
|
||||||
@ -1093,9 +1126,9 @@ DXGIYCbCrTextureHostD3D11::DXGIYCbCrTextureHostD3D11(
|
|||||||
mColorDepth(aDescriptor.colorDepth()),
|
mColorDepth(aDescriptor.colorDepth()),
|
||||||
mYUVColorSpace(aDescriptor.yUVColorSpace()),
|
mYUVColorSpace(aDescriptor.yUVColorSpace()),
|
||||||
mColorRange(aDescriptor.colorRange()) {
|
mColorRange(aDescriptor.colorRange()) {
|
||||||
mHandles[0] = (HANDLE)aDescriptor.handleY();
|
mHandles[0] = aDescriptor.handleY();
|
||||||
mHandles[1] = (HANDLE)aDescriptor.handleCb();
|
mHandles[1] = aDescriptor.handleCb();
|
||||||
mHandles[2] = (HANDLE)aDescriptor.handleCr();
|
mHandles[2] = aDescriptor.handleCr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DXGIYCbCrTextureHostD3D11::CreateRenderTexture(
|
void DXGIYCbCrTextureHostD3D11::CreateRenderTexture(
|
||||||
@ -1423,7 +1456,7 @@ static inline bool ShouldDevCrashOnSyncInitFailure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SyncObjectD3D11Host::SyncObjectD3D11Host(ID3D11Device* aDevice)
|
SyncObjectD3D11Host::SyncObjectD3D11Host(ID3D11Device* aDevice)
|
||||||
: mSyncHandle(0), mDevice(aDevice) {
|
: mSyncHandle(nullptr), mDevice(aDevice) {
|
||||||
MOZ_ASSERT(aDevice);
|
MOZ_ASSERT(aDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1431,7 +1464,8 @@ bool SyncObjectD3D11Host::Init() {
|
|||||||
CD3D11_TEXTURE2D_DESC desc(
|
CD3D11_TEXTURE2D_DESC desc(
|
||||||
DXGI_FORMAT_B8G8R8A8_UNORM, 1, 1, 1, 1,
|
DXGI_FORMAT_B8G8R8A8_UNORM, 1, 1, 1, 1,
|
||||||
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET);
|
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET);
|
||||||
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
||||||
|
|
||||||
RefPtr<ID3D11Texture2D> texture;
|
RefPtr<ID3D11Texture2D> texture;
|
||||||
HRESULT hr =
|
HRESULT hr =
|
||||||
@ -1441,7 +1475,7 @@ bool SyncObjectD3D11Host::Init() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = texture->QueryInterface((IDXGIResource**)getter_AddRefs(mSyncTexture));
|
hr = texture->QueryInterface((IDXGIResource1**)getter_AddRefs(mSyncTexture));
|
||||||
if (FAILED(hr) || !mSyncTexture) {
|
if (FAILED(hr) || !mSyncTexture) {
|
||||||
gfxWarning() << "Could not QI sync texture: " << gfx::hexa(hr);
|
gfxWarning() << "Could not QI sync texture: " << gfx::hexa(hr);
|
||||||
return false;
|
return false;
|
||||||
@ -1454,8 +1488,11 @@ bool SyncObjectD3D11Host::Init() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = mSyncTexture->GetSharedHandle(&mSyncHandle);
|
HANDLE sharedHandle;
|
||||||
if (FAILED(hr) || !mSyncHandle) {
|
hr = mSyncTexture->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr,
|
||||||
|
&sharedHandle);
|
||||||
|
if (FAILED(hr)) {
|
||||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||||
"layers::SyncObjectD3D11Renderer::Init",
|
"layers::SyncObjectD3D11Renderer::Init",
|
||||||
[]() -> void { Accumulate(Telemetry::D3D11_SYNC_HANDLE_FAILURE, 1); }));
|
[]() -> void { Accumulate(Telemetry::D3D11_SYNC_HANDLE_FAILURE, 1); }));
|
||||||
@ -1463,6 +1500,7 @@ bool SyncObjectD3D11Host::Init() {
|
|||||||
<< gfx::hexa(hr);
|
<< gfx::hexa(hr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
mSyncHandle = new gfx::FileHandleWrapper(UniqueFileHandle(sharedHandle));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1511,11 +1549,22 @@ bool SyncObjectD3D11Client::Init(ID3D11Device* aDevice, bool aFallible) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT hr = aDevice->OpenSharedResource(
|
if (!mSyncHandle) {
|
||||||
mSyncHandle, __uuidof(ID3D11Texture2D),
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<ID3D11Device1> device1;
|
||||||
|
aDevice->QueryInterface((ID3D11Device1**)getter_AddRefs(device1));
|
||||||
|
if (!device1) {
|
||||||
|
gfxCriticalNoteOnce << "Failed to get ID3D11Device1";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
HRESULT hr = device1->OpenSharedResource1(
|
||||||
|
mSyncHandle->GetHandle(), __uuidof(ID3D11Texture2D),
|
||||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mSyncTexture));
|
(void**)(ID3D11Texture2D**)getter_AddRefs(mSyncTexture));
|
||||||
if (FAILED(hr) || !mSyncTexture) {
|
if (FAILED(hr) || !mSyncTexture) {
|
||||||
gfxCriticalNote << "Failed to OpenSharedResource for SyncObjectD3D11: "
|
gfxCriticalNote << "Failed to OpenSharedResource1 for SyncObjectD3D11: "
|
||||||
<< hexa(hr);
|
<< hexa(hr);
|
||||||
if (!aFallible && ShouldDevCrashOnSyncInitFailure()) {
|
if (!aFallible && ShouldDevCrashOnSyncInitFailure()) {
|
||||||
gfxDevCrash(LogReason::D3D11FinalizeFrame)
|
gfxDevCrash(LogReason::D3D11FinalizeFrame)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#define MOZILLA_GFX_TEXTURED3D11_H
|
#define MOZILLA_GFX_TEXTURED3D11_H
|
||||||
|
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
|
#include <d3d11_1.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "d3d9.h"
|
#include "d3d9.h"
|
||||||
@ -25,8 +25,9 @@
|
|||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
class FileHandleWrapper;
|
||||||
struct FenceInfo;
|
struct FenceInfo;
|
||||||
}
|
} // namespace gfx
|
||||||
|
|
||||||
namespace gl {
|
namespace gl {
|
||||||
class GLBlitHelper;
|
class GLBlitHelper;
|
||||||
@ -121,11 +122,10 @@ class D3D11TextureData final : public TextureData {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
D3D11TextureData(ID3D11Texture2D* aTexture, uint32_t aArrayIndex,
|
D3D11TextureData(ID3D11Texture2D* aTexture, uint32_t aArrayIndex,
|
||||||
|
RefPtr<gfx::FileHandleWrapper> aSharedHandle,
|
||||||
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
|
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
|
||||||
TextureAllocationFlags aFlags);
|
TextureAllocationFlags aFlags);
|
||||||
|
|
||||||
void GetDXGIResource(IDXGIResource** aOutResource);
|
|
||||||
|
|
||||||
bool PrepareDrawTargetInLock(OpenMode aMode);
|
bool PrepareDrawTargetInLock(OpenMode aMode);
|
||||||
|
|
||||||
friend class gl::GLBlitHelper;
|
friend class gl::GLBlitHelper;
|
||||||
@ -152,6 +152,7 @@ class D3D11TextureData final : public TextureData {
|
|||||||
const bool mHasKeyedMutex;
|
const bool mHasKeyedMutex;
|
||||||
|
|
||||||
RefPtr<ID3D11Texture2D> mTexture;
|
RefPtr<ID3D11Texture2D> mTexture;
|
||||||
|
const RefPtr<gfx::FileHandleWrapper> mSharedHandle;
|
||||||
Maybe<GpuProcessTextureId> mGpuProcessTextureId;
|
Maybe<GpuProcessTextureId> mGpuProcessTextureId;
|
||||||
uint32_t mArrayIndex = 0;
|
uint32_t mArrayIndex = 0;
|
||||||
const TextureAllocationFlags mAllocationFlags;
|
const TextureAllocationFlags mAllocationFlags;
|
||||||
@ -204,7 +205,7 @@ class DXGIYCbCrTextureData : public TextureData {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
RefPtr<ID3D11Texture2D> mD3D11Textures[3];
|
RefPtr<ID3D11Texture2D> mD3D11Textures[3];
|
||||||
HANDLE mHandles[3];
|
RefPtr<gfx::FileHandleWrapper> mHandles[3];
|
||||||
gfx::IntSize mSize;
|
gfx::IntSize mSize;
|
||||||
gfx::IntSize mSizeY;
|
gfx::IntSize mSizeY;
|
||||||
gfx::IntSize mSizeCbCr;
|
gfx::IntSize mSizeCbCr;
|
||||||
@ -389,7 +390,7 @@ class DXGITextureHostD3D11 : public TextureHost {
|
|||||||
uint32_t mArrayIndex = 0;
|
uint32_t mArrayIndex = 0;
|
||||||
RefPtr<DataTextureSourceD3D11> mTextureSource;
|
RefPtr<DataTextureSourceD3D11> mTextureSource;
|
||||||
gfx::IntSize mSize;
|
gfx::IntSize mSize;
|
||||||
HANDLE mHandle;
|
const RefPtr<gfx::FileHandleWrapper> mHandle;
|
||||||
gfx::SurfaceFormat mFormat;
|
gfx::SurfaceFormat mFormat;
|
||||||
bool mHasKeyedMutex;
|
bool mHasKeyedMutex;
|
||||||
gfx::FenceInfo mAcquireFenceInfo;
|
gfx::FenceInfo mAcquireFenceInfo;
|
||||||
@ -449,7 +450,9 @@ class DXGIYCbCrTextureHostD3D11 : public TextureHost {
|
|||||||
gfx::IntSize mSize;
|
gfx::IntSize mSize;
|
||||||
gfx::IntSize mSizeY;
|
gfx::IntSize mSizeY;
|
||||||
gfx::IntSize mSizeCbCr;
|
gfx::IntSize mSizeCbCr;
|
||||||
HANDLE mHandles[3];
|
// Handles will be closed automatically when `UniqueFileHandle` gets
|
||||||
|
// destroyed.
|
||||||
|
RefPtr<gfx::FileHandleWrapper> mHandles[3];
|
||||||
bool mIsLocked;
|
bool mIsLocked;
|
||||||
gfx::ColorDepth mColorDepth;
|
gfx::ColorDepth mColorDepth;
|
||||||
gfx::YUVColorSpace mYUVColorSpace;
|
gfx::YUVColorSpace mYUVColorSpace;
|
||||||
@ -495,7 +498,7 @@ class SyncObjectD3D11Host : public SyncObjectHost {
|
|||||||
|
|
||||||
SyncHandle mSyncHandle;
|
SyncHandle mSyncHandle;
|
||||||
RefPtr<ID3D11Device> mDevice;
|
RefPtr<ID3D11Device> mDevice;
|
||||||
RefPtr<IDXGIResource> mSyncTexture;
|
RefPtr<IDXGIResource1> mSyncTexture;
|
||||||
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -522,7 +525,7 @@ class SyncObjectD3D11Client : public SyncObjectClient {
|
|||||||
std::vector<ID3D11Texture2D*> mSyncedTextures;
|
std::vector<ID3D11Texture2D*> mSyncedTextures;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const SyncHandle mSyncHandle;
|
SyncHandle mSyncHandle;
|
||||||
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
||||||
const RefPtr<ID3D11Device> mDevice;
|
const RefPtr<ID3D11Device> mDevice;
|
||||||
};
|
};
|
||||||
|
@ -245,7 +245,7 @@ RefPtr<TextureHost> TextureHostWrapperD3D11::CreateFromBufferTexture(
|
|||||||
auto colorSpace = ToColorSpace2(bufferTexture->GetYUVColorSpace());
|
auto colorSpace = ToColorSpace2(bufferTexture->GetYUVColorSpace());
|
||||||
|
|
||||||
auto descD3D10 = SurfaceDescriptorD3D10(
|
auto descD3D10 = SurfaceDescriptorD3D10(
|
||||||
WindowsHandle(nullptr), Some(id),
|
nullptr, Some(id),
|
||||||
/* arrayIndex */ 0, gfx::SurfaceFormat::NV12, size, colorSpace,
|
/* arrayIndex */ 0, gfx::SurfaceFormat::NV12, size, colorSpace,
|
||||||
colorRange, /* hasKeyedMutex */ false, /* fenceInfo */ Nothing());
|
colorRange, /* hasKeyedMutex */ false, /* fenceInfo */ Nothing());
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "mozilla/ScrollSnapInfo.h"
|
#include "mozilla/ScrollSnapInfo.h"
|
||||||
#include "mozilla/ServoBindings.h"
|
#include "mozilla/ServoBindings.h"
|
||||||
#include "mozilla/ipc/ByteBuf.h"
|
#include "mozilla/ipc/ByteBuf.h"
|
||||||
|
#include "mozilla/ipc/ProtocolMessageUtils.h"
|
||||||
#include "mozilla/layers/APZInputBridge.h"
|
#include "mozilla/layers/APZInputBridge.h"
|
||||||
#include "mozilla/layers/AsyncDragMetrics.h"
|
#include "mozilla/layers/AsyncDragMetrics.h"
|
||||||
#include "mozilla/layers/CompositorOptions.h"
|
#include "mozilla/layers/CompositorOptions.h"
|
||||||
|
@ -22,6 +22,7 @@ using mozilla::gfx::IntRect from "mozilla/gfx/Rect.h";
|
|||||||
using mozilla::gfx::IntSize from "mozilla/gfx/Point.h";
|
using mozilla::gfx::IntSize from "mozilla/gfx/Point.h";
|
||||||
using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h";
|
using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h";
|
||||||
using mozilla::gfx::FenceInfo from "mozilla/gfx/FileHandleWrapper.h";
|
using mozilla::gfx::FenceInfo from "mozilla/gfx/FileHandleWrapper.h";
|
||||||
|
[RefCounted] using mozilla::gfx::FileHandleWrapper from "mozilla/gfx/FileHandleWrapper.h";
|
||||||
[MoveOnly] using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h";
|
[MoveOnly] using mozilla::ipc::SharedMemoryBasic::Handle from "mozilla/ipc/SharedMemoryBasic.h";
|
||||||
using gfxImageFormat from "gfxTypes.h";
|
using gfxImageFormat from "gfxTypes.h";
|
||||||
using mozilla::layers::MaybeVideoBridgeSource from "mozilla/layers/VideoBridgeUtils.h";
|
using mozilla::layers::MaybeVideoBridgeSource from "mozilla/layers/VideoBridgeUtils.h";
|
||||||
@ -35,7 +36,7 @@ namespace mozilla {
|
|||||||
namespace layers {
|
namespace layers {
|
||||||
|
|
||||||
[Comparable] struct SurfaceDescriptorD3D10 {
|
[Comparable] struct SurfaceDescriptorD3D10 {
|
||||||
WindowsHandle handle;
|
nullable FileHandleWrapper handle;
|
||||||
GpuProcessTextureId? gpuProcessTextureId;
|
GpuProcessTextureId? gpuProcessTextureId;
|
||||||
uint32_t arrayIndex;
|
uint32_t arrayIndex;
|
||||||
SurfaceFormat format;
|
SurfaceFormat format;
|
||||||
@ -47,9 +48,9 @@ namespace layers {
|
|||||||
};
|
};
|
||||||
|
|
||||||
[Comparable] struct SurfaceDescriptorDXGIYCbCr {
|
[Comparable] struct SurfaceDescriptorDXGIYCbCr {
|
||||||
WindowsHandle handleY;
|
nullable FileHandleWrapper handleY;
|
||||||
WindowsHandle handleCb;
|
nullable FileHandleWrapper handleCb;
|
||||||
WindowsHandle handleCr;
|
nullable FileHandleWrapper handleCr;
|
||||||
IntSize size;
|
IntSize size;
|
||||||
IntSize sizeY;
|
IntSize sizeY;
|
||||||
IntSize sizeCbCr;
|
IntSize sizeCbCr;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <dxgi1_2.h>
|
#include <dxgi1_2.h>
|
||||||
#include <d3d10_1.h>
|
#include <d3d10_1.h>
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
|
#include <d3d11_1.h>
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
@ -56,7 +57,8 @@ bool D3D11Checks::DoesRenderTargetViewNeedRecreating(ID3D11Device* aDevice) {
|
|||||||
offscreenTextureDesc.BindFlags =
|
offscreenTextureDesc.BindFlags =
|
||||||
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
|
||||||
offscreenTextureDesc.CPUAccessFlags = 0;
|
offscreenTextureDesc.CPUAccessFlags = 0;
|
||||||
offscreenTextureDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
offscreenTextureDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
||||||
|
|
||||||
HRESULT hr = aDevice->CreateTexture2D(&offscreenTextureDesc, NULL,
|
HRESULT hr = aDevice->CreateTexture2D(&offscreenTextureDesc, NULL,
|
||||||
getter_AddRefs(offscreenTexture));
|
getter_AddRefs(offscreenTexture));
|
||||||
@ -242,7 +244,8 @@ static bool DoesTextureSharingWorkInternal(ID3D11Device* device,
|
|||||||
desc.SampleDesc.Quality = 0;
|
desc.SampleDesc.Quality = 0;
|
||||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
desc.CPUAccessFlags = 0;
|
desc.CPUAccessFlags = 0;
|
||||||
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
||||||
desc.BindFlags = bindflags;
|
desc.BindFlags = bindflags;
|
||||||
|
|
||||||
uint32_t color[texture_size * texture_size];
|
uint32_t color[texture_size * texture_size];
|
||||||
@ -282,22 +285,34 @@ static bool DoesTextureSharingWorkInternal(ID3D11Device* device,
|
|||||||
stride * texture_size);
|
stride * texture_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE shareHandle;
|
RefPtr<IDXGIResource1> otherResource;
|
||||||
RefPtr<IDXGIResource> otherResource;
|
if (FAILED(texture->QueryInterface(__uuidof(IDXGIResource1),
|
||||||
if (FAILED(texture->QueryInterface(__uuidof(IDXGIResource),
|
|
||||||
getter_AddRefs(otherResource)))) {
|
getter_AddRefs(otherResource)))) {
|
||||||
gfxCriticalError() << "DoesD3D11TextureSharingWork_GetResourceFailure";
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_GetResourceFailure";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(otherResource->GetSharedHandle(&shareHandle))) {
|
HANDLE sharedHandle;
|
||||||
|
if (FAILED(otherResource->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE,
|
||||||
|
nullptr, &sharedHandle))) {
|
||||||
gfxCriticalError() << "DoesD3D11TextureSharingWork_GetSharedTextureFailure";
|
gfxCriticalError() << "DoesD3D11TextureSharingWork_GetSharedTextureFailure";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto handle = ipc::FileDescriptor(UniqueFileHandle(sharedHandle));
|
||||||
|
|
||||||
|
RefPtr<ID3D11Device1> device1;
|
||||||
|
device->QueryInterface((ID3D11Device1**)getter_AddRefs(device1));
|
||||||
|
if (!device1) {
|
||||||
|
gfxCriticalNoteOnce << "Failed to get ID3D11Device1";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<ID3D11Resource> sharedResource;
|
RefPtr<ID3D11Resource> sharedResource;
|
||||||
RefPtr<ID3D11Texture2D> sharedTexture;
|
RefPtr<ID3D11Texture2D> sharedTexture;
|
||||||
if (FAILED(device->OpenSharedResource(shareHandle, __uuidof(ID3D11Resource),
|
auto raw = handle.TakePlatformHandle();
|
||||||
|
if (FAILED(device1->OpenSharedResource1(raw.get(), __uuidof(ID3D11Resource),
|
||||||
getter_AddRefs(sharedResource)))) {
|
getter_AddRefs(sharedResource)))) {
|
||||||
gfxCriticalError(CriticalLog::DefaultOptions(false))
|
gfxCriticalError(CriticalLog::DefaultOptions(false))
|
||||||
<< "OpenSharedResource failed for format " << format;
|
<< "OpenSharedResource failed for format " << format;
|
||||||
|
@ -27,7 +27,8 @@ bool FxROutputHandler::TryInitialize(IDXGISwapChain* aSwapChain,
|
|||||||
// Create shareable texture, which will be copied to
|
// Create shareable texture, which will be copied to
|
||||||
D3D11_TEXTURE2D_DESC descOrig = {0};
|
D3D11_TEXTURE2D_DESC descOrig = {0};
|
||||||
texOrig->GetDesc(&descOrig);
|
texOrig->GetDesc(&descOrig);
|
||||||
descOrig.MiscFlags |= D3D11_RESOURCE_MISC_SHARED;
|
descOrig.MiscFlags |=
|
||||||
|
D3D11_RESOURCE_MISC_SHARED_NTHANDLE | D3D11_RESOURCE_MISC_SHARED;
|
||||||
hr = aDevice->CreateTexture2D(&descOrig, nullptr,
|
hr = aDevice->CreateTexture2D(&descOrig, nullptr,
|
||||||
mTexCopy.StartAssignment());
|
mTexCopy.StartAssignment());
|
||||||
if (hr != S_OK) {
|
if (hr != S_OK) {
|
||||||
@ -37,14 +38,16 @@ bool FxROutputHandler::TryInitialize(IDXGISwapChain* aSwapChain,
|
|||||||
// Now, share the texture to a handle that can be marshaled to another
|
// Now, share the texture to a handle that can be marshaled to another
|
||||||
// process
|
// process
|
||||||
HANDLE hCopy = nullptr;
|
HANDLE hCopy = nullptr;
|
||||||
RefPtr<IDXGIResource> texResource;
|
RefPtr<IDXGIResource1> texResource;
|
||||||
hr = mTexCopy->QueryInterface(IID_IDXGIResource,
|
hr = mTexCopy->QueryInterface(IID_IDXGIResource1,
|
||||||
getter_AddRefs(texResource));
|
getter_AddRefs(texResource));
|
||||||
if (hr != S_OK) {
|
if (hr != S_OK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = texResource->GetSharedHandle(&hCopy);
|
hr = texResource->CreateSharedHandle(
|
||||||
|
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE,
|
||||||
|
nullptr, &hCopy);
|
||||||
if (hr != S_OK) {
|
if (hr != S_OK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1389,9 +1389,10 @@ bool VRManager::SubmitFrame(const layers::SurfaceDescriptor& aTexture,
|
|||||||
case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
|
case SurfaceDescriptor::TSurfaceDescriptorD3D10: {
|
||||||
const SurfaceDescriptorD3D10& surf =
|
const SurfaceDescriptorD3D10& surf =
|
||||||
aTexture.get_SurfaceDescriptorD3D10();
|
aTexture.get_SurfaceDescriptorD3D10();
|
||||||
|
auto handle = surf.handle()->ClonePlatformHandle();
|
||||||
layer.textureType =
|
layer.textureType =
|
||||||
VRLayerTextureType::LayerTextureType_D3D10SurfaceDescriptor;
|
VRLayerTextureType::LayerTextureType_D3D10SurfaceDescriptor;
|
||||||
layer.textureHandle = (void*)surf.handle();
|
layer.textureHandle = (void*)handle.release();
|
||||||
layer.textureSize.width = surf.size().width;
|
layer.textureSize.width = surf.size().width;
|
||||||
layer.textureSize.height = surf.size().height;
|
layer.textureSize.height = surf.size().height;
|
||||||
} break;
|
} break;
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include "moz_external_vr.h"
|
#include "moz_external_vr.h"
|
||||||
|
|
||||||
|
#include "mozilla/ipc/FileDescriptor.h"
|
||||||
|
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
# include <d3d11.h>
|
# include <d3d11.h>
|
||||||
#endif // defined(XP_WIN)
|
#endif // defined(XP_WIN)
|
||||||
@ -104,8 +106,10 @@ bool VRSession::SubmitFrame(
|
|||||||
if (aLayer.textureType ==
|
if (aLayer.textureType ==
|
||||||
VRLayerTextureType::LayerTextureType_D3D10SurfaceDescriptor) {
|
VRLayerTextureType::LayerTextureType_D3D10SurfaceDescriptor) {
|
||||||
ID3D11Texture2D* dxTexture = nullptr;
|
ID3D11Texture2D* dxTexture = nullptr;
|
||||||
HRESULT hr = mDevice->OpenSharedResource((HANDLE)aLayer.textureHandle,
|
mozilla::ipc::FileDescriptor::UniquePlatformHandle handle(
|
||||||
IID_PPV_ARGS(&dxTexture));
|
aLayer.textureHandle);
|
||||||
|
HRESULT hr =
|
||||||
|
mDevice->OpenSharedResource1(handle.get(), IID_PPV_ARGS(&dxTexture));
|
||||||
if (SUCCEEDED(hr) && dxTexture != nullptr) {
|
if (SUCCEEDED(hr) && dxTexture != nullptr) {
|
||||||
// Similar to LockD3DTexture in TextureD3D11.cpp
|
// Similar to LockD3DTexture in TextureD3D11.cpp
|
||||||
IDXGIKeyedMutex* mutex = nullptr;
|
IDXGIKeyedMutex* mutex = nullptr;
|
||||||
|
@ -24,7 +24,8 @@ namespace mozilla {
|
|||||||
namespace wr {
|
namespace wr {
|
||||||
|
|
||||||
RenderDXGITextureHost::RenderDXGITextureHost(
|
RenderDXGITextureHost::RenderDXGITextureHost(
|
||||||
HANDLE aHandle, Maybe<layers::GpuProcessTextureId>& aGpuProcessTextureId,
|
RefPtr<gfx::FileHandleWrapper> aHandle,
|
||||||
|
Maybe<layers::GpuProcessTextureId>& aGpuProcessTextureId,
|
||||||
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat,
|
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat,
|
||||||
gfx::ColorSpace2 aColorSpace, gfx::ColorRange aColorRange,
|
gfx::ColorSpace2 aColorSpace, gfx::ColorRange aColorRange,
|
||||||
gfx::IntSize aSize, bool aHasKeyedMutex, gfx::FenceInfo& aAcquireFenceInfo)
|
gfx::IntSize aSize, bool aHasKeyedMutex, gfx::FenceInfo& aAcquireFenceInfo)
|
||||||
@ -214,9 +215,16 @@ bool RenderDXGITextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<ID3D11Device1> device1;
|
||||||
|
aDevice->QueryInterface((ID3D11Device1**)getter_AddRefs(device1));
|
||||||
|
if (!device1) {
|
||||||
|
gfxCriticalNoteOnce << "Failed to get ID3D11Device1";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the D3D11 texture from shared handle.
|
// Get the D3D11 texture from shared handle.
|
||||||
HRESULT hr = aDevice->OpenSharedResource(
|
HRESULT hr = device1->OpenSharedResource1(
|
||||||
(HANDLE)mHandle, __uuidof(ID3D11Texture2D),
|
(HANDLE)mHandle->GetHandle(), __uuidof(ID3D11Texture2D),
|
||||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mTexture));
|
(void**)(ID3D11Texture2D**)getter_AddRefs(mTexture));
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
MOZ_ASSERT(false,
|
MOZ_ASSERT(false,
|
||||||
@ -463,9 +471,9 @@ bool RenderDXGITextureHost::SyncObjectNeeded() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RenderDXGIYCbCrTextureHost::RenderDXGIYCbCrTextureHost(
|
RenderDXGIYCbCrTextureHost::RenderDXGIYCbCrTextureHost(
|
||||||
HANDLE (&aHandles)[3], gfx::YUVColorSpace aYUVColorSpace,
|
RefPtr<gfx::FileHandleWrapper> (&aHandles)[3],
|
||||||
gfx::ColorDepth aColorDepth, gfx::ColorRange aColorRange,
|
gfx::YUVColorSpace aYUVColorSpace, gfx::ColorDepth aColorDepth,
|
||||||
gfx::IntSize aSizeY, gfx::IntSize aSizeCbCr)
|
gfx::ColorRange aColorRange, gfx::IntSize aSizeY, gfx::IntSize aSizeCbCr)
|
||||||
: mHandles{aHandles[0], aHandles[1], aHandles[2]},
|
: mHandles{aHandles[0], aHandles[1], aHandles[2]},
|
||||||
mSurfaces{0},
|
mSurfaces{0},
|
||||||
mStreams{0},
|
mStreams{0},
|
||||||
@ -586,6 +594,13 @@ bool RenderDXGIYCbCrTextureHost::EnsureLockable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool RenderDXGIYCbCrTextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
|
bool RenderDXGIYCbCrTextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
|
||||||
|
RefPtr<ID3D11Device1> device1;
|
||||||
|
aDevice->QueryInterface((ID3D11Device1**)getter_AddRefs(device1));
|
||||||
|
if (!device1) {
|
||||||
|
gfxCriticalNoteOnce << "Failed to get ID3D11Device1";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (mTextures[0]) {
|
if (mTextures[0]) {
|
||||||
RefPtr<ID3D11Device> device;
|
RefPtr<ID3D11Device> device;
|
||||||
mTextures[0]->GetDevice(getter_AddRefs(device));
|
mTextures[0]->GetDevice(getter_AddRefs(device));
|
||||||
@ -601,8 +616,8 @@ bool RenderDXGIYCbCrTextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
|
|||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
// Get the R8 D3D11 texture from shared handle.
|
// Get the R8 D3D11 texture from shared handle.
|
||||||
HRESULT hr = aDevice->OpenSharedResource(
|
HRESULT hr = device1->OpenSharedResource1(
|
||||||
(HANDLE)mHandles[i], __uuidof(ID3D11Texture2D),
|
(HANDLE)mHandles[i]->GetHandle(), __uuidof(ID3D11Texture2D),
|
||||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mTextures[i]));
|
(void**)(ID3D11Texture2D**)getter_AddRefs(mTextures[i]));
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
NS_WARNING(
|
NS_WARNING(
|
||||||
|
@ -27,7 +27,8 @@ namespace wr {
|
|||||||
class RenderDXGITextureHost final : public RenderTextureHostSWGL {
|
class RenderDXGITextureHost final : public RenderTextureHostSWGL {
|
||||||
public:
|
public:
|
||||||
RenderDXGITextureHost(
|
RenderDXGITextureHost(
|
||||||
HANDLE aHandle, Maybe<layers::GpuProcessTextureId>& aGpuProcessTextureId,
|
RefPtr<gfx::FileHandleWrapper> aHandle,
|
||||||
|
Maybe<layers::GpuProcessTextureId>& aGpuProcessTextureId,
|
||||||
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat, gfx::ColorSpace2,
|
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat, gfx::ColorSpace2,
|
||||||
gfx::ColorRange aColorRange, gfx::IntSize aSize, bool aHasKeyedMutex,
|
gfx::ColorRange aColorRange, gfx::IntSize aSize, bool aHasKeyedMutex,
|
||||||
gfx::FenceInfo& aAcquireFenceInfo);
|
gfx::FenceInfo& aAcquireFenceInfo);
|
||||||
@ -99,7 +100,7 @@ class RenderDXGITextureHost final : public RenderTextureHostSWGL {
|
|||||||
|
|
||||||
RefPtr<gl::GLContext> mGL;
|
RefPtr<gl::GLContext> mGL;
|
||||||
|
|
||||||
HANDLE mHandle;
|
RefPtr<gfx::FileHandleWrapper> mHandle;
|
||||||
Maybe<layers::GpuProcessTextureId> mGpuProcessTextureId;
|
Maybe<layers::GpuProcessTextureId> mGpuProcessTextureId;
|
||||||
RefPtr<ID3D11Texture2D> mTexture;
|
RefPtr<ID3D11Texture2D> mTexture;
|
||||||
uint32_t mArrayIndex = 0;
|
uint32_t mArrayIndex = 0;
|
||||||
@ -135,12 +136,10 @@ class RenderDXGITextureHost final : public RenderTextureHostSWGL {
|
|||||||
|
|
||||||
class RenderDXGIYCbCrTextureHost final : public RenderTextureHostSWGL {
|
class RenderDXGIYCbCrTextureHost final : public RenderTextureHostSWGL {
|
||||||
public:
|
public:
|
||||||
explicit RenderDXGIYCbCrTextureHost(HANDLE (&aHandles)[3],
|
explicit RenderDXGIYCbCrTextureHost(
|
||||||
gfx::YUVColorSpace aYUVColorSpace,
|
RefPtr<gfx::FileHandleWrapper> (&aHandles)[3],
|
||||||
gfx::ColorDepth aColorDepth,
|
gfx::YUVColorSpace aYUVColorSpace, gfx::ColorDepth aColorDepth,
|
||||||
gfx::ColorRange aColorRange,
|
gfx::ColorRange aColorRange, gfx::IntSize aSizeY, gfx::IntSize aSizeCbCr);
|
||||||
gfx::IntSize aSizeY,
|
|
||||||
gfx::IntSize aSizeCbCr);
|
|
||||||
|
|
||||||
RenderDXGIYCbCrTextureHost* AsRenderDXGIYCbCrTextureHost() override {
|
RenderDXGIYCbCrTextureHost* AsRenderDXGIYCbCrTextureHost() override {
|
||||||
return this;
|
return this;
|
||||||
@ -198,7 +197,7 @@ class RenderDXGIYCbCrTextureHost final : public RenderTextureHostSWGL {
|
|||||||
|
|
||||||
RefPtr<gl::GLContext> mGL;
|
RefPtr<gl::GLContext> mGL;
|
||||||
|
|
||||||
HANDLE mHandles[3];
|
RefPtr<gfx::FileHandleWrapper> mHandles[3];
|
||||||
RefPtr<ID3D11Texture2D> mTextures[3];
|
RefPtr<ID3D11Texture2D> mTextures[3];
|
||||||
RefPtr<IDXGIKeyedMutex> mKeyedMutexs[3];
|
RefPtr<IDXGIKeyedMutex> mKeyedMutexs[3];
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ already_AddRefed<WebRenderAPI> WebRenderAPI::Create(
|
|||||||
bool useDComp = false;
|
bool useDComp = false;
|
||||||
bool useTripleBuffering = false;
|
bool useTripleBuffering = false;
|
||||||
bool supportsExternalBufferTextures = false;
|
bool supportsExternalBufferTextures = false;
|
||||||
layers::SyncHandle syncHandle = 0;
|
layers::SyncHandle syncHandle = {};
|
||||||
|
|
||||||
// Dispatch a synchronous task because the DocumentHandle object needs to be
|
// Dispatch a synchronous task because the DocumentHandle object needs to be
|
||||||
// created on the render thread. If need be we could delay waiting on this
|
// created on the render thread. If need be we could delay waiting on this
|
||||||
|
Loading…
Reference in New Issue
Block a user