]>
Commit | Line | Data |
---|---|---|
79964ac8 | 1 | /** @file\r |
619e4c06 | 2 | Mde UEFI library API implementation.\r |
79964ac8 | 3 | Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE\r |
4 | \r | |
2b3687db HT |
5 | Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>\r |
6 | This program and the accompanying materials\r | |
79964ac8 | 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 | |
bf428cb3 | 16 | #include "UefiLibInternal.h"\r |
17 | \r | |
18 | GLOBAL_REMOVE_IF_UNREFERENCED 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 | |
79964ac8 | 36 | \r |
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 | |
bf428cb3 | 45 | If Format is NULL, then ASSERT().\r |
46 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
79964ac8 | 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 | |
e115460b | 51 | \r |
bf428cb3 | 52 | @return The number of Unicode characters in the produced\r |
53 | output buffer not including the Null-terminator.\r | |
79964ac8 | 54 | **/\r |
79964ac8 | 55 | UINTN\r |
56 | InternalPrint (\r | |
b51e6bc4 | 57 | IN CONST CHAR16 *Format,\r |
58 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r | |
59 | IN VA_LIST Marker\r | |
79964ac8 | 60 | )\r |
61 | {\r | |
62 | UINTN Return;\r | |
63 | CHAR16 *Buffer;\r | |
64 | UINTN BufferSize;\r | |
65 | \r | |
66 | ASSERT (Format != NULL);\r | |
bf428cb3 | 67 | ASSERT (((UINTN) Format & BIT0) == 0);\r |
79964ac8 | 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 | |
bf428cb3 | 76 | if (Console != NULL && Return > 0) {\r |
79964ac8 | 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 | |
bf428cb3 | 88 | /** \r |
89 | Prints a formatted Unicode string to the console output device specified by \r | |
79964ac8 | 90 | ConOut defined in the EFI_SYSTEM_TABLE.\r |
91 | \r | |
bf428cb3 | 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 | |
79964ac8 | 96 | PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r |
bf428cb3 | 97 | If Format is NULL, then ASSERT().\r |
98 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
79964ac8 | 99 | \r |
100 | @param Format Null-terminated Unicode format string.\r | |
00a1f552 | 101 | @param ... Variable argument list whose contents are accessed based \r |
102 | on the format string specified by Format.\r | |
bf428cb3 | 103 | \r |
104 | @return Number of Unicode characters printed to ConOut.\r | |
79964ac8 | 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 | |
bf428cb3 | 126 | /** \r |
127 | Prints a formatted Unicode string to the console output device specified by \r | |
79964ac8 | 128 | StdErr defined in the EFI_SYSTEM_TABLE.\r |
129 | \r | |
bf428cb3 | 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 | |
79964ac8 | 134 | PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r |
bf428cb3 | 135 | If Format is NULL, then ASSERT().\r |
136 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
79964ac8 | 137 | \r |
138 | @param Format Null-terminated Unicode format string.\r | |
00a1f552 | 139 | @param ... Variable argument list whose contents are accessed based \r |
140 | on the format string specified by Format.\r | |
bf428cb3 | 141 | \r |
142 | @return Number of Unicode characters printed to StdErr.\r | |
79964ac8 | 143 | \r |
144 | **/\r | |
79964ac8 | 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 | |
173 | \r | |
bf428cb3 | 174 | If Format is NULL, then ASSERT().\r |
175 | \r | |
79964ac8 | 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 | |
bf428cb3 | 180 | @return The number of Unicode characters in the produced\r |
181 | output buffer not including the Null-terminator.\r | |
79964ac8 | 182 | \r |
183 | **/\r | |
79964ac8 | 184 | UINTN\r |
185 | AsciiInternalPrint (\r | |
b51e6bc4 | 186 | IN CONST CHAR8 *Format,\r |
187 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r | |
188 | IN VA_LIST Marker\r | |
79964ac8 | 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 | |
bf428cb3 | 216 | /** \r |
217 | Prints a formatted ASCII string to the console output device specified by \r | |
79964ac8 | 218 | ConOut defined in the EFI_SYSTEM_TABLE.\r |
219 | \r | |
bf428cb3 | 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 | |
79964ac8 | 224 | PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r |
bf428cb3 | 225 | If Format is NULL, then ASSERT().\r |
79964ac8 | 226 | \r |
227 | @param Format Null-terminated ASCII format string.\r | |
00a1f552 | 228 | @param ... Variable argument list whose contents are accessed based \r |
229 | on the format string specified by Format.\r | |
bf428cb3 | 230 | \r |
231 | @return Number of ASCII characters printed to ConOut.\r | |
79964ac8 | 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 | |
bf428cb3 | 243 | ASSERT (Format != NULL);\r |
e115460b | 244 | \r |
79964ac8 | 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 | |
bf428cb3 | 254 | /** \r |
255 | Prints a formatted ASCII string to the console output device specified by \r | |
79964ac8 | 256 | StdErr defined in the EFI_SYSTEM_TABLE.\r |
257 | \r | |
bf428cb3 | 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 | |
79964ac8 | 262 | PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r |
bf428cb3 | 263 | If Format is NULL, then ASSERT().\r |
79964ac8 | 264 | \r |
265 | @param Format Null-terminated ASCII format string.\r | |
00a1f552 | 266 | @param ... Variable argument list whose contents are accessed based \r |
267 | on the format string specified by Format.\r | |
bf428cb3 | 268 | \r |
269 | @return Number of ASCII characters printed to ConErr.\r | |
79964ac8 | 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 | |
bf428cb3 | 282 | ASSERT (Format != NULL);\r |
e115460b | 283 | \r |
79964ac8 | 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 | |
bf428cb3 | 293 | /**\r |
e115460b | 294 | Internal function to print a formatted Unicode string to a graphics console device specified by\r |
bf428cb3 | 295 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r |
296 | \r | |
e115460b | 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 | |
bf428cb3 | 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 | |
e115460b | 304 | If a graphics console device is not associated with the ConsoleOutputHandle\r |
bf428cb3 | 305 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r |
e115460b | 306 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no\r |
bf428cb3 | 307 | string is printed, and 0 is returned.\r |
308 | \r | |
e115460b | 309 | @param PointX X coordinate to print the string.\r |
310 | @param PointY Y coordinate to print the string.\r | |
311 | @param Foreground The foreground color of the string being printed. This is\r | |
bf428cb3 | 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 | |
e6813189 | 315 | @param Background The background color of the string being printed. This is\r |
e115460b | 316 | an optional parameter that may be NULL. If it is NULL,\r |
bf428cb3 | 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 | |
e115460b | 322 | @return Number of Unicode Characters printed. Zero means no any character\r |
bf428cb3 | 323 | displayed successfully.\r |
324 | \r | |
325 | **/\r | |
326 | UINTN\r | |
327 | InternalPrintGraphic (\r | |
e115460b | 328 | IN UINTN PointX,\r |
329 | IN UINTN PointY,\r | |
bf428cb3 | 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 | |
bf428cb3 | 337 | UINT32 HorizontalResolution;\r |
338 | UINT32 VerticalResolution;\r | |
339 | UINT32 ColorDepth;\r | |
340 | UINT32 RefreshRate;\r | |
bf428cb3 | 341 | EFI_HII_FONT_PROTOCOL *HiiFont;\r |
342 | EFI_IMAGE_OUTPUT *Blt;\r | |
343 | EFI_FONT_DISPLAY_INFO FontInfo;\r | |
344 | EFI_HII_ROW_INFO *RowInfoArray;\r | |
345 | UINTN RowInfoArraySize;\r | |
346 | EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r | |
347 | EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r | |
348 | EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;\r | |
349 | EFI_HANDLE ConsoleHandle;\r | |
350 | \r | |
351 | HorizontalResolution = 0;\r | |
352 | VerticalResolution = 0;\r | |
353 | Blt = NULL;\r | |
619e4c06 | 354 | RowInfoArray = NULL;\r |
bf428cb3 | 355 | \r |
356 | ConsoleHandle = gST->ConsoleOutHandle;\r | |
357 | \r | |
358 | Status = gBS->HandleProtocol (\r | |
359 | ConsoleHandle,\r | |
360 | &gEfiGraphicsOutputProtocolGuid,\r | |
361 | (VOID **) &GraphicsOutput\r | |
362 | );\r | |
363 | \r | |
364 | UgaDraw = NULL;\r | |
365 | if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r | |
366 | //\r | |
367 | // If no GOP available, try to open UGA Draw protocol if supported.\r | |
368 | //\r | |
369 | GraphicsOutput = NULL;\r | |
370 | \r | |
371 | Status = gBS->HandleProtocol (\r | |
372 | ConsoleHandle,\r | |
373 | &gEfiUgaDrawProtocolGuid,\r | |
374 | (VOID **) &UgaDraw\r | |
375 | );\r | |
376 | }\r | |
377 | if (EFI_ERROR (Status)) {\r | |
619e4c06 | 378 | goto Error;\r |
bf428cb3 | 379 | }\r |
380 | \r | |
381 | Status = gBS->HandleProtocol (\r | |
382 | ConsoleHandle,\r | |
383 | &gEfiSimpleTextOutProtocolGuid,\r | |
384 | (VOID **) &Sto\r | |
385 | );\r | |
386 | \r | |
387 | if (EFI_ERROR (Status)) {\r | |
619e4c06 | 388 | goto Error;\r |
bf428cb3 | 389 | }\r |
390 | \r | |
391 | if (GraphicsOutput != NULL) {\r | |
392 | HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r | |
393 | VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r | |
e115460b | 394 | } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {\r |
bf428cb3 | 395 | UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r |
396 | } else {\r | |
bf428cb3 | 397 | goto Error;\r |
398 | }\r | |
399 | \r | |
400 | ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));\r | |
401 | \r | |
402 | Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &HiiFont);\r | |
403 | if (EFI_ERROR (Status)) {\r | |
404 | goto Error;\r | |
405 | }\r | |
406 | \r | |
bf428cb3 | 407 | Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r |
408 | ASSERT (Blt != NULL);\r | |
409 | \r | |
410 | Blt->Width = (UINT16) (HorizontalResolution);\r | |
411 | Blt->Height = (UINT16) (VerticalResolution);\r | |
412 | \r | |
413 | ZeroMem (&FontInfo, sizeof (EFI_FONT_DISPLAY_INFO));\r | |
414 | \r | |
415 | if (Foreground != NULL) {\r | |
416 | CopyMem (&FontInfo.ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r | |
417 | } else {\r | |
418 | CopyMem (\r | |
419 | &FontInfo.ForegroundColor,\r | |
420 | &mEfiColors[Sto->Mode->Attribute & 0x0f],\r | |
421 | sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
422 | );\r | |
423 | }\r | |
424 | if (Background != NULL) {\r | |
425 | CopyMem (&FontInfo.BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r | |
426 | } else {\r | |
427 | CopyMem (\r | |
428 | &FontInfo.BackgroundColor,\r | |
429 | &mEfiColors[Sto->Mode->Attribute >> 4],\r | |
430 | sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
431 | );\r | |
432 | }\r | |
433 | \r | |
434 | if (GraphicsOutput != NULL) {\r | |
435 | Blt->Image.Screen = GraphicsOutput;\r | |
e115460b | 436 | \r |
bf428cb3 | 437 | Status = HiiFont->StringToImage (\r |
438 | HiiFont,\r | |
619e4c06 | 439 | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |\r |
440 | EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |\r | |
441 | EFI_HII_IGNORE_LINE_BREAK | EFI_HII_DIRECT_TO_SCREEN,\r | |
bf428cb3 | 442 | Buffer,\r |
443 | &FontInfo,\r | |
444 | &Blt,\r | |
e115460b | 445 | PointX,\r |
446 | PointY,\r | |
619e4c06 | 447 | &RowInfoArray,\r |
448 | &RowInfoArraySize,\r | |
bf428cb3 | 449 | NULL\r |
450 | );\r | |
619e4c06 | 451 | if (EFI_ERROR (Status)) {\r |
452 | goto Error;\r | |
453 | }\r | |
bf428cb3 | 454 | \r |
e115460b | 455 | } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r |
456 | ASSERT (UgaDraw!= NULL);\r | |
bf428cb3 | 457 | \r |
458 | Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r | |
459 | ASSERT (Blt->Image.Bitmap != NULL);\r | |
460 | \r | |
bf428cb3 | 461 | //\r |
462 | // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,\r | |
463 | // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.\r | |
464 | //\r | |
465 | Status = HiiFont->StringToImage (\r | |
466 | HiiFont,\r | |
467 | EFI_HII_IGNORE_IF_NO_GLYPH,\r | |
468 | Buffer,\r | |
469 | &FontInfo,\r | |
470 | &Blt,\r | |
e115460b | 471 | PointX,\r |
472 | PointY,\r | |
bf428cb3 | 473 | &RowInfoArray,\r |
474 | &RowInfoArraySize,\r | |
475 | NULL\r | |
476 | );\r | |
477 | \r | |
478 | if (!EFI_ERROR (Status)) {\r | |
479 | ASSERT (RowInfoArray != NULL);\r | |
480 | //\r | |
481 | // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will\r | |
482 | // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.\r | |
483 | //\r | |
484 | ASSERT (RowInfoArraySize <= 1);\r | |
485 | \r | |
486 | Status = UgaDraw->Blt (\r | |
487 | UgaDraw,\r | |
488 | (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r | |
489 | EfiUgaBltBufferToVideo,\r | |
e115460b | 490 | PointX,\r |
491 | PointY,\r | |
492 | PointX,\r | |
493 | PointY,\r | |
bf428cb3 | 494 | RowInfoArray[0].LineWidth,\r |
495 | RowInfoArray[0].LineHeight,\r | |
496 | Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r | |
497 | );\r | |
619e4c06 | 498 | } else {\r |
499 | goto Error;\r | |
bf428cb3 | 500 | }\r |
bf428cb3 | 501 | FreePool (Blt->Image.Bitmap);\r |
bf428cb3 | 502 | } else {\r |
619e4c06 | 503 | goto Error;\r |
bf428cb3 | 504 | }\r |
619e4c06 | 505 | //\r |
506 | // Calculate the number of actual printed characters\r | |
507 | //\r | |
508 | PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;\r | |
bf428cb3 | 509 | \r |
619e4c06 | 510 | FreePool (RowInfoArray);\r |
bf428cb3 | 511 | FreePool (Blt);\r |
619e4c06 | 512 | return PrintNum;\r |
bf428cb3 | 513 | \r |
514 | Error:\r | |
619e4c06 | 515 | if (Blt != NULL) {\r |
516 | FreePool (Blt);\r | |
bf428cb3 | 517 | }\r |
619e4c06 | 518 | return 0;\r |
bf428cb3 | 519 | }\r |
520 | \r | |
521 | /**\r | |
522 | Prints a formatted Unicode string to a graphics console device specified by \r | |
523 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r | |
524 | \r | |
525 | This function prints a formatted Unicode string to the graphics console device \r | |
526 | specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of \r | |
619e4c06 | 527 | Unicode characters displayed, not including partial characters that may be clipped \r |
528 | by the right edge of the display. If the length of the formatted Unicode string is\r | |
529 | greater than PcdUefiLibMaxPrintBufferSize, then at most the first \r | |
57b201b8 | 530 | PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL\r |
531 | StringToImage() service is used to convert the string to a bitmap using the glyphs \r | |
532 | registered with the HII database. No wrapping is performed, so any portions of the \r | |
533 | string the fall outside the active display region will not be displayed. Please see \r | |
534 | Section 27.2.6 of the UEFI Specification for a description of the supported string\r | |
535 | format including the set of control codes supported by the StringToImage() service.\r | |
bf428cb3 | 536 | \r |
537 | If a graphics console device is not associated with the ConsoleOutputHandle \r | |
538 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r | |
539 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no \r | |
540 | string is printed, and 0 is returned.\r | |
541 | If Format is NULL, then ASSERT().\r | |
542 | If Format is not aligned on a 16-bit boundary, then ASSERT().\r | |
543 | \r | |
e115460b | 544 | @param PointX X coordinate to print the string.\r |
545 | @param PointY Y coordinate to print the string.\r | |
546 | @param ForeGround The foreground color of the string being printed. This is\r | |
bf428cb3 | 547 | an optional parameter that may be NULL. If it is NULL,\r |
548 | then the foreground color of the current ConOut device\r | |
549 | in the EFI_SYSTEM_TABLE is used.\r | |
550 | @param BackGround The background color of the string being printed. This is\r | |
551 | an optional parameter that may be NULL. If it is NULL, \r | |
552 | then the background color of the current ConOut device\r | |
553 | in the EFI_SYSTEM_TABLE is used.\r | |
554 | @param Format Null-terminated Unicode format string. See Print Library \r | |
555 | for the supported format string syntax.\r | |
556 | @param ... Variable argument list whose contents are accessed based on \r | |
557 | the format string specified by Format. \r | |
558 | \r | |
559 | @return The number of Unicode characters printed.\r | |
560 | \r | |
561 | **/\r | |
562 | UINTN\r | |
563 | EFIAPI\r | |
564 | PrintXY (\r | |
e115460b | 565 | IN UINTN PointX,\r |
566 | IN UINTN PointY,\r | |
bf428cb3 | 567 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL\r |
568 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL\r | |
569 | IN CONST CHAR16 *Format,\r | |
570 | ...\r | |
571 | )\r | |
572 | {\r | |
573 | VA_LIST Marker;\r | |
574 | CHAR16 *Buffer;\r | |
575 | UINTN BufferSize;\r | |
576 | UINTN PrintNum;\r | |
577 | UINTN ReturnNum;\r | |
578 | \r | |
579 | ASSERT (Format != NULL);\r | |
580 | ASSERT (((UINTN) Format & BIT0) == 0);\r | |
581 | \r | |
582 | VA_START (Marker, Format);\r | |
583 | \r | |
584 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
585 | \r | |
586 | Buffer = (CHAR16 *) AllocatePool (BufferSize);\r | |
587 | ASSERT (Buffer != NULL);\r | |
e115460b | 588 | \r |
bf428cb3 | 589 | PrintNum = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r |
590 | \r | |
e115460b | 591 | ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r |
bf428cb3 | 592 | \r |
593 | FreePool (Buffer);\r | |
594 | \r | |
595 | return ReturnNum;\r | |
596 | }\r | |
597 | \r | |
598 | /**\r | |
599 | Prints a formatted ASCII string to a graphics console device specified by \r | |
600 | ConsoleOutputHandle defined in the EFI_SYSTEM_TABLE at the given (X,Y) coordinates.\r | |
601 | \r | |
602 | This function prints a formatted ASCII string to the graphics console device \r | |
603 | specified by ConsoleOutputHandle in EFI_SYSTEM_TABLE and returns the number of \r | |
619e4c06 | 604 | ASCII characters displayed, not including partial characters that may be clipped \r |
605 | by the right edge of the display. If the length of the formatted ASCII string is\r | |
606 | greater than PcdUefiLibMaxPrintBufferSize, then at most the first \r | |
57b201b8 | 607 | PcdUefiLibMaxPrintBufferSize characters are printed.The EFI_HII_FONT_PROTOCOL\r |
608 | StringToImage() service is used to convert the string to a bitmap using the glyphs \r | |
609 | registered with the HII database. No wrapping is performed, so any portions of the \r | |
610 | string the fall outside the active display region will not be displayed. Please see \r | |
611 | Section 27.2.6 of the UEFI Specification for a description of the supported string\r | |
612 | format including the set of control codes supported by the StringToImage() service.\r | |
bf428cb3 | 613 | \r |
614 | If a graphics console device is not associated with the ConsoleOutputHandle \r | |
615 | defined in the EFI_SYSTEM_TABLE then no string is printed, and 0 is returned.\r | |
616 | If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no \r | |
617 | string is printed, and 0 is returned.\r | |
618 | If Format is NULL, then ASSERT().\r | |
619 | \r | |
e115460b | 620 | @param PointX X coordinate to print the string.\r |
621 | @param PointY Y coordinate to print the string.\r | |
622 | @param ForeGround The foreground color of the string being printed. This is\r | |
bf428cb3 | 623 | an optional parameter that may be NULL. If it is NULL,\r |
624 | then the foreground color of the current ConOut device\r | |
625 | in the EFI_SYSTEM_TABLE is used.\r | |
626 | @param BackGround The background color of the string being printed. This is\r | |
627 | an optional parameter that may be NULL. If it is NULL, \r | |
628 | then the background color of the current ConOut device\r | |
629 | in the EFI_SYSTEM_TABLE is used.\r | |
630 | @param Format Null-terminated ASCII format string. See Print Library \r | |
631 | for the supported format string syntax.\r | |
632 | @param ... Variable argument list whose contents are accessed based on \r | |
633 | the format string specified by Format. \r | |
634 | \r | |
635 | @return The number of ASCII characters printed.\r | |
636 | \r | |
637 | **/\r | |
638 | UINTN\r | |
639 | EFIAPI\r | |
640 | AsciiPrintXY (\r | |
e115460b | 641 | IN UINTN PointX,\r |
642 | IN UINTN PointY,\r | |
bf428cb3 | 643 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL\r |
644 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL\r | |
645 | IN CONST CHAR8 *Format,\r | |
646 | ...\r | |
647 | )\r | |
648 | {\r | |
649 | VA_LIST Marker;\r | |
650 | CHAR16 *Buffer;\r | |
651 | UINTN BufferSize;\r | |
652 | UINTN PrintNum;\r | |
653 | UINTN ReturnNum;\r | |
654 | \r | |
655 | ASSERT (Format != NULL);\r | |
656 | \r | |
657 | VA_START (Marker, Format);\r | |
658 | \r | |
659 | BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r | |
660 | \r | |
661 | Buffer = (CHAR16 *) AllocatePool (BufferSize);\r | |
662 | ASSERT (Buffer != NULL);\r | |
e115460b | 663 | \r |
bf428cb3 | 664 | PrintNum = UnicodeSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r |
665 | \r | |
e115460b | 666 | ReturnNum = InternalPrintGraphic (PointX, PointY, ForeGround, BackGround, Buffer, PrintNum);\r |
bf428cb3 | 667 | \r |
668 | FreePool (Buffer);\r | |
e115460b | 669 | \r |
bf428cb3 | 670 | return ReturnNum;\r |
671 | }\r | |
672 | \r |