]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GraphicsLib/Graphics.c
Merger trackers #7807 and #8372.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GraphicsLib / Graphics.c
index 0881c3d9656643a507a22a06ebb6096f07d349ec..50eb1f56bc0d58f18ddbb84f6b6eb39bf97666c0 100644 (file)
@@ -5,21 +5,36 @@
           when Tiano graphics format is supported.\r
 \r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. 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, Intel Corporation\r
+All rights reserved. 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
 \r
 **/\r
 \r
-//\r
-// Include common header file for this module.\r
-//\r
-#include "CommonHeader.h"\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Protocol/SimpleTextOut.h>\r
+#include <Protocol/OEMBadging.h>\r
+#include <Protocol/ConsoleControl.h>\r
+#include <Protocol/GraphicsOutput.h>\r
+#include <Protocol/FirmwareVolume2.h>\r
+#include <Protocol/UgaDraw.h>\r
+#include <Protocol/HiiFramework.h>\r
+\r
+#include <Guid/Bmp.h>\r
+\r
+#include <Library/GraphicsLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
 \r
 EFI_STATUS\r
 GetGraphicsBitMapFromFV (\r
@@ -39,15 +54,15 @@ Arguments:
 \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
@@ -56,14 +71,14 @@ Returns:
   EFI_STATUS                    Status;\r
   UINTN                         FvProtocolCount;\r
   EFI_HANDLE                    *FvHandles;\r
-  EFI_FIRMWARE_VOLUME_PROTOCOL  *Fv;\r
+  EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
   UINTN                         Index;\r
   UINT32                        AuthenticationStatus;\r
 \r
 \r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
-                  &gEfiFirmwareVolumeProtocolGuid,\r
+                  &gEfiFirmwareVolume2ProtocolGuid,\r
                   NULL,\r
                   &FvProtocolCount,\r
                   &FvHandles\r
@@ -75,7 +90,7 @@ Returns:
   for (Index = 0; Index < FvProtocolCount; Index++) {\r
     Status = gBS->HandleProtocol (\r
                     FvHandles[Index],\r
-                    &gEfiFirmwareVolumeProtocolGuid,\r
+                    &gEfiFirmwareVolume2ProtocolGuid,\r
                     (VOID **) &Fv\r
                     );\r
 \r
@@ -118,8 +133,8 @@ ConvertBmpToGopBlt (
 \r
 Routine Description:\r
 \r
-  Convert a *.BMP graphics image to a UGA blt buffer. If a NULL UgaBlt buffer\r
-  is passed in a UgaBlt buffer will be allocated by this routine. If a UgaBlt\r
+  Convert a *.BMP graphics image to a GOP/UGA 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
 Arguments:\r
@@ -128,21 +143,21 @@ Arguments:
 \r
   BmpImageSize  - Number of bytes in BmpImage\r
 \r
-  UgaBlt        - Buffer containing UGA version of BmpImage.\r
+  GopBlt        - Buffer containing GOP version of BmpImage.\r
 \r
-  UgaBltSize    - Size of UgaBlt in bytes.\r
+  GopBltSize    - Size of GopBlt in bytes.\r
 \r
-  PixelHeight   - Height of UgaBlt/BmpImage in pixels\r
+  PixelHeight   - Height of GopBlt/BmpImage in pixels\r
 \r
-  PixelWidth    - Width of UgaBlt/BmpImage in pixels\r
+  PixelWidth    - Width of GopBlt/BmpImage in pixels\r
 \r
 \r
-Returns: \r
+Returns:\r
 \r
-  EFI_SUCCESS           - UgaBlt and UgaBltSize are returned. \r
+  EFI_SUCCESS           - GopBlt and GopBltSize are returned.\r
   EFI_UNSUPPORTED       - BmpImage is not a valid *.BMP image\r
-  EFI_BUFFER_TOO_SMALL  - The passed in UgaBlt buffer is not big enough.\r
-                          UgaBltSize will contain the required size.\r
+  EFI_BUFFER_TOO_SMALL  - The passed in GopBlt buffer is not big enough.\r
+                          GopBltSize will contain the required size.\r
   EFI_OUT_OF_RESOURCES  - No enough buffer to allocate\r
 \r
 --*/\r
@@ -159,7 +174,7 @@ Returns:
   UINTN             Width;\r
   UINTN             ImageIndex;\r
   BOOLEAN           IsAllocated;\r
-  \r
+\r
   BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;\r
   if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {\r
     return EFI_UNSUPPORTED;\r
@@ -223,7 +238,7 @@ Returns:
         Blt --;\r
         Width --;\r
         break;\r
-      \r
+\r
       case 4:\r
         //\r
         // Convert BMP Palette to 24-bit color\r
@@ -288,7 +303,7 @@ LockKeyboards (
 /*++\r
 \r
 Routine Description:\r
-  Use Console Control Protocol to lock the Console In Spliter virtual handle. \r
+  Use Console Control Protocol to lock the Console In Spliter virtual handle.\r
   This is the ConInHandle and ConIn handle in the EFI system table. All key\r
   presses will be ignored until the Password is typed in. The only way to\r
   disable the password is to type it in to a ConIn device.\r
@@ -297,7 +312,7 @@ Arguments:
   Password - Password used to lock ConIn device\r
 \r
 \r
-Returns: \r
+Returns:\r
 \r
   EFI_SUCCESS     - ConsoleControl has been flipped to graphics and logo\r
                           displayed.\r
@@ -334,7 +349,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
@@ -374,7 +389,7 @@ Returns:
   //\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)) {\r
     GraphicsOutput = NULL;\r
     //\r
@@ -560,16 +575,16 @@ DisableQuietBoot (
 \r
 Routine Description:\r
 \r
-  Use Console Control to turn on UGA based Simple Text Out consoles. The UGA \r
-  Simple Text Out screens will now be synced up with all non UGA output devices\r
+  Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA\r
+  Simple Text Out screens will now be synced up with all non GOP/UGA output devices\r
 \r
 Arguments:\r
 \r
   NONE\r
 \r
-Returns: \r
+Returns:\r
 \r
-  EFI_SUCCESS           - UGA devices are back in text mode and synced up.\r
+  EFI_SUCCESS           - GOP/UGA devices are back in text mode and synced up.\r
   EFI_UNSUPPORTED       - Logo not found\r
 \r
 --*/\r
@@ -626,45 +641,47 @@ Routine Description:
 Arguments:\r
 \r
   GraphicsOutput  - Graphics output protocol interface\r
-  \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
 \r
 --*/\r
 {\r
-  VOID              *Buffer;\r
-  EFI_STATUS        Status;\r
-  UINT16            GlyphWidth;\r
-  UINT32            GlyphStatus;\r
-  UINT16            StringIndex;\r
-  UINTN             Index;\r
-  CHAR16            *UnicodeWeight;\r
-  EFI_NARROW_GLYPH  *Glyph;\r
-  EFI_HII_PROTOCOL  *Hii;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL     *LineBuffer;\r
-  UINT32            HorizontalResolution;\r
-  UINT32            VerticalResolution;\r
-  UINT32            ColorDepth;\r
-  UINT32            RefreshRate;\r
-  UINTN             BufferGlyphWidth;\r
+  VOID                           *Buffer;\r
+  EFI_STATUS                     Status;\r
+  UINT16                         GlyphWidth;\r
+  UINT32                         GlyphStatus;\r
+  UINT16                         StringIndex;\r
+  UINTN                          Index;\r
+  CHAR16                         *UnicodeWeight;\r
+  EFI_NARROW_GLYPH               *Glyph;\r
+  EFI_HII_PROTOCOL               *Hii;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *LineBuffer;\r
+  UINT32                         HorizontalResolution;\r
+  UINT32                         VerticalResolution;\r
+  UINT32                         ColorDepth;\r
+  UINT32                         RefreshRate;\r
+  UINTN                          BufferLen;\r
+  UINTN                          LineBufferLen;\r
+  UINTN                          BufferGlyphWidth;\r
 \r
   GlyphStatus = 0;\r
 \r
@@ -675,7 +692,7 @@ Returns:
   if (Buffer == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   if (GraphicsOutput != NULL) {\r
     HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r
     VerticalResolution   = GraphicsOutput->Mode->Info->VerticalResolution;\r
@@ -685,8 +702,10 @@ Returns:
     //\r
     UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r
   }\r
+  ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));\r
 \r
-  LineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_WIDTH * GLYPH_HEIGHT);\r
+  LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_HEIGHT;\r
+  LineBuffer = AllocatePool (LineBufferLen);\r
   if (LineBuffer == NULL) {\r
     gBS->FreePool (Buffer);\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -709,7 +728,14 @@ Returns:
     }\r
   }\r
 \r
-  for (Index = 0; Index < StrLen (Buffer); Index++) {\r
+  BufferLen = StrLen (Buffer);\r
+\r
+  if (GLYPH_WIDTH * GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {\r
+     Status = EFI_INVALID_PARAMETER;\r
+     goto Error;\r
+  }\r
+\r
+  for (Index = 0; Index < BufferLen; Index++) {\r
     StringIndex = (UINT16) Index;\r
     Status      = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);\r
     if (EFI_ERROR (Status)) {\r
@@ -722,7 +748,7 @@ Returns:
                       (UINT8 *) Glyph,\r
                       mEfiColors[Sto->Mode->Attribute & 0x0f],\r
                       mEfiColors[Sto->Mode->Attribute >> 4],\r
-                      StrLen (Buffer),\r
+                      BufferLen,\r
                       GlyphWidth,\r
                       GLYPH_HEIGHT,\r
                       &LineBuffer[Index * GLYPH_WIDTH]\r
@@ -733,7 +759,7 @@ Returns:
                       (UINT8 *) Glyph,\r
                       *Foreground,\r
                       *Background,\r
-                      StrLen (Buffer),\r
+                      BufferLen,\r
                       GlyphWidth,\r
                       GLYPH_HEIGHT,\r
                       &LineBuffer[Index * GLYPH_WIDTH]\r
@@ -744,7 +770,7 @@ Returns:
   //\r
   // Blt a character to the screen\r
   //\r
-  BufferGlyphWidth = GLYPH_WIDTH * StrLen (Buffer);\r
+  BufferGlyphWidth = GLYPH_WIDTH * BufferLen;\r
   if (GraphicsOutput != NULL) {\r
     Status = GraphicsOutput->Blt (\r
                         GraphicsOutput,\r
@@ -798,11 +824,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