gma: Expect cursor coordinates on framebuffer surface

To our API users, the cursor is on the framebuffer surface. We have
to translate this position in case of rotation.

Change-Id: I16b8e8d5bb3b561c66ffed3af6b2c155b5f88f47
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.sourcearcade.org/c/libgfxinit/+/540
Reviewed-by: Thomas Heijligen <src@posteo.de>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Tested-by: Nico Huber <nico.h@gmx.de>
diff --git a/common/hw-gfx-gma-pipe_setup.adb b/common/hw-gfx-gma-pipe_setup.adb
index 438c600..7b79fc4 100644
--- a/common/hw-gfx-gma-pipe_setup.adb
+++ b/common/hw-gfx-gma-pipe_setup.adb
@@ -514,8 +514,24 @@
       Cursor   : Cursor_Type)
    is
       Width : constant Width_Type := Cursor_Width (Cursor.Size);
-      X : Int32 := Cursor.Center_X - Width / 2;
-      Y : Int32 := Cursor.Center_Y - Width / 2;
+
+      -- The cursor's coordinates are on the framebuffer surface
+      -- but we need to place it on the physical screen:
+      Center_X : constant Int32 :=
+        (case FB.Rotation is
+            when No_Rotation  => Cursor.Center_X,
+            when Rotated_90   => FB.Height   - 1 - Cursor.Center_Y,
+            when Rotated_180  => FB.Width    - 1 - Cursor.Center_X,
+            when Rotated_270  => Cursor.Center_Y);
+      Center_Y : constant Int32 :=
+        (case FB.Rotation is
+            when No_Rotation  => Cursor.Center_Y,
+            when Rotated_90   => Cursor.Center_X,
+            when Rotated_180  => FB.Height   - 1 - Cursor.Center_Y,
+            when Rotated_270  => FB.Width    - 1 - Cursor.Center_X);
+
+      X : Int32 := Center_X - Width / 2;
+      Y : Int32 := Center_Y - Width / 2;
    begin
       -- off-screen cursor needs special care
       if X <= -Width or Y <= -Width or