[PATCH 22/27] Input: Make RawDeviceEvent use doubles internally
Daniel Stone
daniel at fooishbar.org
Fri Jun 3 07:59:58 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>
---
dix/eventconvert.c | 14 +++++++++-----
dix/getevents.c | 20 ++++++--------------
include/eventstr.h | 6 ++----
test/xi2/protocol-eventconvert.c | 14 ++++++--------
4 files changed, 23 insertions(+), 31 deletions(-)
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index ced770e..62777db 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -835,7 +835,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
@@ -856,16 +856,20 @@ 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 = round_towards_zero(ev->valuators.data[i]);
+ axisval->frac = ev->valuators.data[i] - axisval->integral;
+ axisval_raw->integral =
+ round_towards_zero(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 de779b2..2abf0f8 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -179,20 +179,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] = round_towards_zero(val);
- data_frac[i] = (val - data[i]) * (1UL << 32);
+ data[i] = valuator_mask_get_double(mask, i);
}
}
}
@@ -971,13 +967,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);
@@ -1132,8 +1126,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)
{
@@ -1165,8 +1158,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 365b19d..ebe0d7a 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -207,10 +207,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;
};
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 34e9155..0041e7e 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -94,8 +94,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 = round_towards_zero(in->valuators.data[i]);
+ vi.frac = in->valuators.data[i] - vi.integral;
vo.integral = value->integral;
vo.frac = value->frac;
@@ -111,8 +111,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 = round_towards_zero(in->valuators.data_raw[i]);
+ vi.frac = in->valuators.data_raw[i] - vi.integral;
vo.integral = raw_value->integral;
vo.frac = raw_value->frac;
@@ -251,10 +251,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