Go to file
Jonas Ådahl 7ddbcd1fd2 cogl/journal: Don't sometimes hold a ref on the framebuffer
d42f1873fc introduced a semi circular
reference between the CoglFramebuffer, and CoglJournal, where
CoglJournal would keep a reference on the CoglFramebuffer when there
were any entries in the journal log.

To avoid risking leaking these objects indefinitely, when freeing
objects without doing anything that triggered a flush, CoglFramebuffer
had a "filter" on cogl_object_unref() calls, which knew
about under what conditions CoglJournal had a reference to it. When it
could detect that there were only the journal itself holding such a
reference, it'd flush the journal, effectively releasing the reference
the journal held, thus freeing itself, as well as the journal.

When CoglFramebuffer was ported to be implemented using GObject instead
of CoglObject, this "filter" was missed, causing not only awkward but
infrequent leaks, but also situations where we'd flush journals when
only the journal itself held the last reference to the framebuffer,
meaning the journal would free the framebuffer, thus itself, in the
middle of flushing, causing memory corruption and crashes.

A way to detect this, by asserting on CoglObject reference count during
flush, is by adding the `g_assert()` as described below, which will
assert instead cause memory corruption.

void
_cogl_journal_flush (CoglJournal *journal
{
   ...
   _cogl_journal_discard (journal);
+  g_assert (journal->_parent.ref_count > 0);
   ...
}

Fix this by making CoglFramebuffer the owner of the journal, which it
already was, and remove any circle referencing that was there before, as
it is not needed given that the CoglFramebuffer pointer is guaranteed to
be valid for the lifetime of CoglJournal as the framebuffer is the owner
of the journal.

However, to not miss flushing before tearing down, which is important as
this flushes painting calls to the driver that is important for e.g.
using the result of those journal entries, flush the journal the first
time cogl_framebuffer_dispose() is called, before doing anything else.

This also adds a test case. Without having broken the circular
reference, the test would fail on g_assert_null (offscreen), as it would
have been "leaked" at this point, but the actual memory corruption would
be a result of the `cogl_texture_get_data()` call, which flushes the
framebuffer, and causes the 'mid-flush' destruction of the journal
described above. Note that the texture keeps track of dependent
framebuffers, but it does not hold any references to them.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1474
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1735>
2021-02-18 16:59:00 +00:00
.gitlab/issue_templates gitlab: Add missing < in markdown comment tag 2020-02-14 03:10:28 +00:00
.gitlab-ci ci: Install Xwayland from git 2021-01-25 15:14:35 +00:00
clutter clutter: Also pick on TOUCH_BEGIN events 2021-02-16 10:01:22 +01:00
cogl cogl/journal: Don't sometimes hold a ref on the framebuffer 2021-02-18 16:59:00 +00:00
data data: Updated exposed keybindings 2021-02-04 00:09:57 +01:00
doc Add MetaGravity and replace X11 equivalent with it 2020-02-29 21:01:50 +00:00
meson
po Update Catalan translation 2021-02-17 20:34:21 +01:00
src remote-desktop: Document NotifyPointerAxis() more explicit 2021-02-17 21:47:00 +01:00
subprojects build: bump ABI to sysprof-capture-4 2020-07-28 11:13:30 -07:00
tools
.gitignore build: bump ABI to sysprof-capture-4 2020-07-28 11:13:30 -07:00
.gitlab-ci.yml ci: Drop dependencies: stanzas 2021-02-10 09:52:56 +01:00
config.h.meson xwayland: Check for listenfd option 2021-01-22 11:40:30 +01:00
COPYING
meson_options.txt xwayland: Check X11 clients prior to terminate Xwayland 2021-01-18 17:52:22 +01:00
meson.build build: Bump pipewire dependency 2021-02-08 08:37:08 +00:00
mutter.doap mutter.doap: Add marge-bot as a maintainer 2020-11-16 11:59:45 +01:00
NEWS Tag release 40.alpha.1.1 2021-01-14 17:22:43 +01:00
README.md README: Elaborate coding style and commit message guidelines 2020-10-28 07:28:55 +00:00

Mutter

Mutter is a Wayland display server and X11 window manager and compositor library.

When used as a Wayland display server, it runs on top of KMS and libinput. It implements the compositor side of the Wayland core protocol as well as various protocol extensions. It also has functionality related to running X11 applications using Xwayland.

When used on top of Xorg it acts as a X11 window manager and compositing manager.

It contains functionality related to, among other things, window management, window compositing, focus tracking, workspace management, keybindings and monitor configuration.

Internally it uses a fork of Cogl, a hardware acceleration abstraction library used to simplify usage of OpenGL pipelines, as well as a fork af Clutter, a scene graph and user interface toolkit.

Mutter is used by, for example, GNOME Shell, the GNOME core user interface, and by Gala, elementary OS's window manager. It can also be run standalone, using the command "mutter", but just running plain mutter is only intended for debugging purposes.

Contributing

To contribute, open merge requests at https://gitlab.gnome.org/GNOME/mutter.

It can be useful to look at the documentation available at the Wiki.

Coding style and conventions

The coding style used is primarily the GNU flavor of the GNOME coding style with some additions:

  • Use regular C types and stdint.h types instead of GLib fundamental types, except for gboolean, and guint/gulong for GSource ids and signal handler ids. That means e.g. uint64_t instead of guint64, int instead of gint, unsigned int instead of guint if unsignedness is of importance, uint8_t instead of guchar, and so on.

  • Try to to limit line length to 80 characters, although it's not a strict limit.

  • Usage of g_autofree and g_autoptr are encouraged. The style used is

  g_autofree char *text = NULL;
  g_autoptr (MetaSomeThing) thing = NULL;

  text = g_strdup_printf ("The text: %d", a_number);
  thing = g_object_new (META_TYPE_SOME_THING,
                        "text", text,
                        NULL);
  thinger_use_thing (rocket, thing);
  • Declare variables at the top of the block they are used, but avoid non-trivial logic among variable declarations. Non-trivial logic can be getting a pointer that may be NULL, any kind of math, or anything that may have side effects.

  • Instead of boolean arguments in functions, prefer enums or flags when they're more expressive.

  • Use g_new0() etc instead of g_slice_new0().

  • Initialize and assign floating point variables (i.e. float or double) using the form floating_point = 3.14159 or ratio = 2.0.

Git messages

Commit messages should follow the GNOME commit message guidelines. We require an URL to either an issue or a merge request in each commit. Try to always prefix commit subjects with a relevant topic, such as compositor: or clutter/actor:, and it's always better to write too much in the commit message body than too little.

License

Mutter is distributed under the terms of the GNU General Public License, version 2 or later. See the COPYING file for detalis.