[mutter/wip/frame-synchronization: 68/69] Send _NET_WM_FRAME_TIMINGS messages
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/frame-synchronization: 68/69] Send _NET_WM_FRAME_TIMINGS messages
- Date: Fri, 16 Nov 2012 19:13:06 +0000 (UTC)
commit f20d822dfeeb0432d79508814b12485a2bc8c6ee
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Mon Nov 12 14:11:08 2012 -0500
Send _NET_WM_FRAME_TIMINGS messages
We previously had timestamp information stubbed out in
_NET_WM_FRAME_DRAWN. Instead of this, add a high-resolution timestamp
in _NET_WM_FRAME_DRAWN then send a _NET_WM_FRAME_TIMINGS message
after when we have complete frame timing information, representing
the "presentation time" of the frame as an offset from the timestamp
in _NET_WM_FRAME_DRAWN.
To provide maximum space in the messages,_NET_WM_FRAME_DRAWN and
_NET_WM_FRAME_TIMINGS are not done as WM_PROTOCOLS messages but
have their own message types.
https://bugzilla.gnome.org/show_bug.cgi?id=685463
src/compositor/compositor-private.h | 3 +
src/compositor/compositor.c | 19 +++
src/compositor/meta-window-actor-private.h | 1 +
src/compositor/meta-window-actor.c | 174 +++++++++++++++++++++++++---
src/meta/atomnames.h | 1 +
5 files changed, 180 insertions(+), 18 deletions(-)
---
diff --git a/src/compositor/compositor-private.h b/src/compositor/compositor-private.h
index 80be123..07eaf14 100644
--- a/src/compositor/compositor-private.h
+++ b/src/compositor/compositor-private.h
@@ -46,6 +46,9 @@ struct _MetaCompScreen
GHashTable *windows_by_xid;
Window output;
+ CoglOnscreen *onscreen;
+ guint frame_timings_callback_id;
+
/* Used for unredirecting fullscreen windows */
guint disable_unredirect_count;
MetaWindowActor *unredirected_window;
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index 4a5e9db..2d062d4 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -1160,12 +1160,31 @@ meta_compositor_sync_screen_size (MetaCompositor *compositor,
}
static void
+frame_timings_callback (CoglOnscreen *onscreen,
+ gpointer user_data)
+{
+ MetaCompScreen *info = user_data;
+ GList *l;
+
+ for (l = info->windows; l; l = l->next)
+ meta_window_actor_check_frame_timings (l->data);
+}
+
+static void
pre_paint_windows (MetaCompScreen *info)
{
GList *l;
MetaWindowActor *top_window;
MetaWindowActor *expected_unredirected_window = NULL;
+ if (info->onscreen == NULL)
+ {
+ info->onscreen = COGL_ONSCREEN (cogl_get_draw_framebuffer ());
+ info->frame_timings_callback_id = cogl_onscreen_add_frame_timings_callback (info->onscreen,
+ frame_timings_callback,
+ info);
+ }
+
if (info->windows == NULL)
return;
diff --git a/src/compositor/meta-window-actor-private.h b/src/compositor/meta-window-actor-private.h
index 01f7aaa..de50511 100644
--- a/src/compositor/meta-window-actor-private.h
+++ b/src/compositor/meta-window-actor-private.h
@@ -29,6 +29,7 @@ void meta_window_actor_process_damage (MetaWindowActor *self,
void meta_window_actor_pre_paint (MetaWindowActor *self);
void meta_window_actor_post_paint (MetaWindowActor *self);
+void meta_window_actor_check_frame_timings (MetaWindowActor *self);
void meta_window_actor_invalidate_shadow (MetaWindowActor *self);
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index ca244a4..cc2867f 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -96,9 +96,8 @@ struct _MetaWindowActorPrivate
gint map_in_progress;
gint destroy_in_progress;
- /* If non-zero, the client needs to be sent a _NET_WM_FRAME_DRAWN
- * client message with this value */
- gint64 frame_drawn_serial;
+ /* List of FrameData for recent frames */
+ GList *frames;
guint visible : 1;
guint mapped : 1;
@@ -109,6 +108,10 @@ struct _MetaWindowActorPrivate
guint needs_damage_all : 1;
guint received_damage : 1;
+ /* If set, the client needs to be sent a _NET_WM_FRAME_DRAWN
+ * client message using the most recent frame in ->frames */
+ guint needs_frame_drawn : 1;
+
guint needs_pixmap : 1;
guint needs_reshape : 1;
guint recompute_focused_shadow : 1;
@@ -125,6 +128,16 @@ struct _MetaWindowActorPrivate
guint unredirected : 1;
};
+typedef struct _FrameData FrameData;
+
+struct _FrameData
+{
+ CoglOnscreen *onscreen;
+ int64_t frame_counter;
+ guint64 sync_request_serial;
+ gint64 frame_drawn_time;
+};
+
enum
{
PROP_META_WINDOW = 1,
@@ -155,6 +168,8 @@ static gboolean meta_window_actor_get_paint_volume (ClutterActor *actor,
static void meta_window_actor_detach (MetaWindowActor *self);
static gboolean meta_window_actor_has_shadow (MetaWindowActor *self);
+static void meta_window_actor_handle_updates (MetaWindowActor *self);
+
static void meta_window_actor_clear_shape_region (MetaWindowActor *self);
static void meta_window_actor_clear_bounding_region (MetaWindowActor *self);
static void meta_window_actor_clear_shadow_clip (MetaWindowActor *self);
@@ -162,6 +177,13 @@ static void meta_window_actor_clear_shadow_clip (MetaWindowActor *self);
G_DEFINE_TYPE (MetaWindowActor, meta_window_actor, CLUTTER_TYPE_GROUP);
static void
+frame_data_free (FrameData *frame)
+{
+ cogl_object_unref (frame->onscreen);
+ g_slice_free (FrameData, frame);
+}
+
+static void
meta_window_actor_class_init (MetaWindowActorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -695,7 +717,7 @@ meta_window_actor_get_paint_volume (ClutterActor *actor,
/* The paint volume is computed before paint functions are called
* so our bounds might not be updated yet. Force an update. */
- meta_window_actor_pre_paint (self);
+ meta_window_actor_handle_updates (self);
meta_window_actor_get_shape_bounds (self, &bounds);
@@ -962,14 +984,14 @@ meta_window_actor_thaw (MetaWindowActor *self)
/* We do this now since we might be going right back into the
* frozen state */
- meta_window_actor_pre_paint (self);
+ meta_window_actor_handle_updates (self);
/* Since we ignore damage events while a window is frozen for certain effects
* we may need to issue an update_area() covering the whole pixmap if we
* don't know what real damage has happened. */
if (self->priv->needs_damage_all)
meta_window_actor_damage_all (self);
- else if (self->priv->frame_drawn_serial != 0)
+ else if (self->priv->needs_frame_drawn != 0)
{
/* A frame was marked by the client without actually doing any damage;
* we need to make sure that the pre_paint/post_paint functions
@@ -2338,8 +2360,8 @@ meta_window_actor_update_shape (MetaWindowActor *self)
clutter_actor_queue_redraw (priv->actor);
}
-void
-meta_window_actor_pre_paint (MetaWindowActor *self)
+static void
+meta_window_actor_handle_updates (MetaWindowActor *self)
{
MetaWindowActorPrivate *priv = self->priv;
MetaScreen *screen = priv->screen;
@@ -2394,39 +2416,155 @@ meta_window_actor_pre_paint (MetaWindowActor *self)
if (priv->window->needs_frame_drawn)
{
- priv->frame_drawn_serial = priv->window->sync_request_serial;
+ FrameData *frame = g_slice_new0 (FrameData);
+
+ priv->needs_frame_drawn = TRUE;
+
+ frame->sync_request_serial = priv->window->sync_request_serial;
+
+ priv->frames = g_list_prepend (priv->frames, frame);
+
priv->window->needs_frame_drawn = FALSE;
}
}
void
+meta_window_actor_pre_paint (MetaWindowActor *self)
+{
+ MetaWindowActorPrivate *priv = self->priv;
+ GList *l;
+
+ meta_window_actor_handle_updates (self);
+
+ for (l = priv->frames; l != NULL; l = l->next)
+ {
+ FrameData *frame = l->data;
+
+ if (frame->onscreen == NULL)
+ {
+ CoglOnscreen *onscreen = COGL_ONSCREEN (cogl_get_draw_framebuffer());
+
+ frame->onscreen = cogl_object_ref (onscreen);
+ frame->frame_counter = cogl_onscreen_get_frame_counter (onscreen);
+ }
+ }
+}
+
+void
meta_window_actor_post_paint (MetaWindowActor *self)
{
MetaWindowActorPrivate *priv = self->priv;
- if (priv->frame_drawn_serial != 0)
+ if (priv->needs_frame_drawn)
{
MetaScreen *screen = priv->screen;
MetaDisplay *display = meta_screen_get_display (screen);
Display *xdisplay = meta_display_get_xdisplay (display);
- XClientMessageEvent ev;
+ XClientMessageEvent ev = { 0, };
+
+ FrameData *frame = priv->frames->data;
+
+ frame->frame_drawn_time = meta_compositor_monotonic_time_to_server_time (display,
+ g_get_monotonic_time ());
ev.type = ClientMessage;
ev.window = meta_window_get_xwindow (priv->window);
- ev.message_type = display->atom_WM_PROTOCOLS;
+ ev.message_type = display->atom__NET_WM_FRAME_DRAWN;
ev.format = 32;
- ev.data.l[0] = display->atom__NET_WM_FRAME_DRAWN;
- ev.data.l[1] = 0; /* timestamp */
- ev.data.l[2] = priv->frame_drawn_serial & G_GUINT64_CONSTANT(0xffffffff);
- ev.data.l[3] = priv->frame_drawn_serial >> 32;
- ev.data.l[4] = 0; /* vblank estimate */
+ ev.data.l[0] = frame->sync_request_serial >> 32;
+ ev.data.l[1] = frame->sync_request_serial & G_GUINT64_CONSTANT(0xffffffff);
+ ev.data.l[2] = frame->frame_drawn_time >> 32;
+ ev.data.l[3] = frame->frame_drawn_time & G_GUINT64_CONSTANT(0xffffffff);
meta_error_trap_push (display);
XSendEvent (xdisplay, ev.window, False, 0, (XEvent*) &ev);
+ XFlush (xdisplay);
meta_error_trap_pop (display);
- priv->frame_drawn_serial = 0;
+ priv->needs_frame_drawn = FALSE;
+
+ /* Now that we've sent out _NET_WM_FRAME_DRAWN, we might need to send
+ * _NET_WM_FRAME_TIMINGS */
+ meta_window_actor_check_frame_timings (self);
+ }
+}
+
+static void
+send_frame_timings (MetaWindowActor *self,
+ FrameData *frame,
+ CoglFrameTimings *frame_timings)
+{
+ MetaWindowActorPrivate *priv = self->priv;
+ MetaDisplay *display = meta_screen_get_display (priv->screen);
+ Display *xdisplay = meta_display_get_xdisplay (display);
+
+ XClientMessageEvent ev = { 0, };
+
+ ev.type = ClientMessage;
+ ev.window = meta_window_get_xwindow (priv->window);
+ ev.message_type = display->atom__NET_WM_FRAME_TIMINGS;
+ ev.format = 32;
+ ev.data.l[0] = frame->sync_request_serial >> 32;
+ ev.data.l[1] = frame->sync_request_serial & G_GUINT64_CONSTANT(0xffffffff);
+
+ if (frame_timings)
+ {
+ gint64 presentation_time = cogl_frame_timings_get_presentation_time (frame_timings);
+ gint64 refresh_interval = cogl_frame_timings_get_refresh_interval (frame_timings);
+
+ if (presentation_time != 0)
+ {
+ gint64 presentation_time_server = meta_compositor_monotonic_time_to_server_time (display,
+ presentation_time);
+ gint64 presentation_time_offset = presentation_time_server - frame->frame_drawn_time;
+ if (presentation_time_offset == 0)
+ presentation_time_offset = 1;
+
+ if ((gint32)presentation_time_offset == presentation_time_offset)
+ ev.data.l[2] = presentation_time_offset;
+ }
+
+ if (refresh_interval != 0 && (gint32)refresh_interval == refresh_interval)
+ {
+ ev.data.l[3] = refresh_interval;
+ }
+ }
+
+ meta_error_trap_push (display);
+ XSendEvent (xdisplay, ev.window, False, 0, (XEvent*) &ev);
+ XFlush (xdisplay);
+ meta_error_trap_pop (display);
+}
+
+void
+meta_window_actor_check_frame_timings (MetaWindowActor *self)
+{
+ MetaWindowActorPrivate *priv = self->priv;
+ GList *l;
+
+ for (l = priv->frames; l;)
+ {
+ GList *l_next = l->next;
+ FrameData *frame = l->data;
+ CoglFrameTimings *frame_timings;
+
+ if (frame->onscreen == NULL)
+ goto next;
+
+ frame_timings = cogl_onscreen_get_frame_timings (frame->onscreen,
+ frame->frame_counter);
+
+ if (frame->frame_drawn_time != 0 &&
+ (frame_timings == NULL || cogl_frame_timings_get_complete (frame_timings)))
+ {
+ priv->frames = g_list_delete_link (priv->frames, l);
+ send_frame_timings (self, frame, frame_timings);
+ frame_data_free (frame);
+ }
+
+ next:
+ l = l_next;
}
}
diff --git a/src/meta/atomnames.h b/src/meta/atomnames.h
index 35f85d4..06ae8d7 100644
--- a/src/meta/atomnames.h
+++ b/src/meta/atomnames.h
@@ -173,6 +173,7 @@ item(_NET_WM_STATE_STICKY)
item(_NET_WM_FULLSCREEN_MONITORS)
item(_NET_WM_STATE_FOCUSED)
item(_NET_WM_FRAME_DRAWN)
+item(_NET_WM_FRAME_TIMINGS)
#if 0
/* We apparently never use: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]