3 Copyright (c) 2004 - 2007, 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"
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
;
167 BmpHeader
= (BMP_IMAGE_HEADER
*) BmpImage
;
168 if (BmpHeader
->CharB
!= 'B' || BmpHeader
->CharM
!= 'M') {
169 return EFI_UNSUPPORTED
;
172 if (BmpHeader
->CompressionType
!= 0) {
173 return EFI_UNSUPPORTED
;
177 // Calculate Color Map offset in the image.
180 BmpColorMap
= (BMP_COLOR_MAP
*) (Image
+ sizeof (BMP_IMAGE_HEADER
));
183 // Calculate graphics image data address in the image
185 Image
= ((UINT8
*) BmpImage
) + BmpHeader
->ImageOffset
;
188 BltBufferSize
= BmpHeader
->PixelWidth
* BmpHeader
->PixelHeight
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
190 if (*GopBlt
== NULL
) {
191 *GopBltSize
= BltBufferSize
;
192 *GopBlt
= EfiLibAllocatePool (*GopBltSize
);
194 if (*GopBlt
== NULL
) {
195 return EFI_OUT_OF_RESOURCES
;
198 if (*GopBltSize
< BltBufferSize
) {
199 *GopBltSize
= BltBufferSize
;
200 return EFI_BUFFER_TOO_SMALL
;
204 *PixelWidth
= BmpHeader
->PixelWidth
;
205 *PixelHeight
= BmpHeader
->PixelHeight
;
208 // Convert image from BMP to Blt buffer format
211 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
212 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
213 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
214 switch (BmpHeader
->BitPerPixel
) {
217 // Convert 1bit BMP to 24-bit color
219 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
220 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
221 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
222 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
233 // Convert BMP Palette to 24-bit color
235 Index
= (*Image
) >> 4;
236 Blt
->Red
= BmpColorMap
[Index
].Red
;
237 Blt
->Green
= BmpColorMap
[Index
].Green
;
238 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
239 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
242 Index
= (*Image
) & 0x0f;
243 Blt
->Red
= BmpColorMap
[Index
].Red
;
244 Blt
->Green
= BmpColorMap
[Index
].Green
;
245 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
251 // Convert BMP Palette to 24-bit color
253 Blt
->Red
= BmpColorMap
[*Image
].Red
;
254 Blt
->Green
= BmpColorMap
[*Image
].Green
;
255 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
259 Blt
->Blue
= *Image
++;
260 Blt
->Green
= *Image
++;
266 gBS
->FreePool (*GopBlt
);
269 return EFI_UNSUPPORTED
;
275 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
276 if ((ImageIndex
% 4) != 0) {
278 // Bmp Image starts each row on a 32-bit boundary!
280 Image
= Image
+ (4 - (ImageIndex
% 4));
295 Use Console Control Protocol to lock the Console In Spliter virtual handle.
296 This is the ConInHandle and ConIn handle in the EFI system table. All key
297 presses will be ignored until the Password is typed in. The only way to
298 disable the password is to type it in to a ConIn device.
301 Password - Password used to lock ConIn device
306 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
308 EFI_UNSUPPORTED - Logo not found
313 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
315 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
316 if (EFI_ERROR (Status
)) {
317 return EFI_UNSUPPORTED
;
320 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
326 IN EFI_GUID
*LogoFile
332 Use Console Control to turn off UGA based Simple Text Out consoles from going
333 to the UGA device. Put up LogoFile on every UGA device that is a console
337 LogoFile - File name of logo to display on the center of the screen.
342 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
344 EFI_UNSUPPORTED - Logo not found
348 return EnableQuietBootEx (LogoFile
, NULL
);
353 IN EFI_GUID
*LogoFile
,
354 IN EFI_HANDLE ImageHandle
360 Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going
361 to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console
365 LogoFile - File name of logo to display on the center of the screen.
366 ImageHandle - The driver image handle of the caller. The parameter is used to
367 optimize the loading of the logo file so that the FV from which
368 the driver image is loaded will be tried first.
373 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
375 EFI_UNSUPPORTED - Logo not found
380 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
381 EFI_OEM_BADGING_PROTOCOL
*Badging
;
390 EFI_BADGING_FORMAT Format
;
391 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
396 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
397 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
400 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
402 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
403 if (EFI_ERROR (Status
)) {
404 return EFI_UNSUPPORTED
;
409 // Try to open GOP first
411 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**)&GraphicsOutput
);
412 if (EFI_ERROR (Status
)) {
413 GraphicsOutput
= NULL
;
415 // Open GOP failed, try to open UGA
417 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**)&UgaDraw
);
418 if (EFI_ERROR (Status
)) {
419 return EFI_UNSUPPORTED
;
424 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**)&Badging
);
426 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
428 if (GraphicsOutput
!= NULL
) {
429 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
430 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
432 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
433 if (EFI_ERROR (Status
)) {
434 return EFI_UNSUPPORTED
;
443 if (Badging
!= NULL
) {
444 Status
= Badging
->GetImage (
454 if (EFI_ERROR (Status
)) {
459 // Currently only support BMP format
461 if (Format
!= EfiBadgingFormatBMP
) {
462 gBS
->FreePool (ImageData
);
466 Status
= GetGraphicsBitMapFromFVEx (ImageHandle
, LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
467 if (EFI_ERROR (Status
)) {
468 return EFI_UNSUPPORTED
;
473 Attribute
= EfiBadgingDisplayAttributeCenter
;
477 Status
= ConvertBmpToGopBlt (
485 if (EFI_ERROR (Status
)) {
486 gBS
->FreePool (ImageData
);
487 if (Badging
== NULL
) {
495 case EfiBadgingDisplayAttributeLeftTop
:
500 case EfiBadgingDisplayAttributeCenterTop
:
501 DestX
= (SizeOfX
- Width
) / 2;
505 case EfiBadgingDisplayAttributeRightTop
:
506 DestX
= (SizeOfX
- Width
- CoordinateX
);
507 DestY
= CoordinateY
;;
510 case EfiBadgingDisplayAttributeCenterRight
:
511 DestX
= (SizeOfX
- Width
- CoordinateX
);
512 DestY
= (SizeOfY
- Height
) / 2;
515 case EfiBadgingDisplayAttributeRightBottom
:
516 DestX
= (SizeOfX
- Width
- CoordinateX
);
517 DestY
= (SizeOfY
- Height
- CoordinateY
);
520 case EfiBadgingDisplayAttributeCenterBottom
:
521 DestX
= (SizeOfX
- Width
) / 2;
522 DestY
= (SizeOfY
- Height
- CoordinateY
);
525 case EfiBadgingDisplayAttributeLeftBottom
:
527 DestY
= (SizeOfY
- Height
- CoordinateY
);
530 case EfiBadgingDisplayAttributeCenterLeft
:
532 DestY
= (SizeOfY
- Height
) / 2;
535 case EfiBadgingDisplayAttributeCenter
:
536 DestX
= (SizeOfX
- Width
) / 2;
537 DestY
= (SizeOfY
- Height
) / 2;
546 if ((DestX
>= 0) && (DestY
>= 0)) {
547 if (GraphicsOutput
!= NULL
) {
548 Status
= GraphicsOutput
->Blt (
558 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
561 Status
= UgaDraw
->Blt (
563 (EFI_UGA_PIXEL
*) Blt
,
564 EfiUgaBltBufferToVideo
,
571 Width
* sizeof (EFI_UGA_PIXEL
)
576 gBS
->FreePool (ImageData
);
579 if (Badging
== NULL
) {
596 Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
597 Simple Text Out screens will now be synced up with all non GOP/UGA output devices
605 EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
606 EFI_UNSUPPORTED - Logo not found
611 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
613 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
614 if (EFI_ERROR (Status
)) {
615 return EFI_UNSUPPORTED
;
618 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);