--- a/grub-core/video/efi_uga.c +++ b/grub-core/video/efi_uga.c @@ -28,6 +28,7 @@ #include #include #include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); @@ -175,6 +176,21 @@ return ctx.found; } +static grub_guid_t console_control_guid = GRUB_EFI_CONSOLE_CONTROL_GUID; + +/* Return 1 if the firmware console is (or is assumed to be) in text mode. */ +static int +console_is_text (void) +{ + grub_efi_console_control_protocol_t *c; + grub_efi_screen_mode_t mode; + + c = grub_efi_locate_protocol (&console_control_guid, 0); + if (!c || c->get_mode (c, &mode, 0, 0) != GRUB_EFI_SUCCESS) + return 1; + return mode == GRUB_EFI_SCREEN_TEXT; +} + static int check_protocol (void) { @@ -184,17 +200,20 @@ if (c) { grub_uint32_t width, height, depth, rate, pixel; - int ret; + int ret, was_text; if (c->get_mode (c, &width, &height, &depth, &rate)) return 0; + was_text = console_is_text (); grub_efi_set_text_mode (0); pixel = RGB_MAGIC; c->blt (c, (struct grub_efi_uga_pixel *) &pixel, GRUB_EFI_UGA_VIDEO_FILL, 0, 0, 0, 0, 1, height, 0); ret = find_framebuf (&uga_fb, &uga_pitch); - grub_efi_set_text_mode (1); + /* Restore the previous mode instead of forcing text mode. */ + if (was_text) + grub_efi_set_text_mode (1); if (ret) {