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"
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
;
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
= MultU64x32 ((UINT64
) BmpHeader
->PixelWidth
, BmpHeader
->PixelHeight
);
190 // Ensure the BltBufferSize * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
192 if (BltBufferSize
> DivU64x32 ((UINTN
) ~0, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), NULL
)) {
193 return EFI_UNSUPPORTED
;
195 BltBufferSize
= MultU64x32 (BltBufferSize
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
198 if (*GopBlt
== NULL
) {
199 *GopBltSize
= (UINTN
) BltBufferSize
;
200 *GopBlt
= EfiLibAllocatePool (*GopBltSize
);
202 if (*GopBlt
== NULL
) {
203 return EFI_OUT_OF_RESOURCES
;
206 if (*GopBltSize
< (UINTN
) BltBufferSize
) {
207 *GopBltSize
= (UINTN
) BltBufferSize
;
208 return EFI_BUFFER_TOO_SMALL
;
212 *PixelWidth
= BmpHeader
->PixelWidth
;
213 *PixelHeight
= BmpHeader
->PixelHeight
;
216 // Convert image from BMP to Blt buffer format
219 for (Height
= 0; Height
< BmpHeader
->PixelHeight
; Height
++) {
220 Blt
= &BltBuffer
[(BmpHeader
->PixelHeight
- Height
- 1) * BmpHeader
->PixelWidth
];
221 for (Width
= 0; Width
< BmpHeader
->PixelWidth
; Width
++, Image
++, Blt
++) {
222 switch (BmpHeader
->BitPerPixel
) {
225 // Convert 1bit BMP to 24-bit color
227 for (Index
= 0; Index
< 8 && Width
< BmpHeader
->PixelWidth
; Index
++) {
228 Blt
->Red
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Red
;
229 Blt
->Green
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Green
;
230 Blt
->Blue
= BmpColorMap
[((*Image
) >> (7 - Index
)) & 0x1].Blue
;
241 // Convert BMP Palette to 24-bit color
243 Index
= (*Image
) >> 4;
244 Blt
->Red
= BmpColorMap
[Index
].Red
;
245 Blt
->Green
= BmpColorMap
[Index
].Green
;
246 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
247 if (Width
< (BmpHeader
->PixelWidth
- 1)) {
250 Index
= (*Image
) & 0x0f;
251 Blt
->Red
= BmpColorMap
[Index
].Red
;
252 Blt
->Green
= BmpColorMap
[Index
].Green
;
253 Blt
->Blue
= BmpColorMap
[Index
].Blue
;
259 // Convert BMP Palette to 24-bit color
261 Blt
->Red
= BmpColorMap
[*Image
].Red
;
262 Blt
->Green
= BmpColorMap
[*Image
].Green
;
263 Blt
->Blue
= BmpColorMap
[*Image
].Blue
;
267 Blt
->Blue
= *Image
++;
268 Blt
->Green
= *Image
++;
274 gBS
->FreePool (*GopBlt
);
277 return EFI_UNSUPPORTED
;
283 ImageIndex
= (UINTN
) (Image
- ImageHeader
);
284 if ((ImageIndex
% 4) != 0) {
286 // Bmp Image starts each row on a 32-bit boundary!
288 Image
= Image
+ (4 - (ImageIndex
% 4));
303 Use Console Control Protocol to lock the Console In Spliter virtual handle.
304 This is the ConInHandle and ConIn handle in the EFI system table. All key
305 presses will be ignored until the Password is typed in. The only way to
306 disable the password is to type it in to a ConIn device.
309 Password - Password used to lock ConIn device
314 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
316 EFI_UNSUPPORTED - Logo not found
321 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
323 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
324 if (EFI_ERROR (Status
)) {
325 return EFI_UNSUPPORTED
;
328 Status
= ConsoleControl
->LockStdIn (ConsoleControl
, Password
);
334 IN EFI_GUID
*LogoFile
340 Use Console Control to turn off UGA based Simple Text Out consoles from going
341 to the UGA device. Put up LogoFile on every UGA device that is a console
345 LogoFile - File name of logo to display on the center of the screen.
350 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
352 EFI_UNSUPPORTED - Logo not found
356 return EnableQuietBootEx (LogoFile
, NULL
);
361 IN EFI_GUID
*LogoFile
,
362 IN EFI_HANDLE ImageHandle
368 Use Console Control to turn off GOP/UGA based Simple Text Out consoles from going
369 to the GOP/UGA device. Put up LogoFile on every GOP/UGA device that is a console
373 LogoFile - File name of logo to display on the center of the screen.
374 ImageHandle - The driver image handle of the caller. The parameter is used to
375 optimize the loading of the logo file so that the FV from which
376 the driver image is loaded will be tried first.
381 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
383 EFI_UNSUPPORTED - Logo not found
388 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
389 EFI_OEM_BADGING_PROTOCOL
*Badging
;
398 EFI_BADGING_FORMAT Format
;
399 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute
;
404 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Blt
;
405 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
408 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
410 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
411 if (EFI_ERROR (Status
)) {
412 return EFI_UNSUPPORTED
;
417 // Try to open GOP first
419 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiGraphicsOutputProtocolGuid
, (VOID
**)&GraphicsOutput
);
420 if (EFI_ERROR (Status
)) {
421 GraphicsOutput
= NULL
;
423 // Open GOP failed, try to open UGA
425 Status
= gBS
->HandleProtocol (gST
->ConsoleOutHandle
, &gEfiUgaDrawProtocolGuid
, (VOID
**)&UgaDraw
);
426 if (EFI_ERROR (Status
)) {
427 return EFI_UNSUPPORTED
;
432 Status
= gBS
->LocateProtocol (&gEfiOEMBadgingProtocolGuid
, NULL
, (VOID
**)&Badging
);
434 ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenGraphics
);
436 if (GraphicsOutput
!= NULL
) {
437 SizeOfX
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
438 SizeOfY
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
440 Status
= UgaDraw
->GetMode (UgaDraw
, &SizeOfX
, &SizeOfY
, &ColorDepth
, &RefreshRate
);
441 if (EFI_ERROR (Status
)) {
442 return EFI_UNSUPPORTED
;
451 if (Badging
!= NULL
) {
452 Status
= Badging
->GetImage (
462 if (EFI_ERROR (Status
)) {
467 // Currently only support BMP format
469 if (Format
!= EfiBadgingFormatBMP
) {
470 gBS
->FreePool (ImageData
);
474 Status
= GetGraphicsBitMapFromFVEx (ImageHandle
, LogoFile
, (VOID
**) &ImageData
, &ImageSize
);
475 if (EFI_ERROR (Status
)) {
476 return EFI_UNSUPPORTED
;
481 Attribute
= EfiBadgingDisplayAttributeCenter
;
485 Status
= ConvertBmpToGopBlt (
493 if (EFI_ERROR (Status
)) {
494 gBS
->FreePool (ImageData
);
495 if (Badging
== NULL
) {
503 case EfiBadgingDisplayAttributeLeftTop
:
508 case EfiBadgingDisplayAttributeCenterTop
:
509 DestX
= (SizeOfX
- Width
) / 2;
513 case EfiBadgingDisplayAttributeRightTop
:
514 DestX
= (SizeOfX
- Width
- CoordinateX
);
515 DestY
= CoordinateY
;;
518 case EfiBadgingDisplayAttributeCenterRight
:
519 DestX
= (SizeOfX
- Width
- CoordinateX
);
520 DestY
= (SizeOfY
- Height
) / 2;
523 case EfiBadgingDisplayAttributeRightBottom
:
524 DestX
= (SizeOfX
- Width
- CoordinateX
);
525 DestY
= (SizeOfY
- Height
- CoordinateY
);
528 case EfiBadgingDisplayAttributeCenterBottom
:
529 DestX
= (SizeOfX
- Width
) / 2;
530 DestY
= (SizeOfY
- Height
- CoordinateY
);
533 case EfiBadgingDisplayAttributeLeftBottom
:
535 DestY
= (SizeOfY
- Height
- CoordinateY
);
538 case EfiBadgingDisplayAttributeCenterLeft
:
540 DestY
= (SizeOfY
- Height
) / 2;
543 case EfiBadgingDisplayAttributeCenter
:
544 DestX
= (SizeOfX
- Width
) / 2;
545 DestY
= (SizeOfY
- Height
) / 2;
554 if ((DestX
>= 0) && (DestY
>= 0)) {
555 if (GraphicsOutput
!= NULL
) {
556 Status
= GraphicsOutput
->Blt (
566 Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
569 Status
= UgaDraw
->Blt (
571 (EFI_UGA_PIXEL
*) Blt
,
572 EfiUgaBltBufferToVideo
,
579 Width
* sizeof (EFI_UGA_PIXEL
)
584 gBS
->FreePool (ImageData
);
587 if (Badging
== NULL
) {
604 Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA
605 Simple Text Out screens will now be synced up with all non GOP/UGA output devices
613 EFI_SUCCESS - GOP/UGA devices are back in text mode and synced up.
614 EFI_UNSUPPORTED - Logo not found
619 EFI_CONSOLE_CONTROL_PROTOCOL
*ConsoleControl
;
621 Status
= gBS
->LocateProtocol (&gEfiConsoleControlProtocolGuid
, NULL
, (VOID
**)&ConsoleControl
);
622 if (EFI_ERROR (Status
)) {
623 return EFI_UNSUPPORTED
;
626 return ConsoleControl
->SetMode (ConsoleControl
, EfiConsoleControlScreenText
);