]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/GraphicsLib/Graphics.c
add some error check and return.
[mirror_edk2.git] / MdeModulePkg / Library / GraphicsLib / Graphics.c
index f2509c19b9136ff60f34806731faf7cc98d469e7..cccbc6b06f19ec005b647b1a65cbf7dce8d60d98 100644 (file)
@@ -38,6 +38,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DxePiLib.h>\r
+#include <Library/PcdLib.h>\r
 \r
 STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r
   { 0x00, 0x00, 0x00, 0x00 },\r
@@ -113,19 +114,19 @@ Arguments:
 \r
   ImageHandle   - The driver image handle of the caller. The parameter is used to\r
                   optimize the loading of the image file so that the FV from which\r
-                  the driver image is loaded will be tried first. \r
+                  the driver image is loaded will be tried first.\r
 \r
   FileNameGuid  - File Name of graphics file in the FV(s).\r
 \r
-  Image         - Pointer to pointer to return graphics image.  If NULL, a \r
+  Image         - Pointer to pointer to return graphics image.  If NULL, a\r
                   buffer will be allocated.\r
 \r
   ImageSize     - Size of the graphics Image in bytes. Zero if no image found.\r
 \r
 \r
-Returns: \r
+Returns:\r
 \r
-  EFI_SUCCESS          - Image and ImageSize are valid. \r
+  EFI_SUCCESS          - Image and ImageSize are valid.\r
   EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size\r
   EFI_NOT_FOUND        - FileNameGuid not found\r
 \r
@@ -370,7 +371,7 @@ Arguments:
   LogoFile - File name of logo to display on the center of the screen.\r
 \r
 \r
-Returns: \r
+Returns:\r
 \r
   EFI_SUCCESS           - ConsoleControl has been flipped to graphics and logo\r
                           displayed.\r
@@ -401,7 +402,7 @@ Arguments:
                 the driver image is loaded will be tried first.\r
 \r
 \r
-Returns: \r
+Returns:\r
 \r
   EFI_SUCCESS           - ConsoleControl has been flipped to graphics and logo\r
                           displayed.\r
@@ -442,30 +443,35 @@ Returns:
   // Try to open GOP first\r
   //\r
   Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID**)&GraphicsOutput);\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     GraphicsOutput = NULL;\r
     //\r
-    // Open GOP failed, try to open UGA\r
+    // Open GOP failed, try to open UGwhA\r
     //\r
     Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID**)&UgaDraw);\r
-    if (EFI_ERROR (Status)) {\r
-      return EFI_UNSUPPORTED;\r
-    }\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
   }\r
 \r
   Badging = NULL;\r
   Status  = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID**)&Badging);\r
 \r
-  ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);\r
+  Status = ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
   if (GraphicsOutput != NULL) {\r
     SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r
     SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r
-  } else {\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);\r
     if (EFI_ERROR (Status)) {\r
       return EFI_UNSUPPORTED;\r
     }\r
+  } else {\r
+    return EFI_UNSUPPORTED;\r
   }\r
 \r
   Instance = 0;\r
@@ -590,7 +596,7 @@ Returns:
                             Height,\r
                             Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
                             );\r
-      } else {\r
+      } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
         Status = UgaDraw->Blt (\r
                             UgaDraw,\r
                             (EFI_UGA_PIXEL *) Blt,\r
@@ -603,6 +609,8 @@ Returns:
                             Height,\r
                             Width * sizeof (EFI_UGA_PIXEL)\r
                             );\r
+      } else {\r
+      Status = EFI_UNSUPPORTED;\r
       }\r
     }\r
 \r
