]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
MdeModulePkg: TerminalDxe driver code clean up
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
index 8e612c899c5c56813fe46716cf371cccb1ee6daa..bb279f985027e1cdc5c37b485b11ea604cce86da 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This is the main routine for initializing the Graphics Console support routines.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -42,10 +42,11 @@ GRAPHICS_CONSOLE_DEV    mGraphicsConsoleDevTemplate = {
     TRUE\r
   },\r
   {\r
-    { 80, 25, 0, 0, 0, 0 },  // Mode 0\r
-    { 80, 50, 0, 0, 0, 0 },  // Mode 1\r
-    { 100,31, 0, 0, 0, 0 },  // Mode 2\r
-    {  0,  0, 0, 0, 0, 0 }   // Mode 3\r
+    { 80, 25, 0, 0, 0, 0, 0 },  // Mode 0\r
+    { 80, 50, 0, 0, 0, 0, 0 },  // Mode 1\r
+    { 100,31, 0, 0, 0, 0, 0 },  // Mode 2\r
+    {  0,  0, 0, 0, 0, 0, 0 },  // Mode 3\r
+    {  0,  0, 0, 0, 0, 0, 0 }   // Mode 4\r
   },\r
   (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL\r
 };\r
@@ -238,11 +239,13 @@ GraphicsConsoleControllerDriverStart (
   UINT32                               VerticalResolution;\r
   UINT32                               ColorDepth;\r
   UINT32                               RefreshRate;\r
+  UINTN                                ModeIndex;\r
   UINTN                                MaxMode;\r
   UINTN                                Columns;\r
   UINTN                                Rows;\r
   UINT32                               ModeNumber;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE    *Mode;\r
+  GRAPHICS_CONSOLE_MODE_DATA           *ModeData;\r
   ModeNumber = 0;\r
 \r
   //\r
@@ -375,78 +378,63 @@ GraphicsConsoleControllerDriverStart (
   }\r
 \r
   //\r
-  // Compute the maximum number of text Rows and Columns that this current graphics mode can support\r
+  // Add Mode #3 that uses the entire display for user-defined mode\r
   //\r
-  Columns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
-  Rows    = VerticalResolution / EFI_GLYPH_HEIGHT;\r
+  Private->ModeData[3].Columns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
+  Private->ModeData[3].Rows    = VerticalResolution / EFI_GLYPH_HEIGHT;\r
 \r
   //\r
-  // See if the mode is too small to support the required 80x25 text mode\r
+  // Add Mode #4 that uses the PCD values\r
   //\r
-  if (Columns < 80 || Rows < 25) {\r
-    goto Error;\r
-  }\r
+  Private->ModeData[4].Columns = (UINTN) PcdGet32 (PcdConOutColumn);\r
+  Private->ModeData[4].Rows    = (UINTN) PcdGet32 (PcdConOutRow);\r
+\r
   //\r
-  // Add Mode #0 that must be 80x25\r
+  // Compute the maximum number of text Rows and Columns that this current graphics mode can support\r
   //\r
-  MaxMode = 0;\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
-  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].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
-    MaxMode++;\r
-  }\r
+  Columns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
+  Rows    = VerticalResolution / EFI_GLYPH_HEIGHT;\r
 \r
   //\r
-  // If it is not to support Mode #1 - 80x50, then skip it\r
+  // Here we make sure that mode 0 is valid\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].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX        = 0;\r
-    Private->ModeData[MaxMode].DeltaY        = 0;\r
-    MaxMode++;\r
+  if (Columns < Private->ModeData[0].Columns ||\r
+      Rows < Private->ModeData[0].Rows) {\r
+    //\r
+    // 80x25 cannot be supported.\r
+    //\r
+    // Fallback to using the PcdConOutColumn and PcdConOutRow\r
+    // for mode 0.  If the PCDs are also to large, then mode 0\r
+    // will be shrunk to fit as needed.\r
+    //\r
+    Private->ModeData[0].Columns = MIN (Private->ModeData[4].Columns, Columns);\r
+    Private->ModeData[0].Rows    = MIN (Private->ModeData[4].Rows, Rows);\r
   }\r
 \r
