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