summaryrefslogtreecommitdiff
path: root/dix
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2015-12-08 14:20:21 -0800
committerKeith Packard <keithp@keithp.com>2016-05-26 16:07:54 -0700
commitf84703b50cc908a127f4ad923ebbf56f8f244c0d (patch)
tree0a1f83251a6ccc7e772e9a0f5b322f81fd7e9375 /dix
parente2df803fcabd7c2d2fc7991c794856378dcb5489 (diff)
dix: Reallocate touchpoint buffer at input event time [v2]
Now that input is threaded, malloc can be used at event time to resize the touchpoint buffer as needed.x v2: Remove "Need to grow the queue means dropping events." from comment as it no longer applies. (Peter Hutterer) Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'dix')
-rw-r--r--dix/touch.c88
1 files changed, 29 insertions, 59 deletions
diff --git a/dix/touch.c b/dix/touch.c
index 4c0412a17..37902bd05 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -42,9 +42,6 @@
#define TOUCH_HISTORY_SIZE 100
-/* If a touch queue resize is needed, the device id's bit is set. */
-static unsigned char resize_waiting[(MAXDEVICES + 7) / 8];
-
/**
* Some documentation about touch points:
* The driver submits touch events with it's own (unique) touch point ID.
@@ -74,47 +71,27 @@ static unsigned char resize_waiting[(MAXDEVICES + 7) / 8];
* @return Always True. If we fail to grow we probably will topple over soon
* anyway and re-executing this won't help.
*/
+
static Bool
-TouchResizeQueue(ClientPtr client, void *closure)
+TouchResizeQueue(DeviceIntPtr dev)
{
- int i;
-
- input_lock();
-
- /* first two ids are reserved */
- for (i = 2; i < MAXDEVICES; i++) {
- DeviceIntPtr dev;
- DDXTouchPointInfoPtr tmp;
- size_t size;
-
- if (!BitIsOn(resize_waiting, i))
- continue;
+ DDXTouchPointInfoPtr tmp;
+ size_t size;
- ClearBit(resize_waiting, i);
+ /* Grow sufficiently so we don't need to do it often */
+ size = dev->last.num_touches + dev->last.num_touches / 2 + 1;
- /* device may have disappeared by now */
- dixLookupDevice(&dev, i, serverClient, DixWriteAccess);
- if (!dev)
- continue;
-
- /* Need to grow the queue means dropping events. Grow sufficiently so we
- * don't need to do it often */
- size = dev->last.num_touches + dev->last.num_touches / 2 + 1;
-
- tmp = reallocarray(dev->last.touches, size, sizeof(*dev->last.touches));
- if (tmp) {
- int j;
-
- dev->last.touches = tmp;
- for (j = dev->last.num_touches; j < size; j++)
- TouchInitDDXTouchPoint(dev, &dev->last.touches[j]);
- dev->last.num_touches = size;
- }
+ tmp = reallocarray(dev->last.touches, size, sizeof(*dev->last.touches));
+ if (tmp) {
+ int j;
+ dev->last.touches = tmp;
+ for (j = dev->last.num_touches; j < size; j++)
+ TouchInitDDXTouchPoint(dev, &dev->last.touches[j]);
+ dev->last.num_touches = size;
+ return TRUE;
}
- input_unlock();
-
- return TRUE;
+ return FALSE;
}
/**
@@ -172,14 +149,20 @@ TouchBeginDDXTouch(DeviceIntPtr dev, uint32_t ddx_id)
if (TouchFindByDDXID(dev, ddx_id, FALSE))
return NULL;
- for (i = 0; i < dev->last.num_touches; i++) {
- /* Only emulate pointer events on the first touch */
- if (dev->last.touches[i].active)
- emulate_pointer = FALSE;
- else if (!ti) /* ti is now first non-active touch rec */
- ti = &dev->last.touches[i];
+ for (;;) {
+ for (i = 0; i < dev->last.num_touches; i++) {
+ /* Only emulate pointer events on the first touch */
+ if (dev->last.touches[i].active)
+ emulate_pointer = FALSE;
+ else if (!ti) /* ti is now first non-active touch rec */
+ ti = &dev->last.touches[i];
- if (!emulate_pointer && ti)
+ if (!emulate_pointer && ti)
+ break;
+ }
+ if (ti)
+ break;
+ if (!TouchResizeQueue(dev))
break;
}
@@ -194,21 +177,8 @@ TouchBeginDDXTouch(DeviceIntPtr dev, uint32_t ddx_id)
next_client_id = 1;
ti->client_id = client_id;
ti->emulate_pointer = emulate_pointer;
- return ti;
}
-
- /* If we get here, then we've run out of touches and we need to drop the
- * event (we're inside the SIGIO handler here) schedule a WorkProc to
- * grow the queue for us for next time. */
- ErrorFSigSafe("%s: not enough space for touch events (max %u touchpoints). "
- "Dropping this event.\n", dev->name, dev->last.num_touches);
-
- if (!BitIsOn(resize_waiting, dev->id)) {
- SetBit(resize_waiting, dev->id);
- QueueWorkProc(TouchResizeQueue, serverClient, NULL);
- }
-
- return NULL;
+ return ti;
}
void