8a74d28
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8a74d28
From: Hans de Goede <hdegoede@redhat.com>
8a74d28
Date: Fri, 28 Jan 2022 12:43:49 +0100
8a74d28
Subject: [PATCH] EFI: console: Do not set cursor until the first text output
8a74d28
8a74d28
To allow flickerfree boot the EFI console code does not call
8a74d28
grub_efi_set_text_mode (1) until some text is actually output.
8a74d28
8a74d28
Depending on if the output text is because of an error loading
8a74d28
e.g. the .cfg file; or because of showing the menu the cursor needs
8a74d28
to be on or off when the first text is shown.
8a74d28
8a74d28
So far the cursor was hardcoded to being on, but this is causing
8a74d28
drawing artifacts + slow drawing of the menu as reported here:
8a74d28
https://bugzilla.redhat.com/show_bug.cgi?id=1946969
8a74d28
8a74d28
Handle the cursorstate in the same way as the colorstate to fix this,
8a74d28
when no text has been output yet, just cache the cursorstate and
8a74d28
then use the last set value when the first text is output.
8a74d28
8a74d28
Fixes: 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
8a74d28
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
8a74d28
---
8a74d28
 grub-core/term/efi/console.c | 19 ++++++++++++++++---
8a74d28
 1 file changed, 16 insertions(+), 3 deletions(-)
8a74d28
8a74d28
diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c
e622855
index c44b2ac318..a3622e4fe5 100644
8a74d28
--- a/grub-core/term/efi/console.c
8a74d28
+++ b/grub-core/term/efi/console.c
8a74d28
@@ -31,7 +31,15 @@ typedef enum {
8a74d28
 }
8a74d28
 grub_text_mode;
8a74d28
 
8a74d28
+typedef enum {
8a74d28
+    GRUB_CURSOR_MODE_UNDEFINED = -1,
8a74d28
+    GRUB_CURSOR_MODE_OFF = 0,
8a74d28
+    GRUB_CURSUR_MODE_ON
8a74d28
+}
8a74d28
+grub_cursor_mode;
8a74d28
+
8a74d28
 static grub_text_mode text_mode = GRUB_TEXT_MODE_UNDEFINED;
8a74d28
+static grub_cursor_mode cursor_mode = GRUB_CURSOR_MODE_UNDEFINED;
8a74d28
 static grub_term_color_state text_colorstate = GRUB_TERM_COLOR_UNDEFINED;
8a74d28
 
8a74d28
 static grub_uint32_t
8a74d28
@@ -119,8 +127,12 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
8a74d28
 {
8a74d28
   grub_efi_simple_text_output_interface_t *o;
8a74d28
 
8a74d28
-  if (grub_efi_is_finished)
8a74d28
-    return;
8a74d28
+  if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE)
8a74d28
+    {
8a74d28
+      /* Cache cursor changes before the first text-output */
8a74d28
+      cursor_mode = on;
8a74d28
+      return;
8a74d28
+    }
8a74d28
 
8a74d28
   o = grub_efi_system_table->con_out;
8a74d28
   efi_call_2 (o->enable_cursor, o, on);
8a74d28
@@ -143,7 +155,8 @@ grub_prepare_for_text_output (struct grub_term_output *term)
8a74d28
       return GRUB_ERR_BAD_DEVICE;
8a74d28
     }
8a74d28
 
8a74d28
-  grub_console_setcursor (term, 1);
8a74d28
+  if (cursor_mode != GRUB_CURSOR_MODE_UNDEFINED)
8a74d28
+    grub_console_setcursor (term, cursor_mode);
8a74d28
   if (text_colorstate != GRUB_TERM_COLOR_UNDEFINED)
8a74d28
     grub_console_setcolorstate (term, text_colorstate);
8a74d28
   text_mode = GRUB_TEXT_MODE_AVAILABLE;