Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecde4d08 authored by Michael Wright's avatar Michael Wright
Browse files

Convert orientation values in input to ui::Rotation.

ui::Rotation both provides better typesafety as well as some convenience
functions (e.g. operator+, operator-).

Test: atest TouchVideoFrame_test.cpp InputReader_test.cpp
Change-Id: I142e0a8d121316e2c9ac8ca8f1de040e56bc8ddd
parent 4dbae54d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -61,7 +61,8 @@ status_t android_hardware_display_DisplayViewport_toNative(JNIEnv* env, jobject

    viewport->displayId = env->GetIntField(viewportObj, gDisplayViewportClassInfo.displayId);
    viewport->isActive = env->GetBooleanField(viewportObj, gDisplayViewportClassInfo.isActive);
    viewport->orientation = env->GetIntField(viewportObj, gDisplayViewportClassInfo.orientation);
    jint orientation = env->GetIntField(viewportObj, gDisplayViewportClassInfo.orientation);
    viewport->orientation = static_cast<ui::Rotation>(orientation);
    viewport->deviceWidth = env->GetIntField(viewportObj, gDisplayViewportClassInfo.deviceWidth);
    viewport->deviceHeight = env->GetIntField(viewportObj, gDisplayViewportClassInfo.deviceHeight);

+11 −8
Original line number Diff line number Diff line
@@ -199,8 +199,7 @@ static void getNonRotatedSize(const DisplayViewport& viewport, int32_t& width, i
    width = viewport.deviceWidth;
    height = viewport.deviceHeight;

    if (viewport.orientation == DISPLAY_ORIENTATION_90 ||
        viewport.orientation == DISPLAY_ORIENTATION_270) {
    if (viewport.orientation == ui::ROTATION_90 || viewport.orientation == ui::ROTATION_270) {
        std::swap(width, height);
    }
}
@@ -244,38 +243,42 @@ void MouseCursorController::setDisplayViewport(const DisplayViewport& viewport,

        // Undo the previous rotation.
        switch (oldViewport.orientation) {
            case DISPLAY_ORIENTATION_90:
            case ui::ROTATION_90:
                temp = x;
                x = oldViewport.deviceHeight - y;
                y = temp;
                break;
            case DISPLAY_ORIENTATION_180:
            case ui::ROTATION_180:
                x = oldViewport.deviceWidth - x;
                y = oldViewport.deviceHeight - y;
                break;
            case DISPLAY_ORIENTATION_270:
            case ui::ROTATION_270:
                temp = x;
                x = y;
                y = oldViewport.deviceWidth - temp;
                break;
            case ui::ROTATION_0:
                break;
        }

        // Perform the new rotation.
        switch (viewport.orientation) {
            case DISPLAY_ORIENTATION_90:
            case ui::ROTATION_90:
                temp = x;
                x = y;
                y = viewport.deviceHeight - temp;
                break;
            case DISPLAY_ORIENTATION_180:
            case ui::ROTATION_180:
                x = viewport.deviceWidth - x;
                y = viewport.deviceHeight - y;
                break;
            case DISPLAY_ORIENTATION_270:
            case ui::ROTATION_270:
                temp = x;
                x = viewport.deviceWidth - y;
                y = temp;
                break;
            case ui::ROTATION_0:
                break;
        }

        // Apply offsets to convert from the pixel center to the pixel top-left corner position
+2 −2
Original line number Diff line number Diff line
@@ -310,7 +310,7 @@ public:
            const InputDeviceIdentifier& identifier) override;
    std::string getDeviceAlias(const InputDeviceIdentifier& identifier) override;
    TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
                                                           int32_t surfaceRotation) override;
                                                           ui::Rotation surfaceRotation) override;

    TouchAffineTransformation getTouchAffineTransformation(JNIEnv* env, jfloatArray matrixArr);
    void notifyStylusGestureStarted(int32_t deviceId, nsecs_t eventTime) override;
@@ -1153,7 +1153,7 @@ TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
}

TouchAffineTransformation NativeInputManager::getTouchAffineTransformation(
        const std::string& inputDeviceDescriptor, int32_t surfaceRotation) {
        const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation) {
    JNIEnv* env = jniEnv();

    ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.c_str()));