2 Example program using BltLib
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BltLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiLib.h>
19 #include <Library/UefiApplicationEntryPoint.h>
20 #include <Library/UefiBootServicesTableLib.h>
28 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
31 #error ReadTimestamp not supported for this architecture!
49 Tsc1
= ReadTimestamp ();
50 Tsc2
= ReadTimestamp ();
52 Tsc2
= ReadTimestamp ();
53 TscBits
= Tsc2
^ Tsc1
;
54 Bits
= HighBitSet64 (TscBits
);
58 R32
= (UINT32
)((R32
<< Bits
) |
59 RShiftU64 (LShiftU64 (TscBits
, (UINTN
) (64 - Bits
)), (UINTN
) (64 - Bits
)));
72 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
81 BltLibGetSizes (&Width
, &Height
);
82 for (Loop
= 0; Loop
< 10000; Loop
++) {
83 W
= Width
- (Rand32 () % Width
);
84 H
= Height
- (Rand32 () % Height
);
86 X
= Rand32 () % (Width
- W
);
91 Y
= Rand32 () % (Height
- H
);
95 *(UINT32
*) (&Color
) = Rand32 () & 0xffffff;
96 BltLibVideoFill (&Color
, X
, Y
, W
, H
);
106 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
112 BltLibGetSizes (&Width
, &Height
);
113 *(UINT32
*) (&Color
) = 0;
115 for (Y
= 0; Y
< Height
; Y
++) {
116 for (X
= 0; X
< Width
; X
++) {
117 Color
.Red
= (UINT8
) ((X
* 0x100) / Width
);
118 Color
.Green
= (UINT8
) ((Y
* 0x100) / Height
);
119 Color
.Blue
= (UINT8
) ((Y
* 0x100) / Height
);
120 BltLibVideoFill (&Color
, X
, Y
, 1, 1);
140 for (SqRt
= 0, Mask
= (UINT32
) (1 << (HighBitSet32 (Uint32
) / 2));
144 SqRtMask
= SqRt
| Mask
;
145 //DEBUG ((EFI_D_INFO, "Uint32=0x%x SqRtMask=0x%x\n", Uint32, SqRtMask));
146 Squared
= (UINT32
) (SqRtMask
* SqRtMask
);
147 if (Squared
> Uint32
) {
149 } else if (Squared
< Uint32
) {
166 return Uint32SqRt ((UINT32
) ((X
* X
) + (Y
* Y
)));
175 return (UINT8
) (((TriWidth
- ColorDist
) * 0x100) / TriWidth
);
176 //return (((TriWidth * TriWidth - ColorDist * ColorDist) * 0x100) / (TriWidth * TriWidth));
184 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
188 UINTN LineWidth
, TriWidth
, ScreenWidth
;
189 UINTN TriHeight
, ScreenHeight
;
192 BltLibGetSizes (&ScreenWidth
, &ScreenHeight
);
193 *(UINT32
*) (&Color
) = 0;
194 BltLibVideoFill (&Color
, 0, 0, ScreenWidth
, ScreenHeight
);
196 TriWidth
= (UINTN
) DivU64x32 (
197 MultU64x32 (11547005, (UINT32
) ScreenHeight
),
200 TriHeight
= (UINTN
) DivU64x32 (
201 MultU64x32 (8660254, (UINT32
) ScreenWidth
),
204 if (TriWidth
> ScreenWidth
) {
205 DEBUG ((EFI_D_INFO
, "TriWidth at %d was too big\n", TriWidth
));
206 TriWidth
= ScreenWidth
;
207 } else if (TriHeight
> ScreenHeight
) {
208 DEBUG ((EFI_D_INFO
, "TriHeight at %d was too big\n", TriHeight
));
209 TriHeight
= ScreenHeight
;
212 DEBUG ((EFI_D_INFO
, "Triangle Width: %d; Height: %d\n", TriWidth
, TriHeight
));
214 X1
= (ScreenWidth
- TriWidth
) / 2;
215 X3
= X1
+ TriWidth
- 1;
217 Y2
= (ScreenHeight
- TriHeight
) / 2;
218 Y1
= Y2
+ TriHeight
- 1;
220 for (Y
= Y2
; Y
<= Y1
; Y
++) {
223 MultU64x32 (11547005, (UINT32
) (Y
- Y2
)),
226 for (X
= X2
- LineWidth
; X
< (X2
+ LineWidth
); X
++) {
227 ColorDist
= Uint32Dist(X
- X1
, Y1
- Y
);
228 Color
.Red
= GetTriColor (ColorDist
, TriWidth
);
230 ColorDist
= Uint32Dist((X
< X2
) ? X2
- X
: X
- X2
, Y
- Y2
);
231 Color
.Green
= GetTriColor (ColorDist
, TriWidth
);
233 ColorDist
= Uint32Dist(X3
- X
, Y1
- Y
);
234 Color
.Blue
= GetTriColor (ColorDist
, TriWidth
);
236 BltLibVideoFill (&Color
, X
, Y
, 1, 1);
243 The user Entry Point for Application. The user code starts with this function
244 as the real entry point for the application.
246 @param[in] ImageHandle The firmware allocated handle for the EFI image.
247 @param[in] SystemTable A pointer to the EFI System Table.
249 @retval EFI_SUCCESS The entry point is executed successfully.
250 @retval other Some error occurs when executing this entry point.
256 IN EFI_HANDLE ImageHandle
,
257 IN EFI_SYSTEM_TABLE
*SystemTable
261 EFI_GRAPHICS_OUTPUT_PROTOCOL
*Gop
;
263 Status
= gBS
->HandleProtocol (
264 gST
->ConsoleOutHandle
,
265 &gEfiGraphicsOutputProtocolGuid
,
268 if (EFI_ERROR (Status
)) {
272 Status
= BltLibConfigure (
273 (VOID
*)(UINTN
) Gop
->Mode
->FrameBufferBase
,
276 if (EFI_ERROR (Status
)) {