2020-03-03 02:46:11 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001 Havoc Pennington
|
|
|
|
* Copyright (C) 2005 Elijah Newren
|
|
|
|
* Copyright (C) 2020 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-03-03 03:32:33 -05:00
|
|
|
#include "compositor/meta-later-private.h"
|
|
|
|
|
2020-03-03 02:46:11 -05:00
|
|
|
#include "cogl/cogl.h"
|
2020-03-03 03:32:33 -05:00
|
|
|
#include "compositor/compositor-private.h"
|
|
|
|
#include "core/display-private.h"
|
|
|
|
#include "meta/meta-later.h"
|
2020-03-03 02:46:11 -05:00
|
|
|
|
|
|
|
typedef struct _MetaLater
|
|
|
|
{
|
|
|
|
unsigned int id;
|
|
|
|
unsigned int ref_count;
|
|
|
|
MetaLaterType when;
|
|
|
|
|
|
|
|
GSourceFunc func;
|
|
|
|
gpointer user_data;
|
|
|
|
GDestroyNotify destroy_notify;
|
|
|
|
|
|
|
|
guint source_id;
|
|
|
|
gboolean run_once;
|
|
|
|
} MetaLater;
|
|
|
|
|
|
|
|
#define META_LATER_N_TYPES (META_LATER_IDLE + 1)
|
|
|
|
|
|
|
|
struct _MetaLaters
|
|
|
|
{
|
2020-03-03 04:04:16 -05:00
|
|
|
MetaCompositor *compositor;
|
|
|
|
|
2020-03-03 02:46:11 -05:00
|
|
|
unsigned int last_later_id;
|
|
|
|
|
|
|
|
GSList *laters[META_LATER_N_TYPES];
|
|
|
|
|
2020-05-29 17:33:46 -04:00
|
|
|
gulong before_update_handler_id;
|
2020-03-03 02:46:11 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static MetaLater *
|
|
|
|
meta_later_ref (MetaLater *later)
|
|
|
|
{
|
|
|
|
later->ref_count++;
|
|
|
|
return later;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_later_unref (MetaLater *later)
|
|
|
|
{
|
|
|
|
if (--later->ref_count == 0)
|
|
|
|
{
|
|
|
|
if (later->destroy_notify)
|
|
|
|
{
|
|
|
|
later->destroy_notify (later->user_data);
|
|
|
|
later->destroy_notify = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slice_free (MetaLater, later);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_later_destroy (MetaLater *later)
|
|
|
|
{
|
|
|
|
g_clear_handle_id (&later->source_id, g_source_remove);
|
|
|
|
later->func = NULL;
|
|
|
|
meta_later_unref (later);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COGL_HAS_TRACING
|
|
|
|
static const char *
|
|
|
|
later_type_to_string (MetaLaterType when)
|
|
|
|
{
|
|
|
|
switch (when)
|
|
|
|
{
|
|
|
|
case META_LATER_RESIZE:
|
|
|
|
return "Later (resize)";
|
|
|
|
case META_LATER_CALC_SHOWING:
|
|
|
|
return "Later (calc-showing)";
|
|
|
|
case META_LATER_CHECK_FULLSCREEN:
|
|
|
|
return "Later (check-fullscreen)";
|
|
|
|
case META_LATER_SYNC_STACK:
|
|
|
|
return "Later (sync-stack)";
|
|
|
|
case META_LATER_BEFORE_REDRAW:
|
|
|
|
return "Later (before-redraw)";
|
|
|
|
case META_LATER_IDLE:
|
|
|
|
return "Later (idle)";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_later_invoke (MetaLater *later)
|
|
|
|
{
|
|
|
|
COGL_TRACE_BEGIN_SCOPED (later, later_type_to_string (later->when));
|
|
|
|
return later->func (later->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
remove_later_from_list (unsigned int later_id,
|
|
|
|
GSList **laters_list)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = *laters_list; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaLater *later = l->data;
|
|
|
|
|
|
|
|
if (later->id == later_id)
|
|
|
|
{
|
|
|
|
*laters_list = g_slist_delete_link (*laters_list, l);
|
|
|
|
meta_later_destroy (later);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_repaint_laters (GSList **laters_list)
|
|
|
|
{
|
|
|
|
g_autoptr (GSList) laters_copy = NULL;
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = *laters_list; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaLater *later = l->data;
|
|
|
|
|
|
|
|
if (!later->source_id ||
|
|
|
|
(later->when <= META_LATER_BEFORE_REDRAW && !later->run_once))
|
|
|
|
laters_copy = g_slist_prepend (laters_copy, meta_later_ref (later));
|
|
|
|
}
|
|
|
|
laters_copy = g_slist_reverse (laters_copy);
|
|
|
|
|
|
|
|
for (l = laters_copy; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaLater *later = l->data;
|
|
|
|
|
|
|
|
if (!later->func)
|
|
|
|
remove_later_from_list (later->id, laters_list);
|
|
|
|
else if (!meta_later_invoke (later))
|
|
|
|
remove_later_from_list (later->id, laters_list);
|
|
|
|
|
|
|
|
meta_later_unref (later);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 04:04:16 -05:00
|
|
|
static void
|
clutter: Paint views with individual frame clocks
Replace the default master clock with multiple frame clocks, each
driving its own stage view. As each stage view represents one CRTC, this
means we draw each CRTC with its own designated frame clock,
disconnected from all the others.
For example this means we when using the native backend will never need
to wait for one monitor to vsync before painting another, so e.g. having
a 144 Hz monitor next to a 60 Hz monitor, things including both Wayland
and X11 applications and shell UI will be able to render at the
corresponding monitor refresh rate.
This also changes a warning about missed frames when sending
_NETWM_FRAME_TIMINGS messages to a debug log entry, as it's expected
that we'll start missing frames e.g. when a X11 window (via Xwayland) is
exclusively within a stage view that was not painted, while another one
was, still increasing the global frame clock.
Addititonally, this also requires the X11 window actor to schedule
timeouts for _NET_WM_FRAME_DRAWN/_NET_WM_FRAME_TIMINGS event emitting,
if the actor wasn't on any stage views, as now we'll only get the frame
callbacks on actors when they actually were painted, while in the past,
we'd invoke that vfunc when anything was painted.
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/903
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
2020-05-29 18:27:56 -04:00
|
|
|
on_before_update (ClutterStage *stage,
|
|
|
|
ClutterStageView *stage_view,
|
|
|
|
MetaLaters *laters)
|
2020-03-03 02:46:11 -05:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
GSList *l;
|
2020-04-16 13:16:26 -04:00
|
|
|
gboolean needs_schedule_update = FALSE;
|
2020-03-03 02:46:11 -05:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (laters->laters); i++)
|
|
|
|
run_repaint_laters (&laters->laters[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (laters->laters); i++)
|
|
|
|
{
|
|
|
|
for (l = laters->laters[i]; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaLater *later = l->data;
|
|
|
|
|
|
|
|
if (!later->source_id)
|
2020-04-16 13:16:26 -04:00
|
|
|
needs_schedule_update = TRUE;
|
2020-03-03 02:46:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 13:16:26 -04:00
|
|
|
if (needs_schedule_update)
|
2020-05-29 17:33:46 -04:00
|
|
|
clutter_stage_schedule_update (stage);
|
2020-03-03 02:46:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
invoke_later_idle (gpointer data)
|
|
|
|
{
|
|
|
|
MetaLater *later = data;
|
|
|
|
|
|
|
|
if (!later->func (later->user_data))
|
|
|
|
{
|
|
|
|
meta_later_remove (later->id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
later->run_once = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
meta_laters_add (MetaLaters *laters,
|
|
|
|
MetaLaterType when,
|
|
|
|
GSourceFunc func,
|
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
2020-04-16 13:16:26 -04:00
|
|
|
ClutterStage *stage = meta_compositor_get_stage (laters->compositor);
|
2020-03-03 02:46:11 -05:00
|
|
|
MetaLater *later = g_slice_new0 (MetaLater);
|
|
|
|
|
|
|
|
later->id = ++laters->last_later_id;
|
|
|
|
later->ref_count = 1;
|
|
|
|
later->when = when;
|
|
|
|
later->func = func;
|
|
|
|
later->user_data = user_data;
|
|
|
|
later->destroy_notify = notify;
|
|
|
|
|
|
|
|
laters->laters[when] = g_slist_prepend (laters->laters[when], later);
|
|
|
|
|
|
|
|
switch (when)
|
|
|
|
{
|
|
|
|
case META_LATER_RESIZE:
|
|
|
|
later->source_id = g_idle_add_full (META_PRIORITY_RESIZE,
|
|
|
|
invoke_later_idle,
|
|
|
|
later, NULL);
|
|
|
|
g_source_set_name_by_id (later->source_id, "[mutter] invoke_later_idle");
|
2020-04-16 13:16:26 -04:00
|
|
|
clutter_stage_schedule_update (stage);
|
2020-03-03 02:46:11 -05:00
|
|
|
break;
|
|
|
|
case META_LATER_CALC_SHOWING:
|
|
|
|
case META_LATER_CHECK_FULLSCREEN:
|
|
|
|
case META_LATER_SYNC_STACK:
|
|
|
|
case META_LATER_BEFORE_REDRAW:
|
2020-04-16 13:16:26 -04:00
|
|
|
clutter_stage_schedule_update (stage);
|
2020-03-03 02:46:11 -05:00
|
|
|
break;
|
|
|
|
case META_LATER_IDLE:
|
|
|
|
later->source_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
|
|
|
|
invoke_later_idle,
|
|
|
|
later, NULL);
|
|
|
|
g_source_set_name_by_id (later->source_id, "[mutter] invoke_later_idle");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return later->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_later_add:
|
|
|
|
* @when: enumeration value determining the phase at which to run the callback
|
|
|
|
* @func: callback to run later
|
|
|
|
* @data: data to pass to the callback
|
|
|
|
* @notify: function to call to destroy @data when it is no longer in use, or %NULL
|
|
|
|
*
|
|
|
|
* Sets up a callback to be called at some later time. @when determines the
|
|
|
|
* particular later occasion at which it is called. This is much like g_idle_add(),
|
|
|
|
* except that the functions interact properly with clutter event handling.
|
|
|
|
* If a "later" function is added from a clutter event handler, and is supposed
|
|
|
|
* to be run before the stage is redrawn, it will be run before that redraw
|
|
|
|
* of the stage, not the next one.
|
|
|
|
*
|
|
|
|
* Return value: an integer ID (guaranteed to be non-zero) that can be used
|
|
|
|
* to cancel the callback and prevent it from being run.
|
|
|
|
*/
|
|
|
|
unsigned int
|
|
|
|
meta_later_add (MetaLaterType when,
|
|
|
|
GSourceFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
2020-03-03 03:32:33 -05:00
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
MetaCompositor *compositor = display->compositor;
|
|
|
|
|
|
|
|
return meta_laters_add (meta_compositor_get_laters (compositor),
|
|
|
|
when, func, data, notify);
|
2020-03-03 02:46:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_laters_remove (MetaLaters *laters,
|
|
|
|
unsigned int later_id)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (laters->laters); i++)
|
|
|
|
{
|
|
|
|
if (remove_later_from_list (later_id, &laters->laters[i]))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* meta_later_remove:
|
|
|
|
* @later_id: the integer ID returned from meta_later_add()
|
|
|
|
*
|
|
|
|
* Removes a callback added with meta_later_add()
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_later_remove (unsigned int later_id)
|
|
|
|
{
|
2020-03-03 03:32:33 -05:00
|
|
|
MetaDisplay *display = meta_get_display ();
|
|
|
|
MetaCompositor *compositor = display->compositor;
|
|
|
|
|
|
|
|
if (!compositor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
meta_laters_remove (meta_compositor_get_laters (compositor), later_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaLaters *
|
2020-03-03 04:04:16 -05:00
|
|
|
meta_laters_new (MetaCompositor *compositor)
|
2020-03-03 03:32:33 -05:00
|
|
|
{
|
2020-05-29 17:33:46 -04:00
|
|
|
ClutterStage *stage = meta_compositor_get_stage (compositor);
|
2020-03-03 04:04:16 -05:00
|
|
|
MetaLaters *laters;
|
|
|
|
|
|
|
|
laters = g_new0 (MetaLaters, 1);
|
|
|
|
laters->compositor = compositor;
|
|
|
|
|
2020-05-29 17:33:46 -04:00
|
|
|
laters->before_update_handler_id =
|
|
|
|
g_signal_connect (stage, "before-update",
|
|
|
|
G_CALLBACK (on_before_update),
|
|
|
|
laters);
|
2020-03-03 04:04:16 -05:00
|
|
|
|
|
|
|
return laters;
|
2020-03-03 03:32:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_laters_free (MetaLaters *laters)
|
|
|
|
{
|
2020-05-29 17:33:46 -04:00
|
|
|
ClutterStage *stage = meta_compositor_get_stage (laters->compositor);
|
2020-03-03 03:32:33 -05:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (laters->laters); i++)
|
|
|
|
g_slist_free_full (laters->laters[i], (GDestroyNotify) meta_later_unref);
|
|
|
|
|
2020-05-29 17:33:46 -04:00
|
|
|
g_clear_signal_handler (&laters->before_update_handler_id, stage);
|
2020-03-03 03:32:33 -05:00
|
|
|
g_free (laters);
|
2020-03-03 02:46:11 -05:00
|
|
|
}
|