]>
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 | |
23 | UINT32\r | |
24 | Rand32 (\r | |
25 | VOID\r | |
26 | )\r | |
27 | {\r | |
28 | UINTN Found;\r | |
29 | UINTN Bits;\r | |
30 | UINT64 Tsc1;\r | |
31 | UINT64 Tsc2;\r | |
32 | UINT64 TscBits;\r | |
33 | UINT32 R32;\r | |
34 | \r | |
35 | R32 = 0;\r | |
36 | Found = 0;\r | |
37 | Tsc1 = AsmReadTsc ();\r | |
38 | Tsc2 = AsmReadTsc ();\r | |
39 | do {\r | |
40 | Tsc2 = AsmReadTsc ();\r | |
41 | TscBits = Tsc2 ^ Tsc1;\r | |
42 | Bits = HighBitSet64 (TscBits);\r | |
43 | if (Bits > 0) {\r | |
44 | Bits = Bits - 1;\r | |
45 | }\r | |
46 | R32 = (R32 << Bits) | RShiftU64 (LShiftU64 (TscBits, 64 - Bits), 64 - Bits);\r | |
47 | Found = Found + Bits;\r | |
48 | } while (Found < 32);\r | |
49 | \r | |
50 | return R32;\r | |
51 | }\r | |
52 | \r | |
53 | \r | |
54 | VOID\r | |
55 | TestFills (\r | |
56 | VOID\r | |
57 | )\r | |
58 | {\r | |
59 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r | |
60 | UINTN Loop;\r | |
61 | UINTN X;\r | |
62 | UINTN Y;\r | |
63 | UINTN W;\r | |
64 | UINTN H;\r | |
65 | UINTN Width;\r | |
66 | UINTN Height;\r | |
67 | \r | |
68 | BltLibGetSizes (&Width, &Height);\r | |
69 | for (Loop = 0; Loop < 10000; Loop++) {\r | |
70 | W = Width - (Rand32 () % Width);\r | |
71 | H = Height - (Rand32 () % Height);\r | |
72 | if (W != Width) {\r | |
73 | X = Rand32 () % (Width - W);\r | |
74 | } else {\r | |
75 | X = 0;\r | |
76 | }\r | |
77 | if (H != Height) {\r | |
78 | Y = Rand32 () % (Height - H);\r | |
79 | } else {\r | |
80 | Y = 0;\r | |
81 | }\r | |
82 | *(UINT32*) (&Color) = Rand32 () & 0xffffff;\r | |
83 | BltLibVideoFill (&Color, X, Y, W, H);\r | |
84 | }\r | |
85 | }\r | |
86 | \r | |
87 | \r | |
88 | VOID\r | |
89 | TestColor1 (\r | |
90 | VOID\r | |
91 | )\r | |
92 | {\r | |
93 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r | |
94 | UINTN X;\r | |
95 | UINTN Y;\r | |
96 | UINTN Width;\r | |
97 | UINTN Height;\r | |
98 | \r | |
99 | BltLibGetSizes (&Width, &Height);\r | |
100 | *(UINT32*) (&Color) = 0;\r | |
101 | \r | |
102 | for (Y = 0; Y < Height; Y++) {\r | |
103 | for (X = 0; X < Width; X++) {\r | |
104 | Color.Red = ((X * 0x100) / Width);\r | |
105 | Color.Green = ((Y * 0x100) / Height);\r | |
106 | Color.Blue = ((Y * 0x100) / Height);\r | |
107 | BltLibVideoFill (&Color, X, Y, 1, 1);\r | |
108 | }\r | |
109 | }\r | |
110 | }\r | |
111 | \r | |
112 | \r | |
113 | UINT32\r | |
114 | Uint32SqRt (\r | |
115 | IN UINT32 Uint32\r | |
116 | )\r | |
117 | {\r | |
118 | UINTN Mask;\r | |
119 | UINT32 SqRt;\r | |
120 | UINT32 SqRtMask;\r | |
121 | UINT32 Squared;\r | |
122 | \r | |
123 | if (Uint32 == 0) {\r | |
124 | return 0;\r | |
125 | }\r | |
126 | \r | |
127 | for (SqRt = 0, Mask = 1 << (HighBitSet32 (Uint32) / 2);\r | |
128 | Mask != 0;\r | |
129 | Mask = Mask >> 1\r | |
130 | ) {\r | |
131 | SqRtMask = SqRt | Mask;\r | |
132 | //DEBUG ((EFI_D_INFO, "Uint32=0x%x SqRtMask=0x%x\n", Uint32, SqRtMask));\r | |
133 | Squared = (UINT32) (SqRtMask * SqRtMask);\r | |
134 | if (Squared > Uint32) {\r | |
135 | continue;\r | |
136 | } else if (Squared < Uint32) {\r | |
137 | SqRt = SqRtMask;\r | |
138 | } else {\r | |
139 | return SqRtMask;\r | |
140 | }\r | |
141 | }\r | |
142 | \r | |
143 | return SqRt;\r | |
144 | }\r | |
145 | \r | |
146 | \r | |
147 | UINT32\r | |
148 | Uint32Dist (\r | |
149 | IN UINT32 X,\r | |
150 | IN UINT32 Y\r | |
151 | )\r | |
152 | {\r | |
153 | return Uint32SqRt ((X * X) + (Y * Y));\r | |
154 | }\r | |
155 | \r | |
156 | UINT32\r | |
157 | GetTriColor (\r | |
158 | IN UINT32 ColorDist,\r | |
159 | IN UINT32 TriWidth\r | |
160 | )\r | |
161 | {\r | |
162 | return (((TriWidth - ColorDist) * 0x100) / TriWidth);\r | |
163 | //return (((TriWidth * TriWidth - ColorDist * ColorDist) * 0x100) / (TriWidth * TriWidth));\r | |
164 | }\r | |
165 | \r | |
166 | VOID\r | |
167 | TestColor (\r | |
168 | VOID\r | |
169 | )\r | |
170 | {\r | |
171 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r | |
172 | UINTN X, Y;\r | |
173 | UINTN X1, X2, X3;\r | |
174 | UINTN Y1, Y2;\r | |
175 | UINTN LineWidth, TriWidth, ScreenWidth;\r | |
176 | UINTN TriHeight, ScreenHeight;\r | |
177 | UINTN ColorDist;\r | |
178 | \r | |
179 | BltLibGetSizes (&ScreenWidth, &ScreenHeight);\r | |
180 | *(UINT32*) (&Color) = 0;\r | |
181 | BltLibVideoFill (&Color, 0, 0, ScreenWidth, ScreenHeight);\r | |
182 | \r | |
183 | TriWidth = DivU64x32 (MultU64x32 (11547005, ScreenHeight), 10000000);\r | |
184 | TriHeight = DivU64x32 (MultU64x32 (8660254, ScreenWidth), 10000000);\r | |
185 | if (TriWidth > ScreenWidth) {\r | |
186 | DEBUG ((EFI_D_INFO, "TriWidth at %d was too big\n", TriWidth));\r | |
187 | TriWidth = ScreenWidth;\r | |
188 | } else if (TriHeight > ScreenHeight) {\r | |
189 | DEBUG ((EFI_D_INFO, "TriHeight at %d was too big\n", TriHeight));\r | |
190 | TriHeight = ScreenHeight;\r | |
191 | }\r | |
192 | \r | |
193 | DEBUG ((EFI_D_INFO, "Triangle Width: %d; Height: %d\n", TriWidth, TriHeight));\r | |
194 | \r | |
195 | X1 = (ScreenWidth - TriWidth) / 2;\r | |
196 | X3 = X1 + TriWidth - 1;\r | |
197 | X2 = (X1 + X3) / 2;\r | |
198 | Y2 = (ScreenHeight - TriHeight) / 2;\r | |
199 | Y1 = Y2 + TriHeight - 1;\r | |
200 | \r | |
201 | for (Y = Y2; Y <= Y1; Y++) {\r | |
202 | LineWidth =\r | |
203 | DivU64x32 (\r | |
204 | MultU64x32 (11547005, (Y - Y2)),\r | |
205 | 20000000\r | |
206 | );\r | |
207 | for (X = X2 - LineWidth; X < (X2 + LineWidth); X++) {\r | |
208 | ColorDist = Uint32Dist(X - X1, Y1 - Y);\r | |
209 | Color.Red = GetTriColor (ColorDist, TriWidth);\r | |
210 | \r | |
211 | ColorDist = Uint32Dist((X < X2) ? X2 - X : X - X2, Y - Y2);\r | |
212 | Color.Green = GetTriColor (ColorDist, TriWidth);\r | |
213 | \r | |
214 | ColorDist = Uint32Dist(X3 - X, Y1 - Y);\r | |
215 | Color.Blue = GetTriColor (ColorDist, TriWidth);\r | |
216 | \r | |
217 | BltLibVideoFill (&Color, X, Y, 1, 1);\r | |
218 | }\r | |
219 | }\r | |
220 | }\r | |
221 | \r | |
222 | \r | |
223 | /**\r | |
224 | The user Entry Point for Application. The user code starts with this function\r | |
225 | as the real entry point for the application.\r | |
226 | \r | |
227 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
228 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
229 | \r | |
230 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
231 | @retval other Some error occurs when executing this entry point.\r | |
232 | \r | |
233 | **/\r | |
234 | EFI_STATUS\r | |
235 | EFIAPI\r | |
236 | UefiMain (\r | |
237 | IN EFI_HANDLE ImageHandle,\r | |
238 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
239 | )\r | |
240 | {\r | |
241 | EFI_STATUS Status;\r | |
242 | EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;\r | |
243 | \r | |
244 | Status = gBS->HandleProtocol (\r | |
245 | gST->ConsoleOutHandle,\r | |
246 | &gEfiGraphicsOutputProtocolGuid,\r | |
247 | (VOID **) &Gop\r | |
248 | );\r | |
249 | if (EFI_ERROR (Status)) {\r | |
250 | return Status;\r | |
251 | }\r | |
252 | \r | |
253 | Status = BltLibConfigure (\r | |
254 | (VOID*)(UINTN) Gop->Mode->FrameBufferBase,\r | |
255 | Gop->Mode->Info\r | |
256 | );\r | |
257 | if (EFI_ERROR (Status)) {\r | |
258 | return Status;\r | |
259 | }\r | |
260 | \r | |
261 | TestFills ();\r | |
262 | \r | |
263 | TestColor ();\r | |
264 | \r | |
265 | return EFI_SUCCESS;\r | |
266 | }\r |