GKVE/GPE: have DDX allocate events

Don't allocate events on every GKE/GKVE/GPE call, just have the DDX manage
it instead.  Introduce GetMaximumEventsNum(), which is the maximum number
of events these functions will ever produce.
This commit is contained in:
Daniel Stone 2006-08-10 14:00:14 +03:00 • committed by Daniel Stone
commit 539d1f3347
4 changed files with 118 additions and 99 deletions

View file

@ -69,6 +69,8 @@ static struct KdConfigDevice *kdConfigPointers = NULL;
static KdKeyboardDriver *kdKeyboardDrivers = NULL;
static KdPointerDriver *kdPointerDrivers = NULL;
static xEvent *kdEvents = NULL;
static Bool kdInputEnabled;
static Bool kdOffScreen;
static unsigned long kdOffScreenTime;
@ -1271,6 +1273,11 @@ KdInitInput (void)
ErrorF("Failed to add keyboard!\n");
}
if (!kdEvents)
kdEvents = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
if (!kdEvents)
FatalError("Couldn't allocate event buffer\n");
mieqInit();
}
@ -1849,7 +1856,6 @@ KdHandleKeyboardEvent (KdKeyboardInfo *ki, int type, int key)
void
KdReleaseAllKeys (void)
{
xEvent *xE;
int key, nEvents, i;
KdKeyboardInfo *ki;
@ -1860,9 +1866,9 @@ KdReleaseAllKeys (void)
key++) {
if (IsKeyDown(ki, key)) {
KdHandleKeyboardEvent(ki, KeyRelease, key);
nEvents = GetKeyboardEvents(&xE, ki->dixdev, KeyRelease, key);
nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key);
for (i = 0; i < nEvents; i++)
KdQueueEvent (xE++);
KdQueueEvent (kdEvents + i);
}
}
}
@ -1897,7 +1903,6 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo *ki,
KeyClassPtr keyc = NULL;
KeybdCtrl *ctrl = NULL;
int type, nEvents, i;
xEvent *xE = NULL;
#ifdef DEBUG
ErrorF("enqueuing kb event (scancode %d, %s)\n", scan_code, is_up ? "up" : "down");
@ -1939,12 +1944,12 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo *ki,
KdCheckSpecialKeys(ki, type, key_code);
KdHandleKeyboardEvent(ki, type, key_code);
nEvents = GetKeyboardEvents(&xE, ki->dixdev, type, key_code);
nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, type, key_code);
#ifdef DEBUG
ErrorF("KdEnqueueKeyboardEvent: got %d events from GKE\n", nEvents);
#endif
for (i = 0; i < nEvents; i++)
KdQueueEvent(xE++);
KdQueueEvent(kdEvents + i);
}
else {
ErrorF("driver %s wanted to post scancode %d outside of [%d, %d]!\n",
@ -2047,8 +2052,7 @@ void
_KdEnqueuePointerEvent (KdPointerInfo *pi, int type, int x, int y, int z,
int b, int absrel, Bool force)
{
xEvent *xE = NULL;
int n = 0, i = 0;
int nEvents = 0, i = 0;
int valuators[3] = { x, y, z };
#ifdef DEBUG
@ -2060,9 +2064,10 @@ _KdEnqueuePointerEvent (KdPointerInfo *pi, int type, int x, int y, int z,
if (!force && KdHandlePointerEvent(pi, type, x, y, z, b, absrel))
return;
n = GetPointerEvents(&xE, pi->dixdev, type, b, absrel, 3, valuators);
for (i = 0; i < n; i++)
KdQueueEvent(xE++);
nEvents = GetPointerEvents(kdEvents, pi->dixdev, type, b, absrel, 3,
valuators);
for (i = 0; i < nEvents; i++)
KdQueueEvent(kdEvents + i);
}
void

View file

@ -108,6 +108,8 @@ static int debug_level = 0;
#define DBG(lvl, f)
#endif
static xEvent *xf86Events = NULL;
static Bool
xf86SendDragEvents(DeviceIntPtr device)
{
@ -639,7 +641,6 @@ xf86PostMotionEvent(DeviceIntPtr device,
int i = 0, nevents = 0;
Bool drag = xf86SendDragEvents(device);
LocalDevicePtr local = (LocalDevicePtr) device->public.devicePrivate;
xEvent *events = NULL;
int *valuators = NULL;
int flags = 0;
@ -662,15 +663,16 @@ xf86PostMotionEvent(DeviceIntPtr device,
#endif
}
nevents = GetPointerEvents(&events, device, MotionNotify, 0,
if (!xf86Events)
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
if (!xf86Events)
FatalError("Couldn't allocate event store\n");
nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0,
flags, num_valuators, valuators);
for (i = 0; i < nevents; i++) {
if (events->u.keyButtonPointer.time > xf86Info.lastEventTime)
xf86Info.lastEventTime = events->u.keyButtonPointer.time;
mieqEnqueue(events + i);
}
xfree(events);
for (i = 0; i < nevents; i++)
mieqEnqueue(xf86Events + i);
#if 0
if (HAS_MOTION_HISTORY(local)) {
@ -791,7 +793,6 @@ xf86PostButtonEvent(DeviceIntPtr device,
va_list var;
int *valuators = NULL;
int i = 0, nevents = 0;
xEvent *events = NULL;
#ifdef DEBUG
ErrorF("xf86PostButtonEvent BEGIN 0x%x(%s) button=%d down=%s is_absolute=%s\n",
@ -810,18 +811,19 @@ xf86PostButtonEvent(DeviceIntPtr device,
valuators[i] = va_arg(var, int);
}
nevents = GetPointerEvents(&events, device,
if (!xf86Events)
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
if (!xf86Events)
FatalError("Couldn't allocate event store\n");
nevents = GetPointerEvents(xf86Events, device,
is_down ? ButtonPress : ButtonRelease, button,
is_absolute ? POINTER_ABSOLUTE :
POINTER_RELATIVE,
num_valuators, valuators);
for (i = 0; i < nevents; i++) {
if (events->u.keyButtonPointer.time > xf86Info.lastEventTime)
xf86Info.lastEventTime = events->u.keyButtonPointer.time;
mieqEnqueue(events + i);
}
xfree(events);
for (i = 0; i < nevents; i++)
mieqEnqueue(xf86Events + i);
}
_X_EXPORT void
@ -835,38 +837,39 @@ xf86PostKeyEvent(DeviceIntPtr device,
{
va_list var;
int i = 0, nevents = 0, *valuators = NULL;
xEvent *events = NULL;
/* instil confidence in the user */
ErrorF("this function has never been tested properly. if things go quite "
"badly south after this message, then xf86PostKeyEvent is "
"broken.\n");
if (!xf86Events)
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
if (!xf86Events)
FatalError("Couldn't allocate event store\n");
/* the spec says that dkp/dkr events should only get valuators in
* absolute mode. the spec knows all. BOW BEFORE etc. */
if (is_absolute) {
nevents = GetKeyboardValuatorEvents(&events, device,
is_down ? KeyPress : KeyRelease,
key_code, num_valuators,
valuators);
valuators = xcalloc(sizeof(int), num_valuators);
va_start(var, num_valuators);
for (i = 0; i < num_valuators; i++)
valuators[i] = va_arg(var, int);
va_end(var);
nevents = GetKeyboardValuatorEvents(xf86Events, device,
is_down ? KeyPress : KeyRelease,
key_code, num_valuators,
valuators);
}
else {
nevents = GetKeyboardEvents(&events, device,
nevents = GetKeyboardEvents(xf86Events, device,
is_down ? KeyPress : KeyRelease,
key_code);
}
for (i = 0; i < nevents; i++) {
if (events->u.keyButtonPointer.time > xf86Info.lastEventTime)
xf86Info.lastEventTime = events->u.keyButtonPointer.time;
mieqEnqueue(events + i);
}
xfree(events);
for (i = 0; i < nevents; i++)
mieqEnqueue(xf86Events + i);
}
_X_EXPORT void
@ -874,7 +877,6 @@ xf86PostKeyboardEvent(DeviceIntPtr device,
unsigned int key_code,
int is_down)
{
xEvent *events = NULL;
int nevents = 0, i = 0;
#ifdef DEBUG
@ -882,15 +884,16 @@ xf86PostKeyboardEvent(DeviceIntPtr device,
is_down ? "down" : "up", device->id);
#endif
nevents = GetKeyboardEvents(&events, device,
if (!xf86Events)
xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
if (!xf86Events)
FatalError("Couldn't allocate event store\n");
nevents = GetKeyboardEvents(xf86Events, device,
is_down ? KeyPress : KeyRelease, key_code);
for (i = 0; i < nevents; i++) {
if (events->u.keyButtonPointer.time > xf86Info.lastEventTime)
xf86Info.lastEventTime = events->u.keyButtonPointer.time;
mieqEnqueue(events + i);
}
xfree(events);
for (i = 0; i < nevents; i++)
mieqEnqueue(xf86Events + i);
}
/*