3 Copyright (c) 2004 - 2009, 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
;
439 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
440 if (EFI_ERROR (Status
)) {
441 return EFI_UNSUPPORTED
;
450 if (Badging
!= NULL
) {
451 Status
= Badging
->GetImage (
461 if (EFI_ERROR (Status
)) {
466 // Currently only support BMP format
468 if (Format
!= EfiBadgingFormatBMP
) {
469 gBS
->FreePool (ImageData
);
473 Status
= GetGraphicsBitMapFromFVEx (ImageHandle
, LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
474 if (EFI_ERROR (Status
)) {
475 return EFI_UNSUPPORTED
;
480 Attribute
= EfiBadgingDisplayAttributeCenter
;
484 Status
= ConvertBmpToGopBlt (
492 if (EFI_ERROR (Status
)) {
493 gBS
->FreePool (ImageData
);
494 if (Badging
== NULL
) {
502 case EfiBadgingDisplayAttributeLeftTop
:
507 case EfiBadgingDisplayAttributeCenterTop
:
508 DestX
= (SizeOfX
- Width
) / 2;
512 case EfiBadgingDisplayAttributeRightTop
:
513 DestX
= (SizeOfX
- Width
- CoordinateX
);
514 DestY
= CoordinateY
;;
517 case EfiBadgingDisplayAttributeCenterRight
:
518 DestX
= (SizeOfX
- Width
- CoordinateX
);
519 DestY
= (SizeOfY
- Height
) / 2;
522 case EfiBadgingDisplayAttributeRightBottom
:
523 DestX
= (SizeOfX
- Width
- CoordinateX
);
524 DestY
= (SizeOfY
- Height
- CoordinateY
);
527 case EfiBadgingDisplayAttributeCenterBottom
:
528 DestX
= (SizeOfX
- Width
) / 2;
529 DestY
= (SizeOfY
- Height
- CoordinateY
);
532 case EfiBadgingDisplayAttributeLeftBottom
:
534 DestY
= (SizeOfY
- Height
- CoordinateY
);
537 case EfiBadgingDisplayAttributeCenterLeft
:
539 DestY
= (SizeOfY
- Height
) / 2;
542 case EfiBadgingDisplayAttributeCenter
:
543 DestX
= (SizeOfX
- Width
) / 2;
544 DestY
= (SizeOfY
- Height
) / 2;
553 if ((DestX
>= 0) && (DestY
>= 0)) {
554 if (GraphicsOutput
!= NULL
) {
555 Status
= GraphicsOutput
->Blt (
565 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
568 Status
= UgaDraw
->Blt (
570 (EFI_UGA_PIXEL
*) Blt
,
571 EfiUgaBltBufferToVideo
,
578 Width
* sizeof (EFI_UGA_PIXEL
)
583 gBS
->FreePool (ImageData
);
586 if (Badging
== NULL
) {
603 Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
604 Simple Text Out screens will now be synced up with all non GOP/UGA output devices
612 EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
613 EFI_UNSUPPORTED - Logo not found
618 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
620 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**) &ConsoleControl
);
621 if (EFI_ERROR (Status
)) {
622 return EFI_UNSUPPORTED
;
625 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);