Skip to content

Commit 3986a44

Browse files
committed
later: Make MetaCompositor the owner of the MetaLaters state
Since the order of destruction during MetaDisplay tear down is a bit unordered, there are pieces that try to destruct its compositing dependent pieces (i.e. queued MetaLater callbacks) after MetaCompositor has been cleaned up, meaning we need to put some slightly awkward NULL checks to avoid crashing. Original Mutter commit: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/798/diffs?commit_id=2e7d02f1ce8cb8eba15968c7facd815a7ce43080
1 parent 742bea3 commit 3986a44

File tree

7 files changed

+139
-37
lines changed

7 files changed

+139
-37
lines changed

src/compositor/compositor-private.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
/* Wait 2ms after vblank before starting to draw next frame */
1515
#define META_SYNC_DELAY 2
1616

17+
typedef struct _MetaLaters MetaLaters;
18+
1719
struct _MetaCompositorClass
1820
{
1921
GObjectClass parent_class;
@@ -73,6 +75,8 @@ ClutterStage * meta_compositor_get_stage (MetaCompositor *compositor);
7375

7476
gboolean meta_compositor_is_switching_workspace (MetaCompositor *compositor);
7577

78+
MetaLaters * meta_compositor_get_laters (MetaCompositor *compositor);
79+
7680
void meta_update_desklet_stacking (MetaCompositor *compositor);
7781

7882
static inline int64_t

src/compositor/compositor.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "backends/x11/meta-stage-x11.h"
6363
#include "clutter/clutter-muffin.h"
6464
#include "cogl/cogl.h"
65+
#include "compositor/meta-later-private.h"
6566
#include "compositor/meta-window-actor-x11.h"
6667
#include "compositor/meta-window-actor-private.h"
6768
#include "compositor/meta-window-group-private.h"
@@ -132,6 +133,8 @@ typedef struct _MetaCompositorPrivate
132133
int switch_workspace_in_progress;
133134

134135
MetaPluginManager *plugin_mgr;
136+
137+
MetaLaters *laters;
135138
} MetaCompositorPrivate;
136139

137140
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaCompositor, meta_compositor,
@@ -1401,6 +1404,8 @@ meta_compositor_init (MetaCompositor *compositor)
14011404
meta_post_paint_func,
14021405
compositor,
14031406
NULL);
1407+
1408+
priv->laters = meta_laters_new ();
14041409
}
14051410

14061411
static void
@@ -1410,6 +1415,8 @@ meta_compositor_dispose (GObject *object)
14101415
MetaCompositorPrivate *priv =
14111416
meta_compositor_get_instance_private (compositor);
14121417

1418+
g_clear_pointer (&priv->laters, meta_laters_free);
1419+
14131420
g_clear_signal_handler (&priv->stage_after_paint_id, priv->stage);
14141421
g_clear_signal_handler (&priv->stage_presented_id, priv->stage);
14151422

@@ -1745,6 +1752,15 @@ meta_compositor_is_switching_workspace (MetaCompositor *compositor)
17451752
return priv->switch_workspace_in_progress > 0;
17461753
}
17471754

1755+
MetaLaters *
1756+
meta_compositor_get_laters (MetaCompositor *compositor)
1757+
{
1758+
MetaCompositorPrivate *priv =
1759+
meta_compositor_get_instance_private (compositor);
1760+
1761+
return priv->laters;
1762+
}
1763+
17481764
/**
17491765
* meta_get_x11_background_actor_for_display:
17501766
* @display: a #MetaDisplay
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2020 Red Hat Inc.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation; either version 2 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef META_LATER_PRIVATE_H
19+
#define META_LATER_PRIVATE_H
20+
21+
typedef struct _MetaLaters MetaLaters;
22+
23+
MetaLaters * meta_laters_new (void);
24+
25+
void meta_laters_free (MetaLaters *laters);
26+
27+
#endif /* META_LATER_PRIVATE_H */

src/compositor/meta-later.c

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919

2020
#include "config.h"
2121

22+
#include "compositor/meta-later-private.h"
23+
2224
#include "cogl/cogl.h"
23-
#include "meta/util.h"
25+
#include "compositor/compositor-private.h"
26+
#include "core/display-private.h"
27+
#include "meta/meta-later.h"
2428

2529
typedef struct _MetaLater
2630
{
@@ -36,8 +40,6 @@ typedef struct _MetaLater
3640
gboolean run_once;
3741
} MetaLater;
3842

39-
typedef struct _MetaLaters MetaLaters;
40-
4143
#define META_LATER_N_TYPES (META_LATER_IDLE + 1)
4244

4345
struct _MetaLaters
@@ -50,8 +52,6 @@ struct _MetaLaters
5052
guint repaint_func;
5153
};
5254

