On Fri, Nov 11, 2016 at 09:36:24AM -0800, 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>
Reviewed-by: Peter Hutterer <peter.hutte...@who-t.net> thanks, happy now :) Cheers, Peter > --- > Changes from v2: > * Use affirmative (instead of negating) check for default (0,0,100,100) > case. > * Shuffle code to reduce duplication. > * Log warning in case of memory allocation failure. > * Be even lazier (don't go through a free/calloc cycle if pPressCurve is > already allocated). > > Peter: > I'm not totally happy with leaving the nPressCtrl points set to the wrong > value if a memory allocation failure happens. I suppose strict correctness > is probably moot in this situation since the server probably isn't long > for this world once we can't allocate a few hundred KB, but still... :/ > > I've re-shuffled things to try and minimize the amount of repeating of > myself -- let me know if its any better. > > src/wcmCommon.c | 5 ++++- > src/wcmFilter.c | 38 +++++++++++++++++++++++++------------- > src/xf86WacomDefs.h | 3 +-- > 3 files changed, 30 insertions(+), 16 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..aca5cd9 100644 > --- a/src/wcmFilter.c > +++ b/src/wcmFilter.c > @@ -54,23 +54,35 @@ 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; > - > - /* draw bezier line from bottom-left to top-right using ctrl points */ > - filterCurveToLine(pDev->pPressCurve, > - FILTER_PRESSURE_RES, > - 0.0, 0.0, /* bottom left */ > - x0/100.0, y0/100.0, /* control point 1 */ > - x1/100.0, y1/100.0, /* control point 2 */ > - 1.0, 1.0); /* top right */ > + /* A NULL pPressCurve indicates the (default) linear curve */ > + if (x0 == 0 && y0 == 0 && x1 == 100 && y1 == 100) { > + free(pDev->pPressCurve); > + pDev->pPressCurve = NULL; > + } > + else if (!pDev->pPressCurve) { > + pDev->pPressCurve = calloc(FILTER_PRESSURE_RES+1, > sizeof(*pDev->pPressCurve)); > + > + if (!pDev->pPressCurve) { > + LogMessageVerbSigSafe(X_WARNING, 0, > + "Unable to allocate memory for > pressure curve; using default.\n"); > + x0 = 0; > + y0 = 0; > + x1 = 100; > + y1 = 100; > + } > + } > + > + if (pDev->pPressCurve) > + filterCurveToLine(pDev->pPressCurve, > + FILTER_PRESSURE_RES, > + 0.0, 0.0, /* bottom left */ > + 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; > diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h > index 3961545..b10a114 100644 > --- a/src/xf86WacomDefs.h > +++ b/src/xf86WacomDefs.h > @@ -285,8 +285,7 @@ struct _WacomDeviceRec > struct _WacomDeviceState oldState; /* previous state information */ > int oldCursorHwProx; /* previous cursor hardware proximity */ > > - /* JEJ - filters */ > - 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