X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FConsole%2FGraphicsConsoleDxe%2FGraphicsConsole.c;h=2fe6dc02dae7578fd8aebe115c5ad272bd27025d;hp=13486a0462255b6d03cf86429658df6d211118e4;hb=7601dbe7c5ed94c859600649fc316918bb3572b3;hpb=24248368f7e06914e864ea20e38db8d9a9d3d1f7 diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c index 13486a0462..2fe6dc02da 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c @@ -1,10 +1,5 @@ /** @file This is the main routine for initializing the Graphics Console support routines. -Remaining Tasks - Add all standard Glyphs from UEFI 2.0 Specification - Implement optimal automatic Mode creation algorithm - Solve palette issues for mixed graphics and text - When does this protocol reset the palette? Copyright (c) 2006 - 2008 Intel Corporation.
All rights reserved. This program and the accompanying materials @@ -19,6 +14,90 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "GraphicsConsole.h" +// +// Graphics Console Device Private Data template +// +GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate = { + GRAPHICS_CONSOLE_DEV_SIGNATURE, + (EFI_GRAPHICS_OUTPUT_PROTOCOL *) NULL, + (EFI_UGA_DRAW_PROTOCOL *) NULL, + { + GraphicsConsoleConOutReset, + GraphicsConsoleConOutOutputString, + GraphicsConsoleConOutTestString, + GraphicsConsoleConOutQueryMode, + GraphicsConsoleConOutSetMode, + GraphicsConsoleConOutSetAttribute, + GraphicsConsoleConOutClearScreen, + GraphicsConsoleConOutSetCursorPosition, + GraphicsConsoleConOutEnableCursor, + (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL + }, + { + 0, + 0, + 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 +}; + +EFI_HII_DATABASE_PROTOCOL *mHiiDatabase; +EFI_HII_FONT_PROTOCOL *mHiiFont; +BOOLEAN mFirstAccessFlag = TRUE; + +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] = { + // + // B G R reserved + // + {0x00, 0x00, 0x00, 0x00}, // BLACK + {0x98, 0x00, 0x00, 0x00}, // LIGHTBLUE + {0x00, 0x98, 0x00, 0x00}, // LIGHGREEN + {0x98, 0x98, 0x00, 0x00}, // LIGHCYAN + {0x00, 0x00, 0x98, 0x00}, // LIGHRED + {0x98, 0x00, 0x98, 0x00}, // MAGENTA + {0x00, 0x98, 0x98, 0x00}, // BROWN + {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY + {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK + {0xff, 0x00, 0x00, 0x00}, // BLUE + {0x00, 0xff, 0x00, 0x00}, // LIME + {0xff, 0xff, 0x00, 0x00}, // CYAN + {0x00, 0x00, 0xff, 0x00}, // RED + {0xff, 0x00, 0xff, 0x00}, // FUCHSIA + {0x00, 0xff, 0xff, 0x00}, // YELLOW + {0xff, 0xff, 0xff, 0x00} // WHITE +}; + +EFI_NARROW_GLYPH mCursorGlyph = { + 0x0000, + 0x00, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF } +}; + +CHAR16 SpaceStr[] = { NARROW_CHAR, ' ', 0 }; + +EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = { + GraphicsConsoleControllerDriverSupported, + GraphicsConsoleControllerDriverStart, + GraphicsConsoleControllerDriverStop, + 0xa, + NULL, + NULL +}; + /** Gets Graphics Console devcie's foreground color and background color. @@ -37,7 +116,7 @@ GetTextColors ( ); /** - Draw Unicode string on the Graphice Console device's screen. + Draw Unicode string on the Graphics Console device's screen. @param This Protocol instance pointer. @param UnicodeWeight One Unicode string to be displayed. @@ -71,18 +150,18 @@ EraseCursor ( /** Check if the current specific mode supported the user defined resolution - for the Graphice Console devcie based on Graphics Output Protocol. + for the Graphics Console device based on Graphics Output Protocol. - If yes, set the graphic devcice's current mode to this specific mode. + If yes, set the graphic device's current mode to this specific mode. @param GraphicsOutput Graphics Output Protocol instance pointer. @param HorizontalResolution User defined horizontal resolution @param VerticalResolution User defined vertical resolution. @param CurrentModeNumber Current specific mode to be check. - @retval EFI_SUCCESS This driver is removed ControllerHandle. + @retval EFI_SUCCESS The mode is supported. @retval EFI_UNSUPPORTED The specific mode is out of range of graphics - devcie supported. + device supported. @retval other The specific mode does not support user defined resolution or failed to set the current mode to the specific mode on graphics device. @@ -96,105 +175,21 @@ CheckModeSupported ( OUT UINT32 *CurrentModeNumber ); -// -// Globals -// -GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate = { - GRAPHICS_CONSOLE_DEV_SIGNATURE, - (EFI_GRAPHICS_OUTPUT_PROTOCOL *) NULL, - (EFI_UGA_DRAW_PROTOCOL *) NULL, - { - GraphicsConsoleConOutReset, - GraphicsConsoleConOutOutputString, - GraphicsConsoleConOutTestString, - GraphicsConsoleConOutQueryMode, - GraphicsConsoleConOutSetMode, - GraphicsConsoleConOutSetAttribute, - GraphicsConsoleConOutClearScreen, - GraphicsConsoleConOutSetCursorPosition, - GraphicsConsoleConOutEnableCursor, - (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL - }, - { - 0, - 0, - 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 -}; - -EFI_HII_DATABASE_PROTOCOL *mHiiDatabase; -EFI_HII_FONT_PROTOCOL *mHiiFont; -BOOLEAN mFirstAccessFlag = TRUE; - -STATIC EFI_GUID mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, 0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}; - -STATIC CHAR16 mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL }; - -STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = { - // - // B G R - // - {0x00, 0x00, 0x00, 0x00}, // BLACK - {0x98, 0x00, 0x00, 0x00}, // BLUE - {0x00, 0x98, 0x00, 0x00}, // GREEN - {0x98, 0x98, 0x00, 0x00}, // CYAN - {0x00, 0x00, 0x98, 0x00}, // RED - {0x98, 0x00, 0x98, 0x00}, // MAGENTA - {0x00, 0x98, 0x98, 0x00}, // BROWN - {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY - {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK - {0xff, 0x00, 0x00, 0x00}, // LIGHTBLUE - ? - {0x00, 0xff, 0x00, 0x00}, // LIGHTGREEN - ? - {0xff, 0xff, 0x00, 0x00}, // LIGHTCYAN - {0x00, 0x00, 0xff, 0x00}, // LIGHTRED - {0xff, 0x00, 0xff, 0x00}, // LIGHTMAGENTA - {0x00, 0xff, 0xff, 0x00}, // LIGHTBROWN - {0xff, 0xff, 0xff, 0x00} // WHITE -}; - -STATIC EFI_NARROW_GLYPH mCursorGlyph = { - 0x0000, - 0x00, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF } -}; - -STATIC CHAR16 SpaceStr[] = { NARROW_CHAR, ' ', 0 }; - -EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = { - GraphicsConsoleControllerDriverSupported, - GraphicsConsoleControllerDriverStart, - GraphicsConsoleControllerDriverStop, - 0xa, - NULL, - NULL -}; - /** - Test to see if Graphics Console could be supported on the ControllerHandle. + Test to see if Graphics Console could be supported on the Controller. Graphics Console could be supported if Graphics Output Protocol or UGA Draw - Protocol exists on the ControllerHandle. (UGA Draw Protocol could be shipped + Protocol exists on the Controller. (UGA Draw Protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.) @param This Protocol instance pointer. - @param ControllerHandle Handle of device to test. + @param Controller Handle of device to test. @param RemainingDevicePath Optional parameter use to pick a specific child device to start. - @retval EFI_SUCCESS This driver supports this device - @retval other This driver does not support this device + @retval EFI_SUCCESS This driver supports this device. + @retval other This driver does not support this device. **/ EFI_STATUS @@ -294,17 +289,17 @@ Error: /** - Start this driver on ControllerHandle by opening Graphics Output protocol or - UGA Draw protocol, and installing Simple Text Out protocol on ControllerHandle. - (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.) + Start this driver on Controller by opening Graphics Output protocol or + UGA Draw protocol, and installing Simple Text Out protocol on Controller. + (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.) @param This Protocol instance pointer. - @param ControllerHandle Handle of device to bind driver to + @param Controller Handle of device to bind driver to @param RemainingDevicePath Optional parameter use to pick a specific child device to start. - @retval EFI_SUCCESS This driver is added to ControllerHandle - @retval other This driver does not support this device + @retval EFI_SUCCESS This driver is added to Controller. + @retval other This driver does not support this device. **/ EFI_STATUS @@ -317,7 +312,7 @@ GraphicsConsoleControllerDriverStart ( { EFI_STATUS Status; GRAPHICS_CONSOLE_DEV *Private; - UINTN NarrowFontSize; + UINT32 NarrowFontSize; UINT32 HorizontalResolution; UINT32 VerticalResolution; UINT32 ColorDepth; @@ -327,11 +322,11 @@ GraphicsConsoleControllerDriverStart ( UINTN Rows; UINT32 ModeNumber; EFI_HII_SIMPLE_FONT_PACKAGE_HDR *SimplifiedFont; - UINTN PackageLength; + UINT32 PackageLength; EFI_HII_PACKAGE_LIST_HEADER *PackageList; UINT8 *Package; UINT8 *Location; - + EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode; ModeNumber = 0; // @@ -378,19 +373,33 @@ GraphicsConsoleControllerDriverStart ( // 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; } - CopyMem (Package, &PackageLength, 4); - SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR*) (Package + 4); + 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, UsStdNarrowGlyphData, NarrowFontSize); + CopyMem (Location, gUsStdNarrowGlyphData, NarrowFontSize); // // Add this simplified font package to a package list then install it. @@ -398,14 +407,14 @@ GraphicsConsoleControllerDriverStart ( PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package); Status = mHiiDatabase->NewPackageList (mHiiDatabase, PackageList, NULL, &(Private->HiiHandle)); ASSERT_EFI_ERROR (Status); - SafeFreePool (PackageList); - SafeFreePool (Package); + FreePool (PackageList); + FreePool (Package); mFirstAccessFlag = FALSE; } // - // If the current mode information can not be retrieved, then attemp to set the default mode - // of 800x600, 32 bit colot, 60 Hz refresh. + // 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; @@ -439,14 +448,16 @@ GraphicsConsoleControllerDriverStart ( &ModeNumber ); } - - if (EFI_ERROR (Status) || (ModeNumber == Private->GraphicsOutput->Mode->MaxMode)) { + + Mode = Private->GraphicsOutput->Mode; + + if (EFI_ERROR (Status) || (Mode->MaxMode)) { // // Set default mode failed or device don't support default mode, then get the current mode information // - HorizontalResolution = Private->GraphicsOutput->Mode->Info->HorizontalResolution; - VerticalResolution = Private->GraphicsOutput->Mode->Info->VerticalResolution; - ModeNumber = Private->GraphicsOutput->Mode->Mode; + HorizontalResolution = Mode->Info->HorizontalResolution; + VerticalResolution = Mode->Info->VerticalResolution; + ModeNumber = Mode->Mode; } } else if (FeaturePcdGet (PcdUgaConsumeSupport)) { // @@ -509,22 +520,22 @@ GraphicsConsoleControllerDriverStart ( // Add Mode #0 that must be 80x25 // MaxMode = 0; - Private->ModeData[MaxMode].GopWidth = HorizontalResolution; - Private->ModeData[MaxMode].GopHeight = VerticalResolution; + 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; + 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].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; + Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1; + Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1; MaxMode++; } @@ -532,13 +543,13 @@ GraphicsConsoleControllerDriverStart ( // 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].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; + Private->ModeData[MaxMode].DeltaX = 0; + Private->ModeData[MaxMode].DeltaY = 0; MaxMode++; } @@ -546,11 +557,11 @@ GraphicsConsoleControllerDriverStart ( // Add Mode #2 that must be 100x31 (graphic mode >= 800x600) // if (Columns >= 100 && Rows >= 31) { - Private->ModeData[MaxMode].GopWidth = HorizontalResolution; - Private->ModeData[MaxMode].GopHeight = VerticalResolution; + 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; + Private->ModeData[MaxMode].DeltaX = (HorizontalResolution - (100 * EFI_GLYPH_WIDTH)) >> 1; + Private->ModeData[MaxMode].DeltaY = (VerticalResolution - (31 * EFI_GLYPH_HEIGHT)) >> 1; MaxMode++; } @@ -558,13 +569,13 @@ GraphicsConsoleControllerDriverStart ( // 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].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; + Private->ModeData[MaxMode].DeltaX = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1; + Private->ModeData[MaxMode].DeltaY = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1; MaxMode++; } @@ -598,7 +609,7 @@ GraphicsConsoleControllerDriverStart ( Error: if (EFI_ERROR (Status)) { // - // Close the GOP or UGA IO Protocol + // Close the GOP and UGA Draw Protocol // if (Private->GraphicsOutput != NULL) { gBS->CloseProtocol ( @@ -631,20 +642,20 @@ Error: } /** - Stop this driver on ControllerHandle by removing Simple Text Out protocol - and closing the Graphics Output Protocol or UGA Draw protocol on ControllerHandle. - (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.) + Stop this driver on Controller by removing Simple Text Out protocol + and closing the Graphics Output Protocol or UGA Draw protocol on Controller. + (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.) @param This Protocol instance pointer. - @param ControllerHandle Handle of device to stop driver on + @param Controller Handle of device to stop driver on @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of children is zero stop the entire bus driver. @param ChildHandleBuffer List of Child Handles to Stop. - @retval EFI_SUCCESS This driver is removed ControllerHandle. + @retval EFI_SUCCESS This driver is removed Controller. @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the - ControllerHandle. + Controller. @retval other This driver was not removed from this device. **/ @@ -723,7 +734,7 @@ GraphicsConsoleControllerDriverStop ( /** Check if the current specific mode supported the user defined resolution - for the Graphice Console devcie based on Graphics Output Protocol. + for the Graphics Console device based on Graphics Output Protocol. If yes, set the graphic devcice's current mode to this specific mode. @@ -732,9 +743,9 @@ GraphicsConsoleControllerDriverStop ( @param VerticalResolution User defined vertical resolution. @param CurrentModeNumber Current specific mode to be check. - @retval EFI_SUCCESS This driver is removed ControllerHandle. + @retval EFI_SUCCESS The mode is supported. @retval EFI_UNSUPPORTED The specific mode is out of range of graphics - devcie supported. + device supported. @retval other The specific mode does not support user defined resolution or failed to set the current mode to the specific mode on graphics device. @@ -752,10 +763,12 @@ CheckModeSupported ( EFI_STATUS Status; UINTN SizeOfInfo; EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info; + UINT32 MaxMode; - Status = EFI_SUCCESS; - - for (ModeNumber = 0; ModeNumber < GraphicsOutput->Mode->MaxMode; ModeNumber++) { + Status = EFI_SUCCESS; + MaxMode = GraphicsOutput->Mode->MaxMode; + + for (ModeNumber = 0; ModeNumber < MaxMode; ModeNumber++) { Status = GraphicsOutput->QueryMode ( GraphicsOutput, ModeNumber, @@ -767,11 +780,11 @@ CheckModeSupported ( (Info->VerticalResolution == VerticalResolution)) { Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber); if (!EFI_ERROR (Status)) { - gBS->FreePool (Info); + FreePool (Info); break; } } - gBS->FreePool (Info); + FreePool (Info); } } @@ -842,7 +855,7 @@ EfiLocateHiiProtocol ( // /** - Reset the text output device hardware and optionaly run diagnostics. + Reset the text output device hardware and optionally run diagnostics. Implements SIMPLE_TEXT_OUTPUT.Reset(). If ExtendeVerification is TRUE, then perform dependent Graphics Console @@ -1090,27 +1103,12 @@ GraphicsConsoleConOutOutputString ( // Count is used to determine how many characters are used regardless of their attributes // for (Count = 0, Index = 0; (This->Mode->CursorColumn + Index) < MaxColumn; Count++, Index++) { - if (WString[Count] == CHAR_NULL) { - break; - } - - if (WString[Count] == CHAR_BACKSPACE) { - break; - } - - if (WString[Count] == CHAR_LINEFEED) { - break; - } - - if (WString[Count] == CHAR_CARRIAGE_RETURN) { - break; - } - - if (WString[Count] == WIDE_CHAR) { - break; - } - - if (WString[Count] == NARROW_CHAR) { + if (WString[Count] == CHAR_NULL || + WString[Count] == CHAR_BACKSPACE || + WString[Count] == CHAR_LINEFEED || + WString[Count] == CHAR_CARRIAGE_RETURN || + WString[Count] == WIDE_CHAR || + WString[Count] == NARROW_CHAR) { break; } // @@ -1210,8 +1208,10 @@ GraphicsConsoleConOutTestString ( &Blt, NULL ); - SafeFreePool (Blt); - Blt = NULL; + if (Blt != NULL) { + FreePool (Blt); + Blt = NULL; + } Count++; if (EFI_ERROR (Status)) { @@ -1381,7 +1381,7 @@ GraphicsConsoleConOutSetMode ( if (GraphicsOutput != NULL) { if (ModeData->GopModeNumber != GraphicsOutput->Mode->Mode) { // - // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode + // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode // Status = GraphicsOutput->SetMode (GraphicsOutput, ModeData->GopModeNumber); if (EFI_ERROR (Status)) { @@ -1420,7 +1420,7 @@ GraphicsConsoleConOutSetMode ( ); if (EFI_ERROR (Status) || HorizontalResolution != ModeData->GopWidth || VerticalResolution != ModeData->GopHeight) { // - // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode + // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode // Status = UgaDraw->SetMode ( UgaDraw, @@ -1460,7 +1460,7 @@ GraphicsConsoleConOutSetMode ( This->Mode->Mode = (INT32) ModeNumber; // - // Move the text cursor to the upper left hand corner of the displat and enable it + // Move the text cursor to the upper left hand corner of the display and enable it // This->SetCursorPosition (This, 0, 0); @@ -1640,7 +1640,7 @@ GraphicsConsoleConOutSetCursorPosition ( goto Done; } - if (((INT32) Column == This->Mode->CursorColumn) && ((INT32) Row == This->Mode->CursorRow)) { + if ((This->Mode->CursorColumn == (INT32) Column) && (This->Mode->CursorRow == (INT32) Row)) { Status = EFI_SUCCESS; goto Done; } @@ -1720,7 +1720,7 @@ GetTextColors ( } /** - Draw Unicode string on the Graphice Console device's screen. + Draw Unicode string on the Graphics Console device's screen. @param This Protocol instance pointer. @param UnicodeWeight One Unicode string to be displayed. @@ -1759,20 +1759,29 @@ DrawUnicodeWeightAtCursorN ( String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight); if (String == NULL) { - SafeFreePool (Blt); + FreePool (Blt); return EFI_OUT_OF_RESOURCES; } - *(String + Count) = 0; + // + // Set the end character + // + *(String + Count) = L'\0'; FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO)); if (FontInfo == NULL) { - SafeFreePool (Blt); - SafeFreePool (String); + FreePool (Blt); + FreePool (String); return EFI_OUT_OF_RESOURCES; } + // + // Get current foreground and background colors. + // GetTextColors (This, &FontInfo->ForegroundColor, &FontInfo->BackgroundColor); if (Private->GraphicsOutput != NULL) { + // + // If Graphics Output protocol exists, using HII Font protocol to draw. + // Blt->Image.Screen = Private->GraphicsOutput; Status = mHiiFont->StringToImage ( @@ -1789,14 +1798,18 @@ DrawUnicodeWeightAtCursorN ( ); } else if (FeaturePcdGet (PcdUgaConsumeSupport)) { + // + // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled, + // using UGA Draw protocol to draw. + // ASSERT (Private->UgaDraw!= NULL); UgaDraw = Private->UgaDraw; Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); if (Blt->Image.Bitmap == NULL) { - SafeFreePool (Blt); - SafeFreePool (String); + FreePool (Blt); + FreePool (String); return EFI_OUT_OF_RESOURCES; } @@ -1839,15 +1852,21 @@ DrawUnicodeWeightAtCursorN ( ); } - SafeFreePool (RowInfoArray); - SafeFreePool (Blt->Image.Bitmap); + FreePool (RowInfoArray); + FreePool (Blt->Image.Bitmap); } else { Status = EFI_UNSUPPORTED; } - SafeFreePool (Blt); - SafeFreePool (String); - SafeFreePool (FontInfo); + if (Blt != NULL) { + FreePool (Blt); + } + if (String != NULL) { + FreePool (String); + } + if (FontInfo != NULL) { + FreePool (FontInfo); + } return Status; } @@ -1864,17 +1883,17 @@ EraseCursor ( IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This ) { - GRAPHICS_CONSOLE_DEV *Private; - EFI_SIMPLE_TEXT_OUTPUT_MODE *CurrentMode; - INTN GlyphX; - INTN GlyphY; + GRAPHICS_CONSOLE_DEV *Private; + EFI_SIMPLE_TEXT_OUTPUT_MODE *CurrentMode; + INTN GlyphX; + INTN GlyphY; EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; - EFI_UGA_DRAW_PROTOCOL *UgaDraw; + EFI_UGA_DRAW_PROTOCOL *UgaDraw; EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground; EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background; EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar[EFI_GLYPH_HEIGHT][EFI_GLYPH_WIDTH]; - UINTN PosX; - UINTN PosY; + UINTN PosX; + UINTN PosY; CurrentMode = This->Mode; @@ -1929,7 +1948,7 @@ EraseCursor ( // for (PosY = 0; PosY < EFI_GLYPH_HEIGHT; PosY++) { for (PosX = 0; PosX < EFI_GLYPH_WIDTH; PosX++) { - if ((mCursorGlyph.GlyphCol1[PosY] & (1 << PosX)) != 0) { + if ((mCursorGlyph.GlyphCol1[PosY] & (BIT0 << PosX)) != 0) { BltChar[PosY][EFI_GLYPH_WIDTH - PosX - 1].Raw ^= Foreground.Raw; } } @@ -1972,8 +1991,8 @@ EraseCursor ( @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. - @retval EFI_SUCCESS The entry point is executed successfully. - @retval other Some error occurs when executing this entry point. + @retval EFI_SUCCESS The entry point is executed successfully. + @return other Some error occurs when executing this entry point. **/ EFI_STATUS @@ -1998,7 +2017,6 @@ InitializeGraphicsConsole ( ); ASSERT_EFI_ERROR (Status); - return Status; }