On Tue, Nov 01, 2016 at 11:43:43AM -0700, Jason Gerecke wrote:
> Now that the pressure curve contains 65K points it takes up quite a bit
> of memory, especially considering that the pressure curve may not need
> to exist for some devices (e.g. pads) and may just be the default linear
> curve even for those where it should exist. To reduce the amount of
> memory used, we now lazily allocate space for the pressure curve tables
> only when they are set to a non-default curve.
> 
> Signed-off-by: Jason Gerecke <jason.gere...@wacom.com>
> ---
> Changes from v1:
>  * Added this patch to lazilly allocate the pressure curve as requested
> 
>  src/wcmCommon.c     |  5 ++++-
>  src/wcmFilter.c     | 30 ++++++++++++++++++++----------
>  src/xf86WacomDefs.h |  2 +-
>  3 files changed, 25 insertions(+), 12 deletions(-)
> 
> diff --git a/src/wcmCommon.c b/src/wcmCommon.c
> index 0ba0304..28e5488 100644
> --- a/src/wcmCommon.c
> +++ b/src/wcmCommon.c
> @@ -1395,7 +1395,10 @@ static int applyPressureCurve(WacomDevicePtr pDev, 
> const WacomDeviceStatePtr pSt
>       p = min(FILTER_PRESSURE_RES, p);
>  
>       /* apply pressure curve function */
> -     return pDev->pPressCurve[p];
> +     if (pDev->pPressCurve == NULL)
> +             return p;
> +     else
> +             return pDev->pPressCurve[p];
>  }
>  
>  
> /*****************************************************************************
> diff --git a/src/wcmFilter.c b/src/wcmFilter.c
> index e55ef0f..7ef6349 100644
> --- a/src/wcmFilter.c
> +++ b/src/wcmFilter.c
> @@ -54,15 +54,30 @@ int wcmCheckPressureCurveValues(int x0, int y0, int x1, 
> int y1)
>  void wcmSetPressureCurve(WacomDevicePtr pDev, int x0, int y0,
>       int x1, int y1)
>  {
> -     int i;
> -
>       /* sanity check values */
>       if (!wcmCheckPressureCurveValues(x0, y0, x1, y1))
>               return;
>  
> -     /* linear by default */
> -     for (i=0; i<=FILTER_PRESSURE_RES; ++i)
> -             pDev->pPressCurve[i] = i;
> +     free(pDev->pPressCurve);
> +     pDev->pPressCurve = NULL;
> +
> +     if (!(x0 == 0 && y0 == 0 && x1 == 100 && y1 == 100)) {

not a big fan of if (!(foo == x), very easy to overlook. You can just use 
x0 != 0 || y0 != 0 ... here (but see below)

> +             pDev->pPressCurve = calloc(FILTER_PRESSURE_RES+1, 
> sizeof(*pDev->pPressCurve));
> +     }
> +
> +     /* A NULL pPressCurve indicates the (default) linear curve */
> +     if (!pDev->pPressCurve) {
> +             pDev->nPressCtrl[0] = 0;
> +             pDev->nPressCtrl[1] = 0;
> +             pDev->nPressCtrl[2] = 100;
> +             pDev->nPressCtrl[3] = 100;
> +             return;
> +     }
> +
> +     pDev->nPressCtrl[0] = x0;
> +     pDev->nPressCtrl[1] = y0;
> +     pDev->nPressCtrl[2] = x1;
> +     pDev->nPressCtrl[3] = y1;

you can reshuffle this to save on code: 

        pDev->nPressCtrl[0] = x0;
        pDev->nPressCtrl[1] = y0;
        pDev->nPressCtrl[2] = x1;
        pDev->nPressCtrl[3] = y1;

        if (x0 == 0 && y0 == 0 && x1 == 100 && y1 == 100)
                return;

        calloc now
        
if calloc fails, print an error message and return. you could go back and
reset the control points to defaults, but for this niche case you might as
well keep going and just rely on applyPressureCurve() to not access a NULL
curve.


>  
>       /* draw bezier line from bottom-left to top-right using ctrl points */
>       filterCurveToLine(pDev->pPressCurve,
> @@ -71,11 +86,6 @@ void wcmSetPressureCurve(WacomDevicePtr pDev, int x0, int 
> y0,
>               x0/100.0, y0/100.0,     /* control point 1 */
>               x1/100.0, y1/100.0,     /* control point 2 */
>               1.0, 1.0);              /* top right */
> -
> -     pDev->nPressCtrl[0] = x0;
> -     pDev->nPressCtrl[1] = y0;
> -     pDev->nPressCtrl[2] = x1;
> -     pDev->nPressCtrl[3] = y1;
>  }
>  
>  /*
> diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
> index 3961545..c03d5d9 100644
> --- a/src/xf86WacomDefs.h
> +++ b/src/xf86WacomDefs.h
> @@ -286,7 +286,7 @@ struct _WacomDeviceRec
>       int oldCursorHwProx;    /* previous cursor hardware proximity */
>  
>       /* JEJ - filters */

want to remove ^^ while we're at it? doesn't serve much purpose anymore.

Cheers,
   Peter

> -     int pPressCurve[FILTER_PRESSURE_RES + 1]; /* pressure curve */
> +     int *pPressCurve;       /* pressure curve */
>       int nPressCtrl[4];      /* control points for curve */
>       int minPressure;        /* the minimum pressure a pen may hold */
>       int oldMinPressure;     /* to record the last minPressure before going 
> out of proximity */
> -- 
> 2.10.1
> 

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to