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