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
This commit is contained in:
Rui Matos 2013-11-11 18:16:32 +01:00 committed by Emmanuele Bassi
parent 572504db4d
commit e70a0109f2
10 changed files with 20 additions and 20 deletions

View File

@ -2410,7 +2410,7 @@ clutter_do_event (ClutterEvent *event)
* because we've "looked ahead" and know all motion events that * because we've "looked ahead" and know all motion events that
* will occur before drawing the frame. * 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 static void

View File

@ -62,7 +62,8 @@ gboolean _clutter_stage_needs_update (ClutterStage
gboolean _clutter_stage_do_update (ClutterStage *stage); gboolean _clutter_stage_do_update (ClutterStage *stage);
void _clutter_stage_queue_event (ClutterStage *stage, void _clutter_stage_queue_event (ClutterStage *stage,
ClutterEvent *event); ClutterEvent *event,
gboolean copy_event);
gboolean _clutter_stage_has_queued_events (ClutterStage *stage); gboolean _clutter_stage_has_queued_events (ClutterStage *stage);
void _clutter_stage_process_queued_events (ClutterStage *stage); void _clutter_stage_process_queued_events (ClutterStage *stage);
void _clutter_stage_update_input_devices (ClutterStage *stage); void _clutter_stage_update_input_devices (ClutterStage *stage);

View File

@ -937,7 +937,8 @@ clutter_stage_real_fullscreen (ClutterStage *stage)
void void
_clutter_stage_queue_event (ClutterStage *stage, _clutter_stage_queue_event (ClutterStage *stage,
ClutterEvent *event) ClutterEvent *event,
gboolean copy_event)
{ {
ClutterStagePrivate *priv; ClutterStagePrivate *priv;
gboolean first_event; gboolean first_event;
@ -949,7 +950,10 @@ _clutter_stage_queue_event (ClutterStage *stage,
first_event = priv->event_queue->length == 0; 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) if (first_event)
{ {

View File

@ -51,6 +51,7 @@
#include "clutter-xkb-utils.h" #include "clutter-xkb-utils.h"
#include "clutter-backend-private.h" #include "clutter-backend-private.h"
#include "clutter-evdev.h" #include "clutter-evdev.h"
#include "clutter-stage-private.h"
#include "clutter-device-manager-evdev.h" #include "clutter-device-manager-evdev.h"
@ -573,8 +574,7 @@ clutter_event_dispatch (GSource *g_source,
goto out; goto out;
/* forward the event into clutter for emission etc. */ /* forward the event into clutter for emission etc. */
clutter_do_event (event); _clutter_stage_queue_event (event->any.stage, event, FALSE);
clutter_event_free (event);
/* update the device states *after* the event */ /* update the device states *after* the event */
event_state = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_EFFECTIVE); event_state = xkb_state_serialize_mods (seat->xkb, XKB_STATE_MODS_EFFECTIVE);

View File

@ -309,8 +309,7 @@ clutter_gdk_handle_event (GdkEvent *gdk_event)
while (spin > 0 && (event = clutter_event_get ())) while (spin > 0 && (event = clutter_event_get ()))
{ {
/* forward the event into clutter for emission etc. */ /* forward the event into clutter for emission etc. */
clutter_do_event (event); _clutter_stage_queue_event (event->any.stage, event, FALSE);
clutter_event_free (event);
--spin; --spin;
} }

View File

@ -712,8 +712,7 @@ clutter_event_dispatch (GSource *source,
if (event) if (event)
{ {
/* forward the event into clutter for emission etc. */ /* forward the event into clutter for emission etc. */
clutter_do_event (event); _clutter_stage_queue_event (event->any.stage, event, FALSE);
clutter_event_free (event);
} }
_clutter_threads_release_lock (); _clutter_threads_release_lock ();

View File

@ -267,8 +267,7 @@ clutter_event_dispatch (GSource *source,
if (event) if (event)
{ {
/* forward the event into clutter for emission etc. */ /* forward the event into clutter for emission etc. */
clutter_do_event (event); _clutter_stage_queue_event (event->any.stage, event, FALSE);
clutter_event_free (event);
} }
out: out:

View File

@ -35,6 +35,7 @@
#include "clutter-event.h" #include "clutter-event.h"
#include "clutter-main.h" #include "clutter-main.h"
#include "clutter-private.h" #include "clutter-private.h"
#include "clutter-stage-private.h"
#include "clutter-event-wayland.h" #include "clutter-event-wayland.h"
@ -94,8 +95,7 @@ clutter_event_source_wayland_dispatch (GSource *base,
if (event) if (event)
{ {
/* forward the event into clutter for emission etc. */ /* forward the event into clutter for emission etc. */
clutter_do_event (event); _clutter_stage_queue_event (event->any.stage, event, FALSE);
clutter_event_free (event);
} }
_clutter_threads_release_lock (); _clutter_threads_release_lock ();

View File

@ -294,8 +294,7 @@ clutter_event_dispatch (GSource *source,
if ((event = clutter_event_get ())) if ((event = clutter_event_get ()))
{ {
/* forward the event into clutter for emission etc. */ /* forward the event into clutter for emission etc. */
clutter_do_event (event); _clutter_stage_queue_event (event->any.stage, event, FALSE);
clutter_event_free (event);
} }
_clutter_threads_release_lock (); _clutter_threads_release_lock ();

View File

@ -34,6 +34,7 @@
#include "clutter-event-private.h" #include "clutter-event-private.h"
#include "clutter-main.h" #include "clutter-main.h"
#include "clutter-private.h" #include "clutter-private.h"
#include "clutter-stage-private.h"
#include <string.h> #include <string.h>
@ -220,8 +221,7 @@ clutter_x11_handle_event (XEvent *xevent)
while (spin > 0 && (event = clutter_event_get ())) while (spin > 0 && (event = clutter_event_get ()))
{ {
/* forward the event into clutter for emission etc. */ /* forward the event into clutter for emission etc. */
clutter_do_event (event); _clutter_stage_queue_event (event->any.stage, event, FALSE);
clutter_event_free (event);
--spin; --spin;
} }
@ -321,8 +321,7 @@ clutter_event_dispatch (GSource *source,
if (event != NULL) if (event != NULL)
{ {
/* forward the event into clutter for emission etc. */ /* forward the event into clutter for emission etc. */
clutter_do_event (event); _clutter_stage_queue_event (event->any.stage, event, FALSE);
clutter_event_free (event);
} }
_clutter_threads_release_lock (); _clutter_threads_release_lock ();