diff options
author | Peter Hutterer <peter.hutterer@redhat.com> | 2008-12-01 21:20:48 +1000 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2009-01-09 10:30:27 -0800 |
commit | a067bd907e9d3e55edd6ca61279968b6cb96236c (patch) | |
tree | 6877303243d58ce6982450fec2e458fe6d83a943 /mi | |
parent | 3519f83f509dd0363f574d3a68b21df98d5f2732 (diff) |
mi: Clean up CopyGetMasterEvent, re-use the memory.
Alloc an EventList once and then re-use instead of allocing a new event each
time we need a master event.
There's a trick included: because all the event processing handlers only take
an xEvent, init a size 1 EventList and squash the events into this one.
Events that have count > 1 must be squished into an xEvent array anyway before
passing into the event handlers, so we don't lose anything here.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Daniel Stone <daniel@fooishbar.org>
(cherry picked from commit d281866b74f7067f2704c278fe9720eafc0ee5ef)
Diffstat (limited to 'mi')
-rw-r--r-- | mi/mieq.c | 60 |
1 files changed, 30 insertions, 30 deletions
@@ -80,6 +80,7 @@ typedef struct _EventQueue { } EventQueueRec, *EventQueuePtr; static EventQueueRec miEventQueue; +static EventListPtr masterEvents; /* for use in mieqProcessInputEvents */ Bool mieqInit(void) @@ -98,6 +99,17 @@ mieqInit(void) FatalError("Could not allocate event queue.\n"); miEventQueue.events[i].events = evlist; } + + /* XXX: mE is just 1 event long, if we have Motion + Valuator they are + * squashed into the first event to make passing it into the event + * processing handlers easier. This should be fixed when the processing + * handlers switch to EventListPtr instead of xEvent */ + masterEvents = InitEventList(1); + if (!masterEvents) + FatalError("Could not allocated MD event queue.\n"); + SetMinimumEventSize(masterEvents, 1, + (1 + MAX_VALUATOR_EVENTS) * sizeof(xEvent)); + SetInputCheck(&miEventQueue.head, &miEventQueue.tail); return TRUE; } @@ -270,28 +282,21 @@ ChangeDeviceID(DeviceIntPtr dev, xEvent* event) */ void CopyGetMasterEvent(DeviceIntPtr mdev, xEvent* original, - xEvent** master, int count) + EventListPtr master, int count) { - if (count > 1) { - *master = xcalloc(count, sizeof(xEvent)); - if (!*master) - FatalError("[mi] No memory left for master event.\n"); - while(count--) - { - memcpy(&(*master)[count], &original[count], sizeof(xEvent)); - ChangeDeviceID(mdev, &(*master)[count]); - } - } else - { - int len = sizeof(xEvent); - if (original->u.u.type == GenericEvent) - len += GEV(original)->length * 4; - *master = xalloc(len); - if (!*master) - FatalError("[mi] No memory left for master event.\n"); - memcpy(*master, original, len); - ChangeDeviceID(mdev, *master); - } + int len = count * sizeof(xEvent); + + /* Assumption: GenericEvents always have count 1 */ + + if (GEV(original)->type == GenericEvent) + len += GEV(original)->length * 4; + + if (master->evlen < len) + SetMinimumEventSize(master, 1, len); + + memcpy(master->event, original, len); + while (count--) + ChangeDeviceID(mdev, &master->event[count]); } /* Call this from ProcessInputEvents(). */ @@ -303,8 +308,7 @@ mieqProcessInputEvents(void) int x = 0, y = 0; int type, nevents, evlen, i; ScreenPtr screen; - xEvent *event, - *master_event = NULL; + xEvent *event; DeviceIntPtr dev = NULL, master = NULL; @@ -353,10 +357,7 @@ mieqProcessInputEvents(void) } else { if (master) - CopyGetMasterEvent(master, event, - &master_event, nevents); - else - master_event = NULL; + CopyGetMasterEvent(master, event, masterEvents, nevents); /* If someone's registered a custom event handler, let them * steal it. */ @@ -365,19 +366,18 @@ mieqProcessInputEvents(void) handler(DequeueScreen(dev)->myNum, event, dev, nevents); if (master) handler(DequeueScreen(master)->myNum, - master_event, master, nevents); + masterEvents->event, master, nevents); } else { /* process slave first, then master */ dev->public.processInputProc(event, dev, nevents); if (master) - master->public.processInputProc(master_event, master, + master->public.processInputProc(masterEvents->event, master, nevents); } xfree(event); - xfree(master_event); } /* Update the sprite now. Next event may be from different device. */ |