]>
Commit | Line | Data |
---|---|---|
a12199e6 | 1 | /** @file\r |
2 | Example program using BltLib\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include <Uefi.h>\r | |
16 | #include <Library/BltLib.h>\r | |
17 | #include <Library/DebugLib.h>\r | |
18 | #include <Library/UefiLib.h>\r | |
19 | #include <Library/UefiApplicationEntryPoint.h>\r | |
20 | #include <Library/UefiBootServicesTableLib.h>\r | |
21 | \r | |
22 | \r | |
437dfba2 | 23 | UINT64\r |
24 | ReadTimestamp (\r | |
25 | VOID\r | |
26 | )\r | |
27 | {\r | |
28 | #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r | |
29 | return AsmReadTsc ();\r | |
30 | #elif defined (MDE_CPU_IPF)\r | |
31 | return AsmReadItc ();\r | |
32 | #else\r | |
33 | #error ReadTimestamp not supported for this architecture!\r | |
34 | #endif\r | |
35 | }\r | |
36 | \r | |
a12199e6 | 37 | UINT32\r |
38 | Rand32 (\r | |
39 | VOID\r | |
40 | )\r | |
41 | {\r | |
42 | UINTN Found;\r | |
fd776d39 | 43 | INTN Bits;\r |
a12199e6 | 44 | UINT64 Tsc1;\r |
45 | UINT64 Tsc2;\r | |
46 | UINT64 TscBits;\r | |
47 | UINT32 R32;\r | |
48 | \r | |
49 | R32 = 0;\r | |
50 | Found = 0;\r | |
437dfba2 | 51 | Tsc1 = ReadTimestamp ();\r |
52 | Tsc2 = ReadTimestamp ();\r | |
a12199e6 | 53 | do {\r |
437dfba2 | 54 | Tsc2 = ReadTimestamp ();\r |
a12199e6 | 55 | TscBits = Tsc2 ^ Tsc1;\r |
56 | Bits = HighBitSet64 (TscBits);\r | |
57 | if (Bits > 0) {\r | |
58 | Bits = Bits - 1;\r | |
59 | }\r | |
f057c25b | 60 | R32 = (UINT32)((R32 << Bits) |\r |
ef73b0a6 | 61 | RShiftU64 (LShiftU64 (TscBits, (UINTN) (64 - Bits)), (UINTN) (64 - Bits)));\r |
a12199e6 | 62 | Found = Found + Bits;\r |
63 | } while (Found < 32);\r | |
64 | \r | |
65 | return R32;\r | |
66 | }\r | |
67 | \r | |
68 | \r | |
69 | VOID\r | |
70 | TestFills (\r | |
71 | VOID\r | |
72 | )\r | |
73 | {\r | |
74 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r | |
75 | UINTN Loop;\r | |
76 | UINTN X;\r | |
77 | UINTN Y;\r | |
78 | UINTN W;\r | |
79 | UINTN H;\r | |
80 | UINTN Width;\r | |
81 | UINTN Height;\r | |
82 | \r | |
83 | BltLibGetSizes (&Width, &Height);\r | |
84 | for (Loop = 0; Loop < 10000; Loop++) {\r | |
85 | W = Width - (Rand32 () % Width);\r | |
86 | H = Height - (Rand32 () % Height);\r | |
87 | if (W != Width) {\r | |
88 | X = Rand32 () % (Width - W);\r | |
89 | } else {\r | |
90 | X = 0;\r | |
91 | }\r | |
92 | if (H != Height) {\r | |
93 | Y = Rand32 () % (Height - H);\r | |
94 | } else {\r | |
95 | Y = 0;\r | |
96 | }\r | |
97 | *(UINT32*) (&Color) = Rand32 () & 0xffffff;\r | |
98 | BltLibVideoFill (&Color, X, Y, W, H);\r | |
99 | }\r | |
100 | }\r | |
101 | \r | |
102 | \r | |
103 | VOID\r | |
104 | TestColor1 (\r | |
105 | VOID\r | |
106 | )\r | |
107 | {\r | |
108 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r | |
109 | UINTN X;\r | |
110 | UINTN Y;\r | |
111 | UINTN Width;\r | |
112 | UINTN Height;\r | |
113 | \r | |
114 | BltLibGetSizes (&Width, &Height);\r | |
115 | *(UINT32*) (&Color) = 0;\r | |
116 | \r | |
117 | for (Y = 0; Y < Height; Y++) {\r | |
118 | for (X = 0; X < Width; X++) {\r | |
f057c25b | 119 | Color.Red = (UINT8) ((X * 0x100) / Width);\r |
120 | Color.Green = (UINT8) ((Y * 0x100) / Height);\r | |
121 | Color.Blue = (UINT8) ((Y * 0x100) / Height);\r | |
a12199e6 | 122 | BltLibVideoFill (&Color, X, Y, 1, 1);\r |
123 | }\r | |
124 | }\r | |
125 | }\r | |
126 | \r | |
127 | \r | |
128 | UINT32\r | |
129 | Uint32SqRt (\r | |
130 | IN UINT32 Uint32\r | |
131 | )\r | |
132 | {\r | |
f057c25b | 133 | UINT32 Mask;\r |
a12199e6 | 134 | UINT32 SqRt;\r |
135 | UINT32 SqRtMask;\r | |
136 | UINT32 Squared;\r | |
137 | \r | |
138 | if (Uint32 == 0) {\r | |
139 | return 0;\r | |
140 | }\r | |
141 | \r | |
f057c25b | 142 | for (SqRt = 0, Mask = (UINT32) (1 << (HighBitSet32 (Uint32) / 2));\r |
a12199e6 | 143 | Mask != 0;\r |
144 | Mask = Mask >> 1\r | |
145 | ) {\r | |
146 | SqRtMask = SqRt | Mask;\r | |
147 | //DEBUG ((EFI_D_INFO, "Uint32=0x%x SqRtMask=0x%x\n", Uint32, SqRtMask));\r | |
148 | Squared = (UINT32) (SqRtMask * SqRtMask);\r | |
149 | if (Squared > Uint32) {\r | |
150 | continue;\r | |
151 | } else if (Squared < Uint32) {\r | |
152 | SqRt = SqRtMask;\r | |
153 | } else {\r | |
154 | return SqRtMask;\r | |
155 | }\r | |
156 | }\r | |
157 | \r | |
158 | return SqRt;\r | |
159 | }\r | |
160 | \r | |
161 | \r | |
162 | UINT32\r | |
163 | Uint32Dist (\r | |
f057c25b | 164 | IN UINTN X,\r |
165 | IN UINTN Y\r | |
a12199e6 | 166 | )\r |
167 | {\r | |
f057c25b | 168 | return Uint32SqRt ((UINT32) ((X * X) + (Y * Y)));\r |
a12199e6 | 169 | }\r |
170 | \r | |
f057c25b | 171 | UINT8\r |
a12199e6 | 172 | GetTriColor (\r |
f057c25b | 173 | IN UINTN ColorDist,\r |
174 | IN UINTN TriWidth\r | |
a12199e6 | 175 | )\r |
176 | {\r | |
f057c25b | 177 | return (UINT8) (((TriWidth - ColorDist) * 0x100) / TriWidth);\r |
a12199e6 | 178 | //return (((TriWidth * TriWidth - ColorDist * ColorDist) * 0x100) / (TriWidth * TriWidth));\r |
179 | }\r | |
180 | \r | |
181 | VOID\r | |
182 | TestColor (\r | |
183 | VOID\r | |
184 | )\r | |
185 | {\r | |
186 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r | |
187 | UINTN X, Y;\r | |
188 | UINTN X1, X2, X3;\r | |
189 | UINTN Y1, Y2;\r | |
190 | UINTN LineWidth, TriWidth, ScreenWidth;\r | |
191 | UINTN TriHeight, ScreenHeight;\r | |
f057c25b | 192 | UINT32 ColorDist;\r |
a12199e6 | 193 | \r |
194 | BltLibGetSizes (&ScreenWidth, &ScreenHeight);\r | |
195 | *(UINT32*) (&Color) = 0;\r | |
196 | BltLibVideoFill (&Color, 0, 0, ScreenWidth, ScreenHeight);\r | |
197 | \r | |
f057c25b | 198 | TriWidth = (UINTN) DivU64x32 (\r |
199 | MultU64x32 (11547005, (UINT32) ScreenHeight),\r | |
200 | 10000000\r | |
201 | );\r | |
202 | TriHeight = (UINTN) DivU64x32 (\r | |
203 | MultU64x32 (8660254, (UINT32) ScreenWidth),\r | |
204 | 10000000\r | |
205 | );\r | |
a12199e6 | 206 | if (TriWidth > ScreenWidth) {\r |
207 | DEBUG ((EFI_D_INFO, "TriWidth at %d was too big\n", TriWidth));\r | |
208 | TriWidth = ScreenWidth;\r | |
209 | } else if (TriHeight > ScreenHeight) {\r | |
210 | DEBUG ((EFI_D_INFO, "TriHeight at %d was too big\n", TriHeight));\r | |
211 | TriHeight = ScreenHeight;\r | |
212 | }\r | |
213 | \r | |
214 | DEBUG ((EFI_D_INFO, "Triangle Width: %d; Height: %d\n", TriWidth, TriHeight));\r | |
215 | \r | |
216 | X1 = (ScreenWidth - TriWidth) / 2;\r | |
217 | X3 = X1 + TriWidth - 1;\r | |
218 | X2 = (X1 + X3) / 2;\r | |
219 | Y2 = (ScreenHeight - TriHeight) / 2;\r | |
220 | Y1 = Y2 + TriHeight - 1;\r | |
221 | \r | |
222 | for (Y = Y2; Y <= Y1; Y++) {\r | |
223 | LineWidth =\r | |
f057c25b | 224 | (UINTN) DivU64x32 (\r |
225 | MultU64x32 (11547005, (UINT32) (Y - Y2)),\r | |
226 | 20000000\r | |
227 | );\r | |
a12199e6 | 228 | for (X = X2 - LineWidth; X < (X2 + LineWidth); X++) {\r |
229 | ColorDist = Uint32Dist(X - X1, Y1 - Y);\r | |
230 | Color.Red = GetTriColor (ColorDist, TriWidth);\r | |
231 | \r | |
232 | ColorDist = Uint32Dist((X < X2) ? X2 - X : X - X2, Y - Y2);\r | |
233 | Color.Green = GetTriColor (ColorDist, TriWidth);\r | |
234 | \r | |
235 | ColorDist = Uint32Dist(X3 - X, Y1 - Y);\r | |
236 | Color.Blue = GetTriColor (ColorDist, TriWidth);\r | |
237 | \r | |
238 | BltLibVideoFill (&Color, X, Y, 1, 1);\r | |
239 | }\r | |
240 | }\r | |
241 | }\r | |
242 | \r | |
243 | \r | |
244 | /**\r | |
245 | The user Entry Point for Application. The user code starts with this function\r | |
246 | as the real entry point for the application.\r | |
247 | \r | |
248 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
249 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
250 | \r | |
251 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
252 | @retval other Some error occurs when executing this entry point.\r | |
253 | \r | |
254 | **/\r | |
255 | EFI_STATUS\r | |
256 | EFIAPI\r | |
257 | UefiMain (\r | |
258 | IN EFI_HANDLE ImageHandle,\r | |
259 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
260 | )\r | |
261 | {\r | |
262 | EFI_STATUS Status;\r | |
263 | EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;\r | |
264 | \r | |
265 | Status = gBS->HandleProtocol (\r | |
266 | gST->ConsoleOutHandle,\r | |
267 | &gEfiGraphicsOutputProtocolGuid,\r | |
268 | (VOID **) &Gop\r | |
269 | );\r | |
270 | if (EFI_ERROR (Status)) {\r | |
271 | return Status;\r | |
272 | }\r | |
273 | \r | |
274 | Status = BltLibConfigure (\r | |
275 | (VOID*)(UINTN) Gop->Mode->FrameBufferBase,\r | |
276 | Gop->Mode->Info\r | |
277 | );\r | |
278 | if (EFI_ERROR (Status)) {\r | |
279 | return Status;\r | |
280 | }\r | |
281 | \r | |
282 | TestFills ();\r | |
283 | \r | |
284 | TestColor ();\r | |
285 | \r | |
286 | return EFI_SUCCESS;\r | |
287 | }\r |