-  //\r
-  // 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].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
-    MaxMode++;\r
+  MaxMode = 0;\r
+  for (ModeIndex = 0; ModeIndex < GRAPHICS_MAX_MODE; ModeIndex++) {\r
+    ModeData = &Private->ModeData[ModeIndex];\r
+    ModeData->GopWidth      = HorizontalResolution;\r
+    ModeData->GopHeight     = VerticalResolution;\r
+    ModeData->GopModeNumber = ModeNumber;\r
+    if (Columns >= ModeData->Columns &&\r
+        Rows >= ModeData->Rows) {\r
+      ModeData->DeltaX        = (HorizontalResolution - (ModeData->Columns * EFI_GLYPH_WIDTH)) >> 1;\r
+      ModeData->DeltaY        = (VerticalResolution - (ModeData->Rows * EFI_GLYPH_HEIGHT)) >> 1;\r
+      MaxMode = ModeIndex + 1;\r
+    } else {\r
+      ModeData->Columns       = 0;\r
+      ModeData->Rows          = 0;\r
+      ModeData->DeltaX        = 0;\r
+      ModeData->DeltaY        = 0;\r
+    }\r
   }\r
 \r
   //\r
-  // Add Mode #3 that uses the entire display for user-defined mode\r
+  // See if the resolution was too small to support any text modes\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].GopModeNumber = ModeNumber;\r
-    Private->ModeData[MaxMode].DeltaX        = (HorizontalResolution % EFI_GLYPH_WIDTH) >> 1;\r
-    Private->ModeData[MaxMode].DeltaY        = (VerticalResolution % EFI_GLYPH_HEIGHT) >> 1;\r
-    MaxMode++;\r
+  if (MaxMode == 0) {\r
+    goto Error;\r
   }\r
 \r
   //\r