@@ -655,7 +663,7 @@ UINTN
 _IPrint (\r
   IN EFI_GRAPHICS_OUTPUT_PROTOCOL     *GraphicsOutput,\r
   IN EFI_UGA_DRAW_PROTOCOL            *UgaDraw,\r
-  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL     *Sto,\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *Sto,\r
   IN UINTN                            X,\r
   IN UINTN                            Y,\r
   IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Foreground,\r
@@ -674,22 +682,22 @@ Arguments:
   GraphicsOutput  - Graphics output protocol interface\r
 \r
   UgaDraw         - UGA draw protocol interface\r
-  \r
+\r
   Sto             - Simple text out protocol interface\r
-  \r
+\r
   X               - X coordinate to start printing\r
-  \r
+\r
   Y               - Y coordinate to start printing\r
-  \r
+\r
   Foreground      - Foreground color\r
-  \r
+\r
   Background      - Background color\r
-  \r
+\r
   fmt             - Format string\r
-  \r
+\r
   args            - Print arguments\r
 \r
-Returns: \r
+Returns:\r
 \r
   EFI_SUCCESS             -  success\r
   EFI_OUT_OF_RESOURCES    -  out of resources\r
@@ -708,7 +716,7 @@ Returns:
   UINTN                          LineBufferLen;\r
   EFI_HII_FONT_PROTOCOL          *HiiFont;\r
   EFI_IMAGE_OUTPUT               *Blt;\r
-  EFI_FONT_DISPLAY_INFO          *FontInfo;  \r
+  EFI_FONT_DISPLAY_INFO          *FontInfo;\r
 \r
   //\r
   // For now, allocate an arbitrarily long buffer\r
@@ -718,24 +726,31 @@ Returns:
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
+  HorizontalResolution  = 0;\r
+  VerticalResolution    = 0;\r
+  Blt                   = NULL;\r
+  FontInfo              = NULL;\r
+\r
   if (GraphicsOutput != NULL) {\r
     HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r
     VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r
-  } else {\r
+  } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r
+  } else {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Error;\r
   }\r
-  ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0)); \r
 \r
-  Blt      = NULL;\r
-  FontInfo = NULL;\r
+  ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));\r
+\r
   ASSERT (GraphicsOutput != NULL);\r
   Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &HiiFont);\r
   if (EFI_ERROR (Status)) {\r
     goto Error;\r
-  }  \r
+  }\r
 \r
   UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r
-  \r
+\r
   UnicodeWeight = (CHAR16 *) Buffer;\r
 \r
   for (Index = 0; UnicodeWeight[Index] != 0; Index++) {\r
@@ -747,7 +762,7 @@ Returns:
   }\r
 \r
   BufferLen = StrLen (Buffer);\r
\r
+\r
 \r
   LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * EFI_GLYPH_HEIGHT;\r
   if (EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {\r
@@ -764,7 +779,7 @@ Returns:
   Blt->Width        = (UINT16) (HorizontalResolution);\r
   Blt->Height       = (UINT16) (VerticalResolution);\r
   Blt->Image.Screen = GraphicsOutput;\r
-   \r
+\r
   FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));\r
   if (FontInfo == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -774,8 +789,8 @@ Returns:
     CopyMem (&FontInfo->ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
   } else {\r
     CopyMem (\r
-      &FontInfo->ForegroundColor, \r
-      &mEfiColors[Sto->Mode->Attribute & 0x0f], \r
+      &FontInfo->ForegroundColor,\r
+      &mEfiColors[Sto->Mode->Attribute & 0x0f],\r
       sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
       );\r
   }\r
@@ -783,8 +798,8 @@ Returns:
     CopyMem (&FontInfo->BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
   } else {\r
     CopyMem (\r
-      &FontInfo->BackgroundColor, \r
-      &mEfiColors[Sto->Mode->Attribute >> 4], \r
+      &FontInfo->BackgroundColor,\r
+      &mEfiColors[Sto->Mode->Attribute >> 4],\r
       sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
       );\r
   }\r
@@ -801,7 +816,7 @@ Returns:
                        NULL,\r
                        NULL\r
                        );\r
-  \r
+\r
 \r
 Error:\r
   SafeFreePool (Blt);\r
@@ -828,11 +843,11 @@ Routine Description:
 Arguments:\r
 \r
     X           - X coordinate to start printing\r
-    \r
+\r
     Y           - Y coordinate to start printing\r
-    \r
+\r
     ForeGround  - Foreground color\r
-    \r
+\r
     BackGround  - Background color\r
 \r
     Fmt         - Format string\r
@@ -863,7 +878,7 @@ Returns:
                   );\r
 \r
   UgaDraw = NULL;\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     GraphicsOutput = NULL;\r
 \r
     Status = gBS->HandleProtocol (\r
@@ -871,10 +886,9 @@ Returns:
                     &gEfiUgaDrawProtocolGuid,\r
                     (VOID**)&UgaDraw\r
                     );\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
   }\r
 \r
   Status = gBS->HandleProtocol (\r