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
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.
18 Support for Basic Graphics operations.
20 BugBug: Currently *.BMP files are supported. This will be replaced
21 when Tiano graphics format is supported.
27 GetGraphicsBitMapFromFV (
28 IN EFI_GUID
*FileNameGuid
,
36 Return the graphics image file named FileNameGuid into Image and return it's
37 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
42 FileNameGuid - File Name of graphics file in the FV(s).
44 Image - Pointer to pointer to return graphics image. If NULL, a
45 buffer will be allocated.
47 ImageSize - Size of the graphics Image in bytes. Zero if no image found.
52 EFI_SUCCESS - Image and ImageSize are valid.
53 EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
54 EFI_NOT_FOUND - FileNameGuid not found
59 UINTN FvProtocolCount
;
60 EFI_HANDLE
*FvHandles
;
61 EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
;
63 UINT32 AuthenticationStatus
;
66 Status
= gBS
->LocateHandleBuffer (
68 &gEfiFirmwareVolumeProtocolGuid
,
73 if (EFI_ERROR (Status
)) {
77 for (Index
= 0; Index
< FvProtocolCount
; Index
++) {
78 Status
= gBS
->HandleProtocol (
80 &gEfiFirmwareVolumeProtocolGuid
,
85 // Assuming Image and ImageSize are correct on input.
87 Status
= Fv
->ReadSection (
96 if (!EFI_ERROR (Status
)) {
98 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
100 // ImageSize updated to needed size so return
102 return EFI_BUFFER_TOO_SMALL
;
106 return EFI_NOT_FOUND
;
113 IN UINTN BmpImageSize
,
114 IN OUT VOID
**GopBlt
,
115 IN OUT UINTN
*GopBltSize
,
116 OUT UINTN
*PixelHeight
,
117 OUT UINTN
*PixelWidth
123 Convert a *.BMP graphics image to a UGA blt buffer. If a NULL UgaBlt buffer
124 is passed in a UgaBlt buffer will be allocated by this routine. If a UgaBlt
125 buffer is passed in it will be used if it is big enough.
129 BmpImage - Pointer to BMP file
131 BmpImageSize - Number of bytes in BmpImage
133 UgaBlt - Buffer containing UGA version of BmpImage.
135 UgaBltSize - Size of UgaBlt in bytes.
137 PixelHeight - Height of UgaBlt/BmpImage in pixels
139 PixelWidth - Width of UgaBlt/BmpImage in pixels
144 EFI_SUCCESS - UgaBlt and UgaBltSize are returned.
145 EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image
146 EFI_BUFFER_TOO_SMALL - The passed in UgaBlt buffer is not big enough.
147 UgaBltSize will contain the required size.
148 EFI_OUT_OF_RESOURCES - No enough buffer to allocate
154 BMP_IMAGE_HEADER
*BmpHeader
;
155 BMP_COLOR_MAP
*BmpColorMap
;
156 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
157 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
165 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
166 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
167 return EFI_UNSUPPORTED
;
170 if (BmpHeader
->CompressionType
!= 0) {
171 return EFI_UNSUPPORTED
;
175 // Calculate Color Map offset in the image.
178 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
181 // Calculate graphics image data address in the image
183 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
186 BltBufferSize
= BmpHeader
->PixelWidth
* BmpHeader
->PixelHeight
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
188 if (*GopBlt
== NULL
) {
189 *GopBltSize
= BltBufferSize
;
190 *GopBlt
= AllocatePool (*GopBltSize
);
192 if (*GopBlt
== NULL
) {
193 return EFI_OUT_OF_RESOURCES
;
196 if (*GopBltSize
< BltBufferSize
) {
197 *GopBltSize
= BltBufferSize
;
198 return EFI_BUFFER_TOO_SMALL
;
202 *PixelWidth
= BmpHeader
->PixelWidth
;
203 *PixelHeight
= BmpHeader
->PixelHeight
;
206 // Convert image from BMP to Blt buffer format
209 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
210 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
211 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
212 switch (BmpHeader
->BitPerPixel
) {
215 // Convert 1bit BMP to 24-bit color
217 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
218 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
219 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
220 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
231 // Convert BMP Palette to 24-bit color
233 Index
= (*Image
) >> 4;
234 Blt
->Red
= BmpColorMap
[Index
].Red
;
235 Blt
->Green
= BmpColorMap
[Index
].Green
;
236 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
237 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
240 Index
= (*Image
) & 0x0f;
241 Blt
->Red
= BmpColorMap
[Index
].Red
;
242 Blt
->Green
= BmpColorMap
[Index
].Green
;
243 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
249 // Convert BMP Palette to 24-bit color
251 Blt
->Red
= BmpColorMap
[*Image
].Red
;
252 Blt
->Green
= BmpColorMap
[*Image
].Green
;
253 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
257 Blt
->Blue
= *Image
++;
258 Blt
->Green
= *Image
++;
264 gBS
->FreePool (*GopBlt
);
267 return EFI_UNSUPPORTED
;
273 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
274 if ((ImageIndex
% 4) != 0) {
276 // Bmp Image starts each row on a 32-bit boundary!
278 Image
= Image
+ (4 - (ImageIndex
% 4));
293 Use Console Control Protocol to lock the Console In Spliter virtual handle.
294 This is the ConInHandle and ConIn handle in the EFI system table. All key
295 presses will be ignored until the Password is typed in. The only way to
296 disable the password is to type it in to a ConIn device.
299 Password - Password used to lock ConIn device
304 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
306 EFI_UNSUPPORTED - Logo not found
311 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
313 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
314 if (EFI_ERROR (Status
)) {
315 return EFI_UNSUPPORTED
;
318 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
325 IN EFI_GUID
*LogoFile
331 Use Console Control to turn off UGA based Simple Text Out consoles from going
332 to the UGA device. Put up LogoFile on every UGA device that is a console
336 LogoFile - File name of logo to display on the center of the screen.
341 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
343 EFI_UNSUPPORTED - Logo not found
348 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
349 EFI_OEM_BADGING_PROTOCOL
*Badging
;
358 EFI_BADGING_FORMAT Format
;
359 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
364 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
365 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
368 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
370 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
371 if (EFI_ERROR (Status
)) {
372 return EFI_UNSUPPORTED
;
377 // Try to open GOP first
379 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**) &GraphicsOutput
);
380 if (EFI_ERROR(Status
)) {
381 GraphicsOutput
= NULL
;
383 // Open GOP failed, try to open UGA
385 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**) &UgaDraw
);
386 if (EFI_ERROR (Status
)) {
387 return EFI_UNSUPPORTED
;
392 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**) &Badging
);
394 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
396 if (GraphicsOutput
!= NULL
) {
397 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
398 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
400 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
401 if (EFI_ERROR (Status
)) {
402 return EFI_UNSUPPORTED
;
411 if (Badging
!= NULL
) {
412 Status
= Badging
->GetImage (
422 if (EFI_ERROR (Status
)) {
427 // Currently only support BMP format
429 if (Format
!= EfiBadgingFormatBMP
) {
430 gBS
->FreePool (ImageData
);
434 Status
= GetGraphicsBitMapFromFV (LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
435 if (EFI_ERROR (Status
)) {
436 return EFI_UNSUPPORTED
;
441 Attribute
= EfiBadgingDisplayAttributeCenter
;
446 Status
= ConvertBmpToGopBlt (
454 if (EFI_ERROR (Status
)) {
455 gBS
->FreePool (ImageData
);
456 if (Badging
== NULL
) {
464 case EfiBadgingDisplayAttributeLeftTop
:
469 case EfiBadgingDisplayAttributeCenterTop
:
470 DestX
= (SizeOfX
- Width
) / 2;
474 case EfiBadgingDisplayAttributeRightTop
:
475 DestX
= (SizeOfX
- Width
- CoordinateX
);
476 DestY
= CoordinateY
;;
479 case EfiBadgingDisplayAttributeCenterRight
:
480 DestX
= (SizeOfX
- Width
- CoordinateX
);
481 DestY
= (SizeOfY
- Height
) / 2;
484 case EfiBadgingDisplayAttributeRightBottom
:
485 DestX
= (SizeOfX
- Width
- CoordinateX
);
486 DestY
= (SizeOfY
- Height
- CoordinateY
);
489 case EfiBadgingDisplayAttributeCenterBottom
:
490 DestX
= (SizeOfX
- Width
) / 2;
491 DestY
= (SizeOfY
- Height
- CoordinateY
);
494 case EfiBadgingDisplayAttributeLeftBottom
:
496 DestY
= (SizeOfY
- Height
- CoordinateY
);
499 case EfiBadgingDisplayAttributeCenterLeft
:
501 DestY
= (SizeOfY
- Height
) / 2;
504 case EfiBadgingDisplayAttributeCenter
:
505 DestX
= (SizeOfX
- Width
) / 2;
506 DestY
= (SizeOfY
- Height
) / 2;
515 if ((DestX
>= 0) && (DestY
>= 0)) {
516 if (GraphicsOutput
!= NULL
) {
517 Status
= GraphicsOutput
->Blt (
527 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
530 Status
= UgaDraw
->Blt (
532 (EFI_UGA_PIXEL
*) Blt
,
533 EfiUgaBltBufferToVideo
,
540 Width
* sizeof (EFI_UGA_PIXEL
)
545 gBS
->FreePool (ImageData
);
548 if (Badging
== NULL
) {
565 Use Console Control to turn on UGA based Simple Text Out consoles. The UGA
566 Simple Text Out screens will now be synced up with all non UGA output devices
574 EFI_SUCCESS - UGA devices are back in text mode and synced up.
575 EFI_UNSUPPORTED - Logo not found
580 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
582 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
583 if (EFI_ERROR (Status
)) {
584 return EFI_UNSUPPORTED
;
587 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);
590 static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors
[16] = {
591 { 0x00, 0x00, 0x00, 0x00 },
592 { 0x98, 0x00, 0x00, 0x00 },
593 { 0x00, 0x98, 0x00, 0x00 },
594 { 0x98, 0x98, 0x00, 0x00 },
595 { 0x00, 0x00, 0x98, 0x00 },
596 { 0x98, 0x00, 0x98, 0x00 },
597 { 0x00, 0x98, 0x98, 0x00 },
598 { 0x98, 0x98, 0x98, 0x00 },
599 { 0x10, 0x10, 0x10, 0x00 },
600 { 0xff, 0x10, 0x10, 0x00 },
601 { 0x10, 0xff, 0x10, 0x00 },
602 { 0xff, 0xff, 0x10, 0x00 },
603 { 0x10, 0x10, 0xff, 0x00 },
604 { 0xf0, 0x10, 0xff, 0x00 },
605 { 0x10, 0xff, 0xff, 0x00 },
606 { 0xff, 0xff, 0xff, 0x00 }
612 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
613 IN EFI_UGA_DRAW_PROTOCOL
*UgaDraw
,
614 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
,
617 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
618 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
,
626 Display string worker for: Print, PrintAt, IPrint, IPrintAt
630 GraphicsOutput - Graphics output protocol interface
632 UgaDraw - UGA draw protocol interface
634 Sto - Simple text out protocol interface
636 X - X coordinate to start printing
638 Y - Y coordinate to start printing
640 Foreground - Foreground color
642 Background - Background color
646 args - Print arguments
650 EFI_SUCCESS - success
651 EFI_OUT_OF_RESOURCES - out of resources
661 CHAR16
*UnicodeWeight
;
662 EFI_NARROW_GLYPH
*Glyph
;
663 EFI_HII_PROTOCOL
*Hii
;
664 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*LineBuffer
;
665 UINT32 HorizontalResolution
;
666 UINT32 VerticalResolution
;
669 UINTN BufferGlyphWidth
;
674 // For now, allocate an arbitrarily long buffer
676 Buffer
= AllocateZeroPool (0x10000);
677 if (Buffer
== NULL
) {
678 return EFI_OUT_OF_RESOURCES
;
681 if (GraphicsOutput
!= NULL
) {
682 HorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
683 VerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
686 // Get the current mode information from the UGA Draw Protocol
688 UgaDraw
->GetMode (UgaDraw
, &HorizontalResolution
, &VerticalResolution
, &ColorDepth
, &RefreshRate
);
691 LineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * HorizontalResolution
* GLYPH_WIDTH
* GLYPH_HEIGHT
);
692 if (LineBuffer
== NULL
) {
693 gBS
->FreePool (Buffer
);
694 return EFI_OUT_OF_RESOURCES
;
697 Status
= gBS
->LocateProtocol (&gEfiHiiProtocolGuid
, NULL
, (VOID
**) &Hii
);
698 if (EFI_ERROR (Status
)) {
702 UnicodeVSPrint (Buffer
, 0x10000, fmt
, args
);
704 UnicodeWeight
= (CHAR16
*) Buffer
;
706 for (Index
= 0; UnicodeWeight
[Index
] != 0; Index
++) {
707 if (UnicodeWeight
[Index
] == CHAR_BACKSPACE
||
708 UnicodeWeight
[Index
] == CHAR_LINEFEED
||
709 UnicodeWeight
[Index
] == CHAR_CARRIAGE_RETURN
) {
710 UnicodeWeight
[Index
] = 0;
714 for (Index
= 0; Index
< StrLen (Buffer
); Index
++) {
715 StringIndex
= (UINT16
) Index
;
716 Status
= Hii
->GetGlyph (Hii
, UnicodeWeight
, &StringIndex
, (UINT8
**) &Glyph
, &GlyphWidth
, &GlyphStatus
);
717 if (EFI_ERROR (Status
)) {
721 if (Foreground
== NULL
|| Background
== NULL
) {
722 Status
= Hii
->GlyphToBlt (
725 mEfiColors
[Sto
->Mode
->Attribute
& 0x0f],
726 mEfiColors
[Sto
->Mode
->Attribute
>> 4],
730 &LineBuffer
[Index
* GLYPH_WIDTH
]
733 Status
= Hii
->GlyphToBlt (
741 &LineBuffer
[Index
* GLYPH_WIDTH
]
747 // Blt a character to the screen
749 BufferGlyphWidth
= GLYPH_WIDTH
* StrLen (Buffer
);
750 if (GraphicsOutput
!= NULL
) {
751 Status
= GraphicsOutput
->Blt (
761 BufferGlyphWidth
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
764 Status
= UgaDraw
->Blt (
766 (EFI_UGA_PIXEL
*) (UINTN
) LineBuffer
,
767 EfiUgaBltBufferToVideo
,
774 BufferGlyphWidth
* sizeof (EFI_UGA_PIXEL
)
779 gBS
->FreePool (LineBuffer
);
780 gBS
->FreePool (Buffer
);
789 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*ForeGround
, OPTIONAL
790 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BackGround
, OPTIONAL
798 Prints a formatted unicode string to the default console
802 X - X coordinate to start printing
804 Y - Y coordinate to start printing
806 ForeGround - Foreground color
808 BackGround - Background color
812 ... - Print arguments
816 Length of string printed to the console
822 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
823 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
824 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
;
828 VA_START (Args
, Fmt
);
832 Handle
= gST
->ConsoleOutHandle
;
834 Status
= gBS
->HandleProtocol (
836 &gEfiGraphicsOutputProtocolGuid
,
837 (VOID
**) &GraphicsOutput
840 if (EFI_ERROR (Status
)) {
841 GraphicsOutput
= NULL
;
843 Status
= gBS
->HandleProtocol (
845 &gEfiUgaDrawProtocolGuid
,
849 if (EFI_ERROR (Status
)) {
854 Status
= gBS
->HandleProtocol (
856 &gEfiSimpleTextOutProtocolGuid
,
860 if (EFI_ERROR (Status
)) {
864 return _IPrint (GraphicsOutput
, UgaDraw
, Sto
, X
, Y
, ForeGround
, BackGround
, Fmt
, Args
);