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