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.
26 GetGraphicsBitMapFromFV (
27 IN EFI_GUID
*FileNameGuid
,
35 Return the graphics image file named FileNameGuid into Image and return it's
36 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
41 FileNameGuid - File Name of graphics file in the FV(s).
43 Image - Pointer to pointer to return graphics image. If NULL, a
44 buffer will be allocated.
46 ImageSize - Size of the graphics Image in bytes. Zero if no image found.
51 EFI_SUCCESS - Image and ImageSize are valid.
52 EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
53 EFI_NOT_FOUND - FileNameGuid not found
58 UINTN FvProtocolCount
;
59 EFI_HANDLE
*FvHandles
;
60 EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
;
62 UINT32 AuthenticationStatus
;
65 Status
= gBS
->LocateHandleBuffer (
67 &gEfiFirmwareVolumeProtocolGuid
,
72 if (EFI_ERROR (Status
)) {
76 for (Index
= 0; Index
< FvProtocolCount
; Index
++) {
77 Status
= gBS
->HandleProtocol (
79 &gEfiFirmwareVolumeProtocolGuid
,
84 // Assuming Image and ImageSize are correct on input.
86 Status
= Fv
->ReadSection (
88 &gEfiDefaultBmpLogoGuid
,
95 if (!EFI_ERROR (Status
)) {
97 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
99 // ImageSize updated to needed size so return
101 return EFI_BUFFER_TOO_SMALL
;
105 return EFI_NOT_FOUND
;
112 IN UINTN BmpImageSize
,
113 IN OUT VOID
**UgaBlt
,
114 IN OUT UINTN
*UgaBltSize
,
115 OUT UINTN
*PixelHeight
,
116 OUT UINTN
*PixelWidth
122 Convert a *.BMP graphics image to a UGA blt buffer. If a NULL UgaBlt buffer
123 is passed in a UgaBlt buffer will be allocated by this routine. If a UgaBlt
124 buffer is passed in it will be used if it is big enough.
128 BmpImage - Pointer to BMP file
130 BmpImageSize - Number of bytes in BmpImage
132 UgaBlt - Buffer containing UGA version of BmpImage.
134 UgaBltSize - Size of UgaBlt in bytes.
136 PixelHeight - Height of UgaBlt/BmpImage in pixels
138 PixelWidth - Width of UgaBlt/BmpImage in pixels
143 EFI_SUCCESS - UgaBlt and UgaBltSize are returned.
144 EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image
145 EFI_BUFFER_TOO_SMALL - The passed in UgaBlt buffer is not big enough.
146 UgaBltSize will contain the required size.
147 EFI_OUT_OF_RESOURCES - No enough buffer to allocate
153 BMP_IMAGE_HEADER
*BmpHeader
;
154 BMP_COLOR_MAP
*BmpColorMap
;
155 EFI_UGA_PIXEL
*BltBuffer
;
164 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
165 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
166 return EFI_UNSUPPORTED
;
169 if (BmpHeader
->CompressionType
!= 0) {
170 return EFI_UNSUPPORTED
;
174 // Calculate Color Map offset in the image.
177 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
180 // Calculate graphics image data address in the image
182 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
185 BltBufferSize
= BmpHeader
->PixelWidth
* BmpHeader
->PixelHeight
* sizeof (EFI_UGA_PIXEL
);
187 if (*UgaBlt
== NULL
) {
188 *UgaBltSize
= BltBufferSize
;
189 *UgaBlt
= AllocatePool (*UgaBltSize
);
190 if (*UgaBlt
== NULL
) {
191 return EFI_OUT_OF_RESOURCES
;
195 if (*UgaBltSize
< BltBufferSize
) {
196 *UgaBltSize
= BltBufferSize
;
197 return EFI_BUFFER_TOO_SMALL
;
201 *PixelWidth
= BmpHeader
->PixelWidth
;
202 *PixelHeight
= BmpHeader
->PixelHeight
;
205 // Convert image from BMP to Blt buffer format
208 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
209 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
210 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
211 switch (BmpHeader
->BitPerPixel
) {
214 // Convert 1bit BMP to 24-bit color
216 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
217 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
218 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
219 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
230 // Convert BMP Palette to 24-bit color
232 Index
= (*Image
) >> 4;
233 Blt
->Red
= BmpColorMap
[Index
].Red
;
234 Blt
->Green
= BmpColorMap
[Index
].Green
;
235 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
236 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
239 Index
= (*Image
) & 0x0f;
240 Blt
->Red
= BmpColorMap
[Index
].Red
;
241 Blt
->Green
= BmpColorMap
[Index
].Green
;
242 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
248 // Convert BMP Palette to 24-bit color
250 Blt
->Red
= BmpColorMap
[*Image
].Red
;
251 Blt
->Green
= BmpColorMap
[*Image
].Green
;
252 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
256 Blt
->Blue
= *Image
++;
257 Blt
->Green
= *Image
++;
263 gBS
->FreePool (*UgaBlt
);
266 return EFI_UNSUPPORTED
;
272 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
273 if ((ImageIndex
% 4) != 0) {
275 // Bmp Image starts each row on a 32-bit boundary!
277 Image
= Image
+ (4 - (ImageIndex
% 4));
292 Use Console Control Protocol to lock the Console In Spliter virtual handle.
293 This is the ConInHandle and ConIn handle in the EFI system table. All key
294 presses will be ignored until the Password is typed in. The only way to
295 disable the password is to type it in to a ConIn device.
298 Password - Password used to lock ConIn device
303 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
305 EFI_UNSUPPORTED - Logo not found
310 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
312 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
313 if (EFI_ERROR (Status
)) {
314 return EFI_UNSUPPORTED
;
317 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
324 IN EFI_GUID
*LogoFile
330 Use Console Control to turn off UGA based Simple Text Out consoles from going
331 to the UGA device. Put up LogoFile on every UGA device that is a console
335 LogoFile - File name of logo to display on the center of the screen.
340 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
342 EFI_UNSUPPORTED - Logo not found
347 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
348 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
349 EFI_OEM_BADGING_PROTOCOL
*Badging
;
359 EFI_UGA_PIXEL
*UgaBlt
;
363 EFI_BADGING_FORMAT Format
;
364 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
370 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
371 if (EFI_ERROR (Status
)) {
372 return EFI_UNSUPPORTED
;
375 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**) &UgaDraw
);
376 if (EFI_ERROR (Status
)) {
377 return EFI_UNSUPPORTED
;
381 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**) &Badging
);
383 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
385 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
386 if (EFI_ERROR (Status
)) {
387 return EFI_UNSUPPORTED
;
395 if (Badging
!= NULL
) {
396 Status
= Badging
->GetImage (
406 if (EFI_ERROR (Status
)) {
411 // Currently only support BMP format
413 if (Format
!= EfiBadgingFormatBMP
) {
414 gBS
->FreePool (ImageData
);
418 Status
= GetGraphicsBitMapFromFV (LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
419 if (EFI_ERROR (Status
)) {
420 return EFI_UNSUPPORTED
;
425 Attribute
= EfiBadgingDisplayAttributeCenter
;
429 Status
= ConvertBmpToUgaBlt (
437 if (EFI_ERROR (Status
)) {
438 gBS
->FreePool (ImageData
);
443 case EfiBadgingDisplayAttributeLeftTop
:
448 case EfiBadgingDisplayAttributeCenterTop
:
449 DestX
= (SizeOfX
- Width
) / 2;
453 case EfiBadgingDisplayAttributeRightTop
:
454 DestX
= (SizeOfX
- Width
- CoordinateX
);
455 DestY
= CoordinateY
;;
458 case EfiBadgingDisplayAttributeCenterRight
:
459 DestX
= (SizeOfX
- Width
- CoordinateX
);
460 DestY
= (SizeOfY
- Height
) / 2;
463 case EfiBadgingDisplayAttributeRightBottom
:
464 DestX
= (SizeOfX
- Width
- CoordinateX
);
465 DestY
= (SizeOfY
- Height
- CoordinateY
);
468 case EfiBadgingDisplayAttributeCenterBottom
:
469 DestX
= (SizeOfX
- Width
) / 2;
470 DestY
= (SizeOfY
- Height
- CoordinateY
);
473 case EfiBadgingDisplayAttributeLeftBottom
:
475 DestY
= (SizeOfY
- Height
- CoordinateY
);
478 case EfiBadgingDisplayAttributeCenterLeft
:
480 DestY
= (SizeOfY
- Height
) / 2;
483 case EfiBadgingDisplayAttributeCenter
:
484 DestX
= (SizeOfX
- Width
) / 2;
485 DestY
= (SizeOfY
- Height
) / 2;
494 if ((DestX
>= 0) && (DestY
>= 0)) {
495 Status
= UgaDraw
->Blt (
498 EfiUgaBltBufferToVideo
,
505 Width
* sizeof (EFI_UGA_PIXEL
)
509 gBS
->FreePool (ImageData
);
510 gBS
->FreePool (UgaBlt
);
512 if (Badging
== NULL
) {
529 Use Console Control to turn on UGA based Simple Text Out consoles. The UGA
530 Simple Text Out screens will now be synced up with all non UGA output devices
538 EFI_SUCCESS - UGA devices are back in text mode and synced up.
539 EFI_UNSUPPORTED - Logo not found
544 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
546 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
547 if (EFI_ERROR (Status
)) {
548 return EFI_UNSUPPORTED
;
551 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);
554 static EFI_UGA_PIXEL mEfiColors
[16] = {
555 { 0x00, 0x00, 0x00, 0x00 },
556 { 0x98, 0x00, 0x00, 0x00 },
557 { 0x00, 0x98, 0x00, 0x00 },
558 { 0x98, 0x98, 0x00, 0x00 },
559 { 0x00, 0x00, 0x98, 0x00 },
560 { 0x98, 0x00, 0x98, 0x00 },
561 { 0x00, 0x98, 0x98, 0x00 },
562 { 0x98, 0x98, 0x98, 0x00 },
563 { 0x10, 0x10, 0x10, 0x00 },
564 { 0xff, 0x10, 0x10, 0x00 },
565 { 0x10, 0xff, 0x10, 0x00 },
566 { 0xff, 0xff, 0x10, 0x00 },
567 { 0x10, 0x10, 0xff, 0x00 },
568 { 0xf0, 0x10, 0xff, 0x00 },
569 { 0x10, 0xff, 0xff, 0x00 },
570 { 0xff, 0xff, 0xff, 0x00 }
576 IN EFI_UGA_DRAW_PROTOCOL
*UgaDraw
,
577 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
,
580 IN EFI_UGA_PIXEL
*Foreground
,
581 IN EFI_UGA_PIXEL
*Background
,
589 Display string worker for: Print, PrintAt, IPrint, IPrintAt
593 UgaDraw - UGA draw protocol interface
595 Sto - Simple text out protocol interface
597 X - X coordinate to start printing
599 Y - Y coordinate to start printing
601 Foreground - Foreground color
603 Background - Background color
607 args - Print arguments
611 EFI_SUCCESS - success
612 EFI_OUT_OF_RESOURCES - out of resources
622 CHAR16
*UnicodeWeight
;
623 EFI_NARROW_GLYPH
*Glyph
;
624 EFI_HII_PROTOCOL
*Hii
;
625 EFI_UGA_PIXEL
*LineBuffer
;
626 UINT32 HorizontalResolution
;
627 UINT32 VerticalResolution
;
634 // For now, allocate an arbitrarily long buffer
636 Buffer
= AllocateZeroPool (0x10000);
637 if (Buffer
== NULL
) {
638 return EFI_OUT_OF_RESOURCES
;
641 UgaDraw
->GetMode (UgaDraw
, &HorizontalResolution
, &VerticalResolution
, &ColorDepth
, &RefreshRate
);
643 LineBuffer
= AllocatePool (sizeof (EFI_UGA_PIXEL
) * HorizontalResolution
* GLYPH_WIDTH
* GLYPH_HEIGHT
);
644 if (LineBuffer
== NULL
) {
645 gBS
->FreePool (Buffer
);
646 return EFI_OUT_OF_RESOURCES
;
649 Status
= gBS
->LocateProtocol (&gEfiHiiProtocolGuid
, NULL
, (VOID
**) &Hii
);
650 if (EFI_ERROR (Status
)) {
654 UnicodeVSPrint (Buffer
, 0x10000, fmt
, args
);
656 UnicodeWeight
= (CHAR16
*) Buffer
;
658 for (Index
= 0; UnicodeWeight
[Index
] != 0; Index
++) {
659 if (UnicodeWeight
[Index
] == CHAR_BACKSPACE
||
660 UnicodeWeight
[Index
] == CHAR_LINEFEED
||
661 UnicodeWeight
[Index
] == CHAR_CARRIAGE_RETURN
) {
662 UnicodeWeight
[Index
] = 0;
666 for (Index
= 0; Index
< StrLen (Buffer
); Index
++) {
667 StringIndex
= (UINT16
) Index
;
668 Status
= Hii
->GetGlyph (Hii
, UnicodeWeight
, &StringIndex
, (UINT8
**) &Glyph
, &GlyphWidth
, &GlyphStatus
);
669 if (EFI_ERROR (Status
)) {
673 if (Foreground
== NULL
|| Background
== NULL
) {
674 Status
= Hii
->GlyphToBlt (
677 mEfiColors
[Sto
->Mode
->Attribute
& 0x0f],
678 mEfiColors
[Sto
->Mode
->Attribute
>> 4],
682 &LineBuffer
[Index
* GLYPH_WIDTH
]
685 Status
= Hii
->GlyphToBlt (
693 &LineBuffer
[Index
* GLYPH_WIDTH
]
699 // Blt a character to the screen
701 Status
= UgaDraw
->Blt (
704 EfiUgaBltBufferToVideo
,
709 GLYPH_WIDTH
* StrLen (Buffer
),
711 GLYPH_WIDTH
* StrLen (Buffer
) * sizeof (EFI_UGA_PIXEL
)
715 gBS
->FreePool (LineBuffer
);
716 gBS
->FreePool (Buffer
);
725 IN EFI_UGA_PIXEL
*ForeGround
, OPTIONAL
726 IN EFI_UGA_PIXEL
*BackGround
, OPTIONAL
734 Prints a formatted unicode string to the default console
738 X - X coordinate to start printing
740 Y - Y coordinate to start printing
742 ForeGround - Foreground color
744 BackGround - Background color
748 ... - Print arguments
752 Length of string printed to the console
757 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
758 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
;
762 VA_START (Args
, Fmt
);
764 Handle
= gST
->ConsoleOutHandle
;
766 Status
= gBS
->HandleProtocol (
768 &gEfiUgaDrawProtocolGuid
,
772 if (EFI_ERROR (Status
)) {
776 Status
= gBS
->HandleProtocol (
778 &gEfiSimpleTextOutProtocolGuid
,
782 if (EFI_ERROR (Status
)) {
786 return _IPrint (UgaDraw
, Sto
, X
, Y
, ForeGround
, BackGround
, Fmt
, Args
);