]> git.proxmox.com Git - mirror_edk2.git/commitdiff
check list clean.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Jul 2008 06:43:11 +0000 (06:43 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 15 Jul 2008 06:43:11 +0000 (06:43 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5468 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Library/GraphicsLib/Graphics.c
MdeModulePkg/Library/GraphicsLib/GraphicsLib.inf

index 17fac2a27115e03122532d8a55aa39bc43154eda..56204aaecad9c38dce13c152e8f6d97a36fa8aba 100644 (file)
@@ -1,9 +1,6 @@
 /** @file\r
-  Support for Basic Graphics operations.\r
-\r
-  BugBug: Currently *.BMP files are supported. This will be replaced\r
-          when Tiano graphics format is supported.\r
-\r
+  Basic Graphics operations based on UEFI HII, Graphics Output protocol or UGA \r
+  Draw protocol.\r
 \r
 Copyright (c) 2006 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
@@ -123,7 +120,7 @@ GetGraphicsBitMapFromFVEx (
 }\r
 \r
 /**\r
-  Convert a *.BMP graphics image to a GOP/UGA blt buffer. If a NULL Blt buffer\r
+  Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer\r
   is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt\r
   buffer is passed in it will be used if it is big enough.\r
 \r
@@ -138,38 +135,42 @@ GetGraphicsBitMapFromFVEx (
   @retval EFI_UNSUPPORTED       BmpImage is not a valid *.BMP image\r
   @retval EFI_BUFFER_TOO_SMALL  The passed in GopBlt buffer is not big enough.\r
                                 GopBltSize will contain the required size.\r
-  @retval EFI_OUT_OF_RESOURCES  No enough buffer to allocate\r
+  @retval EFI_OUT_OF_RESOURCES  No enough buffer to allocate.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ConvertBmpToGopBlt (\r
-  IN  VOID      *BmpImage,\r
-  IN  UINTN     BmpImageSize,\r
-  IN OUT VOID   **GopBlt,\r
-  IN OUT UINTN  *GopBltSize,\r
-  OUT UINTN     *PixelHeight,\r
-  OUT UINTN     *PixelWidth\r
+  IN     VOID      *BmpImage,\r
+  IN     UINTN     BmpImageSize,\r
+  IN OUT VOID      **GopBlt,\r
+  IN OUT UINTN     *GopBltSize,\r
+     OUT UINTN     *PixelHeight,\r
+     OUT UINTN     *PixelWidth\r
   )\r
 {\r
-  UINT8             *Image;\r
-  UINT8             *ImageHeader;\r
-  BMP_IMAGE_HEADER  *BmpHeader;\r
-  BMP_COLOR_MAP     *BmpColorMap;\r
+  UINT8                         *Image;\r
+  UINT8                         *ImageHeader;\r
+  BMP_IMAGE_HEADER              *BmpHeader;\r
+  BMP_COLOR_MAP                 *BmpColorMap;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;\r
-  UINTN             BltBufferSize;\r
-  UINTN             Index;\r
-  UINTN             Height;\r
-  UINTN             Width;\r
-  UINTN             ImageIndex;\r
-  BOOLEAN           IsAllocated;\r
+  UINTN                         BltBufferSize;\r
+  UINTN                         Index;\r
+  UINTN                         Height;\r
+  UINTN                         Width;\r
+  UINTN                         ImageIndex;\r
+  BOOLEAN                       IsAllocated;\r
 \r
   BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;\r
+\r
   if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  //\r
+  // Doesn't support compress.\r
+  //\r
   if (BmpHeader->CompressionType != 0) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -186,9 +187,15 @@ ConvertBmpToGopBlt (
   Image         = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;\r
   ImageHeader   = Image;\r
 \r
+  //\r
+  // Calculate the BltBuffer needed size.\r
+  //\r
   BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
   IsAllocated   = FALSE;\r
   if (*GopBlt == NULL) {\r
+    //\r
+    // GopBlt is not allocated by caller.\r
+    //\r
     *GopBltSize = BltBufferSize;\r
     *GopBlt     = AllocatePool (*GopBltSize);\r
     IsAllocated = TRUE;\r
@@ -196,6 +203,9 @@ ConvertBmpToGopBlt (
       return EFI_OUT_OF_RESOURCES;\r
     }\r
   } else {\r
+    //\r
+    // GopBlt has been allocated by caller.\r
+    //\r
     if (*GopBltSize < BltBufferSize) {\r
       *GopBltSize = BltBufferSize;\r
       return EFI_BUFFER_TOO_SMALL;\r
@@ -215,7 +225,7 @@ ConvertBmpToGopBlt (
       switch (BmpHeader->BitPerPixel) {\r
       case 1:\r
         //\r
-        // Convert 1bit BMP to 24-bit color\r
+        // Convert 1-bit (2 colors) BMP to 24-bit color\r
         //\r
         for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {\r
           Blt->Red    = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;\r
@@ -231,7 +241,7 @@ ConvertBmpToGopBlt (
 \r
       case 4:\r
         //\r
-        // Convert BMP Palette to 24-bit color\r
+        // Convert 4-bit (16 colors) BMP Palette to 24-bit color\r
         //\r
         Index       = (*Image) >> 4;\r
         Blt->Red    = BmpColorMap[Index].Red;\r
@@ -249,7 +259,7 @@ ConvertBmpToGopBlt (
 \r
       case 8:\r
         //\r
-        // Convert BMP Palette to 24-bit color\r
+        // Convert 8-bit (256 colors) BMP Palette to 24-bit color\r
         //\r
         Blt->Red    = BmpColorMap[*Image].Red;\r
         Blt->Green  = BmpColorMap[*Image].Green;\r
@@ -257,14 +267,20 @@ ConvertBmpToGopBlt (
         break;\r
 \r
       case 24:\r
+        //\r
+        // It is 24-bit BMP.\r
+        //\r
         Blt->Blue   = *Image++;\r
         Blt->Green  = *Image++;\r
         Blt->Red    = *Image;\r
         break;\r
 \r
       default:\r
+        //\r
+        // Other bit format BMP is not supported.\r
+        //\r
         if (IsAllocated) {\r
-          gBS->FreePool (*GopBlt);\r
+          FreePool (*GopBlt);\r
           *GopBlt = NULL;\r
         }\r
         return EFI_UNSUPPORTED;\r
@@ -296,7 +312,7 @@ ConvertBmpToGopBlt (
 \r
   @retval EFI_SUCCESS     ConsoleControl has been flipped to graphics and logo\r
                           displayed.\r
-  @retval EFI_UNSUPPORTED Password not found\r
+  @retval EFI_UNSUPPORTED Password not found.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -320,12 +336,12 @@ LockKeyboards (
 \r
 /**\r
   Use Console Control to turn off UGA based Simple Text Out consoles from going\r
-  to the UGA device. Put up LogoFile on every UGA device that is a console\r
+  to the UGA device. Put up LogoFile on every UGA device that is a console.\r
 \r
-  @param[in]  LogoFile   File name of logo to display on the center of the screen.\r
+  @param  LogoFile        File name of logo to display on the center of the screen.\r
 \r
   @retval EFI_SUCCESS     ConsoleControl has been flipped to graphics and logo displayed.\r
-  @retval EFI_UNSUPPORTED Logo not found\r
+  @retval EFI_UNSUPPORTED Logo not found.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -338,7 +354,7 @@ EnableQuietBoot (
 }\r
 \r
 /**\r
-  Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going\r
+  Use Console Control to turn off UGA based Simple Text Out consoles from going\r
   to the UGA device. Put up LogoFile on every UGA device that is a console\r
 \r
   @param  LogoFile    File name of logo to display on the center of the screen.\r
@@ -347,7 +363,7 @@ EnableQuietBoot (
                       the driver image is loaded will be tried first.\r
 \r
   @retval EFI_SUCCESS     ConsoleControl has been flipped to graphics and logo displayed.\r
-  @retval EFI_UNSUPPORTED Logo not found\r
+  @retval EFI_UNSUPPORTED Logo not found.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -380,7 +396,7 @@ EnableQuietBootEx (
   UINT32                        RefreshRate;\r
   EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
 \r
-  Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID**)&ConsoleControl);\r
+  Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
   if (EFI_ERROR (Status)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
@@ -389,21 +405,24 @@ EnableQuietBootEx (
   //\r
   // Try to open GOP first\r
   //\r
-  Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID**)&GraphicsOutput);\r
+  Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);\r
   if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
     GraphicsOutput = NULL;\r
     //\r
     // Open GOP failed, try to open UGA\r
     //\r
-    Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID**)&UgaDraw);\r
+    Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
   Badging = NULL;\r
-  Status  = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID**)&Badging);\r
+  Status  = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);\r
 \r
+  //\r
+  // Set console control to graphics mode.\r
+  //\r
   Status = ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);\r
   if (EFI_ERROR (Status)) {\r
     return EFI_UNSUPPORTED;\r
@@ -427,6 +446,9 @@ EnableQuietBootEx (
     ImageSize = 0;\r
 \r
     if (Badging != NULL) {\r
+      //\r
+      // Get image from OEMBadging protocol.\r
+      //\r
       Status = Badging->GetImage (\r
                           Badging,\r
                           &Instance,\r
@@ -442,13 +464,16 @@ EnableQuietBootEx (
       }\r
 \r
       //\r
-      // Currently only support BMP format\r
+      // Currently only support BMP format.\r
       //\r
       if (Format != EfiBadgingFormatBMP) {\r
-        gBS->FreePool (ImageData);\r
+        SafeFreePool (ImageData);\r
         continue;\r
       }\r
     } else {\r
+      //\r
+      // Get the specified image from FV.\r
+      //\r
       Status = GetGraphicsBitMapFromFVEx (ImageHandle, LogoFile, (VOID **) &ImageData, &ImageSize);\r
       if (EFI_ERROR (Status)) {\r
         return EFI_UNSUPPORTED;\r
@@ -463,13 +488,13 @@ EnableQuietBootEx (
     Status = ConvertBmpToGopBlt (\r
               ImageData,\r
               ImageSize,\r
-              (VOID**)&Blt,\r
+              (VOID **) &Blt,\r
               &BltSize,\r
               &Height,\r
               &Width\r
               );\r
     if (EFI_ERROR (Status)) {\r
-      gBS->FreePool (ImageData);\r
+      SafeFreePool (ImageData);\r
       if (Badging == NULL) {\r
         return Status;\r
       } else {\r
@@ -477,6 +502,9 @@ EnableQuietBootEx (
       }\r
     }\r
 \r
+    //\r
+    // Caculate the display position according to Attribute.\r
+    //\r
     switch (Attribute) {\r
     case EfiBadgingDisplayAttributeLeftTop:\r
       DestX = CoordinateX;\r
@@ -561,8 +589,8 @@ EnableQuietBootEx (
       }\r
     }\r
 \r
-    gBS->FreePool (ImageData);\r
-    gBS->FreePool (Blt);\r
+    SafeFreePool (ImageData);\r
+    SafeFreePool (Blt);\r
 \r
     if (Badging == NULL) {\r
       break;\r
@@ -594,24 +622,27 @@ DisableQuietBoot (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
+  //\r
+  // Set console control to text mode.\r
+  //\r
   return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);\r
 }\r
 \r
 /**\r
-  Display string worker for: Print, PrintAt, IPrint, IPrintAt.\r
+  Internal display string worker function.\r
 \r
-  @param GraphicsOutput   Graphics output protocol interface\r
-  @param UgaDraw          UGA draw protocol interface\r
-  @param Sto              Simple text out protocol interface\r
-  @param X                X coordinate to start printing\r
-  @param Y                Y coordinate to start printing\r
-  @param Foreground       Foreground color\r
-  @param Background       Background color\r
-  @param fmt              Format string\r
-  @param args             Print arguments\r
+  @param GraphicsOutput   Graphics output protocol interface.\r
+  @param UgaDraw          UGA draw protocol interface.\r
+  @param Sto              Simple text out protocol interface.\r
+  @param X                X coordinate to start printing.\r
+  @param Y                Y coordinate to start printing.\r
+  @param Foreground       Foreground color.\r
+  @param Background       Background color.\r
+  @param fmt              Format string.\r
+  @param args             Print arguments.\r
 \r
-  @retval EFI_SUCCESS             Success.\r
-  @retval EFI_OUT_OF_RESOURCES    Out of resources.\r
+  @return  Number of Characters printed. Zero means no any character \r
+           displayed successfully.\r
 \r
 **/\r
 UINTN\r
@@ -642,13 +673,14 @@ Print (
   EFI_FONT_DISPLAY_INFO          *FontInfo;\r
   EFI_HII_ROW_INFO               *RowInfoArray;\r
   UINTN                          RowInfoArraySize;\r
+  UINTN                          PrintNum;     \r
 \r
   //\r
   // For now, allocate an arbitrarily long buffer\r
   //\r
   Buffer = AllocateZeroPool (0x10000);\r
   if (Buffer == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    return 0;\r
   }\r
 \r
   HorizontalResolution  = 0;\r
@@ -673,7 +705,7 @@ Print (
     goto Error;\r
   }\r
 \r
-  UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r
+  PrintNum = UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r
 \r
   UnicodeWeight = (CHAR16 *) Buffer;\r
 \r
@@ -687,7 +719,6 @@ Print (
 \r
   BufferLen = StrLen (Buffer);\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
      Status = EFI_INVALID_PARAMETER;\r
@@ -801,22 +832,28 @@ Print (
 Error:\r
   SafeFreePool (Blt);\r
   SafeFreePool (FontInfo);\r
-  gBS->FreePool (Buffer);\r
-  return Status;\r
+  FreePool (Buffer);\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    return PrintNum;\r
+  } else {\r
+    return 0;\r
+  }\r
 }\r
 \r
 /**\r
   Print to graphics screen at the given X,Y coordinates of the graphics screen.\r
   see definition of Print to find rules for constructing Fmt.\r
 \r
-  @param  X            Row to start printing at\r
-  @param  Y            Column to start printing at\r
-  @param  ForeGround   Foreground color\r
-  @param  BackGround   background color\r
-  @param  Fmt          Print format sting. See definition of Print\r
-  @param  ...          Argumnet stream defined by Fmt string\r
+  @param  X            Row to start printing at.\r
+  @param  Y            Column to start printing at.\r
+  @param  ForeGround   Foreground color.\r
+  @param  BackGround   background color.\r
+  @param  Fmt          Print format sting. See definition of Print.\r
+  @param  ...          Argumnet stream defined by Fmt string.\r
 \r
-  @retval UINTN     Number of Characters printed\r
+  @return  Number of Characters printed. Zero means no any character \r
+           displayed successfully.\r
 \r
 **/\r
 UINTN\r
@@ -830,12 +867,12 @@ PrintXY (
   ...\r
   )\r
 {\r
-  EFI_HANDLE                    Handle;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
-  EFI_UGA_DRAW_PROTOCOL         *UgaDraw;\r
+  EFI_HANDLE                       Handle;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL     *GraphicsOutput;\r
+  EFI_UGA_DRAW_PROTOCOL            *UgaDraw;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *Sto;\r
-  EFI_STATUS                    Status;\r
-  VA_LIST                       Args;\r
+  EFI_STATUS                       Status;\r
+  VA_LIST                          Args;\r
 \r
   VA_START (Args, Fmt);\r
 \r
@@ -844,31 +881,34 @@ PrintXY (
   Status = gBS->HandleProtocol (\r
                   Handle,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
-                  (VOID**)&GraphicsOutput\r
+                  (VOID **) &GraphicsOutput\r
                   );\r
 \r
   UgaDraw = NULL;\r
   if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
+    //\r
+    // If no GOP available, try to open UGA Draw protocol if supported.\r
+    //\r
     GraphicsOutput = NULL;\r
 \r
     Status = gBS->HandleProtocol (\r
                     Handle,\r
                     &gEfiUgaDrawProtocolGuid,\r
-                    (VOID**)&UgaDraw\r
+                    (VOID **) &UgaDraw\r
                     );\r
   }\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    return 0;\r
   }\r
 \r
   Status = gBS->HandleProtocol (\r
                   Handle,\r
                   &gEfiSimpleTextOutProtocolGuid,\r
-                  (VOID**)&Sto\r
+                  (VOID **) &Sto\r
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    return 0;\r
   }\r
 \r
   return Print (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
index 57722d896284b2db176cfff0577cebedb2ae004f..da6614f510a390a2085baca9a58d66ad61952325 100644 (file)
@@ -1,5 +1,5 @@
 #/** @file\r
-# Graphics Library for UEFI drivers\r
+# Graphics Library for UEFI drivers.\r
 #\r
 # This library provides supports for basic graphic functions.\r
 # Copyright (c) 2006 - 2007, Intel Corporation.\r
@@ -16,7 +16,7 @@
 \r
 [Defines]\r
   INF_VERSION                    = 0x00010005\r
-  BASE_NAME                      = EdkGraphicsLib\r
+  BASE_NAME                      = UefiGraphicsLib\r
   FILE_GUID                      = 08c1a0e4-1208-47f8-a2c5-f42eabee653a\r
   MODULE_TYPE                    = DXE_DRIVER\r
   VERSION_STRING                 = 1.0\r
@@ -46,6 +46,7 @@
   DebugLib\r
   DxePiLib\r
   BaseMemoryLib\r
+  PcdLib\r
 \r
 [Protocols]\r
   gEfiSimpleTextOutProtocolGuid                 # PROTOCOL ALWAYS_CONSUMED\r