Bug 1783195 [Linux] Implement MozClearHandleID to clean glib handle r=emilio
authorstransky <stransky@redhat.com>
Mon, 08 Aug 2022 17:52:20 +0000
changeset 626453 cf25d56f20db47723ffd9f20b7ec068a06e9c5a9
parent 626452 3e49696955b625d9bb910812278068849a7c829b
child 626454 fe8deaa2239718fe6095a37a4badc8081b9de7aa
push id167531
push userstransky@redhat.com
push dateMon, 08 Aug 2022 18:03:15 +0000
treeherderautoland@cf25d56f20db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1783195
milestone105.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1783195 [Linux] Implement MozClearHandleID to clean glib handle r=emilio Differential Revision: https://phabricator.services.mozilla.com/D153753
widget/gtk/nsGtkUtils.h
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
--- a/widget/gtk/nsGtkUtils.h
+++ b/widget/gtk/nsGtkUtils.h
@@ -43,9 +43,17 @@ template <class T>
 static inline void MozClearPointer(T*& pointer, void (*destroy)(T*)) {
   T* hold = pointer;
   pointer = nullptr;
   if (hold) {
     destroy(hold);
   }
 }
 
+template <class T>
+static inline void MozClearHandleID(T& handle, gboolean (*destroy)(T)) {
+  if (handle) {
+    destroy(handle);
+    handle = 0;
+  }
+}
+
 #endif  // nsGtkUtils_h__
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -557,20 +557,17 @@ void nsWindow::Destroy() {
 
   if (mIsDestroyed || !mCreated) return;
 
   LOG("nsWindow::Destroy\n");
 
   mIsDestroyed = true;
   mCreated = false;
 
-  if (mCompositorPauseTimeoutID) {
-    g_source_remove(mCompositorPauseTimeoutID);
-    mCompositorPauseTimeoutID = 0;
-  }
+  MozClearHandleID(mCompositorPauseTimeoutID, g_source_remove);
 
 #ifdef MOZ_WAYLAND
   // Shut down our local vsync source
   if (mWaylandVsyncSource) {
     mWaylandVsyncSource->Shutdown();
     mWaylandVsyncSource = nullptr;
   }
   mWaylandVsyncDispatcher = nullptr;
@@ -6108,20 +6105,17 @@ void nsWindow::PauseCompositorFlickering
                          mCompositorState == COMPOSITOR_ENABLED &&
                          mCompositorWidgetDelegate && !mIsDestroyed;
   if (!pauseCompositor) {
     return;
   }
 
   LOG("nsWindow::PauseCompositorFlickering()");
 
-  if (mCompositorPauseTimeoutID) {
-    g_source_remove(mCompositorPauseTimeoutID);
-    mCompositorPauseTimeoutID = 0;
-  }
+  MozClearHandleID(mCompositorPauseTimeoutID, g_source_remove);
 
   CompositorBridgeChild* remoteRenderer = GetRemoteRenderer();
   if (remoteRenderer) {
     remoteRenderer->SendPause();
     mCompositorState = COMPOSITOR_PAUSED_FLICKERING;
     mCompositorPauseTimeoutID = (int)g_timeout_add(
         COMPOSITOR_PAUSE_TIMEOUT,
         [](void* data) -> gint {
@@ -6144,20 +6138,17 @@ void nsWindow::ResumeCompositorFlickerin
 
   LOG("nsWindow::ResumeCompositorFlickering()\n");
 
   if (mIsDestroyed || !IsWaitingForCompositorResume()) {
     LOG("  early quit\n");
     return;
   }
 
-  if (mCompositorPauseTimeoutID) {
-    g_source_remove(mCompositorPauseTimeoutID);
-    mCompositorPauseTimeoutID = 0;
-  }
+  MozClearHandleID(mCompositorPauseTimeoutID, g_source_remove);
 
   ResumeCompositorImpl();
 }
 
 void nsWindow::ResumeCompositorFromCompositorThread() {
   nsCOMPtr<nsIRunnable> event =
       NewRunnableMethod("nsWindow::ResumeCompositorFlickering", this,
                         &nsWindow::ResumeCompositorFlickering);
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -520,17 +520,17 @@ class nsWindow final : public nsBaseWidg
   GtkWidget* mShell = nullptr;
   MozContainer* mContainer = nullptr;
   GdkWindow* mGdkWindow = nullptr;
   PlatformCompositorWidgetDelegate* mCompositorWidgetDelegate = nullptr;
   mozilla::Atomic<WindowCompositorState, mozilla::Relaxed> mCompositorState{
       COMPOSITOR_ENABLED};
   // This is used in COMPOSITOR_PAUSED_FLICKERING mode only to resume compositor
   // in some reasonable time when page content is not updated.
-  int mCompositorPauseTimeoutID = 0;
+  guint mCompositorPauseTimeoutID = 0;
 
   // The actual size mode that's in effect.
   nsSizeMode mSizeMode = nsSizeMode_Normal;
   nsSizeMode mLastSizeModeBeforeFullscreen = nsSizeMode_Normal;
 
   float mAspectRatio = 0.0f;
   float mAspectRatioSaved = 0.0f;