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.
28 IN UINTN BmpImageSize
,
30 IN OUT UINTN
*GopBltSize
,
31 OUT UINTN
*PixelHeight
,
36 GetGraphicsBitMapFromFV (
37 IN EFI_GUID
*FileNameGuid
,
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
51 FileNameGuid - File Name of graphics file in the FV(s).
53 Image - Pointer to pointer to return graphics image. If NULL, a
54 buffer will be allocated.
56 ImageSize - Size of the graphics Image in bytes. Zero if no image found.
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
68 UINTN FvProtocolCount
;
69 EFI_HANDLE
*FvHandles
;
70 EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
;
72 UINT32 AuthenticationStatus
;
75 Status
= gBS
->LocateHandleBuffer (
77 &gEfiFirmwareVolumeProtocolGuid
,
82 if (EFI_ERROR (Status
)) {
86 for (Index
= 0; Index
< FvProtocolCount
; Index
++) {
87 Status
= gBS
->HandleProtocol (
89 &gEfiFirmwareVolumeProtocolGuid
,
94 // Assuming Image and ImageSize are correct on input.
96 Status
= Fv
->ReadSection (
98 &gEfiDefaultBmpLogoGuid
,
103 &AuthenticationStatus
105 if (!EFI_ERROR (Status
)) {
107 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
109 // ImageSize updated to needed size so return
111 return EFI_BUFFER_TOO_SMALL
;
115 return EFI_NOT_FOUND
;
121 IN UINTN BmpImageSize
,
122 IN OUT VOID
**GopBlt
,
123 IN OUT UINTN
*GopBltSize
,
124 OUT UINTN
*PixelHeight
,
125 OUT UINTN
*PixelWidth
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.
137 BmpImage - Pointer to BMP file
139 BmpImageSize - Number of bytes in BmpImage
141 UgaBlt - Buffer containing UGA version of BmpImage.
143 UgaBltSize - Size of UgaBlt in bytes.
145 PixelHeight - Height of UgaBlt/BmpImage in pixels
147 PixelWidth - Width of UgaBlt/BmpImage in pixels
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
162 BMP_IMAGE_HEADER
*BmpHeader
;
163 BMP_COLOR_MAP
*BmpColorMap
;
164 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
165 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
173 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
174 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
175 return EFI_UNSUPPORTED
;
178 if (BmpHeader
->CompressionType
!= 0) {
179 return EFI_UNSUPPORTED
;
183 // Calculate Color Map offset in the image.
186 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
189 // Calculate graphics image data address in the image
191 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
194 BltBufferSize
= BmpHeader
->PixelWidth
* BmpHeader
->PixelHeight
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
196 if (*GopBlt
== NULL
) {
197 *GopBltSize
= BltBufferSize
;
198 *GopBlt
= AllocatePool (*GopBltSize
);
200 if (*GopBlt
== NULL
) {
201 return EFI_OUT_OF_RESOURCES
;
204 if (*GopBltSize
< BltBufferSize
) {
205 *GopBltSize
= BltBufferSize
;
206 return EFI_BUFFER_TOO_SMALL
;
210 *PixelWidth
= BmpHeader
->PixelWidth
;
211 *PixelHeight
= BmpHeader
->PixelHeight
;
214 // Convert image from BMP to Blt buffer format
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
) {
223 // Convert 1bit BMP to 24-bit color
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
;
239 // Convert BMP Palette to 24-bit color
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)) {
248 Index
= (*Image
) & 0x0f;
249 Blt
->Red
= BmpColorMap
[Index
].Red
;
250 Blt
->Green
= BmpColorMap
[Index
].Green
;
251 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
257 // Convert BMP Palette to 24-bit color
259 Blt
->Red
= BmpColorMap
[*Image
].Red
;
260 Blt
->Green
= BmpColorMap
[*Image
].Green
;
261 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
265 Blt
->Blue
= *Image
++;
266 Blt
->Green
= *Image
++;
272 gBS
->FreePool (*GopBlt
);
275 return EFI_UNSUPPORTED
;
281 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
282 if ((ImageIndex
% 4) != 0) {
284 // Bmp Image starts each row on a 32-bit boundary!
286 Image
= Image
+ (4 - (ImageIndex
% 4));
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.
307 Password - Password used to lock ConIn device
312 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
314 EFI_UNSUPPORTED - Logo not found
319 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
321 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
322 if (EFI_ERROR (Status
)) {
323 return EFI_UNSUPPORTED
;
326 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
333 IN EFI_GUID
*LogoFile
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
344 LogoFile - File name of logo to display on the center of the screen.
349 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
351 EFI_UNSUPPORTED - Logo not found
356 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
357 EFI_OEM_BADGING_PROTOCOL
*Badging
;
366 EFI_BADGING_FORMAT Format
;
367 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
372 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
373 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
376 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
378 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
379 if (EFI_ERROR (Status
)) {
380 return EFI_UNSUPPORTED
;
385 // Try to open GOP first
387 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**) &GraphicsOutput
);
388 if (EFI_ERROR(Status
)) {
389 GraphicsOutput
= NULL
;
391 // Open GOP failed, try to open UGA
393 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**) &UgaDraw
);
394 if (EFI_ERROR (Status
)) {
395 return EFI_UNSUPPORTED
;
400 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**) &Badging
);
402 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
404 if (GraphicsOutput
!= NULL
) {
405 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
406 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
408 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
409 if (EFI_ERROR (Status
)) {
410 return EFI_UNSUPPORTED
;
419 if (Badging
!= NULL
) {
420 Status
= Badging
->GetImage (
430 if (EFI_ERROR (Status
)) {
435 // Currently only support BMP format
437 if (Format
!= EfiBadgingFormatBMP
) {
438 gBS
->FreePool (ImageData
);
442 Status
= GetGraphicsBitMapFromFV (LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
443 if (EFI_ERROR (Status
)) {
444 return EFI_UNSUPPORTED
;
449 Attribute
= EfiBadgingDisplayAttributeCenter
;
453 Status
= ConvertBmpToGopBlt (
461 if (EFI_ERROR (Status
)) {
462 gBS
->FreePool (ImageData
);
463 if (Badging
== NULL
) {
471 case EfiBadgingDisplayAttributeLeftTop
:
476 case EfiBadgingDisplayAttributeCenterTop
:
477 DestX
= (SizeOfX
- Width
) / 2;
481 case EfiBadgingDisplayAttributeRightTop
:
482 DestX
= (SizeOfX
- Width
- CoordinateX
);
483 DestY
= CoordinateY
;;
486 case EfiBadgingDisplayAttributeCenterRight
:
487 DestX
= (SizeOfX
- Width
- CoordinateX
);
488 DestY
= (SizeOfY
- Height
) / 2;
491 case EfiBadgingDisplayAttributeRightBottom
:
492 DestX
= (SizeOfX
- Width
- CoordinateX
);
493 DestY
= (SizeOfY
- Height
- CoordinateY
);
496 case EfiBadgingDisplayAttributeCenterBottom
:
497 DestX
= (SizeOfX
- Width
) / 2;
498 DestY
= (SizeOfY
- Height
- CoordinateY
);
501 case EfiBadgingDisplayAttributeLeftBottom
:
503 DestY
= (SizeOfY
- Height
- CoordinateY
);
506 case EfiBadgingDisplayAttributeCenterLeft
:
508 DestY
= (SizeOfY
- Height
) / 2;
511 case EfiBadgingDisplayAttributeCenter
:
512 DestX
= (SizeOfX
- Width
) / 2;
513 DestY
= (SizeOfY
- Height
) / 2;
522 if ((DestX
>= 0) && (DestY
>= 0)) {
523 if (GraphicsOutput
!= NULL
) {
524 Status
= GraphicsOutput
->Blt (
534 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
537 Status
= UgaDraw
->Blt (
539 (EFI_UGA_PIXEL
*) Blt
,
540 EfiUgaBltBufferToVideo
,
547 Width
* sizeof (EFI_UGA_PIXEL
)
552 gBS
->FreePool (ImageData
);
555 if (Badging
== NULL
) {
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
581 EFI_SUCCESS - UGA devices are back in text mode and synced up.
582 EFI_UNSUPPORTED - Logo not found
587 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
589 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
590 if (EFI_ERROR (Status
)) {
591 return EFI_UNSUPPORTED
;
594 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);
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 }
619 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
620 IN EFI_UGA_DRAW_PROTOCOL
*UgaDraw
,
621 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
,
624 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
625 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
,
633 Display string worker for: Print, PrintAt, IPrint, IPrintAt
637 GraphicsOutput - Graphics output protocol interface
639 UgaDraw - UGA draw protocol interface
641 Sto - Simple text out protocol interface
643 X - X coordinate to start printing
645 Y - Y coordinate to start printing
647 Foreground - Foreground color
649 Background - Background color
653 args - Print arguments
657 EFI_SUCCESS - success
658 EFI_OUT_OF_RESOURCES - out of resources
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
;
676 UINTN BufferGlyphWidth
;
681 // For now, allocate an arbitrarily long buffer
683 Buffer
= AllocateZeroPool (0x10000);
684 if (Buffer
== NULL
) {
685 return EFI_OUT_OF_RESOURCES
;
688 if (GraphicsOutput
!= NULL
) {
689 HorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
690 VerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
693 // Get the current mode information from the UGA Draw Protocol
695 UgaDraw
->GetMode (UgaDraw
, &HorizontalResolution
, &VerticalResolution
, &ColorDepth
, &RefreshRate
);
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
;
704 Status
= gBS
->LocateProtocol (&gEfiHiiProtocolGuid
, NULL
, (VOID
**) &Hii
);
705 if (EFI_ERROR (Status
)) {
709 UnicodeVSPrint (Buffer
, 0x10000, fmt
, args
);
711 UnicodeWeight
= (CHAR16
*) Buffer
;
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;
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
)) {
728 if (Foreground
== NULL
|| Background
== NULL
) {
729 Status
= Hii
->GlyphToBlt (
732 mEfiColors
[Sto
->Mode
->Attribute
& 0x0f],
733 mEfiColors
[Sto
->Mode
->Attribute
>> 4],
737 &LineBuffer
[Index
* GLYPH_WIDTH
]
740 Status
= Hii
->GlyphToBlt (
748 &LineBuffer
[Index
* GLYPH_WIDTH
]
754 // Blt a character to the screen
756 BufferGlyphWidth
= GLYPH_WIDTH
* StrLen (Buffer
);
757 if (GraphicsOutput
!= NULL
) {
758 Status
= GraphicsOutput
->Blt (
768 BufferGlyphWidth
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
771 Status
= UgaDraw
->Blt (
773 (EFI_UGA_PIXEL
*) (UINTN
) LineBuffer
,
774 EfiUgaBltBufferToVideo
,
781 BufferGlyphWidth
* sizeof (EFI_UGA_PIXEL
)
786 gBS
->FreePool (LineBuffer
);
787 gBS
->FreePool (Buffer
);
796 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*ForeGround
, OPTIONAL
797 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BackGround
, OPTIONAL
805 Prints a formatted unicode string to the default console
809 X - X coordinate to start printing
811 Y - Y coordinate to start printing
813 ForeGround - Foreground color
815 BackGround - Background color
819 ... - Print arguments
823 Length of string printed to the console
829 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
830 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
831 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
;
835 VA_START (Args
, Fmt
);
839 Handle
= gST
->ConsoleOutHandle
;
841 Status
= gBS
->HandleProtocol (
843 &gEfiGraphicsOutputProtocolGuid
,
844 (VOID
**) &GraphicsOutput
847 if (EFI_ERROR (Status
)) {
848 GraphicsOutput
= NULL
;
850 Status
= gBS
->HandleProtocol (
852 &gEfiUgaDrawProtocolGuid
,
856 if (EFI_ERROR (Status
)) {
861 Status
= gBS
->HandleProtocol (
863 &gEfiSimpleTextOutProtocolGuid
,
867 if (EFI_ERROR (Status
)) {
871 return _IPrint (GraphicsOutput
, UgaDraw
, Sto
, X
, Y
, ForeGround
, BackGround
, Fmt
, Args
);