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