MotionEvent: Report transformed orientation values

Previously, the AXIS_ORIENTATION value reported by MotionEvent was
unaffected by the window transform. This meant that whatever value that
was generated by InputReader was the value reported to the window. This
meant that if the window was rotated or scaled respective to the logical
display and the window received an event, it could be the case that the
0 value no longer corresponds with the "up" direction of the window.

Now that the input pipeline works in the display panel's coordinate
system, we need the orientation value reported by MotionEvent to be
affected by the window transform.

This CL also refactors the shared logic by which transformed axis values
are calculated into a common function.

Bug: 179274888
Test: atest libinput_tests
Test: atest inputflinger_tests
Test: manual with test app and stylus
Change-Id: Ibb6f135de47f7c1cbde3c023931a760dfbe08e45
diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp
index d09f2ac..973194c 100644
--- a/libs/input/tests/InputPublisherAndConsumer_test.cpp
+++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp
@@ -259,7 +259,13 @@
         EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), motionEvent->getTouchMinor(i));
         EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), motionEvent->getToolMajor(i));
         EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), motionEvent->getToolMinor(i));
-        EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), motionEvent->getOrientation(i));
+
+        // Calculate the orientation after scaling, keeping in mind that an orientation of 0 is
+        // "up", and the positive y direction is "down".
+        const float unscaledOrientation = pc.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION);
+        const float x = sinf(unscaledOrientation) * xScale;
+        const float y = -cosf(unscaledOrientation) * yScale;
+        EXPECT_EQ(atan2f(x, -y), motionEvent->getOrientation(i));
     }
 
     status = mConsumer->sendFinishedSignal(seq, false);