gma pipe_setup: Enable key color feffff for cursor plane

Somehow the alpha blending is not accurate. On a screen with good
color resolution, fully transparent pixels of the cursor are slightly
visible. Hence, enable source keying for the cursor plane.

Change-Id: I1815a1e70b60d4bd74c581eed873ef5a2a32353d
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.sourcearcade.org/c/libgfxinit/+/547
Reviewed-by: Thomas Heijligen <src@posteo.de>
Tested-by: Ada SPARK <gnatbot@sourcearcade.org>
diff --git a/common/hw-gfx-gma-pipe_setup.adb b/common/hw-gfx-gma-pipe_setup.adb
index f49d6c0..f915a52 100644
--- a/common/hw-gfx-gma-pipe_setup.adb
+++ b/common/hw-gfx-gma-pipe_setup.adb
@@ -54,6 +54,8 @@
 
    PLANE_CTL_PLANE_ENABLE              : constant := 1 * 2 ** 31;
    PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888  : constant := 4 * 2 ** 24;
+   PLANE_CTL_KEY_ENABLE_MASK           : constant := 3 * 2 ** 21;
+   PLANE_CTL_KEY_ENABLE_SOURCE         : constant := 1 * 2 ** 21;
    PLANE_CTL_PLANE_GAMMA_DISABLE       : constant := 1 * 2 ** 13;
    PLANE_CTL_TILED_SURFACE_MASK        : constant := 7 * 2 ** 10;
    PLANE_CTL_TILED_SURFACE_LINEAR      : constant := 0 * 2 ** 10;
@@ -62,6 +64,7 @@
    PLANE_CTL_TILED_SURFACE_YF_TILED    : constant := 5 * 2 ** 10;
    PLANE_CTL_ALPHA_MODE_MASK           : constant := 3 * 2 **  4;
    PLANE_CTL_ALPHA_MODE_SW_PREMULTIPLY : constant := 2 * 2 **  4;
+   PLANE_CTL_ALPHA_MODE_HW_PREMULTIPLY : constant := 3 * 2 **  4;
 
    PLANE_CTL_TILED_SURFACE : constant array (Tiling_Type) of Word32 :=
      (Linear   => PLANE_CTL_TILED_SURFACE_LINEAR,
@@ -529,6 +532,13 @@
       Controller : Controller_Type renames Controllers (Pipe);
    begin
       if Use_Plane_For_Cursor (FB) then
+         -- Use feffff (most white cyan) as key color for transparency.
+         -- It turned out that at least on APL, even fully transparent
+         -- pixels are faintly visible when blended onto the primary
+         -- framebuffer.
+         Registers.Write (Controller.PLANE_2_KEYVAL, 16#00_fe_ff_ff#);
+         Registers.Write (Controller.PLANE_2_KEYMSK, 16#07_ff_ff_ff#);
+
          if Config.Has_Plane_Color_Control then
             Registers.Write
               (Register => Controller.PLANE_2_COLOR_CTL,
@@ -659,9 +669,10 @@
 
                Registers.Write
                  (Register    => Controller.PLANE_2_CTL,
-                  Value       => PLANE_CTL_PLANE_ENABLE or
-                                 PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888 or
-                                 PLANE_CTL_TILED_SURFACE (FB.Tiling) or
+                  Value       => PLANE_CTL_PLANE_ENABLE                 or
+                                 PLANE_CTL_SRC_PIX_FMT_RGB_32B_8888     or
+                                 PLANE_CTL_KEY_ENABLE_SOURCE            or
+                                 PLANE_CTL_TILED_SURFACE (FB.Tiling)    or
                                  PLANE_CTL_PLANE_ROTATION (FB.Rotation) or
                                 (if not Config.Has_Plane_Color_Control
                                  then PLANE_CTL_PLANE_GAMMA_DISABLE or