From 1883485edd7eb90c0b76bca41c71e26ae2c0b91a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 26 May 2008 16:35:23 +0930 Subject: [PATCH] If core motion history is required, scale back to screen coords and INT16. --- Xi/gtmotion.c | 2 +- dix/devices.c | 9 +++---- dix/getevents.c | 46 +++++++++++++++++++++++++++++++--- hw/xfree86/common/xf86Helper.c | 4 +-- hw/xfree86/common/xf86Xinput.h | 2 +- include/input.h | 3 ++- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c index 8b59d67ec..7cc5c2670 100644 --- a/Xi/gtmotion.c +++ b/Xi/gtmotion.c @@ -135,7 +135,7 @@ ProcXGetDeviceMotionEvents(ClientPtr client) size = sizeof(Time) + (axes * sizeof(INT32)); rep.nEvents = GetMotionHistory(dev, (xTimecoord **) &coords,/* XXX */ start.milliseconds, stop.milliseconds, - (ScreenPtr) NULL); + (ScreenPtr) NULL, FALSE); } if (rep.nEvents > 0) { length = (rep.nEvents * size + 3) >> 2; diff --git a/dix/devices.c b/dix/devices.c index 9db276b16..60d48b25e 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -2308,12 +2308,9 @@ ProcGetMotionEvents(ClientPtr client) { if (CompareTimeStamps(stop, currentTime) == LATER) stop = currentTime; - coords = (xTimecoord *)xalloc(mouse->valuator->numMotionEvents - * sizeof(xTimecoord)); - if (!coords) - return BadAlloc; - count = GetMotionHistory(mouse, coords, start.milliseconds, - stop.milliseconds, pWin->drawable.pScreen); + count = GetMotionHistory(mouse, &coords, start.milliseconds, + stop.milliseconds, pWin->drawable.pScreen, + TRUE); xmin = pWin->drawable.x - wBorderWidth (pWin); xmax = pWin->drawable.x + (int)pWin->drawable.width + wBorderWidth (pWin); diff --git a/dix/getevents.c b/dix/getevents.c index 349823dc8..643e97763 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -258,15 +258,16 @@ AllocateMotionHistory(DeviceIntPtr pDev) pDev->name, size * pDev->valuator->numMotionEvents); } - /** * Dump the motion history between start and stop into the supplied buffer. * Only records the event for a given screen in theory, but in practice, we * sort of ignore this. + * + * If core is set, we only generate x/y, in INT16, scaled to screen coords. */ _X_EXPORT int GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, - unsigned long stop, ScreenPtr pScreen) + unsigned long stop, ScreenPtr pScreen, BOOL core) { char *ibuff = NULL, *obuff; int i = 0, ret = 0; @@ -277,10 +278,15 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, int dflt; AxisInfo from, *to; /* for scaling */ CARD32 *ocbuf, *icbuf; /* pointer to coordinates for copying */ + INT16 *corebuf; + AxisInfo core_axis = {0}; if (!pDev->valuator || !pDev->valuator->numMotionEvents) return 0; + if (core && !pScreen) + return 0; + if (pDev->isMaster) size = (sizeof(INT32) * 3 * MAX_VALUATORS) + sizeof(Time); else @@ -304,7 +310,36 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, return ret; } else if (current >= start) { - if (pDev->isMaster) + if (core) + { + memcpy(obuff, ibuff, sizeof(Time)); /* copy timestamp */ + + icbuf = (INT32*)(ibuff + sizeof(Time)); + corebuf = (INT16*)(obuff + sizeof(Time)); + + /* fetch x coordinate + range */ + memcpy(&from.min_value, icbuf++, sizeof(INT32)); + memcpy(&from.max_value, icbuf++, sizeof(INT32)); + memcpy(&coord, icbuf++, sizeof(INT32)); + + /* scale to screen coords */ + to = &core_axis; + to->max_value = pScreen->width; + coord = rescaleValuatorAxis(coord, &from, to, pScreen->width); + + memcpy(corebuf, &coord, sizeof(INT16)); + corebuf++; + + /* fetch y coordinate + range */ + memcpy(&from.min_value, icbuf++, sizeof(INT32)); + memcpy(&from.max_value, icbuf++, sizeof(INT32)); + memcpy(&coord, icbuf++, sizeof(INT32)); + + to->max_value = pScreen->height; + coord = rescaleValuatorAxis(coord, &from, to, pScreen->height); + memcpy(corebuf, &coord, sizeof(INT16)); + + } else if (pDev->isMaster) { memcpy(obuff, ibuff, sizeof(Time)); /* copy timestamp */ @@ -345,7 +380,10 @@ GetMotionHistory(DeviceIntPtr pDev, xTimecoord **buff, unsigned long start, /* don't advance by size here. size may be different to the * actually written size if the MD has less valuators than MAX */ - obuff += (sizeof(INT32) * pDev->valuator->numAxes) + sizeof(Time); + if (core) + obuff += sizeof(INT32) + sizeof(Time); + else + obuff += (sizeof(INT32) * pDev->valuator->numAxes) + sizeof(Time); ret++; } } diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index 1dd0bbc0d..eaa6c76fb 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -2933,9 +2933,9 @@ xf86MotionHistoryAllocate(LocalDevicePtr local) _X_EXPORT int xf86GetMotionEvents(DeviceIntPtr pDev, xTimecoord *buff, unsigned long start, - unsigned long stop, ScreenPtr pScreen) + unsigned long stop, ScreenPtr pScreen, BOOL core) { - return GetMotionHistory(pDev, buff, start, stop, pScreen); + return GetMotionHistory(pDev, buff, start, stop, pScreen, core); } _X_EXPORT void diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h index dd72ec733..02f657de3 100644 --- a/hw/xfree86/common/xf86Xinput.h +++ b/hw/xfree86/common/xf86Xinput.h @@ -197,7 +197,7 @@ void xf86DeleteInput(InputInfoPtr pInp, int flags); void xf86MotionHistoryAllocate(LocalDevicePtr local); int xf86GetMotionEvents(DeviceIntPtr dev, xTimecoord *buff, unsigned long start, unsigned long stop, - ScreenPtr pScreen); + ScreenPtr pScreen, BOOL core); /* xf86Option.c */ void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts, diff --git a/include/input.h b/include/input.h index 3071d75de..a816385a5 100644 --- a/include/input.h +++ b/include/input.h @@ -486,7 +486,8 @@ extern int GetMotionHistory( xTimecoord **buff, unsigned long start, unsigned long stop, - ScreenPtr pScreen); + ScreenPtr pScreen, + BOOL core); extern void SwitchCorePointer(DeviceIntPtr pDev);