diff --git a/Application/ModernSetupApp/ModernSetupApp.c b/Application/ModernSetupApp/ModernSetupApp.c index 29c8307..f88687c 100644 --- a/Application/ModernSetupApp/ModernSetupApp.c +++ b/Application/ModernSetupApp/ModernSetupApp.c @@ -47,6 +47,23 @@ UefiMain ( CHAR16 StatusMessage[96]; BOOLEAN Redraw; BOOLEAN ResetConfirmationPending; + SETUP_PAGE OldPage; + SETUP_FOCUS OldFocus; + UINTN OldDashboardSelection; + UINTN OldBootSelection; + UINTN OldDeviceSelection; + UINTN OldPreferencesSelection; + UINTN OldExitSelection; + BOOLEAN OldLanguageDropdownOpen; + UINTN OldLanguageDropdownSelection; + BOOLEAN OldPreferencePopupOpen; + UINTN OldPreferencePopupRow; + UINTN OldPreferencePopupSelection; + MODERN_SETUP_PREFERENCE_POPUP_KIND OldPreferencePopupKind; + UINTN OldPreferenceInputLength; + BOOLEAN OldResetConfirmationPending; + MODERN_UI_PREFERENCES OldPreferences; + CHAR16 OldStatusMessage[96]; gBS->SetWatchdogTimer (0, 0, 0, NULL); mModernSetupImageHandle = ImageHandle; @@ -88,10 +105,35 @@ UefiMain ( continue; } + OldPage = Page; + OldFocus = Focus; + OldDashboardSelection = DashboardSelection; + OldBootSelection = BootSelection; + OldDeviceSelection = DeviceSelection; + OldPreferencesSelection = PreferencesSelection; + OldExitSelection = ExitSelection; + OldLanguageDropdownOpen = mModernSetupLanguageDropdownOpen; + OldLanguageDropdownSelection = mModernSetupLanguageDropdownSelection; + OldPreferencePopupOpen = mModernSetupPreferencePopupOpen; + OldPreferencePopupRow = mModernSetupPreferencePopupRow; + OldPreferencePopupSelection = mModernSetupPreferencePopupSelection; + OldPreferencePopupKind = mModernSetupPreferencePopupKind; + OldPreferenceInputLength = mModernSetupPreferenceInputLength; + OldResetConfirmationPending = ResetConfirmationPending; + CopyMem (&OldPreferences, &mModernSetupPreferences, sizeof (OldPreferences)); + CopyMem (OldStatusMessage, StatusMessage, sizeof (OldStatusMessage)); + if ((Focus == SetupFocusContent) && (Page == PagePreferences) && mModernSetupPreferencePopupOpen && (Event.Type == ModernUiInputOther)) { ModernSetupHandlePreferenceInputKey (&Event, StatusMessage, sizeof (StatusMessage)); ResetConfirmationPending = FALSE; Redraw = TRUE; + if ((OldPreferenceInputLength == mModernSetupPreferenceInputLength) && + (StrCmp (OldStatusMessage, StatusMessage) == 0) && + (CompareMem (&OldPreferences, &mModernSetupPreferences, sizeof (OldPreferences)) == 0)) + { + Redraw = FALSE; + } + continue; } @@ -277,5 +319,36 @@ UefiMain ( default: break; } + + if (((OldPage == PageBoot) && (Page != PageBoot)) || + ((Event.Type == ModernUiInputEnter) && + ((OldPage == PageBoot) || + (OldPage == PageDevices) || + ((OldPage == PageExit) && (OldExitSelection == 1))))) + { + ModernSetupInvalidateBootOptionsCache (); + } + + if (Redraw && (Event.Type != ModernUiInputEnter) && + (OldPage == Page) && + (OldFocus == Focus) && + (OldDashboardSelection == DashboardSelection) && + (OldBootSelection == BootSelection) && + (OldDeviceSelection == DeviceSelection) && + (OldPreferencesSelection == PreferencesSelection) && + (OldExitSelection == ExitSelection) && + (OldLanguageDropdownOpen == mModernSetupLanguageDropdownOpen) && + (OldLanguageDropdownSelection == mModernSetupLanguageDropdownSelection) && + (OldPreferencePopupOpen == mModernSetupPreferencePopupOpen) && + (OldPreferencePopupRow == mModernSetupPreferencePopupRow) && + (OldPreferencePopupSelection == mModernSetupPreferencePopupSelection) && + (OldPreferencePopupKind == mModernSetupPreferencePopupKind) && + (OldPreferenceInputLength == mModernSetupPreferenceInputLength) && + (OldResetConfirmationPending == ResetConfirmationPending) && + (StrCmp (OldStatusMessage, StatusMessage) == 0) && + (CompareMem (&OldPreferences, &mModernSetupPreferences, sizeof (OldPreferences)) == 0)) + { + Redraw = FALSE; + } } } diff --git a/Application/ModernSetupApp/ModernSetupAppActions.c b/Application/ModernSetupApp/ModernSetupAppActions.c index b079b46..c57d765 100644 --- a/Application/ModernSetupApp/ModernSetupAppActions.c +++ b/Application/ModernSetupApp/ModernSetupAppActions.c @@ -16,6 +16,10 @@ STATIC CONST EFI_GUID mNativeFallbackAppGuid = { 0xEEC25BDC, 0x67F2, 0x4D95, { STATIC CONST EFI_GUID mNativeFallbackAppGuid = { 0x462CAA21, 0x7614, 0x4503, { 0x83, 0x6E, 0x8A, 0xB6, 0xF4, 0x66, 0x23, 0x31 } }; #endif +STATIC MODERN_UI_BOOT_OPTION *mModernSetupBootOptionsCache; +STATIC UINTN mModernSetupBootOptionCountCache; +STATIC BOOLEAN mModernSetupBootOptionsCacheValid; + STATIC CONST MODERN_SETUP_DASHBOARD_ROUTE mDashboardCategoryRoutes[DASHBOARD_QUICK_CARD_COUNT] = { { PageBoot, SetupFocusContent }, { PageDevices, SetupFocusContent }, @@ -283,8 +287,58 @@ ModernSetupSetPageSelection ( } +EFI_STATUS +ModernSetupGetCachedBootOptions ( + OUT CONST MODERN_UI_BOOT_OPTION **Options, + OUT UINTN *OptionCount + ) +{ + EFI_STATUS Status; + + if ((Options == NULL) || (OptionCount == NULL)) { + return EFI_INVALID_PARAMETER; + } + + if (!mModernSetupBootOptionsCacheValid) { + ModernSetupInvalidateBootOptionsCache (); + Status = ModernUiBootDataGetOptions ( + mModernSetupImageHandle, + &mModernSetupBootOptionsCache, + &mModernSetupBootOptionCountCache + ); + if (EFI_ERROR (Status)) { + mModernSetupBootOptionsCache = NULL; + mModernSetupBootOptionCountCache = 0; + return Status; + } + + mModernSetupBootOptionsCacheValid = TRUE; + } + + *Options = mModernSetupBootOptionsCache; + *OptionCount = mModernSetupBootOptionCountCache; + return EFI_SUCCESS; +} + +VOID +ModernSetupInvalidateBootOptionsCache ( + VOID + ) +{ + if (mModernSetupBootOptionsCache != NULL) { + ModernUiBootDataFreeOptions ( + mModernSetupBootOptionsCache, + mModernSetupBootOptionCountCache + ); + } + + mModernSetupBootOptionsCache = NULL; + mModernSetupBootOptionCountCache = 0; + mModernSetupBootOptionsCacheValid = FALSE; +} + /** - Count visible boot options from UefiBootManagerLib. + Count visible boot options from the cached Boot#### snapshot. @return Number of visible Boot#### entries, or 0 when none are available. **/ @@ -293,17 +347,16 @@ ModernSetupGetBootCount ( VOID ) { - EFI_STATUS Status; - MODERN_UI_BOOT_OPTION *Options; - UINTN OptionCount; + EFI_STATUS Status; + CONST MODERN_UI_BOOT_OPTION *Options; + UINTN OptionCount; Options = NULL; - Status = ModernUiBootDataGetOptions (mModernSetupImageHandle, &Options, &OptionCount); + Status = ModernSetupGetCachedBootOptions (&Options, &OptionCount); if (EFI_ERROR (Status)) { return 0; } - ModernUiBootDataFreeOptions (Options, OptionCount); return OptionCount; } @@ -395,24 +448,23 @@ ModernSetupLaunchSelectedBootOption ( IN UINTN Selection ) { - EFI_STATUS Status; - MODERN_UI_BOOT_OPTION *Options; - UINTN OptionCount; - UINT16 OptionNumber; + EFI_STATUS Status; + CONST MODERN_UI_BOOT_OPTION *Options; + UINTN OptionCount; + UINT16 OptionNumber; Options = NULL; - Status = ModernUiBootDataGetOptions (mModernSetupImageHandle, &Options, &OptionCount); + Status = ModernSetupGetCachedBootOptions (&Options, &OptionCount); if (EFI_ERROR (Status)) { return Status; } if ((Options == NULL) || (Selection >= OptionCount)) { - ModernUiBootDataFreeOptions (Options, OptionCount); return EFI_NOT_FOUND; } OptionNumber = Options[Selection].OptionNumber; - ModernUiBootDataFreeOptions (Options, OptionCount); + ModernSetupInvalidateBootOptionsCache (); return ModernUiBootDataBootOption (OptionNumber); } diff --git a/Application/ModernSetupApp/ModernSetupAppInternal.h b/Application/ModernSetupApp/ModernSetupAppInternal.h index 2180b8b..2e7cfba 100644 --- a/Application/ModernSetupApp/ModernSetupAppInternal.h +++ b/Application/ModernSetupApp/ModernSetupAppInternal.h @@ -286,6 +286,17 @@ ModernSetupGetDashboardCategoryRoute ( OUT MODERN_SETUP_DASHBOARD_ROUTE *Route ); +EFI_STATUS +ModernSetupGetCachedBootOptions ( + OUT CONST MODERN_UI_BOOT_OPTION **Options, + OUT UINTN *OptionCount + ); + +VOID +ModernSetupInvalidateBootOptionsCache ( + VOID + ); + EFI_STATUS ModernSetupLaunchSelectedBootOption ( IN UINTN Selection diff --git a/Application/ModernSetupApp/ModernSetupAppPages.c b/Application/ModernSetupApp/ModernSetupAppPages.c index a636f35..0569684 100644 --- a/Application/ModernSetupApp/ModernSetupAppPages.c +++ b/Application/ModernSetupApp/ModernSetupAppPages.c @@ -252,7 +252,7 @@ DrawBoot ( ) { EFI_STATUS Status; - MODERN_UI_BOOT_OPTION *BootOptions; + CONST MODERN_UI_BOOT_OPTION *BootOptions; UINTN BootOptionCount; UINTN Index; UINTN Y; @@ -274,7 +274,7 @@ DrawBoot ( ModernUiDrawText (Ui, Panel.X + 20, Panel.Y + 20, ModernUiGetString (ModernUiStringBootInstruction), Theme->MutedText, Theme->Surface); BootOptions = NULL; - Status = ModernUiBootDataGetOptions (mModernSetupImageHandle, &BootOptions, &BootOptionCount); + Status = ModernSetupGetCachedBootOptions (&BootOptions, &BootOptionCount); if (EFI_ERROR (Status) || (BootOptions == NULL)) { ModernUiDrawText (Ui, Panel.X + 20, Panel.Y + 66, ModernUiGetString (ModernUiStringNoBootOptions), Theme->Warning, Theme->Surface); return; @@ -322,8 +322,6 @@ DrawBoot ( if (BootOptionCount == 0) { ModernUiDrawText (Ui, Panel.X + 20, Panel.Y + 66, ModernUiGetString (ModernUiStringNoBootOptions), Theme->Warning, Theme->Surface); } - - ModernUiBootDataFreeOptions (BootOptions, BootOptionCount); } STATIC