mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-10 09:19:28 +00:00
Bug 1415754 - try to use egl stream instead of CreatePbufferFromClientBuffer() for d3d rgb format texture. r=jgilbert
MozReview-Commit-ID: Bydbxtx3oGU
This commit is contained in:
parent
f0fef8ac17
commit
81f7ebd06b
@ -73,6 +73,9 @@ static egl::Stream::GLTextureDescription getGLDescFromTex(ID3D11Texture2D* tex,
|
|||||||
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
||||||
ret.internalFormat = GL_RGBA8;
|
ret.internalFormat = GL_RGBA8;
|
||||||
break;
|
break;
|
||||||
|
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
||||||
|
ret.internalFormat = GL_BGRA8_EXT;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
*out_error = "Unsupported format";
|
*out_error = "Unsupported format";
|
||||||
@ -119,7 +122,7 @@ egl::Error StreamProducerNV12::validateD3DNV12Texture(void *pointer, const egl::
|
|||||||
{
|
{
|
||||||
return egl::EglBadParameter() << errorText;
|
return egl::EglBadParameter() << errorText;
|
||||||
}
|
}
|
||||||
|
|
||||||
return egl::NoError();
|
return egl::NoError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1086,7 +1086,7 @@ DXGITextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
|
|||||||
MOZ_ASSERT(aImageKeys.length() == 1);
|
MOZ_ASSERT(aImageKeys.length() == 1);
|
||||||
|
|
||||||
wr::ImageDescriptor descriptor(GetSize(), GetFormat());
|
wr::ImageDescriptor descriptor(GetSize(), GetFormat());
|
||||||
auto bufferType = wr::WrExternalImageBufferType::Texture2DHandle;
|
auto bufferType = wr::WrExternalImageBufferType::TextureExternalHandle;
|
||||||
(aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0);
|
(aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -69,81 +69,51 @@ RenderDXGITextureHostOGL::EnsureLockable()
|
|||||||
|
|
||||||
const auto& egl = &gl::sEGLLibrary;
|
const auto& egl = &gl::sEGLLibrary;
|
||||||
|
|
||||||
|
// We use EGLStream to get the converted gl handle from d3d texture. The
|
||||||
|
// NV_stream_consumer_gltexture_yuv and ANGLE_stream_producer_d3d_texture_nv12
|
||||||
|
// could support nv12 and rgb d3d texture format.
|
||||||
|
if (!egl->IsExtensionSupported(gl::GLLibraryEGL::NV_stream_consumer_gltexture_yuv) ||
|
||||||
|
!egl->IsExtensionSupported(gl::GLLibraryEGL::ANGLE_stream_producer_d3d_texture_nv12)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the D3D11 device.
|
||||||
|
EGLDeviceEXT eglDevice = nullptr;
|
||||||
|
egl->fQueryDisplayAttribEXT(egl->Display(), LOCAL_EGL_DEVICE_EXT, (EGLAttrib*)&eglDevice);
|
||||||
|
MOZ_ASSERT(eglDevice);
|
||||||
|
ID3D11Device* device = nullptr;
|
||||||
|
egl->fQueryDeviceAttribEXT(eglDevice, LOCAL_EGL_D3D11_DEVICE_ANGLE, (EGLAttrib*)&device);
|
||||||
|
// There's a chance this might fail if we end up on d3d9 angle for some reason.
|
||||||
|
if (!device) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the D3D11 texture from shared handle.
|
||||||
|
if (FAILED(device->OpenSharedResource((HANDLE)mHandle,
|
||||||
|
__uuidof(ID3D11Texture2D),
|
||||||
|
(void**)(ID3D11Texture2D**)getter_AddRefs(mTexture)))) {
|
||||||
|
NS_WARNING("RenderDXGITextureHostOGL::Lock(): Failed to open shared texture");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mKeyedMutex));
|
||||||
|
|
||||||
|
// Create the EGLStream.
|
||||||
|
mStream = egl->fCreateStreamKHR(egl->Display(), nullptr);
|
||||||
|
MOZ_ASSERT(mStream);
|
||||||
|
|
||||||
if (mFormat != gfx::SurfaceFormat::NV12) {
|
if (mFormat != gfx::SurfaceFormat::NV12) {
|
||||||
// The non-nv12 format.
|
// The non-nv12 format.
|
||||||
// Use eglCreatePbufferFromClientBuffer get the gl handle from the d3d
|
|
||||||
// shared handle.
|
|
||||||
if (!egl->IsExtensionSupported(gl::GLLibraryEGL::ANGLE_d3d_share_handle_client_buffer)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mHandle) {
|
mGL->fGenTextures(1, mTextureHandle);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gl texture handle from shared handle.
|
|
||||||
EGLint pbufferAttributes[] = {
|
|
||||||
LOCAL_EGL_WIDTH, mSize.width,
|
|
||||||
LOCAL_EGL_HEIGHT, mSize.height,
|
|
||||||
LOCAL_EGL_TEXTURE_TARGET, LOCAL_EGL_TEXTURE_2D,
|
|
||||||
LOCAL_EGL_TEXTURE_FORMAT, GetEGLTextureFormat(mFormat),
|
|
||||||
LOCAL_EGL_MIPMAP_TEXTURE, LOCAL_EGL_FALSE,
|
|
||||||
LOCAL_EGL_NONE
|
|
||||||
};
|
|
||||||
mSurface = egl->fCreatePbufferFromClientBuffer(egl->Display(),
|
|
||||||
LOCAL_EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE,
|
|
||||||
reinterpret_cast<EGLClientBuffer>(mHandle),
|
|
||||||
gl::GLContextEGL::Cast(mGL.get())->mConfig,
|
|
||||||
pbufferAttributes);
|
|
||||||
if (!mSurface) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query the keyed-mutex.
|
|
||||||
egl->fQuerySurfacePointerANGLE(egl->Display(),
|
|
||||||
mSurface,
|
|
||||||
LOCAL_EGL_DXGI_KEYED_MUTEX_ANGLE,
|
|
||||||
(void**)getter_AddRefs(mKeyedMutex));
|
|
||||||
|
|
||||||
mGL->fGenTextures(1, &mTextureHandle[0]);
|
|
||||||
mGL->fActiveTexture(LOCAL_GL_TEXTURE0);
|
mGL->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||||
mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle[0]);
|
mGL->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL_OES, mTextureHandle[0]);
|
||||||
mGL->TexParams_SetClampNoMips(LOCAL_GL_TEXTURE_2D);
|
mGL->fTexParameteri(LOCAL_GL_TEXTURE_EXTERNAL_OES, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||||
egl->fBindTexImage(egl->Display(), mSurface, LOCAL_EGL_BACK_BUFFER);
|
|
||||||
|
MOZ_ALWAYS_TRUE(egl->fStreamConsumerGLTextureExternalAttribsNV(egl->Display(), mStream, nullptr));
|
||||||
|
MOZ_ALWAYS_TRUE(egl->fCreateStreamProducerD3DTextureNV12ANGLE(egl->Display(), mStream, nullptr));
|
||||||
} else {
|
} else {
|
||||||
// The nv12 format.
|
// The nv12 format.
|
||||||
// The eglCreatePbufferFromClientBuffer doesn't support nv12 format, so we
|
|
||||||
// use EGLStream to get the converted gl handle from d3d nv12 texture.
|
|
||||||
|
|
||||||
if (!egl->IsExtensionSupported(gl::GLLibraryEGL::NV_stream_consumer_gltexture_yuv) ||
|
|
||||||
!egl->IsExtensionSupported(gl::GLLibraryEGL::ANGLE_stream_producer_d3d_texture_nv12)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch the D3D11 device.
|
|
||||||
EGLDeviceEXT eglDevice = nullptr;
|
|
||||||
egl->fQueryDisplayAttribEXT(egl->Display(), LOCAL_EGL_DEVICE_EXT, (EGLAttrib*)&eglDevice);
|
|
||||||
MOZ_ASSERT(eglDevice);
|
|
||||||
ID3D11Device* device = nullptr;
|
|
||||||
egl->fQueryDeviceAttribEXT(eglDevice, LOCAL_EGL_D3D11_DEVICE_ANGLE, (EGLAttrib*)&device);
|
|
||||||
// There's a chance this might fail if we end up on d3d9 angle for some reason.
|
|
||||||
if (!device) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the NV12 D3D11 texture from shared handle.
|
|
||||||
if (FAILED(device->OpenSharedResource((HANDLE)mHandle,
|
|
||||||
__uuidof(ID3D11Texture2D),
|
|
||||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mTexture)))) {
|
|
||||||
NS_WARNING("RenderDXGITextureHostOGL::Lock(): Failed to open shared texture");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
mTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mKeyedMutex));
|
|
||||||
|
|
||||||
// Create the EGLStream.
|
|
||||||
mStream = egl->fCreateStreamKHR(egl->Display(), nullptr);
|
|
||||||
MOZ_ASSERT(mStream);
|
|
||||||
|
|
||||||
// Setup the NV12 stream consumer/producer.
|
// Setup the NV12 stream consumer/producer.
|
||||||
EGLAttrib consumerAttributes[] = {
|
EGLAttrib consumerAttributes[] = {
|
||||||
@ -166,15 +136,15 @@ RenderDXGITextureHostOGL::EnsureLockable()
|
|||||||
mGL->fTexParameteri(LOCAL_GL_TEXTURE_EXTERNAL_OES, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
mGL->fTexParameteri(LOCAL_GL_TEXTURE_EXTERNAL_OES, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||||
MOZ_ALWAYS_TRUE(egl->fStreamConsumerGLTextureExternalAttribsNV(egl->Display(), mStream, consumerAttributes));
|
MOZ_ALWAYS_TRUE(egl->fStreamConsumerGLTextureExternalAttribsNV(egl->Display(), mStream, consumerAttributes));
|
||||||
MOZ_ALWAYS_TRUE(egl->fCreateStreamProducerD3DTextureNV12ANGLE(egl->Display(), mStream, nullptr));
|
MOZ_ALWAYS_TRUE(egl->fCreateStreamProducerD3DTextureNV12ANGLE(egl->Display(), mStream, nullptr));
|
||||||
|
|
||||||
// Insert the NV12 texture.
|
|
||||||
MOZ_ALWAYS_TRUE(egl->fStreamPostD3DTextureNV12ANGLE(egl->Display(), mStream, (void*)mTexture.get(), nullptr));
|
|
||||||
|
|
||||||
// Now, we could get the NV12 gl handle from the stream.
|
|
||||||
egl->fStreamConsumerAcquireKHR(egl->Display(), mStream);
|
|
||||||
MOZ_ASSERT(egl->fGetError() == LOCAL_EGL_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert the d3d texture.
|
||||||
|
MOZ_ALWAYS_TRUE(egl->fStreamPostD3DTextureNV12ANGLE(egl->Display(), mStream, (void*)mTexture.get(), nullptr));
|
||||||
|
|
||||||
|
// Now, we could get the gl handle from the stream.
|
||||||
|
egl->fStreamConsumerAcquireKHR(egl->Display(), mStream);
|
||||||
|
MOZ_ASSERT(egl->fGetError() == LOCAL_EGL_SUCCESS);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +296,7 @@ RenderDXGIYCbCrTextureHostOGL::EnsureLockable()
|
|||||||
if (FAILED(device->OpenSharedResource((HANDLE)mHandles[i],
|
if (FAILED(device->OpenSharedResource((HANDLE)mHandles[i],
|
||||||
__uuidof(ID3D11Texture2D),
|
__uuidof(ID3D11Texture2D),
|
||||||
(void**)(ID3D11Texture2D**)getter_AddRefs(mTextures[i])))) {
|
(void**)(ID3D11Texture2D**)getter_AddRefs(mTextures[i])))) {
|
||||||
NS_WARNING("RenderDXGITextureHostOGL::Lock(): Failed to open shared texture");
|
NS_WARNING("RenderDXGIYCbCrTextureHostOGL::Lock(): Failed to open shared texture");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user