3 Copyright (c) 2004 - 2010, 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
;
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
= MultU64x32 ((UINT64
) BmpHeader
->PixelWidth
, BmpHeader
->PixelHeight
);
191 // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
193 if (BltBufferSize
> DivU64x32 ((UINTN
) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), NULL
)) {
194 return EFI_UNSUPPORTED
;
196 BltBufferSize
= MultU64x32 (BltBufferSize
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
199 if (*GopBlt
== NULL
) {
200 *GopBltSize
= (UINTN
) BltBufferSize
;
201 *GopBlt
= EfiLibAllocatePool (*GopBltSize
);
203 if (*GopBlt
== NULL
) {
204 return EFI_OUT_OF_RESOURCES
;
207 if (*GopBltSize
< (UINTN
) BltBufferSize
) {
208 *GopBltSize
= (UINTN
) BltBufferSize
;
209 return EFI_BUFFER_TOO_SMALL
;
213 *PixelWidth
= BmpHeader
->PixelWidth
;
214 *PixelHeight
= BmpHeader
->PixelHeight
;
217 // Convert image from BMP to Blt buffer format
220 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
221 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
222 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
223 switch (BmpHeader
->BitPerPixel
) {
226 // Convert 1bit BMP to 24-bit color
228 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
229 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
230 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
231 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
242 // Convert BMP Palette to 24-bit color
244 Index
= (*Image
) >> 4;
245 Blt
->Red
= BmpColorMap
[Index
].Red
;
246 Blt
->Green
= BmpColorMap
[Index
].Green
;
247 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
248 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
251 Index
= (*Image
) & 0x0f;
252 Blt
->Red
= BmpColorMap
[Index
].Red
;
253 Blt
->Green
= BmpColorMap
[Index
].Green
;
254 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
260 // Convert BMP Palette to 24-bit color
262 Blt
->Red
= BmpColorMap
[*Image
].Red
;
263 Blt
->Green
= BmpColorMap
[*Image
].Green
;
264 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
268 Blt
->Blue
= *Image
++;
269 Blt
->Green
= *Image
++;
275 gBS
->FreePool (*GopBlt
);
278 return EFI_UNSUPPORTED
;
284 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
285 if ((ImageIndex
% 4) != 0) {
287 // Bmp Image starts each row on a 32-bit boundary!
289 Image
= Image
+ (4 - (ImageIndex
% 4));
304 Use Console Control Protocol to lock the Console In Spliter virtual handle.
305 This is the ConInHandle and ConIn handle in the EFI system table. All key
306 presses will be ignored until the Password is typed in. The only way to
307 disable the password is to type it in to a ConIn device.
310 Password - Password used to lock ConIn device
315 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
317 EFI_UNSUPPORTED - Logo not found
322 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
324 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
325 if (EFI_ERROR (Status
)) {
326 return EFI_UNSUPPORTED
;
329 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
335 IN EFI_GUID
*LogoFile
341 Use Console Control to turn off UGA based Simple Text Out consoles from going
342 to the UGA device. Put up LogoFile on every UGA device that is a console
346 LogoFile - File name of logo to display on the center of the screen.
351 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
353 EFI_UNSUPPORTED - Logo not found
357 return EnableQuietBootEx (LogoFile
, NULL
);
363 IN EFI_GUID
*LogoFile
,
364 IN EFI_HANDLE ImageHandle
370 Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going
371 to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console
375 LogoFile - File name of logo to display on the center of the screen.
380 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
382 EFI_UNSUPPORTED - Logo not found
387 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
388 EFI_OEM_BADGING_PROTOCOL
*Badging
;
397 EFI_BADGING_FORMAT Format
;
398 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
403 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
404 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
407 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
409 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
410 if (EFI_ERROR (Status
)) {
411 return EFI_UNSUPPORTED
;
416 // Try to open GOP first
418 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**) &GraphicsOutput
);
419 if (EFI_ERROR (Status
)) {
420 GraphicsOutput
= NULL
;
422 // Open GOP failed, try to open UGA
424 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**) &UgaDraw
);
425 if (EFI_ERROR (Status
)) {
426 return EFI_UNSUPPORTED
;
431 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**) &Badging
);
433 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
435 if (GraphicsOutput
!= NULL
) {
436 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
437 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
438 } else if (UgaDraw
!= NULL
) {
439 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
440 if (EFI_ERROR (Status
)) {
441 return EFI_UNSUPPORTED
;
444 return EFI_UNSUPPORTED
;
452 if (Badging
!= NULL
) {
453 Status
= Badging
->GetImage (
463 if (EFI_ERROR (Status
)) {
468 // Currently only support BMP format
470 if (Format
!= EfiBadgingFormatBMP
) {
471 gBS
->FreePool (ImageData
);
475 Status
= GetGraphicsBitMapFromFVEx (ImageHandle
, LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
476 if (EFI_ERROR (Status
)) {
477 return EFI_UNSUPPORTED
;
482 Attribute
= EfiBadgingDisplayAttributeCenter
;
486 Status
= ConvertBmpToGopBlt (
494 if (EFI_ERROR (Status
)) {
495 gBS
->FreePool (ImageData
);
496 if (Badging
== NULL
) {
504 case EfiBadgingDisplayAttributeLeftTop
:
509 case EfiBadgingDisplayAttributeCenterTop
:
510 DestX
= (SizeOfX
- Width
) / 2;
514 case EfiBadgingDisplayAttributeRightTop
:
515 DestX
= (SizeOfX
- Width
- CoordinateX
);
516 DestY
= CoordinateY
;;
519 case EfiBadgingDisplayAttributeCenterRight
:
520 DestX
= (SizeOfX
- Width
- CoordinateX
);
521 DestY
= (SizeOfY
- Height
) / 2;
524 case EfiBadgingDisplayAttributeRightBottom
:
525 DestX
= (SizeOfX
- Width
- CoordinateX
);
526 DestY
= (SizeOfY
- Height
- CoordinateY
);
529 case EfiBadgingDisplayAttributeCenterBottom
:
530 DestX
= (SizeOfX
- Width
) / 2;
531 DestY
= (SizeOfY
- Height
- CoordinateY
);
534 case EfiBadgingDisplayAttributeLeftBottom
:
536 DestY
= (SizeOfY
- Height
- CoordinateY
);
539 case EfiBadgingDisplayAttributeCenterLeft
:
541 DestY
= (SizeOfY
- Height
) / 2;
544 case EfiBadgingDisplayAttributeCenter
:
545 DestX
= (SizeOfX
- Width
) / 2;
546 DestY
= (SizeOfY
- Height
) / 2;
555 if ((DestX
>= 0) && (DestY
>= 0)) {
556 if (GraphicsOutput
!= NULL
) {
557 Status
= GraphicsOutput
->Blt (
567 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
570 Status
= UgaDraw
->Blt (
572 (EFI_UGA_PIXEL
*) Blt
,
573 EfiUgaBltBufferToVideo
,
580 Width
* sizeof (EFI_UGA_PIXEL
)
585 gBS
->FreePool (ImageData
);
588 if (Badging
== NULL
) {
605 Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
606 Simple Text Out screens will now be synced up with all non GOP/UGA output devices
614 EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
615 EFI_UNSUPPORTED - Logo not found
620 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
622 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
623 if (EFI_ERROR (Status
)) {
624 return EFI_UNSUPPORTED
;
627 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);