dix: refactor scheme init
This makes it possible to init a scheme in one init call, so we get rid of the tightly coupled two-phase init used before. Signed-off-by: Simon Thum <simon.thum@gmx.de> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
38ffeec0c8
commit
006157f203
|
@ -1279,10 +1279,11 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
|
||||||
|
|
||||||
/* global list of acceleration schemes */
|
/* global list of acceleration schemes */
|
||||||
ValuatorAccelerationRec pointerAccelerationScheme[] = {
|
ValuatorAccelerationRec pointerAccelerationScheme[] = {
|
||||||
{PtrAccelNoOp, NULL, NULL, NULL},
|
{PtrAccelNoOp, NULL, NULL, NULL, NULL},
|
||||||
{PtrAccelPredictable, acceleratePointerPredictable, NULL, AccelerationDefaultCleanup},
|
{PtrAccelPredictable, acceleratePointerPredictable, NULL,
|
||||||
{PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL},
|
InitPredictableAccelerationScheme, AccelerationDefaultCleanup},
|
||||||
{-1, NULL, NULL, NULL} /* terminator */
|
{PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL, NULL},
|
||||||
|
{-1, NULL, NULL, NULL, NULL} /* terminator */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1294,7 +1295,6 @@ InitPointerAccelerationScheme(DeviceIntPtr dev,
|
||||||
int scheme)
|
int scheme)
|
||||||
{
|
{
|
||||||
int x, i = -1;
|
int x, i = -1;
|
||||||
void* data = NULL;
|
|
||||||
ValuatorClassPtr val;
|
ValuatorClassPtr val;
|
||||||
|
|
||||||
val = dev->valuator;
|
val = dev->valuator;
|
||||||
|
@ -1318,35 +1318,14 @@ InitPointerAccelerationScheme(DeviceIntPtr dev,
|
||||||
if (val->accelScheme.AccelCleanupProc)
|
if (val->accelScheme.AccelCleanupProc)
|
||||||
val->accelScheme.AccelCleanupProc(dev);
|
val->accelScheme.AccelCleanupProc(dev);
|
||||||
|
|
||||||
/* init scheme-specific data */
|
if (pointerAccelerationScheme[i].AccelInitProc) {
|
||||||
switch(scheme){
|
if (!pointerAccelerationScheme[i].AccelInitProc(dev,
|
||||||
case PtrAccelPredictable:
|
&pointerAccelerationScheme[i])) {
|
||||||
{
|
|
||||||
DeviceVelocityPtr s;
|
|
||||||
s = malloc(sizeof(DeviceVelocityRec));
|
|
||||||
if(!s)
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
InitVelocityData(s);
|
|
||||||
data = s;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default:
|
} else {
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
val->accelScheme = pointerAccelerationScheme[i];
|
val->accelScheme = pointerAccelerationScheme[i];
|
||||||
val->accelScheme.accelData = data;
|
|
||||||
|
|
||||||
/* post-init scheme */
|
|
||||||
switch(scheme){
|
|
||||||
case PtrAccelPredictable:
|
|
||||||
InitializePredictableAccelerationProperties(dev);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,10 @@ SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, float velocity,
|
||||||
float threshold, float acc);
|
float threshold, float acc);
|
||||||
static PointerAccelerationProfileFunc
|
static PointerAccelerationProfileFunc
|
||||||
GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
|
GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
|
||||||
|
static BOOL
|
||||||
|
InitializePredictableAccelerationProperties(DeviceIntPtr dev);
|
||||||
|
static BOOL
|
||||||
|
DeletePredictableAccelerationProperties(DeviceIntPtr dev);
|
||||||
|
|
||||||
/*#define PTRACCEL_DEBUGGING*/
|
/*#define PTRACCEL_DEBUGGING*/
|
||||||
|
|
||||||
|
@ -85,7 +89,7 @@ GetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init struct so it should match the average case
|
* Init DeviceVelocity struct so it should match the average case
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
InitVelocityData(DeviceVelocityPtr vel)
|
InitVelocityData(DeviceVelocityPtr vel)
|
||||||
|
@ -107,7 +111,7 @@ InitVelocityData(DeviceVelocityPtr vel)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up
|
* Clean up DeviceVelocityRec
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
FreeVelocityData(DeviceVelocityPtr vel){
|
FreeVelocityData(DeviceVelocityPtr vel){
|
||||||
|
@ -116,8 +120,28 @@ FreeVelocityData(DeviceVelocityPtr vel){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* dix uninit helper, called through scheme
|
* Init predictable scheme
|
||||||
|
*/
|
||||||
|
Bool
|
||||||
|
InitPredictableAccelerationScheme(DeviceIntPtr dev,
|
||||||
|
ValuatorAccelerationPtr protoScheme) {
|
||||||
|
DeviceVelocityPtr vel;
|
||||||
|
ValuatorAccelerationRec scheme;
|
||||||
|
scheme = *protoScheme;
|
||||||
|
vel = calloc(1, sizeof(DeviceVelocityRec));
|
||||||
|
if (!vel)
|
||||||
|
return FALSE;
|
||||||
|
InitVelocityData(vel);
|
||||||
|
scheme.accelData = vel;
|
||||||
|
dev->valuator->accelScheme = scheme;
|
||||||
|
InitializePredictableAccelerationProperties(dev);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uninit scheme
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
AccelerationDefaultCleanup(DeviceIntPtr dev)
|
AccelerationDefaultCleanup(DeviceIntPtr dev)
|
||||||
|
@ -1024,12 +1048,10 @@ acceleratePointerPredictable(
|
||||||
int *valuators,
|
int *valuators,
|
||||||
int evtime)
|
int evtime)
|
||||||
{
|
{
|
||||||
float mult = 0.0;
|
float fdx, fdy, tmp, mult; /* no need to init */
|
||||||
int dx = 0, dy = 0;
|
int dx = 0, dy = 0;
|
||||||
int *px = NULL, *py = NULL;
|
int *px = NULL, *py = NULL;
|
||||||
DeviceVelocityPtr velocitydata =
|
DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
|
||||||
(DeviceVelocityPtr) dev->valuator->accelScheme.accelData;
|
|
||||||
float fdx, fdy, tmp; /* no need to init */
|
|
||||||
Bool soften = TRUE;
|
Bool soften = TRUE;
|
||||||
|
|
||||||
if (!num_valuators || !valuators || !velocitydata)
|
if (!num_valuators || !valuators || !velocitydata)
|
||||||
|
|
|
@ -150,6 +150,11 @@ typedef void (*PointerAccelSchemeProc)(
|
||||||
typedef void (*DeviceCallbackProc)(
|
typedef void (*DeviceCallbackProc)(
|
||||||
DeviceIntPtr /*pDev*/);
|
DeviceIntPtr /*pDev*/);
|
||||||
|
|
||||||
|
struct _ValuatorAccelerationRec;
|
||||||
|
typedef Bool (*PointerAccelSchemeInitProc)(
|
||||||
|
DeviceIntPtr /*dev*/,
|
||||||
|
struct _ValuatorAccelerationRec* /*protoScheme*/);
|
||||||
|
|
||||||
typedef struct _DeviceRec {
|
typedef struct _DeviceRec {
|
||||||
pointer devicePrivate;
|
pointer devicePrivate;
|
||||||
ProcessInputProc processInputProc; /* current */
|
ProcessInputProc processInputProc; /* current */
|
||||||
|
|
|
@ -266,6 +266,7 @@ typedef struct _ValuatorAccelerationRec {
|
||||||
int number;
|
int number;
|
||||||
PointerAccelSchemeProc AccelSchemeProc;
|
PointerAccelSchemeProc AccelSchemeProc;
|
||||||
void *accelData; /* at disposal of AccelScheme */
|
void *accelData; /* at disposal of AccelScheme */
|
||||||
|
PointerAccelSchemeInitProc AccelInitProc;
|
||||||
DeviceCallbackProc AccelCleanupProc;
|
DeviceCallbackProc AccelCleanupProc;
|
||||||
} ValuatorAccelerationRec, *ValuatorAccelerationPtr;
|
} ValuatorAccelerationRec, *ValuatorAccelerationPtr;
|
||||||
|
|
||||||
|
|
|
@ -110,12 +110,6 @@ BasicComputeAcceleration(DeviceIntPtr dev, DeviceVelocityPtr vel,
|
||||||
extern _X_EXPORT void
|
extern _X_EXPORT void
|
||||||
FreeVelocityData(DeviceVelocityPtr vel);
|
FreeVelocityData(DeviceVelocityPtr vel);
|
||||||
|
|
||||||
extern _X_INTERNAL BOOL
|
|
||||||
InitializePredictableAccelerationProperties(DeviceIntPtr dev);
|
|
||||||
|
|
||||||
extern _X_INTERNAL BOOL
|
|
||||||
DeletePredictableAccelerationProperties(DeviceIntPtr dev);
|
|
||||||
|
|
||||||
extern _X_EXPORT int
|
extern _X_EXPORT int
|
||||||
SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
|
SetAccelerationProfile(DeviceVelocityPtr vel, int profile_num);
|
||||||
|
|
||||||
|
@ -129,6 +123,10 @@ SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel,
|
||||||
extern _X_INTERNAL void
|
extern _X_INTERNAL void
|
||||||
AccelerationDefaultCleanup(DeviceIntPtr dev);
|
AccelerationDefaultCleanup(DeviceIntPtr dev);
|
||||||
|
|
||||||
|
extern _X_INTERNAL Bool
|
||||||
|
InitPredictableAccelerationScheme(DeviceIntPtr dev,
|
||||||
|
struct _ValuatorAccelerationRec* protoScheme);
|
||||||
|
|
||||||
extern _X_INTERNAL void
|
extern _X_INTERNAL void
|
||||||
acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator,
|
acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator,
|
||||||
int num_valuators, int *valuators, int evtime);
|
int num_valuators, int *valuators, int evtime);
|
||||||
|
|
Loading…
Reference in New Issue