aboutsummaryrefslogtreecommitdiff
path: root/Application
diff options
context:
space:
mode:
authorMatthijs Lavrijsen <mattiwatti@gmail.com>2023-03-26 17:32:56 +0200
committerMatthijs Lavrijsen <mattiwatti@gmail.com>2023-03-26 18:04:00 +0200
commit3e9c9868b0de9e4a245d1cee23639c18628e1b74 (patch)
tree1196b44d7d4c7545e27dd980bce506b0385371ea /Application
parent83bb58f2f48b1aa557172adb2f662ba3750daa78 (diff)
Loader: minor SetHighestAvailableMode improvements
- Add primitive aspect ratio weighting when determining which text mode is best - Move all uses of gST->ConOut to SetHighestAvailableTextMode and exit early if it is NULL
Diffstat (limited to 'Application')
-rw-r--r--Application/Loader/Loader.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/Application/Loader/Loader.c b/Application/Loader/Loader.c
index 7b7f7aa..7165736 100644
--- a/Application/Loader/Loader.c
+++ b/Application/Loader/Loader.c
@@ -176,34 +176,43 @@ LocateFile(
STATIC
EFI_STATUS
EFIAPI
-SetHighestAvailableMode(
+SetHighestAvailableTextMode(
VOID
)
{
+ if (gST->ConOut == NULL)
+ return EFI_NOT_READY;
+
INT32 MaxModeNum = 0;
- UINTN Cols, Rows, MaxColsXRows = 0;
+ UINTN Cols, Rows, MaxWeightedColsXRows = 0;
+ EFI_STATUS Status = EFI_SUCCESS;
for (INT32 ModeNum = 0; ModeNum < gST->ConOut->Mode->MaxMode; ModeNum++)
{
- CONST EFI_STATUS Status = gST->ConOut->QueryMode(gST->ConOut, ModeNum, &Cols, &Rows);
+ Status = gST->ConOut->QueryMode(gST->ConOut, ModeNum, &Cols, &Rows);
if (EFI_ERROR(Status))
continue;
- // Accept only modes where the total of (Rows * Columns) >= the previous known best
- if ((Cols * Rows) >= MaxColsXRows)
+ // Accept only modes where the total of (Rows * Columns) >= the previous known best.
+ // Use 16:10 as an arbitrary weighting that lies in between the common 4:3 and 16:9 ratios
+ CONST UINTN WeightedColsXRows = (16 * Rows) * (10 * Cols);
+ if (WeightedColsXRows >= MaxWeightedColsXRows)
{
- MaxColsXRows = Cols * Rows;
+ MaxWeightedColsXRows = WeightedColsXRows;
MaxModeNum = ModeNum;
}
}
- if (gST->ConOut->Mode->Mode == MaxModeNum)
+ if (gST->ConOut->Mode->Mode != MaxModeNum)
{
- // We're already at the correct mode
- return EFI_SUCCESS;
+ Status = gST->ConOut->SetMode(gST->ConOut, MaxModeNum);
}
- return gST->ConOut->SetMode(gST->ConOut, MaxModeNum);
+ // Clear screen and enable cursor
+ gST->ConOut->ClearScreen(gST->ConOut);
+ gST->ConOut->EnableCursor(gST->ConOut, TRUE);
+
+ return Status;
}
//
@@ -618,8 +627,7 @@ UefiMain(
//
// Set the highest available console mode and clear the screen
//
- SetHighestAvailableMode();
- gST->ConOut->ClearScreen(gST->ConOut);
+ SetHighestAvailableTextMode();
//
// Turn off the watchdog timer
@@ -627,11 +635,6 @@ UefiMain(
gBS->SetWatchdogTimer(0, 0, 0, NULL);
//
- // Enable cursor
- //
- gST->ConOut->EnableCursor(gST->ConOut, TRUE);
-
- //
// Locate, load, start and configure the driver
//
CONST EFI_STATUS DriverStatus = StartAndConfigureDriver(ImageHandle, SystemTable);