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>
41 TscBits
= Tsc2
^ Tsc1
;
42 Bits
= HighBitSet64 (TscBits
);
46 R32
= (UINT32
)((R32
<< Bits
) |
47 RShiftU64 (LShiftU64 (TscBits
, 64 - Bits
), 64 - Bits
));
60 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
69 BltLibGetSizes (&Width
, &Height
);
70 for (Loop
= 0; Loop
< 10000; Loop
++) {
71 W
= Width
- (Rand32 () % Width
);
72 H
= Height
- (Rand32 () % Height
);
74 X
= Rand32 () % (Width
- W
);
79 Y
= Rand32 () % (Height
- H
);
83 *(UINT32
*) (&Color
) = Rand32 () & 0xffffff;
84 BltLibVideoFill (&Color
, X
, Y
, W
, H
);
94 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
100 BltLibGetSizes (&Width
, &Height
);
101 *(UINT32
*) (&Color
) = 0;
103 for (Y
= 0; Y
< Height
; Y
++) {
104 for (X
= 0; X
< Width
; X
++) {
105 Color
.Red
= (UINT8
) ((X
* 0x100) / Width
);
106 Color
.Green
= (UINT8
) ((Y
* 0x100) / Height
);
107 Color
.Blue
= (UINT8
) ((Y
* 0x100) / Height
);
108 BltLibVideoFill (&Color
, X
, Y
, 1, 1);
128 for (SqRt
= 0, Mask
= (UINT32
) (1 << (HighBitSet32 (Uint32
) / 2));
132 SqRtMask
= SqRt
| Mask
;
133 //DEBUG ((EFI_D_INFO, "Uint32=0x%x SqRtMask=0x%x\n", Uint32, SqRtMask));
134 Squared
= (UINT32
) (SqRtMask
* SqRtMask
);
135 if (Squared
> Uint32
) {
137 } else if (Squared
< Uint32
) {
154 return Uint32SqRt ((UINT32
) ((X
* X
) + (Y
* Y
)));
163 return (UINT8
) (((TriWidth
- ColorDist
) * 0x100) / TriWidth
);
164 //return (((TriWidth * TriWidth - ColorDist * ColorDist) * 0x100) / (TriWidth * TriWidth));
172 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
176 UINTN LineWidth
, TriWidth
, ScreenWidth
;
177 UINTN TriHeight
, ScreenHeight
;
180 BltLibGetSizes (&ScreenWidth
, &ScreenHeight
);
181 *(UINT32
*) (&Color
) = 0;
182 BltLibVideoFill (&Color
, 0, 0, ScreenWidth
, ScreenHeight
);
184 TriWidth
= (UINTN
) DivU64x32 (
185 MultU64x32 (11547005, (UINT32
) ScreenHeight
),
188 TriHeight
= (UINTN
) DivU64x32 (
189 MultU64x32 (8660254, (UINT32
) ScreenWidth
),
192 if (TriWidth
> ScreenWidth
) {
193 DEBUG ((EFI_D_INFO
, "TriWidth at %d was too big\n", TriWidth
));
194 TriWidth
= ScreenWidth
;
195 } else if (TriHeight
> ScreenHeight
) {
196 DEBUG ((EFI_D_INFO
, "TriHeight at %d was too big\n", TriHeight
));
197 TriHeight
= ScreenHeight
;
200 DEBUG ((EFI_D_INFO
, "Triangle Width: %d; Height: %d\n", TriWidth
, TriHeight
));
202 X1
= (ScreenWidth
- TriWidth
) / 2;
203 X3
= X1
+ TriWidth
- 1;
205 Y2
= (ScreenHeight
- TriHeight
) / 2;
206 Y1
= Y2
+ TriHeight
- 1;
208 for (Y
= Y2
; Y
<= Y1
; Y
++) {
211 MultU64x32 (11547005, (UINT32
) (Y
- Y2
)),
214 for (X
= X2
- LineWidth
; X
< (X2
+ LineWidth
); X
++) {
215 ColorDist
= Uint32Dist(X
- X1
, Y1
- Y
);
216 Color
.Red
= GetTriColor (ColorDist
, TriWidth
);
218 ColorDist
= Uint32Dist((X
< X2
) ? X2
- X
: X
- X2
, Y
- Y2
);
219 Color
.Green
= GetTriColor (ColorDist
, TriWidth
);
221 ColorDist
= Uint32Dist(X3
- X
, Y1
- Y
);
222 Color
.Blue
= GetTriColor (ColorDist
, TriWidth
);
224 BltLibVideoFill (&Color
, X
, Y
, 1, 1);
231 The user Entry Point for Application. The user code starts with this function
232 as the real entry point for the application.
234 @param[in] ImageHandle The firmware allocated handle for the EFI image.
235 @param[in] SystemTable A pointer to the EFI System Table.
237 @retval EFI_SUCCESS The entry point is executed successfully.
238 @retval other Some error occurs when executing this entry point.
244 IN EFI_HANDLE ImageHandle
,
245 IN EFI_SYSTEM_TABLE
*SystemTable
249 EFI_GRAPHICS_OUTPUT_PROTOCOL
*Gop
;
251 Status
= gBS
->HandleProtocol (
252 gST
->ConsoleOutHandle
,
253 &gEfiGraphicsOutputProtocolGuid
,
256 if (EFI_ERROR (Status
)) {
260 Status
= BltLibConfigure (
261 (VOID
*)(UINTN
) Gop
->Mode
->FrameBufferBase
,
264 if (EFI_ERROR (Status
)) {