2 Example program using BltLib
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BltLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/UefiLib.h>
13 #include <Library/UefiApplicationEntryPoint.h>
14 #include <Library/UefiBootServicesTableLib.h>
22 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
25 #error ReadTimestamp not supported for this architecture!
43 Tsc1
= ReadTimestamp ();
44 Tsc2
= ReadTimestamp ();
46 Tsc2
= ReadTimestamp ();
47 TscBits
= Tsc2
^ Tsc1
;
48 Bits
= HighBitSet64 (TscBits
);
52 R32
= (UINT32
)((R32
<< Bits
) |
53 RShiftU64 (LShiftU64 (TscBits
, (UINTN
) (64 - Bits
)), (UINTN
) (64 - Bits
)));
66 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
75 BltLibGetSizes (&Width
, &Height
);
76 for (Loop
= 0; Loop
< 10000; Loop
++) {
77 W
= Width
- (Rand32 () % Width
);
78 H
= Height
- (Rand32 () % Height
);
80 X
= Rand32 () % (Width
- W
);
85 Y
= Rand32 () % (Height
- H
);
89 *(UINT32
*) (&Color
) = Rand32 () & 0xffffff;
90 BltLibVideoFill (&Color
, X
, Y
, W
, H
);
100 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
106 BltLibGetSizes (&Width
, &Height
);
107 *(UINT32
*) (&Color
) = 0;
109 for (Y
= 0; Y
< Height
; Y
++) {
110 for (X
= 0; X
< Width
; X
++) {
111 Color
.Red
= (UINT8
) ((X
* 0x100) / Width
);
112 Color
.Green
= (UINT8
) ((Y
* 0x100) / Height
);
113 Color
.Blue
= (UINT8
) ((Y
* 0x100) / Height
);
114 BltLibVideoFill (&Color
, X
, Y
, 1, 1);
134 for (SqRt
= 0, Mask
= (UINT32
) (1 << (HighBitSet32 (Uint32
) / 2));
138 SqRtMask
= SqRt
| Mask
;
139 //DEBUG ((EFI_D_INFO, "Uint32=0x%x SqRtMask=0x%x\n", Uint32, SqRtMask));
140 Squared
= (UINT32
) (SqRtMask
* SqRtMask
);
141 if (Squared
> Uint32
) {
143 } else if (Squared
< Uint32
) {
160 return Uint32SqRt ((UINT32
) ((X
* X
) + (Y
* Y
)));
169 return (UINT8
) (((TriWidth
- ColorDist
) * 0x100) / TriWidth
);
170 //return (((TriWidth * TriWidth - ColorDist * ColorDist) * 0x100) / (TriWidth * TriWidth));
178 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
182 UINTN LineWidth
, TriWidth
, ScreenWidth
;
183 UINTN TriHeight
, ScreenHeight
;
186 BltLibGetSizes (&ScreenWidth
, &ScreenHeight
);
187 *(UINT32
*) (&Color
) = 0;
188 BltLibVideoFill (&Color
, 0, 0, ScreenWidth
, ScreenHeight
);
190 TriWidth
= (UINTN
) DivU64x32 (
191 MultU64x32 (11547005, (UINT32
) ScreenHeight
),
194 TriHeight
= (UINTN
) DivU64x32 (
195 MultU64x32 (8660254, (UINT32
) ScreenWidth
),
198 if (TriWidth
> ScreenWidth
) {
199 DEBUG ((EFI_D_INFO
, "TriWidth at %d was too big\n", TriWidth
));
200 TriWidth
= ScreenWidth
;
201 } else if (TriHeight
> ScreenHeight
) {
202 DEBUG ((EFI_D_INFO
, "TriHeight at %d was too big\n", TriHeight
));
203 TriHeight
= ScreenHeight
;
206 DEBUG ((EFI_D_INFO
, "Triangle Width: %d; Height: %d\n", TriWidth
, TriHeight
));
208 X1
= (ScreenWidth
- TriWidth
) / 2;
209 X3
= X1
+ TriWidth
- 1;
211 Y2
= (ScreenHeight
- TriHeight
) / 2;
212 Y1
= Y2
+ TriHeight
- 1;
214 for (Y
= Y2
; Y
<= Y1
; Y
++) {
217 MultU64x32 (11547005, (UINT32
) (Y
- Y2
)),
220 for (X
= X2
- LineWidth
; X
< (X2
+ LineWidth
); X
++) {
221 ColorDist
= Uint32Dist(X
- X1
, Y1
- Y
);
222 Color
.Red
= GetTriColor (ColorDist
, TriWidth
);
224 ColorDist
= Uint32Dist((X
< X2
) ? X2
- X
: X
- X2
, Y
- Y2
);
225 Color
.Green
= GetTriColor (ColorDist
, TriWidth
);
227 ColorDist
= Uint32Dist(X3
- X
, Y1
- Y
);
228 Color
.Blue
= GetTriColor (ColorDist
, TriWidth
);
230 BltLibVideoFill (&Color
, X
, Y
, 1, 1);
237 The user Entry Point for Application. The user code starts with this function
238 as the real entry point for the application.
240 @param[in] ImageHandle The firmware allocated handle for the EFI image.
241 @param[in] SystemTable A pointer to the EFI System Table.
243 @retval EFI_SUCCESS The entry point is executed successfully.
244 @retval other Some error occurs when executing this entry point.
250 IN EFI_HANDLE ImageHandle
,
251 IN EFI_SYSTEM_TABLE
*SystemTable
255 EFI_GRAPHICS_OUTPUT_PROTOCOL
*Gop
;
257 Status
= gBS
->HandleProtocol (
258 gST
->ConsoleOutHandle
,
259 &gEfiGraphicsOutputProtocolGuid
,
262 if (EFI_ERROR (Status
)) {
266 Status
= BltLibConfigure (
267 (VOID
*)(UINTN
) Gop
->Mode
->FrameBufferBase
,
270 if (EFI_ERROR (Status
)) {