From: Chris Bagwell <ch...@cnpbagwell.com>

This helps abstract out filtering better but also helps
trying out custom filters as well (such as only storing
raw changes when something changes).

Mainly, intent is to refactor and keep previous behavior but
two changes did occur.  1) Stop executing filtering logic
while out of proximity for slight performance gain and
2) wcmCheckSuppress() is called at all times.  There used to
be 1 very small window were it was skipped on initial startup
but I can't see any harm in calling it always.

Signed-off-by: Chris Bagwell <ch...@cnpbagwell.com>
---
 src/wcmCommon.c |   80 ++++++++++---------------------------------------
 src/wcmFilter.c |   88 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/wcmFilter.h |    1 +
 3 files changed, 103 insertions(+), 66 deletions(-)

diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index cd550ea..8aa8b17 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -23,6 +23,7 @@
 
 #include "xf86Wacom.h"
 #include "Xwacom.h"
+#include "wcmFilter.h"
 #include <xkbsrv.h>
 #include <xf86_OSproc.h>
 
@@ -37,7 +38,6 @@
 static void transPressureCurve(WacomDevicePtr pDev, WacomDeviceStatePtr 
pState);
 static void commonDispatchDevice(WacomCommonPtr common, unsigned int channel, 
        const WacomChannelPtr pChannel, int suppress);
-static void resetSampleCounter(const WacomChannelPtr pChannel);
 static void sendAButton(InputInfoPtr pInfo, int button, int mask,
                int rx, int ry, int rz, int v3, int v4, int v5);
 
@@ -848,19 +848,6 @@ static int wcmCheckSuppress(WacomCommonPtr common, const 
WacomDeviceState* dsOri
        return returnV;
 }
 
-/* reset raw data counters for filters */
-static void resetSampleCounter(const WacomChannelPtr pChannel)
-{
-       /* if out of proximity, reset hardware filter */
-       if (!pChannel->valid.state.proximity)
-       {
-               pChannel->nSamples = 0;
-               pChannel->rawFilter.npoints = 0;
-               pChannel->rawFilter.statex = 0;
-               pChannel->rawFilter.statey = 0;
-       }
-}
-
 /*****************************************************************************
  * wcmEvent -
  *   Handles suppression, transformation, filtering, and event dispatch.
@@ -872,8 +859,7 @@ void wcmEvent(WacomCommonPtr common, unsigned int channel,
        WacomDeviceState* pLast;
        WacomDeviceState ds;
        WacomChannelPtr pChannel;
-       WacomFilterState* fs;
-       int i, suppress = 0;
+       int suppress = 0;
        WacomDevicePtr priv = common->wcmDevices;
        pChannel = common->wcmChannel + channel;
        pLast = &pChannel->valid.state;
@@ -936,56 +922,24 @@ void wcmEvent(WacomCommonPtr common, unsigned int channel,
                wcmTilt2R(&ds);
        }
 
-       fs = &pChannel->rawFilter;
-       if (!fs->npoints && ds.proximity)
+       if (RAW_FILTERING(common) && common->wcmModel->FilterRaw &&
+           ds.device_type != PAD_ID)
        {
-               DBG(11, common, "initialize Channel data.\n");
-               /* store channel device state for later use */
-               for (i=common->wcmRawSample - 1; i>=0; i--)
-               {
-                       fs->x[i]= ds.x;
-                       fs->y[i]= ds.y;
-                       fs->tiltx[i] = ds.tiltx;
-                       fs->tilty[i] = ds.tilty;
-               }
-               ++fs->npoints;
-       } else  {
-               /* Filter raw data, fix hardware defects, perform error 
correction */
-               for (i=common->wcmRawSample - 1; i>0; i--)
-               {
-                       fs->x[i]= fs->x[i-1];
-                       fs->y[i]= fs->y[i-1];
-               }
-               fs->x[0] = ds.x;
-               fs->y[0] = ds.y;
-               if (HANDLE_TILT(common) && (ds.device_type == STYLUS_ID || 
ds.device_type == ERASER_ID))
-               {
-                       for (i=common->wcmRawSample - 1; i>0; i--)
-                       {
-                               fs->tiltx[i]= fs->tiltx[i-1];
-                               fs->tilty[i]= fs->tilty[i-1];
-                       }
-                       fs->tiltx[0] = ds.tiltx;
-                       fs->tilty[0] = ds.tilty;
-               }
-               if (RAW_FILTERING(common) && common->wcmModel->FilterRaw && 
ds.device_type != PAD_ID)
+               if (common->wcmModel->FilterRaw(common,pChannel,&ds))
                {
-                       if (common->wcmModel->FilterRaw(common,pChannel,&ds))
-                       {
-                               DBG(10, common,
-                                       "Raw filtering discarded data.\n");
-                               resetSampleCounter(pChannel);
-                               return; /* discard */
-                       }
+                       DBG(10, common,
+                           "Raw filtering discarded data.\n");
+                       wcmResetSampleCounter(pChannel);
+                       return; /* discard */
                }
+       }
 
