Bug 1559681 - Repair device-reset handling in RenderCompositorANGLE. r=sotaro

Differential Revision: https://phabricator.services.mozilla.com/D35882

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jeff Gilbert 2019-06-26 06:03:23 +00:00
Родитель 0c725e58b7
Коммит 4ca782e561
2 изменённых файлов: 29 добавлений и 28 удалений

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

@ -38,11 +38,8 @@ UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
return nullptr; return nullptr;
} }
const auto& gle = gl::GLContextEGL::Cast(gl);
const auto& egl = gle->mEgl;
UniquePtr<RenderCompositorANGLE> compositor = UniquePtr<RenderCompositorANGLE> compositor =
MakeUnique<RenderCompositorANGLE>(std::move(aWidget), egl); MakeUnique<RenderCompositorANGLE>(std::move(aWidget));
if (!compositor->Initialize()) { if (!compositor->Initialize()) {
return nullptr; return nullptr;
} }
@ -50,14 +47,11 @@ UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
} }
RenderCompositorANGLE::RenderCompositorANGLE( RenderCompositorANGLE::RenderCompositorANGLE(
RefPtr<widget::CompositorWidget>&& aWidget, gl::GLLibraryEGL* const egl) RefPtr<widget::CompositorWidget>&& aWidget)
: RenderCompositor(std::move(aWidget)), : RenderCompositor(std::move(aWidget)),
mEgl(egl),
mEGLConfig(nullptr), mEGLConfig(nullptr),
mEGLSurface(nullptr), mEGLSurface(nullptr),
mUseTripleBuffering(false) { mUseTripleBuffering(false) {}
MOZ_ASSERT(mEgl);
}
RenderCompositorANGLE::~RenderCompositorANGLE() { RenderCompositorANGLE::~RenderCompositorANGLE() {
DestroyEGLSurface(); DestroyEGLSurface();
@ -65,20 +59,20 @@ RenderCompositorANGLE::~RenderCompositorANGLE() {
} }
ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay() { ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay() {
MOZ_ASSERT(mEgl); auto* egl = gl::GLLibraryEGL::Get();
if (!mEgl || MOZ_ASSERT(egl);
!mEgl->IsExtensionSupported(gl::GLLibraryEGL::EXT_device_query)) { if (!egl || !egl->IsExtensionSupported(gl::GLLibraryEGL::EXT_device_query)) {
return nullptr; return nullptr;
} }
// Fetch the D3D11 device. // Fetch the D3D11 device.
EGLDeviceEXT eglDevice = nullptr; EGLDeviceEXT eglDevice = nullptr;
mEgl->fQueryDisplayAttribEXT(mEgl->Display(), LOCAL_EGL_DEVICE_EXT, egl->fQueryDisplayAttribEXT(egl->Display(), LOCAL_EGL_DEVICE_EXT,
(EGLAttrib*)&eglDevice); (EGLAttrib*)&eglDevice);
MOZ_ASSERT(eglDevice); MOZ_ASSERT(eglDevice);
ID3D11Device* device = nullptr; ID3D11Device* device = nullptr;
mEgl->fQueryDeviceAttribEXT(eglDevice, LOCAL_EGL_D3D11_DEVICE_ANGLE, egl->fQueryDeviceAttribEXT(eglDevice, LOCAL_EGL_D3D11_DEVICE_ANGLE,
(EGLAttrib*)&device); (EGLAttrib*)&device);
if (!device) { if (!device) {
gfxCriticalNote << "Failed to get D3D11Device from EGLDisplay"; gfxCriticalNote << "Failed to get D3D11Device from EGLDisplay";
return nullptr; return nullptr;
@ -87,7 +81,8 @@ ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay() {
} }
bool RenderCompositorANGLE::SutdownEGLLibraryIfNecessary() { bool RenderCompositorANGLE::SutdownEGLLibraryIfNecessary() {
if (!mEgl) { const RefPtr<gl::GLLibraryEGL> egl = gl::GLLibraryEGL::Get();
if (!egl) {
// egl is not initialized yet; // egl is not initialized yet;
return true; return true;
} }
@ -105,7 +100,7 @@ bool RenderCompositorANGLE::SutdownEGLLibraryIfNecessary() {
RenderThread::Get()->RendererCount() == 0) { RenderThread::Get()->RendererCount() == 0) {
// Shutdown GLLibraryEGL for updating EGLDisplay. // Shutdown GLLibraryEGL for updating EGLDisplay.
RenderThread::Get()->ClearSharedGL(); RenderThread::Get()->ClearSharedGL();
mEgl->Shutdown(); egl->Shutdown();
} }
return true; return true;
} }
@ -120,7 +115,8 @@ bool RenderCompositorANGLE::Initialize() {
if (!SutdownEGLLibraryIfNecessary()) { if (!SutdownEGLLibraryIfNecessary()) {
return false; return false;
} }
if (!RenderThread::Get()->SharedGL()) { const auto gl = RenderThread::Get()->SharedGL();
if (!gl) {
gfxCriticalNote << "[WR] failed to get shared GL context."; gfxCriticalNote << "[WR] failed to get shared GL context.";
return false; return false;
} }
@ -231,7 +227,9 @@ bool RenderCompositorANGLE::Initialize() {
// Force enable alpha channel to make sure ANGLE use correct framebuffer // Force enable alpha channel to make sure ANGLE use correct framebuffer
// formart // formart
if (!gl::CreateConfig(mEgl, &mEGLConfig, /* bpp */ 32, const auto& gle = gl::GLContextEGL::Cast(gl);
const auto& egl = gle->mEgl;
if (!gl::CreateConfig(egl, &mEGLConfig, /* bpp */ 32,
/* enableDepthBuffer */ true)) { /* enableDepthBuffer */ true)) {
gfxCriticalNote << "Failed to create EGLConfig for WebRender"; gfxCriticalNote << "Failed to create EGLConfig for WebRender";
} }
@ -442,11 +440,14 @@ bool RenderCompositorANGLE::ResizeBufferIfNeeded() {
const auto buffer = reinterpret_cast<EGLClientBuffer>(backBuf.get()); const auto buffer = reinterpret_cast<EGLClientBuffer>(backBuf.get());
const EGLSurface surface = mEgl->fCreatePbufferFromClientBuffer( const auto gl = RenderThread::Get()->SharedGL();
mEgl->Display(), LOCAL_EGL_D3D_TEXTURE_ANGLE, buffer, mEGLConfig, const auto& gle = gl::GLContextEGL::Cast(gl);
const auto& egl = gle->mEgl;
const EGLSurface surface = egl->fCreatePbufferFromClientBuffer(
egl->Display(), LOCAL_EGL_D3D_TEXTURE_ANGLE, buffer, mEGLConfig,
pbuffer_attribs); pbuffer_attribs);
EGLint err = mEgl->fGetError(); EGLint err = egl->fGetError();
if (err != LOCAL_EGL_SUCCESS) { if (err != LOCAL_EGL_SUCCESS) {
gfxCriticalError() << "Failed to create Pbuffer of back buffer error: " gfxCriticalError() << "Failed to create Pbuffer of back buffer error: "
<< gfx::hexa(err) << " Size : " << size; << gfx::hexa(err) << " Size : " << size;
@ -462,8 +463,10 @@ bool RenderCompositorANGLE::ResizeBufferIfNeeded() {
void RenderCompositorANGLE::DestroyEGLSurface() { void RenderCompositorANGLE::DestroyEGLSurface() {
// Release EGLSurface of back buffer before calling ResizeBuffers(). // Release EGLSurface of back buffer before calling ResizeBuffers().
if (mEGLSurface) { if (mEGLSurface) {
gl::GLContextEGL::Cast(gl())->SetEGLSurfaceOverride(EGL_NO_SURFACE); const auto& gle = gl::GLContextEGL::Cast(gl());
mEgl->fDestroySurface(mEgl->Display(), mEGLSurface); const auto& egl = gle->mEgl;
gle->SetEGLSurfaceOverride(EGL_NO_SURFACE);
egl->fDestroySurface(egl->Display(), mEGLSurface);
mEGLSurface = nullptr; mEGLSurface = nullptr;
} }
} }

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

@ -35,8 +35,7 @@ class RenderCompositorANGLE : public RenderCompositor {
static UniquePtr<RenderCompositor> Create( static UniquePtr<RenderCompositor> Create(
RefPtr<widget::CompositorWidget>&& aWidget); RefPtr<widget::CompositorWidget>&& aWidget);
explicit RenderCompositorANGLE(RefPtr<widget::CompositorWidget>&& aWidget, explicit RenderCompositorANGLE(RefPtr<widget::CompositorWidget>&& aWidget);
gl::GLLibraryEGL*);
virtual ~RenderCompositorANGLE(); virtual ~RenderCompositorANGLE();
bool Initialize(); bool Initialize();
@ -68,7 +67,6 @@ class RenderCompositorANGLE : public RenderCompositor {
bool SutdownEGLLibraryIfNecessary(); bool SutdownEGLLibraryIfNecessary();
RefPtr<ID3D11Query> GetD3D11Query(); RefPtr<ID3D11Query> GetD3D11Query();
RefPtr<gl::GLLibraryEGL> mEgl;
EGLConfig mEGLConfig; EGLConfig mEGLConfig;
EGLSurface mEGLSurface; EGLSurface mEGLSurface;