]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
Global variables have been moved backward ahead of functions.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
index 13486a0462255b6d03cf86429658df6d211118e4..f925daa975bd935c7b4e2c622f15f9620663a3d6 100644 (file)
@@ -1,10 +1,5 @@
 /** @file\r
   This is the main routine for initializing the Graphics Console support routines.\r
-Remaining Tasks\r
-  Add all standard Glyphs from UEFI 2.0 Specification\r
-  Implement optimal automatic Mode creation algorithm\r
-  Solve palette issues for mixed graphics and text\r
-  When does this protocol reset the palette?\r
 \r
 Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
 All rights reserved. This program and the accompanying materials\r
@@ -19,87 +14,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "GraphicsConsole.h"\r
 \r
-/**\r
-  Gets Graphics Console devcie's foreground color and background color.\r
-\r
-  @param  This                  Protocol instance pointer.\r
-  @param  Foreground            Returned text foreground color.\r
-  @param  Background            Returned text background color.\r
-\r
-  @retval EFI_SUCCESS           It returned always.\r
-\r
-**/\r
-EFI_STATUS\r
-GetTextColors (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
-  OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Foreground,\r
-  OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Background\r
-  );\r
-\r
-/**\r
-  Draw Unicode string on the Graphice Console device's screen.\r
-\r
-  @param  This                  Protocol instance pointer.\r
-  @param  UnicodeWeight         One Unicode string to be displayed.\r
-  @param  Count                 The count of Unicode string.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES  If no memory resource to use.\r
-  @retval EFI_UNSUPPORTED       If no Graphics Output protocol and UGA Draw\r
-                                protocol exist.\r
-  @retval EFI_SUCCESS           Drawing Unicode string implemented successfully.\r
-\r
-**/\r
-EFI_STATUS\r
-DrawUnicodeWeightAtCursorN (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
-  IN  CHAR16                           *UnicodeWeight,\r
-  IN  UINTN                            Count\r
-  );\r
-\r
-/**\r
-  Erase the cursor on the screen.\r
-\r
-  @param  This                  Protocol instance pointer.\r
-\r
-  @retval EFI_SUCCESS           The cursor is erased successfully.\r
-\r
-**/\r
-EFI_STATUS\r
-EraseCursor (\r
-  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
-  );\r
-\r
-/**\r
-  Check if the current specific mode supported the user defined resolution\r
-  for the Graphice Console devcie based on Graphics Output Protocol.\r
-\r
-  If yes, set the graphic devcice's current mode to this specific mode.\r
-  \r
-  @param  GraphicsOutput        Graphics Output Protocol instance pointer.\r
-  @param  HorizontalResolution  User defined horizontal resolution\r
-  @param  VerticalResolution    User defined vertical resolution.\r
-  @param  CurrentModeNumber     Current specific mode to be check.\r
-\r
-  @retval EFI_SUCCESS       This driver is removed ControllerHandle.\r
-  @retval EFI_UNSUPPORTED   The specific mode is out of range of graphics \r
-                            devcie supported.\r
-  @retval other             The specific mode does not support user defined \r
-                            resolution or failed to set the current mode to the \r
-                            specific mode on graphics device.\r
-\r
-**/\r
-EFI_STATUS\r
-CheckModeSupported (\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput,\r
-  IN  UINT32  HorizontalResolution,\r
-  IN  UINT32  VerticalResolution,\r
-  OUT UINT32  *CurrentModeNumber\r
-  );\r
 \r
 //\r
-// Globals\r
+// Graphics Console Devcie Private Data template\r
 //\r
-GRAPHICS_CONSOLE_DEV        mGraphicsConsoleDevTemplate = {\r
+GRAPHICS_CONSOLE_DEV    mGraphicsConsoleDevTemplate = {\r
   GRAPHICS_CONSOLE_DEV_SIGNATURE,\r
   (EFI_GRAPHICS_OUTPUT_PROTOCOL *) NULL,\r
   (EFI_UGA_DRAW_PROTOCOL *) NULL,\r
@@ -137,11 +56,11 @@ EFI_HII_DATABASE_PROTOCOL   *mHiiDatabase;
 EFI_HII_FONT_PROTOCOL       *mHiiFont;\r
 BOOLEAN                     mFirstAccessFlag = TRUE;\r
 \r
-STATIC EFI_GUID             mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, 0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad};\r
+EFI_GUID             mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};\r
 \r
