3 Copyright (c) 2004 - 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 #include "EfiDriverLib.h"
27 #include "GraphicsLib.h"
31 GetGraphicsBitMapFromFV (
32 IN EFI_GUID
*FileNameGuid
,
40 Return the graphics image file named FileNameGuid into Image and return it's
41 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
46 FileNameGuid - File Name of graphics file in the FV(s).
48 Image - Pointer to pointer to return graphics image. If NULL, a
49 buffer will be allocated.
51 ImageSize - Size of the graphics Image in bytes. Zero if no image found.
56 EFI_SUCCESS - Image and ImageSize are valid.
57 EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
58 EFI_NOT_FOUND - FileNameGuid not found
62 return GetGraphicsBitMapFromFVEx (NULL
, FileNameGuid
, Image
, ImageSize
);
66 GetGraphicsBitMapFromFVEx (
67 IN EFI_HANDLE ImageHandle
,
68 IN EFI_GUID
*FileNameGuid
,
76 Return the graphics image file named FileNameGuid into Image and return it's
77 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
82 ImageHandle - The driver image handle of the caller. The parameter is used to
83 optimize the loading of the image file so that the FV from which
84 the driver image is loaded will be tried first.
86 FileNameGuid - File Name of graphics file in the FV(s).
88 Image - Pointer to pointer to return graphics image. If NULL, a
89 buffer will be allocated.
91 ImageSize - Size of the graphics Image in bytes. Zero if no image found.
96 EFI_SUCCESS - Image and ImageSize are valid.
97 EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
98 EFI_NOT_FOUND - FileNameGuid not found
104 &gEfiDefaultBmpLogoGuid
,
116 IN UINTN BmpImageSize
,
117 IN OUT VOID
**GopBlt
,
118 IN OUT UINTN
*GopBltSize
,
119 OUT UINTN
*PixelHeight
,
120 OUT UINTN
*PixelWidth
126 Convert a *.BMP graphics image to a GOP/UGA blt buffer. If a NULL Blt buffer
127 is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt
128 buffer is passed in it will be used if it is big enough.
132 BmpImage - Pointer to BMP file
134 BmpImageSize - Number of bytes in BmpImage
136 GopBlt - Buffer containing GOP version of BmpImage.
138 GopBltSize - Size of GopBlt in bytes.
140 PixelHeight - Height of GopBlt/BmpImage in pixels
142 PixelWidth - Width of GopBlt/BmpImage in pixels
147 EFI_SUCCESS - GopBlt and GopBltSize are returned.
148 EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image
149 EFI_BUFFER_TOO_SMALL - The passed in GopBlt buffer is not big enough.
150 GopBltSize will contain the required size.
151 EFI_OUT_OF_RESOURCES - No enough buffer to allocate
157 BMP_IMAGE_HEADER
*BmpHeader
;
158 BMP_COLOR_MAP
*BmpColorMap
;
159 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
160 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
168 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
169 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
170 return EFI_UNSUPPORTED
;
173 if (BmpHeader
->CompressionType
!= 0) {
174 return EFI_UNSUPPORTED
;
178 // Calculate Color Map offset in the image.
181 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
184 // Calculate graphics image data address in the image
186 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
189 BltBufferSize
= BmpHeader
->PixelWidth
* BmpHeader
->PixelHeight
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
191 if (*GopBlt
== NULL
) {
192 *GopBltSize
= BltBufferSize
;
193 *GopBlt
= EfiLibAllocatePool (*GopBltSize
);
195 if (*GopBlt
== NULL
) {
196 return EFI_OUT_OF_RESOURCES
;
199 if (*GopBltSize
< BltBufferSize
) {
200 *GopBltSize
= BltBufferSize
;
201 return EFI_BUFFER_TOO_SMALL
;
205 *PixelWidth
= BmpHeader
->PixelWidth
;
206 *PixelHeight
= BmpHeader
->PixelHeight
;
209 // Convert image from BMP to Blt buffer format
212 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
213 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
214 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
215 switch (BmpHeader
->BitPerPixel
) {
218 // Convert 1bit BMP to 24-bit color
220 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
221 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
222 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
223 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
234 // Convert BMP Palette to 24-bit color
236 Index
= (*Image
) >> 4;
237 Blt
->Red
= BmpColorMap
[Index
].Red
;
238 Blt
->Green
= BmpColorMap
[Index
].Green
;
239 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
240 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
243 Index
= (*Image
) & 0x0f;
244 Blt
->Red
= BmpColorMap
[Index
].Red
;
245 Blt
->Green
= BmpColorMap
[Index
].Green
;
246 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
252 // Convert BMP Palette to 24-bit color
254 Blt
->Red
= BmpColorMap
[*Image
].Red
;
255 Blt
->Green
= BmpColorMap
[*Image
].Green
;
256 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
260 Blt
->Blue
= *Image
++;
261 Blt
->Green
= *Image
++;
267 gBS
->FreePool (*GopBlt
);
270 return EFI_UNSUPPORTED
;
276 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
277 if ((ImageIndex
% 4) != 0) {
279 // Bmp Image starts each row on a 32-bit boundary!
281 Image
= Image
+ (4 - (ImageIndex
% 4));
296 Use Console Control Protocol to lock the Console In Spliter virtual handle.
297 This is the ConInHandle and ConIn handle in the EFI system table. All key
298 presses will be ignored until the Password is typed in. The only way to
299 disable the password is to type it in to a ConIn device.
302 Password - Password used to lock ConIn device
307 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
309 EFI_UNSUPPORTED - Logo not found
314 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
316 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, &ConsoleControl
);
317 if (EFI_ERROR (Status
)) {
318 return EFI_UNSUPPORTED
;
321 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
327 IN EFI_GUID
*LogoFile
333 Use Console Control to turn off UGA based Simple Text Out consoles from going
334 to the UGA device. Put up LogoFile on every UGA device that is a console
338 LogoFile - File name of logo to display on the center of the screen.
343 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
345 EFI_UNSUPPORTED - Logo not found
349 return EnableQuietBootEx (LogoFile
, NULL
);
355 IN EFI_GUID
*LogoFile
,
356 IN EFI_HANDLE ImageHandle
362 Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going
363 to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console
367 LogoFile - File name of logo to display on the center of the screen.
372 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
374 EFI_UNSUPPORTED - Logo not found
379 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
380 EFI_OEM_BADGING_PROTOCOL
*Badging
;
389 EFI_BADGING_FORMAT Format
;
390 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
395 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
396 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
399 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
401 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, &ConsoleControl
);
402 if (EFI_ERROR (Status
)) {
403 return EFI_UNSUPPORTED
;
408 // Try to open GOP first
410 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, &GraphicsOutput
);
411 if (EFI_ERROR (Status
)) {
412 GraphicsOutput
= NULL
;
414 // Open GOP failed, try to open UGA
416 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, &UgaDraw
);
417 if (EFI_ERROR (Status
)) {
418 return EFI_UNSUPPORTED
;
423 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, &Badging
);
425 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
427 if (GraphicsOutput
!= NULL
) {
428 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
429 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
431 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
432 if (EFI_ERROR (Status
)) {
433 return EFI_UNSUPPORTED
;
442 if (Badging
!= NULL
) {
443 Status
= Badging
->GetImage (
453 if (EFI_ERROR (Status
)) {
458 // Currently only support BMP format
460 if (Format
!= EfiBadgingFormatBMP
) {
461 gBS
->FreePool (ImageData
);
465 Status
= GetGraphicsBitMapFromFVEx (ImageHandle
, LogoFile
, &ImageData
, &ImageSize
);
466 if (EFI_ERROR (Status
)) {
467 return EFI_UNSUPPORTED
;
472 Attribute
= EfiBadgingDisplayAttributeCenter
;
476 Status
= ConvertBmpToGopBlt (
484 if (EFI_ERROR (Status
)) {
485 gBS
->FreePool (ImageData
);
486 if (Badging
== NULL
) {
494 case EfiBadgingDisplayAttributeLeftTop
:
499 case EfiBadgingDisplayAttributeCenterTop
:
500 DestX
= (SizeOfX
- Width
) / 2;
504 case EfiBadgingDisplayAttributeRightTop
:
505 DestX
= (SizeOfX
- Width
- CoordinateX
);
506 DestY
= CoordinateY
;;
509 case EfiBadgingDisplayAttributeCenterRight
:
510 DestX
= (SizeOfX
- Width
- CoordinateX
);
511 DestY
= (SizeOfY
- Height
) / 2;
514 case EfiBadgingDisplayAttributeRightBottom
:
515 DestX
= (SizeOfX
- Width
- CoordinateX
);
516 DestY
= (SizeOfY
- Height
- CoordinateY
);
519 case EfiBadgingDisplayAttributeCenterBottom
:
520 DestX
= (SizeOfX
- Width
) / 2;
521 DestY
= (SizeOfY
- Height
- CoordinateY
);
524 case EfiBadgingDisplayAttributeLeftBottom
:
526 DestY
= (SizeOfY
- Height
- CoordinateY
);
529 case EfiBadgingDisplayAttributeCenterLeft
:
531 DestY
= (SizeOfY
- Height
) / 2;
534 case EfiBadgingDisplayAttributeCenter
:
535 DestX
= (SizeOfX
- Width
) / 2;
536 DestY
= (SizeOfY
- Height
) / 2;
545 if ((DestX
>= 0) && (DestY
>= 0)) {
546 if (GraphicsOutput
!= NULL
) {
547 Status
= GraphicsOutput
->Blt (
557 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
560 Status
= UgaDraw
->Blt (
562 (EFI_UGA_PIXEL
*) Blt
,
563 EfiUgaBltBufferToVideo
,
570 Width
* sizeof (EFI_UGA_PIXEL
)
575 gBS
->FreePool (ImageData
);
578 if (Badging
== NULL
) {
595 Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
596 Simple Text Out screens will now be synced up with all non GOP/UGA output devices
604 EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
605 EFI_UNSUPPORTED - Logo not found
610 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
612 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, &ConsoleControl
);
613 if (EFI_ERROR (Status
)) {
614 return EFI_UNSUPPORTED
;
617 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);