From 3927ee7fe1bc0e7b80fee39b967b26818bfaa287 Mon Sep 17 00:00:00 2001 From: Mike Beaton Date: Thu, 18 May 2023 07:56:45 +0100 Subject: [PATCH] OcBootManagementLib: Save and restore text and graphics mode settings round tools and failed entries --- Changelog.md | 1 + .../OcBootManagementLib/OcBootManagementLib.c | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/Changelog.md b/Changelog.md index 7ca8ff93..b652c7d0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ OpenCore Changelog - Added Unicode font pages for some accented characters, plus box drawing and block elements, to `Builtin` text renderer - Improved support for overlong menu entries and very narrow console modes in builtin picker - Made `Builtin` text renderer ignore UI Scale, when required to ensure that text mode reaches minimum supported size of 80x25 +- Added save and restore of text and graphics mode round tools and failed boot entries #### v0.9.2 - Added `DisableIoMapperMapping` quirk, thx @CaseySJ diff --git a/Library/OcBootManagementLib/OcBootManagementLib.c b/Library/OcBootManagementLib/OcBootManagementLib.c index a03ca11c..7433ab7c 100644 --- a/Library/OcBootManagementLib/OcBootManagementLib.c +++ b/Library/OcBootManagementLib/OcBootManagementLib.c @@ -44,6 +44,70 @@ #include #include +STATIC UINT32 mSavedGopMode; +STATIC EFI_CONSOLE_CONTROL_SCREEN_MODE mSavedConsoleControlMode; +STATIC INT32 mSavedConsoleMode; + +STATIC +EFI_STATUS +SaveMode ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; + + mSavedConsoleMode = gST->ConOut->Mode->Mode; + + mSavedConsoleControlMode = OcConsoleControlGetMode (); + + Status = gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiGraphicsOutputProtocolGuid, + (VOID **)&Gop + ); + + if (EFI_ERROR (Status)) { + mSavedGopMode = MAX_UINT32; + } else { + mSavedGopMode = Gop->Mode->Mode; + } + + return Status; +} + +STATIC +EFI_STATUS +RestoreMode ( + VOID + ) +{ + EFI_STATUS Status; + EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop; + + if (mSavedGopMode == MAX_UINT32) { + Status = EFI_SUCCESS; + } else { + Status = gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiGraphicsOutputProtocolGuid, + (VOID **)&Gop + ); + + if ( !EFI_ERROR (Status) + && (Gop->Mode->Mode != mSavedGopMode)) + { + Status = Gop->SetMode (Gop, mSavedGopMode); + } + } + + OcConsoleControlSetMode (mSavedConsoleControlMode); + + gST->ConOut->SetMode (gST->ConOut, mSavedConsoleMode); + + return Status; +} + STATIC EFI_STATUS RunShowMenu ( @@ -409,6 +473,7 @@ OcRunBootPicker ( } } + SaveMode (); FwRuntime = Chosen->FullNvramAccess ? OcDisableNvramProtection () : NULL; Status = OcLoadBootEntry ( @@ -418,6 +483,7 @@ OcRunBootPicker ( ); OcRestoreNvramProtection (FwRuntime); + RestoreMode (); // // Do not wait on successful return code. -- GitLab