From 5c5510777ad6ca1ea7f8b379d8a66fb1ca19329d Mon Sep 17 00:00:00 2001 From: stransky Date: Thu, 14 Apr 2022 06:14:45 +0000 Subject: [PATCH] Bug 1764283 [Wayland] Don't commit to MozContainer when WindowSurfaceProvider internals are released r=emilio Differential Revision: https://phabricator.services.mozilla.com/D143602 --- widget/gtk/WindowSurfaceProvider.cpp | 46 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/widget/gtk/WindowSurfaceProvider.cpp b/widget/gtk/WindowSurfaceProvider.cpp index d7a1ca64e3e5..82d6ba3caacb 100644 --- a/widget/gtk/WindowSurfaceProvider.cpp +++ b/widget/gtk/WindowSurfaceProvider.cpp @@ -161,28 +161,36 @@ WindowSurfaceProvider::StartRemoteDrawingInRegion( void WindowSurfaceProvider::EndRemoteDrawingInRegion( gfx::DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) { -#if defined(MOZ_WAYLAND) - if (GdkIsWaylandDisplay() && moz_container_wayland_is_commiting_to_parent( - mWidget->GetMozContainer())) { - // If we're drawing directly to wl_surface owned by Gtk we need to use it - // in main thread to sync with Gtk access to it. - NS_DispatchToMainThread(NS_NewRunnableFunction( - "WindowSurfaceProvider::EndRemoteDrawingInRegion", - [RefPtr{mWidget}, this, aInvalidRegion]() { - MutexAutoLock lock(mMutex); - // Commit to mWindowSurface only when we have a valid one. - if (mWindowSurface && mWindowSurfaceValid) { - mWindowSurface->Commit(aInvalidRegion); - } - })); + MutexAutoLock lock(mMutex); + // Commit to mWindowSurface only if we have a valid one. + if (!mWindowSurface || !mWindowSurfaceValid) { return; } -#endif - MutexAutoLock lock(mMutex); - // Commit to mWindowSurface only when we have a valid one. - if (mWindowSurface && mWindowSurfaceValid) { - mWindowSurface->Commit(aInvalidRegion); +#if defined(MOZ_WAYLAND) + if (GdkIsWaylandDisplay()) { + // We're called too early or we're unmapped. + // Don't draw anything. + if (!mWidget) { + return; + } + if (moz_container_wayland_is_commiting_to_parent( + mWidget->GetMozContainer())) { + // If we're drawing directly to wl_surface owned by Gtk we need to use it + // in main thread to sync with Gtk access to it. + NS_DispatchToMainThread(NS_NewRunnableFunction( + "WindowSurfaceProvider::EndRemoteDrawingInRegion", + [RefPtr{mWidget}, this, aInvalidRegion]() { + MutexAutoLock lock(mMutex); + // Commit to mWindowSurface only when we have a valid one. + if (mWindowSurface && mWindowSurfaceValid) { + mWindowSurface->Commit(aInvalidRegion); + } + })); + return; + } } +#endif + mWindowSurface->Commit(aInvalidRegion); } } // namespace widget