]>
Commit | Line | Data |
---|---|---|
e386b444 | 1 | /** @file\r |
727501bb | 2 | Mde UEFI library API implementation.\r |
e386b444 | 3 | Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE\r |
4 | \r | |
9095d37b | 5 | Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e386b444 | 7 | \r |
8 | **/\r | |
9 | \r | |
f734a10a | 10 | #include "UefiLibInternal.h"\r |
e386b444 | 11 | \r |
0057fda6 | 12 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r |
b3154720 | 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 | |
e386b444 | 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 | |
f80b0830 | 39 | If Format is NULL, then ASSERT().\r |
40 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
e386b444 | 41 | \r |
58380e9c | 42 | @param Format A Null-terminated Unicode format string.\r |
e386b444 | 43 | @param Console The output console.\r |
58380e9c | 44 | @param Marker A VA_LIST marker for the variable argument list.\r |
73e4adbe | 45 | \r |
f80b0830 | 46 | @return The number of Unicode characters in the produced\r |
58380e9c | 47 | output buffer, not including the Null-terminator.\r |
e386b444 | 48 | **/\r |
e386b444 | 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 | |
cda8ba5e | 56 | EFI_STATUS Status;\r |
57 | UINTN Return;\r | |
58 | CHAR16 *Buffer;\r | |
59 | UINTN BufferSize;\r | |
e386b444 | 60 | \r |
61 | ASSERT (Format != NULL);\r | |
b3154720 | 62 | ASSERT (((UINTN) Format & BIT0) == 0);\r |
cda8ba5e | 63 | ASSERT (Console != NULL);\r |
e386b444 | 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 | |
2ad4dad0 | 72 | if (Console != NULL && Return > 0) {\r |
e386b444 | 73 | //\r |
74 | // To be extra safe make sure Console has been initialized\r | |
75 | //\r | |
cda8ba5e | 76 | Status = Console->OutputString (Console, Buffer);\r |
77 | if (EFI_ERROR (Status)) {\r | |
78 | Return = 0;\r | |
79 | }\r | |
e386b444 | 80 | }\r |
81 | \r | |
82 | FreePool (Buffer);\r | |
83 | \r | |
84 | return Return;\r | |
85 | }\r | |
86 | \r | |
9095d37b LG |
87 | /**\r |
88 | Prints a formatted Unicode string to the console output device specified by\r | |
e386b444 | 89 | ConOut defined in the EFI_SYSTEM_TABLE.\r |
90 | \r | |
9095d37b LG |
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 | |
e386b444 | 95 | PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r |
f80b0830 | 96 | If Format is NULL, then ASSERT().\r |
97 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
cda8ba5e | 98 | If gST->ConOut is NULL, then ASSERT().\r |
e386b444 | 99 | \r |
58380e9c | 100 | @param Format A Null-terminated Unicode format string.\r |
9095d37b | 101 | @param ... A Variable argument list whose contents are accessed based\r |
285010e7 | 102 | on the format string specified by Format.\r |
9095d37b | 103 | \r |
2fc59a00 | 104 | @return The number of Unicode characters printed to ConOut.\r |
e386b444 | 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 | |
9095d37b LG |
126 | /**\r |
127 | Prints a formatted Unicode string to the console output device specified by\r | |
e386b444 | 128 | StdErr defined in the EFI_SYSTEM_TABLE.\r |
129 | \r | |
9095d37b LG |
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 | |
e386b444 | 134 | PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r |
f80b0830 | 135 | If Format is NULL, then ASSERT().\r |
136 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
cda8ba5e | 137 | If gST->StdErr is NULL, then ASSERT().\r |
e386b444 | 138 | \r |
58380e9c | 139 | @param Format A Null-terminated Unicode format string.\r |
9095d37b | 140 | @param ... Variable argument list whose contents are accessed based\r |
285010e7 | 141 | on the format string specified by Format.\r |
9095d37b | 142 | \r |
2fc59a00 | 143 | @return The number of Unicode characters printed to StdErr.\r |
e386b444 | 144 | \r |
145 | **/\r | |
e386b444 | 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 | |
f80b0830 | 174 | \r |
175 | If Format is NULL, then ASSERT().\r | |
e386b444 | 176 | \r |
58380e9c | 177 | @param Format A Null-terminated ASCII format string.\r |
e386b444 | 178 | @param Console The output console.\r |
179 | @param Marker VA_LIST marker for the variable argument list.\r | |
180 | \r | |
f80b0830 | 181 | @return The number of Unicode characters in the produced\r |
182 | output buffer not including the Null-terminator.\r | |
e386b444 | 183 | \r |
184 | **/\r | |
e386b444 | 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 | |
cda8ba5e | 192 | EFI_STATUS Status;\r |
193 | UINTN Return;\r | |
194 | CHAR16 *Buffer;\r | |
195 | UINTN BufferSize;\r | |
e386b444 | 196 | \r |
197 | ASSERT (Format != NULL);\r | |
cda8ba5e | 198 | ASSERT (Console != NULL);\r |
e386b444 | 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 | |
cda8ba5e | 211 | Status = Console->OutputString (Console, Buffer);\r |
212 | if (EFI_ERROR (Status)) {\r | |
213 | Return = 0;\r | |
214 | }\r | |
e386b444 | 215 | }\r |
216 | \r | |
217 | FreePool (Buffer);\r | |
218 | \r | |
219 | return Return;\r | |
220 | }\r | |
221 | \r | |
9095d37b LG |
222 | /**\r |
223 | Prints a formatted ASCII string to the console output device specified by\r | |
e386b444 | 224 | ConOut defined in the EFI_SYSTEM_TABLE.\r |
225 | \r | |
9095d37b LG |
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 | |
e386b444 | 230 | PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r |
f80b0830 | 231 | If Format is NULL, then ASSERT().\r |
cda8ba5e | 232 | If gST->ConOut is NULL, then ASSERT().\r |
e386b444 | 233 | \r |
58380e9c | 234 | @param Format A Null-terminated ASCII format string.\r |
9095d37b | 235 | @param ... Variable argument list whose contents are accessed based\r |
285010e7 | 236 | on the format string specified by Format.\r |
9095d37b | 237 | \r |
2fc59a00 | 238 | @return The number of ASCII characters printed to ConOut.\r |
e386b444 | 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 | |
9edc73ad | 250 | ASSERT (Format != NULL);\r |
73e4adbe | 251 | \r |
e386b444 | 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 | |
9095d37b LG |
261 | /**\r |
262 | Prints a formatted ASCII string to the console output device specified by\r | |
e386b444 | 263 | StdErr defined in the EFI_SYSTEM_TABLE.\r |
264 | \r | |
9095d37b LG |
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 | |
e386b444 | 269 | PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r |
f80b0830 | 270 | If Format is NULL, then ASSERT().\r |
cda8ba5e | 271 | If gST->StdErr is NULL, then ASSERT().\r |
e386b444 | 272 | \r |
58380e9c | 273 | @param Format A Null-terminated ASCII format string.\r |
9095d37b | 274 | @param ... Variable argument list whose contents are accessed based\r |
285010e7 | 275 | on the format string specified by Format.\r |
9095d37b | 276 | \r |
2fc59a00 | 277 | @return The number of ASCII characters printed to ConErr.\r |
e386b444 | 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 | |
9edc73ad | 290 | ASSERT (Format != NULL);\r |
73e4adbe | 291 | \r |
e386b444 | 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 | |
b3154720 | 301 | /**\r |
73e4adbe | 302 | Internal function to print a formatted Unicode string to a graphics console device specified by\r |
b3154720 | 303 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r |
304 | \r | |
73e4adbe | 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 | |
b3154720 | 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 | |
73e4adbe | 312 | If a graphics console device is not associated with the ConsoleOutputHandle\r |
b3154720 | 313 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r |
73e4adbe | 314 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no\r |
b3154720 | 315 | string is printed, and 0 is returned.\r |
316 | \r | |
58380e9c | 317 | @param PointX An X coordinate to print the string.\r |
318 | @param PointY A Y coordinate to print the string.\r | |
51969ecb | 319 | @param Foreground The foreground color of the string being printed. This is\r |
b3154720 | 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 | |
a72edceb | 323 | @param Background The background color of the string being printed. This is\r |
73e4adbe | 324 | an optional parameter that may be NULL. If it is NULL,\r |
b3154720 | 325 | then the background color of the current ConOut device\r |
326 | in the EFI_SYSTEM_TABLE is used.\r | |
58380e9c | 327 | @param Buffer A Null-terminated Unicode formatted string.\r |
b3154720 | 328 | @param PrintNum The number of Unicode formatted string to be printed.\r |
329 | \r | |
2fc59a00 | 330 | @return The number of Unicode Characters printed. Zero means no any character\r |
b3154720 | 331 | displayed successfully.\r |
332 | \r | |
333 | **/\r | |
334 | UINTN\r | |
335 | InternalPrintGraphic (\r | |
51969ecb | 336 | IN UINTN PointX,\r |
337 | IN UINTN PointY,\r | |
b3154720 | 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 | |
b3154720 | 345 | UINT32 HorizontalResolution;\r |
346 | UINT32 VerticalResolution;\r | |
347 | UINT32 ColorDepth;\r | |
348 | UINT32 RefreshRate;\r | |
b3154720 | 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 | |
63fffe4e | 358 | UINTN Width;\r |
359 | UINTN Height;\r | |
360 | UINTN Delta;\r | |
b3154720 | 361 | \r |
362 | HorizontalResolution = 0;\r | |
363 | VerticalResolution = 0;\r | |
364 | Blt = NULL;\r | |
d9e63d93 | 365 | RowInfoArray = NULL;\r |
b3154720 | 366 | \r |
367 | ConsoleHandle = gST->ConsoleOutHandle;\r | |
9095d37b | 368 | \r |
cda8ba5e | 369 | ASSERT( ConsoleHandle != NULL);\r |
b3154720 | 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 | |
d9e63d93 | 391 | goto Error;\r |
b3154720 | 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 | |
d9e63d93 | 401 | goto Error;\r |
b3154720 | 402 | }\r |
403 | \r | |
404 | if (GraphicsOutput != NULL) {\r | |
405 | HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r | |
406 | VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r | |
73e4adbe | 407 | } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r |
b3154720 | 408 | UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r |
409 | } else {\r | |
b3154720 | 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 | |
b3154720 | 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 | |
73e4adbe | 449 | \r |
b3154720 | 450 | Status = HiiFont->StringToImage (\r |
451 | HiiFont,\r | |
d9e63d93 | 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 | |
b3154720 | 455 | Buffer,\r |
456 | &FontInfo,\r | |
457 | &Blt,\r | |
51969ecb | 458 | PointX,\r |
459 | PointY,\r | |
d9e63d93 | 460 | &RowInfoArray,\r |
461 | &RowInfoArraySize,\r | |
b3154720 | 462 | NULL\r |
463 | );\r | |
d9e63d93 | 464 | if (EFI_ERROR (Status)) {\r |
465 | goto Error;\r | |
466 | }\r | |
b3154720 | 467 | \r |
468 | } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r | |
469 | ASSERT (UgaDraw!= NULL);\r | |
470 | \r | |
458cd568 HW |
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 | |
b3154720 | 479 | ASSERT (Blt->Image.Bitmap != NULL);\r |
480 | \r | |
b3154720 | 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 | |
392b3cf8 | 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 | |
b3154720 | 490 | Buffer,\r |
491 | &FontInfo,\r | |
492 | &Blt,\r | |
51969ecb | 493 | PointX,\r |
494 | PointY,\r | |
b3154720 | 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 | |
57ee276f | 503 | // Explicit Line break characters are ignored, so the updated parameter RowInfoArraySize by StringToImage will\r |
b3154720 | 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 | |
63fffe4e | 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 | |
b3154720 | 517 | Status = UgaDraw->Blt (\r |
518 | UgaDraw,\r | |
519 | (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r | |
520 | EfiUgaBltBufferToVideo,\r | |
51969ecb | 521 | PointX,\r |
522 | PointY,\r | |
523 | PointX,\r | |
524 | PointY,\r | |
63fffe4e | 525 | Width,\r |
526 | Height,\r | |
527 | Delta\r | |
b3154720 | 528 | );\r |
d9e63d93 | 529 | } else {\r |
530 | goto Error;\r | |
b3154720 | 531 | }\r |
b3154720 | 532 | FreePool (Blt->Image.Bitmap);\r |
b3154720 | 533 | } else {\r |
d9e63d93 | 534 | goto Error;\r |
b3154720 | 535 | }\r |
d9e63d93 | 536 | //\r |
537 | // Calculate the number of actual printed characters\r | |
538 | //\r | |
63fffe4e | 539 | if (RowInfoArraySize != 0) {\r |
540 | PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;\r | |
541 | } else {\r | |
542 | PrintNum = 0;\r | |
543 | }\r | |
b3154720 | 544 | \r |
d9e63d93 | 545 | FreePool (RowInfoArray);\r |
b3154720 | 546 | FreePool (Blt);\r |
d9e63d93 | 547 | return PrintNum;\r |
b3154720 | 548 | \r |
549 | Error:\r | |
d9e63d93 | 550 | if (Blt != NULL) {\r |
551 | FreePool (Blt);\r | |
b3154720 | 552 | }\r |
d9e63d93 | 553 | return 0;\r |
b3154720 | 554 | }\r |
555 | \r | |
556 | /**\r | |
9095d37b | 557 | Prints a formatted Unicode string to a graphics console device specified by\r |
b3154720 | 558 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r |
559 | \r | |
9095d37b LG |
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 | |
b9c8d8bd | 563 | by the right edge of the display. If the length of the formatted Unicode string is\r |
9095d37b | 564 | greater than PcdUefiLibMaxPrintBufferSize, then at most the first\r |
d9e63d93 | 565 | PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL\r |
9095d37b LG |
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 | |
d9e63d93 | 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 | |
b3154720 | 571 | \r |
9095d37b | 572 | If a graphics console device is not associated with the ConsoleOutputHandle\r |
b3154720 | 573 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r |
9095d37b | 574 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no\r |
b3154720 | 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 | |
cda8ba5e | 578 | If gST->ConsoleOutputHandle is NULL, then ASSERT().\r |
b3154720 | 579 | \r |
58380e9c | 580 | @param PointX An X coordinate to print the string.\r |
581 | @param PointY A Y coordinate to print the string.\r | |
28d3e14f | 582 | @param ForeGround The foreground color of the string being printed. This is\r |
b3154720 | 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 | |
9095d37b | 587 | an optional parameter that may be NULL. If it is NULL,\r |
b3154720 | 588 | then the background color of the current ConOut device\r |
589 | in the EFI_SYSTEM_TABLE is used.\r | |
9095d37b | 590 | @param Format A Null-terminated Unicode format string. See Print Library\r |
b3154720 | 591 | for the supported format string syntax.\r |
9095d37b LG |
592 | @param ... A Variable argument list whose contents are accessed based on\r |
593 | the format string specified by Format.\r | |
b3154720 | 594 | \r |
cf8ae2f6 | 595 | @return The number of Unicode characters printed.\r |
b3154720 | 596 | \r |
597 | **/\r | |
598 | UINTN\r | |
599 | EFIAPI\r | |
600 | PrintXY (\r | |
51969ecb | 601 | IN UINTN PointX,\r |
602 | IN UINTN PointY,\r | |
b3154720 | 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 | |
73e4adbe | 624 | \r |
b3154720 | 625 | PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r |
626 | \r | |
3bbe68a3 | 627 | VA_END (Marker);\r |
628 | \r | |
51969ecb | 629 | ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r |
b3154720 | 630 | \r |
631 | FreePool (Buffer);\r | |
632 | \r | |
633 | return ReturnNum;\r | |
634 | }\r | |
635 | \r | |
636 | /**\r | |
9095d37b | 637 | Prints a formatted ASCII string to a graphics console device specified by\r |
b3154720 | 638 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r |
639 | \r | |
9095d37b LG |
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 | |
b9c8d8bd | 643 | by the right edge of the display. If the length of the formatted ASCII string is\r |
9095d37b | 644 | greater than PcdUefiLibMaxPrintBufferSize, then at most the first\r |
d9e63d93 | 645 | PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL\r |
9095d37b LG |
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 | |
d9e63d93 | 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 | |
b3154720 | 651 | \r |
9095d37b | 652 | If a graphics console device is not associated with the ConsoleOutputHandle\r |
b3154720 | 653 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r |
9095d37b | 654 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no\r |
b3154720 | 655 | string is printed, and 0 is returned.\r |
656 | If Format is NULL, then ASSERT().\r | |
cda8ba5e | 657 | If gST->ConsoleOutputHandle is NULL, then ASSERT().\r |
b3154720 | 658 | \r |
58380e9c | 659 | @param PointX An X coordinate to print the string.\r |
660 | @param PointY A Y coordinate to print the string.\r | |
28d3e14f | 661 | @param ForeGround The foreground color of the string being printed. This is\r |
b3154720 | 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 | |
9095d37b | 666 | an optional parameter that may be NULL. If it is NULL,\r |
b3154720 | 667 | then the background color of the current ConOut device\r |
668 | in the EFI_SYSTEM_TABLE is used.\r | |
9095d37b | 669 | @param Format A Null-terminated ASCII format string. See Print Library\r |
b3154720 | 670 | for the supported format string syntax.\r |
9095d37b LG |
671 | @param ... Variable argument list whose contents are accessed based on\r |
672 | the format string specified by Format.\r | |
b3154720 | 673 | \r |
cf8ae2f6 | 674 | @return The number of ASCII characters printed.\r |
b3154720 | 675 | \r |
676 | **/\r | |
677 | UINTN\r | |
678 | EFIAPI\r | |
679 | AsciiPrintXY (\r | |
51969ecb | 680 | IN UINTN PointX,\r |
681 | IN UINTN PointY,\r | |
b3154720 | 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 | |
73e4adbe | 702 | \r |
b3154720 | 703 | PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r |
704 | \r | |
3bbe68a3 | 705 | VA_END (Marker);\r |
706 | \r | |
51969ecb | 707 | ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r |
b3154720 | 708 | \r |
709 | FreePool (Buffer);\r | |
73e4adbe | 710 | \r |
b3154720 | 711 | return ReturnNum;\r |
712 | }\r | |
713 | \r | |
9095d37b | 714 | /**\r |
f405c067 | 715 | Appends a formatted Unicode string to a Null-terminated Unicode string\r |
9095d37b LG |
716 | \r |
717 | This function appends a formatted Unicode string to the Null-terminated\r | |
f405c067 | 718 | Unicode string specified by String. String is optional and may be NULL.\r |
9095d37b | 719 | Storage for the formatted Unicode string returned is allocated using\r |
f405c067 | 720 | AllocatePool(). The pointer to the appended string is returned. The caller\r |
721 | is responsible for freeing the returned string.\r | |
9095d37b | 722 | \r |
f405c067 | 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 | |
9095d37b | 726 | \r |
f405c067 | 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 | |
9095d37b | 732 | @return Null-terminated Unicode string is that is the formatted\r |
f405c067 | 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 | |
265fa9fa | 746 | VA_LIST ExtraMarker;\r |
f405c067 | 747 | \r |
265fa9fa | 748 | VA_COPY (ExtraMarker, Marker);\r |
749 | CharactersRequired = SPrintLength(FormatString, ExtraMarker);\r | |
750 | VA_END (ExtraMarker);\r | |
f405c067 | 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 | |
a3f28ac9 | 758 | BufferToReturn = AllocatePool(SizeRequired);\r |
f405c067 | 759 | \r |
760 | if (BufferToReturn == NULL) {\r | |
761 | return NULL;\r | |
a3f28ac9 HW |
762 | } else {\r |
763 | BufferToReturn[0] = L'\0';\r | |
f405c067 | 764 | }\r |
a3f28ac9 | 765 | \r |
228593f9 | 766 | if (String != NULL) {\r |
a3f28ac9 | 767 | StrCpyS(BufferToReturn, SizeRequired / sizeof(CHAR16), String);\r |
228593f9 | 768 | }\r |
f405c067 | 769 | \r |
f405c067 | 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 | |
9095d37b | 777 | /**\r |
f405c067 | 778 | Appends a formatted Unicode string to a Null-terminated Unicode string\r |
9095d37b LG |
779 | \r |
780 | This function appends a formatted Unicode string to the Null-terminated\r | |
f405c067 | 781 | Unicode string specified by String. String is optional and may be NULL.\r |
9095d37b | 782 | Storage for the formatted Unicode string returned is allocated using\r |
f405c067 | 783 | AllocatePool(). The pointer to the appended string is returned. The caller\r |
784 | is responsible for freeing the returned string.\r | |
9095d37b | 785 | \r |
f405c067 | 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 | |
9095d37b | 789 | \r |
f405c067 | 790 | @param[in] String A Null-terminated Unicode string.\r |
791 | @param[in] FormatString A Null-terminated Unicode format string.\r | |
9095d37b LG |
792 | @param[in] ... The variable argument list whose contents are\r |
793 | accessed based on the format string specified by\r | |
f405c067 | 794 | FormatString.\r |
795 | \r | |
796 | @retval NULL There was not enough available memory.\r | |
9095d37b | 797 | @return Null-terminated Unicode string is that is the formatted\r |
f405c067 | 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 | |
3bbe68a3 | 809 | CHAR16 *NewString;\r |
810 | \r | |
f405c067 | 811 | VA_START (Marker, FormatString);\r |
3bbe68a3 | 812 | NewString = CatVSPrint(String, FormatString, Marker);\r |
813 | VA_END (Marker);\r | |
814 | return NewString;\r | |
f405c067 | 815 | }\r |
816 | \r |