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:
JerryShih 2017-11-28 20:04:00 +08:00
Родитель f0fef8ac17
Коммит 81f7ebd06b
3 изменённых файлов: 52 добавлений и 79 удалений

Просмотреть файл

@ -73,6 +73,9 @@ static egl::Stream::GLTextureDescription getGLDescFromTex(ID3D11Texture2D* tex,
case DXGI_FORMAT_R8G8B8A8_UNORM:
ret.internalFormat = GL_RGBA8;
break;
case DXGI_FORMAT_B8G8R8A8_UNORM:
ret.internalFormat = GL_BGRA8_EXT;
break;
default:
*out_error = "Unsupported format";

Просмотреть файл

@ -1086,7 +1086,7 @@ DXGITextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
MOZ_ASSERT(aImageKeys.length() == 1);
wr::ImageDescriptor descriptor(GetSize(), GetFormat());
auto bufferType = wr::WrExternalImageBufferType::Texture2DHandle;
auto bufferType = wr::WrExternalImageBufferType::TextureExternalHandle;
(aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0);
break;
}

Просмотреть файл

@ -69,52 +69,9 @@ RenderDXGITextureHostOGL::EnsureLockable()
const auto& egl = &gl::sEGLLibrary;
if (mFormat != gfx::SurfaceFormat::NV12) {
// 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) {
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->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle[0]);
mGL->TexParams_SetClampNoMips(LOCAL_GL_TEXTURE_2D);
egl->fBindTexImage(egl->Display(), mSurface, LOCAL_EGL_BACK_BUFFER);
} else {
// The nv12 format.
// The eglCreatePbufferFromClientBuffer doesn't support nv12 format, so we
// use EGLStream to get the converted gl handle from d3d nv12 texture.
// 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;
@ -131,7 +88,7 @@ RenderDXGITextureHostOGL::EnsureLockable()
return false;
}
// Get the NV12 D3D11 texture from shared handle.
// Get the D3D11 texture from shared handle.
if (FAILED(device->OpenSharedResource((HANDLE)mHandle,
__uuidof(ID3D11Texture2D),
(void**)(ID3D11Texture2D**)getter_AddRefs(mTexture)))) {
@ -145,6 +102,19 @@ RenderDXGITextureHostOGL::EnsureLockable()
mStream = egl->fCreateStreamKHR(egl->Display(), nullptr);
MOZ_ASSERT(mStream);
if (mFormat != gfx::SurfaceFormat::NV12) {
// The non-nv12 format.
mGL->fGenTextures(1, mTextureHandle);
mGL->fActiveTexture(LOCAL_GL_TEXTURE0);
mGL->fBindTexture(LOCAL_GL_TEXTURE_EXTERNAL_OES, mTextureHandle[0]);
mGL->fTexParameteri(LOCAL_GL_TEXTURE_EXTERNAL_OES, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
MOZ_ALWAYS_TRUE(egl->fStreamConsumerGLTextureExternalAttribsNV(egl->Display(), mStream, nullptr));
MOZ_ALWAYS_TRUE(egl->fCreateStreamProducerD3DTextureNV12ANGLE(egl->Display(), mStream, nullptr));
} else {
// The nv12 format.
// Setup the NV12 stream consumer/producer.
EGLAttrib consumerAttributes[] = {
LOCAL_EGL_COLOR_BUFFER_TYPE,
@ -166,14 +136,14 @@ RenderDXGITextureHostOGL::EnsureLockable()
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->fCreateStreamProducerD3DTextureNV12ANGLE(egl->Display(), mStream, nullptr));
}
// Insert the NV12 texture.
// Insert the d3d texture.
MOZ_ALWAYS_TRUE(egl->fStreamPostD3DTextureNV12ANGLE(egl->Display(), mStream, (void*)mTexture.get(), nullptr));
// Now, we could get the NV12 gl handle from the stream.
// Now, we could get the gl handle from the stream.
egl->fStreamConsumerAcquireKHR(egl->Display(), mStream);
MOZ_ASSERT(egl->fGetError() == LOCAL_EGL_SUCCESS);
}
return true;
}
@ -326,7 +296,7 @@ RenderDXGIYCbCrTextureHostOGL::EnsureLockable()
if (FAILED(device->OpenSharedResource((HANDLE)mHandles[i],
__uuidof(ID3D11Texture2D),
(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;
}
}