зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1673983 - Add RenderTextureHostSWGL support to D3D11 RenderTextureHosts. r=lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D95799
This commit is contained in:
Родитель
f9fe60e315
Коммит
b8c9f1b675
|
@ -1718,6 +1718,13 @@ bool CompositorD3D11::Failed(HRESULT hr, const char* aContext) {
|
|||
return true;
|
||||
}
|
||||
|
||||
SyncObjectHost* CompositorD3D11::GetSyncObject() {
|
||||
if (mAttachments) {
|
||||
return mAttachments->mSyncObject;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CompositorD3D11::HandleError(HRESULT hr, Severity aSeverity) {
|
||||
if (SUCCEEDED(hr)) {
|
||||
return;
|
||||
|
|
|
@ -149,6 +149,8 @@ class CompositorD3D11 : public Compositor {
|
|||
mTarget = nullptr;
|
||||
}
|
||||
|
||||
SyncObjectHost* GetSyncObject();
|
||||
|
||||
private:
|
||||
enum Severity {
|
||||
Recoverable,
|
||||
|
|
|
@ -999,12 +999,6 @@ void DXGITextureHostD3D11::PushResourceUpdates(
|
|||
MOZ_ASSERT_UNREACHABLE("unexpected to be called without ANGLE");
|
||||
return;
|
||||
}
|
||||
// XXX Software WebRender is not handled yet.
|
||||
if (gfx::gfxVars::UseSoftwareWebRender()) {
|
||||
gfxCriticalNoteOnce
|
||||
<< "Software WebRender is not suppored by DXGITextureHostD3D11.";
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mHandle);
|
||||
auto method = aOp == TextureHost::ADD_IMAGE
|
||||
|
@ -1019,7 +1013,10 @@ void DXGITextureHostD3D11::PushResourceUpdates(
|
|||
|
||||
wr::ImageDescriptor descriptor(mSize, GetFormat());
|
||||
auto imageType =
|
||||
wr::ExternalImageType::TextureHandle(wr::TextureTarget::External);
|
||||
gfx::gfxVars::UseSoftwareWebRender()
|
||||
? wr::ExternalImageType::TextureHandle(wr::TextureTarget::Rect)
|
||||
: wr::ExternalImageType::TextureHandle(
|
||||
wr::TextureTarget::External);
|
||||
(aResources.*method)(aImageKeys[0], descriptor, aExtID, imageType, 0);
|
||||
break;
|
||||
}
|
||||
|
@ -1038,7 +1035,10 @@ void DXGITextureHostD3D11::PushResourceUpdates(
|
|||
? gfx::SurfaceFormat::R8G8
|
||||
: gfx::SurfaceFormat::R16G16);
|
||||
auto imageType =
|
||||
wr::ExternalImageType::TextureHandle(wr::TextureTarget::External);
|
||||
gfx::gfxVars::UseSoftwareWebRender()
|
||||
? wr::ExternalImageType::TextureHandle(wr::TextureTarget::Rect)
|
||||
: wr::ExternalImageType::TextureHandle(
|
||||
wr::TextureTarget::External);
|
||||
(aResources.*method)(aImageKeys[0], descriptor0, aExtID, imageType, 0);
|
||||
(aResources.*method)(aImageKeys[1], descriptor1, aExtID, imageType, 1);
|
||||
break;
|
||||
|
@ -1059,12 +1059,6 @@ void DXGITextureHostD3D11::PushDisplayItems(
|
|||
MOZ_ASSERT_UNREACHABLE("unexpected to be called without ANGLE");
|
||||
return;
|
||||
}
|
||||
// XXX Software WebRender is not handled yet.
|
||||
if (gfx::gfxVars::UseSoftwareWebRender()) {
|
||||
gfxCriticalNoteOnce
|
||||
<< "Software WebRender is not suppored by DXGITextureHostD3D11.";
|
||||
return;
|
||||
}
|
||||
|
||||
switch (GetFormat()) {
|
||||
case gfx::SurfaceFormat::R8G8B8X8:
|
||||
|
@ -1256,8 +1250,8 @@ bool DXGIYCbCrTextureHostD3D11::BindTextureSource(
|
|||
|
||||
void DXGIYCbCrTextureHostD3D11::CreateRenderTexture(
|
||||
const wr::ExternalImageId& aExternalImageId) {
|
||||
RefPtr<wr::RenderTextureHost> texture =
|
||||
new wr::RenderDXGIYCbCrTextureHost(mHandles, mSizeY, mSizeCbCr);
|
||||
RefPtr<wr::RenderTextureHost> texture = new wr::RenderDXGIYCbCrTextureHost(
|
||||
mHandles, mYUVColorSpace, mColorDepth, mSizeY, mSizeCbCr);
|
||||
|
||||
wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
|
||||
texture.forget());
|
||||
|
@ -1275,12 +1269,6 @@ void DXGIYCbCrTextureHostD3D11::PushResourceUpdates(
|
|||
MOZ_ASSERT_UNREACHABLE("unexpected to be called without ANGLE");
|
||||
return;
|
||||
}
|
||||
// XXX Software WebRender is not handled yet.
|
||||
if (gfx::gfxVars::UseSoftwareWebRender()) {
|
||||
gfxCriticalNoteOnce
|
||||
<< "Software WebRender is not suppored by DXGIYCbCrTextureHostD3D11.";
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mHandles[0] && mHandles[1] && mHandles[2]);
|
||||
MOZ_ASSERT(aImageKeys.length() == 3);
|
||||
|
@ -1294,7 +1282,9 @@ void DXGIYCbCrTextureHostD3D11::PushResourceUpdates(
|
|||
? &wr::TransactionBuilder::AddExternalImage
|
||||
: &wr::TransactionBuilder::UpdateExternalImage;
|
||||
auto imageType =
|
||||
wr::ExternalImageType::TextureHandle(wr::TextureTarget::External);
|
||||
gfx::gfxVars::UseSoftwareWebRender()
|
||||
? wr::ExternalImageType::TextureHandle(wr::TextureTarget::Rect)
|
||||
: wr::ExternalImageType::TextureHandle(wr::TextureTarget::External);
|
||||
|
||||
// y
|
||||
wr::ImageDescriptor descriptor0(mSizeY, gfx::SurfaceFormat::A8);
|
||||
|
@ -1313,12 +1303,6 @@ void DXGIYCbCrTextureHostD3D11::PushDisplayItems(
|
|||
MOZ_ASSERT_UNREACHABLE("unexpected to be called without ANGLE");
|
||||
return;
|
||||
}
|
||||
// XXX Software WebRender is not handled yet.
|
||||
if (gfx::gfxVars::UseSoftwareWebRender()) {
|
||||
gfxCriticalNoteOnce
|
||||
<< "Software WebRender is not suppored by DXGIYCbCrTextureHostD3D11.";
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(aImageKeys.length() == 3);
|
||||
|
||||
|
|
|
@ -103,7 +103,9 @@ class KnowsCompositor {
|
|||
bool SupportsD3D11() const {
|
||||
return GetCompositorBackendType() == layers::LayersBackend::LAYERS_D3D11 ||
|
||||
(GetCompositorBackendType() == layers::LayersBackend::LAYERS_WR &&
|
||||
GetCompositorUseANGLE());
|
||||
(GetCompositorUseANGLE() ||
|
||||
mTextureFactoryIdentifier.mWebRenderCompositor ==
|
||||
layers::WebRenderCompositor::D3D11));
|
||||
}
|
||||
|
||||
bool GetCompositorUseANGLE() const {
|
||||
|
|
|
@ -69,7 +69,8 @@ gfx::YUVColorSpace RenderBufferTextureHostSWGL::GetYUVColorSpace() const {
|
|||
}
|
||||
}
|
||||
|
||||
bool RenderBufferTextureHostSWGL::MapPlane(uint8_t aChannelIndex,
|
||||
bool RenderBufferTextureHostSWGL::MapPlane(RenderCompositor* aCompositor,
|
||||
uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) {
|
||||
switch (mDescriptor.type()) {
|
||||
case layers::BufferDescriptor::TYCbCrDescriptor: {
|
||||
|
|
|
@ -25,7 +25,8 @@ class RenderBufferTextureHostSWGL final : public RenderTextureHostSWGL {
|
|||
|
||||
gfx::YUVColorSpace GetYUVColorSpace() const override;
|
||||
|
||||
bool MapPlane(uint8_t aChannelIndex, PlaneInfo& aPlaneInfo) override;
|
||||
bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) override;
|
||||
|
||||
void UnmapPlanes() override;
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ class CompositorWidget;
|
|||
|
||||
namespace wr {
|
||||
|
||||
class RenderCompositorD3D11SWGL;
|
||||
|
||||
class RenderCompositor {
|
||||
public:
|
||||
static UniquePtr<RenderCompositor> Create(
|
||||
|
@ -85,6 +87,10 @@ class RenderCompositor {
|
|||
return layers::WebRenderCompositor::DRAW;
|
||||
}
|
||||
|
||||
virtual RenderCompositorD3D11SWGL* AsRenderCompositorD3D11SWGL() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// True if AttachExternalImage supports being used with an external
|
||||
// image that maps to a RenderBufferTextureHost
|
||||
virtual bool SupportsExternalBufferTextures() const { return false; }
|
||||
|
|
|
@ -44,6 +44,7 @@ RenderCompositorD3D11SWGL::RenderCompositorD3D11SWGL(
|
|||
mCompositor(aCompositor),
|
||||
mContext(aContext) {
|
||||
MOZ_ASSERT(mContext);
|
||||
mSyncObject = mCompositor->GetSyncObject();
|
||||
}
|
||||
|
||||
RenderCompositorD3D11SWGL::~RenderCompositorD3D11SWGL() {
|
||||
|
|
|
@ -49,6 +49,7 @@ class RenderCompositorD3D11SWGL : public RenderCompositor {
|
|||
layers::WebRenderCompositor CompositorType() const override {
|
||||
return layers::WebRenderCompositor::D3D11;
|
||||
}
|
||||
RenderCompositorD3D11SWGL* AsRenderCompositorD3D11SWGL() { return this; }
|
||||
|
||||
// Interface for wr::Compositor
|
||||
CompositorCapabilities GetCompositorCapabilities() override;
|
||||
|
@ -95,6 +96,8 @@ class RenderCompositorD3D11SWGL : public RenderCompositor {
|
|||
int32_t mY;
|
||||
};
|
||||
|
||||
ID3D11Device* GetDevice() { return mCompositor->GetDevice(); }
|
||||
|
||||
private:
|
||||
RefPtr<layers::CompositorD3D11> mCompositor;
|
||||
void* mContext = nullptr;
|
||||
|
|
|
@ -58,6 +58,93 @@ ID3D11Texture2D* RenderDXGITextureHost::GetD3D11Texture2D() {
|
|||
return mTexture;
|
||||
}
|
||||
|
||||
size_t RenderDXGITextureHost::GetPlaneCount() const {
|
||||
if (mFormat == gfx::SurfaceFormat::NV12 ||
|
||||
mFormat == gfx::SurfaceFormat::P010 ||
|
||||
mFormat == gfx::SurfaceFormat::P016) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static bool MapTexture(T* aHost, RenderCompositor* aCompositor,
|
||||
RefPtr<ID3D11Texture2D>& aTexture,
|
||||
RefPtr<ID3D11DeviceContext>& aDeviceContext,
|
||||
RefPtr<ID3D11Texture2D>& aCpuTexture,
|
||||
D3D11_MAPPED_SUBRESOURCE& aMappedSubresource) {
|
||||
RenderCompositorD3D11SWGL* compositor =
|
||||
aCompositor->AsRenderCompositorD3D11SWGL();
|
||||
if (!compositor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!aHost->EnsureD3D11Texture2D(compositor->GetDevice())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!aHost->LockInternal()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
D3D11_TEXTURE2D_DESC textureDesc = {0};
|
||||
aTexture->GetDesc(&textureDesc);
|
||||
|
||||
compositor->GetDevice()->GetImmediateContext(getter_AddRefs(aDeviceContext));
|
||||
|
||||
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
textureDesc.Usage = D3D11_USAGE_STAGING;
|
||||
textureDesc.BindFlags = 0;
|
||||
textureDesc.MiscFlags = 0;
|
||||
textureDesc.MipLevels = 1;
|
||||
HRESULT hr = compositor->GetDevice()->CreateTexture2D(
|
||||
&textureDesc, nullptr, getter_AddRefs(aCpuTexture));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aDeviceContext->CopyResource(aCpuTexture, aTexture);
|
||||
aHost->Unlock();
|
||||
|
||||
hr = aDeviceContext->Map(aCpuTexture, 0, D3D11_MAP_READ, 0,
|
||||
&aMappedSubresource);
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
bool RenderDXGITextureHost::MapPlane(RenderCompositor* aCompositor,
|
||||
uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) {
|
||||
// TODO: We currently readback from the GPU texture into a new
|
||||
// staging texture every time this is mapped. We might be better
|
||||
// off retaining the mapped memory to trade performance for memory
|
||||
// usage.
|
||||
if (!mCpuTexture && !MapTexture(this, aCompositor, mTexture, mDeviceContext,
|
||||
mCpuTexture, mMappedSubresource)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aPlaneInfo.mSize = GetSize(aChannelIndex);
|
||||
aPlaneInfo.mStride = mMappedSubresource.RowPitch;
|
||||
aPlaneInfo.mData = mMappedSubresource.pData;
|
||||
|
||||
// If this is the second plane, then offset the data pointer by the
|
||||
// size of the first plane.
|
||||
if (aChannelIndex == 1) {
|
||||
aPlaneInfo.mData =
|
||||
(uint8_t*)aPlaneInfo.mData + aPlaneInfo.mStride * GetSize(0).height;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderDXGITextureHost::UnmapPlanes() {
|
||||
mMappedSubresource.pData = nullptr;
|
||||
if (mCpuTexture) {
|
||||
mDeviceContext->Unmap(mCpuTexture, 0);
|
||||
mCpuTexture = nullptr;
|
||||
}
|
||||
mDeviceContext = nullptr;
|
||||
}
|
||||
|
||||
bool RenderDXGITextureHost::EnsureD3D11Texture2D() {
|
||||
if (mTexture) {
|
||||
return true;
|
||||
|
@ -80,8 +167,16 @@ bool RenderDXGITextureHost::EnsureD3D11Texture2D() {
|
|||
return false;
|
||||
}
|
||||
|
||||
return EnsureD3D11Texture2D(device);
|
||||
}
|
||||
|
||||
bool RenderDXGITextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
|
||||
if (mTexture) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the D3D11 texture from shared handle.
|
||||
HRESULT hr = device->OpenSharedResource(
|
||||
HRESULT hr = aDevice->OpenSharedResource(
|
||||
(HANDLE)mHandle, __uuidof(ID3D11Texture2D),
|
||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mTexture));
|
||||
if (FAILED(hr)) {
|
||||
|
@ -94,6 +189,7 @@ bool RenderDXGITextureHost::EnsureD3D11Texture2D() {
|
|||
return false;
|
||||
}
|
||||
MOZ_ASSERT(mTexture.get());
|
||||
mTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mKeyedMutex));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -136,7 +232,6 @@ bool RenderDXGITextureHost::EnsureLockable(wr::ImageRendering aRendering) {
|
|||
if (!EnsureD3D11Texture2D()) {
|
||||
return false;
|
||||
}
|
||||
mTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mKeyedMutex));
|
||||
|
||||
// Create the EGLStream.
|
||||
mStream = egl->fCreateStreamKHR(nullptr);
|
||||
|
@ -223,21 +318,28 @@ wr::WrExternalImage RenderDXGITextureHost::Lock(uint8_t aChannelIndex,
|
|||
return InvalidToWrExternalImage();
|
||||
}
|
||||
|
||||
if (!LockInternal()) {
|
||||
return InvalidToWrExternalImage();
|
||||
}
|
||||
|
||||
gfx::IntSize size = GetSize(aChannelIndex);
|
||||
return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0, 0,
|
||||
size.width, size.height);
|
||||
}
|
||||
|
||||
bool RenderDXGITextureHost::LockInternal() {
|
||||
if (!mLocked) {
|
||||
if (mKeyedMutex) {
|
||||
HRESULT hr = mKeyedMutex->AcquireSync(0, 10000);
|
||||
if (hr != S_OK) {
|
||||
gfxCriticalError() << "RenderDXGITextureHost AcquireSync timeout, hr="
|
||||
<< gfx::hexa(hr);
|
||||
return InvalidToWrExternalImage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
mLocked = true;
|
||||
}
|
||||
|
||||
gfx::IntSize size = GetSize(aChannelIndex);
|
||||
return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0, 0,
|
||||
size.width, size.height);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderDXGITextureHost::Unlock() {
|
||||
|
@ -312,11 +414,14 @@ gfx::IntSize RenderDXGITextureHost::GetSize(uint8_t aChannelIndex) const {
|
|||
}
|
||||
|
||||
RenderDXGIYCbCrTextureHost::RenderDXGIYCbCrTextureHost(
|
||||
WindowsHandle (&aHandles)[3], gfx::IntSize aSizeY, gfx::IntSize aSizeCbCr)
|
||||
WindowsHandle (&aHandles)[3], gfx::YUVColorSpace aYUVColorSpace,
|
||||
gfx::ColorDepth aColorDepth, gfx::IntSize aSizeY, gfx::IntSize aSizeCbCr)
|
||||
: mHandles{aHandles[0], aHandles[1], aHandles[2]},
|
||||
mSurfaces{0},
|
||||
mStreams{0},
|
||||
mTextureHandles{0},
|
||||
mYUVColorSpace(aYUVColorSpace),
|
||||
mColorDepth(aColorDepth),
|
||||
mSizeY(aSizeY),
|
||||
mSizeCbCr(aSizeCbCr),
|
||||
mLocked(false) {
|
||||
|
@ -329,6 +434,31 @@ RenderDXGIYCbCrTextureHost::RenderDXGIYCbCrTextureHost(
|
|||
MOZ_ASSERT(aHandles[0] && aHandles[1] && aHandles[2]);
|
||||
}
|
||||
|
||||
bool RenderDXGIYCbCrTextureHost::MapPlane(RenderCompositor* aCompositor,
|
||||
uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) {
|
||||
D3D11_MAPPED_SUBRESOURCE mappedSubresource;
|
||||
if (!MapTexture(this, aCompositor, mTextures[aChannelIndex], mDeviceContext,
|
||||
mCpuTexture[aChannelIndex], mappedSubresource)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aPlaneInfo.mSize = GetSize(aChannelIndex);
|
||||
aPlaneInfo.mStride = mappedSubresource.RowPitch;
|
||||
aPlaneInfo.mData = mappedSubresource.pData;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderDXGIYCbCrTextureHost::UnmapPlanes() {
|
||||
for (uint32_t i = 0; i < 3; i++) {
|
||||
if (mCpuTexture[i]) {
|
||||
mDeviceContext->Unmap(mCpuTexture[i], 0);
|
||||
mCpuTexture[i] = nullptr;
|
||||
}
|
||||
}
|
||||
mDeviceContext = nullptr;
|
||||
}
|
||||
|
||||
RenderDXGIYCbCrTextureHost::~RenderDXGIYCbCrTextureHost() {
|
||||
MOZ_COUNT_DTOR_INHERITED(RenderDXGIYCbCrTextureHost, RenderTextureHost);
|
||||
DeleteTextureHandle();
|
||||
|
@ -378,27 +508,7 @@ bool RenderDXGIYCbCrTextureHost::EnsureLockable(wr::ImageRendering aRendering) {
|
|||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
// Get the R8 D3D11 texture from shared handle.
|
||||
HRESULT hr = device->OpenSharedResource(
|
||||
(HANDLE)mHandles[i], __uuidof(ID3D11Texture2D),
|
||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mTextures[i]));
|
||||
if (FAILED(hr)) {
|
||||
NS_WARNING(
|
||||
"RenderDXGIYCbCrTextureHost::EnsureLockable(): Failed to open "
|
||||
"shared "
|
||||
"texture");
|
||||
gfxCriticalNote
|
||||
<< "RenderDXGIYCbCrTextureHost Failed to open shared texture, hr="
|
||||
<< gfx::hexa(hr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
mTextures[i]->QueryInterface(
|
||||
(IDXGIKeyedMutex**)getter_AddRefs(mKeyedMutexs[i]));
|
||||
}
|
||||
EnsureD3D11Texture2D(device);
|
||||
|
||||
mGL->fGenTextures(3, mTextureHandles);
|
||||
bool ok = true;
|
||||
|
@ -434,6 +544,49 @@ bool RenderDXGIYCbCrTextureHost::EnsureLockable(wr::ImageRendering aRendering) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool RenderDXGIYCbCrTextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
// Get the R8 D3D11 texture from shared handle.
|
||||
HRESULT hr = aDevice->OpenSharedResource(
|
||||
(HANDLE)mHandles[i], __uuidof(ID3D11Texture2D),
|
||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mTextures[i]));
|
||||
if (FAILED(hr)) {
|
||||
NS_WARNING(
|
||||
"RenderDXGIYCbCrTextureHost::EnsureLockable(): Failed to open "
|
||||
"shared "
|
||||
"texture");
|
||||
gfxCriticalNote
|
||||
<< "RenderDXGIYCbCrTextureHost Failed to open shared texture, hr="
|
||||
<< gfx::hexa(hr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
mTextures[i]->QueryInterface(
|
||||
(IDXGIKeyedMutex**)getter_AddRefs(mKeyedMutexs[i]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderDXGIYCbCrTextureHost::LockInternal() {
|
||||
if (!mLocked) {
|
||||
if (mKeyedMutexs[0]) {
|
||||
for (const auto& mutex : mKeyedMutexs) {
|
||||
HRESULT hr = mutex->AcquireSync(0, 10000);
|
||||
if (hr != S_OK) {
|
||||
gfxCriticalError()
|
||||
<< "RenderDXGIYCbCrTextureHost AcquireSync timeout, hr="
|
||||
<< gfx::hexa(hr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
mLocked = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
wr::WrExternalImage RenderDXGIYCbCrTextureHost::Lock(
|
||||
uint8_t aChannelIndex, gl::GLContext* aGL, wr::ImageRendering aRendering) {
|
||||
if (mGL.get() != aGL) {
|
||||
|
@ -454,19 +607,8 @@ wr::WrExternalImage RenderDXGIYCbCrTextureHost::Lock(
|
|||
return InvalidToWrExternalImage();
|
||||
}
|
||||
|
||||
if (!mLocked) {
|
||||
if (mKeyedMutexs[0]) {
|
||||
for (const auto& mutex : mKeyedMutexs) {
|
||||
HRESULT hr = mutex->AcquireSync(0, 10000);
|
||||
if (hr != S_OK) {
|
||||
gfxCriticalError()
|
||||
<< "RenderDXGIYCbCrTextureHost AcquireSync timeout, hr="
|
||||
<< gfx::hexa(hr);
|
||||
return InvalidToWrExternalImage();
|
||||
}
|
||||
}
|
||||
}
|
||||
mLocked = true;
|
||||
if (!LockInternal()) {
|
||||
return InvalidToWrExternalImage();
|
||||
}
|
||||
|
||||
gfx::IntSize size = GetSize(aChannelIndex);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define MOZILLA_GFX_RENDERD3D11TEXTUREHOST_H
|
||||
|
||||
#include "GLTypes.h"
|
||||
#include "RenderTextureHost.h"
|
||||
#include "RenderTextureHostSWGL.h"
|
||||
|
||||
struct ID3D11Texture2D;
|
||||
struct IDXGIKeyedMutex;
|
||||
|
@ -17,7 +17,7 @@ namespace mozilla {
|
|||
|
||||
namespace wr {
|
||||
|
||||
class RenderDXGITextureHost final : public RenderTextureHost {
|
||||
class RenderDXGITextureHost final : public RenderTextureHostSWGL {
|
||||
public:
|
||||
explicit RenderDXGITextureHost(WindowsHandle aHandle,
|
||||
gfx::SurfaceFormat aFormat,
|
||||
|
@ -37,14 +37,32 @@ class RenderDXGITextureHost final : public RenderTextureHost {
|
|||
|
||||
RenderDXGITextureHost* AsRenderDXGITextureHost() override { return this; }
|
||||
|
||||
gfx::SurfaceFormat GetFormat() const { return mFormat; }
|
||||
|
||||
gfx::YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
|
||||
|
||||
gfx::ColorRange GetColorRange() const { return mColorRange; }
|
||||
|
||||
ID3D11Texture2D* GetD3D11Texture2D();
|
||||
|
||||
// RenderTextureHostSWGL
|
||||
gfx::SurfaceFormat GetFormat() const override { return mFormat; }
|
||||
gfx::ColorDepth GetColorDepth() const override {
|
||||
if (mFormat == gfx::SurfaceFormat::P010) {
|
||||
return gfx::ColorDepth::COLOR_10;
|
||||
}
|
||||
if (mFormat == gfx::SurfaceFormat::P016) {
|
||||
return gfx::ColorDepth::COLOR_16;
|
||||
}
|
||||
return gfx::ColorDepth::COLOR_8;
|
||||
}
|
||||
size_t GetPlaneCount() const override;
|
||||
bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) override;
|
||||
void UnmapPlanes() override;
|
||||
gfx::YUVColorSpace GetYUVColorSpace() const override {
|
||||
return mYUVColorSpace;
|
||||
}
|
||||
|
||||
bool EnsureD3D11Texture2D(ID3D11Device* aDevice);
|
||||
bool LockInternal();
|
||||
|
||||
private:
|
||||
virtual ~RenderDXGITextureHost();
|
||||
|
||||
|
@ -59,6 +77,11 @@ class RenderDXGITextureHost final : public RenderTextureHost {
|
|||
RefPtr<ID3D11Texture2D> mTexture;
|
||||
RefPtr<IDXGIKeyedMutex> mKeyedMutex;
|
||||
|
||||
// Temporary state between MapPlane and UnmapPlanes.
|
||||
RefPtr<ID3D11DeviceContext> mDeviceContext;
|
||||
RefPtr<ID3D11Texture2D> mCpuTexture;
|
||||
D3D11_MAPPED_SUBRESOURCE mMappedSubresource;
|
||||
|
||||
EGLSurface mSurface;
|
||||
EGLStreamKHR mStream;
|
||||
|
||||
|
@ -74,9 +97,11 @@ class RenderDXGITextureHost final : public RenderTextureHost {
|
|||
bool mLocked;
|
||||
};
|
||||
|
||||
class RenderDXGIYCbCrTextureHost final : public RenderTextureHost {
|
||||
class RenderDXGIYCbCrTextureHost final : public RenderTextureHostSWGL {
|
||||
public:
|
||||
explicit RenderDXGIYCbCrTextureHost(WindowsHandle (&aHandles)[3],
|
||||
gfx::YUVColorSpace aYUVColorSpace,
|
||||
gfx::ColorDepth aColorDepth,
|
||||
gfx::IntSize aSizeY,
|
||||
gfx::IntSize aSizeCbCr);
|
||||
|
||||
|
@ -90,6 +115,22 @@ class RenderDXGIYCbCrTextureHost final : public RenderTextureHost {
|
|||
|
||||
bool SyncObjectNeeded() override { return true; }
|
||||
|
||||
// RenderTextureHostSWGL
|
||||
gfx::SurfaceFormat GetFormat() const override {
|
||||
return gfx::SurfaceFormat::YUV;
|
||||
}
|
||||
gfx::ColorDepth GetColorDepth() const override { return mColorDepth; }
|
||||
size_t GetPlaneCount() const override { return 3; }
|
||||
bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) override;
|
||||
void UnmapPlanes() override;
|
||||
gfx::YUVColorSpace GetYUVColorSpace() const override {
|
||||
return mYUVColorSpace;
|
||||
}
|
||||
|
||||
bool EnsureD3D11Texture2D(ID3D11Device* aDevice);
|
||||
bool LockInternal();
|
||||
|
||||
private:
|
||||
virtual ~RenderDXGIYCbCrTextureHost();
|
||||
|
||||
|
@ -109,6 +150,12 @@ class RenderDXGIYCbCrTextureHost final : public RenderTextureHost {
|
|||
// The gl handles for Y, Cb and Cr data.
|
||||
GLuint mTextureHandles[3];
|
||||
|
||||
// Temporary state between MapPlane and UnmapPlanes.
|
||||
RefPtr<ID3D11DeviceContext> mDeviceContext;
|
||||
RefPtr<ID3D11Texture2D> mCpuTexture[3];
|
||||
|
||||
gfx::YUVColorSpace mYUVColorSpace;
|
||||
gfx::ColorDepth mColorDepth;
|
||||
gfx::IntSize mSizeY;
|
||||
gfx::IntSize mSizeCbCr;
|
||||
|
||||
|
|
|
@ -145,7 +145,8 @@ gfx::YUVColorSpace RenderMacIOSurfaceTextureHost::GetYUVColorSpace() const {
|
|||
return mSurface->GetYUVColorSpace();
|
||||
}
|
||||
|
||||
bool RenderMacIOSurfaceTextureHost::MapPlane(uint8_t aChannelIndex,
|
||||
bool RenderMacIOSurfaceTextureHost::MapPlane(RenderCompositor* aCompositor,
|
||||
uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) {
|
||||
if (!aChannelIndex) {
|
||||
mSurface->Lock();
|
||||
|
|
|
@ -41,7 +41,8 @@ class RenderMacIOSurfaceTextureHost final : public RenderTextureHostSWGL {
|
|||
gfx::SurfaceFormat GetFormat() const override;
|
||||
gfx::ColorDepth GetColorDepth() const override;
|
||||
gfx::YUVColorSpace GetYUVColorSpace() const override;
|
||||
bool MapPlane(uint8_t aChannelIndex, PlaneInfo& aPlaneInfo) override;
|
||||
bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) override;
|
||||
void UnmapPlanes() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -34,7 +34,8 @@ gfx::ColorDepth RenderSharedSurfaceTextureHostSWGL::GetColorDepth() const {
|
|||
return gfx::ColorDepth::COLOR_8;
|
||||
}
|
||||
|
||||
bool RenderSharedSurfaceTextureHostSWGL::MapPlane(uint8_t aChannelIndex,
|
||||
bool RenderSharedSurfaceTextureHostSWGL::MapPlane(RenderCompositor* aCompositor,
|
||||
uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) {
|
||||
if (NS_WARN_IF(
|
||||
!mSurface->Map(gfx::DataSourceSurface::MapType::READ, &mMap))) {
|
||||
|
|
|
@ -32,7 +32,8 @@ class RenderSharedSurfaceTextureHostSWGL final : public RenderTextureHostSWGL {
|
|||
|
||||
gfx::ColorDepth GetColorDepth() const override;
|
||||
|
||||
bool MapPlane(uint8_t aChannelIndex, PlaneInfo& aPlaneInfo) override;
|
||||
bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) override;
|
||||
|
||||
void UnmapPlanes() override;
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ wr::WrExternalImage RenderTextureHost::Lock(uint8_t aChannelIndex,
|
|||
|
||||
wr::WrExternalImage RenderTextureHost::LockSWGL(uint8_t aChannelIndex,
|
||||
void* aContext,
|
||||
RenderCompositor* aCompositor,
|
||||
wr::ImageRendering aRendering) {
|
||||
return InvalidToWrExternalImage();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ class GLContext;
|
|||
|
||||
namespace wr {
|
||||
|
||||
class RenderCompositor;
|
||||
class RenderDXGITextureHost;
|
||||
class RenderMacIOSurfaceTextureHost;
|
||||
class RenderBufferTextureHost;
|
||||
|
@ -44,6 +45,7 @@ class RenderTextureHost {
|
|||
virtual void Unlock() {}
|
||||
|
||||
virtual wr::WrExternalImage LockSWGL(uint8_t aChannelIndex, void* aContext,
|
||||
RenderCompositor* aCompositor,
|
||||
wr::ImageRendering aRendering);
|
||||
|
||||
virtual void UnlockSWGL() {}
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
namespace mozilla {
|
||||
namespace wr {
|
||||
|
||||
bool RenderTextureHostSWGL::UpdatePlanes(wr::ImageRendering aRendering) {
|
||||
bool RenderTextureHostSWGL::UpdatePlanes(RenderCompositor* aCompositor,
|
||||
wr::ImageRendering aRendering) {
|
||||
wr_swgl_make_current(mContext);
|
||||
size_t planeCount = GetPlaneCount();
|
||||
bool filterUpdate = IsFilterUpdateNecessary(aRendering);
|
||||
|
@ -25,7 +26,7 @@ bool RenderTextureHostSWGL::UpdatePlanes(wr::ImageRendering aRendering) {
|
|||
gfx::ColorDepth colorDepth = GetColorDepth();
|
||||
for (size_t i = 0; i < planeCount; i++) {
|
||||
PlaneInfo& plane = mPlanes[i];
|
||||
if (!MapPlane(i, plane)) {
|
||||
if (!MapPlane(aCompositor, i, plane)) {
|
||||
if (i > 0) {
|
||||
UnmapPlanes();
|
||||
}
|
||||
|
@ -94,12 +95,13 @@ bool RenderTextureHostSWGL::SetContext(void* aContext) {
|
|||
}
|
||||
|
||||
wr::WrExternalImage RenderTextureHostSWGL::LockSWGL(
|
||||
uint8_t aChannelIndex, void* aContext, wr::ImageRendering aRendering) {
|
||||
uint8_t aChannelIndex, void* aContext, RenderCompositor* aCompositor,
|
||||
wr::ImageRendering aRendering) {
|
||||
if (!SetContext(aContext)) {
|
||||
return InvalidToWrExternalImage();
|
||||
}
|
||||
if (!mLocked) {
|
||||
if (!UpdatePlanes(aRendering)) {
|
||||
if (!UpdatePlanes(aCompositor, aRendering)) {
|
||||
return InvalidToWrExternalImage();
|
||||
}
|
||||
mLocked = true;
|
||||
|
@ -142,7 +144,7 @@ bool RenderTextureHostSWGL::LockSWGLCompositeSurface(
|
|||
return false;
|
||||
}
|
||||
if (!mLocked) {
|
||||
if (!UpdatePlanes(mCachedRendering)) {
|
||||
if (!UpdatePlanes(nullptr, mCachedRendering)) {
|
||||
return false;
|
||||
}
|
||||
mLocked = true;
|
||||
|
|
|
@ -17,6 +17,7 @@ class RenderTextureHostSWGL : public RenderTextureHost {
|
|||
RenderTextureHostSWGL() {}
|
||||
|
||||
wr::WrExternalImage LockSWGL(uint8_t aChannelIndex, void* aContext,
|
||||
RenderCompositor* aCompositor,
|
||||
wr::ImageRendering aRendering) override;
|
||||
|
||||
void UnlockSWGL() override;
|
||||
|
@ -25,9 +26,7 @@ class RenderTextureHostSWGL : public RenderTextureHost {
|
|||
|
||||
virtual size_t GetPlaneCount() const = 0;
|
||||
|
||||
virtual gfx::SurfaceFormat GetFormat() const {
|
||||
return gfx::SurfaceFormat::UNKNOWN;
|
||||
}
|
||||
virtual gfx::SurfaceFormat GetFormat() const = 0;
|
||||
|
||||
virtual gfx::ColorDepth GetColorDepth() const {
|
||||
return gfx::ColorDepth::UNKNOWN;
|
||||
|
@ -46,7 +45,8 @@ class RenderTextureHostSWGL : public RenderTextureHost {
|
|||
gfx::IntSize mSize;
|
||||
};
|
||||
|
||||
virtual bool MapPlane(uint8_t aChannelIndex, PlaneInfo& aPlaneInfo) = 0;
|
||||
virtual bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) = 0;
|
||||
|
||||
virtual void UnmapPlanes() = 0;
|
||||
|
||||
|
@ -64,7 +64,8 @@ class RenderTextureHostSWGL : public RenderTextureHost {
|
|||
|
||||
bool SetContext(void* aContext);
|
||||
|
||||
bool UpdatePlanes(wr::ImageRendering aRendering);
|
||||
bool UpdatePlanes(RenderCompositor* aCompositor,
|
||||
wr::ImageRendering aRendering);
|
||||
|
||||
void CleanupPlanes();
|
||||
|
||||
|
|
|
@ -109,10 +109,11 @@ gfx::YUVColorSpace RenderTextureHostWrapper::GetYUVColorSpace() const {
|
|||
return gfx::YUVColorSpace::UNKNOWN;
|
||||
}
|
||||
|
||||
bool RenderTextureHostWrapper::MapPlane(uint8_t aChannelIndex,
|
||||
bool RenderTextureHostWrapper::MapPlane(RenderCompositor* aCompositor,
|
||||
uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) {
|
||||
if (RenderTextureHostSWGL* swglHost = EnsureRenderTextureHostSWGL()) {
|
||||
return swglHost->MapPlane(aChannelIndex, aPlaneInfo);
|
||||
return swglHost->MapPlane(aCompositor, aChannelIndex, aPlaneInfo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ class RenderTextureHostWrapper final : public RenderTextureHostSWGL {
|
|||
gfx::SurfaceFormat GetFormat() const override;
|
||||
gfx::ColorDepth GetColorDepth() const override;
|
||||
gfx::YUVColorSpace GetYUVColorSpace() const override;
|
||||
bool MapPlane(uint8_t aChannelIndex, PlaneInfo& aPlaneInfo) override;
|
||||
bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex,
|
||||
PlaneInfo& aPlaneInfo) override;
|
||||
void UnmapPlanes() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -71,7 +71,8 @@ wr::WrExternalImage wr_renderer_lock_external_image(
|
|||
if (auto* gl = renderer->gl()) {
|
||||
return texture->Lock(aChannelIndex, gl, aRendering);
|
||||
} else if (auto* swgl = renderer->swgl()) {
|
||||
return texture->LockSWGL(aChannelIndex, swgl, aRendering);
|
||||
return texture->LockSWGL(aChannelIndex, swgl, renderer->GetCompositor(),
|
||||
aRendering);
|
||||
} else {
|
||||
gfxCriticalNoteOnce
|
||||
<< "No GL or SWGL context available to lock ExternalImage for extId:"
|
||||
|
|
|
@ -113,6 +113,8 @@ class RendererOGL {
|
|||
|
||||
RenderTextureHost* GetRenderTexture(wr::ExternalImageId aExternalImageId);
|
||||
|
||||
RenderCompositor* GetCompositor() { return mCompositor.get(); }
|
||||
|
||||
void AccumulateMemoryReport(MemoryReport* aReport);
|
||||
|
||||
void SetProfilerUI(const nsCString& aUI);
|
||||
|
|
Загрузка…
Ссылка в новой задаче