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