]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OptionRomPkg BltLibSample: Add sample application for BltLib
authorjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 12 Apr 2011 15:08:26 +0000 (15:08 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 12 Apr 2011 15:08:26 +0000 (15:08 +0000)
This application uses BltLib to draw various items on the
screen.  It can be used as a test for a BltLib library
implementation, and it can be used to compare the results of
two BltLib implementations (such as the performance).

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11523 6f19259b-4bc3-4df7-8a09-765794883524

OptionRomPkg/Application/BltLibSample/BltLibSample.c [new file with mode: 0644]
OptionRomPkg/Application/BltLibSample/BltLibSample.inf [new file with mode: 0644]
OptionRomPkg/OptionRomPkg.dsc

diff --git a/OptionRomPkg/Application/BltLibSample/BltLibSample.c b/OptionRomPkg/Application/BltLibSample/BltLibSample.c
new file mode 100644 (file)
index 0000000..2471813
--- /dev/null
@@ -0,0 +1,266 @@
+/** @file\r
+  Example program using BltLib\r
+\r
+  Copyright (c) 2006 - 2011, 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
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Library/BltLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiApplicationEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+\r
+UINT32\r
+Rand32 (\r
+  VOID\r
+  )\r
+{\r
+  UINTN    Found;\r
+  UINTN    Bits;\r
+  UINT64   Tsc1;\r
+  UINT64   Tsc2;\r
+  UINT64   TscBits;\r
+  UINT32   R32;\r
+\r
+  R32 = 0;\r
+  Found = 0;\r
+  Tsc1 = AsmReadTsc ();\r
+  Tsc2 = AsmReadTsc ();\r
+  do {\r
+    Tsc2 = AsmReadTsc ();\r
+    TscBits = Tsc2 ^ Tsc1;\r
+    Bits = HighBitSet64 (TscBits);\r
+    if (Bits > 0) {\r
+      Bits = Bits - 1;\r
+    }\r
+    R32 = (R32 << Bits) | RShiftU64 (LShiftU64 (TscBits, 64 - Bits), 64 - Bits);\r
+    Found = Found + Bits;\r
+  } while (Found < 32);\r
+\r
+  return R32;\r
+}\r
+\r
+\r
+VOID\r
+TestFills (\r
+  VOID\r
+  )\r
+{\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Color;\r
+  UINTN                          Loop;\r
+  UINTN                          X;\r
+  UINTN                          Y;\r
+  UINTN                          W;\r
+  UINTN                          H;\r
+  UINTN                          Width;\r
+  UINTN                          Height;\r
+\r
+  BltLibGetSizes (&Width, &Height);\r
+  for (Loop = 0; Loop < 10000; Loop++) {\r
+    W = Width - (Rand32 () % Width);\r
+    H = Height - (Rand32 () % Height);\r
+    if (W != Width) {\r
+      X = Rand32 () % (Width - W);\r
+    } else {\r
+      X = 0;\r
+    }\r
+    if (H != Height) {\r
+      Y = Rand32 () % (Height - H);\r
+    } else {\r
+      Y = 0;\r
+    }\r
+    *(UINT32*) (&Color) = Rand32 () & 0xffffff;\r
+    BltLibVideoFill (&Color, X, Y, W, H);\r
+  }\r
+}\r
+\r
+\r
+VOID\r
+TestColor1 (\r
+  VOID\r
+  )\r
+{\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Color;\r
+  UINTN                          X;\r
+  UINTN                          Y;\r
+  UINTN                          Width;\r
+  UINTN                          Height;\r
+\r
+  BltLibGetSizes (&Width, &Height);\r
+  *(UINT32*) (&Color) = 0;\r
+\r
+  for (Y = 0; Y < Height; Y++) {\r
+    for (X = 0; X < Width; X++) {\r
+      Color.Red = ((X * 0x100) / Width);\r
+      Color.Green = ((Y * 0x100) / Height);\r
+      Color.Blue = ((Y * 0x100) / Height);\r
+      BltLibVideoFill (&Color, X, Y, 1, 1);\r
+    }\r
+  }\r
+}\r
+\r
+\r
+UINT32\r
+Uint32SqRt (\r
+  IN  UINT32  Uint32\r
+  )\r
+{\r
+  UINTN  Mask;\r
+  UINT32 SqRt;\r
+  UINT32 SqRtMask;\r
+  UINT32 Squared;\r
+\r
+  if (Uint32 == 0) {\r
+    return 0;\r
+  }\r
+\r
+  for (SqRt = 0, Mask = 1 << (HighBitSet32 (Uint32) / 2);\r
+       Mask != 0;\r
+       Mask = Mask >> 1\r
+      ) {\r
+    SqRtMask = SqRt | Mask;\r
+    //DEBUG ((EFI_D_INFO, "Uint32=0x%x SqRtMask=0x%x\n", Uint32, SqRtMask));\r
+    Squared = (UINT32) (SqRtMask * SqRtMask);\r
+    if (Squared > Uint32) {\r
+      continue;\r
+    } else if (Squared < Uint32) {\r
+      SqRt = SqRtMask;\r
+    } else {\r
+      return SqRtMask;\r
+    }\r
+  }\r
+\r
+  return SqRt;\r
+}\r
+\r
+\r
+UINT32\r
+Uint32Dist (\r
+  IN UINT32 X,\r
+  IN UINT32 Y\r
+  )\r
+{\r
+  return Uint32SqRt ((X * X) + (Y * Y));\r
+}\r
+\r
+UINT32\r
+GetTriColor (\r
+  IN UINT32 ColorDist,\r
+  IN UINT32 TriWidth\r
+  )\r
+{\r
+  return (((TriWidth - ColorDist) * 0x100) / TriWidth);\r
+  //return (((TriWidth * TriWidth - ColorDist * ColorDist) * 0x100) / (TriWidth * TriWidth));\r
+}\r
+\r
+VOID\r
+TestColor (\r
+  VOID\r
+  )\r
+{\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  Color;\r
+  UINTN                          X, Y;\r
+  UINTN                          X1, X2, X3;\r
+  UINTN                          Y1, Y2;\r
+  UINTN                          LineWidth, TriWidth, ScreenWidth;\r
+  UINTN                          TriHeight, ScreenHeight;\r
+  UINTN                          ColorDist;\r
+\r
+  BltLibGetSizes (&ScreenWidth, &ScreenHeight);\r
+  *(UINT32*) (&Color) = 0;\r
+  BltLibVideoFill (&Color, 0, 0, ScreenWidth, ScreenHeight);\r
+\r
+  TriWidth = DivU64x32 (MultU64x32 (11547005, ScreenHeight), 10000000);\r
+  TriHeight = DivU64x32 (MultU64x32 (8660254, ScreenWidth), 10000000);\r
+  if (TriWidth > ScreenWidth) {\r
+    DEBUG ((EFI_D_INFO, "TriWidth at %d was too big\n", TriWidth));\r
+    TriWidth = ScreenWidth;\r
+  } else if (TriHeight > ScreenHeight) {\r
+    DEBUG ((EFI_D_INFO, "TriHeight at %d was too big\n", TriHeight));\r
+    TriHeight = ScreenHeight;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "Triangle Width: %d; Height: %d\n", TriWidth, TriHeight));\r
+\r
+  X1 = (ScreenWidth - TriWidth) / 2;\r
+  X3 = X1 + TriWidth - 1;\r
+  X2 = (X1 + X3) / 2;\r
+  Y2 = (ScreenHeight - TriHeight) / 2;\r
+  Y1 = Y2 + TriHeight - 1;\r
+\r
+  for (Y = Y2; Y <= Y1; Y++) {\r
+    LineWidth =\r
+      DivU64x32 (\r
+        MultU64x32 (11547005, (Y - Y2)),\r
+        20000000\r
+        );\r
+    for (X = X2 - LineWidth; X < (X2 + LineWidth); X++) {\r
+      ColorDist = Uint32Dist(X - X1, Y1 - Y);\r
+      Color.Red = GetTriColor (ColorDist, TriWidth);\r
+\r
+      ColorDist = Uint32Dist((X < X2) ? X2 - X : X - X2, Y - Y2);\r
+      Color.Green = GetTriColor (ColorDist, TriWidth);\r
+\r
+      ColorDist = Uint32Dist(X3 - X, Y1 - Y);\r
+      Color.Blue = GetTriColor (ColorDist, TriWidth);\r
+\r
+      BltLibVideoFill (&Color, X, Y, 1, 1);\r
+    }\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  The user Entry Point for Application. The user code starts with this function\r
+  as the real entry point for the application.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UefiMain (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                     Status;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL   *Gop;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  gST->ConsoleOutHandle,\r
+                  &gEfiGraphicsOutputProtocolGuid,\r
+                  (VOID **) &Gop\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = BltLibConfigure (\r
+             (VOID*)(UINTN) Gop->Mode->FrameBufferBase,\r
+             Gop->Mode->Info\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  TestFills ();\r
+\r
+  TestColor ();\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/OptionRomPkg/Application/BltLibSample/BltLibSample.inf b/OptionRomPkg/Application/BltLibSample/BltLibSample.inf
new file mode 100644 (file)
index 0000000..a1334f8
--- /dev/null
@@ -0,0 +1,35 @@
+## @file\r
+#  Test the BltLib interface\r
+#\r
+#  Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r
+#\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
+#  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
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = BltLibSample\r
+  FILE_GUID                      = f7763316-8c04-41d8-a87d-45b73c13c43c\r
+  MODULE_TYPE                    = UEFI_APPLICATION\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = UefiMain\r
+\r
+[Sources]\r
+  BltLibSample.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  OptionRomPkg/OptionRomPkg.dec\r
+\r
+[LibraryClasses]\r
+  BltLib\r
+  UefiApplicationEntryPoint\r
+  UefiLib\r
+\r
index a6a4047ca074207447f3418f579de907798418fa..522038f2808e33129b347141ada70a2f6e4ae0c4 100644 (file)
@@ -47,6 +47,7 @@
   DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf  \r
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  BltLib|OptionRomPkg/Library/GopBltLib/GopBltLib.inf\r
   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
   TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
   UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
@@ -56,6 +57,7 @@
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf\r
   DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf\r
 \r
 ################################################################################\r
   OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf\r
   OptionRomPkg/Library/GopBltLib/GopBltLib.inf\r
 \r
+  OptionRomPkg/Application/BltLibSample/BltLibSample.inf\r
+\r
   OptionRomPkg/AtapiPassThruDxe/AtapiPassThruDxe.inf\r
   OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430Dxe.inf\r
   OptionRomPkg/UndiRuntimeDxe/UndiRuntimeDxe.inf\r