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
**GopBlt
,
114 IN OUT UINTN
*GopBltSize
,
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_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
156 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
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_GRAPHICS_OUTPUT_BLT_PIXEL
);
187 if (*GopBlt
== NULL
) {
188 *GopBltSize
= BltBufferSize
;
189 *GopBlt
= AllocatePool (*GopBltSize
);
191 if (*GopBlt
== NULL
) {
192 return EFI_OUT_OF_RESOURCES
;
195 if (*GopBltSize
< BltBufferSize
) {
196 *GopBltSize
= 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 (*GopBlt
);
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_OEM_BADGING_PROTOCOL
*Badging
;
357 EFI_BADGING_FORMAT Format
;
358 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
363 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
364 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
367 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
369 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
370 if (EFI_ERROR (Status
)) {
371 return EFI_UNSUPPORTED
;
376 // Try to open GOP first
378 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**) &GraphicsOutput
);
379 if (EFI_ERROR(Status
)) {
380 GraphicsOutput
= NULL
;
382 // Open GOP failed, try to open UGA
384 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**) &UgaDraw
);
385 if (EFI_ERROR (Status
)) {
386 return EFI_UNSUPPORTED
;
391 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**) &Badging
);
393 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
395 if (GraphicsOutput
!= NULL
) {
396 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
397 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
399 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
400 if (EFI_ERROR (Status
)) {
401 return EFI_UNSUPPORTED
;
410 if (Badging
!= NULL
) {
411 Status
= Badging
->GetImage (
421 if (EFI_ERROR (Status
)) {
426 // Currently only support BMP format
428 if (Format
!= EfiBadgingFormatBMP
) {
429 gBS
->FreePool (ImageData
);
433 Status
= GetGraphicsBitMapFromFV (LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
434 if (EFI_ERROR (Status
)) {
435 return EFI_UNSUPPORTED
;
440 Attribute
= EfiBadgingDisplayAttributeCenter
;
444 Status
= ConvertBmpToGopBlt (
452 if (EFI_ERROR (Status
)) {
453 gBS
->FreePool (ImageData
);
454 if (Badging
== NULL
) {
462 case EfiBadgingDisplayAttributeLeftTop
:
467 case EfiBadgingDisplayAttributeCenterTop
:
468 DestX
= (SizeOfX
- Width
) / 2;
472 case EfiBadgingDisplayAttributeRightTop
:
473 DestX
= (SizeOfX
- Width
- CoordinateX
);
474 DestY
= CoordinateY
;;
477 case EfiBadgingDisplayAttributeCenterRight
:
478 DestX
= (SizeOfX
- Width
- CoordinateX
);
479 DestY
= (SizeOfY
- Height
) / 2;
482 case EfiBadgingDisplayAttributeRightBottom
:
483 DestX
= (SizeOfX
- Width
- CoordinateX
);
484 DestY
= (SizeOfY
- Height
- CoordinateY
);
487 case EfiBadgingDisplayAttributeCenterBottom
:
488 DestX
= (SizeOfX
- Width
) / 2;
489 DestY
= (SizeOfY
- Height
- CoordinateY
);
492 case EfiBadgingDisplayAttributeLeftBottom
:
494 DestY
= (SizeOfY
- Height
- CoordinateY
);
497 case EfiBadgingDisplayAttributeCenterLeft
:
499 DestY
= (SizeOfY
- Height
) / 2;
502 case EfiBadgingDisplayAttributeCenter
:
503 DestX
= (SizeOfX
- Width
) / 2;
504 DestY
= (SizeOfY
- Height
) / 2;
513 if ((DestX
>= 0) && (DestY
>= 0)) {
514 if (GraphicsOutput
!= NULL
) {
515 Status
= GraphicsOutput
->Blt (
525 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
528 Status
= UgaDraw
->Blt (
530 (EFI_UGA_PIXEL
*) Blt
,
531 EfiUgaBltBufferToVideo
,
538 Width
* sizeof (EFI_UGA_PIXEL
)
543 gBS
->FreePool (ImageData
);
546 if (Badging
== NULL
) {
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
572 EFI_SUCCESS - UGA devices are back in text mode and synced up.
573 EFI_UNSUPPORTED - Logo not found
578 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
580 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
581 if (EFI_ERROR (Status
)) {
582 return EFI_UNSUPPORTED
;
585 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);
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 }
610 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
611 IN EFI_UGA_DRAW_PROTOCOL
*UgaDraw
,
612 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
,
615 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
616 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
,
624 Display string worker for: Print, PrintAt, IPrint, IPrintAt
628 GraphicsOutput - Graphics output protocol interface
630 UgaDraw - UGA draw protocol interface
632 Sto - Simple text out protocol interface
634 X - X coordinate to start printing
636 Y - Y coordinate to start printing
638 Foreground - Foreground color
640 Background - Background color
644 args - Print arguments
648 EFI_SUCCESS - success
649 EFI_OUT_OF_RESOURCES - out of resources
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
;
671 // For now, allocate an arbitrarily long buffer
673 Buffer
= AllocateZeroPool (0x10000);
674 if (Buffer
== NULL
) {
675 return EFI_OUT_OF_RESOURCES
;
678 if (GraphicsOutput
!= NULL
) {
679 HorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
680 VerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
683 // Get the current mode information from the UGA Draw Protocol
685 UgaDraw
->GetMode (UgaDraw
, &HorizontalResolution
, &VerticalResolution
, &ColorDepth
, &RefreshRate
);
688 LineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * HorizontalResolution
* GLYPH_WIDTH
* GLYPH_HEIGHT
);
689 if (LineBuffer
== NULL
) {
690 gBS
->FreePool (Buffer
);
691 return EFI_OUT_OF_RESOURCES
;
694 Status
= gBS
->LocateProtocol (&gEfiHiiProtocolGuid
, NULL
, (VOID
**) &Hii
);
695 if (EFI_ERROR (Status
)) {
699 UnicodeVSPrint (Buffer
, 0x10000, fmt
, args
);
701 UnicodeWeight
= (CHAR16
*) Buffer
;
703 for (Index
= 0; UnicodeWeight
[Index
] != 0; Index
++) {
704 if (UnicodeWeight
[Index
] == CHAR_BACKSPACE
||
705 UnicodeWeight
[Index
] == CHAR_LINEFEED
||
706 UnicodeWeight
[Index
] == CHAR_CARRIAGE_RETURN
) {
707 UnicodeWeight
[Index
] = 0;
711 for (Index
= 0; Index
< StrLen (Buffer
); Index
++) {
712 StringIndex
= (UINT16
) Index
;
713 Status
= Hii
->GetGlyph (Hii
, UnicodeWeight
, &StringIndex
, (UINT8
**) &Glyph
, &GlyphWidth
, &GlyphStatus
);
714 if (EFI_ERROR (Status
)) {
718 if (Foreground
== NULL
|| Background
== NULL
) {
719 Status
= Hii
->GlyphToBlt (
722 mEfiColors
[Sto
->Mode
->Attribute
& 0x0f],
723 mEfiColors
[Sto
->Mode
->Attribute
>> 4],
727 &LineBuffer
[Index
* GLYPH_WIDTH
]
730 Status
= Hii
->GlyphToBlt (
738 &LineBuffer
[Index
* GLYPH_WIDTH
]
744 // Blt a character to the screen
746 if (GraphicsOutput
!= NULL
) {
747 Status
= GraphicsOutput
->Blt (
755 GLYPH_WIDTH
* StrLen (Buffer
),
757 GLYPH_WIDTH
* StrLen (Buffer
) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
760 Status
= UgaDraw
->Blt (
762 (EFI_UGA_PIXEL
*) (UINTN
) LineBuffer
,
763 EfiUgaBltBufferToVideo
,
768 GLYPH_WIDTH
* StrLen (Buffer
),
770 GLYPH_WIDTH
* StrLen (Buffer
) * sizeof (EFI_UGA_PIXEL
)
775 gBS
->FreePool (LineBuffer
);
776 gBS
->FreePool (Buffer
);
785 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*ForeGround
, OPTIONAL
786 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BackGround
, OPTIONAL
794 Prints a formatted unicode string to the default console
798 X - X coordinate to start printing
800 Y - Y coordinate to start printing
802 ForeGround - Foreground color
804 BackGround - Background color
808 ... - Print arguments
812 Length of string printed to the console
818 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
819 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
820 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*Sto
;
824 VA_START (Args
, Fmt
);
828 Handle
= gST
->ConsoleOutHandle
;
830 Status
= gBS
->HandleProtocol (
832 &gEfiGraphicsOutputProtocolGuid
,
833 (VOID
**) &GraphicsOutput
836 if (EFI_ERROR (Status
)) {
837 GraphicsOutput
= NULL
;
839 Status
= gBS
->HandleProtocol (
841 &gEfiUgaDrawProtocolGuid
,
845 if (EFI_ERROR (Status
)) {
850 Status
= gBS
->HandleProtocol (
852 &gEfiSimpleTextOutProtocolGuid
,
856 if (EFI_ERROR (Status
)) {
860 return _IPrint (GraphicsOutput
, UgaDraw
, Sto
, X
, Y
, ForeGround
, BackGround
, Fmt
, Args
);