Bug 1802977 [Linux] Release nsWindow referenced by GtkCompositorWidget from main thread by NS_ReleaseOnMainThread() r=aosmond default tip
authorstransky <stransky@redhat.com>
Wed, 30 Nov 2022 10:26:00 +0000
changeset 644128 9b463a0b6bfa9b2bbcd4c12590934977cc90aa9c
parent 644127 257b76dde705d2af06603b7d946f42be6c784257
push id40445
push usermlaza@mozilla.com
push dateWed, 30 Nov 2022 21:47:07 +0000
treeherdermozilla-central@9b463a0b6bfa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaosmond
bugs1802977
milestone109.0a1
first release with
nightly linux32
9b463a0b6bfa / 109.0a1 / 20221130214707 / files
nightly linux64
9b463a0b6bfa / 109.0a1 / 20221130214707 / files
nightly mac
9b463a0b6bfa / 109.0a1 / 20221130214707 / files
nightly win32
9b463a0b6bfa / 109.0a1 / 20221130214707 / files
nightly win64
9b463a0b6bfa / 109.0a1 / 20221130214707 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1802977 [Linux] Release nsWindow referenced by GtkCompositorWidget from main thread by NS_ReleaseOnMainThread() r=aosmond Differential Revision: https://phabricator.services.mozilla.com/D163330
widget/gtk/GtkCompositorWidget.cpp
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
--- a/widget/gtk/GtkCompositorWidget.cpp
+++ b/widget/gtk/GtkCompositorWidget.cpp
@@ -64,16 +64,18 @@ GtkCompositorWidget::GtkCompositorWidget
         (void*)mWidget.get(), (void*)mWidget, !!mIsRenderingSuspended);
   }
 #endif
 }
 
 GtkCompositorWidget::~GtkCompositorWidget() {
   LOG("GtkCompositorWidget::~GtkCompositorWidget [%p]\n", (void*)mWidget.get());
   DisableRendering();
+  RefPtr<nsIWidget> widget = mWidget.forget();
+  NS_ReleaseOnMainThread("GtkCompositorWidget::mWidget", widget.forget());
 }
 
 already_AddRefed<gfx::DrawTarget> GtkCompositorWidget::StartRemoteDrawing() {
   return nullptr;
 }
 void GtkCompositorWidget::EndRemoteDrawing() {}
 
 already_AddRefed<gfx::DrawTarget>
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -568,25 +568,19 @@ void nsWindow::DestroyChildWindows() {
     nsWindow* kid = get_window_for_gdk_window(child);
     if (kid) {
       kid->Destroy();
     }
   }
 }
 
 void nsWindow::Destroy() {
-  // Allow to call ~nsWindow from different thread (Compositor for instance)
-  // in case that nsWindow is already destroyed.
-  if (mIsDestroyed) {
-    return;
-  }
-
   MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
 
-  if (!mCreated) {
+  if (mIsDestroyed || !mCreated) {
     return;
   }
 
   LOG("nsWindow::Destroy\n");
 
   mIsDestroyed = true;
   mCreated = false;
 
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -621,17 +621,17 @@ class nsWindow final : public nsBaseWidg
   // threads.
   //
   // FIXME(emilio): GetTitlebarRect() reads other things that TSAN doesn't
   // catch because mDrawInTitlebar is false on automation ~always. We should
   // probably make GetTitlebarRect() simpler / properly thread-safe.
   mozilla::Atomic<bool, mozilla::Relaxed> mDrawInTitlebar{false};
 
   // Has this widget been destroyed yet?
-  mozilla::Atomic<bool> mIsDestroyed;
+  bool mIsDestroyed;
   // mIsShown tracks requested visible status from browser perspective, i.e.
   // if the window should be visible or now.
   bool mIsShown : 1;
   // mNeedsShow is set when browser requested to show this window but we failed
   // to do so for some reason (wrong window size for instance).
   // In such case we set mIsShown = true and mNeedsShow = true to indicate
   // that the window is not actually visible but we report to browser that
   // it is visible (mIsShown == true).