[PATCH v2 06/28] Input: Add double-precision valuator_mask API

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


Add API for valuator_mask that accepts and returns doubles, rather than
ints.  No double API is provided for set_range at the moment.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 dix/inpututils.c |   30 +++++++++++++++++++++++++-----
 include/input.h  |    5 +++++
 test/input.c     |   21 +++++++++++++++------
 3 files changed, 45 insertions(+), 11 deletions(-)

v2: Use valuator_mask_set_double from valuator_mask_set, rather than
    duplicating, likewise for _get.

diff --git a/dix/inpututils.c b/dix/inpututils.c
index 20132d5..a12ab77 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -497,10 +497,10 @@ valuator_mask_isset(const ValuatorMask *mask, int valuator)
 }
 
 /**
- * Set the valuator to the given data.
+ * Set the valuator to the given floating-point data.
  */
 void
-valuator_mask_set(ValuatorMask *mask, int valuator, int data)
+valuator_mask_set_double(ValuatorMask *mask, int valuator, double data)
 {
     mask->last_bit = max(valuator, mask->last_bit);
     SetBit(mask->mask, valuator);
@@ -508,13 +508,33 @@ valuator_mask_set(ValuatorMask *mask, int valuator, int data)
 }
 
 /**
- * Return the requested valuator value. If the mask bit is not set for the
- * given valuator, the returned value is undefined.
+ * Set the valuator to the given integer data.
+ */
+void
+valuator_mask_set(ValuatorMask *mask, int valuator, int data)
+{
+    valuator_mask_set_double(mask, valuator, data);
+}
+
+/**
+ * Return the requested valuator value as a double. If the mask bit is not
+ * set for the given valuator, the returned value is undefined.
+ */
+double
+valuator_mask_get_double(const ValuatorMask *mask, int valuator)
+{
+    return mask->valuators[valuator];
+}
+
+/**
+ * Return the requested valuator value as an integer, rounding towards zero.
+ * If the mask bit is not set for the given valuator, the returned value is
+ * undefined.
  */
 int
 valuator_mask_get(const ValuatorMask *mask, int valuator)
 {
-    return trunc(mask->valuators[valuator]);
+    return trunc(valuator_mask_get_double(mask, valuator));
 }
 
 /**
diff --git a/include/input.h b/include/input.h
index 56847ed..512e12c 100644
--- a/include/input.h
+++ b/include/input.h
@@ -585,6 +585,9 @@ extern _X_EXPORT void valuator_mask_set_range(ValuatorMask *mask,
 extern _X_EXPORT void valuator_mask_set(ValuatorMask *mask,
                                         int valuator,
                                         int data);
+extern _X_EXPORT void valuator_mask_set_double(ValuatorMask *mask,
+                                               int valuator,
+                                               double data);
 extern _X_EXPORT void valuator_mask_zero(ValuatorMask *mask);
 extern _X_EXPORT int valuator_mask_size(const ValuatorMask *mask);
 extern _X_EXPORT int valuator_mask_isset(const ValuatorMask *mask, int bit);
@@ -593,5 +596,7 @@ extern _X_EXPORT int valuator_mask_num_valuators(const ValuatorMask *mask);
 extern _X_EXPORT void valuator_mask_copy(ValuatorMask *dest,
                                          const ValuatorMask *src);
 extern _X_EXPORT int valuator_mask_get(const ValuatorMask *mask, int valnum);
+extern _X_EXPORT double valuator_mask_get_double(const ValuatorMask *mask,
+                                                 int valnum);
 
 #endif /* INPUT_H */
diff --git a/test/input.c b/test/input.c
index 837ce49..04bb11c 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1089,12 +1089,16 @@ static void dix_input_valuator_masks(void)
 {
     ValuatorMask *mask = NULL, *copy;
     int nvaluators = MAX_VALUATORS;
-    int valuators[nvaluators];
+    double valuators[nvaluators];
+    int val_ranged[nvaluators];
     int i;
     int first_val, num_vals;
 
     for (i = 0; i < nvaluators; i++)
-        valuators[i] = i;
+    {
+        valuators[i] = i + 0.5;
+        val_ranged[i] = i;
+    }
 
     mask = valuator_mask_new(nvaluators);
     assert(mask != NULL);
@@ -1104,9 +1108,10 @@ static void dix_input_valuator_masks(void)
     for (i = 0; i < nvaluators; i++)
     {
         assert(!valuator_mask_isset(mask, i));
-        valuator_mask_set(mask, i, valuators[i]);
+        valuator_mask_set_double(mask, i, valuators[i]);
         assert(valuator_mask_isset(mask, i));
-        assert(valuator_mask_get(mask, i) == valuators[i]);
+        assert(valuator_mask_get(mask, i) == trunc(valuators[i]));
+        assert(valuator_mask_get_double(mask, i) == valuators[i]);
         assert(valuator_mask_size(mask) == i + 1);
         assert(valuator_mask_num_valuators(mask) == i + 1);
     }
@@ -1132,7 +1137,7 @@ static void dix_input_valuator_masks(void)
     first_val = 5;
     num_vals = 6;
 
-    valuator_mask_set_range(mask, first_val, num_vals, valuators);
+    valuator_mask_set_range(mask, first_val, num_vals, val_ranged);
     assert(valuator_mask_size(mask) == first_val + num_vals);
     assert(valuator_mask_num_valuators(mask) == num_vals);
     for (i = 0; i < nvaluators; i++)
@@ -1142,7 +1147,9 @@ static void dix_input_valuator_masks(void)
         else
         {
             assert(valuator_mask_isset(mask, i));
-            assert(valuator_mask_get(mask, i) == valuators[i - first_val]);
+            assert(valuator_mask_get(mask, i) == val_ranged[i - first_val]);
+            assert(valuator_mask_get_double(mask, i) ==
+                    val_ranged[i - first_val]);
         }
     }
 
@@ -1156,6 +1163,8 @@ static void dix_input_valuator_masks(void)
     {
         assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
         assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
+        assert(valuator_mask_get_double(mask, i) ==
+                valuator_mask_get_double(copy, i));
     }
 
     valuator_mask_free(&mask);
-- 
1.7.5.3



More information about the xorg-devel mailing list