window: Move _NET_WM_SYNC_REQUEST and family to MetaWindowX11

The code to react to _NET_WM_SYNC_REQUEST and family (counter,
alarm, etc) currently lives in MetaWindow, even though most of
its management is done by MetaWindowX11.

In an ideal Wayland-as-default world, MetaWindow is completely
agnostic to the display server implementation, delegating to
MetaWindowX11 and MetaWindowWayland their respective display
server internals.

To help this goal, move the X11-specific code to deal with
_NET_WM_SYNC_REQUEST to MetaWindowX11.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/372
This commit is contained in:
Georges Basile Stavracas Neto
2018-12-22 17:27:32 -02:00
committed by Jonas Ådahl
parent f798912cbd
commit b4d55325d7
7 changed files with 199 additions and 111 deletions

View File

@@ -30,6 +30,7 @@
#include "meta/meta-x11-errors.h"
#include "meta/window.h"
#include "x11/meta-x11-display-private.h"
#include "x11/window-x11.h"
struct _MetaWindowActorX11
{
@@ -366,9 +367,12 @@ meta_window_actor_x11_queue_frame_drawn (MetaWindowActor *actor,
if (meta_window_actor_is_destroyed (actor))
return;
g_assert (META_IS_WINDOW_X11 (window));
frame = g_slice_new0 (FrameData);
frame->frame_counter = -1;
frame->sync_request_serial = window->sync_request_serial;
frame->sync_request_serial =
meta_window_x11_get_sync_request_serial (META_WINDOW_X11 (window));
actor_x11->frames = g_list_prepend (actor_x11->frames, frame);
@@ -485,13 +489,14 @@ meta_window_actor_x11_constructed (GObject *object)
MetaWindowActor *window_actor = META_WINDOW_ACTOR (object);
MetaWindow *window =
meta_window_actor_get_meta_window (window_actor);
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
G_OBJECT_CLASS (meta_window_actor_x11_parent_class)->constructed (object);
/* If a window doesn't start off with updates frozen, we should
* we should send a _NET_WM_FRAME_DRAWN immediately after the first drawn.
*/
if (window->extended_sync_request_counter &&
if (meta_window_x11_has_extended_sync_request_counter (window_x11) &&
!meta_window_updates_are_frozen (window))
meta_window_actor_queue_frame_drawn (window_actor, FALSE);
}

View File

@@ -403,9 +403,6 @@ struct _MetaWindow
/* if TRUE we have a grab on the focus click buttons */
guint have_focus_click_grab : 1;
/* if TRUE, application is buggy and SYNC resizing is turned off */
guint disable_sync : 1;
/* if TRUE, window is attached to its parent */
guint attached : 1;
@@ -431,21 +428,9 @@ struct _MetaWindow
/* _NET_WM_WINDOW_OPACITY rescaled to 0xFF */
guint8 opacity;
/* if TRUE, the we have the new form of sync request counter which
* also handles application frames */
guint extended_sync_request_counter : 1;
/* Note: can be NULL */
GSList *struts;
/* XSync update counter */
XSyncCounter sync_request_counter;
gint64 sync_request_serial;
gint64 sync_request_wait_serial;
guint sync_request_timeout_id;
/* alarm monitoring client's _NET_WM_SYNC_REQUEST_COUNTER */
XSyncAlarm sync_request_alarm;
/* Number of UnmapNotify that are caused by us, if
* we get UnmapNotify with none pending then the client
* is withdrawing the window.

View File

@@ -999,11 +999,6 @@ _meta_window_shared_new (MetaDisplay *display,
window->workspace = NULL;
window->sync_request_counter = None;
window->sync_request_serial = 0;
window->sync_request_timeout_id = 0;
window->sync_request_alarm = None;
meta_window_update_sandboxed_app_id (window);
meta_window_update_desc (window);
@@ -1083,7 +1078,6 @@ _meta_window_shared_new (MetaDisplay *display,
window->calc_placement = FALSE;
window->shaken_loose = FALSE;
window->have_focus_click_grab = FALSE;
window->disable_sync = FALSE;
window->unmaps_pending = 0;
@@ -1528,12 +1522,6 @@ meta_window_unmanage (MetaWindow *window,
invalidate_work_areas (window);
}
if (window->sync_request_timeout_id)
{
g_source_remove (window->sync_request_timeout_id);
window->sync_request_timeout_id = 0;
}
if (window->display->grab_window == window)
meta_display_end_grab_op (window->display, timestamp);
@@ -5948,8 +5936,8 @@ check_moveresize_frequency (MetaWindow *window,
/* If we are throttling via _NET_WM_SYNC_REQUEST, we don't need
* an artificial timeout-based throttled */
if (!window->disable_sync &&
window->sync_request_alarm != None)
if (window->client_type == META_WINDOW_CLIENT_TYPE_X11 &&
meta_window_x11_has_sync_request_alarm (META_WINDOW_X11 (window)))
return TRUE;
elapsed = time_diff (&current_time, &window->display->grab_last_moveresize_time);
@@ -6311,7 +6299,8 @@ update_resize (MetaWindow *window,
* resize the window when the window responds, or when we time
* the response out.
*/
if (window->sync_request_timeout_id != 0)
if (window->client_type == META_WINDOW_CLIENT_TYPE_X11 &&
meta_window_x11_is_sync_request_scheduled (META_WINDOW_X11 (window)))
return;
if (!check_moveresize_frequency (window, &remaining) && !force)

View File

@@ -1068,34 +1068,9 @@ reload_update_counter (MetaWindow *window,
MetaPropValue *value,
gboolean initial)
{
if (value->type != META_PROP_VALUE_INVALID)
{
meta_window_x11_destroy_sync_request_alarm (window);
window->sync_request_counter = None;
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
if (value->v.xcounter_list.n_counters == 0)
{
meta_warning ("_NET_WM_SYNC_REQUEST_COUNTER is empty\n");
return;
}
if (value->v.xcounter_list.n_counters == 1)
{
window->sync_request_counter = value->v.xcounter_list.counters[0];
window->extended_sync_request_counter = FALSE;
}
else
{
window->sync_request_counter = value->v.xcounter_list.counters[1];
window->extended_sync_request_counter = TRUE;
}
meta_verbose ("Window has _NET_WM_SYNC_REQUEST_COUNTER 0x%lx (extended=%s)\n",
window->sync_request_counter,
window->extended_sync_request_counter ? "true" : "false");
if (window->extended_sync_request_counter)
meta_window_x11_create_sync_request_alarm (window);
}
meta_window_x11_setup_sync_request_counter (window_x11, value);
}
#define FLAG_TOGGLED_ON(old,new,flag) \

View File

@@ -25,6 +25,8 @@
#include "core/window-private.h"
#include "x11/iconcache.h"
#include "x11/window-x11.h"
#include "x11/xprops.h"
G_BEGIN_DECLS
@@ -72,8 +74,28 @@ struct _MetaWindowX11Private
MetaIconCache icon_cache;
Pixmap wm_hints_pixmap;
Pixmap wm_hints_mask;
/* alarm monitoring client's _NET_WM_SYNC_REQUEST_COUNTER */
XSyncAlarm sync_request_alarm;
/* XSync update counter */
XSyncCounter sync_request_counter;
int64_t sync_request_serial;
int64_t sync_request_wait_serial;
guint sync_request_timeout_id;
/* if TRUE, application is buggy and SYNC resizing is turned off */
gboolean disable_sync;
/* if TRUE, the we have the new form of sync request counter which
* also handles application frames */
gboolean extended_sync_request_counter;
};
void meta_window_x11_setup_sync_request_counter (MetaWindowX11 *window_x11,
MetaPropValue *value);
G_END_DECLS
#endif

View File

@@ -588,6 +588,12 @@ meta_window_x11_unmanage (MetaWindow *window)
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11);
if (priv->sync_request_timeout_id)
{
g_source_remove (priv->sync_request_timeout_id);
priv->sync_request_timeout_id = 0;
}
meta_x11_error_trap_push (x11_display);
meta_window_x11_destroy_sync_request_alarm (window);
@@ -895,7 +901,7 @@ meta_window_x11_grab_op_began (MetaWindow *window,
if (meta_grab_op_is_resizing (op))
{
if (window->sync_request_counter != None)
if (priv->sync_request_counter != None)
meta_window_x11_create_sync_request_alarm (window);
if (window->size_hints.width_inc > 2 || window->size_hints.height_inc > 2)
@@ -1038,18 +1044,20 @@ static gboolean
sync_request_timeout (gpointer data)
{
MetaWindow *window = data;
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (META_WINDOW_X11 (window));
window->sync_request_timeout_id = 0;
priv->sync_request_timeout_id = 0;
/* We have now waited for more than a second for the
* application to respond to the sync request
*/
window->disable_sync = TRUE;
priv->disable_sync = TRUE;
/* Reset the wait serial, so we don't continue freezing
* window updates
*/
window->sync_request_wait_serial = 0;
priv->sync_request_wait_serial = 0;
meta_compositor_sync_updates_frozen (window->display->compositor, window);
if (window == window->display->grab_window &&
@@ -1068,6 +1076,9 @@ sync_request_timeout (gpointer data)
static void
send_sync_request (MetaWindow *window)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
MetaX11Display *x11_display = window->display->x11_display;
XClientMessageEvent ev;
gint64 wait_serial;
@@ -1079,9 +1090,9 @@ send_sync_request (MetaWindow *window)
* for the old style. The increment of 240 is specified by the EWMH
* and is (1 second) * (60fps) * (an increment of 4 per frame).
*/
wait_serial = window->sync_request_serial + 240;
wait_serial = priv->sync_request_serial + 240;
window->sync_request_wait_serial = wait_serial;
priv->sync_request_wait_serial = wait_serial;
ev.type = ClientMessage;
ev.window = window->xwindow;
@@ -1096,7 +1107,7 @@ send_sync_request (MetaWindow *window)
ev.data.l[1] = meta_display_get_current_time (window->display);
ev.data.l[2] = wait_serial & G_GUINT64_CONSTANT(0xffffffff);
ev.data.l[3] = wait_serial >> 32;
ev.data.l[4] = window->extended_sync_request_counter ? 1 : 0;
ev.data.l[4] = priv->extended_sync_request_counter ? 1 : 0;
/* We don't need to trap errors here as we are already
* inside an error_trap_push()/pop() pair.
@@ -1108,10 +1119,10 @@ send_sync_request (MetaWindow *window)
* if this time expires, we consider the window unresponsive
* and resize it unsynchonized.
*/
window->sync_request_timeout_id = g_timeout_add (1000,
priv->sync_request_timeout_id = g_timeout_add (1000,
sync_request_timeout,
window);
g_source_set_name_by_id (window->sync_request_timeout_id,
g_source_set_name_by_id (priv->sync_request_timeout_id,
"[mutter] sync_request_timeout");
meta_compositor_sync_updates_frozen (window->display->compositor, window);
@@ -1329,7 +1340,7 @@ meta_window_x11_move_resize_internal (MetaWindow *window,
* will be left undisturbed for us to paint to the screen until
* the client finishes redrawing.
*/
if (window->extended_sync_request_counter)
if (priv->extended_sync_request_counter)
configure_frame_first = TRUE;
else
configure_frame_first = size_dx + size_dy >= 0;
@@ -1357,10 +1368,10 @@ meta_window_x11_move_resize_internal (MetaWindow *window,
if (window == window->display->grab_window &&
meta_grab_op_is_resizing (window->display->grab_op) &&
!window->disable_sync &&
window->sync_request_counter != None &&
window->sync_request_alarm != None &&
window->sync_request_timeout_id == 0)
!priv->disable_sync &&
priv->sync_request_counter != None &&
priv->sync_request_alarm != None &&
priv->sync_request_timeout_id == 0)
{
send_sync_request (window);
}
@@ -1696,11 +1707,15 @@ meta_window_x11_is_stackable (MetaWindow *window)
static gboolean
meta_window_x11_are_updates_frozen (MetaWindow *window)
{
if (window->extended_sync_request_counter &&
window->sync_request_serial % 2 == 1)
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
if (priv->extended_sync_request_counter &&
priv->sync_request_serial % 2 == 1)
return TRUE;
if (window->sync_request_serial < window->sync_request_wait_serial)
if (priv->sync_request_serial < priv->sync_request_wait_serial)
return TRUE;
return FALSE;
@@ -3561,12 +3576,15 @@ meta_window_x11_set_allowed_actions_hint (MetaWindow *window)
void
meta_window_x11_create_sync_request_alarm (MetaWindow *window)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
MetaX11Display *x11_display = window->display->x11_display;
XSyncAlarmAttributes values;
XSyncValue init;
if (window->sync_request_counter == None ||
window->sync_request_alarm != None)
if (priv->sync_request_counter == None ||
priv->sync_request_alarm != None)
return;
meta_x11_error_trap_push (x11_display);
@@ -3575,29 +3593,29 @@ meta_window_x11_create_sync_request_alarm (MetaWindow *window)
* the client before mapping the window. In the old style, we're
* responsible for setting the initial value of the counter.
*/
if (window->extended_sync_request_counter)
if (priv->extended_sync_request_counter)
{
if (!XSyncQueryCounter(x11_display->xdisplay,
window->sync_request_counter,
priv->sync_request_counter,
&init))
{
meta_x11_error_trap_pop_with_return (x11_display);
window->sync_request_counter = None;
priv->sync_request_counter = None;
return;
}
window->sync_request_serial =
priv->sync_request_serial =
XSyncValueLow32 (init) + ((gint64)XSyncValueHigh32 (init) << 32);
}
else
{
XSyncIntToValue (&init, 0);
XSyncSetCounter (x11_display->xdisplay,
window->sync_request_counter, init);
window->sync_request_serial = 0;
priv->sync_request_counter, init);
priv->sync_request_serial = 0;
}
values.trigger.counter = window->sync_request_counter;
values.trigger.counter = priv->sync_request_counter;
values.trigger.test_type = XSyncPositiveComparison;
/* Initialize to one greater than the current value */
@@ -3611,7 +3629,7 @@ meta_window_x11_create_sync_request_alarm (MetaWindow *window)
/* we want events (on by default anyway) */
values.events = True;
window->sync_request_alarm = XSyncCreateAlarm (x11_display->xdisplay,
priv->sync_request_alarm = XSyncCreateAlarm (x11_display->xdisplay,
XSyncCACounter |
XSyncCAValueType |
XSyncCAValue |
@@ -3621,26 +3639,28 @@ meta_window_x11_create_sync_request_alarm (MetaWindow *window)
&values);
if (meta_x11_error_trap_pop_with_return (x11_display) == Success)
meta_x11_display_register_sync_alarm (x11_display, &window->sync_request_alarm, window);
meta_x11_display_register_sync_alarm (x11_display, &priv->sync_request_alarm, window);
else
{
window->sync_request_alarm = None;
window->sync_request_counter = None;
priv->sync_request_alarm = None;
priv->sync_request_counter = None;
}
}
void
meta_window_x11_destroy_sync_request_alarm (MetaWindow *window)
{
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (META_WINDOW_X11 (window));
MetaX11Display *x11_display = window->display->x11_display;
if (window->sync_request_alarm != None)
if (priv->sync_request_alarm != None)
{
/* Has to be unregistered _before_ clearing the structure field */
meta_x11_display_unregister_sync_alarm (x11_display, window->sync_request_alarm);
meta_x11_display_unregister_sync_alarm (x11_display, priv->sync_request_alarm);
XSyncDestroyAlarm (x11_display->xdisplay,
window->sync_request_alarm);
window->sync_request_alarm = None;
priv->sync_request_alarm);
priv->sync_request_alarm = None;
}
}
@@ -3648,31 +3668,34 @@ void
meta_window_x11_update_sync_request_counter (MetaWindow *window,
gint64 new_counter_value)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
gboolean needs_frame_drawn = FALSE;
gboolean no_delay_frame = FALSE;
if (window->extended_sync_request_counter && new_counter_value % 2 == 0)
if (priv->extended_sync_request_counter && new_counter_value % 2 == 0)
{
needs_frame_drawn = TRUE;
no_delay_frame = new_counter_value == window->sync_request_serial + 1;
no_delay_frame = new_counter_value == priv->sync_request_serial + 1;
}
window->sync_request_serial = new_counter_value;
priv->sync_request_serial = new_counter_value;
meta_compositor_sync_updates_frozen (window->display->compositor, window);
if (window == window->display->grab_window &&
meta_grab_op_is_resizing (window->display->grab_op) &&
new_counter_value >= window->sync_request_wait_serial &&
(!window->extended_sync_request_counter || new_counter_value % 2 == 0) &&
window->sync_request_timeout_id)
new_counter_value >= priv->sync_request_wait_serial &&
(!priv->extended_sync_request_counter || new_counter_value % 2 == 0) &&
priv->sync_request_timeout_id)
{
meta_topic (META_DEBUG_RESIZING,
"Alarm event received last motion x = %d y = %d\n",
window->display->grab_latest_motion_x,
window->display->grab_latest_motion_y);
g_source_remove (window->sync_request_timeout_id);
window->sync_request_timeout_id = 0;
g_source_remove (priv->sync_request_timeout_id);
priv->sync_request_timeout_id = 0;
/* This means we are ready for another configure;
* no pointer round trip here, to keep in sync */
@@ -3687,7 +3710,7 @@ meta_window_x11_update_sync_request_counter (MetaWindow *window,
* the application has come to its senses (maybe it was just
* busy with a pagefault or a long computation).
*/
window->disable_sync = FALSE;
priv->disable_sync = FALSE;
if (needs_frame_drawn)
meta_compositor_queue_frame_drawn (window->display->compositor, window,
@@ -3699,3 +3722,86 @@ meta_window_x11_get_toplevel_xwindow (MetaWindow *window)
{
return window->frame ? window->frame->xwindow : window->xwindow;
}
int64_t
meta_window_x11_get_sync_request_serial (MetaWindowX11 *window_x11)
{
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
g_return_val_if_fail (META_IS_WINDOW_X11 (window_x11), -1);
return priv->sync_request_serial;
}
gboolean
meta_window_x11_has_sync_request_alarm (MetaWindowX11 *window_x11)
{
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
g_return_val_if_fail (META_IS_WINDOW_X11 (window_x11), FALSE);
return !priv->disable_sync &&
priv->sync_request_alarm != None;
}
gboolean
meta_window_x11_is_sync_request_scheduled (MetaWindowX11 *window_x11)
{
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
g_return_val_if_fail (META_IS_WINDOW_X11 (window_x11), FALSE);
return priv->sync_request_timeout_id != 0;
}
gboolean
meta_window_x11_has_extended_sync_request_counter (MetaWindowX11 *window_x11)
{
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
g_return_val_if_fail (META_IS_WINDOW_X11 (window_x11), FALSE);
return priv->extended_sync_request_counter;
}
void
meta_window_x11_setup_sync_request_counter (MetaWindowX11 *window_x11,
MetaPropValue *value)
{
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
MetaWindow *window = META_WINDOW (window_x11);
if (value->type == META_PROP_VALUE_INVALID)
return;
meta_window_x11_destroy_sync_request_alarm (window);
priv->sync_request_counter = None;
if (value->v.xcounter_list.n_counters == 0)
{
meta_warning ("_NET_WM_SYNC_REQUEST_COUNTER is empty\n");
return;
}
if (value->v.xcounter_list.n_counters == 1)
{
priv->sync_request_counter = value->v.xcounter_list.counters[0];
priv->extended_sync_request_counter = FALSE;
}
else
{
priv->sync_request_counter = value->v.xcounter_list.counters[1];
priv->extended_sync_request_counter = TRUE;
}
meta_verbose ("Window has _NET_WM_SYNC_REQUEST_COUNTER 0x%lx (extended=%s)\n",
priv->sync_request_counter,
priv->extended_sync_request_counter ? "true" : "false");
if (priv->extended_sync_request_counter)
meta_window_x11_create_sync_request_alarm (window);
}

View File

@@ -81,4 +81,10 @@ void meta_window_x11_configure_notify (MetaWindow *window,
Window meta_window_x11_get_toplevel_xwindow (MetaWindow *window);
int64_t meta_window_x11_get_sync_request_serial (MetaWindowX11 *window_x11);
gboolean meta_window_x11_is_sync_request_scheduled (MetaWindowX11 *window_x11);
gboolean meta_window_x11_has_sync_request_alarm (MetaWindowX11 *window_x11);
gboolean meta_window_x11_has_extended_sync_request_counter (MetaWindowX11 *window_x11);
#endif