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