-               /* Discard unwanted data */
-               suppress = wcmCheckSuppress(common, pLast, &ds);
-               if (!suppress)
-               {
-                       resetSampleCounter(pChannel);
-                       return;
-               }
+       /* Discard unwanted data */
+       suppress = wcmCheckSuppress(common, pLast, &ds);
+       if (!suppress)
+       {
+               wcmResetSampleCounter(pChannel);
+               return;
        }
 
        /* JEJ - Do not move this code without discussing it with me.
@@ -1013,7 +967,7 @@ void wcmEvent(WacomCommonPtr common, unsigned int channel,
            (ds.device_type != TOUCH_ID))
                commonDispatchDevice(common,channel,pChannel, suppress);
 ret:
-       resetSampleCounter(pChannel);
+       wcmResetSampleCounter(pChannel);
 }
 
 static int idtotype(int id)
diff --git a/src/wcmFilter.c b/src/wcmFilter.c
index f2cbec1..a7a6281 100644
--- a/src/wcmFilter.c
+++ b/src/wcmFilter.c
@@ -35,7 +35,7 @@ static void filterCurveToLine(int* pCurve, int nMax, double 
x0, double y0,
 static int filterOnLine(double x0, double y0, double x1, double y1,
                double a, double b);
 static void filterLine(int* pCurve, int nMax, int x0, int y0, int x1, int y1);
-static void filterIntuosStylus(WacomCommonPtr common, WacomFilterStatePtr 
state, WacomDeviceStatePtr ds);
+static void filterIntuosStylus(WacomCommonPtr common, WacomChannelPtr 
pChannel, WacomDeviceStatePtr ds);
 void wcmTilt2R(WacomDeviceStatePtr ds);
 
 
@@ -80,6 +80,25 @@ void wcmSetPressureCurve(WacomDevicePtr pDev, int x0, int y0,
        pDev->nPressCtrl[3] = y1;
 }
 
+/*
+ * wcmResetSampleCounter --
+ * Device specific filter routines are responcible for storing raw data
+ * as well as filtering.  wcmResetSampleCounter is called to reset
+ * raw counters.
+ */
+void wcmResetSampleCounter(const WacomChannelPtr pChannel)
+{
+       /* if out of proximity, reset hardware filter */
+       if (!pChannel->valid.state.proximity)
+       {
+               pChannel->nSamples = 0;
+               pChannel->rawFilter.npoints = 0;
+               pChannel->rawFilter.statex = 0;
+               pChannel->rawFilter.statey = 0;
+       }
+}
+
+
 static void filterNearestPoint(double x0, double y0, double x1, double y1,
                double a, double b, double* x, double* y)
 {
@@ -202,16 +221,73 @@ static void filterLine(int* pCurve, int nMax, int x0, int 
y0, int x1, int y1)
                }
        }
 }
