2 Example program using BltLib
4 Copyright (c) 2006 - 2011, 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)
30 #elif defined (MDE_CPU_IPF)
33 #error ReadTimestamp not supported for this architecture!
51 Tsc1
= ReadTimestamp ();
52 Tsc2
= ReadTimestamp ();
54 Tsc2
= ReadTimestamp ();
55 TscBits
= Tsc2
^ Tsc1
;
56 Bits
= HighBitSet64 (TscBits
);
60 R32
= (UINT32
)((R32
<< Bits
) |
61 RShiftU64 (LShiftU64 (TscBits
, (UINTN
) (64 - Bits
)), (UINTN
) (64 - Bits
)));
74 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
83 BltLibGetSizes (&Width
, &Height
);
84 for (Loop
= 0; Loop
< 10000; Loop
++) {
85 W
= Width
- (Rand32 () % Width
);
86 H
= Height
- (Rand32 () % Height
);
88 X
= Rand32 () % (Width
- W
);
93 Y
= Rand32 () % (Height
- H
);
97 *(UINT32
*) (&Color
) = Rand32 () & 0xffffff;
98 BltLibVideoFill (&Color
, X
, Y
, W
, H
);
108 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
114 BltLibGetSizes (&Width
, &Height
);
115 *(UINT32
*) (&Color
) = 0;
117 for (Y
= 0; Y
< Height
; Y
++) {
118 for (X
= 0; X
< Width
; X
++) {
119 Color
.Red
= (UINT8
) ((X
* 0x100) / Width
);
120 Color
.Green
= (UINT8
) ((Y
* 0x100) / Height
);
121 Color
.Blue
= (UINT8
) ((Y
* 0x100) / Height
);
122 BltLibVideoFill (&Color
, X
, Y
, 1, 1);
142 for (SqRt
= 0, Mask
= (UINT32
) (1 << (HighBitSet32 (Uint32
) / 2));
146 SqRtMask
= SqRt
| Mask
;
147 //DEBUG ((EFI_D_INFO, "Uint32=0x%x SqRtMask=0x%x\n", Uint32, SqRtMask));
148 Squared
= (UINT32
) (SqRtMask
* SqRtMask
);
149 if (Squared
> Uint32
) {
151 } else if (Squared
< Uint32
) {
168 return Uint32SqRt ((UINT32
) ((X
* X
) + (Y
* Y
)));
177 return (UINT8
) (((TriWidth
- ColorDist
) * 0x100) / TriWidth
);
178 //return (((TriWidth * TriWidth - ColorDist * ColorDist) * 0x100) / (TriWidth * TriWidth));
186 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
190 UINTN LineWidth
, TriWidth
, ScreenWidth
;
191 UINTN TriHeight
, ScreenHeight
;
194 BltLibGetSizes (&ScreenWidth
, &ScreenHeight
);
195 *(UINT32
*) (&Color
) = 0;
196 BltLibVideoFill (&Color
, 0, 0, ScreenWidth
, ScreenHeight
);
198 TriWidth
= (UINTN
) DivU64x32 (
199 MultU64x32 (11547005, (UINT32
) ScreenHeight
),
202 TriHeight
= (UINTN
) DivU64x32 (
203 MultU64x32 (8660254, (UINT32
) ScreenWidth
),
206 if (TriWidth
> ScreenWidth
) {
207 DEBUG ((EFI_D_INFO
, "TriWidth at %d was too big\n", TriWidth
));
208 TriWidth
= ScreenWidth
;
209 } else if (TriHeight
> ScreenHeight
) {
210 DEBUG ((EFI_D_INFO
, "TriHeight at %d was too big\n", TriHeight
));
211 TriHeight
= ScreenHeight
;
214 DEBUG ((EFI_D_INFO
, "Triangle Width: %d; Height: %d\n", TriWidth
, TriHeight
));
216 X1
= (ScreenWidth
- TriWidth
) / 2;
217 X3
= X1
+ TriWidth
- 1;
219 Y2
= (ScreenHeight
- TriHeight
) / 2;
220 Y1
= Y2
+ TriHeight
- 1;
222 for (Y
= Y2
; Y
<= Y1
; Y
++) {
225 MultU64x32 (11547005, (UINT32
) (Y
- Y2
)),
228 for (X
= X2
- LineWidth
; X
< (X2
+ LineWidth
); X
++) {
229 ColorDist
= Uint32Dist(X
- X1
, Y1
- Y
);
230 Color
.Red
= GetTriColor (ColorDist
, TriWidth
);
232 ColorDist
= Uint32Dist((X
< X2
) ? X2
- X
: X
- X2
, Y
- Y2
);
233 Color
.Green
= GetTriColor (ColorDist
, TriWidth
);
235 ColorDist
= Uint32Dist(X3
- X
, Y1
- Y
);
236 Color
.Blue
= GetTriColor (ColorDist
, TriWidth
);
238 BltLibVideoFill (&Color
, X
, Y
, 1, 1);
245 The user Entry Point for Application. The user code starts with this function
246 as the real entry point for the application.
248 @param[in] ImageHandle The firmware allocated handle for the EFI image.
249 @param[in] SystemTable A pointer to the EFI System Table.
251 @retval EFI_SUCCESS The entry point is executed successfully.
252 @retval other Some error occurs when executing this entry point.
258 IN EFI_HANDLE ImageHandle
,
259 IN EFI_SYSTEM_TABLE
*SystemTable
263 EFI_GRAPHICS_OUTPUT_PROTOCOL
*Gop
;
265 Status
= gBS
->HandleProtocol (
266 gST
->ConsoleOutHandle
,
267 &gEfiGraphicsOutputProtocolGuid
,
270 if (EFI_ERROR (Status
)) {
274 Status
= BltLibConfigure (
275 (VOID
*)(UINTN
) Gop
->Mode
->FrameBufferBase
,
278 if (EFI_ERROR (Status
)) {