]>
Commit | Line | Data |
---|---|---|
79964ac8 | 1 | /** @file\r |
619e4c06 | 2 | Mde UEFI library API implementation.\r |
79964ac8 | 3 | Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE\r |
4 | \r | |
2b3687db HT |
5 | Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>\r |
6 | This program and the accompanying materials\r | |
79964ac8 | 7 | are licensed and made available under the terms and conditions of the BSD License\r |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
bf428cb3 | 16 | #include "UefiLibInternal.h"\r |
17 | \r | |
18 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r | |
19 | { 0x00, 0x00, 0x00, 0x00 },\r | |
20 | { 0x98, 0x00, 0x00, 0x00 },\r | |
21 | { 0x00, 0x98, 0x00, 0x00 },\r | |
22 | { 0x98, 0x98, 0x00, 0x00 },\r | |
23 | { 0x00, 0x00, 0x98, 0x00 },\r | |
24 | { 0x98, 0x00, 0x98, 0x00 },\r | |
25 | { 0x00, 0x98, 0x98, 0x00 },\r | |
26 | { 0x98, 0x98, 0x98, 0x00 },\r | |
27 | { 0x10, 0x10, 0x10, 0x00 },\r | |
28 | { 0xff, 0x10, 0x10, 0x00 },\r | |
29 | { 0x10, 0xff, 0x10, 0x00 },\r | |
30 | { 0xff, 0xff, 0x10, 0x00 },\r | |
31 | { 0x10, 0x10, 0xff, 0x00 },\r | |
32 | { 0xf0, 0x10, 0xff, 0x00 },\r | |
33 | { 0x10, 0xff, 0xff, 0x00 },\r | |
34 | { 0xff, 0xff, 0xff, 0x00 }\r | |
35 | };\r | |
79964ac8 | 36 | \r |
37 | /**\r | |
38 | Internal function which prints a formatted Unicode string to the console output device\r | |
39 | specified by Console\r | |
40 | \r | |
41 | This function prints a formatted Unicode string to the console output device\r | |
42 | specified by Console and returns the number of Unicode characters that printed\r | |
43 | to it. If the length of the formatted Unicode string is greater than PcdUefiLibMaxPrintBufferSize,\r | |
44 | then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r | |
bf428cb3 | 45 | If Format is NULL, then ASSERT().\r |
46 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
79964ac8 | 47 | \r |
48 | @param Format Null-terminated Unicode format string.\r | |
49 | @param Console The output console.\r | |
50 | @param Marker VA_LIST marker for the variable argument list.\r | |
e115460b | 51 | \r |
bf428cb3 | 52 | @return The number of Unicode characters in the produced\r |
53 | output buffer not including the Null-terminator.\r | |
79964ac8 | 54 | **/\r |
79964ac8 | 55 | UINTN\r |
56 | InternalPrint (\r | |
b51e6bc4 | 57 | IN CONST CHAR16 *Format,\r |
58 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r | |
59 | IN VA_LIST Marker\r | |
79964ac8 | 60 | )\r |
61 | {\r | |
4ea439fb | 62 | EFI_STATUS Status;\r |
79964ac8 | 63 | UINTN Return;\r |
64 | CHAR16 *Buffer;\r | |
65 | UINTN BufferSize;\r | |
66 | \r | |
67 | ASSERT (Format != NULL);\r | |
bf428cb3 | 68 | ASSERT (((UINTN) Format & BIT0) == 0);\r |
4ea439fb | 69 | ASSERT (Console != NULL);\r |
79964ac8 | 70 | \r |
71 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
72 | \r | |
73 | Buffer = (CHAR16 *) AllocatePool(BufferSize);\r | |
74 | ASSERT (Buffer != NULL);\r | |
75 | \r | |
76 | Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r | |
77 | \r | |
bf428cb3 | 78 | if (Console != NULL && Return > 0) {\r |
79964ac8 | 79 | //\r |
80 | // To be extra safe make sure Console has been initialized\r | |
81 | //\r | |
4ea439fb | 82 | Status = Console->OutputString (Console, Buffer);\r |
83 | if (EFI_ERROR (Status)) {\r | |
84 | Return = 0;\r | |
85 | }\r | |
79964ac8 | 86 | }\r |
87 | \r | |
88 | FreePool (Buffer);\r | |
89 | \r | |
90 | return Return;\r | |
91 | }\r | |
92 | \r | |
bf428cb3 | 93 | /** \r |
94 | Prints a formatted Unicode string to the console output device specified by \r | |
79964ac8 | 95 | ConOut defined in the EFI_SYSTEM_TABLE.\r |
96 | \r | |
bf428cb3 | 97 | This function prints a formatted Unicode string to the console output device \r |
98 | specified by ConOut in EFI_SYSTEM_TABLE and returns the number of Unicode \r | |
99 | characters that printed to ConOut. If the length of the formatted Unicode \r | |
100 | string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r | |
79964ac8 | 101 | PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r |
bf428cb3 | 102 | If Format is NULL, then ASSERT().\r |
103 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
4ea439fb | 104 | If gST->ConOut is NULL, then ASSERT().\r |
79964ac8 | 105 | \r |
106 | @param Format Null-terminated Unicode format string.\r | |
00a1f552 | 107 | @param ... Variable argument list whose contents are accessed based \r |
108 | on the format string specified by Format.\r | |
bf428cb3 | 109 | \r |
110 | @return Number of Unicode characters printed to ConOut.\r | |
79964ac8 | 111 | \r |
112 | **/\r | |
113 | UINTN\r | |
114 | EFIAPI\r | |
115 | Print (\r | |
116 | IN CONST CHAR16 *Format,\r | |
117 | ...\r | |
118 | )\r | |
119 | {\r | |
120 | VA_LIST Marker;\r | |
121 | UINTN Return;\r | |
122 | \r | |
123 | VA_START (Marker, Format);\r | |
124 | \r | |
125 | Return = InternalPrint (Format, gST->ConOut, Marker);\r | |
126 | \r | |
127 | VA_END (Marker);\r | |
128 | \r | |
129 | return Return;\r | |
130 | }\r | |
131 | \r | |
bf428cb3 | 132 | /** \r |
133 | Prints a formatted Unicode string to the console output device specified by \r | |
79964ac8 | 134 | StdErr defined in the EFI_SYSTEM_TABLE.\r |
135 | \r | |
bf428cb3 | 136 | This function prints a formatted Unicode string to the console output device \r |
137 | specified by StdErr in EFI_SYSTEM_TABLE and returns the number of Unicode \r | |
138 | characters that printed to StdErr. If the length of the formatted Unicode \r | |
139 | string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r | |
79964ac8 | 140 | PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r |
bf428cb3 | 141 | If Format is NULL, then ASSERT().\r |
142 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
4ea439fb | 143 | If gST->StdErr is NULL, then ASSERT().\r |
79964ac8 | 144 | \r |
145 | @param Format Null-terminated Unicode format string.\r | |
00a1f552 | 146 | @param ... Variable argument list whose contents are accessed based \r |
147 | on the format string specified by Format.\r | |
bf428cb3 | 148 | \r |
149 | @return Number of Unicode characters printed to StdErr.\r | |
79964ac8 | 150 | \r |
151 | **/\r | |
79964ac8 | 152 | UINTN\r |
153 | EFIAPI\r | |
154 | ErrorPrint (\r | |
155 | IN CONST CHAR16 *Format,\r | |
156 | ...\r | |
157 | )\r | |
158 | {\r | |
159 | VA_LIST Marker;\r | |
160 | UINTN Return;\r | |
161 | \r | |
162 | VA_START (Marker, Format);\r | |
163 | \r | |
164 | Return = InternalPrint( Format, gST->StdErr, Marker);\r | |
165 | \r | |
166 | VA_END (Marker);\r | |
167 | \r | |
168 | return Return;\r | |
169 | }\r | |
170 | \r | |
171 | \r | |
172 | /**\r | |
173 | Internal function which prints a formatted ASCII string to the console output device\r | |
174 | specified by Console\r | |
175 | \r | |
176 | This function prints a formatted ASCII string to the console output device\r | |
177 | specified by Console and returns the number of ASCII characters that printed\r | |
178 | to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,\r | |
179 | then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r | |
180 | \r | |
bf428cb3 | 181 | If Format is NULL, then ASSERT().\r |
182 | \r | |
79964ac8 | 183 | @param Format Null-terminated ASCII format string.\r |
184 | @param Console The output console.\r | |
185 | @param Marker VA_LIST marker for the variable argument list.\r | |
186 | \r | |
bf428cb3 | 187 | @return The number of Unicode characters in the produced\r |
188 | output buffer not including the Null-terminator.\r | |
79964ac8 | 189 | \r |
190 | **/\r | |
79964ac8 | 191 | UINTN\r |
192 | AsciiInternalPrint (\r | |
b51e6bc4 | 193 | IN CONST CHAR8 *Format,\r |
194 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r | |
195 | IN VA_LIST Marker\r | |
79964ac8 | 196 | )\r |
197 | {\r | |
4ea439fb | 198 | EFI_STATUS Status;\r |
79964ac8 | 199 | UINTN Return;\r |
200 | CHAR16 *Buffer;\r | |
201 | UINTN BufferSize;\r | |
202 | \r | |
203 | ASSERT (Format != NULL);\r | |
4ea439fb | 204 | ASSERT (Console != NULL);\r |
79964ac8 | 205 | \r |
206 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
207 | \r | |
208 | Buffer = (CHAR16 *) AllocatePool(BufferSize);\r | |
209 | ASSERT (Buffer != NULL);\r | |
210 | \r | |
211 | Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r | |
212 | \r | |
213 | if (Console != NULL) {\r | |
214 | //\r | |
215 | // To be extra safe make sure Console has been initialized\r | |
216 | //\r | |
4ea439fb | 217 | Status = Console->OutputString (Console, Buffer);\r |
218 | if (EFI_ERROR (Status)) {\r | |
219 | Return = 0;\r | |
220 | }\r | |
79964ac8 | 221 | }\r |
222 | \r | |
223 | FreePool (Buffer);\r | |
224 | \r | |
225 | return Return;\r | |
226 | }\r | |
227 | \r | |
bf428cb3 | 228 | /** \r |
229 | Prints a formatted ASCII string to the console output device specified by \r | |
79964ac8 | 230 | ConOut defined in the EFI_SYSTEM_TABLE.\r |
231 | \r | |
bf428cb3 | 232 | This function prints a formatted ASCII string to the console output device \r |
233 | specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII \r | |
234 | characters that printed to ConOut. If the length of the formatted ASCII \r | |
235 | string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r | |
79964ac8 | 236 | PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r |
bf428cb3 | 237 | If Format is NULL, then ASSERT().\r |
4ea439fb | 238 | If gST->ConOut is NULL, then ASSERT().\r |
79964ac8 | 239 | \r |
240 | @param Format Null-terminated ASCII format string.\r | |
00a1f552 | 241 | @param ... Variable argument list whose contents are accessed based \r |
242 | on the format string specified by Format.\r | |
bf428cb3 | 243 | \r |
244 | @return Number of ASCII characters printed to ConOut.\r | |
79964ac8 | 245 | \r |
246 | **/\r | |
247 | UINTN\r | |
248 | EFIAPI\r | |
249 | AsciiPrint (\r | |
250 | IN CONST CHAR8 *Format,\r | |
251 | ...\r | |
252 | )\r | |
253 | {\r | |
254 | VA_LIST Marker;\r | |
255 | UINTN Return;\r | |
bf428cb3 | 256 | ASSERT (Format != NULL);\r |
e115460b | 257 | \r |
79964ac8 | 258 | VA_START (Marker, Format);\r |
259 | \r | |
260 | Return = AsciiInternalPrint( Format, gST->ConOut, Marker);\r | |
261 | \r | |
262 | VA_END (Marker);\r | |
263 | \r | |
264 | return Return;\r | |
265 | }\r | |
266 | \r | |
bf428cb3 | 267 | /** \r |
268 | Prints a formatted ASCII string to the console output device specified by \r | |
79964ac8 | 269 | StdErr defined in the EFI_SYSTEM_TABLE.\r |
270 | \r | |
bf428cb3 | 271 | This function prints a formatted ASCII string to the console output device \r |
272 | specified by StdErr in EFI_SYSTEM_TABLE and returns the number of ASCII \r | |
273 | characters that printed to StdErr. If the length of the formatted ASCII \r | |
274 | string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r | |
79964ac8 | 275 | PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r |
bf428cb3 | 276 | If Format is NULL, then ASSERT().\r |
4ea439fb | 277 | If gST->StdErr is NULL, then ASSERT().\r |
79964ac8 | 278 | \r |
279 | @param Format Null-terminated ASCII format string.\r | |
00a1f552 | 280 | @param ... Variable argument list whose contents are accessed based \r |
281 | on the format string specified by Format.\r | |
bf428cb3 | 282 | \r |
283 | @return Number of ASCII characters printed to ConErr.\r | |
79964ac8 | 284 | \r |
285 | **/\r | |
286 | UINTN\r | |
287 | EFIAPI\r | |
288 | AsciiErrorPrint (\r | |
289 | IN CONST CHAR8 *Format,\r | |
290 | ...\r | |
291 | )\r | |
292 | {\r | |
293 | VA_LIST Marker;\r | |
294 | UINTN Return;\r | |
295 | \r | |
bf428cb3 | 296 | ASSERT (Format != NULL);\r |
e115460b | 297 | \r |
79964ac8 | 298 | VA_START (Marker, Format);\r |
299 | \r | |
300 | Return = AsciiInternalPrint( Format, gST->StdErr, Marker);\r | |
301 | \r | |
302 | VA_END (Marker);\r | |
303 | \r | |
304 | return Return;\r | |
305 | }\r | |
306 | \r | |
bf428cb3 | 307 | /**\r |
e115460b | 308 | Internal function to print a formatted Unicode string to a graphics console device specified by\r |
bf428cb3 | 309 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r |
310 | \r | |
e115460b | 311 | This function prints a formatted Unicode string to the graphics console device\r |
312 | specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of\r | |
313 | Unicode characters printed. The EFI_HII_FONT_PROTOCOL is used to convert the\r | |
314 | string to a bitmap using the glyphs registered with the\r | |
bf428cb3 | 315 | HII database. No wrapping is performed, so any portions of the string the fall\r |
316 | outside the active display region will not be displayed.\r | |
317 | \r | |
e115460b | 318 | If a graphics console device is not associated with the ConsoleOutputHandle\r |
bf428cb3 | 319 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r |
e115460b | 320 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no\r |
bf428cb3 | 321 | string is printed, and 0 is returned.\r |
322 | \r | |
e115460b | 323 | @param PointX X coordinate to print the string.\r |
324 | @param PointY Y coordinate to print the string.\r | |
325 | @param Foreground The foreground color of the string being printed. This is\r | |
bf428cb3 | 326 | an optional parameter that may be NULL. If it is NULL,\r |
327 | then the foreground color of the current ConOut device\r | |
328 | in the EFI_SYSTEM_TABLE is used.\r | |
e6813189 | 329 | @param Background The background color of the string being printed. This is\r |
e115460b | 330 | an optional parameter that may be NULL. If it is NULL,\r |
bf428cb3 | 331 | then the background color of the current ConOut device\r |
332 | in the EFI_SYSTEM_TABLE is used.\r | |
333 | @param Buffer Null-terminated Unicode formatted string.\r | |
334 | @param PrintNum The number of Unicode formatted string to be printed.\r | |
335 | \r | |
e115460b | 336 | @return Number of Unicode Characters printed. Zero means no any character\r |
bf428cb3 | 337 | displayed successfully.\r |
338 | \r | |
339 | **/\r | |
340 | UINTN\r | |
341 | InternalPrintGraphic (\r | |
e115460b | 342 | IN UINTN PointX,\r |
343 | IN UINTN PointY,\r | |
bf428cb3 | 344 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,\r |
345 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background,\r | |
346 | IN CHAR16 *Buffer,\r | |
347 | IN UINTN PrintNum\r | |
348 | )\r | |
349 | {\r | |
350 | EFI_STATUS Status;\r | |
bf428cb3 | 351 | UINT32 HorizontalResolution;\r |
352 | UINT32 VerticalResolution;\r | |
353 | UINT32 ColorDepth;\r | |
354 | UINT32 RefreshRate;\r | |
bf428cb3 | 355 | EFI_HII_FONT_PROTOCOL *HiiFont;\r |
356 | EFI_IMAGE_OUTPUT *Blt;\r | |
357 | EFI_FONT_DISPLAY_INFO FontInfo;\r | |
358 | EFI_HII_ROW_INFO *RowInfoArray;\r | |
359 | UINTN RowInfoArraySize;\r | |
360 | EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r | |
361 | EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r | |
362 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;\r | |
363 | EFI_HANDLE ConsoleHandle;\r | |
4ea439fb | 364 | UINTN Width;\r |
365 | UINTN Height;\r | |
366 | UINTN Delta;\r | |
bf428cb3 | 367 | \r |
368 | HorizontalResolution = 0;\r | |
369 | VerticalResolution = 0;\r | |
370 | Blt = NULL;\r | |
619e4c06 | 371 | RowInfoArray = NULL;\r |
bf428cb3 | 372 | \r |
373 | ConsoleHandle = gST->ConsoleOutHandle;\r | |
374 | \r | |
4ea439fb | 375 | ASSERT( ConsoleHandle != NULL);\r |
376 | \r | |
bf428cb3 | 377 | Status = gBS->HandleProtocol (\r |
378 | ConsoleHandle,\r | |
379 | &gEfiGraphicsOutputProtocolGuid,\r | |
380 | (VOID **) &GraphicsOutput\r | |
381 | );\r | |
382 | \r | |
383 | UgaDraw = NULL;\r | |
384 | if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r | |
385 | //\r | |
386 | // If no GOP available, try to open UGA Draw protocol if supported.\r | |
387 | //\r | |
388 | GraphicsOutput = NULL;\r | |
389 | \r | |
390 | Status = gBS->HandleProtocol (\r | |
391 | ConsoleHandle,\r | |
392 | &gEfiUgaDrawProtocolGuid,\r | |
393 | (VOID **) &UgaDraw\r | |
394 | );\r | |
395 | }\r | |
396 | if (EFI_ERROR (Status)) {\r | |
619e4c06 | 397 | goto Error;\r |
bf428cb3 | 398 | }\r |
399 | \r | |
400 | Status = gBS->HandleProtocol (\r | |
401 | ConsoleHandle,\r | |
402 | &gEfiSimpleTextOutProtocolGuid,\r | |
403 | (VOID **) &Sto\r | |
404 | );\r | |
405 | \r | |
406 | if (EFI_ERROR (Status)) {\r | |
619e4c06 | 407 | goto Error;\r |
bf428cb3 | 408 | }\r |
409 | \r | |
410 | if (GraphicsOutput != NULL) {\r | |
411 | HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r | |
412 | VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r | |
e115460b | 413 | } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r |
bf428cb3 | 414 | UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r |
415 | } else {\r | |
bf428cb3 | 416 | goto Error;\r |
417 | }\r | |
418 | \r | |
419 | ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));\r | |
420 | \r | |
421 | Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &HiiFont);\r | |
422 | if (EFI_ERROR (Status)) {\r | |
423 | goto Error;\r | |
424 | }\r | |
425 | \r | |
bf428cb3 | 426 | Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r |
427 | ASSERT (Blt != NULL);\r | |
428 | \r | |
429 | Blt->Width = (UINT16) (HorizontalResolution);\r | |
430 | Blt->Height = (UINT16) (VerticalResolution);\r | |
431 | \r | |
432 | ZeroMem (&FontInfo, sizeof (EFI_FONT_DISPLAY_INFO));\r | |
433 | \r | |
434 | if (Foreground != NULL) {\r | |
435 | CopyMem (&FontInfo.ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r | |
436 | } else {\r | |
437 | CopyMem (\r | |
438 | &FontInfo.ForegroundColor,\r | |
439 | &mEfiColors[Sto->Mode->Attribute & 0x0f],\r | |
440 | sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
441 | );\r | |
442 | }\r | |
443 | if (Background != NULL) {\r | |
444 | CopyMem (&FontInfo.BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r | |
445 | } else {\r | |
446 | CopyMem (\r | |
447 | &FontInfo.BackgroundColor,\r | |
448 | &mEfiColors[Sto->Mode->Attribute >> 4],\r | |
449 | sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
450 | );\r | |
451 | }\r | |
452 | \r | |
453 | if (GraphicsOutput != NULL) {\r | |
454 | Blt->Image.Screen = GraphicsOutput;\r | |
e115460b | 455 | \r |
bf428cb3 | 456 | Status = HiiFont->StringToImage (\r |
457 | HiiFont,\r | |
619e4c06 | 458 | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |\r |
459 | EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |\r | |
460 | EFI_HII_IGNORE_LINE_BREAK | EFI_HII_DIRECT_TO_SCREEN,\r | |
bf428cb3 | 461 | Buffer,\r |
462 | &FontInfo,\r | |
463 | &Blt,\r | |
e115460b | 464 | PointX,\r |
465 | PointY,\r | |
619e4c06 | 466 | &RowInfoArray,\r |
467 | &RowInfoArraySize,\r | |
bf428cb3 | 468 | NULL\r |
469 | );\r | |
619e4c06 | 470 | if (EFI_ERROR (Status)) {\r |
471 | goto Error;\r | |
472 | }\r | |
bf428cb3 | 473 | \r |
e115460b | 474 | } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r |
475 | ASSERT (UgaDraw!= NULL);\r | |
bf428cb3 | 476 | \r |
477 | Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r | |
478 | ASSERT (Blt->Image.Bitmap != NULL);\r | |
479 | \r | |
bf428cb3 | 480 | //\r |
481 | // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,\r | |
482 | // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.\r | |
483 | //\r | |
484 | Status = HiiFont->StringToImage (\r | |
485 | HiiFont,\r | |
4ea439fb | 486 | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |\r |
487 | EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |\r | |
488 | EFI_HII_IGNORE_LINE_BREAK,\r | |
bf428cb3 | 489 | Buffer,\r |
490 | &FontInfo,\r | |
491 | &Blt,\r | |
e115460b | 492 | PointX,\r |
493 | PointY,\r | |
bf428cb3 | 494 | &RowInfoArray,\r |
495 | &RowInfoArraySize,\r | |
496 | NULL\r | |
497 | );\r | |
498 | \r | |
499 | if (!EFI_ERROR (Status)) {\r | |
500 | ASSERT (RowInfoArray != NULL);\r | |
501 | //\r | |
4ea439fb | 502 | // Explicit Line break characters are ignored, so the updated parameter RowInfoArraySize by StringToImage will\r |
bf428cb3 | 503 | // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.\r |
504 | //\r | |
505 | ASSERT (RowInfoArraySize <= 1);\r | |
506 | \r | |
4ea439fb | 507 | if (RowInfoArraySize != 0) {\r |
508 | Width = RowInfoArray[0].LineWidth;\r | |
509 | Height = RowInfoArray[0].LineHeight;\r | |
510 | Delta = Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r | |
511 | } else {\r | |
512 | Width = 0;\r | |
513 | Height = 0;\r | |
514 | Delta = 0;\r | |
515 | }\r | |
bf428cb3 | 516 | Status = UgaDraw->Blt (\r |
517 | UgaDraw,\r | |
518 | (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r | |
519 | EfiUgaBltBufferToVideo,\r | |
e115460b | 520 | PointX,\r |
521 | PointY,\r | |
522 | PointX,\r | |
523 | PointY,\r | |
4ea439fb | 524 | Width,\r |
525 | Height,\r | |
526 | Delta\r | |
bf428cb3 | 527 | );\r |
619e4c06 | 528 | } else {\r |
529 | goto Error;\r | |
bf428cb3 | 530 | }\r |
bf428cb3 | 531 | FreePool (Blt->Image.Bitmap);\r |
bf428cb3 | 532 | } else {\r |
619e4c06 | 533 | goto Error;\r |
bf428cb3 | 534 | }\r |
619e4c06 | 535 | //\r |
536 | // Calculate the number of actual printed characters\r | |
537 | //\r | |
4ea439fb | 538 | if (RowInfoArraySize != 0) {\r |
619e4c06 | 539 | PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;\r |
4ea439fb | 540 | } else {\r |
541 | PrintNum = 0;\r | |
542 | }\r | |
bf428cb3 | 543 | \r |
619e4c06 | 544 | FreePool (RowInfoArray);\r |
bf428cb3 | 545 | FreePool (Blt);\r |
619e4c06 | 546 | return PrintNum;\r |
bf428cb3 | 547 | \r |
548 | Error:\r | |
619e4c06 | 549 | if (Blt != NULL) {\r |
550 | FreePool (Blt);\r | |
bf428cb3 | 551 | }\r |
619e4c06 | 552 | return 0;\r |
bf428cb3 | 553 | }\r |
554 | \r | |
555 | /**\r | |
556 | Prints a formatted Unicode string to a graphics console device specified by \r | |
557 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r | |
558 | \r | |
559 | This function prints a formatted Unicode string to the graphics console device \r | |
560 | specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of \r | |
619e4c06 | 561 | Unicode characters displayed, not including partial characters that may be clipped \r |
562 | by the right edge of the display. If the length of the formatted Unicode string is\r | |
563 | greater than PcdUefiLibMaxPrintBufferSize, then at most the first \r | |
57b201b8 | 564 | PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL\r |
565 | StringToImage() service is used to convert the string to a bitmap using the glyphs \r | |
566 | registered with the HII database. No wrapping is performed, so any portions of the \r | |
567 | string the fall outside the active display region will not be displayed. Please see \r | |
568 | Section 27.2.6 of the UEFI Specification for a description of the supported string\r | |
569 | format including the set of control codes supported by the StringToImage() service.\r | |
bf428cb3 | 570 | \r |
571 | If a graphics console device is not associated with the ConsoleOutputHandle \r | |
572 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r | |
573 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no \r | |
574 | string is printed, and 0 is returned.\r | |
575 | If Format is NULL, then ASSERT().\r | |
576 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
4ea439fb | 577 | If gST->ConsoleOutputHandle is NULL, then ASSERT().\r |
bf428cb3 | 578 | \r |
e115460b | 579 | @param PointX X coordinate to print the string.\r |
580 | @param PointY Y coordinate to print the string.\r | |
581 | @param ForeGround The foreground color of the string being printed. This is\r | |
bf428cb3 | 582 | an optional parameter that may be NULL. If it is NULL,\r |
583 | then the foreground color of the current ConOut device\r | |
584 | in the EFI_SYSTEM_TABLE is used.\r | |
585 | @param BackGround The background color of the string being printed. This is\r | |
586 | an optional parameter that may be NULL. If it is NULL, \r | |
587 | then the background color of the current ConOut device\r | |
588 | in the EFI_SYSTEM_TABLE is used.\r | |
589 | @param Format Null-terminated Unicode format string. See Print Library \r | |
590 | for the supported format string syntax.\r | |
591 | @param ... Variable argument list whose contents are accessed based on \r | |
592 | the format string specified by Format. \r | |
593 | \r | |
594 | @return The number of Unicode characters printed.\r | |
595 | \r | |
596 | **/\r | |
597 | UINTN\r | |
598 | EFIAPI\r | |
599 | PrintXY (\r | |
e115460b | 600 | IN UINTN PointX,\r |
601 | IN UINTN PointY,\r | |
bf428cb3 | 602 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL\r |
603 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL\r | |
604 | IN CONST CHAR16 *Format,\r | |
605 | ...\r | |
606 | )\r | |
607 | {\r | |
608 | VA_LIST Marker;\r | |
609 | CHAR16 *Buffer;\r | |
610 | UINTN BufferSize;\r | |
611 | UINTN PrintNum;\r | |
612 | UINTN ReturnNum;\r | |
613 | \r | |
614 | ASSERT (Format != NULL);\r | |
615 | ASSERT (((UINTN) Format & BIT0) == 0);\r | |
616 | \r | |
617 | VA_START (Marker, Format);\r | |
618 | \r | |
619 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
620 | \r | |
621 | Buffer = (CHAR16 *) AllocatePool (BufferSize);\r | |
622 | ASSERT (Buffer != NULL);\r | |
e115460b | 623 | \r |
bf428cb3 | 624 | PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r |
625 | \r | |
e115460b | 626 | ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r |
bf428cb3 | 627 | \r |
628 | FreePool (Buffer);\r | |
629 | \r | |
630 | return ReturnNum;\r | |
631 | }\r | |
632 | \r | |
633 | /**\r | |
634 | Prints a formatted ASCII string to a graphics console device specified by \r | |
635 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r | |
636 | \r | |
637 | This function prints a formatted ASCII string to the graphics console device \r | |
638 | specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of \r | |
619e4c06 | 639 | ASCII characters displayed, not including partial characters that may be clipped \r |
640 | by the right edge of the display. If the length of the formatted ASCII string is\r | |
641 | greater than PcdUefiLibMaxPrintBufferSize, then at most the first \r | |
57b201b8 | 642 | PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL\r |
643 | StringToImage() service is used to convert the string to a bitmap using the glyphs \r | |
644 | registered with the HII database. No wrapping is performed, so any portions of the \r | |
645 | string the fall outside the active display region will not be displayed. Please see \r | |
646 | Section 27.2.6 of the UEFI Specification for a description of the supported string\r | |
647 | format including the set of control codes supported by the StringToImage() service.\r | |
bf428cb3 | 648 | \r |
649 | If a graphics console device is not associated with the ConsoleOutputHandle \r | |
650 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r | |
651 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no \r | |
652 | string is printed, and 0 is returned.\r | |
653 | If Format is NULL, then ASSERT().\r | |
4ea439fb | 654 | If gST->ConsoleOutputHandle is NULL, then ASSERT().\r |
bf428cb3 | 655 | \r |
e115460b | 656 | @param PointX X coordinate to print the string.\r |
657 | @param PointY Y coordinate to print the string.\r | |
658 | @param ForeGround The foreground color of the string being printed. This is\r | |
bf428cb3 | 659 | an optional parameter that may be NULL. If it is NULL,\r |
660 | then the foreground color of the current ConOut device\r | |
661 | in the EFI_SYSTEM_TABLE is used.\r | |
662 | @param BackGround The background color of the string being printed. This is\r | |
663 | an optional parameter that may be NULL. If it is NULL, \r | |
664 | then the background color of the current ConOut device\r | |
665 | in the EFI_SYSTEM_TABLE is used.\r | |
666 | @param Format Null-terminated ASCII format string. See Print Library \r | |
667 | for the supported format string syntax.\r | |
668 | @param ... Variable argument list whose contents are accessed based on \r | |
669 | the format string specified by Format. \r | |
670 | \r | |
671 | @return The number of ASCII characters printed.\r | |
672 | \r | |
673 | **/\r | |
674 | UINTN\r | |
675 | EFIAPI\r | |
676 | AsciiPrintXY (\r | |
e115460b | 677 | IN UINTN PointX,\r |
678 | IN UINTN PointY,\r | |
bf428cb3 | 679 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL\r |
680 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL\r | |
681 | IN CONST CHAR8 *Format,\r | |
682 | ...\r | |
683 | )\r | |
684 | {\r | |
685 | VA_LIST Marker;\r | |
686 | CHAR16 *Buffer;\r | |
687 | UINTN BufferSize;\r | |
688 | UINTN PrintNum;\r | |
689 | UINTN ReturnNum;\r | |
690 | \r | |
691 | ASSERT (Format != NULL);\r | |
692 | \r | |
693 | VA_START (Marker, Format);\r | |
694 | \r | |
695 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
696 | \r | |
697 | Buffer = (CHAR16 *) AllocatePool (BufferSize);\r | |
698 | ASSERT (Buffer != NULL);\r | |
e115460b | 699 | \r |
bf428cb3 | 700 | PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r |
701 | \r | |
e115460b | 702 | ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r |
bf428cb3 | 703 | \r |
704 | FreePool (Buffer);\r | |
e115460b | 705 | \r |
bf428cb3 | 706 | return ReturnNum;\r |
707 | }\r | |
708 | \r |