Convert MotionEvent#getSurfaceRotation to ui::Rotation
Because it might have an invalid rotation it needs to return
std::optional<ui::Rotation>, but at least we're using the types
effectively here.
Test: compiles
Change-Id: I27076edcc6ce33594552863caa8ee643027a81e7
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 162b757..9e8ebf3 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -21,6 +21,7 @@
#include <cutils/compiler.h>
#include <inttypes.h>
#include <string.h>
+#include <optional>
#include <android-base/file.h>
#include <android-base/logging.h>
@@ -552,21 +553,21 @@
&pointerCoords[getPointerCount()]);
}
-int32_t MotionEvent::getSurfaceRotation() const {
+std::optional<ui::Rotation> MotionEvent::getSurfaceRotation() const {
// The surface rotation is the rotation from the window's coordinate space to that of the
// display. Since the event's transform takes display space coordinates to window space, the
// returned surface rotation is the inverse of the rotation for the surface.
switch (mTransform.getOrientation()) {
case ui::Transform::ROT_0:
- return static_cast<int32_t>(ui::ROTATION_0);
+ return ui::ROTATION_0;
case ui::Transform::ROT_90:
- return static_cast<int32_t>(ui::ROTATION_270);
+ return ui::ROTATION_270;
case ui::Transform::ROT_180:
- return static_cast<int32_t>(ui::ROTATION_180);
+ return ui::ROTATION_180;
case ui::Transform::ROT_270:
- return static_cast<int32_t>(ui::ROTATION_90);
+ return ui::ROTATION_90;
default:
- return -1;
+ return std::nullopt;
}
}