diff options
Diffstat (limited to 'services/input')
-rw-r--r-- | services/input/InputDispatcher.cpp | 41 | ||||
-rw-r--r-- | services/input/InputReader.cpp | 61 | ||||
-rw-r--r-- | services/input/tests/InputReader_test.cpp | 39 |
3 files changed, 75 insertions, 66 deletions
diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp index cbfdd75..466a9b3 100644 --- a/services/input/InputDispatcher.cpp +++ b/services/input/InputDispatcher.cpp @@ -482,8 +482,10 @@ bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) { && (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) && mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY && mInputTargetWaitApplication != NULL) { - int32_t x = int32_t(motionEntry->firstSample.pointerCoords[0].x); - int32_t y = int32_t(motionEntry->firstSample.pointerCoords[0].y); + int32_t x = int32_t(motionEntry->firstSample.pointerCoords[0]. + getAxisValue(AINPUT_MOTION_AXIS_X)); + int32_t y = int32_t(motionEntry->firstSample.pointerCoords[0]. + getAxisValue(AINPUT_MOTION_AXIS_Y)); const InputWindow* touchedWindow = findTouchedWindowAtLocked(x, y); if (touchedWindow && touchedWindow->inputWindowHandle != NULL @@ -888,11 +890,15 @@ void InputDispatcher::logOutboundMotionDetailsLocked(const char* prefix, const M "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, " "orientation=%f", i, entry->pointerIds[i], - sample->pointerCoords[i].x, sample->pointerCoords[i].y, - sample->pointerCoords[i].pressure, sample->pointerCoords[i].size, - sample->pointerCoords[i].touchMajor, sample->pointerCoords[i].touchMinor, - sample->pointerCoords[i].toolMajor, sample->pointerCoords[i].toolMinor, - sample->pointerCoords[i].orientation); + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_X), + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_Y), + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_PRESSURE), + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_SIZE), + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR), + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR), + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR), + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR), + sample->pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION)); } // Keep in mind that due to batching, it is possible for the number of samples actually @@ -1188,8 +1194,10 @@ int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime, /* Case 1: New splittable pointer going down. */ int32_t pointerIndex = getMotionEventActionPointerIndex(action); - int32_t x = int32_t(entry->firstSample.pointerCoords[pointerIndex].x); - int32_t y = int32_t(entry->firstSample.pointerCoords[pointerIndex].y); + int32_t x = int32_t(entry->firstSample.pointerCoords[pointerIndex]. + getAxisValue(AINPUT_MOTION_AXIS_X)); + int32_t y = int32_t(entry->firstSample.pointerCoords[pointerIndex]. + getAxisValue(AINPUT_MOTION_AXIS_Y)); const InputWindow* newTouchedWindow = NULL; const InputWindow* topErrorWindow = NULL; @@ -2275,11 +2283,16 @@ void InputDispatcher::notifyMotion(nsecs_t eventTime, int32_t deviceId, uint32_t LOGD(" Pointer %d: id=%d, x=%f, y=%f, pressure=%f, size=%f, " "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, " "orientation=%f", - i, pointerIds[i], pointerCoords[i].x, pointerCoords[i].y, - pointerCoords[i].pressure, pointerCoords[i].size, - pointerCoords[i].touchMajor, pointerCoords[i].touchMinor, - pointerCoords[i].toolMajor, pointerCoords[i].toolMinor, - pointerCoords[i].orientation); + i, pointerIds[i], + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_X), + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_Y), + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_PRESSURE), + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_SIZE), + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR), + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR), + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR), + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR), + pointerCoords[i].getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION)); } #endif if (! validateMotionEvent(action, pointerCount, pointerIds)) { diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp index 05f40ba..577da01 100644 --- a/services/input/InputReader.cpp +++ b/services/input/InputReader.cpp @@ -1285,24 +1285,23 @@ void CursorInputMapper::sync(nsecs_t when) { } } + pointerCoords.clear(); + if (mPointerController != NULL) { mPointerController->move(deltaX, deltaY); if (downChanged) { mPointerController->setButtonState(mLocked.down ? POINTER_BUTTON_1 : 0); } - mPointerController->getPosition(&pointerCoords.x, &pointerCoords.y); + float x, y; + mPointerController->getPosition(&x, &y); + pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_X, x); + pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_Y, y); } else { - pointerCoords.x = deltaX; - pointerCoords.y = deltaY; + pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_X, deltaX); + pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_Y, deltaY); } - pointerCoords.pressure = mLocked.down ? 1.0f : 0.0f; - pointerCoords.size = 0; - pointerCoords.touchMajor = 0; - pointerCoords.touchMinor = 0; - pointerCoords.toolMajor = 0; - pointerCoords.toolMinor = 0; - pointerCoords.orientation = 0; + pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_PRESSURE, mLocked.down ? 1.0f : 0.0f); } // release lock int32_t metaState = mContext->getGlobalMetaState(); @@ -2686,15 +2685,16 @@ void TouchInputMapper::dispatchTouch(nsecs_t when, uint32_t policyFlags, // Write output coords. PointerCoords& out = pointerCoords[outIndex]; - out.x = x; - out.y = y; - out.pressure = pressure; - out.size = size; - out.touchMajor = touchMajor; - out.touchMinor = touchMinor; - out.toolMajor = toolMajor; - out.toolMinor = toolMinor; - out.orientation = orientation; + out.clear(); + out.setAxisValue(AINPUT_MOTION_AXIS_X, x); + out.setAxisValue(AINPUT_MOTION_AXIS_Y, y); + out.setAxisValue(AINPUT_MOTION_AXIS_PRESSURE, pressure); + out.setAxisValue(AINPUT_MOTION_AXIS_SIZE, size); + out.setAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR, touchMajor); + out.setAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR, touchMinor); + out.setAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR, toolMajor); + out.setAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR, toolMinor); + out.setAxisValue(AINPUT_MOTION_AXIS_ORIENTATION, orientation); pointerIds[outIndex] = int32_t(id); @@ -2706,14 +2706,17 @@ void TouchInputMapper::dispatchTouch(nsecs_t when, uint32_t policyFlags, // Check edge flags by looking only at the first pointer since the flags are // global to the event. if (motionEventAction == AMOTION_EVENT_ACTION_DOWN) { - if (pointerCoords[0].x <= 0) { + float x = pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X); + float y = pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y); + + if (x <= 0) { motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_LEFT; - } else if (pointerCoords[0].x >= mLocked.orientedSurfaceWidth) { + } else if (x >= mLocked.orientedSurfaceWidth) { motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_RIGHT; } - if (pointerCoords[0].y <= 0) { + if (y <= 0) { motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_TOP; - } else if (pointerCoords[0].y >= mLocked.orientedSurfaceHeight) { + } else if (y >= mLocked.orientedSurfaceHeight) { motionEventEdgeFlags |= AMOTION_EVENT_EDGE_FLAG_BOTTOM; } } @@ -3853,15 +3856,9 @@ void JoystickInputMapper::sync(nsecs_t when) { if (motionAxisChanged) { PointerCoords pointerCoords; - pointerCoords.x = mAxes.x.value; - pointerCoords.y = mAxes.y.value; - pointerCoords.touchMajor = 0; - pointerCoords.touchMinor = 0; - pointerCoords.toolMajor = 0; - pointerCoords.toolMinor = 0; - pointerCoords.pressure = 0; - pointerCoords.size = 0; - pointerCoords.orientation = 0; + pointerCoords.clear(); + pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_X, mAxes.x.value); + pointerCoords.setAxisValue(AINPUT_MOTION_AXIS_Y, mAxes.y.value); int32_t pointerId = 0; getDispatcher()->notifyMotion(when, getDeviceId(), AINPUT_SOURCE_JOYSTICK, 0, diff --git a/services/input/tests/InputReader_test.cpp b/services/input/tests/InputReader_test.cpp index 8ec1fd4..34d613a 100644 --- a/services/input/tests/InputReader_test.cpp +++ b/services/input/tests/InputReader_test.cpp @@ -1473,15 +1473,15 @@ protected: float x, float y, float pressure, float size, float touchMajor, float touchMinor, float toolMajor, float toolMinor, float orientation) { - ASSERT_NEAR(x, coords.x, 1); - ASSERT_NEAR(y, coords.y, 1); - ASSERT_NEAR(pressure, coords.pressure, EPSILON); - ASSERT_NEAR(size, coords.size, EPSILON); - ASSERT_NEAR(touchMajor, coords.touchMajor, 1); - ASSERT_NEAR(touchMinor, coords.touchMinor, 1); - ASSERT_NEAR(toolMajor, coords.toolMajor, 1); - ASSERT_NEAR(toolMinor, coords.toolMinor, 1); - ASSERT_NEAR(orientation, coords.orientation, EPSILON); + ASSERT_NEAR(x, coords.getAxisValue(AINPUT_MOTION_AXIS_X), 1); + ASSERT_NEAR(y, coords.getAxisValue(AINPUT_MOTION_AXIS_Y), 1); + ASSERT_NEAR(pressure, coords.getAxisValue(AINPUT_MOTION_AXIS_PRESSURE), EPSILON); + ASSERT_NEAR(size, coords.getAxisValue(AINPUT_MOTION_AXIS_SIZE), EPSILON); + ASSERT_NEAR(touchMajor, coords.getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MAJOR), 1); + ASSERT_NEAR(touchMinor, coords.getAxisValue(AINPUT_MOTION_AXIS_TOUCH_MINOR), 1); + ASSERT_NEAR(toolMajor, coords.getAxisValue(AINPUT_MOTION_AXIS_TOOL_MAJOR), 1); + ASSERT_NEAR(toolMinor, coords.getAxisValue(AINPUT_MOTION_AXIS_TOOL_MINOR), 1); + ASSERT_NEAR(orientation, coords.getAxisValue(AINPUT_MOTION_AXIS_ORIENTATION), EPSILON); } }; @@ -2078,7 +2078,6 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentXYUpdates) { process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0, 0, 0); ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action); - ASSERT_NEAR(0.0f, args.pointerCoords[0].x, EPSILON); ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0], 0.0f, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); } @@ -2893,8 +2892,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_DoesNotRotate processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); - ASSERT_NEAR(50, args.pointerCoords[0].x, 1); - ASSERT_NEAR(75, args.pointerCoords[0].y, 1); + ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1); + ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1); processUp(mapper); processSync(mapper); @@ -2915,8 +2914,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); - ASSERT_NEAR(50, args.pointerCoords[0].x, 1); - ASSERT_NEAR(75, args.pointerCoords[0].y, 1); + ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1); + ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1); processUp(mapper); processSync(mapper); @@ -2928,8 +2927,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); - ASSERT_NEAR(75, args.pointerCoords[0].x, 1); - ASSERT_NEAR(DISPLAY_WIDTH - 50, args.pointerCoords[0].y, 1); + ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1); + ASSERT_NEAR(DISPLAY_WIDTH - 50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1); processUp(mapper); processSync(mapper); @@ -2941,8 +2940,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); - ASSERT_NEAR(DISPLAY_WIDTH - 50, args.pointerCoords[0].x, 1); - ASSERT_NEAR(DISPLAY_HEIGHT - 75, args.pointerCoords[0].y, 1); + ASSERT_NEAR(DISPLAY_WIDTH - 50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1); + ASSERT_NEAR(DISPLAY_HEIGHT - 75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1); processUp(mapper); processSync(mapper); @@ -2954,8 +2953,8 @@ TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) processSync(mapper); ASSERT_NO_FATAL_FAILURE(mFakeDispatcher->assertNotifyMotionWasCalled(&args)); - ASSERT_NEAR(DISPLAY_HEIGHT - 75, args.pointerCoords[0].x, 1); - ASSERT_NEAR(50, args.pointerCoords[0].y, 1); + ASSERT_NEAR(DISPLAY_HEIGHT - 75, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_X), 1); + ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AINPUT_MOTION_AXIS_Y), 1); processUp(mapper); processSync(mapper); |