53-
static MetaLaters _laters;
54-
5555
static MetaLater *
5656
meta_later_ref (MetaLater *later)
5757
{
@@ -292,7 +292,11 @@ meta_later_add (MetaLaterType when,
292292
gpointer data,
293293
GDestroyNotify notify)
294294
{
295-
return meta_laters_add (&_laters, when, func, data, notify);
295+
MetaDisplay *display = meta_get_display ();
296+
MetaCompositor *compositor = display->compositor;
297+
298+
return meta_laters_add (meta_compositor_get_laters (compositor),
299+
when, func, data, notify);
296300
}
297301

298302
static void
@@ -317,5 +321,31 @@ meta_laters_remove (MetaLaters *laters,
317321
void
318322
meta_later_remove (unsigned int later_id)
319323
{
320-
meta_laters_remove (&_laters, later_id);
324+
MetaDisplay *display = meta_get_display ();
325+
MetaCompositor *compositor = display->compositor;
326+
327+
if (!compositor)
328+
return;
329+
330+
meta_laters_remove (meta_compositor_get_laters (compositor), later_id);
331+
}
332+
333+
MetaLaters *
334+
meta_laters_new (void)
335+
{
336+
return g_new0 (MetaLaters, 1);
337+
}
338+
339+
void
340+
meta_laters_free (MetaLaters *laters)
341+
{
342+
unsigned int i;
343+
344+
for (i = 0; i < G_N_ELEMENTS (laters->laters); i++)
345+
g_slist_free_full (laters->laters[i], (GDestroyNotify) meta_later_unref);
346+
347+
g_clear_object (&laters->timeline);
348+
if (laters->repaint_func)
349+
clutter_threads_remove_repaint_func (laters->repaint_func);
350+
g_free (laters);
321351
}

src/meta/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ muffin_public_headers = [
1919
'meta-idle-monitor.h',
2020
'meta-inhibit-shortcuts-dialog.h',
2121
'meta-launch-context.h',
22+
'meta-later.h',
2223
'meta-monitor-manager.h',
2324
'meta-plugin.h',
2425
'meta-remote-access-controller.h',

src/meta/meta-later.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) 2001 Havoc Pennington
3+
* Copyright (C) 2005 Elijah Newren
4+
* Copyright (C) 2020 Red Hat Inc.
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License as
8+
* published by the Free Software Foundation; either version 2 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef META_LATER_H
21+
#define META_LATER_H
22+
23+
/**
24+
* MetaLaterType:
25+
* @META_LATER_RESIZE: call in a resize processing phase that is done
26+
* before GTK+ repainting (including window borders) is done.
27+
* @META_LATER_CALC_SHOWING: used by Mutter to compute which windows should be mapped
28+
* @META_LATER_CHECK_FULLSCREEN: used by Mutter to see if there's a fullscreen window
29+
* @META_LATER_SYNC_STACK: used by Mutter to send it's idea of the stacking order to the server
30+
* @META_LATER_BEFORE_REDRAW: call before the stage is redrawn
31+
* @META_LATER_IDLE: call at a very low priority (can be blocked
32+
* by running animations or redrawing applications)
33+
**/
34+
typedef enum
35+
{
36+
META_LATER_RESIZE,
37+
META_LATER_CALC_SHOWING,
38+
META_LATER_CHECK_FULLSCREEN,
39+
META_LATER_SYNC_STACK,
40+
META_LATER_BEFORE_REDRAW,
41+
META_LATER_IDLE
42+
} MetaLaterType;
43+
44+
META_EXPORT
45+
guint meta_later_add (MetaLaterType when,
46+
GSourceFunc func,
47+
gpointer data,
48+
GDestroyNotify notify);
49+
50+
META_EXPORT
51+
void meta_later_remove (guint later_id);
52+
53+
#endif /* META_LATER_H */

src/meta/util.h

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <glib-object.h>
2828

2929
#include <meta/common.h>
30+
#include <meta/meta-later.h>
3031

3132
META_EXPORT
3233
gboolean meta_is_verbose (void);
@@ -186,36 +187,6 @@ GPid meta_show_dialog (const char *type,
186187

187188
#endif /* !WITH_VERBOSE_MODE */
188189

189-
/**
190-
* MetaLaterType:
191-
* @META_LATER_RESIZE: call in a resize processing phase that is done
192-
* before GTK+ repainting (including window borders) is done.
193-
* @META_LATER_CALC_SHOWING: used by Mutter to compute which windows should be mapped
194-
* @META_LATER_CHECK_FULLSCREEN: used by Mutter to see if there's a fullscreen window
195-
* @META_LATER_SYNC_STACK: used by Mutter to send it's idea of the stacking order to the server
196-
* @META_LATER_BEFORE_REDRAW: call before the stage is redrawn
197-
* @META_LATER_IDLE: call at a very low priority (can be blocked
198-
* by running animations or redrawing applications)
199-
**/
200-
typedef enum
201-
{
202-
META_LATER_RESIZE,
203-
META_LATER_CALC_SHOWING,
204-
META_LATER_CHECK_FULLSCREEN,
205-
META_LATER_SYNC_STACK,
206-
META_LATER_BEFORE_REDRAW,
207-
META_LATER_IDLE
208-
} MetaLaterType;
209-
210-
META_EXPORT
211-
guint meta_later_add (MetaLaterType when,
212-
GSourceFunc func,
213-
gpointer data,
214-
GDestroyNotify notify);
215-
216-
META_EXPORT
217-
void meta_later_remove (guint later_id);
218-
219190
typedef enum
220191
{
221192
META_LOCALE_DIRECTION_LTR,

0 commit comments

Comments
 (0)