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