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