]>
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 |
2f88bd3a | 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 | |
2f88bd3a | 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 | |
2f88bd3a | 67 | Buffer = (CHAR16 *)AllocatePool (BufferSize);\r |
e386b444 | 68 | ASSERT (Buffer != NULL);\r |
69 | \r | |
70 | Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r | |
71 | \r | |
2f88bd3a | 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 | |
2f88bd3a MK |
114 | VA_LIST Marker;\r |
115 | UINTN Return;\r | |
e386b444 | 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 | |
2f88bd3a MK |
153 | VA_LIST Marker;\r |
154 | UINTN Return;\r | |
e386b444 | 155 | \r |
156 | VA_START (Marker, Format);\r | |
157 | \r | |
2f88bd3a | 158 | Return = InternalPrint (Format, gST->StdErr, Marker);\r |
e386b444 | 159 | \r |
160 | VA_END (Marker);\r | |
161 | \r | |
162 | return Return;\r | |
163 | }\r | |
164 | \r | |
e386b444 | 165 | /**\r |
166 | Internal function which prints a formatted ASCII string to the console output device\r | |
167 | specified by Console\r | |
168 | \r | |
169 | This function prints a formatted ASCII string to the console output device\r | |
170 | specified by Console and returns the number of ASCII characters that printed\r | |
171 | to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,\r | |
172 | then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r | |
f80b0830 | 173 | \r |
174 | If Format is NULL, then ASSERT().\r | |
e386b444 | 175 | \r |
58380e9c | 176 | @param Format A Null-terminated ASCII format string.\r |
e386b444 | 177 | @param Console The output console.\r |
178 | @param Marker VA_LIST marker for the variable argument list.\r | |
179 | \r | |
f80b0830 | 180 | @return The number of Unicode characters in the produced\r |
181 | output buffer not including the Null-terminator.\r | |
e386b444 | 182 | \r |
183 | **/\r | |
e386b444 | 184 | UINTN\r |
185 | AsciiInternalPrint (\r | |
186 | IN CONST CHAR8 *Format,\r | |
187 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r | |
188 | IN VA_LIST Marker\r | |
189 | )\r | |
190 | {\r | |
cda8ba5e | 191 | EFI_STATUS Status;\r |
192 | UINTN Return;\r | |
193 | CHAR16 *Buffer;\r | |
194 | UINTN BufferSize;\r | |
e386b444 | 195 | \r |
196 | ASSERT (Format != NULL);\r | |
cda8ba5e | 197 | ASSERT (Console != NULL);\r |
e386b444 | 198 | \r |
199 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
200 | \r | |
2f88bd3a | 201 | Buffer = (CHAR16 *)AllocatePool (BufferSize);\r |
e386b444 | 202 | ASSERT (Buffer != NULL);\r |
203 | \r | |
204 | Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r | |
205 | \r | |
206 | if (Console != NULL) {\r | |
207 | //\r | |
208 | // To be extra safe make sure Console has been initialized\r | |
209 | //\r | |
cda8ba5e | 210 | Status = Console->OutputString (Console, Buffer);\r |
211 | if (EFI_ERROR (Status)) {\r | |
212 | Return = 0;\r | |
213 | }\r | |
e386b444 | 214 | }\r |
215 | \r | |
216 | FreePool (Buffer);\r | |
217 | \r | |
218 | return Return;\r | |
219 | }\r | |
220 | \r | |
9095d37b LG |
221 | /**\r |
222 | Prints a formatted ASCII string to the console output device specified by\r | |
e386b444 | 223 | ConOut defined in the EFI_SYSTEM_TABLE.\r |
224 | \r | |
9095d37b LG |
225 | This function prints a formatted ASCII string to the console output device\r |
226 | specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII\r | |
227 | characters that printed to ConOut. If the length of the formatted ASCII\r | |
228 | string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r | |
e386b444 | 229 | PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r |
f80b0830 | 230 | If Format is NULL, then ASSERT().\r |
cda8ba5e | 231 | If gST->ConOut is NULL, then ASSERT().\r |
e386b444 | 232 | \r |
58380e9c | 233 | @param Format A Null-terminated ASCII format string.\r |
9095d37b | 234 | @param ... Variable argument list whose contents are accessed based\r |
285010e7 | 235 | on the format string specified by Format.\r |
9095d37b | 236 | \r |
2fc59a00 | 237 | @return The number of ASCII characters printed to ConOut.\r |
e386b444 | 238 | \r |
239 | **/\r | |
240 | UINTN\r | |
241 | EFIAPI\r | |
242 | AsciiPrint (\r | |
243 | IN CONST CHAR8 *Format,\r | |
244 | ...\r | |
245 | )\r | |
246 | {\r | |
2f88bd3a MK |
247 | VA_LIST Marker;\r |
248 | UINTN Return;\r | |
249 | \r | |
9edc73ad | 250 | ASSERT (Format != NULL);\r |
73e4adbe | 251 | \r |
e386b444 | 252 | VA_START (Marker, Format);\r |
253 | \r | |
2f88bd3a | 254 | Return = AsciiInternalPrint (Format, gST->ConOut, Marker);\r |
e386b444 | 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 | |
2f88bd3a MK |
287 | VA_LIST Marker;\r |
288 | UINTN Return;\r | |
e386b444 | 289 | \r |
9edc73ad | 290 | ASSERT (Format != NULL);\r |
73e4adbe | 291 | \r |
e386b444 | 292 | VA_START (Marker, Format);\r |
293 | \r | |
2f88bd3a | 294 | Return = AsciiInternalPrint (Format, gST->StdErr, Marker);\r |
e386b444 | 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 | |
2f88bd3a MK |
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 | |
b3154720 | 342 | )\r |
343 | {\r | |
2f88bd3a MK |
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 | |
b3154720 | 366 | \r |
367 | ConsoleHandle = gST->ConsoleOutHandle;\r | |
9095d37b | 368 | \r |
2f88bd3a | 369 | ASSERT (ConsoleHandle != NULL);\r |
b3154720 | 370 | \r |
371 | Status = gBS->HandleProtocol (\r | |
372 | ConsoleHandle,\r | |
373 | &gEfiGraphicsOutputProtocolGuid,\r | |
2f88bd3a | 374 | (VOID **)&GraphicsOutput\r |
b3154720 | 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 | |
2f88bd3a | 387 | (VOID **)&UgaDraw\r |
b3154720 | 388 | );\r |
389 | }\r | |
2f88bd3a | 390 | \r |
b3154720 | 391 | if (EFI_ERROR (Status)) {\r |
d9e63d93 | 392 | goto Error;\r |
b3154720 | 393 | }\r |
394 | \r | |
395 | Status = gBS->HandleProtocol (\r | |
396 | ConsoleHandle,\r | |
397 | &gEfiSimpleTextOutProtocolGuid,\r | |
2f88bd3a | 398 | (VOID **)&Sto\r |
b3154720 | 399 | );\r |
400 | \r | |
401 | if (EFI_ERROR (Status)) {\r | |
d9e63d93 | 402 | goto Error;\r |
b3154720 | 403 | }\r |
404 | \r | |
405 | if (GraphicsOutput != NULL) {\r | |
406 | HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r | |
2f88bd3a MK |
407 | VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r |
408 | } else if ((UgaDraw != NULL) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r | |
b3154720 | 409 | UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r |
410 | } else {\r | |
b3154720 | 411 | goto Error;\r |
412 | }\r | |
413 | \r | |
2f88bd3a | 414 | ASSERT ((HorizontalResolution != 0) && (VerticalResolution != 0));\r |
b3154720 | 415 | \r |
2f88bd3a | 416 | Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **)&HiiFont);\r |
b3154720 | 417 | if (EFI_ERROR (Status)) {\r |
418 | goto Error;\r | |
419 | }\r | |
420 | \r | |
2f88bd3a | 421 | Blt = (EFI_IMAGE_OUTPUT *)AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r |
b3154720 | 422 | ASSERT (Blt != NULL);\r |
423 | \r | |
2f88bd3a MK |
424 | Blt->Width = (UINT16)(HorizontalResolution);\r |
425 | Blt->Height = (UINT16)(VerticalResolution);\r | |
b3154720 | 426 | \r |
427 | ZeroMem (&FontInfo, sizeof (EFI_FONT_DISPLAY_INFO));\r | |
428 | \r | |
429 | if (Foreground != NULL) {\r | |
430 | CopyMem (&FontInfo.ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r | |
431 | } else {\r | |
432 | CopyMem (\r | |
433 | &FontInfo.ForegroundColor,\r | |
434 | &mEfiColors[Sto->Mode->Attribute & 0x0f],\r | |
435 | sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
436 | );\r | |
437 | }\r | |
2f88bd3a | 438 | \r |
b3154720 | 439 | if (Background != NULL) {\r |
440 | CopyMem (&FontInfo.BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r | |
441 | } else {\r | |
442 | CopyMem (\r | |
443 | &FontInfo.BackgroundColor,\r | |
444 | &mEfiColors[Sto->Mode->Attribute >> 4],\r | |
445 | sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
446 | );\r | |
447 | }\r | |
448 | \r | |
449 | if (GraphicsOutput != NULL) {\r | |
450 | Blt->Image.Screen = GraphicsOutput;\r | |
73e4adbe | 451 | \r |
b3154720 | 452 | Status = HiiFont->StringToImage (\r |
2f88bd3a MK |
453 | HiiFont,\r |
454 | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |\r | |
455 | EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |\r | |
456 | EFI_HII_IGNORE_LINE_BREAK | EFI_HII_DIRECT_TO_SCREEN,\r | |
457 | Buffer,\r | |
458 | &FontInfo,\r | |
459 | &Blt,\r | |
460 | PointX,\r | |
461 | PointY,\r | |
462 | &RowInfoArray,\r | |
463 | &RowInfoArraySize,\r | |
464 | NULL\r | |
465 | );\r | |
d9e63d93 | 466 | if (EFI_ERROR (Status)) {\r |
467 | goto Error;\r | |
468 | }\r | |
b3154720 | 469 | } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r |
2f88bd3a | 470 | ASSERT (UgaDraw != NULL);\r |
b3154720 | 471 | \r |
458cd568 HW |
472 | //\r |
473 | // Ensure Width * Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow.\r | |
474 | //\r | |
475 | if (Blt->Width > DivU64x32 (MAX_UINTN, Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {\r | |
476 | goto Error;\r | |
477 | }\r | |
478 | \r | |
2f88bd3a | 479 | Blt->Image.Bitmap = AllocateZeroPool ((UINT32)Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r |
b3154720 | 480 | ASSERT (Blt->Image.Bitmap != NULL);\r |
481 | \r | |
b3154720 | 482 | //\r |
483 | // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,\r | |
484 | // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.\r | |
485 | //\r | |
486 | Status = HiiFont->StringToImage (\r | |
2f88bd3a MK |
487 | HiiFont,\r |
488 | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |\r | |
489 | EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |\r | |
490 | EFI_HII_IGNORE_LINE_BREAK,\r | |
491 | Buffer,\r | |
492 | &FontInfo,\r | |
493 | &Blt,\r | |
494 | PointX,\r | |
495 | PointY,\r | |
496 | &RowInfoArray,\r | |
497 | &RowInfoArraySize,\r | |
498 | NULL\r | |
499 | );\r | |
b3154720 | 500 | \r |
501 | if (!EFI_ERROR (Status)) {\r | |
502 | ASSERT (RowInfoArray != NULL);\r | |
503 | //\r | |
57ee276f | 504 | // Explicit Line break characters are ignored, so the updated parameter RowInfoArraySize by StringToImage will\r |
b3154720 | 505 | // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.\r |
506 | //\r | |
507 | ASSERT (RowInfoArraySize <= 1);\r | |
508 | \r | |
63fffe4e | 509 | if (RowInfoArraySize != 0) {\r |
510 | Width = RowInfoArray[0].LineWidth;\r | |
511 | Height = RowInfoArray[0].LineHeight;\r | |
512 | Delta = Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r | |
513 | } else {\r | |
514 | Width = 0;\r | |
515 | Height = 0;\r | |
516 | Delta = 0;\r | |
517 | }\r | |
2f88bd3a | 518 | \r |
b3154720 | 519 | Status = UgaDraw->Blt (\r |
520 | UgaDraw,\r | |
2f88bd3a | 521 | (EFI_UGA_PIXEL *)Blt->Image.Bitmap,\r |
b3154720 | 522 | EfiUgaBltBufferToVideo,\r |
51969ecb | 523 | PointX,\r |
524 | PointY,\r | |
525 | PointX,\r | |
526 | PointY,\r | |
63fffe4e | 527 | Width,\r |
528 | Height,\r | |
529 | Delta\r | |
b3154720 | 530 | );\r |
d9e63d93 | 531 | } else {\r |
532 | goto Error;\r | |
b3154720 | 533 | }\r |
2f88bd3a | 534 | \r |
b3154720 | 535 | FreePool (Blt->Image.Bitmap);\r |
b3154720 | 536 | } else {\r |
d9e63d93 | 537 | goto Error;\r |
b3154720 | 538 | }\r |
2f88bd3a | 539 | \r |
d9e63d93 | 540 | //\r |
541 | // Calculate the number of actual printed characters\r | |
542 | //\r | |
63fffe4e | 543 | if (RowInfoArraySize != 0) {\r |
544 | PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;\r | |
545 | } else {\r | |
546 | PrintNum = 0;\r | |
547 | }\r | |
b3154720 | 548 | \r |
d9e63d93 | 549 | FreePool (RowInfoArray);\r |
b3154720 | 550 | FreePool (Blt);\r |
d9e63d93 | 551 | return PrintNum;\r |
b3154720 | 552 | \r |
553 | Error:\r | |
d9e63d93 | 554 | if (Blt != NULL) {\r |
555 | FreePool (Blt);\r | |
b3154720 | 556 | }\r |
2f88bd3a | 557 | \r |
d9e63d93 | 558 | return 0;\r |
b3154720 | 559 | }\r |
560 | \r | |
561 | /**\r | |
9095d37b | 562 | Prints a formatted Unicode string to a graphics console device specified by\r |
b3154720 | 563 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r |
564 | \r | |
9095d37b LG |
565 | This function prints a formatted Unicode string to the graphics console device\r |
566 | specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of\r | |
567 | Unicode characters displayed, not including partial characters that may be clipped\r | |
b9c8d8bd | 568 | by the right edge of the display. If the length of the formatted Unicode string is\r |
9095d37b | 569 | greater than PcdUefiLibMaxPrintBufferSize, then at most the first\r |
d9e63d93 | 570 | PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL\r |
9095d37b LG |
571 | StringToImage() service is used to convert the string to a bitmap using the glyphs\r |
572 | registered with the HII database. No wrapping is performed, so any portions of the\r | |
573 | string the fall outside the active display region will not be displayed. Please see\r | |
d9e63d93 | 574 | Section 27.2.6 of the UEFI Specification for a description of the supported string\r |
575 | format including the set of control codes supported by the StringToImage() service.\r | |
b3154720 | 576 | \r |
9095d37b | 577 | If a graphics console device is not associated with the ConsoleOutputHandle\r |
b3154720 | 578 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r |
9095d37b | 579 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no\r |
b3154720 | 580 | string is printed, and 0 is returned.\r |
581 | If Format is NULL, then ASSERT().\r | |
582 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
cda8ba5e | 583 | If gST->ConsoleOutputHandle is NULL, then ASSERT().\r |
b3154720 | 584 | \r |
58380e9c | 585 | @param PointX An X coordinate to print the string.\r |
586 | @param PointY A Y coordinate to print the string.\r | |
28d3e14f | 587 | @param ForeGround The foreground color of the string being printed. This is\r |
b3154720 | 588 | an optional parameter that may be NULL. If it is NULL,\r |
589 | then the foreground color of the current ConOut device\r | |
590 | in the EFI_SYSTEM_TABLE is used.\r | |
591 | @param BackGround The background color of the string being printed. This is\r | |
9095d37b | 592 | an optional parameter that may be NULL. If it is NULL,\r |
b3154720 | 593 | then the background color of the current ConOut device\r |
594 | in the EFI_SYSTEM_TABLE is used.\r | |
9095d37b | 595 | @param Format A Null-terminated Unicode format string. See Print Library\r |
b3154720 | 596 | for the supported format string syntax.\r |
9095d37b LG |
597 | @param ... A Variable argument list whose contents are accessed based on\r |
598 | the format string specified by Format.\r | |
b3154720 | 599 | \r |
cf8ae2f6 | 600 | @return The number of Unicode characters printed.\r |
b3154720 | 601 | \r |
602 | **/\r | |
603 | UINTN\r | |
604 | EFIAPI\r | |
605 | PrintXY (\r | |
2f88bd3a MK |
606 | IN UINTN PointX,\r |
607 | IN UINTN PointY,\r | |
608 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL,\r | |
609 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL,\r | |
610 | IN CONST CHAR16 *Format,\r | |
b3154720 | 611 | ...\r |
612 | )\r | |
613 | {\r | |
2f88bd3a MK |
614 | VA_LIST Marker;\r |
615 | CHAR16 *Buffer;\r | |
616 | UINTN BufferSize;\r | |
617 | UINTN PrintNum;\r | |
618 | UINTN ReturnNum;\r | |
b3154720 | 619 | \r |
620 | ASSERT (Format != NULL);\r | |
2f88bd3a | 621 | ASSERT (((UINTN)Format & BIT0) == 0);\r |
b3154720 | 622 | \r |
623 | VA_START (Marker, Format);\r | |
624 | \r | |
625 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
626 | \r | |
2f88bd3a | 627 | Buffer = (CHAR16 *)AllocatePool (BufferSize);\r |
b3154720 | 628 | ASSERT (Buffer != NULL);\r |
73e4adbe | 629 | \r |
b3154720 | 630 | PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r |
631 | \r | |
3bbe68a3 | 632 | VA_END (Marker);\r |
633 | \r | |
51969ecb | 634 | ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r |
b3154720 | 635 | \r |
636 | FreePool (Buffer);\r | |
637 | \r | |
638 | return ReturnNum;\r | |
639 | }\r | |
640 | \r | |
641 | /**\r | |
9095d37b | 642 | Prints a formatted ASCII string to a graphics console device specified by\r |
b3154720 | 643 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r |
644 | \r | |
9095d37b LG |
645 | This function prints a formatted ASCII string to the graphics console device\r |
646 | specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of\r | |
647 | ASCII characters displayed, not including partial characters that may be clipped\r | |
b9c8d8bd | 648 | by the right edge of the display. If the length of the formatted ASCII string is\r |
9095d37b | 649 | greater than PcdUefiLibMaxPrintBufferSize, then at most the first\r |
d9e63d93 | 650 | PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL\r |
9095d37b LG |
651 | StringToImage() service is used to convert the string to a bitmap using the glyphs\r |
652 | registered with the HII database. No wrapping is performed, so any portions of the\r | |
653 | string the fall outside the active display region will not be displayed. Please see\r | |
d9e63d93 | 654 | Section 27.2.6 of the UEFI Specification for a description of the supported string\r |
655 | format including the set of control codes supported by the StringToImage() service.\r | |
b3154720 | 656 | \r |
9095d37b | 657 | If a graphics console device is not associated with the ConsoleOutputHandle\r |
b3154720 | 658 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r |
9095d37b | 659 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no\r |
b3154720 | 660 | string is printed, and 0 is returned.\r |
661 | If Format is NULL, then ASSERT().\r | |
cda8ba5e | 662 | If gST->ConsoleOutputHandle is NULL, then ASSERT().\r |
b3154720 | 663 | \r |
58380e9c | 664 | @param PointX An X coordinate to print the string.\r |
665 | @param PointY A Y coordinate to print the string.\r | |
28d3e14f | 666 | @param ForeGround The foreground color of the string being printed. This is\r |
b3154720 | 667 | an optional parameter that may be NULL. If it is NULL,\r |
668 | then the foreground color of the current ConOut device\r | |
669 | in the EFI_SYSTEM_TABLE is used.\r | |
670 | @param BackGround The background color of the string being printed. This is\r | |
9095d37b | 671 | an optional parameter that may be NULL. If it is NULL,\r |
b3154720 | 672 | then the background color of the current ConOut device\r |
673 | in the EFI_SYSTEM_TABLE is used.\r | |
9095d37b | 674 | @param Format A Null-terminated ASCII format string. See Print Library\r |
b3154720 | 675 | for the supported format string syntax.\r |
9095d37b LG |
676 | @param ... Variable argument list whose contents are accessed based on\r |
677 | the format string specified by Format.\r | |
b3154720 | 678 | \r |
cf8ae2f6 | 679 | @return The number of ASCII characters printed.\r |
b3154720 | 680 | \r |
681 | **/\r | |
682 | UINTN\r | |
683 | EFIAPI\r | |
684 | AsciiPrintXY (\r | |
2f88bd3a MK |
685 | IN UINTN PointX,\r |
686 | IN UINTN PointY,\r | |
687 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL,\r | |
688 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL,\r | |
689 | IN CONST CHAR8 *Format,\r | |
b3154720 | 690 | ...\r |
691 | )\r | |
692 | {\r | |
2f88bd3a MK |
693 | VA_LIST Marker;\r |
694 | CHAR16 *Buffer;\r | |
695 | UINTN BufferSize;\r | |
696 | UINTN PrintNum;\r | |
697 | UINTN ReturnNum;\r | |
b3154720 | 698 | \r |
699 | ASSERT (Format != NULL);\r | |
700 | \r | |
701 | VA_START (Marker, Format);\r | |
702 | \r | |
703 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
704 | \r | |
2f88bd3a | 705 | Buffer = (CHAR16 *)AllocatePool (BufferSize);\r |
b3154720 | 706 | ASSERT (Buffer != NULL);\r |
73e4adbe | 707 | \r |
b3154720 | 708 | PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r |
709 | \r | |
3bbe68a3 | 710 | VA_END (Marker);\r |
711 | \r | |
51969ecb | 712 | ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r |
b3154720 | 713 | \r |
714 | FreePool (Buffer);\r | |
73e4adbe | 715 | \r |
b3154720 | 716 | return ReturnNum;\r |
717 | }\r | |
718 | \r | |
9095d37b | 719 | /**\r |
f405c067 | 720 | Appends a formatted Unicode string to a Null-terminated Unicode string\r |
9095d37b LG |
721 | \r |
722 | This function appends a formatted Unicode string to the Null-terminated\r | |
f405c067 | 723 | Unicode string specified by String. String is optional and may be NULL.\r |
9095d37b | 724 | Storage for the formatted Unicode string returned is allocated using\r |
f405c067 | 725 | AllocatePool(). The pointer to the appended string is returned. The caller\r |
726 | is responsible for freeing the returned string.\r | |
9095d37b | 727 | \r |
f405c067 | 728 | If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().\r |
729 | If FormatString is NULL, then ASSERT().\r | |
730 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r | |
9095d37b | 731 | \r |
f405c067 | 732 | @param[in] String A Null-terminated Unicode string.\r |
733 | @param[in] FormatString A Null-terminated Unicode format string.\r | |
734 | @param[in] Marker VA_LIST marker for the variable argument list.\r | |
735 | \r | |
736 | @retval NULL There was not enough available memory.\r | |
9095d37b | 737 | @return Null-terminated Unicode string is that is the formatted\r |
f405c067 | 738 | string appended to String.\r |
739 | **/\r | |
2f88bd3a | 740 | CHAR16 *\r |
f405c067 | 741 | EFIAPI\r |
742 | CatVSPrint (\r | |
2f88bd3a | 743 | IN CHAR16 *String OPTIONAL,\r |
f405c067 | 744 | IN CONST CHAR16 *FormatString,\r |
745 | IN VA_LIST Marker\r | |
746 | )\r | |
747 | {\r | |
2f88bd3a MK |
748 | UINTN CharactersRequired;\r |
749 | UINTN SizeRequired;\r | |
750 | CHAR16 *BufferToReturn;\r | |
751 | VA_LIST ExtraMarker;\r | |
f405c067 | 752 | \r |
265fa9fa | 753 | VA_COPY (ExtraMarker, Marker);\r |
2f88bd3a | 754 | CharactersRequired = SPrintLength (FormatString, ExtraMarker);\r |
265fa9fa | 755 | VA_END (ExtraMarker);\r |
f405c067 | 756 | \r |
757 | if (String != NULL) {\r | |
2f88bd3a | 758 | SizeRequired = StrSize (String) + (CharactersRequired * sizeof (CHAR16));\r |
f405c067 | 759 | } else {\r |
2f88bd3a | 760 | SizeRequired = sizeof (CHAR16) + (CharactersRequired * sizeof (CHAR16));\r |
f405c067 | 761 | }\r |
762 | \r | |
2f88bd3a | 763 | BufferToReturn = AllocatePool (SizeRequired);\r |
f405c067 | 764 | \r |
765 | if (BufferToReturn == NULL) {\r | |
766 | return NULL;\r | |
a3f28ac9 HW |
767 | } else {\r |
768 | BufferToReturn[0] = L'\0';\r | |
f405c067 | 769 | }\r |
a3f28ac9 | 770 | \r |
228593f9 | 771 | if (String != NULL) {\r |
2f88bd3a | 772 | StrCpyS (BufferToReturn, SizeRequired / sizeof (CHAR16), String);\r |
228593f9 | 773 | }\r |
f405c067 | 774 | \r |
2f88bd3a | 775 | UnicodeVSPrint (BufferToReturn + StrLen (BufferToReturn), (CharactersRequired+1) * sizeof (CHAR16), FormatString, Marker);\r |
f405c067 | 776 | \r |
2f88bd3a | 777 | ASSERT (StrSize (BufferToReturn) == SizeRequired);\r |
f405c067 | 778 | \r |
779 | return (BufferToReturn);\r | |
780 | }\r | |
781 | \r | |
9095d37b | 782 | /**\r |
f405c067 | 783 | Appends a formatted Unicode string to a Null-terminated Unicode string\r |
9095d37b LG |
784 | \r |
785 | This function appends a formatted Unicode string to the Null-terminated\r | |
f405c067 | 786 | Unicode string specified by String. String is optional and may be NULL.\r |
9095d37b | 787 | Storage for the formatted Unicode string returned is allocated using\r |
f405c067 | 788 | AllocatePool(). The pointer to the appended string is returned. The caller\r |
789 | is responsible for freeing the returned string.\r | |
9095d37b | 790 | \r |
f405c067 | 791 | If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().\r |
792 | If FormatString is NULL, then ASSERT().\r | |
793 | If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r | |
9095d37b | 794 | \r |
f405c067 | 795 | @param[in] String A Null-terminated Unicode string.\r |
796 | @param[in] FormatString A Null-terminated Unicode format string.\r | |
9095d37b LG |
797 | @param[in] ... The variable argument list whose contents are\r |
798 | accessed based on the format string specified by\r | |
f405c067 | 799 | FormatString.\r |
800 | \r | |
801 | @retval NULL There was not enough available memory.\r | |
9095d37b | 802 | @return Null-terminated Unicode string is that is the formatted\r |
f405c067 | 803 | string appended to String.\r |
804 | **/\r | |
805 | CHAR16 *\r | |
806 | EFIAPI\r | |
807 | CatSPrint (\r | |
2f88bd3a | 808 | IN CHAR16 *String OPTIONAL,\r |
f405c067 | 809 | IN CONST CHAR16 *FormatString,\r |
810 | ...\r | |
811 | )\r | |
812 | {\r | |
2f88bd3a MK |
813 | VA_LIST Marker;\r |
814 | CHAR16 *NewString;\r | |
3bbe68a3 | 815 | \r |
f405c067 | 816 | VA_START (Marker, FormatString);\r |
2f88bd3a | 817 | NewString = CatVSPrint (String, FormatString, Marker);\r |
3bbe68a3 | 818 | VA_END (Marker);\r |
819 | return NewString;\r | |
f405c067 | 820 | }\r |