dix: improve pointer acceleration API

This makes the ptr accel api actually sensible from a driver
perspective, since it avoids superfluous device lookups.
Also, makes independent accel contexts possible.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Simon Thum 2009-06-24 11:16:24 +02:00 committed by Peter Hutterer
parent b8050bb6de
commit 373e8c960d
2 changed files with 54 additions and 30 deletions

View File

@ -63,7 +63,7 @@
int int
SetAccelerationProfile(DeviceVelocityPtr s, int profile_num); SetAccelerationProfile(DeviceVelocityPtr s, int profile_num);
static float static float
SimpleSmoothProfile(DeviceVelocityPtr pVel, float velocity, SimpleSmoothProfile(DeviceIntPtr dev, DeviceVelocityPtr vel, float velocity,
float threshold, float acc); float threshold, float acc);
static PointerAccelerationProfileFunc static PointerAccelerationProfileFunc
GetAccelerationProfile(DeviceVelocityPtr s, int profile_num); GetAccelerationProfile(DeviceVelocityPtr s, int profile_num);
@ -108,7 +108,7 @@ InitVelocityData(DeviceVelocityPtr s)
/** /**
* Clean up * Clean up
*/ */
static void void
FreeVelocityData(DeviceVelocityPtr s){ FreeVelocityData(DeviceVelocityPtr s){
xfree(s->tracker); xfree(s->tracker);
SetAccelerationProfile(s, PROFILE_UNINITIALIZE); SetAccelerationProfile(s, PROFILE_UNINITIALIZE);
@ -555,7 +555,7 @@ QueryTrackers(DeviceVelocityPtr s, int cur_t){
* Perform velocity approximation based on 2D 'mickeys' (mouse motion delta). * Perform velocity approximation based on 2D 'mickeys' (mouse motion delta).
* return true if non-visible state reset is suggested * return true if non-visible state reset is suggested
*/ */
static short short
ProcessVelocityData2D( ProcessVelocityData2D(
DeviceVelocityPtr s, DeviceVelocityPtr s,
int dx, int dx,
@ -616,19 +616,20 @@ ApplySofteningAndConstantDeceleration(
/* /*
* compute the acceleration for given velocity and enforce min_acceleartion * compute the acceleration for given velocity and enforce min_acceleartion
*/ */
static float float
BasicComputeAcceleration( BasicComputeAcceleration(
DeviceVelocityPtr pVel, DeviceIntPtr dev,
DeviceVelocityPtr vel,
float velocity, float velocity,
float threshold, float threshold,
float acc){ float acc){
float result; float result;
result = pVel->Profile(pVel, velocity, threshold, acc); result = vel->Profile(dev, vel, velocity, threshold, acc);
/* enforce min_acceleration */ /* enforce min_acceleration */
if (result < pVel->min_acceleration) if (result < vel->min_acceleration)
result = pVel->min_acceleration; result = vel->min_acceleration;
return result; return result;
} }
@ -637,6 +638,7 @@ BasicComputeAcceleration(
*/ */
static float static float
ComputeAcceleration( ComputeAcceleration(
DeviceIntPtr dev,
DeviceVelocityPtr vel, DeviceVelocityPtr vel,
float threshold, float threshold,
float acc){ float acc){
@ -655,9 +657,11 @@ ComputeAcceleration(
* current and previous velocity. * current and previous velocity.
* Though being the more natural choice, it causes a minor delay * Though being the more natural choice, it causes a minor delay
* in comparison, so it can be disabled. */ * in comparison, so it can be disabled. */
res = BasicComputeAcceleration(vel, vel->velocity, threshold, acc); res = BasicComputeAcceleration(
res += BasicComputeAcceleration(vel, vel->last_velocity, threshold, acc); dev, vel, vel->velocity, threshold, acc);
res += 4.0f * BasicComputeAcceleration(vel, res += BasicComputeAcceleration(
dev, vel, vel->last_velocity, threshold, acc);
res += 4.0f * BasicComputeAcceleration(dev, vel,
(vel->last_velocity + vel->velocity) / 2, (vel->last_velocity + vel->velocity) / 2,
threshold, acc); threshold, acc);
res /= 6.0f; res /= 6.0f;
@ -665,7 +669,8 @@ ComputeAcceleration(
vel->velocity, vel->last_velocity, res); vel->velocity, vel->last_velocity, res);
return res; return res;
}else{ }else{
res = BasicComputeAcceleration(vel, vel->velocity, threshold, acc); res = BasicComputeAcceleration(dev, vel,
vel->velocity, threshold, acc);
DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n", DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n",
vel->velocity, res); vel->velocity, res);
return res; return res;
@ -682,7 +687,8 @@ ComputeAcceleration(
*/ */
static float static float
PolynomialAccelerationProfile( PolynomialAccelerationProfile(
DeviceVelocityPtr pVel, DeviceIntPtr dev,
DeviceVelocityPtr vel,
float velocity, float velocity,
float ignored, float ignored,
float acc) float acc)
@ -697,18 +703,21 @@ PolynomialAccelerationProfile(
*/ */
static float static float
ClassicProfile( ClassicProfile(
DeviceVelocityPtr pVel, DeviceIntPtr dev,
DeviceVelocityPtr vel,
float velocity, float velocity,
float threshold, float threshold,
float acc) float acc)
{ {
if (threshold) { if (threshold > 0) {
return SimpleSmoothProfile (pVel, return SimpleSmoothProfile (dev,
vel,
velocity, velocity,
threshold, threshold,
acc); acc);
} else { } else {
return PolynomialAccelerationProfile (pVel, return PolynomialAccelerationProfile (dev,
vel,
velocity, velocity,
0, 0,
acc); acc);
@ -726,7 +735,8 @@ ClassicProfile(
*/ */
static float static float
PowerProfile( PowerProfile(
DeviceVelocityPtr pVel, DeviceIntPtr dev,
DeviceVelocityPtr vel,
float velocity, float velocity,
float threshold, float threshold,
float acc) float acc)
@ -736,9 +746,9 @@ PowerProfile(
acc = (acc-1.0) * 0.1f + 1.0; /* without this, acc of 2 is unuseable */ acc = (acc-1.0) * 0.1f + 1.0; /* without this, acc of 2 is unuseable */
if (velocity <= threshold) if (velocity <= threshold)
return pVel->min_acceleration; return vel->min_acceleration;
vel_dist = velocity - threshold; vel_dist = velocity - threshold;
return (pow(acc, vel_dist)) * pVel->min_acceleration; return (pow(acc, vel_dist)) * vel->min_acceleration;
} }
@ -763,7 +773,8 @@ CalcPenumbralGradient(float x){
*/ */
static float static float
SimpleSmoothProfile( SimpleSmoothProfile(
DeviceVelocityPtr pVel, DeviceIntPtr dev,
DeviceVelocityPtr vel,
float velocity, float velocity,
float threshold, float threshold,
float acc) float acc)
@ -788,7 +799,8 @@ SimpleSmoothProfile(
*/ */
static float static float
SmoothLinearProfile( SmoothLinearProfile(
DeviceVelocityPtr pVel, DeviceIntPtr dev,
DeviceVelocityPtr vel,
float velocity, float velocity,
float threshold, float threshold,
float acc) float acc)
@ -811,14 +823,15 @@ SmoothLinearProfile(
res = nv * 2.0f / M_PI /* steepness of gradient at 0.5 */ res = nv * 2.0f / M_PI /* steepness of gradient at 0.5 */
+ 1.0f; /* gradient crosses 2|1 */ + 1.0f; /* gradient crosses 2|1 */
} }
res += pVel->min_acceleration; res += vel->min_acceleration;
return res; return res;
} }
static float static float
LinearProfile( LinearProfile(
DeviceVelocityPtr pVel, DeviceIntPtr dev,
DeviceVelocityPtr vel,
float velocity, float velocity,
float threshold, float threshold,
float acc) float acc)
@ -829,7 +842,8 @@ LinearProfile(
static float static float
NoProfile( NoProfile(
DeviceVelocityPtr pVel, DeviceIntPtr dev,
DeviceVelocityPtr vel,
float velocity, float velocity,
float threshold, float threshold,
float acc) float acc)
@ -992,7 +1006,7 @@ acceleratePointerPredictable(
if (pDev->ptrfeed && pDev->ptrfeed->ctrl.num) { if (pDev->ptrfeed && pDev->ptrfeed->ctrl.num) {
/* invoke acceleration profile to determine acceleration */ /* invoke acceleration profile to determine acceleration */
mult = ComputeAcceleration (velocitydata, mult = ComputeAcceleration (pDev, velocitydata,
pDev->ptrfeed->ctrl.threshold, pDev->ptrfeed->ctrl.threshold,
(float)pDev->ptrfeed->ctrl.num / (float)pDev->ptrfeed->ctrl.num /
(float)pDev->ptrfeed->ctrl.den); (float)pDev->ptrfeed->ctrl.den);

View File

@ -1,6 +1,6 @@
/* /*
* *
* Copyright © 2006-2008 Simon Thum simon dot thum at gmx dot de * Copyright © 2006-2009 Simon Thum simon dot thum at gmx dot de
* *
* Permission is hereby granted, free of charge, to any person obtaining a * Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"), * copy of this software and associated documentation files (the "Software"),
@ -47,8 +47,8 @@ struct _DeviceVelocityRec;
* returns actual acceleration depending on velocity, acceleration control,... * returns actual acceleration depending on velocity, acceleration control,...
*/ */
typedef float (*PointerAccelerationProfileFunc) typedef float (*PointerAccelerationProfileFunc)
(struct _DeviceVelocityRec* /*pVel*/, (DeviceIntPtr dev, struct _DeviceVelocityRec* vel,
float /*velocity*/, float /*threshold*/, float /*acc*/); float velocity, float threshold, float accelCoeff);
/** /**
* a motion history, with just enough information to * a motion history, with just enough information to
@ -96,8 +96,18 @@ InitVelocityData(DeviceVelocityPtr s);
extern _X_EXPORT void extern _X_EXPORT void
InitTrackers(DeviceVelocityPtr s, int ntracker); InitTrackers(DeviceVelocityPtr s, int ntracker);
extern _X_EXPORT short
ProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time);
extern _X_EXPORT float
BasicComputeAcceleration(DeviceIntPtr dev, DeviceVelocityPtr vel,
float velocity, float threshold, float acc);
extern _X_EXPORT void
FreeVelocityData(DeviceVelocityPtr vel);
extern _X_EXPORT BOOL extern _X_EXPORT BOOL
InitializePredictableAccelerationProperties(DeviceIntPtr pDev); InitializePredictableAccelerationProperties(DeviceIntPtr dev);
extern _X_EXPORT int extern _X_EXPORT int
SetAccelerationProfile(DeviceVelocityPtr s, int profile_num); SetAccelerationProfile(DeviceVelocityPtr s, int profile_num);