[PATCH 04/27] Input: Add double-precision valuator_mask API

Peter Hutterer peter.hutterer at who-t.net
Mon Jun 6 21:51:06 PDT 2011


On Fri, Jun 03, 2011 at 03:59:40PM +0100, Daniel Stone wrote:
> 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>
> ---
>  dix/inpututils.c |   28 +++++++++++++++++++++++++---
>  include/input.h  |    5 +++++
>  test/input.c     |   21 +++++++++++++++------
>  3 files changed, 45 insertions(+), 9 deletions(-)
> 
> diff --git a/dix/inpututils.c b/dix/inpututils.c
> index 085a6b4..07adbb5 100644
> --- a/dix/inpututils.c
> +++ b/dix/inpututils.c
> @@ -497,7 +497,7 @@ valuator_mask_isset(const ValuatorMask *mask, int valuator)
>  }
>  
>  /**
> - * Set the valuator to the given data.
> + * Set the valuator to the given integer data.
>   */
>  void
>  valuator_mask_set(ValuatorMask *mask, int valuator, int data)
> @@ -508,8 +508,20 @@ 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 floating-point data.
> + */
> +void
> +valuator_mask_set_double(ValuatorMask *mask, int valuator, double data)
> +{
> +    mask->last_bit = max(valuator, mask->last_bit);
> +    SetBit(mask->mask, valuator);
> +    mask->valuators[valuator] = data;
> +}

given that the function does a bit more than just a single assignment, it
may be worth changing valuator_mask_set to call valuator_mask_set_double
instead of duplicating the three lines.

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net> either way though.

Cheers,
  Peter

> +
> +/**
> + * 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)
> @@ -518,6 +530,16 @@ valuator_mask_get(const ValuatorMask *mask, int valuator)
>  }
>  
>  /**
> + * 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];
> +}
> +
> +/**
>   * Remove the valuator from the mask.
>   */
>  void
> diff --git a/include/input.h b/include/input.h
> index a15623a..db56b25 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,6 +596,8 @@ 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);
>  
>  extern _X_EXPORT double round_towards_zero(double val);
>  
> diff --git a/test/input.c b/test/input.c
> index ac37d67..0d72fb8 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) == round_towards_zero(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
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list