--- /dev/null
+/** @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