aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Stratiienko <r.stratiienko@gmail.com>2023-10-15 01:52:00 +0300
committerRoman Stratiienko <r.stratiienko@gmail.com>2023-10-15 02:16:45 +0300
commitb9bd2712fbc61174120f63d948e68f93d1ab410b (patch)
tree71095a6e6c192414baa3d0eec24f65615ebc60e0
parent492739c5b3d0bffdb637c35ec46aa77885013e84 (diff)
downloaddrm_hwcomposer-b9bd2712fbc61174120f63d948e68f93d1ab410b.tar.gz
drm_hwcomposer: Fix DRM and HWC rotation direction misalignment
[DRM API][1] uses a counter-clockwise direction, while [HWC API][2] uses a clockwise. [1]: https://elixir.bootlin.com/linux/v6.5.7/source/include/uapi/drm/drm_mode.h#L172 [2]: https://cs.android.com/android/platform/superproject/main/+/main:hardware/libhardware/include_all/hardware/hwcomposer_defs.h;l=96;drc=e9d7337d9d1edc0d8e3ece246ecde747e345e876 Closes: https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer/-/issues/78 Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
-rw-r--r--compositor/LayerData.h1
-rw-r--r--drm/DrmPlane.cpp14
2 files changed, 11 insertions, 4 deletions
diff --git a/compositor/LayerData.h b/compositor/LayerData.h
index 8f4b7aa..a808adc 100644
--- a/compositor/LayerData.h
+++ b/compositor/LayerData.h
@@ -33,6 +33,7 @@ namespace android {
class DrmFbIdHandle;
+/* Rotation is defined in the clockwise direction */
enum LayerTransform : uint32_t {
kIdentity = 0,
kFlipH = 1 << 0,
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index 228e3dd..19b7609 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -88,14 +88,17 @@ int DrmPlane::Init() {
GetPlaneProperty("zpos", zpos_property_, Presence::kOptional);
+ /* DRM/KMS uses counter-clockwise rotations, while HWC API uses
+ * clockwise. That's why 90 and 270 are swapped here.
+ */
if (GetPlaneProperty("rotation", rotation_property_, Presence::kOptional)) {
rotation_property_.AddEnumToMap("rotate-0", LayerTransform::kIdentity,
transform_enum_map_);
- rotation_property_.AddEnumToMap("rotate-90", LayerTransform::kRotate90,
+ rotation_property_.AddEnumToMap("rotate-90", LayerTransform::kRotate270,
transform_enum_map_);
rotation_property_.AddEnumToMap("rotate-180", LayerTransform::kRotate180,
transform_enum_map_);
- rotation_property_.AddEnumToMap("rotate-270", LayerTransform::kRotate270,
+ rotation_property_.AddEnumToMap("rotate-270", LayerTransform::kRotate90,
transform_enum_map_);
rotation_property_.AddEnumToMap("reflect-x", LayerTransform::kFlipH,
transform_enum_map_);
@@ -220,16 +223,19 @@ bool DrmPlane::HasNonRgbFormat() const {
static uint64_t ToDrmRotation(LayerTransform transform) {
uint64_t rotation = 0;
+ /* DRM/KMS uses counter-clockwise rotations, while HWC API uses
+ * clockwise. That's why 90 and 270 are swapped here.
+ */
if ((transform & LayerTransform::kFlipH) != 0)
rotation |= DRM_MODE_REFLECT_X;
if ((transform & LayerTransform::kFlipV) != 0)
rotation |= DRM_MODE_REFLECT_Y;
if ((transform & LayerTransform::kRotate90) != 0)
- rotation |= DRM_MODE_ROTATE_90;
+ rotation |= DRM_MODE_ROTATE_270;
else if ((transform & LayerTransform::kRotate180) != 0)
rotation |= DRM_MODE_ROTATE_180;
else if ((transform & LayerTransform::kRotate270) != 0)
- rotation |= DRM_MODE_ROTATE_270;
+ rotation |= DRM_MODE_ROTATE_90;
else
rotation |= DRM_MODE_ROTATE_0;