3 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
4 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
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
;
161 UINT64 BltBufferSize
;
166 UINTN DataSizePerLine
;
170 if (sizeof (BMP_IMAGE_HEADER
) > BmpImageSize
) {
171 return EFI_INVALID_PARAMETER
;
174 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
176 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
177 return EFI_UNSUPPORTED
;
181 // Doesn't support compress.
183 if (BmpHeader
->CompressionType
!= 0) {
184 return EFI_UNSUPPORTED
;
188 // Only support BITMAPINFOHEADER format.
189 // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER
191 if (BmpHeader
->HeaderSize
!= sizeof (BMP_IMAGE_HEADER
) - ((UINTN
) &(((BMP_IMAGE_HEADER
*)0)->HeaderSize
))) {
192 return EFI_UNSUPPORTED
;
196 // The data size in each line must be 4 byte alignment.
198 DataSizePerLine
= ((BmpHeader
->PixelWidth
* BmpHeader
->BitPerPixel
+ 31) >> 3) & (~0x3);
199 BltBufferSize
= MultU64x32 (DataSizePerLine
, BmpHeader
->PixelHeight
);
200 if (BltBufferSize
> (UINT32
) ~0) {
201 return EFI_INVALID_PARAMETER
;
204 if ((BmpHeader
->Size
!= BmpImageSize
) ||
205 (BmpHeader
->Size
< BmpHeader
->ImageOffset
) ||
206 (BmpHeader
->Size
- BmpHeader
->ImageOffset
!= BmpHeader
->PixelHeight
* DataSizePerLine
)) {
207 return EFI_INVALID_PARAMETER
;
211 // Calculate Color Map offset in the image.
214 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
215 if (BmpHeader
->ImageOffset
< sizeof (BMP_IMAGE_HEADER
)) {
216 return EFI_INVALID_PARAMETER
;
219 if (BmpHeader
->ImageOffset
> sizeof (BMP_IMAGE_HEADER
)) {
220 switch (BmpHeader
->BitPerPixel
) {
234 if (BmpHeader
->ImageOffset
- sizeof (BMP_IMAGE_HEADER
) != sizeof (BMP_COLOR_MAP
) * ColorMapNum
) {
235 return EFI_INVALID_PARAMETER
;
240 // Calculate graphics image data address in the image
242 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
245 BltBufferSize
= MultU64x32 ((UINT64
) BmpHeader
->PixelWidth
, BmpHeader
->PixelHeight
);
247 // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
249 if (BltBufferSize
> DivU64x32 ((UINTN
) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), NULL
)) {
250 return EFI_UNSUPPORTED
;
252 BltBufferSize
= MultU64x32 (BltBufferSize
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
255 if (*GopBlt
== NULL
) {
256 *GopBltSize
= (UINTN
) BltBufferSize
;
257 *GopBlt
= EfiLibAllocatePool (*GopBltSize
);
259 if (*GopBlt
== NULL
) {
260 return EFI_OUT_OF_RESOURCES
;
263 if (*GopBltSize
< (UINTN
) BltBufferSize
) {
264 *GopBltSize
= (UINTN
) BltBufferSize
;
265 return EFI_BUFFER_TOO_SMALL
;
269 *PixelWidth
= BmpHeader
->PixelWidth
;
270 *PixelHeight
= BmpHeader
->PixelHeight
;
273 // Convert image from BMP to Blt buffer format
276 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
277 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
278 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
279 switch (BmpHeader
->BitPerPixel
) {
282 // Convert 1bit BMP to 24-bit color
284 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
285 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
286 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
287 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
298 // Convert BMP Palette to 24-bit color
300 Index
= (*Image
) >> 4;
301 Blt
->Red
= BmpColorMap
[Index
].Red
;
302 Blt
->Green
= BmpColorMap
[Index
].Green
;
303 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
304 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
307 Index
= (*Image
) & 0x0f;
308 Blt
->Red
= BmpColorMap
[Index
].Red
;
309 Blt
->Green
= BmpColorMap
[Index
].Green
;
310 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
316 // Convert BMP Palette to 24-bit color
318 Blt
->Red
= BmpColorMap
[*Image
].Red
;
319 Blt
->Green
= BmpColorMap
[*Image
].Green
;
320 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
324 Blt
->Blue
= *Image
++;
325 Blt
->Green
= *Image
++;
331 gBS
->FreePool (*GopBlt
);
334 return EFI_UNSUPPORTED
;
340 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
341 if ((ImageIndex
% 4) != 0) {
343 // Bmp Image starts each row on a 32-bit boundary!
345 Image
= Image
+ (4 - (ImageIndex
% 4));
360 Use Console Control Protocol to lock the Console In Spliter virtual handle.
361 This is the ConInHandle and ConIn handle in the EFI system table. All key
362 presses will be ignored until the Password is typed in. The only way to
363 disable the password is to type it in to a ConIn device.
366 Password - Password used to lock ConIn device
371 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
373 EFI_UNSUPPORTED - Logo not found
378 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
380 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
381 if (EFI_ERROR (Status
)) {
382 return EFI_UNSUPPORTED
;
385 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
391 IN EFI_GUID
*LogoFile
397 Use Console Control to turn off UGA based Simple Text Out consoles from going
398 to the UGA device. Put up LogoFile on every UGA device that is a console
402 LogoFile - File name of logo to display on the center of the screen.
407 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
409 EFI_UNSUPPORTED - Logo not found
413 return EnableQuietBootEx (LogoFile
, NULL
);
419 IN EFI_GUID
*LogoFile
,
420 IN EFI_HANDLE ImageHandle
426 Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going
427 to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console
431 LogoFile - File name of logo to display on the center of the screen.
436 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
438 EFI_UNSUPPORTED - Logo not found
443 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
444 EFI_OEM_BADGING_PROTOCOL
*Badging
;
453 EFI_BADGING_FORMAT Format
;
454 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
459 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
460 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
463 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
465 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
466 if (EFI_ERROR (Status
)) {
467 return EFI_UNSUPPORTED
;
472 // Try to open GOP first
474 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**) &GraphicsOutput
);
475 if (EFI_ERROR (Status
)) {
476 GraphicsOutput
= NULL
;
478 // Open GOP failed, try to open UGA
480 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**) &UgaDraw
);
481 if (EFI_ERROR (Status
)) {
482 return EFI_UNSUPPORTED
;
487 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**) &Badging
);
489 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
491 if (GraphicsOutput
!= NULL
) {
492 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
493 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
494 } else if (UgaDraw
!= NULL
) {
495 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
496 if (EFI_ERROR (Status
)) {
497 return EFI_UNSUPPORTED
;
500 return EFI_UNSUPPORTED
;
508 if (Badging
!= NULL
) {
509 Status
= Badging
->GetImage (
519 if (EFI_ERROR (Status
)) {
524 // Currently only support BMP format
526 if (Format
!= EfiBadgingFormatBMP
) {
527 gBS
->FreePool (ImageData
);
531 Status
= GetGraphicsBitMapFromFVEx (ImageHandle
, LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
532 if (EFI_ERROR (Status
)) {
533 return EFI_UNSUPPORTED
;
538 Attribute
= EfiBadgingDisplayAttributeCenter
;
542 Status
= ConvertBmpToGopBlt (
550 if (EFI_ERROR (Status
)) {
551 gBS
->FreePool (ImageData
);
552 if (Badging
== NULL
) {
560 case EfiBadgingDisplayAttributeLeftTop
:
565 case EfiBadgingDisplayAttributeCenterTop
:
566 DestX
= (SizeOfX
- Width
) / 2;
570 case EfiBadgingDisplayAttributeRightTop
:
571 DestX
= (SizeOfX
- Width
- CoordinateX
);
572 DestY
= CoordinateY
;;
575 case EfiBadgingDisplayAttributeCenterRight
:
576 DestX
= (SizeOfX
- Width
- CoordinateX
);
577 DestY
= (SizeOfY
- Height
) / 2;
580 case EfiBadgingDisplayAttributeRightBottom
:
581 DestX
= (SizeOfX
- Width
- CoordinateX
);
582 DestY
= (SizeOfY
- Height
- CoordinateY
);
585 case EfiBadgingDisplayAttributeCenterBottom
:
586 DestX
= (SizeOfX
- Width
) / 2;
587 DestY
= (SizeOfY
- Height
- CoordinateY
);
590 case EfiBadgingDisplayAttributeLeftBottom
:
592 DestY
= (SizeOfY
- Height
- CoordinateY
);
595 case EfiBadgingDisplayAttributeCenterLeft
:
597 DestY
= (SizeOfY
- Height
) / 2;
600 case EfiBadgingDisplayAttributeCenter
:
601 DestX
= (SizeOfX
- Width
) / 2;
602 DestY
= (SizeOfY
- Height
) / 2;
611 if ((DestX
>= 0) && (DestY
>= 0)) {
612 if (GraphicsOutput
!= NULL
) {
613 Status
= GraphicsOutput
->Blt (
623 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
626 Status
= UgaDraw
->Blt (
628 (EFI_UGA_PIXEL
*) Blt
,
629 EfiUgaBltBufferToVideo
,
636 Width
* sizeof (EFI_UGA_PIXEL
)
641 gBS
->FreePool (ImageData
);
644 if (Badging
== NULL
) {
661 Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
662 Simple Text Out screens will now be synced up with all non GOP/UGA output devices
670 EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
671 EFI_UNSUPPORTED - Logo not found
676 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
678 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
679 if (EFI_ERROR (Status
)) {
680 return EFI_UNSUPPORTED
;
683 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);