-STATIC CHAR16               mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
+CHAR16               mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };\r
 \r
-STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL        mEfiColors[16] = {\r
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL        mEfiColors[16] = {\r
   //\r
   // B     G     R\r
   //\r
@@ -163,13 +82,13 @@ STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL        mEfiColors[16] = {
   {0xff, 0xff, 0xff, 0x00}  // WHITE\r
 };\r
 \r
-STATIC EFI_NARROW_GLYPH     mCursorGlyph = {\r
+EFI_NARROW_GLYPH     mCursorGlyph = {\r
   0x0000,\r
   0x00,\r
   { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }\r
 };\r
 \r
-STATIC CHAR16       SpaceStr[] = { NARROW_CHAR, ' ', 0 };\r
+CHAR16       SpaceStr[] = { NARROW_CHAR, ' ', 0 };\r
 \r
 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {\r
   GraphicsConsoleControllerDriverSupported,\r
@@ -180,21 +99,98 @@ EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding = {
   NULL\r
 };\r
 \r
+/**\r
+  Gets Graphics Console devcie's foreground color and background color.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  Foreground            Returned text foreground color.\r
+  @param  Background            Returned text background color.\r
+\r
+  @retval EFI_SUCCESS           It returned always.\r
+\r
+**/\r
+EFI_STATUS\r
+GetTextColors (\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
+  OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Foreground,\r
+  OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Background\r
+  );\r
+\r
+/**\r
+  Draw Unicode string on the Graphice Console device's screen.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  UnicodeWeight         One Unicode string to be displayed.\r
+  @param  Count                 The count of Unicode string.\r
+\r
+  @retval EFI_OUT_OF_RESOURCES  If no memory resource to use.\r
+  @retval EFI_UNSUPPORTED       If no Graphics Output protocol and UGA Draw\r
+                                protocol exist.\r
+  @retval EFI_SUCCESS           Drawing Unicode string implemented successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+DrawUnicodeWeightAtCursorN (\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,\r
+  IN  CHAR16                           *UnicodeWeight,\r
+  IN  UINTN                            Count\r
+  );\r
+\r
+/**\r
+  Erase the cursor on the screen.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS           The cursor is erased successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EraseCursor (\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
+  );\r
 \r
 /**\r
-  Test to see if Graphics Console could be supported on the ControllerHandle.\r
+  Check if the current specific mode supported the user defined resolution\r
+  for the Graphice Console devcie based on Graphics Output Protocol.\r
+\r
+  If yes, set the graphic devcice's current mode to this specific mode.\r
+  \r
+  @param  GraphicsOutput        Graphics Output Protocol instance pointer.\r
+  @param  HorizontalResolution  User defined horizontal resolution\r
+  @param  VerticalResolution    User defined vertical resolution.\r
+  @param  CurrentModeNumber     Current specific mode to be check.\r
+\r
+  @retval EFI_SUCCESS       The mode is supported.\r
+  @retval EFI_UNSUPPORTED   The specific mode is out of range of graphics \r
+                            devcie supported.\r
+  @retval other             The specific mode does not support user defined \r
+                            resolution or failed to set the current mode to the \r
+                            specific mode on graphics device.\r
+\r
+**/\r
+EFI_STATUS\r
+CheckModeSupported (\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput,\r
+  IN  UINT32  HorizontalResolution,\r
+  IN  UINT32  VerticalResolution,\r
+  OUT UINT32  *CurrentModeNumber\r
+  );\r
+\r
+\r
+/**\r
+  Test to see if Graphics Console could be supported on the Controller.\r
 \r
   Graphics Console could be supported if Graphics Output Protocol or UGA Draw\r
-  Protocol exists on the ControllerHandle. (UGA Draw Protocol could be shipped\r
+  Protocol exists on the Controller. (UGA Draw Protocol could be skipped\r
   if PcdUgaConsumeSupport is set to FALSE.)\r
 \r
   @param  This                Protocol instance pointer.\r
-  @param  ControllerHandle    Handle of device to test.\r
+  @param  Controller          Handle of device to test.\r
   @param  RemainingDevicePath Optional parameter use to pick a specific child\r
                               device to start.\r
 \r
-  @retval EFI_SUCCESS         This driver supports this device\r
-  @retval other               This driver does not support this device\r
+  @retval EFI_SUCCESS         This driver supports this device.\r
+  @retval other               This driver does not support this device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -294,17 +290,17 @@ Error:
 \r
 \r
 /**\r
-  Start this driver on ControllerHandle by opening Graphics Output protocol or \r
-  UGA Draw protocol, and installing Simple Text Out protocol on ControllerHandle.\r
+  Start this driver on Controller by opening Graphics Output protocol or \r
+  UGA Draw protocol, and installing Simple Text Out protocol on Controller.\r
   (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)\r
   \r
   @param  This                 Protocol instance pointer.\r
-  @param  ControllerHandle     Handle of device to bind driver to\r
+  @param  Controller           Handle of device to bind driver to\r
   @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
                                device to start.\r
 \r
-  @retval EFI_SUCCESS          This driver is added to ControllerHandle\r
-  @retval other                This driver does not support this device\r
+  @retval EFI_SUCCESS          This driver is added to Controller.\r
+  @retval other                This driver does not support this device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -390,7 +386,7 @@ GraphicsConsoleControllerDriverStart (
     SimplifiedFont->NumberOfNarrowGlyphs = (UINT16) (NarrowFontSize / sizeof (EFI_NARROW_GLYPH));\r
 \r
     Location = (UINT8 *) (&SimplifiedFont->NumberOfWideGlyphs + 1);\r
-    CopyMem (Location, UsStdNarrowGlyphData, NarrowFontSize);\r
+    CopyMem (Location, gUsStdNarrowGlyphData, NarrowFontSize);\r
 \r
     //\r
     // Add this simplified font package to a package list then install it.\r
@@ -398,8 +394,8 @@ GraphicsConsoleControllerDriverStart (
     PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package);\r
     Status = mHiiDatabase->NewPackageList (mHiiDatabase, PackageList, NULL, &(Private->HiiHandle));\r
     ASSERT_EFI_ERROR (Status);\r
-    SafeFreePool (PackageList);\r
-    SafeFreePool (Package);\r
+    FreePool (PackageList);\r
+    FreePool (Package);\r
 \r
     mFirstAccessFlag = FALSE;\r
   }\r
@@ -509,22 +505,22 @@ GraphicsConsoleControllerDriverStart (
   // Add Mode #0 that must be 80x25\r
   //\r
   MaxMode = 0;\r
-  Private->ModeData[MaxMode].GopWidth   = HorizontalResolution;\r
-  Private->ModeData[MaxMode].GopHeight  = VerticalResolution;\r
+  Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
+  Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
   Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-  Private->ModeData[MaxMode].DeltaX     = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
-  Private->ModeData[MaxMode].DeltaY     = (VerticalResolution - (25 * EFI_GLYPH_HEIGHT)) >> 1;\r
+  Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
+  Private->ModeData[MaxMode].DeltaY        = (VerticalResolution - (25 * EFI_GLYPH_HEIGHT)) >> 1;\r
   MaxMode++;\r
 \r
   //\r
   // If it is possible to support Mode #1 - 80x50, than add it as an active mode\r
   //\r
   if (Rows >= 50) {\r
-    Private->ModeData[MaxMode].GopWidth   = HorizontalResolution;\r
-    Private->ModeData[MaxMode].GopHeight  = VerticalResolution;\r
+    Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
+    Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
     Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX     = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
-    Private->ModeData[MaxMode].DeltaY     = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;\r
+    Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
+    Private->ModeData[MaxMode].DeltaY        = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;\r
     MaxMode++;\r
   }\r
 \r
@@ -532,13 +528,13 @@ GraphicsConsoleControllerDriverStart (
   // If it is not to support Mode #1 - 80x50, then skip it\r
   //\r
   if (MaxMode < 2) {\r
-    Private->ModeData[MaxMode].Columns    = 0;\r
-    Private->ModeData[MaxMode].Rows       = 0;\r
-    Private->ModeData[MaxMode].GopWidth   = HorizontalResolution;\r
-    Private->ModeData[MaxMode].GopHeight  = VerticalResolution;\r
+    Private->ModeData[MaxMode].Columns       = 0;\r
+    Private->ModeData[MaxMode].Rows          = 0;\r
+    Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
+    Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
     Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX     = 0;\r
-    Private->ModeData[MaxMode].DeltaY     = 0;\r
+    Private->ModeData[MaxMode].DeltaX        = 0;\r
+    Private->ModeData[MaxMode].DeltaY        = 0;\r
     MaxMode++;\r
   }\r
 \r
@@ -546,11 +542,11 @@ GraphicsConsoleControllerDriverStart (
   // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)\r
   //\r
   if (Columns >= 100 && Rows >= 31) {\r
-    Private->ModeData[MaxMode].GopWidth   = HorizontalResolution;\r
-    Private->ModeData[MaxMode].GopHeight  = VerticalResolution;\r
+    Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
+    Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
     Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX     = (HorizontalResolution - (100 * EFI_GLYPH_WIDTH)) >> 1;\r
-    Private->ModeData[MaxMode].DeltaY     = (VerticalResolution - (31 * EFI_GLYPH_HEIGHT)) >> 1;\r
+    Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution - (100 * EFI_GLYPH_WIDTH)) >> 1;\r
+    Private->ModeData[MaxMode].DeltaY        = (VerticalResolution - (31 * EFI_GLYPH_HEIGHT)) >> 1;\r
     MaxMode++;\r
   }\r
 \r
@@ -558,13 +554,13 @@ GraphicsConsoleControllerDriverStart (
   // Add Mode #3 that uses the entire display for user-defined mode\r
   //\r
   if (HorizontalResolution > 800 && VerticalResolution > 600) {\r
-    Private->ModeData[MaxMode].Columns    = HorizontalResolution/EFI_GLYPH_WIDTH;\r
-    Private->ModeData[MaxMode].Rows       = VerticalResolution/EFI_GLYPH_HEIGHT;\r
-    Private->ModeData[MaxMode].GopWidth   = HorizontalResolution;\r
-    Private->ModeData[MaxMode].GopHeight  = VerticalResolution;\r
+    Private->ModeData[MaxMode].Columns       = HorizontalResolution/EFI_GLYPH_WIDTH;\r
+    Private->ModeData[MaxMode].Rows          = VerticalResolution/EFI_GLYPH_HEIGHT;\r
+    Private->ModeData[MaxMode].GopWidth      = HorizontalResolution;\r
+    Private->ModeData[MaxMode].GopHeight     = VerticalResolution;\r
     Private->ModeData[MaxMode].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX     = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1;\r
-    Private->ModeData[MaxMode].DeltaY     = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1;\r
+    Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1;\r
+    Private->ModeData[MaxMode].DeltaY        = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1;\r
     MaxMode++;\r
   }\r
 \r
@@ -598,7 +594,7 @@ GraphicsConsoleControllerDriverStart (
 Error:\r
   if (EFI_ERROR (Status)) {\r
     //\r
-    // Close the GOP or UGA IO Protocol\r
+    // Close the GOP and UGA Draw Protocol\r
     //\r
     if (Private->GraphicsOutput != NULL) {\r
       gBS->CloseProtocol (\r
@@ -631,20 +627,20 @@ Error:
 }\r
 \r
 /**\r
-  Stop this driver on ControllerHandle by removing Simple Text Out protocol \r
-  and closing the Graphics Output Protocol or UGA Draw protocol on ControllerHandle.\r
+  Stop this driver on Controller by removing Simple Text Out protocol \r
+  and closing the Graphics Output Protocol or UGA Draw protocol on Controller.\r
   (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)\r
   \r
 \r
   @param  This              Protocol instance pointer.\r
-  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  Controller        Handle of device to stop driver on\r
   @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
                             children is zero stop the entire bus driver.\r
   @param  ChildHandleBuffer List of Child Handles to Stop.\r
 \r
-  @retval EFI_SUCCESS       This driver is removed ControllerHandle.\r
+  @retval EFI_SUCCESS       This driver is removed Controller.\r
   @retval EFI_NOT_STARTED   Simple Text Out protocol could not be found the \r
-                            ControllerHandle.\r
+                            Controller.\r
   @retval other             This driver was not removed from this device.\r
 \r
 **/\r
@@ -732,7 +728,7 @@ GraphicsConsoleControllerDriverStop (
   @param  VerticalResolution    User defined vertical resolution.\r
   @param  CurrentModeNumber     Current specific mode to be check.\r
 \r
-  @retval EFI_SUCCESS       This driver is removed ControllerHandle.\r
+  @retval EFI_SUCCESS       The mode is supported.\r
   @retval EFI_UNSUPPORTED   The specific mode is out of range of graphics \r
                             devcie supported.\r
   @retval other             The specific mode does not support user defined \r
@@ -1210,8 +1206,10 @@ GraphicsConsoleConOutTestString (
                          &Blt,\r
                          NULL\r
                          );\r
-    SafeFreePool (Blt);\r
-    Blt = NULL;\r
+    if (Blt != NULL) {\r
+      FreePool (Blt);\r
+      Blt = NULL;\r
+    }\r
     Count++;\r
 \r
     if (EFI_ERROR (Status)) {\r
@@ -1640,7 +1638,7 @@ GraphicsConsoleConOutSetCursorPosition (
     goto Done;\r
   }\r
 \r
-  if (((INT32) Column == This->Mode->CursorColumn) && ((INT32) Row == This->Mode->CursorRow)) {\r
+  if ((This->Mode->CursorColumn == (INT32) Column) && (This->Mode->CursorRow == (INT32) Row)) {\r
     Status = EFI_SUCCESS;\r
     goto Done;\r
   }\r
@@ -1759,20 +1757,29 @@ DrawUnicodeWeightAtCursorN (
 \r
   String = AllocateCopyPool ((Count + 1) * sizeof (CHAR16), UnicodeWeight);\r
   if (String == NULL) {\r
-    SafeFreePool (Blt);\r
+    FreePool (Blt);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  *(String + Count) = 0;\r
+  //\r
+  // Set the end character\r
+  //\r
+  *(String + Count) = L'\0';\r
 \r
   FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));\r
   if (FontInfo == NULL) {\r
-    SafeFreePool (Blt);\r
-    SafeFreePool (String);\r
+    FreePool (Blt);\r
+    FreePool (String);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  //\r
+  // Get current foreground and background colors.\r
+  //\r
   GetTextColors (This, &FontInfo->ForegroundColor, &FontInfo->BackgroundColor);\r
 \r
   if (Private->GraphicsOutput != NULL) {\r
+    //\r
+    // If Graphcis Output protocol exists, using HII Font protocol to draw. \r
+    //\r
     Blt->Image.Screen = Private->GraphicsOutput;\r
 \r
     Status = mHiiFont->StringToImage (\r
@@ -1789,14 +1796,18 @@ DrawUnicodeWeightAtCursorN (
                          );\r
 \r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    //\r
+    // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled, \r
+    // using UGA Draw protocol to draw.\r
+    //\r
     ASSERT (Private->UgaDraw!= NULL);\r
 \r
     UgaDraw = Private->UgaDraw;\r
 \r
     Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
     if (Blt->Image.Bitmap == NULL) {\r
-      SafeFreePool (Blt);\r
-      SafeFreePool (String);\r
+      FreePool (Blt);\r
+      FreePool (String);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
 \r
@@ -1839,15 +1850,21 @@ DrawUnicodeWeightAtCursorN (
                           );\r
     }\r
 \r
-    SafeFreePool (RowInfoArray);\r
-    SafeFreePool (Blt->Image.Bitmap);\r
+    FreePool (RowInfoArray);\r
+    FreePool (Blt->Image.Bitmap);\r
   } else {\r
     Status = EFI_UNSUPPORTED;\r
   }\r
 \r
-  SafeFreePool (Blt);\r
-  SafeFreePool (String);\r
-  SafeFreePool (FontInfo);\r
+  if (Blt != NULL) {\r
+    FreePool (Blt);\r
+  }\r
+  if (String != NULL) {\r
+    FreePool (String);\r
+  }\r
+  if (FontInfo != NULL) {\r
+    FreePool (FontInfo);\r
+  }\r
   return Status;\r
 }\r
 \r