@@ -640,10 +628,18 @@ CheckModeSupported (
     if (!EFI_ERROR (Status)) {\r
       if ((Info->HorizontalResolution == HorizontalResolution) &&\r
           (Info->VerticalResolution == VerticalResolution)) {\r
-        Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);\r
-        if (!EFI_ERROR (Status)) {\r
-          FreePool (Info);\r
+        if ((GraphicsOutput->Mode->Info->HorizontalResolution == HorizontalResolution) &&\r
+            (GraphicsOutput->Mode->Info->VerticalResolution == VerticalResolution)) {\r
+          //\r
+          // If video device has been set to this mode, we do not need to SetMode again\r
+          //\r
           break;\r
+        } else {\r
+          Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);\r
+          if (!EFI_ERROR (Status)) {\r
+            FreePool (Info);\r
+            break;\r
+          }\r
         }\r
       }\r
       FreePool (Info);\r
@@ -808,8 +804,8 @@ GraphicsConsoleConOutOutputString (
 \r
   MaxColumn = Private->ModeData[Mode].Columns;\r
   MaxRow    = Private->ModeData[Mode].Rows;\r
-  DeltaX    = Private->ModeData[Mode].DeltaX;\r
-  DeltaY    = Private->ModeData[Mode].DeltaY;\r
+  DeltaX    = (UINTN) Private->ModeData[Mode].DeltaX;\r
+  DeltaY    = (UINTN) Private->ModeData[Mode].DeltaY;\r
   Width     = MaxColumn * EFI_GLYPH_WIDTH;\r
   Height    = (MaxRow - 1) * EFI_GLYPH_HEIGHT;\r
   Delta     = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
@@ -819,7 +815,7 @@ GraphicsConsoleConOutOutputString (
   //\r
   GetTextColors (This, &Foreground, &Background);\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   Warning = FALSE;\r
 \r
@@ -839,7 +835,7 @@ GraphicsConsoleConOutOutputString (
         This->Mode->CursorRow--;\r
         This->Mode->CursorColumn = (INT32) (MaxColumn - 1);\r
         This->OutputString (This, SpaceStr);\r
-        EraseCursor (This);\r
+        FlushCursor (This);\r
         This->Mode->CursorRow--;\r
         This->Mode->CursorColumn = (INT32) (MaxColumn - 1);\r
       } else if (This->Mode->CursorColumn > 0) {\r
@@ -849,7 +845,7 @@ GraphicsConsoleConOutOutputString (
         //\r
         This->Mode->CursorColumn--;\r
         This->OutputString (This, SpaceStr);\r
-        EraseCursor (This);\r
+        FlushCursor (This);\r
         This->Mode->CursorColumn--;\r
       }\r
 \r
@@ -1008,16 +1004,16 @@ GraphicsConsoleConOutOutputString (
       }\r
 \r
       if (This->Mode->CursorColumn >= (INT32) MaxColumn) {\r
-        EraseCursor (This);\r
+        FlushCursor (This);\r
         This->OutputString (This, mCrLfString);\r
-        EraseCursor (This);\r
+        FlushCursor (This);\r
       }\r
     }\r
   }\r
 \r
   This->Mode->Attribute = OriginAttribute;\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   if (Warning) {\r
     Status = EFI_WARN_UNKNOWN_GLYPH;\r
@@ -1180,11 +1176,6 @@ GraphicsConsoleConOutSetMode (
   UgaDraw   = Private->UgaDraw;\r
   ModeData  = &(Private->ModeData[ModeNumber]);\r
 \r
-  if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
-    Status = EFI_UNSUPPORTED;\r
-    goto Done;\r
-  }\r
-\r
   //\r
   // Make sure the requested mode number is supported\r
   //\r
@@ -1231,7 +1222,7 @@ GraphicsConsoleConOutSetMode (
     // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,\r
     // so erase the cursor, and free the LineBuffer for the current mode\r
     //\r
-    EraseCursor (This);\r
+    FlushCursor (This);\r
 \r
     FreePool (Private->LineBuffer);\r
   }\r
@@ -1322,9 +1313,12 @@ GraphicsConsoleConOutSetMode (
   This->Mode->Mode = (INT32) ModeNumber;\r
 \r
   //\r
-  // Move the text cursor to the upper left hand corner of the display and enable it\r
+  // Move the text cursor to the upper left hand corner of the display and flush it\r
   //\r
-  This->SetCursorPosition (This, 0, 0);\r
+  This->Mode->CursorColumn  = 0;\r
+  This->Mode->CursorRow     = 0;\r
+\r
+  FlushCursor (This);  \r
 \r
   Status = EFI_SUCCESS;\r
 \r
@@ -1369,11 +1363,11 @@ GraphicsConsoleConOutSetAttribute (
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   This->Mode->Attribute = (INT32) Attribute;\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
 \r
@@ -1450,7 +1444,7 @@ GraphicsConsoleConOutClearScreen (
   This->Mode->CursorColumn  = 0;\r
   This->Mode->CursorRow     = 0;\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
 \r
@@ -1507,12 +1501,12 @@ GraphicsConsoleConOutSetCursorPosition (
     goto Done;\r
   }\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   This->Mode->CursorColumn  = (INT32) Column;\r
   This->Mode->CursorRow     = (INT32) Row;\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
 Done:\r
   gBS->RestoreTPL (OldTpl);\r
@@ -1544,11 +1538,11 @@ GraphicsConsoleConOutEnableCursor (
 \r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   This->Mode->CursorVisible = Visible;\r
 \r
-  EraseCursor (This);\r
+  FlushCursor (This);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
   return EFI_SUCCESS;\r
@@ -1733,7 +1727,12 @@ DrawUnicodeWeightAtCursorN (
 }\r
 \r
 /**\r
-  Erase the cursor on the screen.\r
+  Flush the cursor on the screen.\r
+  \r
+  If CursorVisible is FALSE, nothing to do and return directly.\r
+  If CursorVisible is TRUE, \r
+     i) If the cursor shows on screen, it will be erased.\r
+    ii) If the cursor does not show on screen, it will be shown. \r
 \r
   @param  This                  Protocol instance pointer.\r
 \r
@@ -1741,7 +1740,7 @@ DrawUnicodeWeightAtCursorN (
 \r
 **/\r
 EFI_STATUS\r
-EraseCursor (\r
+FlushCursor (\r
   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This\r
   )\r
 {\r
@@ -1943,7 +1942,7 @@ InitializeGraphicsConsole (
 \r
   //\r
   // Register notify function on HII Database Protocol to add font package.\r
-  // \r
+  //\r
   EfiCreateProtocolNotifyEvent (\r
     &gEfiHiiDatabaseProtocolGuid,\r
     TPL_CALLBACK,\r