+static void storeRawSample(WacomCommonPtr common, WacomChannelPtr pChannel,
+                          WacomDeviceStatePtr ds)
+{
+       WacomFilterState *fs;
+       int i;
 
+       fs = &pChannel->rawFilter;
+       if (!fs->npoints && ds->proximity)
+       {
+               DBG(10, common, "initialize channel data.\n");
+               /* Store initial value over whole average window */
+               for (i=common->wcmRawSample - 1; i>=0; i--)
+               {
+                       fs->x[i]= ds->x;
+                       fs->y[i]= ds->y;
+               }
+               if (HANDLE_TILT(common) && (ds->device_type == STYLUS_ID ||
+                                           ds->device_type == ERASER_ID))
+               {
+                       for (i=common->wcmRawSample - 1; i>=0; i--)
+                       {
+                               fs->tiltx[i] = ds->tiltx;
+                               fs->tilty[i] = ds->tilty;
+                       }
+               }
+               ++fs->npoints;
+       } else if (ds->proximity) {
+               /* Shift window and insert latest sample */
+               for (i=common->wcmRawSample - 1; i>0; i--)
+               {
+                       fs->x[i]= fs->x[i-1];
+                       fs->y[i]= fs->y[i-1];
+               }
+               fs->x[0] = ds->x;
+               fs->y[0] = ds->y;
+               if (HANDLE_TILT(common) && (ds->device_type == STYLUS_ID ||
+                                           ds->device_type == ERASER_ID))
+               {
+                       for (i=common->wcmRawSample - 1; i>0; i--)
+                       {
+                               fs->tiltx[i]= fs->tiltx[i-1];
+                               fs->tilty[i]= fs->tilty[i-1];
+                       }
+                       fs->tiltx[0] = ds->tiltx;
+                       fs->tilty[0] = ds->tilty;
+               }
+       }
+}
 /*****************************************************************************
  * filterIntuosStylus --
  *   Correct some hardware defects we've been seeing in Intuos pads,
  *   but also cuts down quite a bit on jitter.
  ****************************************************************************/
 
-static void filterIntuosStylus(WacomCommonPtr common, WacomFilterStatePtr 
state, WacomDeviceStatePtr ds)
+static void filterIntuosStylus(WacomCommonPtr common,
+                              WacomChannelPtr pChannel,
+                              WacomDeviceStatePtr ds)
 {
        int x=0, y=0, tx=0, ty=0, i;
+       WacomFilterState *state;
+
+       storeRawSample(common, pChannel, ds);
+
+       if (!ds->proximity)
+               return;
+
+       state = &pChannel->rawFilter;
 
        for ( i=0; i<common->wcmRawSample; i++ )
        {
@@ -250,6 +326,12 @@ int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr 
pChannel,
        int *x, *y, i; 
 
        DBG(10, common, "common->wcmRawSample = %d \n", common->wcmRawSample);
+
+       storeRawSample(common, pChannel, ds);
+
+       if (!ds->proximity)
+               return 0;
+
        x = pChannel->rawFilter.x;
        y = pChannel->rawFilter.y;
 
@@ -279,7 +361,7 @@ int wcmFilterIntuos(WacomCommonPtr common, WacomChannelPtr 
pChannel,
         * cannot be fixed, return 1 such that the data is discarded. */
 
        if (ds->device_type != CURSOR_ID)
-               filterIntuosStylus(common, &pChannel->rawFilter, ds);
+               filterIntuosStylus(common, pChannel, ds);
        else
                wcmFilterCoord(common, pChannel, ds);
 
diff --git a/src/wcmFilter.h b/src/wcmFilter.h
index db84dc9..3a8204d 100644
--- a/src/wcmFilter.h
+++ b/src/wcmFilter.h
@@ -30,6 +30,7 @@ int wcmFilterIntuos(WacomCommonPtr common, WacomChannelPtr 
pChannel,
        WacomDeviceStatePtr ds);
 int wcmFilterCoord(WacomCommonPtr common, WacomChannelPtr pChannel,
        WacomDeviceStatePtr ds);
+void wcmResetSampleCounter(const WacomChannelPtr pChannel);
 
 /****************************************************************************/
 #endif /* __XF86_WCMFILTER_H */
-- 
1.7.3.1


------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to