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
diff --git a/gfxtest/hw-gfx-gma-gfx_test.adb b/gfxtest/hw-gfx-gma-gfx_test.adb
index d4bd145..dddb2a8 100644
--- a/gfxtest/hw-gfx-gma-gfx_test.adb
+++ b/gfxtest/hw-gfx-gma-gfx_test.adb
@@ -417,8 +417,8 @@
declare
C : Cursor_Type renames Pipes (Pipe).Cursor;
FB : Framebuffer_Type renames Pipes (Pipe).Framebuffer;
- Width : constant Width_Type := Rotated_Width (FB);
- Height : constant Height_Type := Rotated_Height (FB);
+ Width : constant Width_Type := FB.Width;
+ Height : constant Height_Type := FB.Height;
CS : Cursor_Script_Entry renames Cursor_Script
(Natural (Cnt) mod (Cursor_Script'Last + 1));
begin
@@ -516,8 +516,8 @@
C : Cursor_Type renames Pipes (Pipe).Cursor;
CI : Cursor_Info renames Cursor_Infos (Pipe);
FB : Framebuffer_Type renames Pipes (Pipe).Framebuffer;
- Width : constant Width_Type := Rotated_Width (FB);
- Height : constant Height_Type := Rotated_Height (FB);
+ Width : constant Width_Type := FB.Width;
+ Height : constant Height_Type := FB.Height;
Update : Boolean := False;
begin
@@ -634,8 +634,8 @@
(64, Height - New_FB.Start_Y - Rand_Div (Height));
Cursor.Mode := No_Cursor;
- Cursor.Center_X := Rotated_Width (New_FB) / 2;
- Cursor.Center_Y := Rotated_Height (New_FB) / 2;
+ Cursor.Center_X := New_FB.Width / 2;
+ Cursor.Center_Y := New_FB.Height / 2;
CI.X_Velo := 6 * Cursor_Rand (Gen) / (Width / New_FB.Width);
CI.Y_Velo := 6 * Cursor_Rand (Gen) / (Height / New_FB.Height);
end;