Bug 1740675 - Cleanup device handling around RenderThread r=nical,gfx-reviewers

RenderCompositorANGLE::ShutdownEGLLibraryIfNecessary() is not necessary since Bug 1656034 fix. Device reset handling could be more platform independent.

Differential Revision: https://phabricator.services.mozilla.com/D130960
This commit is contained in:
sotaro 2021-11-17 01:18:05 +00:00
Родитель d026785d01
Коммит 8ca63c894d
6 изменённых файлов: 35 добавлений и 71 удалений

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

@ -47,7 +47,7 @@ extern LazyLogModule gRenderThreadLog;
/* static */
UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError) {
const auto& gl = RenderThread::Get()->SingletonGL(aError);
RefPtr<gl::GLContext> gl = RenderThread::Get()->SingletonGL(aError);
if (!gl) {
if (aError.IsEmpty()) {
aError.Assign("RcANGLE(no shared GL)"_ns);
@ -58,7 +58,7 @@ UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
}
UniquePtr<RenderCompositorANGLE> compositor =
MakeUnique<RenderCompositorANGLE>(aWidget);
MakeUnique<RenderCompositorANGLE>(aWidget, std::move(gl));
if (!compositor->Initialize(aError)) {
return nullptr;
}
@ -66,8 +66,10 @@ UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
}
RenderCompositorANGLE::RenderCompositorANGLE(
const RefPtr<widget::CompositorWidget>& aWidget)
const RefPtr<widget::CompositorWidget>& aWidget,
RefPtr<gl::GLContext>&& aGL)
: RenderCompositor(aWidget),
mGL(aGL),
mEGLConfig(nullptr),
mEGLSurface(nullptr),
mUseTripleBuffering(false),
@ -76,6 +78,7 @@ RenderCompositorANGLE::RenderCompositorANGLE(
mUsePartialPresent(false),
mFullRender(false),
mDisablingNativeCompositor(false) {
MOZ_ASSERT(mGL);
LOG("RenderCompositorANGLE::RenderCompositorANGLE()");
}
@ -87,16 +90,7 @@ RenderCompositorANGLE::~RenderCompositorANGLE() {
}
ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay(nsACString& aError) {
const auto& gl = RenderThread::Get()->SingletonGL(aError);
if (!gl) {
if (aError.IsEmpty()) {
aError.Assign("RcANGLE(no shared GL in get device)"_ns);
} else {
aError.Append("(GetDevice)"_ns);
}
return nullptr;
}
const auto& gle = gl::GLContextEGL::Cast(gl);
const auto& gle = gl::GLContextEGL::Cast(mGL);
const auto& egl = gle->mEgl;
MOZ_ASSERT(egl);
if (!egl ||
@ -119,27 +113,6 @@ ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay(nsACString& aError) {
return device;
}
bool RenderCompositorANGLE::ShutdownEGLLibraryIfNecessary(nsACString& aError) {
const auto& displayDevice = GetDeviceOfEGLDisplay(aError);
RefPtr<ID3D11Device> device =
gfx::DeviceManagerDx::Get()->GetCompositorDevice();
// When DeviceReset is handled by GPUProcessManager/GPUParent,
// CompositorDevice is updated to a new device. EGLDisplay also needs to be
// updated, since EGLDisplay uses DeviceManagerDx::mCompositorDevice on ANGLE
// WebRender use case. EGLDisplay could be updated when Renderer count becomes
// 0. It is ensured by GPUProcessManager during handling DeviceReset.
// GPUChild::RecvNotifyDeviceReset() destroys all CompositorSessions before
// re-creating them.
if ((!displayDevice || device.get() != displayDevice) &&
RenderThread::Get()->RendererCount() == 0) {
// Shutdown GLLibraryEGL for updating EGLDisplay.
RenderThread::Get()->ClearSingletonGL();
}
return true;
}
bool RenderCompositorANGLE::Initialize(nsACString& aError) {
// TODO(aosmond): This causes us to lose WebRender because it is unable to
// distinguish why we failed and retry once the reset is complete. This does
@ -150,27 +123,12 @@ bool RenderCompositorANGLE::Initialize(nsACString& aError) {
return false;
}
// Update device if necessary.
if (!ShutdownEGLLibraryIfNecessary(aError)) {
aError.Append("(Shutdown EGL)"_ns);
return false;
}
const auto gl = RenderThread::Get()->SingletonGL(aError);
if (!gl) {
if (aError.IsEmpty()) {
aError.Assign("RcANGLE(no shared GL post maybe shutdown)"_ns);
} else {
aError.Append("(Initialize)"_ns);
}
return false;
}
// Force enable alpha channel to make sure ANGLE use correct framebuffer
// formart
const auto& gle = gl::GLContextEGL::Cast(gl);
const auto& gle = gl::GLContextEGL::Cast(mGL);
const auto& egl = gle->mEgl;
if (!gl::CreateConfig(*egl, &mEGLConfig, /* bpp */ 32,
/* enableDepthBuffer */ false, gl->IsGLES())) {
/* enableDepthBuffer */ false, mGL->IsGLES())) {
aError.Assign("RcANGLE(create EGLConfig failed)"_ns);
return false;
}
@ -192,7 +150,7 @@ bool RenderCompositorANGLE::Initialize(nsACString& aError) {
if (gfx::gfxVars::UseWebRenderDCompWin()) {
HWND compositorHwnd = GetCompositorHwnd();
if (compositorHwnd) {
mDCLayerTree = DCLayerTree::Create(gl, mEGLConfig, mDevice, mCtx,
mDCLayerTree = DCLayerTree::Create(mGL, mEGLConfig, mDevice, mCtx,
compositorHwnd, aError);
if (!mDCLayerTree) {
return false;
@ -703,8 +661,7 @@ bool RenderCompositorANGLE::CreateEGLSurface() {
const auto buffer = reinterpret_cast<EGLClientBuffer>(backBuf.get());
const auto gl = RenderThread::Get()->SingletonGL();
const auto& gle = gl::GLContextEGL::Cast(gl);
const auto& gle = gl::GLContextEGL::Cast(mGL);
const auto& egl = gle->mEgl;
const EGLSurface surface = egl->fCreatePbufferFromClientBuffer(
LOCAL_EGL_D3D_TEXTURE_ANGLE, buffer, mEGLConfig, pbuffer_attribs);

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

@ -36,7 +36,8 @@ class RenderCompositorANGLE : public RenderCompositor {
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
explicit RenderCompositorANGLE(
const RefPtr<widget::CompositorWidget>& aWidget);
const RefPtr<widget::CompositorWidget>& aWidget,
RefPtr<gl::GLContext>&& aGL);
virtual ~RenderCompositorANGLE();
bool Initialize(nsACString& aError);
@ -49,9 +50,7 @@ class RenderCompositorANGLE : public RenderCompositor {
bool Resume() override;
void Update() override;
gl::GLContext* gl() const override {
return RenderThread::Get()->SingletonGL();
}
gl::GLContext* gl() const override { return mGL; }
bool MakeCurrent() override;
@ -124,11 +123,12 @@ class RenderCompositorANGLE : public RenderCompositor {
void CreateSwapChainForDCompIfPossible(IDXGIFactory2* aDXGIFactory2);
RefPtr<IDXGISwapChain1> CreateSwapChainForDComp(bool aUseTripleBuffering,
bool aUseAlpha);
bool ShutdownEGLLibraryIfNecessary(nsACString& aError);
RefPtr<ID3D11Query> GetD3D11Query();
void ReleaseNativeCompositorResources();
HWND GetCompositorHwnd();
RefPtr<gl::GLContext> mGL;
EGLConfig mEGLConfig;
EGLSurface mEGLSurface;

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

@ -41,11 +41,16 @@ UniquePtr<RenderCompositor> RenderCompositorEGL::Create(
if ((kIsWayland || kIsX11) && !gfx::gfxVars::UseEGL()) {
return nullptr;
}
if (!RenderThread::Get()->SingletonGL()) {
gfxCriticalNote << "Failed to get shared GL context";
RefPtr<gl::GLContext> gl = RenderThread::Get()->SingletonGL(aError);
if (!gl) {
if (aError.IsEmpty()) {
aError.Assign("RcANGLE(no shared GL)"_ns);
} else {
aError.Append("(Create)"_ns);
}
return nullptr;
}
return MakeUnique<RenderCompositorEGL>(aWidget);
return MakeUnique<RenderCompositorEGL>(aWidget, std::move(gl));
}
EGLSurface RenderCompositorEGL::CreateEGLSurface() {
@ -59,8 +64,10 @@ EGLSurface RenderCompositorEGL::CreateEGLSurface() {
}
RenderCompositorEGL::RenderCompositorEGL(
const RefPtr<widget::CompositorWidget>& aWidget)
: RenderCompositor(aWidget), mEGLSurface(EGL_NO_SURFACE) {
const RefPtr<widget::CompositorWidget>& aWidget,
RefPtr<gl::GLContext>&& aGL)
: RenderCompositor(aWidget), mGL(aGL), mEGLSurface(EGL_NO_SURFACE) {
MOZ_ASSERT(mGL);
LOG("RenderCompositorEGL::RenderCompositorEGL()");
}
@ -204,10 +211,6 @@ bool RenderCompositorEGL::Resume() {
bool RenderCompositorEGL::IsPaused() { return mEGLSurface == EGL_NO_SURFACE; }
gl::GLContext* RenderCompositorEGL::gl() const {
return RenderThread::Get()->SingletonGL();
}
bool RenderCompositorEGL::MakeCurrent() {
const auto& gle = gl::GLContextEGL::Cast(gl());

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

@ -19,7 +19,8 @@ class RenderCompositorEGL : public RenderCompositor {
static UniquePtr<RenderCompositor> Create(
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
explicit RenderCompositorEGL(const RefPtr<widget::CompositorWidget>& aWidget);
explicit RenderCompositorEGL(const RefPtr<widget::CompositorWidget>& aWidget,
RefPtr<gl::GLContext>&& aGL);
virtual ~RenderCompositorEGL();
bool BeginFrame() override;
@ -28,7 +29,7 @@ class RenderCompositorEGL : public RenderCompositor {
bool Resume() override;
bool IsPaused() override;
gl::GLContext* gl() const override;
gl::GLContext* gl() const override { return mGL; }
bool MakeCurrent() override;
@ -52,6 +53,8 @@ class RenderCompositorEGL : public RenderCompositor {
void DestroyEGLSurface();
RefPtr<gl::GLContext> mGL;
EGLSurface mEGLSurface;
#ifdef MOZ_WIDGET_ANDROID
// On android we must track our own surface size.

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

@ -262,6 +262,7 @@ void RenderThread::RemoveRenderer(wr::WindowId aWindowId) {
mRenderers.erase(aWindowId);
if (mRenderers.empty()) {
ClearSingletonGL();
mHandlingDeviceReset = false;
mHandlingWebRenderError = false;
}
@ -864,6 +865,7 @@ void RenderThread::HandleDeviceReset(const char* aWhere, GLenum aReason) {
// All RenderCompositors will be destroyed by the GPUProcessManager in
// either OnRemoteProcessDeviceReset via the GPUChild, or
// OnInProcessDeviceReset here directly.
// On Windows, device will be re-created before sessions re-creation.
gfxCriticalNote << "GFX: RenderThread detected a device reset in "
<< aWhere;
if (XRE_IsGPUProcess()) {

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

@ -157,7 +157,6 @@ RenderedFrameId RendererOGL::UpdateAndRender(
// XXX This could cause oom in webrender since pending_texture_updates is
// not handled. It needs to be addressed.
return RenderedFrameId();
;
}
// XXX set clear color if MOZ_WIDGET_ANDROID is defined.