Skip to content

Commit

Permalink
Bug 1880323 [Linux] Don't destroy layer manager at DisableRendering()…
Browse files Browse the repository at this point in the history
… r=emilio

Right now we destroy layer managed when nsWindow becomes hidden.
It makes sure that window rendering queue is suspended and invalid wl_surface is not used any more.
But it's also expensive operation and we need to create layer manager again if the window becomes visible again.
It also introduces a regression it tab is reparented and remairing nsWindow is closed.
In such case rendering pipeline is deleted and reparented tab is empty as associated rendering resources are already freed.

In this patch we don't delete layer manager on window hide but rather keep that operation to nsWindow::Destroy() as we do before.
Instead force GL backend to create small fallback EGLSurface for hidden nsWindow and keep potential async rendering running
until the window is deleted.

Differential Revision: https://phabricator.services.mozilla.com/D202179
  • Loading branch information
stransky committed Feb 23, 2024
1 parent 3518bd0 commit e8f95a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
7 changes: 6 additions & 1 deletion widget/gtk/MozContainerWayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ bool moz_container_wayland_egl_window_set_size(MozContainer* container,
nsIntSize aSize, int aScale) {
MozContainerWayland* wl_container = &container->data.wl_container;
MutexAutoLock lock(wl_container->container_lock);

// We may be called after unmap so we're missing egl window completelly.
// In such case don't return false which would block compositor.
// We return true here and don't block flush WebRender queue.
// We'll be repainted if our window become visible again anyway.
if (!wl_container->eglwindow) {
return false;
return true;
}

if (wl_container->buffer_scale != aScale) {
Expand Down
36 changes: 28 additions & 8 deletions widget/gtk/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,6 @@ void nsWindow::Destroy() {

MozClearHandleID(mCompositorPauseTimeoutID, g_source_remove);

ClearTransparencyBitmap();

#ifdef MOZ_WAYLAND
// Shut down our local vsync source
if (mWaylandVsyncSource) {
Expand Down Expand Up @@ -613,9 +611,9 @@ void nsWindow::Destroy() {

ClearTransparencyBitmap();

// Ensure any resources assigned to the window get cleaned up first
// to avoid double-freeing.
DisableRendering();
DestroyLayerManager();

mSurfaceProvider.CleanupResources();

g_signal_handlers_disconnect_by_data(gtk_settings_get_default(), this);

Expand Down Expand Up @@ -9874,8 +9872,6 @@ void nsWindow::ClearRenderingQueue() {
void nsWindow::DisableRendering() {
LOG("nsWindow::DisableRendering()");

DestroyLayerManager();

if (mGdkWindow) {
if (mIMContext) {
mIMContext->SetGdkWindow(nullptr);
Expand All @@ -9884,7 +9880,31 @@ void nsWindow::DisableRendering() {
mGdkWindow = nullptr;
}

mSurfaceProvider.CleanupResources();
#ifdef MOZ_WAYLAND
// Widget is backed by OpenGL EGLSurface created over wl_surface
// owned by mContainer.
// RenderCompositorEGL::Resume() deletes recent EGLSurface based on
// wl_surface owned by mContainer and creates a new fallback EGLSurface.
// Then we can delete wl_surface in moz_container_wayland_unmap().
// We don't want to pause compositor as it may lead to whole
// browser freeze (Bug 1777664).
///
// We don't need to do such operation for SW backend as
// WindowSurfaceWaylandMB::Commit() gets wl_surface from
// MozContainer every commit.
if (moz_container_wayland_has_egl_window(mContainer) &&
mCompositorWidgetDelegate) {
if (CompositorBridgeChild* remoteRenderer = GetRemoteRenderer()) {
// Call DisableRendering() to make GtkCompositorWidget hidden.
// Then SendResume() will create fallback EGLSurface, see
// GLContextEGL::CreateEGLSurfaceForCompositorWidget().
mCompositorWidgetDelegate->DisableRendering();
remoteRenderer->SendResume();
mCompositorWidgetDelegate->EnableRendering(GetX11Window(),
GetShapedState());
}
}
#endif
}

// Apply workaround for Mutter compositor bug (mzbz#1777269).
Expand Down

0 comments on commit e8f95a5

Please sign in to comment.