From e70a0109f2306080a853aa15eb61fd9ce53edf73 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Mon, 11 Nov 2013 18:16:32 +0100 Subject: [PATCH] Avoid needless event copies when queueing from a backend to a stage All backends follow the same pattern of queueing events first in ClutterMainContext, then copying them to a ClutterStage queue and immediately free them. Instead, we can just pass ownership of events directly to ClutterStage thus avoiding the allocation and copy in between. https://bugzilla.gnome.org/show_bug.cgi?id=711857 --- clutter/clutter-main.c | 2 +- clutter/clutter-stage-private.h | 3 ++- clutter/clutter-stage.c | 8 ++++++-- clutter/evdev/clutter-device-manager-evdev.c | 4 ++-- clutter/gdk/clutter-event-gdk.c | 3 +-- clutter/osx/clutter-event-loop-osx.c | 3 +-- clutter/tslib/clutter-event-tslib.c | 3 +-- clutter/wayland/clutter-event-wayland.c | 4 ++-- clutter/win32/clutter-event-win32.c | 3 +-- clutter/x11/clutter-event-x11.c | 7 +++---- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c index 925a77aab..bfa1dd084 100644 --- a/clutter/clutter-main.c +++ b/clutter/clutter-main.c @@ -2410,7 +2410,7 @@ clutter_do_event (ClutterEvent *event) * because we've "looked ahead" and know all motion events that * will occur before drawing the frame. */ - _clutter_stage_queue_event (event->any.stage, event); + _clutter_stage_queue_event (event->any.stage, event, TRUE); } static void diff --git a/clutter/clutter-stage-private.h b/clutter/clutter-stage-private.h index 890fcdccc..7529cdfdd 100644 --- a/clutter/clutter-stage-private.h +++ b/clutter/clutter-stage-private.h @@ -62,7 +62,8 @@ gboolean _clutter_stage_needs_update (ClutterStage gboolean _clutter_stage_do_update (ClutterStage *stage); void _clutter_stage_queue_event (ClutterStage *stage, - ClutterEvent *event); + ClutterEvent *event, + gboolean copy_event); gboolean _clutter_stage_has_queued_events (ClutterStage *stage); void _clutter_stage_process_queued_events (ClutterStage *stage); void _clutter_stage_update_input_devices (ClutterStage *stage); diff --git a/clutter/clutter-stage.c b/clutter/clutter-stage.c index 6825f32e0..d9a1c6766 100644 --- a/clutter/clutter-stage.c +++ b/clutter/clutter-stage.c @@ -937,7 +937,8 @@ clutter_stage_real_fullscreen (ClutterStage *stage) void _clutter_stage_queue_event (ClutterStage *stage, - ClutterEvent *event) + ClutterEvent *event, + gboolean copy_event) { ClutterStagePrivate *priv; gboolean first_event; @@ -949,7 +950,10 @@ _clutter_stage_queue_event (ClutterStage *stage, first_event = priv->event_queue->length == 0; - g_queue_push_tail (priv->event_queue, clutter_event_copy (event)); + if (copy_event) + event = clutter_event_copy (event); + + g_queue_push_tail (priv->event_queue, event); if (first_event) { diff --git a/clutter/evdev/clutter-device-manager-evdev.c b/clutter/evdev/clutter-device-manager-evdev.c index 75d090b49..7d60d8524 100644 --- a/clutter/evdev/clutter-device-manager-evdev.c +++ b/clutter/evdev/clutter-device-manager-evdev.c @@ -51,6 +51,7 @@ #include "clutter-xkb-utils.h" #include "clutter-backend-private.h" #include "clutter-evdev.h" +#include "clutter-stage-private.h" #include "clutter-device-manager-evdev.h" @@ -573,8 +574,7 @@ clutter_event_dispatch (GSource *g_source, goto out; /* forward the event into clutter for emission etc. */ - clutter_do_event (event); - clutter_event_free (event); + _clutter_stage_queue_event (event->any.stage, event, FALSE); /* update the device states *after* the event */ event_state = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_EFFECTIVE); diff --git a/clutter/gdk/clutter-event-gdk.c b/clutter/gdk/clutter-event-gdk.c index d9ce5deff..eb5325cbd 100644 --- a/clutter/gdk/clutter-event-gdk.c +++ b/clutter/gdk/clutter-event-gdk.c @@ -309,8 +309,7 @@ clutter_gdk_handle_event (GdkEvent *gdk_event) while (spin > 0 && (event = clutter_event_get ())) { /* forward the event into clutter for emission etc. */ - clutter_do_event (event); - clutter_event_free (event); + _clutter_stage_queue_event (event->any.stage, event, FALSE); --spin; } diff --git a/clutter/osx/clutter-event-loop-osx.c b/clutter/osx/clutter-event-loop-osx.c index 6b3a561ef..77a4330ab 100644 --- a/clutter/osx/clutter-event-loop-osx.c +++ b/clutter/osx/clutter-event-loop-osx.c @@ -712,8 +712,7 @@ clutter_event_dispatch (GSource *source, if (event) { /* forward the event into clutter for emission etc. */ - clutter_do_event (event); - clutter_event_free (event); + _clutter_stage_queue_event (event->any.stage, event, FALSE); } _clutter_threads_release_lock (); diff --git a/clutter/tslib/clutter-event-tslib.c b/clutter/tslib/clutter-event-tslib.c index 260562565..8ed27f347 100644 --- a/clutter/tslib/clutter-event-tslib.c +++ b/clutter/tslib/clutter-event-tslib.c @@ -267,8 +267,7 @@ clutter_event_dispatch (GSource *source, if (event) { /* forward the event into clutter for emission etc. */ - clutter_do_event (event); - clutter_event_free (event); + _clutter_stage_queue_event (event->any.stage, event, FALSE); } out: diff --git a/clutter/wayland/clutter-event-wayland.c b/clutter/wayland/clutter-event-wayland.c index 08dfbeed3..c832d80b8 100644 --- a/clutter/wayland/clutter-event-wayland.c +++ b/clutter/wayland/clutter-event-wayland.c @@ -35,6 +35,7 @@ #include "clutter-event.h" #include "clutter-main.h" #include "clutter-private.h" +#include "clutter-stage-private.h" #include "clutter-event-wayland.h" @@ -94,8 +95,7 @@ clutter_event_source_wayland_dispatch (GSource *base, if (event) { /* forward the event into clutter for emission etc. */ - clutter_do_event (event); - clutter_event_free (event); + _clutter_stage_queue_event (event->any.stage, event, FALSE); } _clutter_threads_release_lock (); diff --git a/clutter/win32/clutter-event-win32.c b/clutter/win32/clutter-event-win32.c index 504011114..524dce0ed 100644 --- a/clutter/win32/clutter-event-win32.c +++ b/clutter/win32/clutter-event-win32.c @@ -294,8 +294,7 @@ clutter_event_dispatch (GSource *source, if ((event = clutter_event_get ())) { /* forward the event into clutter for emission etc. */ - clutter_do_event (event); - clutter_event_free (event); + _clutter_stage_queue_event (event->any.stage, event, FALSE); } _clutter_threads_release_lock (); diff --git a/clutter/x11/clutter-event-x11.c b/clutter/x11/clutter-event-x11.c index 9eedbcd2a..3305063c3 100644 --- a/clutter/x11/clutter-event-x11.c +++ b/clutter/x11/clutter-event-x11.c @@ -34,6 +34,7 @@ #include "clutter-event-private.h" #include "clutter-main.h" #include "clutter-private.h" +#include "clutter-stage-private.h" #include @@ -220,8 +221,7 @@ clutter_x11_handle_event (XEvent *xevent) while (spin > 0 && (event = clutter_event_get ())) { /* forward the event into clutter for emission etc. */ - clutter_do_event (event); - clutter_event_free (event); + _clutter_stage_queue_event (event->any.stage, event, FALSE); --spin; } @@ -321,8 +321,7 @@ clutter_event_dispatch (GSource *source, if (event != NULL) { /* forward the event into clutter for emission etc. */ - clutter_do_event (event); - clutter_event_free (event); + _clutter_stage_queue_event (event->any.stage, event, FALSE); } _clutter_threads_release_lock ();