summaryrefslogtreecommitdiffstats
path: root/services/input/InputReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/input/InputReader.cpp')
-rw-r--r--services/input/InputReader.cpp356
1 files changed, 222 insertions, 134 deletions
diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp
index cd6a2ec..bc8df18 100644
--- a/services/input/InputReader.cpp
+++ b/services/input/InputReader.cpp
@@ -203,34 +203,18 @@ static void synthesizeButtonKeys(InputReaderContext* context, int32_t action,
// --- InputReaderConfiguration ---
-bool InputReaderConfiguration::getDisplayInfo(int32_t displayId, bool external,
- int32_t* width, int32_t* height, int32_t* orientation) const {
- if (displayId == 0) {
- const DisplayInfo& info = external ? mExternalDisplay : mInternalDisplay;
- if (info.width > 0 && info.height > 0) {
- if (width) {
- *width = info.width;
- }
- if (height) {
- *height = info.height;
- }
- if (orientation) {
- *orientation = info.orientation;
- }
- return true;
- }
+bool InputReaderConfiguration::getDisplayInfo(bool external, DisplayViewport* outViewport) const {
+ const DisplayViewport& viewport = external ? mExternalDisplay : mInternalDisplay;
+ if (viewport.displayId >= 0) {
+ *outViewport = viewport;
+ return true;
}
return false;
}
-void InputReaderConfiguration::setDisplayInfo(int32_t displayId, bool external,
- int32_t width, int32_t height, int32_t orientation) {
- if (displayId == 0) {
- DisplayInfo& info = external ? mExternalDisplay : mInternalDisplay;
- info.width = width;
- info.height = height;
- info.orientation = orientation;
- }
+void InputReaderConfiguration::setDisplayInfo(bool external, const DisplayViewport& viewport) {
+ DisplayViewport& v = external ? mExternalDisplay : mInternalDisplay;
+ v = viewport;
}
@@ -972,8 +956,9 @@ void InputDevice::process(const RawEvent* rawEvents, size_t count) {
size_t numMappers = mMappers.size();
for (const RawEvent* rawEvent = rawEvents; count--; rawEvent++) {
#if DEBUG_RAW_EVENTS
- ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x",
- rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value);
+ ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%lld",
+ rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value,
+ rawEvent->when);
#endif
if (mDropUntilNextSync) {
@@ -1816,7 +1801,7 @@ void InputMapper::dumpRawAbsoluteAxisInfo(String8& dump,
// --- SwitchInputMapper ---
SwitchInputMapper::SwitchInputMapper(InputDevice* device) :
- InputMapper(device) {
+ InputMapper(device), mUpdatedSwitchValues(0), mUpdatedSwitchMask(0) {
}
SwitchInputMapper::~SwitchInputMapper() {
@@ -1829,14 +1814,33 @@ uint32_t SwitchInputMapper::getSources() {
void SwitchInputMapper::process(const RawEvent* rawEvent) {
switch (rawEvent->type) {
case EV_SW:
- processSwitch(rawEvent->when, rawEvent->code, rawEvent->value);
+ processSwitch(rawEvent->code, rawEvent->value);
break;
+
+ case EV_SYN:
+ if (rawEvent->code == SYN_REPORT) {
+ sync(rawEvent->when);
+ }
}
}
-void SwitchInputMapper::processSwitch(nsecs_t when, int32_t switchCode, int32_t switchValue) {
- NotifySwitchArgs args(when, 0, switchCode, switchValue);
- getListener()->notifySwitch(&args);
+void SwitchInputMapper::processSwitch(int32_t switchCode, int32_t switchValue) {
+ if (switchCode >= 0 && switchCode < 32) {
+ if (switchValue) {
+ mUpdatedSwitchValues |= 1 << switchCode;
+ }
+ mUpdatedSwitchMask |= 1 << switchCode;
+ }
+}
+
+void SwitchInputMapper::sync(nsecs_t when) {
+ if (mUpdatedSwitchMask) {
+ NotifySwitchArgs args(when, 0, mUpdatedSwitchValues, mUpdatedSwitchMask);
+ getListener()->notifySwitch(&args);
+
+ mUpdatedSwitchValues = 0;
+ mUpdatedSwitchMask = 0;
+ }
}
int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
@@ -2001,9 +2005,11 @@ void KeyboardInputMapper::configure(nsecs_t when,
}
if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
- if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0) {
- if (!config->getDisplayInfo(mParameters.associatedDisplayId,
- false /*external*/, NULL, NULL, &mOrientation)) {
+ if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
+ DisplayViewport v;
+ if (config->getDisplayInfo(false /*external*/, &v)) {
+ mOrientation = v.orientation;
+ } else {
mOrientation = DISPLAY_ORIENTATION_0;
}
} else {
@@ -2017,16 +2023,16 @@ void KeyboardInputMapper::configureParameters() {
getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"),
mParameters.orientationAware);
- mParameters.associatedDisplayId = -1;
+ mParameters.hasAssociatedDisplay = false;
if (mParameters.orientationAware) {
- mParameters.associatedDisplayId = 0;
+ mParameters.hasAssociatedDisplay = true;
}
}
void KeyboardInputMapper::dumpParameters(String8& dump) {
dump.append(INDENT3 "Parameters:\n");
- dump.appendFormat(INDENT4 "AssociatedDisplayId: %d\n",
- mParameters.associatedDisplayId);
+ dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n",
+ toString(mParameters.hasAssociatedDisplay));
dump.appendFormat(INDENT4 "OrientationAware: %s\n",
toString(mParameters.orientationAware));
}
@@ -2086,7 +2092,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
if (down) {
// Rotate key codes according to orientation if needed.
- if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0) {
+ if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
keyCode = rotateKeyCode(keyCode, mOrientation);
}
@@ -2317,9 +2323,11 @@ void CursorInputMapper::configure(nsecs_t when,
}
if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
- if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0) {
- if (!config->getDisplayInfo(mParameters.associatedDisplayId,
- false /*external*/, NULL, NULL, &mOrientation)) {
+ if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
+ DisplayViewport v;
+ if (config->getDisplayInfo(false /*external*/, &v)) {
+ mOrientation = v.orientation;
+ } else {
mOrientation = DISPLAY_ORIENTATION_0;
}
} else {
@@ -2344,16 +2352,16 @@ void CursorInputMapper::configureParameters() {
getDevice()->getConfiguration().tryGetProperty(String8("cursor.orientationAware"),
mParameters.orientationAware);
- mParameters.associatedDisplayId = -1;
+ mParameters.hasAssociatedDisplay = false;
if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
- mParameters.associatedDisplayId = 0;
+ mParameters.hasAssociatedDisplay = true;
}
}
void CursorInputMapper::dumpParameters(String8& dump) {
dump.append(INDENT3 "Parameters:\n");
- dump.appendFormat(INDENT4 "AssociatedDisplayId: %d\n",
- mParameters.associatedDisplayId);
+ dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n",
+ toString(mParameters.hasAssociatedDisplay));
switch (mParameters.mode) {
case Parameters::MODE_POINTER:
@@ -2420,7 +2428,7 @@ void CursorInputMapper::sync(nsecs_t when) {
bool moved = deltaX != 0 || deltaY != 0;
// Rotate delta according to orientation if needed.
- if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0
+ if (mParameters.orientationAware && mParameters.hasAssociatedDisplay
&& (deltaX != 0.0f || deltaY != 0.0f)) {
rotateDelta(mOrientation, &deltaX, &deltaY);
}
@@ -2443,6 +2451,7 @@ void CursorInputMapper::sync(nsecs_t when) {
mPointerVelocityControl.move(when, &deltaX, &deltaY);
+ int32_t displayId;
if (mPointerController != NULL) {
if (moved || scrolled || buttonsChanged) {
mPointerController->setPresentation(
@@ -2463,9 +2472,11 @@ void CursorInputMapper::sync(nsecs_t when) {
mPointerController->getPosition(&x, &y);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+ displayId = ADISPLAY_ID_DEFAULT;
} else {
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
+ displayId = ADISPLAY_ID_NONE;
}
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, down ? 1.0f : 0.0f);
@@ -2497,7 +2508,8 @@ void CursorInputMapper::sync(nsecs_t when) {
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
motionEventAction, 0, metaState, currentButtonState, 0,
- 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime);
+ displayId, 1, &pointerProperties, &pointerCoords,
+ mXPrecision, mYPrecision, downTime);
getListener()->notifyMotion(&args);
// Send hover move after UP to tell the application that the mouse is hovering now.
@@ -2506,7 +2518,8 @@ void CursorInputMapper::sync(nsecs_t when) {
NotifyMotionArgs hoverArgs(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
metaState, currentButtonState, AMOTION_EVENT_EDGE_FLAG_NONE,
- 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime);
+ displayId, 1, &pointerProperties, &pointerCoords,
+ mXPrecision, mYPrecision, downTime);
getListener()->notifyMotion(&hoverArgs);
}
@@ -2518,7 +2531,8 @@ void CursorInputMapper::sync(nsecs_t when) {
NotifyMotionArgs scrollArgs(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_SCROLL, 0, metaState, currentButtonState,
AMOTION_EVENT_EDGE_FLAG_NONE,
- 1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime);
+ displayId, 1, &pointerProperties, &pointerCoords,
+ mXPrecision, mYPrecision, downTime);
getListener()->notifyMotion(&scrollArgs);
}
}
@@ -2551,7 +2565,8 @@ void CursorInputMapper::fadePointer() {
TouchInputMapper::TouchInputMapper(InputDevice* device) :
InputMapper(device),
mSource(0), mDeviceMode(DEVICE_MODE_DISABLED),
- mSurfaceOrientation(-1), mSurfaceWidth(-1), mSurfaceHeight(-1) {
+ mSurfaceWidth(-1), mSurfaceHeight(-1), mSurfaceLeft(0), mSurfaceTop(0),
+ mSurfaceOrientation(DISPLAY_ORIENTATION_0) {
}
TouchInputMapper::~TouchInputMapper() {
@@ -2613,6 +2628,8 @@ void TouchInputMapper::dump(String8& dump) {
dumpSurface(dump);
dump.appendFormat(INDENT3 "Translation and Scaling Factors:\n");
+ dump.appendFormat(INDENT4 "XTranslate: %0.3f\n", mXTranslate);
+ dump.appendFormat(INDENT4 "YTranslate: %0.3f\n", mYTranslate);
dump.appendFormat(INDENT4 "XScale: %0.3f\n", mXScale);
dump.appendFormat(INDENT4 "YScale: %0.3f\n", mYScale);
dump.appendFormat(INDENT4 "XPrecision: %0.3f\n", mXPrecision);
@@ -2620,7 +2637,6 @@ void TouchInputMapper::dump(String8& dump) {
dump.appendFormat(INDENT4 "GeometricScale: %0.3f\n", mGeometricScale);
dump.appendFormat(INDENT4 "PressureScale: %0.3f\n", mPressureScale);
dump.appendFormat(INDENT4 "SizeScale: %0.3f\n", mSizeScale);
- dump.appendFormat(INDENT4 "OrientationCenter: %0.3f\n", mOrientationCenter);
dump.appendFormat(INDENT4 "OrientationScale: %0.3f\n", mOrientationScale);
dump.appendFormat(INDENT4 "DistanceScale: %0.3f\n", mDistanceScale);
dump.appendFormat(INDENT4 "HaveTilt: %s\n", toString(mHaveTilt));
@@ -2783,15 +2799,15 @@ void TouchInputMapper::configureParameters() {
getDevice()->getConfiguration().tryGetProperty(String8("touch.orientationAware"),
mParameters.orientationAware);
- mParameters.associatedDisplayId = -1;
+ mParameters.hasAssociatedDisplay = false;
mParameters.associatedDisplayIsExternal = false;
if (mParameters.orientationAware
|| mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
|| mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) {
+ mParameters.hasAssociatedDisplay = true;
mParameters.associatedDisplayIsExternal =
mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
&& getDevice()->isExternal();
- mParameters.associatedDisplayId = 0;
}
}
@@ -2823,8 +2839,9 @@ void TouchInputMapper::dumpParameters(String8& dump) {
ALOG_ASSERT(false);
}
- dump.appendFormat(INDENT4 "AssociatedDisplay: id=%d, isExternal=%s\n",
- mParameters.associatedDisplayId, toString(mParameters.associatedDisplayIsExternal));
+ dump.appendFormat(INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s\n",
+ toString(mParameters.hasAssociatedDisplay),
+ toString(mParameters.associatedDisplayIsExternal));
dump.appendFormat(INDENT4 "OrientationAware: %s\n",
toString(mParameters.orientationAware));
}
@@ -2862,7 +2879,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
mSource |= AINPUT_SOURCE_STYLUS;
}
} else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
- && mParameters.associatedDisplayId >= 0) {
+ && mParameters.hasAssociatedDisplay) {
mSource = AINPUT_SOURCE_TOUCHSCREEN;
mDeviceMode = DEVICE_MODE_DIRECT;
if (hasStylus()) {
@@ -2881,32 +2898,93 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
return;
}
+ // Raw width and height in the natural orientation.
+ int32_t rawWidth = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
+ int32_t rawHeight = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
+
// Get associated display dimensions.
- if (mParameters.associatedDisplayId >= 0) {
- if (!mConfig.getDisplayInfo(mParameters.associatedDisplayId,
- mParameters.associatedDisplayIsExternal,
- &mAssociatedDisplayWidth, &mAssociatedDisplayHeight,
- &mAssociatedDisplayOrientation)) {
+ bool viewportChanged = false;
+ DisplayViewport newViewport;
+ if (mParameters.hasAssociatedDisplay) {
+ if (!mConfig.getDisplayInfo(mParameters.associatedDisplayIsExternal, &newViewport)) {
ALOGI(INDENT "Touch device '%s' could not query the properties of its associated "
- "display %d. The device will be inoperable until the display size "
+ "display. The device will be inoperable until the display size "
"becomes available.",
- getDeviceName().string(), mParameters.associatedDisplayId);
+ getDeviceName().string());
mDeviceMode = DEVICE_MODE_DISABLED;
return;
}
- }
-
- // Configure dimensions.
- int32_t width, height, orientation;
- if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
- width = mAssociatedDisplayWidth;
- height = mAssociatedDisplayHeight;
- orientation = mParameters.orientationAware ?
- mAssociatedDisplayOrientation : DISPLAY_ORIENTATION_0;
} else {
- width = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
- height = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
- orientation = DISPLAY_ORIENTATION_0;
+ newViewport.setNonDisplayViewport(rawWidth, rawHeight);
+ }
+ if (mViewport != newViewport) {
+ mViewport = newViewport;
+ viewportChanged = true;
+
+ if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
+ // Convert rotated viewport to natural surface coordinates.
+ int32_t naturalLogicalWidth, naturalLogicalHeight;
+ int32_t naturalPhysicalWidth, naturalPhysicalHeight;
+ int32_t naturalPhysicalLeft, naturalPhysicalTop;
+ int32_t naturalDeviceWidth, naturalDeviceHeight;
+ switch (mViewport.orientation) {
+ case DISPLAY_ORIENTATION_90:
+ naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
+ naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
+ naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop;
+ naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft;
+ naturalPhysicalLeft = mViewport.deviceHeight - mViewport.physicalBottom;
+ naturalPhysicalTop = mViewport.physicalLeft;
+ naturalDeviceWidth = mViewport.deviceHeight;
+ naturalDeviceHeight = mViewport.deviceWidth;
+ break;
+ case DISPLAY_ORIENTATION_180:
+ naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft;
+ naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop;
+ naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft;
+ naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop;
+ naturalPhysicalLeft = mViewport.deviceWidth - mViewport.physicalRight;
+ naturalPhysicalTop = mViewport.deviceHeight - mViewport.physicalBottom;
+ naturalDeviceWidth = mViewport.deviceWidth;
+ naturalDeviceHeight = mViewport.deviceHeight;
+ break;
+ case DISPLAY_ORIENTATION_270:
+ naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
+ naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
+ naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop;
+ naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft;
+ naturalPhysicalLeft = mViewport.physicalTop;
+ naturalPhysicalTop = mViewport.deviceWidth - mViewport.physicalRight;
+ naturalDeviceWidth = mViewport.deviceHeight;
+ naturalDeviceHeight = mViewport.deviceWidth;
+ break;
+ case DISPLAY_ORIENTATION_0:
+ default:
+ naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft;
+ naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop;
+ naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft;
+ naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop;
+ naturalPhysicalLeft = mViewport.physicalLeft;
+ naturalPhysicalTop = mViewport.physicalTop;
+ naturalDeviceWidth = mViewport.deviceWidth;
+ naturalDeviceHeight = mViewport.deviceHeight;
+ break;
+ }
+
+ mSurfaceWidth = naturalLogicalWidth * naturalDeviceWidth / naturalPhysicalWidth;
+ mSurfaceHeight = naturalLogicalHeight * naturalDeviceHeight / naturalPhysicalHeight;
+ mSurfaceLeft = naturalPhysicalLeft * naturalLogicalWidth / naturalPhysicalWidth;
+ mSurfaceTop = naturalPhysicalTop * naturalLogicalHeight / naturalPhysicalHeight;
+
+ mSurfaceOrientation = mParameters.orientationAware ?
+ mViewport.orientation : DISPLAY_ORIENTATION_0;
+ } else {
+ mSurfaceWidth = rawWidth;
+ mSurfaceHeight = rawHeight;
+ mSurfaceLeft = 0;
+ mSurfaceTop = 0;
+ mSurfaceOrientation = DISPLAY_ORIENTATION_0;
+ }
}
// If moving between pointer modes, need to reset some state.
@@ -2926,22 +3004,17 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
mPointerController.clear();
}
- bool orientationChanged = mSurfaceOrientation != orientation;
- if (orientationChanged) {
- mSurfaceOrientation = orientation;
- }
-
- bool sizeChanged = mSurfaceWidth != width || mSurfaceHeight != height;
- if (sizeChanged || deviceModeChanged) {
- ALOGI("Device reconfigured: id=%d, name='%s', surface size is now %dx%d, mode is %d",
- getDeviceId(), getDeviceName().string(), width, height, mDeviceMode);
-
- mSurfaceWidth = width;
- mSurfaceHeight = height;
+ if (viewportChanged || deviceModeChanged) {
+ ALOGI("Device reconfigured: id=%d, name='%s', size %dx%d, orientation %d, mode %d, "
+ "display id %d",
+ getDeviceId(), getDeviceName().string(), mSurfaceWidth, mSurfaceHeight,
+ mSurfaceOrientation, mDeviceMode, mViewport.displayId);
// Configure X and Y factors.
- mXScale = float(width) / (mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1);
- mYScale = float(height) / (mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1);
+ mXScale = float(mSurfaceWidth) / rawWidth;
+ mYScale = float(mSurfaceHeight) / rawHeight;
+ mXTranslate = -mSurfaceLeft;
+ mYTranslate = -mSurfaceTop;
mXPrecision = 1.0f / mXScale;
mYPrecision = 1.0f / mYScale;
@@ -2958,7 +3031,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
mGeometricScale = avg(mXScale, mYScale);
// Size of diagonal axis.
- float diagonalSize = hypotf(width, height);
+ float diagonalSize = hypotf(mSurfaceWidth, mSurfaceHeight);
// Size factors.
if (mCalibration.sizeCalibration != Calibration::SIZE_CALIBRATION_NONE) {
@@ -3051,7 +3124,6 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
}
// Orientation
- mOrientationCenter = 0;
mOrientationScale = 0;
if (mHaveTilt) {
mOrientedRanges.haveOrientation = true;
@@ -3067,10 +3139,13 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
if (mCalibration.orientationCalibration
== Calibration::ORIENTATION_CALIBRATION_INTERPOLATED) {
if (mRawPointerAxes.orientation.valid) {
- mOrientationCenter = avg(mRawPointerAxes.orientation.minValue,
- mRawPointerAxes.orientation.maxValue);
- mOrientationScale = M_PI / (mRawPointerAxes.orientation.maxValue -
- mRawPointerAxes.orientation.minValue);
+ if (mRawPointerAxes.orientation.maxValue > 0) {
+ mOrientationScale = M_PI_2 / mRawPointerAxes.orientation.maxValue;
+ } else if (mRawPointerAxes.orientation.minValue < 0) {
+ mOrientationScale = -M_PI_2 / mRawPointerAxes.orientation.minValue;
+ } else {
+ mOrientationScale = 0;
+ }
}
}
@@ -3108,50 +3183,38 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
mOrientedRanges.distance.fuzz =
mRawPointerAxes.distance.fuzz * mDistanceScale;
}
- }
- if (orientationChanged || sizeChanged || deviceModeChanged) {
- // Compute oriented surface dimensions, precision, scales and ranges.
+ // Compute oriented precision, scales and ranges.
// Note that the maximum value reported is an inclusive maximum value so it is one
// unit less than the total width or height of surface.
switch (mSurfaceOrientation) {
case DISPLAY_ORIENTATION_90:
case DISPLAY_ORIENTATION_270:
- mOrientedSurfaceWidth = mSurfaceHeight;
- mOrientedSurfaceHeight = mSurfaceWidth;
-
mOrientedXPrecision = mYPrecision;
mOrientedYPrecision = mXPrecision;
- mOrientedRanges.x.min = 0;
- mOrientedRanges.x.max = (mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue)
- * mYScale;
+ mOrientedRanges.x.min = mYTranslate;
+ mOrientedRanges.x.max = mSurfaceHeight + mYTranslate - 1;
mOrientedRanges.x.flat = 0;
mOrientedRanges.x.fuzz = mYScale;
- mOrientedRanges.y.min = 0;
- mOrientedRanges.y.max = (mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue)
- * mXScale;
+ mOrientedRanges.y.min = mXTranslate;
+ mOrientedRanges.y.max = mSurfaceWidth + mXTranslate - 1;
mOrientedRanges.y.flat = 0;
mOrientedRanges.y.fuzz = mXScale;
break;
default:
- mOrientedSurfaceWidth = mSurfaceWidth;
- mOrientedSurfaceHeight = mSurfaceHeight;
-
mOrientedXPrecision = mXPrecision;
mOrientedYPrecision = mYPrecision;
- mOrientedRanges.x.min = 0;
- mOrientedRanges.x.max = (mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue)
- * mXScale;
+ mOrientedRanges.x.min = mXTranslate;
+ mOrientedRanges.x.max = mSurfaceWidth + mXTranslate - 1;
mOrientedRanges.x.flat = 0;
mOrientedRanges.x.fuzz = mXScale;
- mOrientedRanges.y.min = 0;
- mOrientedRanges.y.max = (mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue)
- * mYScale;
+ mOrientedRanges.y.min = mYTranslate;
+ mOrientedRanges.y.max = mSurfaceHeight + mYTranslate - 1;
mOrientedRanges.y.flat = 0;
mOrientedRanges.y.fuzz = mYScale;
break;
@@ -3159,11 +3222,8 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
// Compute pointer gesture detection parameters.
if (mDeviceMode == DEVICE_MODE_POINTER) {
- int32_t rawWidth = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
- int32_t rawHeight = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
float rawDiagonal = hypotf(rawWidth, rawHeight);
- float displayDiagonal = hypotf(mAssociatedDisplayWidth,
- mAssociatedDisplayHeight);
+ float displayDiagonal = hypotf(mSurfaceWidth, mSurfaceHeight);
// Scale movements such that one whole swipe of the touch pad covers a
// given area relative to the diagonal size of the display when no acceleration
@@ -3198,8 +3258,21 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
}
void TouchInputMapper::dumpSurface(String8& dump) {
+ dump.appendFormat(INDENT3 "Viewport: displayId=%d, orientation=%d, "
+ "logicalFrame=[%d, %d, %d, %d], "
+ "physicalFrame=[%d, %d, %d, %d], "
+ "deviceSize=[%d, %d]\n",
+ mViewport.displayId, mViewport.orientation,
+ mViewport.logicalLeft, mViewport.logicalTop,
+ mViewport.logicalRight, mViewport.logicalBottom,
+ mViewport.physicalLeft, mViewport.physicalTop,
+ mViewport.physicalRight, mViewport.physicalBottom,
+ mViewport.deviceWidth, mViewport.deviceHeight);
+
dump.appendFormat(INDENT3 "SurfaceWidth: %dpx\n", mSurfaceWidth);
dump.appendFormat(INDENT3 "SurfaceHeight: %dpx\n", mSurfaceHeight);
+ dump.appendFormat(INDENT3 "SurfaceLeft: %d\n", mSurfaceLeft);
+ dump.appendFormat(INDENT3 "SurfaceTop: %d\n", mSurfaceTop);
dump.appendFormat(INDENT3 "SurfaceOrientation: %d\n", mSurfaceOrientation);
}
@@ -3284,6 +3357,8 @@ void TouchInputMapper::parseCalibration() {
out.sizeCalibration = Calibration::SIZE_CALIBRATION_GEOMETRIC;
} else if (sizeCalibrationString == "diameter") {
out.sizeCalibration = Calibration::SIZE_CALIBRATION_DIAMETER;
+ } else if (sizeCalibrationString == "box") {
+ out.sizeCalibration = Calibration::SIZE_CALIBRATION_BOX;
} else if (sizeCalibrationString == "area") {
out.sizeCalibration = Calibration::SIZE_CALIBRATION_AREA;
} else if (sizeCalibrationString != "default") {
@@ -3404,6 +3479,9 @@ void TouchInputMapper::dumpCalibration(String8& dump) {
case Calibration::SIZE_CALIBRATION_DIAMETER:
dump.append(INDENT4 "touch.size.calibration: diameter\n");
break;
+ case Calibration::SIZE_CALIBRATION_BOX:
+ dump.append(INDENT4 "touch.size.calibration: box\n");
+ break;
case Calibration::SIZE_CALIBRATION_AREA:
dump.append(INDENT4 "touch.size.calibration: area\n");
break;
@@ -3954,6 +4032,7 @@ void TouchInputMapper::cookPointerData() {
switch (mCalibration.sizeCalibration) {
case Calibration::SIZE_CALIBRATION_GEOMETRIC:
case Calibration::SIZE_CALIBRATION_DIAMETER:
+ case Calibration::SIZE_CALIBRATION_BOX:
case Calibration::SIZE_CALIBRATION_AREA:
if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.toolMajor.valid) {
touchMajor = in.touchMajor;
@@ -4050,7 +4129,7 @@ void TouchInputMapper::cookPointerData() {
switch (mCalibration.orientationCalibration) {
case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED:
- orientation = (in.orientation - mOrientationCenter) * mOrientationScale;
+ orientation = in.orientation * mOrientationScale;
break;
case Calibration::ORIENTATION_CALIBRATION_VECTOR: {
int32_t c1 = signExtendNybble((in.orientation & 0xf0) >> 4);
@@ -4088,28 +4167,28 @@ void TouchInputMapper::cookPointerData() {
float x, y;
switch (mSurfaceOrientation) {
case DISPLAY_ORIENTATION_90:
- x = float(in.y - mRawPointerAxes.y.minValue) * mYScale;
- y = float(mRawPointerAxes.x.maxValue - in.x) * mXScale;
+ x = float(in.y - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
+ y = float(mRawPointerAxes.x.maxValue - in.x) * mXScale + mXTranslate;
orientation -= M_PI_2;
if (orientation < - M_PI_2) {
orientation += M_PI;
}
break;
case DISPLAY_ORIENTATION_180:
- x = float(mRawPointerAxes.x.maxValue - in.x) * mXScale;
- y = float(mRawPointerAxes.y.maxValue - in.y) * mYScale;
+ x = float(mRawPointerAxes.x.maxValue - in.x) * mXScale + mXTranslate;
+ y = float(mRawPointerAxes.y.maxValue - in.y) * mYScale + mYTranslate;
break;
case DISPLAY_ORIENTATION_270:
- x = float(mRawPointerAxes.y.maxValue - in.y) * mYScale;
- y = float(in.x - mRawPointerAxes.x.minValue) * mXScale;
+ x = float(mRawPointerAxes.y.maxValue - in.y) * mYScale + mYTranslate;
+ y = float(in.x - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
orientation += M_PI_2;
if (orientation > M_PI_2) {
orientation -= M_PI;
}
break;
default:
- x = float(in.x - mRawPointerAxes.x.minValue) * mXScale;
- y = float(in.y - mRawPointerAxes.y.minValue) * mYScale;
+ x = float(in.x - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
+ y = float(in.y - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
break;
}
@@ -4365,7 +4444,8 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
- 1, &pointerProperties, &pointerCoords, 0, 0, mPointerGesture.downTime);
+ mViewport.displayId, 1, &pointerProperties, &pointerCoords,
+ 0, 0, mPointerGesture.downTime);
getListener()->notifyMotion(&args);
}
@@ -5273,6 +5353,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
// Send up.
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_UP, 0, metaState, mLastButtonState, 0,
+ mViewport.displayId,
1, &mPointerSimple.lastProperties, &mPointerSimple.lastCoords,
mOrientedXPrecision, mOrientedYPrecision,
mPointerSimple.downTime);
@@ -5285,6 +5366,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
// Send hover exit.
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_HOVER_EXIT, 0, metaState, mLastButtonState, 0,
+ mViewport.displayId,
1, &mPointerSimple.lastProperties, &mPointerSimple.lastCoords,
mOrientedXPrecision, mOrientedYPrecision,
mPointerSimple.downTime);
@@ -5299,6 +5381,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
// Send down.
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_DOWN, 0, metaState, mCurrentButtonState, 0,
+ mViewport.displayId,
1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
mOrientedXPrecision, mOrientedYPrecision,
mPointerSimple.downTime);
@@ -5308,6 +5391,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
// Send move.
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_MOVE, 0, metaState, mCurrentButtonState, 0,
+ mViewport.displayId,
1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
mOrientedXPrecision, mOrientedYPrecision,
mPointerSimple.downTime);
@@ -5321,6 +5405,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
// Send hover enter.
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_HOVER_ENTER, 0, metaState, mCurrentButtonState, 0,
+ mViewport.displayId,
1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
mOrientedXPrecision, mOrientedYPrecision,
mPointerSimple.downTime);
@@ -5330,6 +5415,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
// Send hover move.
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_HOVER_MOVE, 0, metaState, mCurrentButtonState, 0,
+ mViewport.displayId,
1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
mOrientedXPrecision, mOrientedYPrecision,
mPointerSimple.downTime);
@@ -5350,6 +5436,7 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
AMOTION_EVENT_ACTION_SCROLL, 0, metaState, mCurrentButtonState, 0,
+ mViewport.displayId,
1, &mPointerSimple.currentProperties, &pointerCoords,
mOrientedXPrecision, mOrientedYPrecision,
mPointerSimple.downTime);
@@ -5411,7 +5498,8 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32
NotifyMotionArgs args(when, getDeviceId(), source, policyFlags,
action, flags, metaState, buttonState, edgeFlags,
- pointerCount, pointerProperties, pointerCoords, xPrecision, yPrecision, downTime);
+ mViewport.displayId, pointerCount, pointerProperties, pointerCoords,
+ xPrecision, yPrecision, downTime);
getListener()->notifyMotion(&args);
}
@@ -6214,7 +6302,7 @@ void JoystickInputMapper::sync(nsecs_t when, bool force) {
}
}
- // Moving a joystick axis should not wake the devide because joysticks can
+ // Moving a joystick axis should not wake the device because joysticks can
// be fairly noisy even when not in use. On the other hand, pushing a gamepad
// button will likely wake the device.
// TODO: Use the input device configuration to control this behavior more finely.
@@ -6222,7 +6310,7 @@ void JoystickInputMapper::sync(nsecs_t when, bool force) {
NotifyMotionArgs args(when, getDeviceId(), AINPUT_SOURCE_JOYSTICK, policyFlags,
AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
- 1, &pointerProperties, &pointerCoords, 0, 0, 0);
+ ADISPLAY_ID_NONE, 1, &pointerProperties, &pointerCoords, 0, 0, 0);
getListener()->notifyMotion(&args);
}