X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FConsole%2FGraphicsConsoleDxe%2FGraphicsConsole.c;h=26ea19f300aab95788a89efce198f53bcdf92fb6;hb=9d510e61fceee7b92955ef9a3c20343752d8ce3f;hp=a0983baf697681e4aef936223e51108b57cbd112;hpb=677fdb90fae88a7edd284da3397ca61d9933879d;p=mirror_edk2.git
diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
index a0983baf69..26ea19f300 100644
--- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
+++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
@@ -1,14 +1,8 @@
/** @file
This is the main routine for initializing the Graphics Console support routines.
-Copyright (c) 2006 - 2008 Intel Corporation.
-All rights reserved. This program and the accompanying materials
-are licensed and made available under the terms and conditions of the BSD License
-which accompanies this distribution. The full text of the license may be found at
-http://opensource.org/licenses/bsd-license.php
-
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -35,31 +29,35 @@ GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate = {
},
{
0,
- 0,
+ -1,
EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK),
0,
0,
TRUE
},
- {
- { 80, 25, 0, 0, 0, 0 }, // Mode 0
- { 80, 50, 0, 0, 0, 0 }, // Mode 1
- { 100,31, 0, 0, 0, 0 }, // Mode 2
- { 0, 0, 0, 0, 0, 0 } // Mode 3
- },
- (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,
- (EFI_HII_HANDLE ) 0
+ (GRAPHICS_CONSOLE_MODE_DATA *) NULL,
+ (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL
+};
+
+GRAPHICS_CONSOLE_MODE_DATA mGraphicsConsoleModeData[] = {
+ {100, 31},
+ //
+ // New modes can be added here.
+ // The last entry is specific for full screen mode.
+ //
+ {0, 0}
};
EFI_HII_DATABASE_PROTOCOL *mHiiDatabase;
EFI_HII_FONT_PROTOCOL *mHiiFont;
-BOOLEAN mFirstAccessFlag = TRUE;
+EFI_HII_HANDLE mHiiHandle;
+VOID *mHiiRegistration;
EFI_GUID mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};
CHAR16 mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };
-EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL mGraphicsEfiColors[16] = {
//
// B G R reserved
//
@@ -209,6 +207,148 @@ Error:
return Status;
}
+/**
+ Initialize all the text modes which the graphics console supports.
+
+ It returns information for available text modes that the graphics can support.
+
+ @param[in] HorizontalResolution The size of video screen in pixels in the X dimension.
+ @param[in] VerticalResolution The size of video screen in pixels in the Y dimension.
+ @param[in] GopModeNumber The graphics mode number which graphis console is based on.
+ @param[out] TextModeCount The total number of text modes that graphics console supports.
+ @param[out] TextModeData The buffer to the text modes column and row information.
+ Caller is responsible to free it when it's non-NULL.
+
+ @retval EFI_SUCCESS The supporting mode information is returned.
+ @retval EFI_INVALID_PARAMETER The parameters are invalid.
+
+**/
+EFI_STATUS
+InitializeGraphicsConsoleTextMode (
+ IN UINT32 HorizontalResolution,
+ IN UINT32 VerticalResolution,
+ IN UINT32 GopModeNumber,
+ OUT UINTN *TextModeCount,
+ OUT GRAPHICS_CONSOLE_MODE_DATA **TextModeData
+ )
+{
+ UINTN Index;
+ UINTN Count;
+ GRAPHICS_CONSOLE_MODE_DATA *ModeBuffer;
+ GRAPHICS_CONSOLE_MODE_DATA *NewModeBuffer;
+ UINTN ValidCount;
+ UINTN ValidIndex;
+ UINTN MaxColumns;
+ UINTN MaxRows;
+
+ if ((TextModeCount == NULL) || (TextModeData == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Count = sizeof (mGraphicsConsoleModeData) / sizeof (GRAPHICS_CONSOLE_MODE_DATA);
+
+ //
+ // Compute the maximum number of text Rows and Columns that this current graphics mode can support.
+ // To make graphics console work well, MaxColumns and MaxRows should not be zero.
+ //
+ MaxColumns = HorizontalResolution / EFI_GLYPH_WIDTH;
+ MaxRows = VerticalResolution / EFI_GLYPH_HEIGHT;
+
+ //
+ // According to UEFI spec, all output devices support at least 80x25 text mode.
+ //
+ ASSERT ((MaxColumns >= 80) && (MaxRows >= 25));
+
+ //
+ // Add full screen mode to the last entry.
+ //
+ mGraphicsConsoleModeData[Count - 1].Columns = MaxColumns;
+ mGraphicsConsoleModeData[Count - 1].Rows = MaxRows;
+
+ //
+ // Get defined mode buffer pointer.
+ //
+ ModeBuffer = mGraphicsConsoleModeData;
+
+ //
+ // Here we make sure that the final mode exposed does not include the duplicated modes,
+ // and does not include the invalid modes which exceed the max column and row.
+ // Reserve 2 modes for 80x25, 80x50 of graphics console.
+ //
+ NewModeBuffer = AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA) * (Count + 2));
+ ASSERT (NewModeBuffer != NULL);
+
+ //
+ // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.
+ //
+ ValidCount = 0;
+
+ NewModeBuffer[ValidCount].Columns = 80;
+ NewModeBuffer[ValidCount].Rows = 25;
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;
+ ValidCount++;
+
+ if ((MaxColumns >= 80) && (MaxRows >= 50)) {
+ NewModeBuffer[ValidCount].Columns = 80;
+ NewModeBuffer[ValidCount].Rows = 50;
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;
+ }
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;
+ ValidCount++;
+
+ //
+ // Start from mode 2 to put the valid mode other than 80x25 and 80x50 in the output mode buffer.
+ //
+ for (Index = 0; Index < Count; Index++) {
+ if ((ModeBuffer[Index].Columns == 0) || (ModeBuffer[Index].Rows == 0) ||
+ (ModeBuffer[Index].Columns > MaxColumns) || (ModeBuffer[Index].Rows > MaxRows)) {
+ //
+ // Skip the pre-defined mode which is invalid or exceeds the max column and row.
+ //
+ continue;
+ }
+ for (ValidIndex = 0; ValidIndex < ValidCount; ValidIndex++) {
+ if ((ModeBuffer[Index].Columns == NewModeBuffer[ValidIndex].Columns) &&
+ (ModeBuffer[Index].Rows == NewModeBuffer[ValidIndex].Rows)) {
+ //
+ // Skip the duplicated mode.
+ //
+ break;
+ }
+ }
+ if (ValidIndex == ValidCount) {
+ NewModeBuffer[ValidCount].Columns = ModeBuffer[Index].Columns;
+ NewModeBuffer[ValidCount].Rows = ModeBuffer[Index].Rows;
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;
+ ValidCount++;
+ }
+ }
+
+ DEBUG_CODE (
+ for (Index = 0; Index < ValidCount; Index++) {
+ DEBUG ((EFI_D_INFO, "Graphics - Mode %d, Column = %d, Row = %d\n",
+ Index, NewModeBuffer[Index].Columns, NewModeBuffer[Index].Rows));
+ }
+ );
+
+ //
+ // Return valid mode count and mode information buffer.
+ //
+ *TextModeCount = ValidCount;
+ *TextModeData = NewModeBuffer;
+ return EFI_SUCCESS;
+}
/**
Start this driver on Controller by opening Graphics Output protocol or
@@ -234,21 +374,17 @@ GraphicsConsoleControllerDriverStart (
{
EFI_STATUS Status;
GRAPHICS_CONSOLE_DEV *Private;
- UINT32 NarrowFontSize;
UINT32 HorizontalResolution;
UINT32 VerticalResolution;
UINT32 ColorDepth;
UINT32 RefreshRate;
+ UINT32 ModeIndex;
UINTN MaxMode;
- UINTN Columns;
- UINTN Rows;
UINT32 ModeNumber;
- EFI_HII_SIMPLE_FONT_PACKAGE_HDR *SimplifiedFont;
- UINT32 PackageLength;
- EFI_HII_PACKAGE_LIST_HEADER *PackageList;
- UINT8 *Package;
- UINT8 *Location;
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
+ UINTN SizeOfInfo;
+ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
+
ModeNumber = 0;
//
@@ -288,58 +424,8 @@ GraphicsConsoleControllerDriverStart (
goto Error;
}
- NarrowFontSize = ReturnNarrowFontSize ();
-
- if (mFirstAccessFlag) {
- //
- // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only.
- // Looks ugly. Might be updated when font tool is ready.
- //
- // +--------------------------------+ <-- Package
- // | |
- // | PackageLength(4 bytes) |
- // | |
- // |--------------------------------| <-- SimplifiedFont
- // | |
- // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
- // | |
- // |--------------------------------| <-- Location
- // | |
- // | gUsStdNarrowGlyphData |
- // | |
- // +--------------------------------+
-
- PackageLength = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + NarrowFontSize + 4;
- Package = AllocateZeroPool (PackageLength);
- if (Package == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
- WriteUnaligned32((UINT32 *) Package,PackageLength);
- SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR *) (Package + 4);
- SimplifiedFont->Header.Length = (UINT32) (PackageLength - 4);
- SimplifiedFont->Header.Type = EFI_HII_PACKAGE_SIMPLE_FONTS;
- SimplifiedFont->NumberOfNarrowGlyphs = (UINT16) (NarrowFontSize / sizeof (EFI_NARROW_GLYPH));
-
- Location = (UINT8 *) (&SimplifiedFont->NumberOfWideGlyphs + 1);
- CopyMem (Location, gUsStdNarrowGlyphData, NarrowFontSize);
-
- //
- // Add this simplified font package to a package list then install it.
- //
- PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package);
- Status = mHiiDatabase->NewPackageList (mHiiDatabase, PackageList, NULL, &(Private->HiiHandle));
- ASSERT_EFI_ERROR (Status);
- FreePool (PackageList);
- FreePool (Package);
-
- mFirstAccessFlag = FALSE;
- }
- //
- // If the current mode information can not be retrieved, then attempt to set the default mode
- // of 800x600, 32 bit color, 60 Hz refresh.
- //
- HorizontalResolution = 800;
- VerticalResolution = 600;
+ HorizontalResolution = PcdGet32 (PcdVideoHorizontalResolution);
+ VerticalResolution = PcdGet32 (PcdVideoVerticalResolution);
if (Private->GraphicsOutput != NULL) {
//
@@ -347,39 +433,78 @@ GraphicsConsoleControllerDriverStart (
// for the user-defined mode; if there are multiple video devices,
// graphic console driver will set all the video devices to the same mode.
//
- Status = CheckModeSupported (
- Private->GraphicsOutput,
- CURRENT_HORIZONTAL_RESOLUTION,
- CURRENT_VERTICAL_RESOLUTION,
- &ModeNumber
- );
- if (!EFI_ERROR(Status)) {
+ if ((HorizontalResolution == 0x0) || (VerticalResolution == 0x0)) {
//
- // Update default mode to current mode
+ // Find the highest resolution which GOP supports.
//
- HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;
- VerticalResolution = CURRENT_VERTICAL_RESOLUTION;
+ MaxMode = Private->GraphicsOutput->Mode->MaxMode;
+
+ for (ModeIndex = 0; ModeIndex < MaxMode; ModeIndex++) {
+ Status = Private->GraphicsOutput->QueryMode (
+ Private->GraphicsOutput,
+ ModeIndex,
+ &SizeOfInfo,
+ &Info
+ );
+ if (!EFI_ERROR (Status)) {
+ if ((Info->HorizontalResolution > HorizontalResolution) ||
+ ((Info->HorizontalResolution == HorizontalResolution) && (Info->VerticalResolution > VerticalResolution))) {
+ HorizontalResolution = Info->HorizontalResolution;
+ VerticalResolution = Info->VerticalResolution;
+ ModeNumber = ModeIndex;
+ }
+ FreePool (Info);
+ }
+ }
+ if ((HorizontalResolution == 0x0) || (VerticalResolution == 0x0)) {
+ Status = EFI_UNSUPPORTED;
+ goto Error;
+ }
} else {
//
- // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
+ // Use user-defined resolution
//
Status = CheckModeSupported (
Private->GraphicsOutput,
- 800,
- 600,
+ HorizontalResolution,
+ VerticalResolution,
&ModeNumber
);
+ if (EFI_ERROR (Status)) {
+ //
+ // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
+ //
+ HorizontalResolution = 800;
+ VerticalResolution = 600;
+ Status = CheckModeSupported (
+ Private->GraphicsOutput,
+ HorizontalResolution,
+ VerticalResolution,
+ &ModeNumber
+ );
+ Mode = Private->GraphicsOutput->Mode;
+ if (EFI_ERROR (Status) && Mode->MaxMode != 0) {
+ //
+ // Set default mode failed or device don't support default mode, then get the current mode information
+ //
+ HorizontalResolution = Mode->Info->HorizontalResolution;
+ VerticalResolution = Mode->Info->VerticalResolution;
+ ModeNumber = Mode->Mode;
+ }
+ }
}
-
- Mode = Private->GraphicsOutput->Mode;
-
- if (EFI_ERROR (Status) || (Mode->MaxMode != 0)) {
+ if (ModeNumber != Private->GraphicsOutput->Mode->Mode) {
//
- // Set default mode failed or device don't support default mode, then get the current mode information
+ // Current graphics mode is not set or is not set to the mode which we has found,
+ // set the new graphic mode.
//
- HorizontalResolution = Mode->Info->HorizontalResolution;
- VerticalResolution = Mode->Info->VerticalResolution;
- ModeNumber = Mode->Mode;
+ Status = Private->GraphicsOutput->SetMode (Private->GraphicsOutput, ModeNumber);
+ if (EFI_ERROR (Status)) {
+ //
+ // The mode set operation failed
+ //
+ goto Error;
+ }
}
} else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
//
@@ -389,22 +514,19 @@ GraphicsConsoleControllerDriverStart (
RefreshRate = 60;
Status = Private->UgaDraw->SetMode (
Private->UgaDraw,
- CURRENT_HORIZONTAL_RESOLUTION,
- CURRENT_VERTICAL_RESOLUTION,
+ HorizontalResolution,
+ VerticalResolution,
ColorDepth,
RefreshRate
);
- if (!EFI_ERROR (Status)) {
- HorizontalResolution = CURRENT_HORIZONTAL_RESOLUTION;
- VerticalResolution = CURRENT_VERTICAL_RESOLUTION;
- } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
+ if (EFI_ERROR (Status)) {
//
// Try to set 800*600 which is required by UEFI/EFI spec
//
Status = Private->UgaDraw->SetMode (
Private->UgaDraw,
- HorizontalResolution,
- VerticalResolution,
+ 800,
+ 600,
ColorDepth,
RefreshRate
);
@@ -420,85 +542,24 @@ GraphicsConsoleControllerDriverStart (
goto Error;
}
}
- } else {
- Status = EFI_UNSUPPORTED;
- goto Error;
}
}
- //
- // Compute the maximum number of text Rows and Columns that this current graphics mode can support
- //
- Columns = HorizontalResolution / EFI_GLYPH_WIDTH;
- Rows = VerticalResolution / EFI_GLYPH_HEIGHT;
-
- //
- // See if the mode is too small to support the required 80x25 text mode
- //
- if (Columns < 80 || Rows < 25) {
- goto Error;
- }
- //
- // Add Mode #0 that must be 80x25
- //
- MaxMode = 0;
- Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
- Private->ModeData[MaxMode].GopHeight = VerticalResolution;
- Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
- Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;
- Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (25 * EFI_GLYPH_HEIGHT)) >> 1;
- MaxMode++;
-
- //
- // If it is possible to support Mode #1 - 80x50, than add it as an active mode
- //
- if (Rows >= 50) {
- Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
- Private->ModeData[MaxMode].GopHeight = VerticalResolution;
- Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
- Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;
- Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;
- MaxMode++;
- }
-
- //
- // If it is not to support Mode #1 - 80x50, then skip it
- //
- if (MaxMode < 2) {
- Private->ModeData[MaxMode].Columns = 0;
- Private->ModeData[MaxMode].Rows = 0;
- Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
- Private->ModeData[MaxMode].GopHeight = VerticalResolution;
- Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
- Private->ModeData[MaxMode].DeltaX = 0;
- Private->ModeData[MaxMode].DeltaY = 0;
- MaxMode++;
- }
+ DEBUG ((EFI_D_INFO, "GraphicsConsole video resolution %d x %d\n", HorizontalResolution, VerticalResolution));
//
- // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)
+ // Initialize the mode which GraphicsConsole supports.
//
- if (Columns >= 100 && Rows >= 31) {
- Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
- Private->ModeData[MaxMode].GopHeight = VerticalResolution;
- Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
- Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (100 * EFI_GLYPH_WIDTH)) >> 1;
- Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (31 * EFI_GLYPH_HEIGHT)) >> 1;
- MaxMode++;
- }
+ Status = InitializeGraphicsConsoleTextMode (
+ HorizontalResolution,
+ VerticalResolution,
+ ModeNumber,
+ &MaxMode,
+ &Private->ModeData
+ );
- //
- // Add Mode #3 that uses the entire display for user-defined mode
- //
- if (HorizontalResolution > 800 && VerticalResolution > 600) {
- Private->ModeData[MaxMode].Columns = HorizontalResolution/EFI_GLYPH_WIDTH;
- Private->ModeData[MaxMode].Rows = VerticalResolution/EFI_GLYPH_HEIGHT;
- Private->ModeData[MaxMode].GopWidth = HorizontalResolution;
- Private->ModeData[MaxMode].GopHeight = VerticalResolution;
- Private->ModeData[MaxMode].GopModeNumber = ModeNumber;
- Private->ModeData[MaxMode].DeltaX = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1;
- Private->ModeData[MaxMode].DeltaY = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1;
- MaxMode++;
+ if (EFI_ERROR (Status)) {
+ goto Error;
}
//
@@ -506,16 +567,15 @@ GraphicsConsoleControllerDriverStart (
//
Private->SimpleTextOutputMode.MaxMode = (INT32) MaxMode;
- //
- // Determine the number of text modes that this protocol can support
- //
- Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);
- if (EFI_ERROR (Status)) {
- goto Error;
- }
-
DEBUG_CODE_BEGIN ();
- GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");
+ Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+ Status = GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
DEBUG_CODE_END ();
//
@@ -535,29 +595,32 @@ Error:
//
if (Private->GraphicsOutput != NULL) {
gBS->CloseProtocol (
- Controller,
- &gEfiGraphicsOutputProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
+ Controller,
+ &gEfiGraphicsOutputProtocolGuid,
+ This->DriverBindingHandle,
+ Controller
+ );
} else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
gBS->CloseProtocol (
- Controller,
- &gEfiUgaDrawProtocolGuid,
- This->DriverBindingHandle,
- Controller
- );
+ Controller,
+ &gEfiUgaDrawProtocolGuid,
+ This->DriverBindingHandle,
+ Controller
+ );
+ }
+
+ if (Private->LineBuffer != NULL) {
+ FreePool (Private->LineBuffer);
+ }
+
+ if (Private->ModeData != NULL) {
+ FreePool (Private->ModeData);
}
//
// Free private data
//
- if (Private != NULL) {
- if (Private->LineBuffer != NULL) {
- FreePool (Private->LineBuffer);
- }
- FreePool (Private);
- }
+ FreePool (Private);
}
return Status;
@@ -634,21 +697,18 @@ GraphicsConsoleControllerDriverStop (
);
}
- //
- // Remove the font pack
- //
- if (Private->HiiHandle != NULL) {
- HiiLibRemovePackages (Private->HiiHandle);
- mFirstAccessFlag = TRUE;
+ if (Private->LineBuffer != NULL) {
+ FreePool (Private->LineBuffer);
+ }
+
+ if (Private->ModeData != NULL) {
+ FreePool (Private->ModeData);
}
//
// Free our instance data
//
- if (Private != NULL) {
- FreePool (Private->LineBuffer);
- FreePool (Private);
- }
+ FreePool (Private);
}
return Status;
@@ -700,10 +760,19 @@ CheckModeSupported (
if (!EFI_ERROR (Status)) {
if ((Info->HorizontalResolution == HorizontalResolution) &&
(Info->VerticalResolution == VerticalResolution)) {
- Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
- if (!EFI_ERROR (Status)) {
+ if ((GraphicsOutput->Mode->Info->HorizontalResolution == HorizontalResolution) &&
+ (GraphicsOutput->Mode->Info->VerticalResolution == VerticalResolution)) {
+ //
+ // If video device has been set to this mode, we do not need to SetMode again
+ //
FreePool (Info);
break;
+ } else {
+ Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
+ if (!EFI_ERROR (Status)) {
+ FreePool (Info);
+ break;
+ }
}
}
FreePool (Info);
@@ -733,42 +802,14 @@ EfiLocateHiiProtocol (
VOID
)
{
- EFI_HANDLE Handle;
- UINTN Size;
EFI_STATUS Status;
- //
- // There should only be one - so buffer size is this
- //
- Size = sizeof (EFI_HANDLE);
-
- Status = gBS->LocateHandle (
- ByProtocol,
- &gEfiHiiDatabaseProtocolGuid,
- NULL,
- &Size,
- (VOID **) &Handle
- );
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- Status = gBS->HandleProtocol (
- Handle,
- &gEfiHiiDatabaseProtocolGuid,
- (VOID **) &mHiiDatabase
- );
-
+ Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &mHiiDatabase);
if (EFI_ERROR (Status)) {
return Status;
}
- Status = gBS->HandleProtocol (
- Handle,
- &gEfiHiiFontProtocolGuid,
- (VOID **) &mHiiFont
- );
+ Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &mHiiFont);
return Status;
}
@@ -801,8 +842,13 @@ GraphicsConsoleConOutReset (
IN BOOLEAN ExtendedVerification
)
{
- This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
- return This->SetMode (This, 0);
+ EFI_STATUS Status;
+ Status = This->SetMode (This, 0);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ Status = This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
+ return Status;
}
@@ -855,6 +901,13 @@ GraphicsConsoleConOutOutputString (
INT32 OriginAttribute;
EFI_TPL OldTpl;
+ if (This->Mode->Mode == -1) {
+ //
+ // If current mode is not valid, return error.
+ //
+ return EFI_UNSUPPORTED;
+ }
+
Status = EFI_SUCCESS;
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
@@ -868,8 +921,8 @@ GraphicsConsoleConOutOutputString (
MaxColumn = Private->ModeData[Mode].Columns;
MaxRow = Private->ModeData[Mode].Rows;
- DeltaX = Private->ModeData[Mode].DeltaX;
- DeltaY = Private->ModeData[Mode].DeltaY;
+ DeltaX = (UINTN) Private->ModeData[Mode].DeltaX;
+ DeltaY = (UINTN) Private->ModeData[Mode].DeltaY;
Width = MaxColumn * EFI_GLYPH_WIDTH;
Height = (MaxRow - 1) * EFI_GLYPH_HEIGHT;
Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
@@ -879,7 +932,7 @@ GraphicsConsoleConOutOutputString (
//
GetTextColors (This, &Foreground, &Background);
- EraseCursor (This);
+ FlushCursor (This);
Warning = FALSE;
@@ -899,7 +952,7 @@ GraphicsConsoleConOutOutputString (
This->Mode->CursorRow--;
This->Mode->CursorColumn = (INT32) (MaxColumn - 1);
This->OutputString (This, SpaceStr);
- EraseCursor (This);
+ FlushCursor (This);
This->Mode->CursorRow--;
This->Mode->CursorColumn = (INT32) (MaxColumn - 1);
} else if (This->Mode->CursorColumn > 0) {
@@ -909,7 +962,7 @@ GraphicsConsoleConOutOutputString (
//
This->Mode->CursorColumn--;
This->OutputString (This, SpaceStr);
- EraseCursor (This);
+ FlushCursor (This);
This->Mode->CursorColumn--;
}
@@ -1068,16 +1121,16 @@ GraphicsConsoleConOutOutputString (
}
if (This->Mode->CursorColumn >= (INT32) MaxColumn) {
- EraseCursor (This);
+ FlushCursor (This);
This->OutputString (This, mCrLfString);
- EraseCursor (This);
+ FlushCursor (This);
}
}
}
This->Mode->Attribute = OriginAttribute;
- EraseCursor (This);
+ FlushCursor (This);
if (Warning) {
Status = EFI_WARN_UNKNOWN_GLYPH;
@@ -1187,7 +1240,7 @@ GraphicsConsoleConOutQueryMode (
*Columns = Private->ModeData[ModeNumber].Columns;
*Rows = Private->ModeData[ModeNumber].Rows;
- if (*Columns <= 0 && *Rows <= 0) {
+ if (*Columns <= 0 || *Rows <= 0) {
Status = EFI_UNSUPPORTED;
goto Done;
@@ -1238,12 +1291,6 @@ GraphicsConsoleConOutSetMode (
Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
GraphicsOutput = Private->GraphicsOutput;
UgaDraw = Private->UgaDraw;
- ModeData = &(Private->ModeData[ModeNumber]);
-
- if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {
- Status = EFI_UNSUPPORTED;
- goto Done;
- }
//
// Make sure the requested mode number is supported
@@ -1253,37 +1300,25 @@ GraphicsConsoleConOutSetMode (
goto Done;
}
+ ModeData = &(Private->ModeData[ModeNumber]);
+
if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {
Status = EFI_UNSUPPORTED;
goto Done;
}
- //
- // Attempt to allocate a line buffer for the requested mode number
- //
- NewLineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT);
- if (NewLineBuffer == NULL) {
- //
- // The new line buffer could not be allocated, so return an error.
- // No changes to the state of the current console have been made, so the current console is still valid
- //
- Status = EFI_OUT_OF_RESOURCES;
- goto Done;
- }
//
// If the mode has been set at least one other time, then LineBuffer will not be NULL
//
if (Private->LineBuffer != NULL) {
- //
- // Clear the current text window on the current graphics console
- //
- This->ClearScreen (This);
-
//
// If the new mode is the same as the old mode, then just return EFI_SUCCESS
//
if ((INT32) ModeNumber == This->Mode->Mode) {
- FreePool (NewLineBuffer);
+ //
+ // Clear the current text window on the current graphics console
+ //
+ This->ClearScreen (This);
Status = EFI_SUCCESS;
goto Done;
}
@@ -1291,10 +1326,25 @@ GraphicsConsoleConOutSetMode (
// Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
// so erase the cursor, and free the LineBuffer for the current mode
//
- EraseCursor (This);
+ FlushCursor (This);
FreePool (Private->LineBuffer);
}
+
+ //
+ // Attempt to allocate a line buffer for the requested mode number
+ //
+ NewLineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * ModeData->Columns * EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT);
+
+ if (NewLineBuffer == NULL) {
+ //
+ // The new line buffer could not be allocated, so return an error.
+ // No changes to the state of the current console have been made, so the current console is still valid
+ //
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Done;
+ }
+
//
// Assign the current line buffer to the newly allocated line buffer
//
@@ -1318,7 +1368,7 @@ GraphicsConsoleConOutSetMode (
//
Status = GraphicsOutput->Blt (
GraphicsOutput,
- &mEfiColors[0],
+ &mGraphicsEfiColors[0],
EfiBltVideoFill,
0,
0,
@@ -1363,7 +1413,7 @@ GraphicsConsoleConOutSetMode (
//
Status = UgaDraw->Blt (
UgaDraw,
- (EFI_UGA_PIXEL *) (UINTN) &mEfiColors[0],
+ (EFI_UGA_PIXEL *) (UINTN) &mGraphicsEfiColors[0],
EfiUgaVideoFill,
0,
0,
@@ -1382,9 +1432,12 @@ GraphicsConsoleConOutSetMode (
This->Mode->Mode = (INT32) ModeNumber;
//
- // Move the text cursor to the upper left hand corner of the display and enable it
+ // Move the text cursor to the upper left hand corner of the display and flush it
//
- This->SetCursorPosition (This, 0, 0);
+ This->Mode->CursorColumn = 0;
+ This->Mode->CursorRow = 0;
+
+ FlushCursor (This);
Status = EFI_SUCCESS;
@@ -1419,7 +1472,7 @@ GraphicsConsoleConOutSetAttribute (
{
EFI_TPL OldTpl;
- if ((Attribute | 0xFF) != 0xFF) {
+ if ((Attribute | 0x7F) != 0x7F) {
return EFI_UNSUPPORTED;
}
@@ -1429,11 +1482,11 @@ GraphicsConsoleConOutSetAttribute (
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
- EraseCursor (This);
+ FlushCursor (This);
This->Mode->Attribute = (INT32) Attribute;
- EraseCursor (This);
+ FlushCursor (This);
gBS->RestoreTPL (OldTpl);
@@ -1469,6 +1522,13 @@ GraphicsConsoleConOutClearScreen (
EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
EFI_TPL OldTpl;
+ if (This->Mode->Mode == -1) {
+ //
+ // If current mode is not valid, return error.
+ //
+ return EFI_UNSUPPORTED;
+ }
+
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This);
@@ -1510,7 +1570,7 @@ GraphicsConsoleConOutClearScreen (
This->Mode->CursorColumn = 0;
This->Mode->CursorRow = 0;
- EraseCursor (This);
+ FlushCursor (This);
gBS->RestoreTPL (OldTpl);
@@ -1550,6 +1610,13 @@ GraphicsConsoleConOutSetCursorPosition (
EFI_STATUS Status;
EFI_TPL OldTpl;
+ if (This->Mode->Mode == -1) {
+ //
+ // If current mode is not valid, return error.
+ //
+ return EFI_UNSUPPORTED;
+ }
+
Status = EFI_SUCCESS;
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
@@ -1567,12 +1634,12 @@ GraphicsConsoleConOutSetCursorPosition (
goto Done;
}
- EraseCursor (This);
+ FlushCursor (This);
This->Mode->CursorColumn = (INT32) Column;
This->Mode->CursorRow = (INT32) Row;
- EraseCursor (This);
+ FlushCursor (This);
Done:
gBS->RestoreTPL (OldTpl);
@@ -1591,6 +1658,8 @@ Done:
the cursor is set to be invisible.
@retval EFI_SUCCESS The operation completed successfully.
+ @retval EFI_UNSUPPORTED The output device's mode is not currently in a
+ defined text mode.
**/
EFI_STATUS
@@ -1602,13 +1671,20 @@ GraphicsConsoleConOutEnableCursor (
{
EFI_TPL OldTpl;
+ if (This->Mode->Mode == -1) {
+ //
+ // If current mode is not valid, return error.
+ //
+ return EFI_UNSUPPORTED;
+ }
+
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
- EraseCursor (This);
+ FlushCursor (This);
This->Mode->CursorVisible = Visible;
- EraseCursor (This);
+ FlushCursor (This);
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
@@ -1635,8 +1711,8 @@ GetTextColors (
Attribute = This->Mode->Attribute & 0x7F;
- *Foreground = mEfiColors[Attribute & 0x0f];
- *Background = mEfiColors[Attribute >> 4];
+ *Foreground = mGraphicsEfiColors[Attribute & 0x0f];
+ *Background = mGraphicsEfiColors[Attribute >> 4];
return EFI_SUCCESS;
}
@@ -1708,7 +1784,7 @@ DrawUnicodeWeightAtCursorN (
Status = mHiiFont->StringToImage (
mHiiFont,
- EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,
+ EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN | EFI_HII_IGNORE_LINE_BREAK,
String,
FontInfo,
&Blt,
@@ -1742,7 +1818,7 @@ DrawUnicodeWeightAtCursorN (
//
Status = mHiiFont->StringToImage (
mHiiFont,
- EFI_HII_IGNORE_IF_NO_GLYPH,
+ EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK,
String,
FontInfo,
&Blt,
@@ -1793,7 +1869,12 @@ DrawUnicodeWeightAtCursorN (
}
/**
- Erase the cursor on the screen.
+ Flush the cursor on the screen.
+
+ If CursorVisible is FALSE, nothing to do and return directly.
+ If CursorVisible is TRUE,
+ i) If the cursor shows on screen, it will be erased.
+ ii) If the cursor does not show on screen, it will be shown.
@param This Protocol instance pointer.
@@ -1801,7 +1882,7 @@ DrawUnicodeWeightAtCursorN (
**/
EFI_STATUS
-EraseCursor (
+FlushCursor (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
)
{
@@ -1907,6 +1988,83 @@ EraseCursor (
return EFI_SUCCESS;
}
+/**
+ HII Database Protocol notification event handler.
+
+ Register font package when HII Database Protocol has been installed.
+
+ @param[in] Event Event whose notification function is being invoked.
+ @param[in] Context Pointer to the notification function's context.
+**/
+VOID
+EFIAPI
+RegisterFontPackage (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ EFI_STATUS Status;
+ EFI_HII_SIMPLE_FONT_PACKAGE_HDR *SimplifiedFont;
+ UINT32 PackageLength;
+ UINT8 *Package;
+ UINT8 *Location;
+ EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
+
+ //
+ // Locate HII Database Protocol
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiHiiDatabaseProtocolGuid,
+ NULL,
+ (VOID **) &HiiDatabase
+ );
+ if (EFI_ERROR (Status)) {
+ return;
+ }
+
+ //
+ // Add 4 bytes to the header for entire length for HiiAddPackages use only.
+ //
+ // +--------------------------------+ <-- Package
+ // | |
+ // | PackageLength(4 bytes) |
+ // | |
+ // |--------------------------------| <-- SimplifiedFont
+ // | |
+ // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
+ // | |
+ // |--------------------------------| <-- Location
+ // | |
+ // | gUsStdNarrowGlyphData |
+ // | |
+ // +--------------------------------+
+
+ PackageLength = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + mNarrowFontSize + 4;
+ Package = AllocateZeroPool (PackageLength);
+ ASSERT (Package != NULL);
+
+ WriteUnaligned32((UINT32 *) Package,PackageLength);
+ SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR *) (Package + 4);
+ SimplifiedFont->Header.Length = (UINT32) (PackageLength - 4);
+ SimplifiedFont->Header.Type = EFI_HII_PACKAGE_SIMPLE_FONTS;
+ SimplifiedFont->NumberOfNarrowGlyphs = (UINT16) (mNarrowFontSize / sizeof (EFI_NARROW_GLYPH));
+
+ Location = (UINT8 *) (&SimplifiedFont->NumberOfWideGlyphs + 1);
+ CopyMem (Location, gUsStdNarrowGlyphData, mNarrowFontSize);
+
+ //
+ // Add this simplified font package to a package list then install it.
+ //
+ mHiiHandle = HiiAddPackages (
+ &mFontPackageListGuid,
+ NULL,
+ Package,
+ NULL
+ );
+ ASSERT (mHiiHandle != NULL);
+ FreePool (Package);
+}
+
/**
The user Entry Point for module GraphicsConsole. The user code starts with this function.
@@ -1926,6 +2084,17 @@ InitializeGraphicsConsole (
{
EFI_STATUS Status;
+ //
+ // Register notify function on HII Database Protocol to add font package.
+ //
+ EfiCreateProtocolNotifyEvent (
+ &gEfiHiiDatabaseProtocolGuid,
+ TPL_CALLBACK,
+ RegisterFontPackage,
+ NULL,
+ &mHiiRegistration
+ );
+
//
// Install driver model protocol(s).
//