зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
d026785d01
Коммит
8ca63c894d
|
@ -47,7 +47,7 @@ extern LazyLogModule gRenderThreadLog;
|
||||||
/* static */
|
/* static */
|
||||||
UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
|
UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
|
||||||
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError) {
|
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 (!gl) {
|
||||||
if (aError.IsEmpty()) {
|
if (aError.IsEmpty()) {
|
||||||
aError.Assign("RcANGLE(no shared GL)"_ns);
|
aError.Assign("RcANGLE(no shared GL)"_ns);
|
||||||
|
@ -58,7 +58,7 @@ UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
|
||||||
}
|
}
|
||||||
|
|
||||||
UniquePtr<RenderCompositorANGLE> compositor =
|
UniquePtr<RenderCompositorANGLE> compositor =
|
||||||
MakeUnique<RenderCompositorANGLE>(aWidget);
|
MakeUnique<RenderCompositorANGLE>(aWidget, std::move(gl));
|
||||||
if (!compositor->Initialize(aError)) {
|
if (!compositor->Initialize(aError)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,10 @@ UniquePtr<RenderCompositor> RenderCompositorANGLE::Create(
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderCompositorANGLE::RenderCompositorANGLE(
|
RenderCompositorANGLE::RenderCompositorANGLE(
|
||||||
const RefPtr<widget::CompositorWidget>& aWidget)
|
const RefPtr<widget::CompositorWidget>& aWidget,
|
||||||
|
RefPtr<gl::GLContext>&& aGL)
|
||||||
: RenderCompositor(aWidget),
|
: RenderCompositor(aWidget),
|
||||||
|
mGL(aGL),
|
||||||
mEGLConfig(nullptr),
|
mEGLConfig(nullptr),
|
||||||
mEGLSurface(nullptr),
|
mEGLSurface(nullptr),
|
||||||
mUseTripleBuffering(false),
|
mUseTripleBuffering(false),
|
||||||
|
@ -76,6 +78,7 @@ RenderCompositorANGLE::RenderCompositorANGLE(
|
||||||
mUsePartialPresent(false),
|
mUsePartialPresent(false),
|
||||||
mFullRender(false),
|
mFullRender(false),
|
||||||
mDisablingNativeCompositor(false) {
|
mDisablingNativeCompositor(false) {
|
||||||
|
MOZ_ASSERT(mGL);
|
||||||
LOG("RenderCompositorANGLE::RenderCompositorANGLE()");
|
LOG("RenderCompositorANGLE::RenderCompositorANGLE()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,16 +90,7 @@ RenderCompositorANGLE::~RenderCompositorANGLE() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay(nsACString& aError) {
|
ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay(nsACString& aError) {
|
||||||
const auto& gl = RenderThread::Get()->SingletonGL(aError);
|
const auto& gle = gl::GLContextEGL::Cast(mGL);
|
||||||
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& egl = gle->mEgl;
|
const auto& egl = gle->mEgl;
|
||||||
MOZ_ASSERT(egl);
|
MOZ_ASSERT(egl);
|
||||||
if (!egl ||
|
if (!egl ||
|
||||||
|
@ -119,27 +113,6 @@ ID3D11Device* RenderCompositorANGLE::GetDeviceOfEGLDisplay(nsACString& aError) {
|
||||||
return device;
|
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) {
|
bool RenderCompositorANGLE::Initialize(nsACString& aError) {
|
||||||
// TODO(aosmond): This causes us to lose WebRender because it is unable to
|
// 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
|
// distinguish why we failed and retry once the reset is complete. This does
|
||||||
|
@ -150,27 +123,12 @@ bool RenderCompositorANGLE::Initialize(nsACString& aError) {
|
||||||
return false;
|
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
|
// Force enable alpha channel to make sure ANGLE use correct framebuffer
|
||||||
// formart
|
// formart
|
||||||
const auto& gle = gl::GLContextEGL::Cast(gl);
|
const auto& gle = gl::GLContextEGL::Cast(mGL);
|
||||||
const auto& egl = gle->mEgl;
|
const auto& egl = gle->mEgl;
|
||||||
if (!gl::CreateConfig(*egl, &mEGLConfig, /* bpp */ 32,
|
if (!gl::CreateConfig(*egl, &mEGLConfig, /* bpp */ 32,
|
||||||
/* enableDepthBuffer */ false, gl->IsGLES())) {
|
/* enableDepthBuffer */ false, mGL->IsGLES())) {
|
||||||
aError.Assign("RcANGLE(create EGLConfig failed)"_ns);
|
aError.Assign("RcANGLE(create EGLConfig failed)"_ns);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +150,7 @@ bool RenderCompositorANGLE::Initialize(nsACString& aError) {
|
||||||
if (gfx::gfxVars::UseWebRenderDCompWin()) {
|
if (gfx::gfxVars::UseWebRenderDCompWin()) {
|
||||||
HWND compositorHwnd = GetCompositorHwnd();
|
HWND compositorHwnd = GetCompositorHwnd();
|
||||||
if (compositorHwnd) {
|
if (compositorHwnd) {
|
||||||
mDCLayerTree = DCLayerTree::Create(gl, mEGLConfig, mDevice, mCtx,
|
mDCLayerTree = DCLayerTree::Create(mGL, mEGLConfig, mDevice, mCtx,
|
||||||
compositorHwnd, aError);
|
compositorHwnd, aError);
|
||||||
if (!mDCLayerTree) {
|
if (!mDCLayerTree) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -703,8 +661,7 @@ bool RenderCompositorANGLE::CreateEGLSurface() {
|
||||||
|
|
||||||
const auto buffer = reinterpret_cast<EGLClientBuffer>(backBuf.get());
|
const auto buffer = reinterpret_cast<EGLClientBuffer>(backBuf.get());
|
||||||
|
|
||||||
const auto gl = RenderThread::Get()->SingletonGL();
|
const auto& gle = gl::GLContextEGL::Cast(mGL);
|
||||||
const auto& gle = gl::GLContextEGL::Cast(gl);
|
|
||||||
const auto& egl = gle->mEgl;
|
const auto& egl = gle->mEgl;
|
||||||
const EGLSurface surface = egl->fCreatePbufferFromClientBuffer(
|
const EGLSurface surface = egl->fCreatePbufferFromClientBuffer(
|
||||||
LOCAL_EGL_D3D_TEXTURE_ANGLE, buffer, mEGLConfig, pbuffer_attribs);
|
LOCAL_EGL_D3D_TEXTURE_ANGLE, buffer, mEGLConfig, pbuffer_attribs);
|
||||||
|
|
|
@ -36,7 +36,8 @@ class RenderCompositorANGLE : public RenderCompositor {
|
||||||
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
|
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
|
||||||
|
|
||||||
explicit RenderCompositorANGLE(
|
explicit RenderCompositorANGLE(
|
||||||
const RefPtr<widget::CompositorWidget>& aWidget);
|
const RefPtr<widget::CompositorWidget>& aWidget,
|
||||||
|
RefPtr<gl::GLContext>&& aGL);
|
||||||
virtual ~RenderCompositorANGLE();
|
virtual ~RenderCompositorANGLE();
|
||||||
bool Initialize(nsACString& aError);
|
bool Initialize(nsACString& aError);
|
||||||
|
|
||||||
|
@ -49,9 +50,7 @@ class RenderCompositorANGLE : public RenderCompositor {
|
||||||
bool Resume() override;
|
bool Resume() override;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
gl::GLContext* gl() const override {
|
gl::GLContext* gl() const override { return mGL; }
|
||||||
return RenderThread::Get()->SingletonGL();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MakeCurrent() override;
|
bool MakeCurrent() override;
|
||||||
|
|
||||||
|
@ -124,11 +123,12 @@ class RenderCompositorANGLE : public RenderCompositor {
|
||||||
void CreateSwapChainForDCompIfPossible(IDXGIFactory2* aDXGIFactory2);
|
void CreateSwapChainForDCompIfPossible(IDXGIFactory2* aDXGIFactory2);
|
||||||
RefPtr<IDXGISwapChain1> CreateSwapChainForDComp(bool aUseTripleBuffering,
|
RefPtr<IDXGISwapChain1> CreateSwapChainForDComp(bool aUseTripleBuffering,
|
||||||
bool aUseAlpha);
|
bool aUseAlpha);
|
||||||
bool ShutdownEGLLibraryIfNecessary(nsACString& aError);
|
|
||||||
RefPtr<ID3D11Query> GetD3D11Query();
|
RefPtr<ID3D11Query> GetD3D11Query();
|
||||||
void ReleaseNativeCompositorResources();
|
void ReleaseNativeCompositorResources();
|
||||||
HWND GetCompositorHwnd();
|
HWND GetCompositorHwnd();
|
||||||
|
|
||||||
|
RefPtr<gl::GLContext> mGL;
|
||||||
|
|
||||||
EGLConfig mEGLConfig;
|
EGLConfig mEGLConfig;
|
||||||
EGLSurface mEGLSurface;
|
EGLSurface mEGLSurface;
|
||||||
|
|
||||||
|
|
|
@ -41,11 +41,16 @@ UniquePtr<RenderCompositor> RenderCompositorEGL::Create(
|
||||||
if ((kIsWayland || kIsX11) && !gfx::gfxVars::UseEGL()) {
|
if ((kIsWayland || kIsX11) && !gfx::gfxVars::UseEGL()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!RenderThread::Get()->SingletonGL()) {
|
RefPtr<gl::GLContext> gl = RenderThread::Get()->SingletonGL(aError);
|
||||||
gfxCriticalNote << "Failed to get shared GL context";
|
if (!gl) {
|
||||||
|
if (aError.IsEmpty()) {
|
||||||
|
aError.Assign("RcANGLE(no shared GL)"_ns);
|
||||||
|
} else {
|
||||||
|
aError.Append("(Create)"_ns);
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return MakeUnique<RenderCompositorEGL>(aWidget);
|
return MakeUnique<RenderCompositorEGL>(aWidget, std::move(gl));
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLSurface RenderCompositorEGL::CreateEGLSurface() {
|
EGLSurface RenderCompositorEGL::CreateEGLSurface() {
|
||||||
|
@ -59,8 +64,10 @@ EGLSurface RenderCompositorEGL::CreateEGLSurface() {
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderCompositorEGL::RenderCompositorEGL(
|
RenderCompositorEGL::RenderCompositorEGL(
|
||||||
const RefPtr<widget::CompositorWidget>& aWidget)
|
const RefPtr<widget::CompositorWidget>& aWidget,
|
||||||
: RenderCompositor(aWidget), mEGLSurface(EGL_NO_SURFACE) {
|
RefPtr<gl::GLContext>&& aGL)
|
||||||
|
: RenderCompositor(aWidget), mGL(aGL), mEGLSurface(EGL_NO_SURFACE) {
|
||||||
|
MOZ_ASSERT(mGL);
|
||||||
LOG("RenderCompositorEGL::RenderCompositorEGL()");
|
LOG("RenderCompositorEGL::RenderCompositorEGL()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,10 +211,6 @@ bool RenderCompositorEGL::Resume() {
|
||||||
|
|
||||||
bool RenderCompositorEGL::IsPaused() { return mEGLSurface == EGL_NO_SURFACE; }
|
bool RenderCompositorEGL::IsPaused() { return mEGLSurface == EGL_NO_SURFACE; }
|
||||||
|
|
||||||
gl::GLContext* RenderCompositorEGL::gl() const {
|
|
||||||
return RenderThread::Get()->SingletonGL();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RenderCompositorEGL::MakeCurrent() {
|
bool RenderCompositorEGL::MakeCurrent() {
|
||||||
const auto& gle = gl::GLContextEGL::Cast(gl());
|
const auto& gle = gl::GLContextEGL::Cast(gl());
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,8 @@ class RenderCompositorEGL : public RenderCompositor {
|
||||||
static UniquePtr<RenderCompositor> Create(
|
static UniquePtr<RenderCompositor> Create(
|
||||||
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
|
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();
|
virtual ~RenderCompositorEGL();
|
||||||
|
|
||||||
bool BeginFrame() override;
|
bool BeginFrame() override;
|
||||||
|
@ -28,7 +29,7 @@ class RenderCompositorEGL : public RenderCompositor {
|
||||||
bool Resume() override;
|
bool Resume() override;
|
||||||
bool IsPaused() override;
|
bool IsPaused() override;
|
||||||
|
|
||||||
gl::GLContext* gl() const override;
|
gl::GLContext* gl() const override { return mGL; }
|
||||||
|
|
||||||
bool MakeCurrent() override;
|
bool MakeCurrent() override;
|
||||||
|
|
||||||
|
@ -52,6 +53,8 @@ class RenderCompositorEGL : public RenderCompositor {
|
||||||
|
|
||||||
void DestroyEGLSurface();
|
void DestroyEGLSurface();
|
||||||
|
|
||||||
|
RefPtr<gl::GLContext> mGL;
|
||||||
|
|
||||||
EGLSurface mEGLSurface;
|
EGLSurface mEGLSurface;
|
||||||
#ifdef MOZ_WIDGET_ANDROID
|
#ifdef MOZ_WIDGET_ANDROID
|
||||||
// On android we must track our own surface size.
|
// On android we must track our own surface size.
|
||||||
|
|
|
@ -262,6 +262,7 @@ void RenderThread::RemoveRenderer(wr::WindowId aWindowId) {
|
||||||
mRenderers.erase(aWindowId);
|
mRenderers.erase(aWindowId);
|
||||||
|
|
||||||
if (mRenderers.empty()) {
|
if (mRenderers.empty()) {
|
||||||
|
ClearSingletonGL();
|
||||||
mHandlingDeviceReset = false;
|
mHandlingDeviceReset = false;
|
||||||
mHandlingWebRenderError = false;
|
mHandlingWebRenderError = false;
|
||||||
}
|
}
|
||||||
|
@ -864,6 +865,7 @@ void RenderThread::HandleDeviceReset(const char* aWhere, GLenum aReason) {
|
||||||
// All RenderCompositors will be destroyed by the GPUProcessManager in
|
// All RenderCompositors will be destroyed by the GPUProcessManager in
|
||||||
// either OnRemoteProcessDeviceReset via the GPUChild, or
|
// either OnRemoteProcessDeviceReset via the GPUChild, or
|
||||||
// OnInProcessDeviceReset here directly.
|
// OnInProcessDeviceReset here directly.
|
||||||
|
// On Windows, device will be re-created before sessions re-creation.
|
||||||
gfxCriticalNote << "GFX: RenderThread detected a device reset in "
|
gfxCriticalNote << "GFX: RenderThread detected a device reset in "
|
||||||
<< aWhere;
|
<< aWhere;
|
||||||
if (XRE_IsGPUProcess()) {
|
if (XRE_IsGPUProcess()) {
|
||||||
|
|
|
@ -157,7 +157,6 @@ RenderedFrameId RendererOGL::UpdateAndRender(
|
||||||
// XXX This could cause oom in webrender since pending_texture_updates is
|
// XXX This could cause oom in webrender since pending_texture_updates is
|
||||||
// not handled. It needs to be addressed.
|
// not handled. It needs to be addressed.
|
||||||
return RenderedFrameId();
|
return RenderedFrameId();
|
||||||
;
|
|
||||||
}
|
}
|
||||||
// XXX set clear color if MOZ_WIDGET_ANDROID is defined.
|
// XXX set clear color if MOZ_WIDGET_ANDROID is defined.
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче