git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2895 6f19259b...
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 29 Jun 2007 07:07:06 +0000 (07:07 +0000)
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 29 Jun 2007 07:07:06 +0000 (07:07 +0000)
IntelFrameworkModulePkg/Library/GraphicsLib/CommonHeader.h [new file with mode: 0644]
IntelFrameworkModulePkg/Library/GraphicsLib/Graphics.c [new file with mode: 0644]
IntelFrameworkModulePkg/Library/GraphicsLib/GraphicsLib.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Library/GraphicsLib/GraphicsLib.msa [new file with mode: 0644]

diff --git a/IntelFrameworkModulePkg/Library/GraphicsLib/CommonHeader.h b/IntelFrameworkModulePkg/Library/GraphicsLib/CommonHeader.h
new file mode 100644 (file)
index 0000000..3c31cb1
--- /dev/null
@@ -0,0 +1,45 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2006 - 2007, 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
+   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
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/SimpleTextOut.h>\r
+#include <Protocol/OEMBadging.h>\r
+#include <Protocol/ConsoleControl.h>\r
+#include <Protocol/GraphicsOutput.h>\r
+#include <Protocol/FirmwareVolume.h>\r
+#include <Protocol/UgaDraw.h>\r
+#include <Protocol/FrameworkHii.h>\r
+\r
+#include <Guid/Bmp.h>\r
+//\r
+// The Library classes this module consumes\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
+\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Library/GraphicsLib/Graphics.c b/IntelFrameworkModulePkg/Library/GraphicsLib/Graphics.c
new file mode 100644 (file)
index 0000000..a90eb53
--- /dev/null
@@ -0,0 +1,870 @@
+/*++\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
+\r
+Module Name:\r
+\r
+  Graphics.c\r
+\r
+Abstract:\r
+\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
+--*/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+EFI_STATUS\r
+GetGraphicsBitMapFromFV (\r
+  IN  EFI_GUID      *FileNameGuid,\r
+  OUT VOID          **Image,\r
+  OUT UINTN         *ImageSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Return the graphics image file named FileNameGuid into Image and return it's\r
+  size in ImageSize. All Firmware Volumes (FV) in the system are searched for the\r
+  file name.\r
+\r
+Arguments:\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
+                  buffer will be allocated.\r
+\r
+  ImageSize     - Size of the graphics Image in bytes. Zero if no image found.\r
+\r
+\r
+Returns: \r
+\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
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  UINTN                         FvProtocolCount;\r
+  EFI_HANDLE                    *FvHandles;\r
+  EFI_FIRMWARE_VOLUME_PROTOCOL  *Fv;\r
+  UINTN                         Index;\r
+  UINT32                        AuthenticationStatus;\r
+\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiFirmwareVolumeProtocolGuid,\r
+                  NULL,\r
+                  &FvProtocolCount,\r
+                  &FvHandles\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  for (Index = 0; Index < FvProtocolCount; Index++) {\r
+    Status = gBS->HandleProtocol (\r
+                    FvHandles[Index],\r
+                    &gEfiFirmwareVolumeProtocolGuid,\r
+                    (VOID **) &Fv\r
+                    );\r
+\r
+    //\r
+    // Assuming Image and ImageSize are correct on input.\r
+    //\r
+    Status = Fv->ReadSection (\r
+                  Fv,\r
+                  FileNameGuid,\r
+                  EFI_SECTION_RAW,\r
+                  0,\r
+                  Image,\r
+                  ImageSize,\r
+                  &AuthenticationStatus\r
+                  );\r
+    if (!EFI_ERROR (Status)) {\r
+      return EFI_SUCCESS;\r
+    } else if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      //\r
+      // ImageSize updated to needed size so return\r
+      //\r
+      return EFI_BUFFER_TOO_SMALL;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\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
+  )\r
+/*++\r
+\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
+  buffer is passed in it will be used if it is big enough.\r
+\r
+Arguments:\r
+\r
+  BmpImage      - Pointer to BMP file\r
+\r
+  BmpImageSize  - Number of bytes in BmpImage\r
+\r
+  UgaBlt        - Buffer containing UGA version of BmpImage.\r
+\r
+  UgaBltSize    - Size of UgaBlt in bytes.\r
+\r
+  PixelHeight   - Height of UgaBlt/BmpImage in pixels\r
+\r
+  PixelWidth    - Width of UgaBlt/BmpImage in pixels\r
+\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS           - UgaBlt and UgaBltSize 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_OUT_OF_RESOURCES  - No enough buffer to allocate\r
+\r
+--*/\r
+{\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
+  \r
+  BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;\r
+  if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (BmpHeader->CompressionType != 0) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Calculate Color Map offset in the image.\r
+  //\r
+  Image       = BmpImage;\r
+  BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));\r
+\r
+  //\r
+  // Calculate graphics image data address in the image\r
+  //\r
+  Image         = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;\r
+  ImageHeader   = Image;\r
+\r
+  BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
+  IsAllocated   = FALSE;\r
+  if (*GopBlt == NULL) {\r
+    *GopBltSize = BltBufferSize;\r
+    *GopBlt     = AllocatePool (*GopBltSize);\r
+    IsAllocated = TRUE;\r
+    if (*GopBlt == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  } else {\r
+    if (*GopBltSize < BltBufferSize) {\r
+      *GopBltSize = BltBufferSize;\r
+      return EFI_BUFFER_TOO_SMALL;\r
+    }\r
+  }\r
+\r
+  *PixelWidth   = BmpHeader->PixelWidth;\r
+  *PixelHeight  = BmpHeader->PixelHeight;\r
+\r
+  //\r
+  // Convert image from BMP to Blt buffer format\r
+  //\r
+  BltBuffer = *GopBlt;\r
+  for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {\r
+    Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];\r
+    for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {\r
+      switch (BmpHeader->BitPerPixel) {\r
+      case 1:\r
+        //\r
+        // Convert 1bit 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
+          Blt->Green  = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;\r
+          Blt->Blue   = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;\r
+          Blt++;\r
+          Width++;\r
+        }\r
+\r
+        Blt --;\r
+        Width --;\r
+        break;\r
+      \r
+      case 4:\r
+        //\r
+        // Convert BMP Palette to 24-bit color\r
+        //\r
+        Index       = (*Image) >> 4;\r
+        Blt->Red    = BmpColorMap[Index].Red;\r
+        Blt->Green  = BmpColorMap[Index].Green;\r
+        Blt->Blue   = BmpColorMap[Index].Blue;\r
+        if (Width < (BmpHeader->PixelWidth - 1)) {\r
+          Blt++;\r
+          Width++;\r
+          Index       = (*Image) & 0x0f;\r
+          Blt->Red    = BmpColorMap[Index].Red;\r
+          Blt->Green  = BmpColorMap[Index].Green;\r
+          Blt->Blue   = BmpColorMap[Index].Blue;\r
+        }\r
+        break;\r
+\r
+      case 8:\r
+        //\r
+        // Convert BMP Palette to 24-bit color\r
+        //\r
+        Blt->Red    = BmpColorMap[*Image].Red;\r
+        Blt->Green  = BmpColorMap[*Image].Green;\r
+        Blt->Blue   = BmpColorMap[*Image].Blue;\r
+        break;\r
+\r
+      case 24:\r
+        Blt->Blue   = *Image++;\r
+        Blt->Green  = *Image++;\r
+        Blt->Red    = *Image;\r
+        break;\r
+\r
+      default:\r
+        if (IsAllocated) {\r
+          gBS->FreePool (*GopBlt);\r
+          *GopBlt = NULL;\r
+        }\r
+        return EFI_UNSUPPORTED;\r
+        break;\r
+      };\r
+\r
+    }\r
+\r
+    ImageIndex = (UINTN) (Image - ImageHeader);\r
+    if ((ImageIndex % 4) != 0) {\r
+      //\r
+      // Bmp Image starts each row on a 32-bit boundary!\r
+      //\r
+      Image = Image + (4 - (ImageIndex % 4));\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+LockKeyboards (\r
+  IN  CHAR16    *Password\r
+  )\r
+/*++\r
+\r
+Routine Description:\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
+\r
+Arguments:\r
+  Password - Password used to lock ConIn device\r
+\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS     - ConsoleControl has been flipped to graphics and logo\r
+                          displayed.\r
+  EFI_UNSUPPORTED - Logo not found\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_CONSOLE_CONTROL_PROTOCOL  *ConsoleControl;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = ConsoleControl->LockStdIn (ConsoleControl, Password);\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EnableQuietBoot (\r
+  IN  EFI_GUID  *LogoFile\r
+  )\r
+/*++\r
+\r
+Routine Description:\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
+\r
+Arguments:\r
+\r
+  LogoFile - File name of logo to display on the center of the screen.\r
+\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS           - ConsoleControl has been flipped to graphics and logo\r
+                          displayed.\r
+  EFI_UNSUPPORTED       - Logo not found\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_CONSOLE_CONTROL_PROTOCOL  *ConsoleControl;\r
+  EFI_OEM_BADGING_PROTOCOL      *Badging;\r
+  UINT32                        SizeOfX;\r
+  UINT32                        SizeOfY;\r
+  INTN                          DestX;\r
+  INTN                          DestY;\r
+  UINT8                         *ImageData;\r
+  UINTN                         ImageSize;\r
+  UINTN                         BltSize;\r
+  UINT32                        Instance;\r
+  EFI_BADGING_FORMAT            Format;\r
+  EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;\r
+  UINTN                         CoordinateX;\r
+  UINTN                         CoordinateY;\r
+  UINTN                         Height;\r
+  UINTN                         Width;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;\r
+  EFI_UGA_DRAW_PROTOCOL         *UgaDraw;\r
+  UINT32                        ColorDepth;\r
+  UINT32                        RefreshRate;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL  *GraphicsOutput;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  UgaDraw = NULL;\r
+  //\r
+  // Try to open GOP first\r
+  //\r
+  Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput); \r
+  if (EFI_ERROR(Status)) {\r
+    GraphicsOutput = NULL;\r
+    //\r
+    // Open GOP failed, try to open UGA\r
+    //\r
+    Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
+  Badging = NULL;\r
+  Status  = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);\r
+\r
+  ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);\r
+\r
+  if (GraphicsOutput != NULL) {\r
+    SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r
+    SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r
+  } else {\r
+    Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
+  Instance = 0;\r
+  while (1) {\r
+    ImageData = NULL;\r
+    ImageSize = 0;\r
+\r
+    if (Badging != NULL) {\r
+      Status = Badging->GetImage (\r
+                          Badging,\r
+                          &Instance,\r
+                          &Format,\r
+                          &ImageData,\r
+                          &ImageSize,\r
+                          &Attribute,\r
+                          &CoordinateX,\r
+                          &CoordinateY\r
+                          );\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+\r
+      //\r
+      // Currently only support BMP format\r
+      //\r
+      if (Format != EfiBadgingFormatBMP) {\r
+        gBS->FreePool (ImageData);\r
+        continue;\r
+      }\r
+    } else {\r
+      Status = GetGraphicsBitMapFromFV (LogoFile, (VOID **) &ImageData, &ImageSize);\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+\r
+      CoordinateX = 0;\r
+      CoordinateY = 0;\r
+      Attribute   = EfiBadgingDisplayAttributeCenter;\r
+    }\r
+\r
+    Blt = NULL;\r
+    BltSize = 0;\r
+    Status = ConvertBmpToGopBlt (\r
+              ImageData,\r
+              ImageSize,\r
+              (VOID**)&Blt,\r
+              &BltSize,\r
+              &Height,\r
+              &Width\r
+              );\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->FreePool (ImageData);\r
+      if (Badging == NULL) {\r
+        return Status;\r
+      } else {\r
+        continue;\r
+      }\r
+    }\r
+\r
+    switch (Attribute) {\r
+    case EfiBadgingDisplayAttributeLeftTop:\r
+      DestX = CoordinateX;\r
+      DestY = CoordinateY;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenterTop:\r
+      DestX = (SizeOfX - Width) / 2;\r
+      DestY = CoordinateY;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeRightTop:\r
+      DestX = (SizeOfX - Width - CoordinateX);\r
+      DestY = CoordinateY;;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenterRight:\r
+      DestX = (SizeOfX - Width - CoordinateX);\r
+      DestY = (SizeOfY - Height) / 2;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeRightBottom:\r
+      DestX = (SizeOfX - Width - CoordinateX);\r
+      DestY = (SizeOfY - Height - CoordinateY);\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenterBottom:\r
+      DestX = (SizeOfX - Width) / 2;\r
+      DestY = (SizeOfY - Height - CoordinateY);\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeLeftBottom:\r
+      DestX = CoordinateX;\r
+      DestY = (SizeOfY - Height - CoordinateY);\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenterLeft:\r
+      DestX = CoordinateX;\r
+      DestY = (SizeOfY - Height) / 2;\r
+      break;\r
+\r
+    case EfiBadgingDisplayAttributeCenter:\r
+      DestX = (SizeOfX - Width) / 2;\r
+      DestY = (SizeOfY - Height) / 2;\r
+      break;\r
+\r
+    default:\r
+      DestX = CoordinateX;\r
+      DestY = CoordinateY;\r
+      break;\r
+    }\r
+\r
+    if ((DestX >= 0) && (DestY >= 0)) {\r
+      if (GraphicsOutput != NULL) {\r
+        Status = GraphicsOutput->Blt (\r
+                            GraphicsOutput,\r
+                            Blt,\r
+                            EfiBltBufferToVideo,\r
+                            0,\r
+                            0,\r
+                            (UINTN) DestX,\r
+                            (UINTN) DestY,\r
+                            Width,\r
+                            Height,\r
+                            Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                            );\r
+      } else {\r
+        Status = UgaDraw->Blt (\r
+                            UgaDraw,\r
+                            (EFI_UGA_PIXEL *) Blt,\r
+                            EfiUgaBltBufferToVideo,\r
+                            0,\r
+                            0,\r
+                            (UINTN) DestX,\r
+                            (UINTN) DestY,\r
+                            Width,\r
+                            Height,\r
+                            Width * sizeof (EFI_UGA_PIXEL)\r
+                            );\r
+      }\r
+    }\r
+\r
+    gBS->FreePool (ImageData);\r
+    gBS->FreePool (Blt);\r
+\r
+    if (Badging == NULL) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+DisableQuietBoot (\r
+  VOID\r
+  )\r
+/*++\r
+\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
+\r
+Arguments:\r
+\r
+  NONE\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS           - UGA devices are back in text mode and synced up.\r
+  EFI_UNSUPPORTED       - Logo not found\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_CONSOLE_CONTROL_PROTOCOL  *ConsoleControl;\r
+\r
+  Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);\r
+}\r
+\r
+static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r
+  { 0x00, 0x00, 0x00, 0x00 },\r
+  { 0x98, 0x00, 0x00, 0x00 },\r
+  { 0x00, 0x98, 0x00, 0x00 },\r
+  { 0x98, 0x98, 0x00, 0x00 },\r
+  { 0x00, 0x00, 0x98, 0x00 },\r
+  { 0x98, 0x00, 0x98, 0x00 },\r
+  { 0x00, 0x98, 0x98, 0x00 },\r
+  { 0x98, 0x98, 0x98, 0x00 },\r
+  { 0x10, 0x10, 0x10, 0x00 },\r
+  { 0xff, 0x10, 0x10, 0x00 },\r
+  { 0x10, 0xff, 0x10, 0x00 },\r
+  { 0xff, 0xff, 0x10, 0x00 },\r
+  { 0x10, 0x10, 0xff, 0x00 },\r
+  { 0xf0, 0x10, 0xff, 0x00 },\r
+  { 0x10, 0xff, 0xff, 0x00 },\r
+  { 0xff, 0xff, 0xff, 0x00 }\r
+};\r
+\r
+STATIC\r
+UINTN\r
+_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 UINTN                            X,\r
+  IN UINTN                            Y,\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Foreground,\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *Background,\r
+  IN CHAR16                           *fmt,\r
+  IN VA_LIST                          args\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Display string worker for: Print, PrintAt, IPrint, IPrintAt\r
+\r
+Arguments:\r
+\r
+  GraphicsOutput  - Graphics output protocol interface\r
+  \r
+  UgaDraw         - UGA draw protocol interface\r
+  \r
+  Sto             - Simple text out protocol interface\r
+  \r
+  X               - X coordinate to start printing\r
+  \r
+  Y               - Y coordinate to start printing\r
+  \r
+  Foreground      - Foreground color\r
+  \r
+  Background      - Background color\r
+  \r
+  fmt             - Format string\r
+  \r
+  args            - Print arguments\r
+\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
+\r
+  GlyphStatus = 0;\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
+  }\r
+  \r
+  if (GraphicsOutput != NULL) {\r
+    HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r
+    VerticalResolution   = GraphicsOutput->Mode->Info->VerticalResolution;\r
+  } else {\r
+    //\r
+    // Get the current mode information from the UGA Draw Protocol\r
+    //\r
+    UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r
+  }\r
+\r
+  LineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_WIDTH * GLYPH_HEIGHT);\r
+  if (LineBuffer == NULL) {\r
+    gBS->FreePool (Buffer);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, (VOID **) &Hii);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r
+\r
+  UnicodeWeight = (CHAR16 *) Buffer;\r
+\r
+  for (Index = 0; UnicodeWeight[Index] != 0; Index++) {\r
+    if (UnicodeWeight[Index] == CHAR_BACKSPACE ||\r
+        UnicodeWeight[Index] == CHAR_LINEFEED  ||\r
+        UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) {\r
+      UnicodeWeight[Index] = 0;\r
+    }\r
+  }\r
+\r
+  for (Index = 0; Index < StrLen (Buffer); Index++) {\r
+    StringIndex = (UINT16) Index;\r
+    Status      = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);\r
+    if (EFI_ERROR (Status)) {\r
+      goto Error;\r
+    }\r
+\r
+    if (Foreground == NULL || Background == NULL) {\r
+      Status = Hii->GlyphToBlt (\r
+                      Hii,\r
+                      (UINT8 *) Glyph,\r
+                      mEfiColors[Sto->Mode->Attribute & 0x0f],\r
+                      mEfiColors[Sto->Mode->Attribute >> 4],\r
+                      StrLen (Buffer),\r
+                      GlyphWidth,\r
+                      GLYPH_HEIGHT,\r
+                      &LineBuffer[Index * GLYPH_WIDTH]\r
+                      );\r
+    } else {\r
+      Status = Hii->GlyphToBlt (\r
+                      Hii,\r
+                      (UINT8 *) Glyph,\r
+                      *Foreground,\r
+                      *Background,\r
+                      StrLen (Buffer),\r
+                      GlyphWidth,\r
+                      GLYPH_HEIGHT,\r
+                      &LineBuffer[Index * GLYPH_WIDTH]\r
+                      );\r
+    }\r
+  }\r
+\r
+  //\r
+  // Blt a character to the screen\r
+  //\r
+  BufferGlyphWidth = GLYPH_WIDTH * StrLen (Buffer);\r
+  if (GraphicsOutput != NULL) {\r
+    Status = GraphicsOutput->Blt (\r
+                        GraphicsOutput,\r
+                        LineBuffer,\r
+                        EfiBltBufferToVideo,\r
+                        0,\r
+                        0,\r
+                        X,\r
+                        Y,\r
+                        BufferGlyphWidth,\r
+                        GLYPH_HEIGHT,\r
+                        BufferGlyphWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                        );\r
+  } else {\r
+    Status = UgaDraw->Blt (\r
+                        UgaDraw,\r
+                        (EFI_UGA_PIXEL *) (UINTN) LineBuffer,\r
+                        EfiUgaBltBufferToVideo,\r
+                        0,\r
+                        0,\r
+                        X,\r
+                        Y,\r
+                        BufferGlyphWidth,\r
+                        GLYPH_HEIGHT,\r
+                        BufferGlyphWidth * sizeof (EFI_UGA_PIXEL)\r
+                        );\r
+  }\r
+\r
+Error:\r
+  gBS->FreePool (LineBuffer);\r
+  gBS->FreePool (Buffer);\r
+  return Status;\r
+}\r
+\r
+\r
+UINTN\r
+PrintXY (\r
+  IN UINTN                            X,\r
+  IN UINTN                            Y,\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *ForeGround, OPTIONAL\r
+  IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL    *BackGround, OPTIONAL\r
+  IN CHAR16                           *Fmt,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+    Prints a formatted unicode string to the default console\r
+\r
+Arguments:\r
+\r
+    X           - X coordinate to start printing\r
+    \r
+    Y           - Y coordinate to start printing\r
+    \r
+    ForeGround  - Foreground color\r
+    \r
+    BackGround  - Background color\r
+\r
+    Fmt         - Format string\r
+\r
+    ...         - Print arguments\r
+\r
+Returns:\r
+\r
+    Length of string printed to the console\r
+\r
+--*/\r
+{\r
+  EFI_HANDLE                    Handle;\r
+\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
+\r
+  VA_START (Args, Fmt);\r
+\r
+  UgaDraw = NULL;\r
+\r
+  Handle = gST->ConsoleOutHandle;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  (VOID **) &GraphicsOutput\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    GraphicsOutput = NULL;\r
+\r
+    Status = gBS->HandleProtocol (\r
+                    Handle,\r
+                    &gEfiUgaDrawProtocolGuid,\r
+                    (VOID **) &UgaDraw\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  (VOID **) &Sto\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
+}\r
diff --git a/IntelFrameworkModulePkg/Library/GraphicsLib/GraphicsLib.inf b/IntelFrameworkModulePkg/Library/GraphicsLib/GraphicsLib.inf
new file mode 100644 (file)
index 0000000..0afd451
--- /dev/null
@@ -0,0 +1,92 @@
+#/** @file\r
+# Graphics Library for UEFI drivers\r
+#\r
+# This library provides supports for basic graphic functions.\r
+# Copyright (c) 2006 - 2007, Intel Corporation.\r
+#\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
+#  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
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = EdkGraphicsLib\r
+  FILE_GUID                      = 08c1a0e4-1208-47f8-a2c5-f42eabee653a\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = EdkGraphicsLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  Graphics.c\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseLib\r
+  PrintLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiHiiProtocolGuid                           # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiSimpleTextOutProtocolGuid                 # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiGraphicsOutputProtocolGuid                # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiUgaDrawProtocolGuid                       # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiConsoleControlProtocolGuid                # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiFirmwareVolumeProtocolGuid                # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiOEMBadgingProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/IntelFrameworkModulePkg/Library/GraphicsLib/GraphicsLib.msa b/IntelFrameworkModulePkg/Library/GraphicsLib/GraphicsLib.msa
new file mode 100644 (file)
index 0000000..7bab912
--- /dev/null
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>EdkGraphicsLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>08c1a0e4-1208-47f8-a2c5-f42eabee653a</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Graphics Library for UEFI drivers</Abstract>\r
+    <Description>This library provides supports for basic graphic functions.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials
+      are licensed and made available under the terms and conditions of the BSD License
+      which accompanies this distribution.  The full text of the license may be found at
+      http://opensource.org/licenses/bsd-license.php
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>EdkGraphicsLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>EdkGraphicsLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Graphics.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiOEMBadgingProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiFirmwareVolumeProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiConsoleControlProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiUgaDrawProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiGraphicsOutputProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiSimpleTextOutProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file