From d0d0c1b37038d51c2de3a498e952e2047f98660b Mon Sep 17 00:00:00 2001 From: li-elvin Date: Tue, 7 Aug 2012 09:32:46 +0000 Subject: [PATCH] Removed SetMode in GraphicsConsole Start() in release BIOS to improve performance. Initialize current text mode number to 0xFF as invalid text mode per UEFI spec. Add current mode check in text out protocol interface to avoid invalid text mode. Signed-off-by: Li Elvin Reviewed-by: Ni Ruiyu , Tian Hot (hot.tian@intel.com) git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13599 6f19259b-4bc3-4df7-8a09-765794883524 --- .../GraphicsConsoleDxe/GraphicsConsole.c | 109 ++++++++++++------ 1 file changed, 76 insertions(+), 33 deletions(-) diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c index 117569fa62..7167033841 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c @@ -1,7 +1,7 @@ /** @file This is the main routine for initializing the Graphics Console support routines. -Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2012, 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 @@ -35,7 +35,7 @@ GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate = { }, { 0, - 0, + -1, EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK), 0, 0, @@ -559,16 +559,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 (); // @@ -863,8 +862,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; } @@ -917,8 +921,15 @@ GraphicsConsoleConOutOutputString ( INT32 OriginAttribute; EFI_TPL OldTpl; - Status = EFI_SUCCESS; + if (This->Mode->Mode == -1) { + // + // If current mode is not valid, return error. + // + return EFI_UNSUPPORTED; + } + Status = EFI_SUCCESS; + OldTpl = gBS->RaiseTPL (TPL_NOTIFY); // // Current mode @@ -1300,7 +1311,6 @@ GraphicsConsoleConOutSetMode ( Private = GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This); GraphicsOutput = Private->GraphicsOutput; UgaDraw = Private->UgaDraw; - ModeData = &(Private->ModeData[ModeNumber]); // // Make sure the requested mode number is supported @@ -1309,38 +1319,26 @@ GraphicsConsoleConOutSetMode ( Status = EFI_UNSUPPORTED; 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; } @@ -1352,6 +1350,21 @@ GraphicsConsoleConOutSetMode ( 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 // @@ -1483,6 +1496,13 @@ GraphicsConsoleConOutSetAttribute ( return EFI_UNSUPPORTED; } + if (This->Mode->Mode == -1) { + // + // If current mode is not valid, return error. + // + return EFI_UNSUPPORTED; + } + if ((INT32) Attribute == This->Mode->Attribute) { return EFI_SUCCESS; } @@ -1528,6 +1548,13 @@ GraphicsConsoleConOutClearScreen ( EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground; 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); @@ -1610,6 +1637,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); @@ -1651,6 +1685,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 @@ -1662,6 +1698,13 @@ 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); FlushCursor (This); -- 2.39.2