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"
30 GetGraphicsBitMapFromFV (
31 IN EFI_GUID
*FileNameGuid
,
39 Return the graphics image file named FileNameGuid into Image and return it's
40 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
45 FileNameGuid - File Name of graphics file in the FV(s).
47 Image - Pointer to pointer to return graphics image. If NULL, a
48 buffer will be allocated.
50 ImageSize - Size of the graphics Image in bytes. Zero if no image found.
55 EFI_SUCCESS - Image and ImageSize are valid.
56 EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
57 EFI_NOT_FOUND - FileNameGuid not found
61 return GetGraphicsBitMapFromFVEx (NULL
, FileNameGuid
, Image
, ImageSize
);
65 GetGraphicsBitMapFromFVEx (
66 IN EFI_HANDLE ImageHandle
,
67 IN EFI_GUID
*FileNameGuid
,
75 Return the graphics image file named FileNameGuid into Image and return it's
76 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
81 ImageHandle - The driver image handle of the caller. The parameter is used to
82 optimize the loading of the image file so that the FV from which
83 the driver image is loaded will be tried first.
85 FileNameGuid - File Name of graphics file in the FV(s).
87 Image - Pointer to pointer to return graphics image. If NULL, a
88 buffer will be allocated.
90 ImageSize - Size of the graphics Image in bytes. Zero if no image found.
95 EFI_SUCCESS - Image and ImageSize are valid.
96 EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
97 EFI_NOT_FOUND - FileNameGuid not found
115 IN UINTN BmpImageSize
,
116 IN OUT VOID
**GopBlt
,
117 IN OUT UINTN
*GopBltSize
,
118 OUT UINTN
*PixelHeight
,
119 OUT UINTN
*PixelWidth
125 Convert a *.BMP graphics image to a GOP/UGA blt buffer. If a NULL Blt buffer
126 is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt
127 buffer is passed in it will be used if it is big enough.
131 BmpImage - Pointer to BMP file
133 BmpImageSize - Number of bytes in BmpImage
135 GopBlt - Buffer containing GOP version of BmpImage.
137 GopBltSize - Size of GopBlt in bytes.
139 PixelHeight - Height of GopBlt/BmpImage in pixels
141 PixelWidth - Width of GopBlt/BmpImage in pixels
146 EFI_SUCCESS - GopBlt and GopBltSize are returned.
147 EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image
148 EFI_BUFFER_TOO_SMALL - The passed in GopBlt buffer is not big enough.
149 GopBltSize will contain the required size.
150 EFI_OUT_OF_RESOURCES - No enough buffer to allocate
156 BMP_IMAGE_HEADER
*BmpHeader
;
157 BMP_COLOR_MAP
*BmpColorMap
;
158 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
159 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
160 UINT64 BltBufferSize
;
165 UINTN DataSizePerLine
;
169 if (sizeof (BMP_IMAGE_HEADER
) > BmpImageSize
) {
170 return EFI_INVALID_PARAMETER
;
173 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
175 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
176 return EFI_UNSUPPORTED
;
180 // Doesn't support compress.
182 if (BmpHeader
->CompressionType
!= 0) {
183 return EFI_UNSUPPORTED
;
187 // Only support BITMAPINFOHEADER format.
188 // BITMAPFILEHEADER + BITMAPINFOHEADER = BMP_IMAGE_HEADER
190 if (BmpHeader
->HeaderSize
!= sizeof (BMP_IMAGE_HEADER
) - ((UINTN
) &(((BMP_IMAGE_HEADER
*)0)->HeaderSize
))) {
191 return EFI_UNSUPPORTED
;
195 // The data size in each line must be 4 byte alignment.
197 DataSizePerLine
= ((BmpHeader
->PixelWidth
* BmpHeader
->BitPerPixel
+ 31) >> 3) & (~0x3);
198 BltBufferSize
= MultU64x32 (DataSizePerLine
, BmpHeader
->PixelHeight
);
199 if (BltBufferSize
> (UINT32
) ~0) {
200 return EFI_INVALID_PARAMETER
;
203 if ((BmpHeader
->Size
!= BmpImageSize
) ||
204 (BmpHeader
->Size
< BmpHeader
->ImageOffset
) ||
205 (BmpHeader
->Size
- BmpHeader
->ImageOffset
!= BmpHeader
->PixelHeight
* DataSizePerLine
)) {
206 return EFI_INVALID_PARAMETER
;
210 // Calculate Color Map offset in the image.
213 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
214 if (BmpHeader
->ImageOffset
< sizeof (BMP_IMAGE_HEADER
)) {
215 return EFI_INVALID_PARAMETER
;
218 if (BmpHeader
->ImageOffset
> sizeof (BMP_IMAGE_HEADER
)) {
219 switch (BmpHeader
->BitPerPixel
) {
233 if (BmpHeader
->ImageOffset
- sizeof (BMP_IMAGE_HEADER
) != sizeof (BMP_COLOR_MAP
) * ColorMapNum
) {
234 return EFI_INVALID_PARAMETER
;
239 // Calculate graphics image data address in the image
241 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
244 BltBufferSize
= MultU64x32 ((UINT64
) BmpHeader
->PixelWidth
, BmpHeader
->PixelHeight
);
246 // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
248 if (BltBufferSize
> DivU64x32 ((UINTN
) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), NULL
)) {
249 return EFI_UNSUPPORTED
;
251 BltBufferSize
= MultU64x32 (BltBufferSize
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
254 if (*GopBlt
== NULL
) {
255 *GopBltSize
= (UINTN
) BltBufferSize
;
256 *GopBlt
= EfiLibAllocatePool (*GopBltSize
);
258 if (*GopBlt
== NULL
) {
259 return EFI_OUT_OF_RESOURCES
;
262 if (*GopBltSize
< (UINTN
) BltBufferSize
) {
263 *GopBltSize
= (UINTN
) BltBufferSize
;
264 return EFI_BUFFER_TOO_SMALL
;
268 *PixelWidth
= BmpHeader
->PixelWidth
;
269 *PixelHeight
= BmpHeader
->PixelHeight
;
272 // Convert image from BMP to Blt buffer format
275 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
276 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
277 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
278 switch (BmpHeader
->BitPerPixel
) {
281 // Convert 1bit BMP to 24-bit color
283 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
284 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
285 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
286 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
297 // Convert BMP Palette to 24-bit color
299 Index
= (*Image
) >> 4;
300 Blt
->Red
= BmpColorMap
[Index
].Red
;
301 Blt
->Green
= BmpColorMap
[Index
].Green
;
302 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
303 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
306 Index
= (*Image
) & 0x0f;
307 Blt
->Red
= BmpColorMap
[Index
].Red
;
308 Blt
->Green
= BmpColorMap
[Index
].Green
;
309 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
315 // Convert BMP Palette to 24-bit color
317 Blt
->Red
= BmpColorMap
[*Image
].Red
;
318 Blt
->Green
= BmpColorMap
[*Image
].Green
;
319 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
323 Blt
->Blue
= *Image
++;
324 Blt
->Green
= *Image
++;
330 gBS
->FreePool (*GopBlt
);
333 return EFI_UNSUPPORTED
;
339 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
340 if ((ImageIndex
% 4) != 0) {
342 // Bmp Image starts each row on a 32-bit boundary!
344 Image
= Image
+ (4 - (ImageIndex
% 4));
359 Use Console Control Protocol to lock the Console In Spliter virtual handle.
360 This is the ConInHandle and ConIn handle in the EFI system table. All key
361 presses will be ignored until the Password is typed in. The only way to
362 disable the password is to type it in to a ConIn device.
365 Password - Password used to lock ConIn device
370 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
372 EFI_UNSUPPORTED - Logo not found
377 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
379 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
380 if (EFI_ERROR (Status
)) {
381 return EFI_UNSUPPORTED
;
384 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
390 IN EFI_GUID
*LogoFile
396 Use Console Control to turn off UGA based Simple Text Out consoles from going
397 to the UGA device. Put up LogoFile on every UGA device that is a console
401 LogoFile - File name of logo to display on the center of the screen.
406 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
408 EFI_UNSUPPORTED - Logo not found
412 return EnableQuietBootEx (LogoFile
, NULL
);
417 IN EFI_GUID
*LogoFile
,
418 IN EFI_HANDLE ImageHandle
424 Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going
425 to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console
429 LogoFile - File name of logo to display on the center of the screen.
430 ImageHandle - The driver image handle of the caller. The parameter is used to
431 optimize the loading of the logo file so that the FV from which
432 the driver image is loaded will be tried first.
437 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
439 EFI_UNSUPPORTED - Logo not found
444 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
445 EFI_OEM_BADGING_PROTOCOL
*Badging
;
454 EFI_BADGING_FORMAT Format
;
455 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
460 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
461 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
464 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
466 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
467 if (EFI_ERROR (Status
)) {
468 return EFI_UNSUPPORTED
;
473 // Try to open GOP first
475 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**)&GraphicsOutput
);
476 if (EFI_ERROR (Status
)) {
477 GraphicsOutput
= NULL
;
479 // Open GOP failed, try to open UGA
481 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**)&UgaDraw
);
482 if (EFI_ERROR (Status
)) {
483 return EFI_UNSUPPORTED
;
488 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**)&Badging
);
490 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
492 if (GraphicsOutput
!= NULL
) {
493 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
494 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
495 } else if (UgaDraw
!= NULL
) {
496 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
497 if (EFI_ERROR (Status
)) {
498 return EFI_UNSUPPORTED
;
501 return EFI_UNSUPPORTED
;
509 if (Badging
!= NULL
) {
510 Status
= Badging
->GetImage (
520 if (EFI_ERROR (Status
)) {
525 // Currently only support BMP format
527 if (Format
!= EfiBadgingFormatBMP
) {
528 gBS
->FreePool (ImageData
);
532 Status
= GetGraphicsBitMapFromFVEx (ImageHandle
, LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
533 if (EFI_ERROR (Status
)) {
534 return EFI_UNSUPPORTED
;
539 Attribute
= EfiBadgingDisplayAttributeCenter
;
543 Status
= ConvertBmpToGopBlt (
551 if (EFI_ERROR (Status
)) {
552 gBS
->FreePool (ImageData
);
553 if (Badging
== NULL
) {
561 case EfiBadgingDisplayAttributeLeftTop
:
566 case EfiBadgingDisplayAttributeCenterTop
:
567 DestX
= (SizeOfX
- Width
) / 2;
571 case EfiBadgingDisplayAttributeRightTop
:
572 DestX
= (SizeOfX
- Width
- CoordinateX
);
573 DestY
= CoordinateY
;;
576 case EfiBadgingDisplayAttributeCenterRight
:
577 DestX
= (SizeOfX
- Width
- CoordinateX
);
578 DestY
= (SizeOfY
- Height
) / 2;
581 case EfiBadgingDisplayAttributeRightBottom
:
582 DestX
= (SizeOfX
- Width
- CoordinateX
);
583 DestY
= (SizeOfY
- Height
- CoordinateY
);
586 case EfiBadgingDisplayAttributeCenterBottom
:
587 DestX
= (SizeOfX
- Width
) / 2;
588 DestY
= (SizeOfY
- Height
- CoordinateY
);
591 case EfiBadgingDisplayAttributeLeftBottom
:
593 DestY
= (SizeOfY
- Height
- CoordinateY
);
596 case EfiBadgingDisplayAttributeCenterLeft
:
598 DestY
= (SizeOfY
- Height
) / 2;
601 case EfiBadgingDisplayAttributeCenter
:
602 DestX
= (SizeOfX
- Width
) / 2;
603 DestY
= (SizeOfY
- Height
) / 2;
612 if ((DestX
>= 0) && (DestY
>= 0)) {
613 if (GraphicsOutput
!= NULL
) {
614 Status
= GraphicsOutput
->Blt (
624 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
627 Status
= UgaDraw
->Blt (
629 (EFI_UGA_PIXEL
*) Blt
,
630 EfiUgaBltBufferToVideo
,
637 Width
* sizeof (EFI_UGA_PIXEL
)
642 gBS
->FreePool (ImageData
);
645 if (Badging
== NULL
) {
662 Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
663 Simple Text Out screens will now be synced up with all non GOP/UGA output devices
671 EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
672 EFI_UNSUPPORTED - Logo not found
677 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
679 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
680 if (EFI_ERROR (Status
)) {
681 return EFI_UNSUPPORTED
;
684 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);