Rename PcdPlatformBusSpeed to PcdFSBClock and update help text.
[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
d4f397c0 162 BOOLEAN IsAllocated;\r
163 \r
878ddf1f 164 BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;\r
165 if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {\r
166 return EFI_UNSUPPORTED;\r
167 }\r
168\r
169 if (BmpHeader->CompressionType != 0) {\r
170 return EFI_UNSUPPORTED;\r
171 }\r
172\r
173 //\r
174 // Calculate Color Map offset in the image.\r
175 //\r
176 Image = BmpImage;\r
177 BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));\r
178\r
179 //\r
180 // Calculate graphics image data address in the image\r
181 //\r
182 Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;\r
183 ImageHeader = Image;\r
184\r
185 BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_UGA_PIXEL);\r
d4f397c0 186 IsAllocated = FALSE;\r
878ddf1f 187 if (*UgaBlt == NULL) {\r
188 *UgaBltSize = BltBufferSize;\r
189 *UgaBlt = AllocatePool (*UgaBltSize);\r
190 if (*UgaBlt == NULL) {\r
191 return EFI_OUT_OF_RESOURCES;\r
192 }\r
d4f397c0 193 IsAllocated = TRUE;\r
878ddf1f 194 } else {\r
195 if (*UgaBltSize < BltBufferSize) {\r
196 *UgaBltSize = BltBufferSize;\r
197 return EFI_BUFFER_TOO_SMALL;\r
198 }\r
199 }\r
200\r
201 *PixelWidth = BmpHeader->PixelWidth;\r
202 *PixelHeight = BmpHeader->PixelHeight;\r
203\r
204 //\r
205 // Convert image from BMP to Blt buffer format\r
206 //\r
207 BltBuffer = *UgaBlt;\r
208 for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {\r
209 Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];\r
210 for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {\r
211 switch (BmpHeader->BitPerPixel) {\r
212 case 1:\r
213 //\r
214 // Convert 1bit BMP to 24-bit color\r
215 //\r
216 for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {\r
217 Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;\r
218 Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;\r
219 Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;\r
220 Blt++;\r
221 Width++;\r
222 }\r
223\r
224 Blt --;\r
225 Width --;\r
226 break;\r
227 \r
228 case 4:\r
229 //\r
230 // Convert BMP Palette to 24-bit color\r
231 //\r
232 Index = (*Image) >> 4;\r
233 Blt->Red = BmpColorMap[Index].Red;\r
234 Blt->Green = BmpColorMap[Index].Green;\r
235 Blt->Blue = BmpColorMap[Index].Blue;\r
236 if (Width < (BmpHeader->PixelWidth - 1)) {\r
237 Blt++;\r
238 Width++;\r
239 Index = (*Image) & 0x0f;\r
240 Blt->Red = BmpColorMap[Index].Red;\r
241 Blt->Green = BmpColorMap[Index].Green;\r
242 Blt->Blue = BmpColorMap[Index].Blue;\r
243 }\r
244 break;\r
245\r
246 case 8:\r
247 //\r
248 // Convert BMP Palette to 24-bit color\r
249 //\r
250 Blt->Red = BmpColorMap[*Image].Red;\r
251 Blt->Green = BmpColorMap[*Image].Green;\r
252 Blt->Blue = BmpColorMap[*Image].Blue;\r
253 break;\r
254\r
255 case 24:\r
256 Blt->Blue = *Image++;\r
257 Blt->Green = *Image++;\r
258 Blt->Red = *Image;\r
259 break;\r
260\r
261 default:\r
d4f397c0 262 if (IsAllocated) {\r
263 gBS->FreePool (*UgaBlt);\r
264 *UgaBlt = NULL;\r
265 }\r
878ddf1f 266 return EFI_UNSUPPORTED;\r
267 break;\r
268 };\r
269\r
270 }\r
271\r
272 ImageIndex = (UINTN) (Image - ImageHeader);\r
273 if ((ImageIndex % 4) != 0) {\r
274 //\r
275 // Bmp Image starts each row on a 32-bit boundary!\r
276 //\r
277 Image = Image + (4 - (ImageIndex % 4));\r
278 }\r
279 }\r
280\r
281 return EFI_SUCCESS;\r
282}\r
283\r
284\r
285EFI_STATUS\r
286LockKeyboards (\r
287 IN CHAR16 *Password\r
288 )\r
289/*++\r
290\r
291Routine Description:\r
292 Use Console Control Protocol to lock the Console In Spliter virtual handle. \r
293 This is the ConInHandle and ConIn handle in the EFI system table. All key\r
294 presses will be ignored until the Password is typed in. The only way to\r
295 disable the password is to type it in to a ConIn device.\r
296\r
297Arguments:\r
298 Password - Password used to lock ConIn device\r
299\r
300\r
301Returns: \r
302\r
303 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo\r
304 displayed.\r
305 EFI_UNSUPPORTED - Logo not found\r
306\r
307--*/\r
308{\r
309 EFI_STATUS Status;\r
310 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
311\r
312 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
313 if (EFI_ERROR (Status)) {\r
314 return EFI_UNSUPPORTED;\r
315 }\r
316\r
317 Status = ConsoleControl->LockStdIn (ConsoleControl, Password);\r
318 return Status;\r
319}\r
320\r
321\r
322EFI_STATUS\r
323EnableQuietBoot (\r
324 IN EFI_GUID *LogoFile\r
325 )\r
326/*++\r
327\r
328Routine Description:\r
329\r
330 Use Console Control to turn off UGA based Simple Text Out consoles from going\r
331 to the UGA device. Put up LogoFile on every UGA device that is a console\r
332\r
333Arguments:\r
334\r
335 LogoFile - File name of logo to display on the center of the screen.\r
336\r
337\r
338Returns: \r
339\r
340 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo\r
341 displayed.\r
342 EFI_UNSUPPORTED - Logo not found\r
343\r
344--*/\r
345{\r
346 EFI_STATUS Status;\r
347 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
348 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
349 EFI_OEM_BADGING_PROTOCOL *Badging;\r
350 UINT32 SizeOfX;\r
351 UINT32 SizeOfY;\r
352 UINT32 ColorDepth;\r
353 UINT32 RefreshRate;\r
354 INTN DestX;\r
355 INTN DestY;\r
356\r
357 UINT8 *ImageData;\r
358 UINTN ImageSize;\r
359 EFI_UGA_PIXEL *UgaBlt;\r
360 UINTN UgaBltSize;\r
361\r
362 UINT32 Instance;\r
363 EFI_BADGING_FORMAT Format;\r
364 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;\r
365 UINTN CoordinateX;\r
366 UINTN CoordinateY;\r
367 UINTN Height;\r
368 UINTN Width;\r
369\r
370 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
371 if (EFI_ERROR (Status)) {\r
372 return EFI_UNSUPPORTED;\r
373 }\r
374\r
375 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);\r
376 if (EFI_ERROR (Status)) {\r
377 return EFI_UNSUPPORTED;\r
378 }\r
379\r
380 Badging = NULL;\r
381 Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);\r
382\r
383 ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);\r
384\r
385 Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);\r
386 if (EFI_ERROR (Status)) {\r
387 return EFI_UNSUPPORTED;\r
388 }\r
389\r
390 Instance = 0;\r
391 while (1) {\r
392 ImageData = NULL;\r
393 ImageSize = 0;\r
394\r
395 if (Badging != NULL) {\r
396 Status = Badging->GetImage (\r
397 Badging,\r
398 &Instance,\r
399 &Format,\r
400 &ImageData,\r
401 &ImageSize,\r
402 &Attribute,\r
403 &CoordinateX,\r
404 &CoordinateY\r
405 );\r
406 if (EFI_ERROR (Status)) {\r
407 return Status;\r
408 }\r
409\r
410 //\r
411 // Currently only support BMP format\r
412 //\r
413 if (Format != EfiBadgingFormatBMP) {\r
414 gBS->FreePool (ImageData);\r
415 continue;\r
416 }\r
417 } else {\r
418 Status = GetGraphicsBitMapFromFV (LogoFile, (VOID **) &ImageData, &ImageSize);\r
419 if (EFI_ERROR (Status)) {\r
420 return EFI_UNSUPPORTED;\r
421 }\r
422\r
423 CoordinateX = 0;\r
424 CoordinateY = 0;\r
425 Attribute = EfiBadgingDisplayAttributeCenter;\r
426 }\r
427\r
428 UgaBlt = NULL;\r
429 Status = ConvertBmpToUgaBlt (\r
430 ImageData,\r
431 ImageSize,\r
432 (VOID **) &UgaBlt,\r
433 &UgaBltSize,\r
434 &Height,\r
435 &Width\r
436 );\r
437 if (EFI_ERROR (Status)) {\r
438 gBS->FreePool (ImageData);\r
439 continue;\r
440 }\r
441\r
442 switch (Attribute) {\r
443 case EfiBadgingDisplayAttributeLeftTop:\r
444 DestX = CoordinateX;\r
445 DestY = CoordinateY;\r
446 break;\r
447\r
448 case EfiBadgingDisplayAttributeCenterTop:\r
449 DestX = (SizeOfX - Width) / 2;\r
450 DestY = CoordinateY;\r
451 break;\r
452\r
453 case EfiBadgingDisplayAttributeRightTop:\r
454 DestX = (SizeOfX - Width - CoordinateX);\r
455 DestY = CoordinateY;;\r
456 break;\r
457\r
458 case EfiBadgingDisplayAttributeCenterRight:\r
459 DestX = (SizeOfX - Width - CoordinateX);\r
460 DestY = (SizeOfY - Height) / 2;\r
461 break;\r
462\r
463 case EfiBadgingDisplayAttributeRightBottom:\r
464 DestX = (SizeOfX - Width - CoordinateX);\r
465 DestY = (SizeOfY - Height - CoordinateY);\r
466 break;\r
467\r
468 case EfiBadgingDisplayAttributeCenterBottom:\r
469 DestX = (SizeOfX - Width) / 2;\r
470 DestY = (SizeOfY - Height - CoordinateY);\r
471 break;\r
472\r
473 case EfiBadgingDisplayAttributeLeftBottom:\r
474 DestX = CoordinateX;\r
475 DestY = (SizeOfY - Height - CoordinateY);\r
476 break;\r
477\r
478 case EfiBadgingDisplayAttributeCenterLeft:\r
479 DestX = CoordinateX;\r
480 DestY = (SizeOfY - Height) / 2;\r
481 break;\r
482\r
483 case EfiBadgingDisplayAttributeCenter:\r
484 DestX = (SizeOfX - Width) / 2;\r
485 DestY = (SizeOfY - Height) / 2;\r
486 break;\r
487\r
488 default:\r
489 DestX = CoordinateX;\r
490 DestY = CoordinateY;\r
491 break;\r
492 }\r
493\r
494 if ((DestX >= 0) && (DestY >= 0)) {\r
495 Status = UgaDraw->Blt (\r
496 UgaDraw,\r
497 UgaBlt,\r
498 EfiUgaBltBufferToVideo,\r
499 0,\r
500 0,\r
501 (UINTN) DestX,\r
502 (UINTN) DestY,\r
503 Width,\r
504 Height,\r
505 Width * sizeof (EFI_UGA_PIXEL)\r
506 );\r
507 }\r
508\r
509 gBS->FreePool (ImageData);\r
510 gBS->FreePool (UgaBlt);\r
511\r
512 if (Badging == NULL) {\r
513 break;\r
514 }\r
515 }\r
516\r
517 return Status;\r
518}\r
519\r
520\r
521EFI_STATUS\r
522DisableQuietBoot (\r
523 VOID\r
524 )\r
525/*++\r
526\r
527Routine Description:\r
528\r
529 Use Console Control to turn on UGA based Simple Text Out consoles. The UGA \r
530 Simple Text Out screens will now be synced up with all non UGA output devices\r
531\r
532Arguments:\r
533\r
534 NONE\r
535\r
536Returns: \r
537\r
538 EFI_SUCCESS - UGA devices are back in text mode and synced up.\r
539 EFI_UNSUPPORTED - Logo not found\r
540\r
541--*/\r
542{\r
543 EFI_STATUS Status;\r
544 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
545\r
546 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
547 if (EFI_ERROR (Status)) {\r
548 return EFI_UNSUPPORTED;\r
549 }\r
550\r
551 return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);\r
552}\r
553\r
554static EFI_UGA_PIXEL mEfiColors[16] = {\r
555 { 0x00, 0x00, 0x00, 0x00 },\r
556 { 0x98, 0x00, 0x00, 0x00 },\r
557 { 0x00, 0x98, 0x00, 0x00 },\r
558 { 0x98, 0x98, 0x00, 0x00 },\r
559 { 0x00, 0x00, 0x98, 0x00 },\r
560 { 0x98, 0x00, 0x98, 0x00 },\r
561 { 0x00, 0x98, 0x98, 0x00 },\r
562 { 0x98, 0x98, 0x98, 0x00 },\r
563 { 0x10, 0x10, 0x10, 0x00 },\r
564 { 0xff, 0x10, 0x10, 0x00 },\r
565 { 0x10, 0xff, 0x10, 0x00 },\r
566 { 0xff, 0xff, 0x10, 0x00 },\r
567 { 0x10, 0x10, 0xff, 0x00 },\r
568 { 0xf0, 0x10, 0xff, 0x00 },\r
569 { 0x10, 0xff, 0xff, 0x00 },\r
570 { 0xff, 0xff, 0xff, 0x00 }\r
571};\r
572\r
573STATIC\r
574UINTN\r
575_IPrint (\r
576 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw,\r
577 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto,\r
578 IN UINTN X,\r
579 IN UINTN Y,\r
580 IN EFI_UGA_PIXEL *Foreground,\r
581 IN EFI_UGA_PIXEL *Background,\r
582 IN CHAR16 *fmt,\r
583 IN VA_LIST args\r
584 )\r
585/*++\r
586\r
587Routine Description:\r
588\r
589 Display string worker for: Print, PrintAt, IPrint, IPrintAt\r
590\r
591Arguments:\r
592\r
593 UgaDraw - UGA draw protocol interface\r
594 \r
595 Sto - Simple text out protocol interface\r
596 \r
597 X - X coordinate to start printing\r
598 \r
599 Y - Y coordinate to start printing\r
600 \r
601 Foreground - Foreground color\r
602 \r
603 Background - Background color\r
604 \r
605 fmt - Format string\r
606 \r
607 args - Print arguments\r
608\r
609Returns: \r
610\r
611 EFI_SUCCESS - success\r
612 EFI_OUT_OF_RESOURCES - out of resources\r
613\r
614--*/\r
615{\r
616 VOID *Buffer;\r
617 EFI_STATUS Status;\r
618 UINT16 GlyphWidth;\r
619 UINT32 GlyphStatus;\r
620 UINT16 StringIndex;\r
621 UINTN Index;\r
622 CHAR16 *UnicodeWeight;\r
623 EFI_NARROW_GLYPH *Glyph;\r
624 EFI_HII_PROTOCOL *Hii;\r
625 EFI_UGA_PIXEL *LineBuffer;\r
626 UINT32 HorizontalResolution;\r
627 UINT32 VerticalResolution;\r
628 UINT32 ColorDepth;\r
629 UINT32 RefreshRate;\r
630\r
631 GlyphStatus = 0;\r
632\r
633 //\r
634 // For now, allocate an arbitrarily long buffer\r
635 //\r
636 Buffer = AllocateZeroPool (0x10000);\r
637 if (Buffer == NULL) {\r
638 return EFI_OUT_OF_RESOURCES;\r
639 }\r
640\r
641 UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r
642\r
643 LineBuffer = AllocatePool (sizeof (EFI_UGA_PIXEL) * HorizontalResolution * GLYPH_WIDTH * GLYPH_HEIGHT);\r
644 if (LineBuffer == NULL) {\r
645 gBS->FreePool (Buffer);\r
646 return EFI_OUT_OF_RESOURCES;\r
647 }\r
648\r
649 Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, (VOID **) &Hii);\r
650 if (EFI_ERROR (Status)) {\r
651 goto Error;\r
652 }\r
653\r
654 UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r
655\r
656 UnicodeWeight = (CHAR16 *) Buffer;\r
657\r
658 for (Index = 0; UnicodeWeight[Index] != 0; Index++) {\r
659 if (UnicodeWeight[Index] == CHAR_BACKSPACE ||\r
660 UnicodeWeight[Index] == CHAR_LINEFEED ||\r
661 UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) {\r
662 UnicodeWeight[Index] = 0;\r
663 }\r
664 }\r
665\r
666 for (Index = 0; Index < StrLen (Buffer); Index++) {\r
667 StringIndex = (UINT16) Index;\r
668 Status = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);\r
669 if (EFI_ERROR (Status)) {\r
670 goto Error;\r
671 }\r
672\r
673 if (Foreground == NULL || Background == NULL) {\r
674 Status = Hii->GlyphToBlt (\r
675 Hii,\r
676 (UINT8 *) Glyph,\r
677 mEfiColors[Sto->Mode->Attribute & 0x0f],\r
678 mEfiColors[Sto->Mode->Attribute >> 4],\r
679 StrLen (Buffer),\r
680 GlyphWidth,\r
681 GLYPH_HEIGHT,\r
682 &LineBuffer[Index * GLYPH_WIDTH]\r
683 );\r
684 } else {\r
685 Status = Hii->GlyphToBlt (\r
686 Hii,\r
687 (UINT8 *) Glyph,\r
688 *Foreground,\r
689 *Background,\r
690 StrLen (Buffer),\r
691 GlyphWidth,\r
692 GLYPH_HEIGHT,\r
693 &LineBuffer[Index * GLYPH_WIDTH]\r
694 );\r
695 }\r
696 }\r
697\r
698 //\r
699 // Blt a character to the screen\r
700 //\r
701 Status = UgaDraw->Blt (\r
702 UgaDraw,\r
703 LineBuffer,\r
704 EfiUgaBltBufferToVideo,\r
705 0,\r
706 0,\r
707 X,\r
708 Y,\r
709 GLYPH_WIDTH * StrLen (Buffer),\r
710 GLYPH_HEIGHT,\r
711 GLYPH_WIDTH * StrLen (Buffer) * sizeof (EFI_UGA_PIXEL)\r
712 );\r
713\r
714Error:\r
715 gBS->FreePool (LineBuffer);\r
716 gBS->FreePool (Buffer);\r
717 return Status;\r
718}\r
719\r
720\r
721UINTN\r
722PrintXY (\r
723 IN UINTN X,\r
724 IN UINTN Y,\r
725 IN EFI_UGA_PIXEL *ForeGround, OPTIONAL\r
726 IN EFI_UGA_PIXEL *BackGround, OPTIONAL\r
727 IN CHAR16 *Fmt,\r
728 ...\r
729 )\r
730/*++\r
731\r
732Routine Description:\r
733\r
734 Prints a formatted unicode string to the default console\r
735\r
736Arguments:\r
737\r
738 X - X coordinate to start printing\r
739 \r
740 Y - Y coordinate to start printing\r
741 \r
742 ForeGround - Foreground color\r
743 \r
744 BackGround - Background color\r
745\r
746 Fmt - Format string\r
747\r
748 ... - Print arguments\r
749\r
750Returns:\r
751\r
752 Length of string printed to the console\r
753\r
754--*/\r
755{\r
756 EFI_HANDLE Handle;\r
757 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
758 EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto;\r
759 EFI_STATUS Status;\r
760 VA_LIST Args;\r
761\r
762 VA_START (Args, Fmt);\r
763\r
764 Handle = gST->ConsoleOutHandle;\r
765\r
766 Status = gBS->HandleProtocol (\r
767 Handle,\r
768 &gEfiUgaDrawProtocolGuid,\r
769 (VOID **) &UgaDraw\r
770 );\r
771\r
772 if (EFI_ERROR (Status)) {\r
773 return Status;\r
774 }\r
775\r
776 Status = gBS->HandleProtocol (\r
777 Handle,\r
778 &gEfiSimpleTextOutProtocolGuid,\r
779 (VOID **) &Sto\r
780 );\r
781\r
782 if (EFI_ERROR (Status)) {\r
783 return Status;\r
784 }\r
785\r
786 return _IPrint (UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
787}\r