]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Library/EdkGraphicsLib/Graphics.c
1. Fix EDKT451 It should append ".txt" to filename
[mirror_edk2.git] / EdkModulePkg / Library / EdkGraphicsLib / Graphics.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 Graphics.c\r
15\r
16Abstract:\r
17\r
18 Support for Basic Graphics operations.\r
19\r
20 BugBug: Currently *.BMP files are supported. This will be replaced\r
21 when Tiano graphics format is supported.\r
22\r
23--*/\r
24\r
25EFI_STATUS\r
26GetGraphicsBitMapFromFV (\r
27 IN EFI_GUID *FileNameGuid,\r
28 OUT VOID **Image,\r
29 OUT UINTN *ImageSize\r
30 )\r
31/*++\r
32\r
33Routine Description:\r
34\r
35 Return the graphics image file named FileNameGuid into Image and return it's\r
36 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the\r
37 file name.\r
38\r
39Arguments:\r
40\r
41 FileNameGuid - File Name of graphics file in the FV(s).\r
42\r
43 Image - Pointer to pointer to return graphics image. If NULL, a \r
44 buffer will be allocated.\r
45\r
46 ImageSize - Size of the graphics Image in bytes. Zero if no image found.\r
47\r
48\r
49Returns: \r
50\r
51 EFI_SUCCESS - Image and ImageSize are valid. \r
52 EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size\r
53 EFI_NOT_FOUND - FileNameGuid not found\r
54\r
55--*/\r
56{\r
57 EFI_STATUS Status;\r
58 UINTN FvProtocolCount;\r
59 EFI_HANDLE *FvHandles;\r
60 EFI_FIRMWARE_VOLUME_PROTOCOL *Fv;\r
61 UINTN Index;\r
62 UINT32 AuthenticationStatus;\r
63\r
64\r
65 Status = gBS->LocateHandleBuffer (\r
66 ByProtocol,\r
67 &gEfiFirmwareVolumeProtocolGuid,\r
68 NULL,\r
69 &FvProtocolCount,\r
70 &FvHandles\r
71 );\r
72 if (EFI_ERROR (Status)) {\r
73 return EFI_NOT_FOUND;\r
74 }\r
75\r
76 for (Index = 0; Index < FvProtocolCount; Index++) {\r
77 Status = gBS->HandleProtocol (\r
78 FvHandles[Index],\r
79 &gEfiFirmwareVolumeProtocolGuid,\r
80 (VOID **) &Fv\r
81 );\r
82\r
83 //\r
84 // Assuming Image and ImageSize are correct on input.\r
85 //\r
86 Status = Fv->ReadSection (\r
87 Fv,\r
88 &gEfiDefaultBmpLogoGuid,\r
89 EFI_SECTION_RAW,\r
90 0,\r
91 Image,\r
92 ImageSize,\r
93 &AuthenticationStatus\r
94 );\r
95 if (!EFI_ERROR (Status)) {\r
96 return EFI_SUCCESS;\r
97 } else if (Status == EFI_BUFFER_TOO_SMALL) {\r
98 //\r
99 // ImageSize updated to needed size so return\r
100 //\r
101 return EFI_BUFFER_TOO_SMALL;\r
102 }\r
103 }\r
104\r
105 return EFI_NOT_FOUND;\r
106}\r
107\r
108\r
109EFI_STATUS\r
110ConvertBmpToUgaBlt (\r
111 IN VOID *BmpImage,\r
112 IN UINTN BmpImageSize,\r
113 IN OUT VOID **UgaBlt,\r
114 IN OUT UINTN *UgaBltSize,\r
115 OUT UINTN *PixelHeight,\r
116 OUT UINTN *PixelWidth\r
117 )\r
118/*++\r
119\r
120Routine Description:\r
121\r
122 Convert a *.BMP graphics image to a UGA blt buffer. If a NULL UgaBlt buffer\r
123 is passed in a UgaBlt buffer will be allocated by this routine. If a UgaBlt\r
124 buffer is passed in it will be used if it is big enough.\r
125\r
126Arguments:\r
127\r
128 BmpImage - Pointer to BMP file\r
129\r
130 BmpImageSize - Number of bytes in BmpImage\r
131\r
132 UgaBlt - Buffer containing UGA version of BmpImage.\r
133\r
134 UgaBltSize - Size of UgaBlt in bytes.\r
135\r
136 PixelHeight - Height of UgaBlt/BmpImage in pixels\r
137\r
138 PixelWidth - Width of UgaBlt/BmpImage in pixels\r
139\r
140\r
141Returns: \r
142\r
143 EFI_SUCCESS - UgaBlt and UgaBltSize are returned. \r
144 EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image\r
145 EFI_BUFFER_TOO_SMALL - The passed in UgaBlt buffer is not big enough.\r
146 UgaBltSize will contain the required size.\r
147 EFI_OUT_OF_RESOURCES - No enough buffer to allocate\r
148\r
149--*/\r
150{\r
151 UINT8 *Image;\r
152 UINT8 *ImageHeader;\r
153 BMP_IMAGE_HEADER *BmpHeader;\r
154 BMP_COLOR_MAP *BmpColorMap;\r
155 EFI_UGA_PIXEL *BltBuffer;\r
156 EFI_UGA_PIXEL *Blt;\r
157 UINTN BltBufferSize;\r
158 UINTN Index;\r
159 UINTN Height;\r
160 UINTN Width;\r
161 UINTN ImageIndex;\r
162\r
163 BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;\r
164 if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {\r
165 return EFI_UNSUPPORTED;\r
166 }\r
167\r
168 if (BmpHeader->CompressionType != 0) {\r
169 return EFI_UNSUPPORTED;\r
170 }\r
171\r
172 //\r
173 // Calculate Color Map offset in the image.\r
174 //\r
175 Image = BmpImage;\r
176 BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));\r
177\r
178 //\r
179 // Calculate graphics image data address in the image\r
180 //\r
181 Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;\r
182 ImageHeader = Image;\r
183\r
184 BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_UGA_PIXEL);\r
185 if (*UgaBlt == NULL) {\r
186 *UgaBltSize = BltBufferSize;\r
187 *UgaBlt = AllocatePool (*UgaBltSize);\r
188 if (*UgaBlt == NULL) {\r
189 return EFI_OUT_OF_RESOURCES;\r
190 }\r
191 } else {\r
192 if (*UgaBltSize < BltBufferSize) {\r
193 *UgaBltSize = BltBufferSize;\r
194 return EFI_BUFFER_TOO_SMALL;\r
195 }\r
196 }\r
197\r
198 *PixelWidth = BmpHeader->PixelWidth;\r
199 *PixelHeight = BmpHeader->PixelHeight;\r
200\r
201 //\r
202 // Convert image from BMP to Blt buffer format\r
203 //\r
204 BltBuffer = *UgaBlt;\r
205 for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {\r
206 Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];\r
207 for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {\r
208 switch (BmpHeader->BitPerPixel) {\r
209 case 1:\r
210 //\r
211 // Convert 1bit BMP to 24-bit color\r
212 //\r
213 for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {\r
214 Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;\r
215 Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;\r
216 Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;\r
217 Blt++;\r
218 Width++;\r
219 }\r
220\r
221 Blt --;\r
222 Width --;\r
223 break;\r
224 \r
225 case 4:\r
226 //\r
227 // Convert BMP Palette to 24-bit color\r
228 //\r
229 Index = (*Image) >> 4;\r
230 Blt->Red = BmpColorMap[Index].Red;\r
231 Blt->Green = BmpColorMap[Index].Green;\r
232 Blt->Blue = BmpColorMap[Index].Blue;\r
233 if (Width < (BmpHeader->PixelWidth - 1)) {\r
234 Blt++;\r
235 Width++;\r
236 Index = (*Image) & 0x0f;\r
237 Blt->Red = BmpColorMap[Index].Red;\r
238 Blt->Green = BmpColorMap[Index].Green;\r
239 Blt->Blue = BmpColorMap[Index].Blue;\r
240 }\r
241 break;\r
242\r
243 case 8:\r
244 //\r
245 // Convert BMP Palette to 24-bit color\r
246 //\r
247 Blt->Red = BmpColorMap[*Image].Red;\r
248 Blt->Green = BmpColorMap[*Image].Green;\r
249 Blt->Blue = BmpColorMap[*Image].Blue;\r
250 break;\r
251\r
252 case 24:\r
253 Blt->Blue = *Image++;\r
254 Blt->Green = *Image++;\r
255 Blt->Red = *Image;\r
256 break;\r
257\r
258 default:\r
259 return EFI_UNSUPPORTED;\r
260 break;\r
261 };\r
262\r
263 }\r
264\r
265 ImageIndex = (UINTN) (Image - ImageHeader);\r
266 if ((ImageIndex % 4) != 0) {\r
267 //\r
268 // Bmp Image starts each row on a 32-bit boundary!\r
269 //\r
270 Image = Image + (4 - (ImageIndex % 4));\r
271 }\r
272 }\r
273\r
274 return EFI_SUCCESS;\r
275}\r
276\r
277\r
278EFI_STATUS\r
279LockKeyboards (\r
280 IN CHAR16 *Password\r
281 )\r
282/*++\r
283\r
284Routine Description:\r
285 Use Console Control Protocol to lock the Console In Spliter virtual handle. \r
286 This is the ConInHandle and ConIn handle in the EFI system table. All key\r
287 presses will be ignored until the Password is typed in. The only way to\r
288 disable the password is to type it in to a ConIn device.\r
289\r
290Arguments:\r
291 Password - Password used to lock ConIn device\r
292\r
293\r
294Returns: \r
295\r
296 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo\r
297 displayed.\r
298 EFI_UNSUPPORTED - Logo not found\r
299\r
300--*/\r
301{\r
302 EFI_STATUS Status;\r
303 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
304\r
305 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
306 if (EFI_ERROR (Status)) {\r
307 return EFI_UNSUPPORTED;\r
308 }\r
309\r
310 Status = ConsoleControl->LockStdIn (ConsoleControl, Password);\r
311 return Status;\r
312}\r
313\r
314\r
315EFI_STATUS\r
316EnableQuietBoot (\r
317 IN EFI_GUID *LogoFile\r
318 )\r
319/*++\r
320\r
321Routine Description:\r
322\r
323 Use Console Control to turn off UGA based Simple Text Out consoles from going\r
324 to the UGA device. Put up LogoFile on every UGA device that is a console\r
325\r
326Arguments:\r
327\r
328 LogoFile - File name of logo to display on the center of the screen.\r
329\r
330\r
331Returns: \r
332\r
333 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo\r
334 displayed.\r
335 EFI_UNSUPPORTED - Logo not found\r
336\r
337--*/\r
338{\r
339 EFI_STATUS Status;\r
340 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
341 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
342 EFI_OEM_BADGING_PROTOCOL *Badging;\r
343 UINT32 SizeOfX;\r
344 UINT32 SizeOfY;\r
345 UINT32 ColorDepth;\r
346 UINT32 RefreshRate;\r
347 INTN DestX;\r
348 INTN DestY;\r
349\r
350 UINT8 *ImageData;\r
351 UINTN ImageSize;\r
352 EFI_UGA_PIXEL *UgaBlt;\r
353 UINTN UgaBltSize;\r
354\r
355 UINT32 Instance;\r
356 EFI_BADGING_FORMAT Format;\r
357 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;\r
358 UINTN CoordinateX;\r
359 UINTN CoordinateY;\r
360 UINTN Height;\r
361 UINTN Width;\r
362\r
363 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
364 if (EFI_ERROR (Status)) {\r
365 return EFI_UNSUPPORTED;\r
366 }\r
367\r
368 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);\r
369 if (EFI_ERROR (Status)) {\r
370 return EFI_UNSUPPORTED;\r
371 }\r
372\r
373 Badging = NULL;\r
374 Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);\r
375\r
376 ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);\r
377\r
378 Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);\r
379 if (EFI_ERROR (Status)) {\r
380 return EFI_UNSUPPORTED;\r
381 }\r
382\r
383 Instance = 0;\r
384 while (1) {\r
385 ImageData = NULL;\r
386 ImageSize = 0;\r
387\r
388 if (Badging != NULL) {\r
389 Status = Badging->GetImage (\r
390 Badging,\r
391 &Instance,\r
392 &Format,\r
393 &ImageData,\r
394 &ImageSize,\r
395 &Attribute,\r
396 &CoordinateX,\r
397 &CoordinateY\r
398 );\r
399 if (EFI_ERROR (Status)) {\r
400 return Status;\r
401 }\r
402\r
403 //\r
404 // Currently only support BMP format\r
405 //\r
406 if (Format != EfiBadgingFormatBMP) {\r
407 gBS->FreePool (ImageData);\r
408 continue;\r
409 }\r
410 } else {\r
411 Status = GetGraphicsBitMapFromFV (LogoFile, (VOID **) &ImageData, &ImageSize);\r
412 if (EFI_ERROR (Status)) {\r
413 return EFI_UNSUPPORTED;\r
414 }\r
415\r
416 CoordinateX = 0;\r
417 CoordinateY = 0;\r
418 Attribute = EfiBadgingDisplayAttributeCenter;\r
419 }\r
420\r
421 UgaBlt = NULL;\r
422 Status = ConvertBmpToUgaBlt (\r
423 ImageData,\r
424 ImageSize,\r
425 (VOID **) &UgaBlt,\r
426 &UgaBltSize,\r
427 &Height,\r
428 &Width\r
429 );\r
430 if (EFI_ERROR (Status)) {\r
431 gBS->FreePool (ImageData);\r
432 continue;\r
433 }\r
434\r
435 switch (Attribute) {\r
436 case EfiBadgingDisplayAttributeLeftTop:\r
437 DestX = CoordinateX;\r
438 DestY = CoordinateY;\r
439 break;\r
440\r
441 case EfiBadgingDisplayAttributeCenterTop:\r
442 DestX = (SizeOfX - Width) / 2;\r
443 DestY = CoordinateY;\r
444 break;\r
445\r
446 case EfiBadgingDisplayAttributeRightTop:\r
447 DestX = (SizeOfX - Width - CoordinateX);\r
448 DestY = CoordinateY;;\r
449 break;\r
450\r
451 case EfiBadgingDisplayAttributeCenterRight:\r
452 DestX = (SizeOfX - Width - CoordinateX);\r
453 DestY = (SizeOfY - Height) / 2;\r
454 break;\r
455\r
456 case EfiBadgingDisplayAttributeRightBottom:\r
457 DestX = (SizeOfX - Width - CoordinateX);\r
458 DestY = (SizeOfY - Height - CoordinateY);\r
459 break;\r
460\r
461 case EfiBadgingDisplayAttributeCenterBottom:\r
462 DestX = (SizeOfX - Width) / 2;\r
463 DestY = (SizeOfY - Height - CoordinateY);\r
464 break;\r
465\r
466 case EfiBadgingDisplayAttributeLeftBottom:\r
467 DestX = CoordinateX;\r
468 DestY = (SizeOfY - Height - CoordinateY);\r
469 break;\r
470\r
471 case EfiBadgingDisplayAttributeCenterLeft:\r
472 DestX = CoordinateX;\r
473 DestY = (SizeOfY - Height) / 2;\r
474 break;\r
475\r
476 case EfiBadgingDisplayAttributeCenter:\r
477 DestX = (SizeOfX - Width) / 2;\r
478 DestY = (SizeOfY - Height) / 2;\r
479 break;\r
480\r
481 default:\r
482 DestX = CoordinateX;\r
483 DestY = CoordinateY;\r
484 break;\r
485 }\r
486\r
487 if ((DestX >= 0) && (DestY >= 0)) {\r
488 Status = UgaDraw->Blt (\r
489 UgaDraw,\r
490 UgaBlt,\r
491 EfiUgaBltBufferToVideo,\r
492 0,\r
493 0,\r
494 (UINTN) DestX,\r
495 (UINTN) DestY,\r
496 Width,\r
497 Height,\r
498 Width * sizeof (EFI_UGA_PIXEL)\r
499 );\r
500 }\r
501\r
502 gBS->FreePool (ImageData);\r
503 gBS->FreePool (UgaBlt);\r
504\r
505 if (Badging == NULL) {\r
506 break;\r
507 }\r
508 }\r
509\r
510 return Status;\r
511}\r
512\r
513\r
514EFI_STATUS\r
515DisableQuietBoot (\r
516 VOID\r
517 )\r
518/*++\r
519\r
520Routine Description:\r
521\r
522 Use Console Control to turn on UGA based Simple Text Out consoles. The UGA \r
523 Simple Text Out screens will now be synced up with all non UGA output devices\r
524\r
525Arguments:\r
526\r
527 NONE\r
528\r
529Returns: \r
530\r
531 EFI_SUCCESS - UGA devices are back in text mode and synced up.\r
532 EFI_UNSUPPORTED - Logo not found\r
533\r
534--*/\r
535{\r
536 EFI_STATUS Status;\r
537 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
538\r
539 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
540 if (EFI_ERROR (Status)) {\r
541 return EFI_UNSUPPORTED;\r
542 }\r
543\r
544 return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);\r
545}\r
546\r
547static EFI_UGA_PIXEL mEfiColors[16] = {\r
548 { 0x00, 0x00, 0x00, 0x00 },\r
549 { 0x98, 0x00, 0x00, 0x00 },\r
550 { 0x00, 0x98, 0x00, 0x00 },\r
551 { 0x98, 0x98, 0x00, 0x00 },\r
552 { 0x00, 0x00, 0x98, 0x00 },\r
553 { 0x98, 0x00, 0x98, 0x00 },\r
554 { 0x00, 0x98, 0x98, 0x00 },\r
555 { 0x98, 0x98, 0x98, 0x00 },\r
556 { 0x10, 0x10, 0x10, 0x00 },\r
557 { 0xff, 0x10, 0x10, 0x00 },\r
558 { 0x10, 0xff, 0x10, 0x00 },\r
559 { 0xff, 0xff, 0x10, 0x00 },\r
560 { 0x10, 0x10, 0xff, 0x00 },\r
561 { 0xf0, 0x10, 0xff, 0x00 },\r
562 { 0x10, 0xff, 0xff, 0x00 },\r
563 { 0xff, 0xff, 0xff, 0x00 }\r
564};\r
565\r
566STATIC\r
567UINTN\r
568_IPrint (\r
569 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw,\r
570 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto,\r
571 IN UINTN X,\r
572 IN UINTN Y,\r
573 IN EFI_UGA_PIXEL *Foreground,\r
574 IN EFI_UGA_PIXEL *Background,\r
575 IN CHAR16 *fmt,\r
576 IN VA_LIST args\r
577 )\r
578/*++\r
579\r
580Routine Description:\r
581\r
582 Display string worker for: Print, PrintAt, IPrint, IPrintAt\r
583\r
584Arguments:\r
585\r
586 UgaDraw - UGA draw protocol interface\r
587 \r
588 Sto - Simple text out protocol interface\r
589 \r
590 X - X coordinate to start printing\r
591 \r
592 Y - Y coordinate to start printing\r
593 \r
594 Foreground - Foreground color\r
595 \r
596 Background - Background color\r
597 \r
598 fmt - Format string\r
599 \r
600 args - Print arguments\r
601\r
602Returns: \r
603\r
604 EFI_SUCCESS - success\r
605 EFI_OUT_OF_RESOURCES - out of resources\r
606\r
607--*/\r
608{\r
609 VOID *Buffer;\r
610 EFI_STATUS Status;\r
611 UINT16 GlyphWidth;\r
612 UINT32 GlyphStatus;\r
613 UINT16 StringIndex;\r
614 UINTN Index;\r
615 CHAR16 *UnicodeWeight;\r
616 EFI_NARROW_GLYPH *Glyph;\r
617 EFI_HII_PROTOCOL *Hii;\r
618 EFI_UGA_PIXEL *LineBuffer;\r
619 UINT32 HorizontalResolution;\r
620 UINT32 VerticalResolution;\r
621 UINT32 ColorDepth;\r
622 UINT32 RefreshRate;\r
623\r
624 GlyphStatus = 0;\r
625\r
626 //\r
627 // For now, allocate an arbitrarily long buffer\r
628 //\r
629 Buffer = AllocateZeroPool (0x10000);\r
630 if (Buffer == NULL) {\r
631 return EFI_OUT_OF_RESOURCES;\r
632 }\r
633\r
634 UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r
635\r
636 LineBuffer = AllocatePool (sizeof (EFI_UGA_PIXEL) * HorizontalResolution * GLYPH_WIDTH * GLYPH_HEIGHT);\r
637 if (LineBuffer == NULL) {\r
638 gBS->FreePool (Buffer);\r
639 return EFI_OUT_OF_RESOURCES;\r
640 }\r
641\r
642 Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, (VOID **) &Hii);\r
643 if (EFI_ERROR (Status)) {\r
644 goto Error;\r
645 }\r
646\r
647 UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r
648\r
649 UnicodeWeight = (CHAR16 *) Buffer;\r
650\r
651 for (Index = 0; UnicodeWeight[Index] != 0; Index++) {\r
652 if (UnicodeWeight[Index] == CHAR_BACKSPACE ||\r
653 UnicodeWeight[Index] == CHAR_LINEFEED ||\r
654 UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) {\r
655 UnicodeWeight[Index] = 0;\r
656 }\r
657 }\r
658\r
659 for (Index = 0; Index < StrLen (Buffer); Index++) {\r
660 StringIndex = (UINT16) Index;\r
661 Status = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);\r
662 if (EFI_ERROR (Status)) {\r
663 goto Error;\r
664 }\r
665\r
666 if (Foreground == NULL || Background == NULL) {\r
667 Status = Hii->GlyphToBlt (\r
668 Hii,\r
669 (UINT8 *) Glyph,\r
670 mEfiColors[Sto->Mode->Attribute & 0x0f],\r
671 mEfiColors[Sto->Mode->Attribute >> 4],\r
672 StrLen (Buffer),\r
673 GlyphWidth,\r
674 GLYPH_HEIGHT,\r
675 &LineBuffer[Index * GLYPH_WIDTH]\r
676 );\r
677 } else {\r
678 Status = Hii->GlyphToBlt (\r
679 Hii,\r
680 (UINT8 *) Glyph,\r
681 *Foreground,\r
682 *Background,\r
683 StrLen (Buffer),\r
684 GlyphWidth,\r
685 GLYPH_HEIGHT,\r
686 &LineBuffer[Index * GLYPH_WIDTH]\r
687 );\r
688 }\r
689 }\r
690\r
691 //\r
692 // Blt a character to the screen\r
693 //\r
694 Status = UgaDraw->Blt (\r
695 UgaDraw,\r
696 LineBuffer,\r
697 EfiUgaBltBufferToVideo,\r
698 0,\r
699 0,\r
700 X,\r
701 Y,\r
702 GLYPH_WIDTH * StrLen (Buffer),\r
703 GLYPH_HEIGHT,\r
704 GLYPH_WIDTH * StrLen (Buffer) * sizeof (EFI_UGA_PIXEL)\r
705 );\r
706\r
707Error:\r
708 gBS->FreePool (LineBuffer);\r
709 gBS->FreePool (Buffer);\r
710 return Status;\r
711}\r
712\r
713\r
714UINTN\r
715PrintXY (\r
716 IN UINTN X,\r
717 IN UINTN Y,\r
718 IN EFI_UGA_PIXEL *ForeGround, OPTIONAL\r
719 IN EFI_UGA_PIXEL *BackGround, OPTIONAL\r
720 IN CHAR16 *Fmt,\r
721 ...\r
722 )\r
723/*++\r
724\r
725Routine Description:\r
726\r
727 Prints a formatted unicode string to the default console\r
728\r
729Arguments:\r
730\r
731 X - X coordinate to start printing\r
732 \r
733 Y - Y coordinate to start printing\r
734 \r
735 ForeGround - Foreground color\r
736 \r
737 BackGround - Background color\r
738\r
739 Fmt - Format string\r
740\r
741 ... - Print arguments\r
742\r
743Returns:\r
744\r
745 Length of string printed to the console\r
746\r
747--*/\r
748{\r
749 EFI_HANDLE Handle;\r
750 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
751 EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto;\r
752 EFI_STATUS Status;\r
753 VA_LIST Args;\r
754\r
755 VA_START (Args, Fmt);\r
756\r
757 Handle = gST->ConsoleOutHandle;\r
758\r
759 Status = gBS->HandleProtocol (\r
760 Handle,\r
761 &gEfiUgaDrawProtocolGuid,\r
762 (VOID **) &UgaDraw\r
763 );\r
764\r
765 if (EFI_ERROR (Status)) {\r
766 return Status;\r
767 }\r
768\r
769 Status = gBS->HandleProtocol (\r
770 Handle,\r
771 &gEfiSimpleTextOutProtocolGuid,\r
772 (VOID **) &Sto\r
773 );\r
774\r
775 if (EFI_ERROR (Status)) {\r
776 return Status;\r
777 }\r
778\r
779 return _IPrint (UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
780}\r