[PATCH 2/3] refactor scheme init

Simon Thum simon.thum at gmx.de
Sat Sep 4 07:31:24 PDT 2010


Signed-off-by: Simon Thum <simon.thum at gmx.de>
---
 dix/devices.c      |   54 ++++++++++++++++-----------------------------------
 dix/ptrveloc.c     |   32 +++++++++++++++++++++++-------
 include/input.h    |    4 +++
 include/inputstr.h |    1 +
 include/ptrveloc.h |    3 ++
 5 files changed, 49 insertions(+), 45 deletions(-)

diff --git a/dix/devices.c b/dix/devices.c
index 2e65a04..acde30c 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1286,10 +1286,11 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
 
 /* global list of acceleration schemes */
 ValuatorAccelerationRec pointerAccelerationScheme[] = {
-    {PtrAccelNoOp,        NULL, NULL, NULL},
-    {PtrAccelPredictable, acceleratePointerPredictable, NULL, AccelerationDefaultCleanup},
-    {PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL},
-    {-1, NULL, NULL, NULL} /* terminator */
+    {PtrAccelNoOp, NULL, NULL, NULL, NULL},
+    {PtrAccelPredictable, acceleratePointerPredictable, NULL,
+	InitPredictableAccelerationScheme, AccelerationDefaultCleanup},
+    {PtrAccelLightweight, acceleratePointerLightweight, NULL, NULL, NULL},
+    {-1, NULL, NULL, NULL, NULL} /* terminator */
 };
 
 /**
@@ -1301,59 +1302,38 @@ InitPointerAccelerationScheme(DeviceIntPtr dev,
                               int scheme)
 {
     int x, i = -1;
-    void* data = NULL;
     ValuatorClassPtr val;
+    ValuatorAccelerationPtr schemeRec;
 
     val = dev->valuator;
 
-    if(!val)
+    if (!val)
 	return FALSE;
 
-    if(IsMaster(dev) && scheme != PtrAccelNoOp)
+    if (IsMaster(dev) && scheme != PtrAccelNoOp)
         return FALSE;
 
-    for(x = 0; pointerAccelerationScheme[x].number >= 0; x++) {
+    for (x = 0; pointerAccelerationScheme[x].number >= 0; x++) {
         if(pointerAccelerationScheme[x].number == scheme){
             i = x;
             break;
         }
     }
 
-    if(-1 == i)
+    if (-1 == i)
         return FALSE;
 
     if (val->accelScheme.AccelCleanupProc)
         val->accelScheme.AccelCleanupProc(dev);
 
-    /* init scheme-specific data */
-    switch(scheme){
-        case PtrAccelPredictable:
-        {
-            DeviceVelocityPtr s;
-            s = malloc(sizeof(DeviceVelocityRec));
-            if(!s)
-        	return FALSE;
-            InitVelocityData(s);
-            data = s;
-            break;
-        }
-        default:
-            break;
+    if (pointerAccelerationScheme[i].AccelInitProc) {
+	schemeRec = pointerAccelerationScheme[i].AccelInitProc(dev);
+	if (!schemeRec)
+	    return FALSE;
+	val->accelScheme = *schemeRec;
+    } else {
+	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;
 }
 
diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 30e14b1..990bfe9 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -85,7 +85,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
 InitVelocityData(DeviceVelocityPtr vel)
@@ -107,7 +107,7 @@ InitVelocityData(DeviceVelocityPtr vel)
 
 
 /**
- * Clean up
+ * Clean up DeviceVelocityRec
  */
 void
 FreeVelocityData(DeviceVelocityPtr vel){
@@ -116,8 +116,26 @@ FreeVelocityData(DeviceVelocityPtr vel){
 }
 
 
-/*
- *  dix uninit helper, called through scheme
+/**
+ * Init predictable scheme
+ */
+ValuatorAccelerationPtr
+InitPredictableAccelerationScheme(DeviceIntPtr dev) {
+    DeviceVelocityPtr vel;
+    ValuatorAccelerationPtr scheme;
+    scheme = calloc(1, sizeof(ValuatorAccelerationRec));
+    vel = calloc(1, sizeof(DeviceVelocityRec));
+    if (!vel || !scheme)
+	return NULL;
+    InitVelocityData(vel);
+    scheme->accelData = vel;
+    InitializePredictableAccelerationProperties(dev);
+    return scheme;
+}
+
+
+/**
+ *  Uninit scheme
  */
 void
 AccelerationDefaultCleanup(DeviceIntPtr dev)
@@ -1026,12 +1044,10 @@ acceleratePointerPredictable(
     int *valuators,
     int evtime)
 {
-    float mult = 0.0;
+    float fdx, fdy, tmp, mult; /* no need to init */
     int dx = 0, dy = 0;
     int *px = NULL, *py = NULL;
-    DeviceVelocityPtr velocitydata =
-	(DeviceVelocityPtr) dev->valuator->accelScheme.accelData;
-    float fdx, fdy, tmp; /* no need to init */
+    DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
     Bool soften = TRUE;
 
     if (!num_valuators || !valuators || !velocitydata)
diff --git a/include/input.h b/include/input.h
index ffb1c33..a3967be 100644
--- a/include/input.h
+++ b/include/input.h
@@ -149,6 +149,10 @@ typedef void (*PointerAccelSchemeProc)(
 typedef void (*DeviceCallbackProc)(
               DeviceIntPtr /*pDev*/);
 
+struct _ValuatorAccelerationRec;
+typedef struct _ValuatorAccelerationRec* (*PointerAccelSchemeInitProc)(
+              DeviceIntPtr /*dev*/);
+
 typedef struct _DeviceRec {
     pointer	devicePrivate;
     ProcessInputProc processInputProc;	/* current */
diff --git a/include/inputstr.h b/include/inputstr.h
index 1b504e9..0e29b97 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -223,6 +223,7 @@ typedef struct _ValuatorAccelerationRec {
     int                         number;
     PointerAccelSchemeProc      AccelSchemeProc;
     void                       *accelData; /* at disposal of AccelScheme */
+    PointerAccelSchemeInitProc  AccelInitProc;
     DeviceCallbackProc          AccelCleanupProc;
 } ValuatorAccelerationRec, *ValuatorAccelerationPtr;
 
diff --git a/include/ptrveloc.h b/include/ptrveloc.h
index 6f999a8..db511be 100644
--- a/include/ptrveloc.h
+++ b/include/ptrveloc.h
@@ -129,6 +129,9 @@ SetDeviceSpecificAccelerationProfile(DeviceVelocityPtr vel,
 extern _X_INTERNAL void
 AccelerationDefaultCleanup(DeviceIntPtr dev);
 
+extern _X_INTERNAL struct _ValuatorAccelerationRec*
+InitPredictableAccelerationScheme(DeviceIntPtr dev);
+
 extern _X_INTERNAL void
 acceleratePointerPredictable(DeviceIntPtr dev, int first_valuator,
                              int num_valuators, int *valuators, int evtime);
-- 
1.7.1


--------------070002080801000903070402
Content-Type: text/plain;
 name="0003-refactor-predictable-scheme-initialization.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0003-refactor-predictable-scheme-initialization.patch"



More information about the xorg-devel mailing list