[PATCH 21/28] Input: Make RawDeviceEvent use doubles internally

Daniel Stone daniel at fooishbar.org
Thu Jun 9 10:17:29 PDT 2011


Change RawDeviceEvent to use doubles for valuators internally, rather
than data(_raw) and data(_raw)_frac.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 dix/eventconvert.c               |   13 ++++++++-----
 dix/getevents.c                  |   20 ++++++--------------
 include/eventstr.h               |    6 ++----
 test/xi2/protocol-eventconvert.c |   14 ++++++--------
 4 files changed, 22 insertions(+), 31 deletions(-)

diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index fa8ba9e..54e9020 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -649,7 +649,7 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
     int vallen, nvals;
     int i, len = sizeof(xXIRawEvent);
     char *ptr;
-    FP3232 *axisval;
+    FP3232 *axisval, *axisval_raw;
 
     nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask));
     len += nvals * sizeof(FP3232) * 2; /* 8 byte per valuator, once
@@ -671,16 +671,19 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
 
     ptr = (char*)&raw[1];
     axisval = (FP3232*)(ptr + raw->valuators_len * 4);
+    axisval_raw = axisval + nvals;
     for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++)
     {
         if (BitIsOn(ev->valuators.mask, i))
         {
             SetBit(ptr, i);
-            axisval->integral = ev->valuators.data[i];
-            axisval->frac = ev->valuators.data_frac[i];
-            (axisval + nvals)->integral = ev->valuators.data_raw[i];
-            (axisval + nvals)->frac = ev->valuators.data_raw_frac[i];
+            axisval->integral = trunc(ev->valuators.data[i]);
+            axisval->frac = ev->valuators.data[i] - axisval->integral;
+            axisval_raw->integral = trunc(ev->valuators.data_raw[i]);
+            axisval_raw->frac = ev->valuators.data_raw[i] -
+                                axisval_raw->integral;
             axisval++;
+            axisval_raw++;
         }
     }
 
diff --git a/dix/getevents.c b/dix/getevents.c
index 9eecfdd..331613a 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -178,20 +178,16 @@ init_raw(DeviceIntPtr dev, RawDeviceEvent *event, Time ms, int type, int detail)
 }
 
 static void
-set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, int32_t* data,
-                  int32_t* data_frac)
+set_raw_valuators(RawDeviceEvent *event, ValuatorMask *mask, double* data)
 {
     int i;
-    double val;
 
     for (i = 0; i < valuator_mask_size(mask); i++)
     {
         if (valuator_mask_isset(mask, i))
         {
             SetBit(event->valuators.mask, i);
-            val = valuator_mask_get_double(mask, i);
-            data[i] = trunc(val);
-            data_frac[i] = (val - data[i]) * (1UL << 32);
+            data[i] = valuator_mask_get_double(mask, i);
         }
     }
 }
@@ -969,13 +965,11 @@ GetKeyboardEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     valuator_mask_copy(&mask, mask_in);
 
     init_raw(pDev, raw, ms, type, key_code);
-    set_raw_valuators(raw, &mask, raw->valuators.data_raw,
-                      raw->valuators.data_raw_frac);
+    set_raw_valuators(raw, &mask, raw->valuators.data_raw);
 
     clipValuators(pDev, &mask);
 
-    set_raw_valuators(raw, &mask, raw->valuators.data,
-                      raw->valuators.data_frac);
+    set_raw_valuators(raw, &mask, raw->valuators.data);
 
     event = &events->device_event;
     init_event(pDev, event, ms);
@@ -1145,8 +1139,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
     valuator_mask_copy(&mask, mask_in);
 
     init_raw(pDev, raw, ms, type, buttons);
-    set_raw_valuators(raw, &mask, raw->valuators.data_raw,
-                      raw->valuators.data_raw_frac);
+    set_raw_valuators(raw, &mask, raw->valuators.data_raw);
 
     if (flags & POINTER_ABSOLUTE)
     {
@@ -1178,8 +1171,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
         moveRelative(pDev, &mask);
     }
 
-    set_raw_valuators(raw, &mask, raw->valuators.data,
-                      raw->valuators.data_frac);
+    set_raw_valuators(raw, &mask, raw->valuators.data);
 
     positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative, scr,
                    &mask, &screenx, &screeny);
diff --git a/include/eventstr.h b/include/eventstr.h
index ecaeddc..0645585 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -199,10 +199,8 @@ struct _RawDeviceEvent
     } detail;
     struct {
         uint8_t  mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
-        int32_t  data[MAX_VALUATORS];         /**< Valuator data */
-        int32_t  data_frac[MAX_VALUATORS];    /**< Fractional part for data */
-        int32_t  data_raw[MAX_VALUATORS];     /**< Valuator data as posted */
-        int32_t  data_raw_frac[MAX_VALUATORS];/**< Fractional part for data_raw */
+        double   data[MAX_VALUATORS];         /**< Valuator data */
+        double   data_raw[MAX_VALUATORS];     /**< Valuator data as posted */
     } valuators;
     uint32_t flags;       /**< Flags to be copied into the generated event */
 };
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 5eb4531..2e915e8 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -95,8 +95,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
             value = (FP3232*)(((unsigned char*)&out[1]) + out->valuators_len * 4);
             value += nvals;
 
-            vi.integral = in->valuators.data[i];
-            vi.frac = in->valuators.data_frac[i];
+            vi.integral = trunc(in->valuators.data[i]);
+            vi.frac = in->valuators.data[i] - vi.integral;
 
             vo.integral = value->integral;
             vo.frac = value->frac;
@@ -112,8 +112,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
 
             raw_value = value + bits_set;
 
-            vi.integral = in->valuators.data_raw[i];
-            vi.frac = in->valuators.data_raw_frac[i];
+            vi.integral = trunc(in->valuators.data_raw[i]);
+            vi.frac = in->valuators.data_raw[i] - vi.integral;
 
             vo.integral = raw_value->integral;
             vo.frac = raw_value->frac;
@@ -252,10 +252,8 @@ static void test_convert_XIRawEvent(void)
     {
         XISetMask(in.valuators.mask, i);
 
-        in.valuators.data[i] = i;
-        in.valuators.data_raw[i] = i + 10;
-        in.valuators.data_frac[i] = i + 20;
-        in.valuators.data_raw_frac[i] = i + 30;
+        in.valuators.data[i] = i + (i * 0.0010);
+        in.valuators.data_raw[i] = (i + 10) + (i * 0.0030);
         test_XIRawEvent(&in);
         XIClearMask(in.valuators.mask, i);
     }
-- 
1.7.5.3



More information about the xorg-devel mailing list