]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c
MdeModulePkg/GraphicsConsoleDxe: Initialize the output mode
[mirror_edk2.git] / MdeModulePkg / Universal / Console / GraphicsConsoleDxe / GraphicsConsole.c
index 52b0ec651cd39314b462bb63d4f99aab33b37ca9..c042451a9b5234baf309d7626c5a41755355fb8e 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   This is the main routine for initializing the Graphics Console support routines.\r
 \r
-Copyright (c) 2006 - 2012, 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -57,7 +51,7 @@ GRAPHICS_CONSOLE_MODE_DATA mGraphicsConsoleModeData[] = {
 EFI_HII_DATABASE_PROTOCOL   *mHiiDatabase;\r
 EFI_HII_FONT_PROTOCOL       *mHiiFont;\r
 EFI_HII_HANDLE              mHiiHandle;\r
-EFI_EVENT                   mHiiRegistration;\r
+VOID                        *mHiiRegistration;\r
 \r
 EFI_GUID             mFontPackageListGuid = {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};\r
 \r
@@ -245,8 +239,8 @@ InitializeGraphicsConsoleTextMode (
   UINTN                       ValidCount;\r
   UINTN                       ValidIndex;\r
   UINTN                       MaxColumns;\r
-  UINTN                       MaxRows;  \r
-  \r
+  UINTN                       MaxRows;\r
+\r
   if ((TextModeCount == NULL) || (TextModeData == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -287,7 +281,7 @@ InitializeGraphicsConsoleTextMode (
   //\r
   // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.\r
   //\r
-  ValidCount = 0;  \r
+  ValidCount = 0;\r
 \r
   NewModeBuffer[ValidCount].Columns       = 80;\r
   NewModeBuffer[ValidCount].Rows          = 25;\r
@@ -295,20 +289,20 @@ InitializeGraphicsConsoleTextMode (
   NewModeBuffer[ValidCount].GopHeight     = VerticalResolution;\r
   NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
   NewModeBuffer[ValidCount].DeltaX        = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;\r
-  NewModeBuffer[ValidCount].DeltaY        = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;      \r
+  NewModeBuffer[ValidCount].DeltaY        = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;\r
   ValidCount++;\r
 \r
   if ((MaxColumns >= 80) && (MaxRows >= 50)) {\r
     NewModeBuffer[ValidCount].Columns = 80;\r
     NewModeBuffer[ValidCount].Rows    = 50;\r
     NewModeBuffer[ValidCount].DeltaX  = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
-    NewModeBuffer[ValidCount].DeltaY  = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;    \r
+    NewModeBuffer[ValidCount].DeltaY  = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;\r
   }\r
   NewModeBuffer[ValidCount].GopWidth      = HorizontalResolution;\r
   NewModeBuffer[ValidCount].GopHeight     = VerticalResolution;\r
   NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
   ValidCount++;\r
-  \r
+\r
   //\r
   // Start from mode 2 to put the valid mode other than 80x25 and 80x50 in the output mode buffer.\r
   //\r
@@ -340,14 +334,14 @@ InitializeGraphicsConsoleTextMode (
       ValidCount++;\r
     }\r
   }\r
\r
+\r
   DEBUG_CODE (\r
     for (Index = 0; Index < ValidCount; Index++) {\r
-      DEBUG ((EFI_D_INFO, "Graphics - Mode %d, Column = %d, Row = %d\n", \r
-                           Index, NewModeBuffer[Index].Columns, NewModeBuffer[Index].Rows));  \r
+      DEBUG ((EFI_D_INFO, "Graphics - Mode %d, Column = %d, Row = %d\n",\r
+                           Index, NewModeBuffer[Index].Columns, NewModeBuffer[Index].Rows));\r
     }\r
   );\r
-  \r
+\r
   //\r
   // Return valid mode count and mode information buffer.\r
   //\r
@@ -388,9 +382,15 @@ GraphicsConsoleControllerDriverStart (
   UINTN                                MaxMode;\r
   UINT32                               ModeNumber;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE    *Mode;\r
-  UINTN                                SizeOfInfo;  \r
+  UINTN                                SizeOfInfo;\r
   EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
-  \r
+  INT32                                PreferMode;\r
+  INT32                                Index;\r
+  UINTN                                Column;\r
+  UINTN                                Row;\r
+  UINTN                                DefaultColumn;\r
+  UINTN                                DefaultRow;\r
+\r
   ModeNumber = 0;\r
 \r
   //\r
@@ -442,9 +442,9 @@ GraphicsConsoleControllerDriverStart (
     if ((HorizontalResolution == 0x0) || (VerticalResolution == 0x0)) {\r
       //\r
       // Find the highest resolution which GOP supports.\r
-      //    \r
+      //\r
       MaxMode = Private->GraphicsOutput->Mode->MaxMode;\r
-      \r
+\r
       for (ModeIndex = 0; ModeIndex < MaxMode; ModeIndex++) {\r
         Status = Private->GraphicsOutput->QueryMode (\r
                            Private->GraphicsOutput,\r
@@ -453,8 +453,8 @@ GraphicsConsoleControllerDriverStart (
                            &Info\r
                            );\r
         if (!EFI_ERROR (Status)) {\r
-          if ((Info->HorizontalResolution >= HorizontalResolution) &&\r
-              (Info->VerticalResolution >= VerticalResolution)) {\r
+          if ((Info->HorizontalResolution > HorizontalResolution) ||\r
+              ((Info->HorizontalResolution == HorizontalResolution) && (Info->VerticalResolution > VerticalResolution))) {\r
             HorizontalResolution = Info->HorizontalResolution;\r
             VerticalResolution   = Info->VerticalResolution;\r
             ModeNumber           = ModeIndex;\r
@@ -480,10 +480,12 @@ GraphicsConsoleControllerDriverStart (
         //\r
         // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec\r
         //\r
+        HorizontalResolution = 800;\r
+        VerticalResolution   = 600;\r
         Status = CheckModeSupported (\r
                      Private->GraphicsOutput,\r
-                     800,\r
-                     600,\r
+                     HorizontalResolution,\r
+                     VerticalResolution,\r
                      &ModeNumber\r
                      );\r
         Mode = Private->GraphicsOutput->Mode;\r
@@ -497,6 +499,19 @@ GraphicsConsoleControllerDriverStart (
         }\r
       }\r
     }\r
+    if (ModeNumber != Private->GraphicsOutput->Mode->Mode) {\r
+      //\r
+      // Current graphics mode is not set or is not set to the mode which we has found,\r
+      // set the new graphic mode.\r
+      //\r
+      Status = Private->GraphicsOutput->SetMode (Private->GraphicsOutput, ModeNumber);\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // The mode set operation failed\r
+        //\r
+        goto Error;\r
+      }\r
+    }\r
   } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     //\r
     // At first try to set user-defined resolution\r
@@ -536,6 +551,8 @@ GraphicsConsoleControllerDriverStart (
     }\r
   }\r
 \r
+  DEBUG ((EFI_D_INFO, "GraphicsConsole video resolution %d x %d\n", HorizontalResolution, VerticalResolution));\r
+\r
   //\r
   // Initialize the mode which GraphicsConsole supports.\r
   //\r
@@ -556,16 +573,32 @@ GraphicsConsoleControllerDriverStart (
   //\r
   Private->SimpleTextOutputMode.MaxMode = (INT32) MaxMode;\r
 \r
-  DEBUG_CODE_BEGIN ();\r
-    Status = GraphicsConsoleConOutSetMode (&Private->SimpleTextOutput, 0);\r
-    if (EFI_ERROR (Status)) {\r
-      goto Error;\r
+  //\r
+  // Initialize the Mode of graphics console devices\r
+  //\r
+  PreferMode = -1;\r
+  DefaultColumn = PcdGet32 (PcdConOutColumn);\r
+  DefaultRow = PcdGet32 (PcdConOutRow);\r
+  Column = 0;\r
+  Row = 0;\r
+  for (Index = 0; Index < (INT32)MaxMode; Index++) {\r
+    if (DefaultColumn != 0 && DefaultRow != 0) {\r
+      if ((Private->ModeData[Index].Columns == DefaultColumn) &&\r
+          (Private->ModeData[Index].Rows == DefaultRow)) {\r
+        PreferMode = Index;\r
+        break;\r
+      }\r
+    } else {\r
+      if ((Private->ModeData[Index].Columns > Column) &&\r
+          (Private->ModeData[Index].Rows > Row)) {\r
+        Column = Private->ModeData[Index].Columns;\r
+        Row = Private->ModeData[Index].Rows;\r
+        PreferMode = Index;\r
+      }\r
     }\r
-    Status = GraphicsConsoleConOutOutputString (&Private->SimpleTextOutput, (CHAR16 *)L"Graphics Console Started\n\r");\r
-    if (EFI_ERROR (Status)) {\r
-      goto Error;\r
-    }  \r
-  DEBUG_CODE_END ();\r
+  }\r
+  Private->SimpleTextOutput.Mode->Mode = (INT32)PreferMode;\r
+  DEBUG ((DEBUG_INFO, "Graphics Console Started, Mode: %d\n", PreferMode));\r
 \r
   //\r
   // Install protocol interfaces for the Graphics Console device.\r
@@ -791,42 +824,14 @@ EfiLocateHiiProtocol (
   VOID\r
   )\r
 {\r
-  EFI_HANDLE  Handle;\r
-  UINTN       Size;\r
   EFI_STATUS  Status;\r
 \r
-  //\r
-  // There should only be one - so buffer size is this\r
-  //\r
-  Size = sizeof (EFI_HANDLE);\r
-\r
-  Status = gBS->LocateHandle (\r
-                  ByProtocol,\r
-                  &gEfiHiiDatabaseProtocolGuid,\r
-                  NULL,\r
-                  &Size,\r
-                  (VOID **) &Handle\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = gBS->HandleProtocol (\r
-                  Handle,\r
-                  &gEfiHiiDatabaseProtocolGuid,\r
-                  (VOID **) &mHiiDatabase\r
-                  );\r
-\r
+  Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &mHiiDatabase);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
-  Status = gBS->HandleProtocol (\r
-                  Handle,\r
-                  &gEfiHiiFontProtocolGuid,\r
-                  (VOID **) &mHiiFont\r
-                  );\r
+  Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &mHiiFont);\r
   return Status;\r
 }\r
 \r
@@ -926,7 +931,7 @@ GraphicsConsoleConOutOutputString (
   }\r
 \r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
   //\r
   // Current mode\r
@@ -1316,7 +1321,7 @@ GraphicsConsoleConOutSetMode (
     Status = EFI_UNSUPPORTED;\r
     goto Done;\r
   }\r
-  \r
+\r
   ModeData  = &(Private->ModeData[ModeNumber]);\r
 \r
   if (ModeData->Columns <= 0 && ModeData->Rows <= 0) {\r
@@ -1454,7 +1459,7 @@ GraphicsConsoleConOutSetMode (
   This->Mode->CursorColumn  = 0;\r
   This->Mode->CursorRow     = 0;\r
 \r
-  FlushCursor (This);  \r
+  FlushCursor (This);\r
 \r
   Status = EFI_SUCCESS;\r
 \r
@@ -1489,14 +1494,7 @@ GraphicsConsoleConOutSetAttribute (
 {\r
   EFI_TPL               OldTpl;\r
 \r
-  if ((Attribute | 0xFF) != 0xFF) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  if (This->Mode->Mode == -1) {\r
-    //\r
-    // If current mode is not valid, return error.\r
-    //\r
+  if ((Attribute | 0x7F) != 0x7F) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -1545,7 +1543,7 @@ GraphicsConsoleConOutClearScreen (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
   EFI_TPL                       OldTpl;\r
-  \r
+\r
   if (This->Mode->Mode == -1) {\r
     //\r
     // If current mode is not valid, return error.\r
@@ -1894,11 +1892,11 @@ DrawUnicodeWeightAtCursorN (
 \r
 /**\r
   Flush the cursor on the screen.\r
-  \r
+\r
   If CursorVisible is FALSE, nothing to do and return directly.\r
-  If CursorVisible is TRUE, \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
+    ii) If the cursor does not show on screen, it will be shown.\r
 \r
   @param  This                  Protocol instance pointer.\r
 \r
@@ -2042,7 +2040,9 @@ RegisterFontPackage (
                   NULL,\r
                   (VOID **) &HiiDatabase\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
 \r
   //\r
   // Add 4 bytes to the header for entire length for HiiAddPackages use only.\r