2 Support for Basic Graphics operations.
\r
4 BugBug: Currently *.BMP files are supported. This will be replaced
\r
5 when Tiano graphics format is supported.
\r
8 Copyright (c) 2006, Intel Corporation
\r
9 All rights reserved. This program and the accompanying materials
\r
10 are licensed and made available under the terms and conditions of the BSD License
\r
11 which accompanies this distribution. The full text of the license may be found at
\r
12 http://opensource.org/licenses/bsd-license.php
\r
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
20 // Include common header file for this module.
\r
22 #include "CommonHeader.h"
\r
25 GetGraphicsBitMapFromFV (
\r
26 IN EFI_GUID *FileNameGuid,
\r
28 OUT UINTN *ImageSize
\r
32 Routine Description:
\r
34 Return the graphics image file named FileNameGuid into Image and return it's
\r
35 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the
\r
40 FileNameGuid - File Name of graphics file in the FV(s).
\r
42 Image - Pointer to pointer to return graphics image. If NULL, a
\r
43 buffer will be allocated.
\r
45 ImageSize - Size of the graphics Image in bytes. Zero if no image found.
\r
50 EFI_SUCCESS - Image and ImageSize are valid.
\r
51 EFI_BUFFER_TOO_SMALL - Image not big enough. ImageSize has required size
\r
52 EFI_NOT_FOUND - FileNameGuid not found
\r
57 UINTN FvProtocolCount;
\r
58 EFI_HANDLE *FvHandles;
\r
59 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
\r
61 UINT32 AuthenticationStatus;
\r
64 Status = gBS->LocateHandleBuffer (
\r
66 &gEfiFirmwareVolume2ProtocolGuid,
\r
71 if (EFI_ERROR (Status)) {
\r
72 return EFI_NOT_FOUND;
\r
75 for (Index = 0; Index < FvProtocolCount; Index++) {
\r
76 Status = gBS->HandleProtocol (
\r
78 &gEfiFirmwareVolume2ProtocolGuid,
\r
83 // Assuming Image and ImageSize are correct on input.
\r
85 Status = Fv->ReadSection (
\r
92 &AuthenticationStatus
\r
94 if (!EFI_ERROR (Status)) {
\r
96 } else if (Status == EFI_BUFFER_TOO_SMALL) {
\r
98 // ImageSize updated to needed size so return
\r
100 return EFI_BUFFER_TOO_SMALL;
\r
104 return EFI_NOT_FOUND;
\r
109 ConvertBmpToGopBlt (
\r
111 IN UINTN BmpImageSize,
\r
112 IN OUT VOID **GopBlt,
\r
113 IN OUT UINTN *GopBltSize,
\r
114 OUT UINTN *PixelHeight,
\r
115 OUT UINTN *PixelWidth
\r
119 Routine Description:
\r
121 Convert a *.BMP graphics image to a UGA blt buffer. If a NULL UgaBlt buffer
\r
122 is passed in a UgaBlt buffer will be allocated by this routine. If a UgaBlt
\r
123 buffer is passed in it will be used if it is big enough.
\r
127 BmpImage - Pointer to BMP file
\r
129 BmpImageSize - Number of bytes in BmpImage
\r
131 UgaBlt - Buffer containing UGA version of BmpImage.
\r
133 UgaBltSize - Size of UgaBlt in bytes.
\r
135 PixelHeight - Height of UgaBlt/BmpImage in pixels
\r
137 PixelWidth - Width of UgaBlt/BmpImage in pixels
\r
142 EFI_SUCCESS - UgaBlt and UgaBltSize are returned.
\r
143 EFI_UNSUPPORTED - BmpImage is not a valid *.BMP image
\r
144 EFI_BUFFER_TOO_SMALL - The passed in UgaBlt buffer is not big enough.
\r
145 UgaBltSize will contain the required size.
\r
146 EFI_OUT_OF_RESOURCES - No enough buffer to allocate
\r
151 UINT8 *ImageHeader;
\r
152 BMP_IMAGE_HEADER *BmpHeader;
\r
153 BMP_COLOR_MAP *BmpColorMap;
\r
154 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
\r
155 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
\r
156 UINTN BltBufferSize;
\r
161 BOOLEAN IsAllocated;
\r
163 BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;
\r
164 if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {
\r
165 return EFI_UNSUPPORTED;
\r
168 if (BmpHeader->CompressionType != 0) {
\r
169 return EFI_UNSUPPORTED;
\r
173 // Calculate Color Map offset in the image.
\r
176 BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));
\r
179 // Calculate graphics image data address in the image
\r
181 Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;
\r
182 ImageHeader = Image;
\r
184 BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
\r
185 IsAllocated = FALSE;
\r
186 if (*GopBlt == NULL) {
\r
187 *GopBltSize = BltBufferSize;
\r
188 *GopBlt = AllocatePool (*GopBltSize);
\r
189 IsAllocated = TRUE;
\r
190 if (*GopBlt == NULL) {
\r
191 return EFI_OUT_OF_RESOURCES;
\r
194 if (*GopBltSize < BltBufferSize) {
\r
195 *GopBltSize = BltBufferSize;
\r
196 return EFI_BUFFER_TOO_SMALL;
\r
200 *PixelWidth = BmpHeader->PixelWidth;
\r
201 *PixelHeight = BmpHeader->PixelHeight;
\r
204 // Convert image from BMP to Blt buffer format
\r
206 BltBuffer = *GopBlt;
\r
207 for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {
\r
208 Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];
\r
209 for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {
\r
210 switch (BmpHeader->BitPerPixel) {
\r
213 // Convert 1bit BMP to 24-bit color
\r
215 for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {
\r
216 Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;
\r
217 Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;
\r
218 Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;
\r
229 // Convert BMP Palette to 24-bit color
\r
231 Index = (*Image) >> 4;
\r
232 Blt->Red = BmpColorMap[Index].Red;
\r
233 Blt->Green = BmpColorMap[Index].Green;
\r
234 Blt->Blue = BmpColorMap[Index].Blue;
\r
235 if (Width < (BmpHeader->PixelWidth - 1)) {
\r
238 Index = (*Image) & 0x0f;
\r
239 Blt->Red = BmpColorMap[Index].Red;
\r
240 Blt->Green = BmpColorMap[Index].Green;
\r
241 Blt->Blue = BmpColorMap[Index].Blue;
\r
247 // Convert BMP Palette to 24-bit color
\r
249 Blt->Red = BmpColorMap[*Image].Red;
\r
250 Blt->Green = BmpColorMap[*Image].Green;
\r
251 Blt->Blue = BmpColorMap[*Image].Blue;
\r
255 Blt->Blue = *Image++;
\r
256 Blt->Green = *Image++;
\r
262 gBS->FreePool (*GopBlt);
\r
265 return EFI_UNSUPPORTED;
\r
271 ImageIndex = (UINTN) (Image - ImageHeader);
\r
272 if ((ImageIndex % 4) != 0) {
\r
274 // Bmp Image starts each row on a 32-bit boundary!
\r
276 Image = Image + (4 - (ImageIndex % 4));
\r
280 return EFI_SUCCESS;
\r
286 IN CHAR16 *Password
\r
290 Routine Description:
\r
291 Use Console Control Protocol to lock the Console In Spliter virtual handle.
\r
292 This is the ConInHandle and ConIn handle in the EFI system table. All key
\r
293 presses will be ignored until the Password is typed in. The only way to
\r
294 disable the password is to type it in to a ConIn device.
\r
297 Password - Password used to lock ConIn device
\r
302 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
\r
304 EFI_UNSUPPORTED - Logo not found
\r
309 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
\r
311 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
\r
312 if (EFI_ERROR (Status)) {
\r
313 return EFI_UNSUPPORTED;
\r
316 Status = ConsoleControl->LockStdIn (ConsoleControl, Password);
\r
323 IN EFI_GUID *LogoFile
\r
327 Routine Description:
\r
329 Use Console Control to turn off UGA based Simple Text Out consoles from going
\r
330 to the UGA device. Put up LogoFile on every UGA device that is a console
\r
334 LogoFile - File name of logo to display on the center of the screen.
\r
339 EFI_SUCCESS - ConsoleControl has been flipped to graphics and logo
\r
341 EFI_UNSUPPORTED - Logo not found
\r
346 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
\r
347 EFI_OEM_BADGING_PROTOCOL *Badging;
\r
356 EFI_BADGING_FORMAT Format;
\r
357 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;
\r
362 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
\r
363 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
\r
365 UINT32 RefreshRate;
\r
366 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
\r
368 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
\r
369 if (EFI_ERROR (Status)) {
\r
370 return EFI_UNSUPPORTED;
\r
375 // Try to open GOP first
\r
377 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
\r
378 if (EFI_ERROR(Status)) {
\r
379 GraphicsOutput = NULL;
\r
381 // Open GOP failed, try to open UGA
\r
383 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);
\r
384 if (EFI_ERROR (Status)) {
\r
385 return EFI_UNSUPPORTED;
\r
390 Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);
\r
392 ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);
\r
394 if (GraphicsOutput != NULL) {
\r
395 SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
\r
396 SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
\r
398 Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);
\r
399 if (EFI_ERROR (Status)) {
\r
400 return EFI_UNSUPPORTED;
\r
409 if (Badging != NULL) {
\r
410 Status = Badging->GetImage (
\r
420 if (EFI_ERROR (Status)) {
\r
425 // Currently only support BMP format
\r
427 if (Format != EfiBadgingFormatBMP) {
\r
428 gBS->FreePool (ImageData);
\r
432 Status = GetGraphicsBitMapFromFV (LogoFile, (VOID **) &ImageData, &ImageSize);
\r
433 if (EFI_ERROR (Status)) {
\r
434 return EFI_UNSUPPORTED;
\r
439 Attribute = EfiBadgingDisplayAttributeCenter;
\r
444 Status = ConvertBmpToGopBlt (
\r
452 if (EFI_ERROR (Status)) {
\r
453 gBS->FreePool (ImageData);
\r
454 if (Badging == NULL) {
\r
461 switch (Attribute) {
\r
462 case EfiBadgingDisplayAttributeLeftTop:
\r
463 DestX = CoordinateX;
\r
464 DestY = CoordinateY;
\r
467 case EfiBadgingDisplayAttributeCenterTop:
\r
468 DestX = (SizeOfX - Width) / 2;
\r
469 DestY = CoordinateY;
\r
472 case EfiBadgingDisplayAttributeRightTop:
\r
473 DestX = (SizeOfX - Width - CoordinateX);
\r
474 DestY = CoordinateY;;
\r
477 case EfiBadgingDisplayAttributeCenterRight:
\r
478 DestX = (SizeOfX - Width - CoordinateX);
\r
479 DestY = (SizeOfY - Height) / 2;
\r
482 case EfiBadgingDisplayAttributeRightBottom:
\r
483 DestX = (SizeOfX - Width - CoordinateX);
\r
484 DestY = (SizeOfY - Height - CoordinateY);
\r
487 case EfiBadgingDisplayAttributeCenterBottom:
\r
488 DestX = (SizeOfX - Width) / 2;
\r
489 DestY = (SizeOfY - Height - CoordinateY);
\r
492 case EfiBadgingDisplayAttributeLeftBottom:
\r
493 DestX = CoordinateX;
\r
494 DestY = (SizeOfY - Height - CoordinateY);
\r
497 case EfiBadgingDisplayAttributeCenterLeft:
\r
498 DestX = CoordinateX;
\r
499 DestY = (SizeOfY - Height) / 2;
\r
502 case EfiBadgingDisplayAttributeCenter:
\r
503 DestX = (SizeOfX - Width) / 2;
\r
504 DestY = (SizeOfY - Height) / 2;
\r
508 DestX = CoordinateX;
\r
509 DestY = CoordinateY;
\r
513 if ((DestX >= 0) && (DestY >= 0)) {
\r
514 if (GraphicsOutput != NULL) {
\r
515 Status = GraphicsOutput->Blt (
\r
518 EfiBltBufferToVideo,
\r
525 Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
\r
528 Status = UgaDraw->Blt (
\r
530 (EFI_UGA_PIXEL *) Blt,
\r
531 EfiUgaBltBufferToVideo,
\r
538 Width * sizeof (EFI_UGA_PIXEL)
\r
543 gBS->FreePool (ImageData);
\r
544 gBS->FreePool (Blt);
\r
546 if (Badging == NULL) {
\r
561 Routine Description:
\r
563 Use Console Control to turn on UGA based Simple Text Out consoles. The UGA
\r
564 Simple Text Out screens will now be synced up with all non UGA output devices
\r
572 EFI_SUCCESS - UGA devices are back in text mode and synced up.
\r
573 EFI_UNSUPPORTED - Logo not found
\r
578 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
\r
580 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);
\r
581 if (EFI_ERROR (Status)) {
\r
582 return EFI_UNSUPPORTED;
\r
585 return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);
\r
588 static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {
\r
589 { 0x00, 0x00, 0x00, 0x00 },
\r
590 { 0x98, 0x00, 0x00, 0x00 },
\r
591 { 0x00, 0x98, 0x00, 0x00 },
\r
592 { 0x98, 0x98, 0x00, 0x00 },
\r
593 { 0x00, 0x00, 0x98, 0x00 },
\r
594 { 0x98, 0x00, 0x98, 0x00 },
\r
595 { 0x00, 0x98, 0x98, 0x00 },
\r
596 { 0x98, 0x98, 0x98, 0x00 },
\r
597 { 0x10, 0x10, 0x10, 0x00 },
\r
598 { 0xff, 0x10, 0x10, 0x00 },
\r
599 { 0x10, 0xff, 0x10, 0x00 },
\r
600 { 0xff, 0xff, 0x10, 0x00 },
\r
601 { 0x10, 0x10, 0xff, 0x00 },
\r
602 { 0xf0, 0x10, 0xff, 0x00 },
\r
603 { 0x10, 0xff, 0xff, 0x00 },
\r
604 { 0xff, 0xff, 0xff, 0x00 }
\r
610 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
\r
611 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw,
\r
612 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto,
\r
615 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,
\r
616 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background,
\r
622 Routine Description:
\r
624 Display string worker for: Print, PrintAt, IPrint, IPrintAt
\r
628 GraphicsOutput - Graphics output protocol interface
\r
630 UgaDraw - UGA draw protocol interface
\r
632 Sto - Simple text out protocol interface
\r
634 X - X coordinate to start printing
\r
636 Y - Y coordinate to start printing
\r
638 Foreground - Foreground color
\r
640 Background - Background color
\r
642 fmt - Format string
\r
644 args - Print arguments
\r
648 EFI_SUCCESS - success
\r
649 EFI_OUT_OF_RESOURCES - out of resources
\r
656 UINT32 GlyphStatus;
\r
657 UINT16 StringIndex;
\r
659 CHAR16 *UnicodeWeight;
\r
660 EFI_NARROW_GLYPH *Glyph;
\r
661 EFI_HII_PROTOCOL *Hii;
\r
662 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LineBuffer;
\r
663 UINT32 HorizontalResolution;
\r
664 UINT32 VerticalResolution;
\r
666 UINT32 RefreshRate;
\r
667 UINTN BufferGlyphWidth;
\r
672 // For now, allocate an arbitrarily long buffer
\r
674 Buffer = AllocateZeroPool (0x10000);
\r
675 if (Buffer == NULL) {
\r
676 return EFI_OUT_OF_RESOURCES;
\r
679 if (GraphicsOutput != NULL) {
\r
680 HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
\r
681 VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
\r
684 // Get the current mode information from the UGA Draw Protocol
\r
686 UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);
\r
689 LineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_WIDTH * GLYPH_HEIGHT);
\r
690 if (LineBuffer == NULL) {
\r
691 gBS->FreePool (Buffer);
\r
692 return EFI_OUT_OF_RESOURCES;
\r
695 Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, (VOID **) &Hii);
\r
696 if (EFI_ERROR (Status)) {
\r
700 UnicodeVSPrint (Buffer, 0x10000, fmt, args);
\r
702 UnicodeWeight = (CHAR16 *) Buffer;
\r
704 for (Index = 0; UnicodeWeight[Index] != 0; Index++) {
\r
705 if (UnicodeWeight[Index] == CHAR_BACKSPACE ||
\r
706 UnicodeWeight[Index] == CHAR_LINEFEED ||
\r
707 UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) {
\r
708 UnicodeWeight[Index] = 0;
\r
712 for (Index = 0; Index < StrLen (Buffer); Index++) {
\r
713 StringIndex = (UINT16) Index;
\r
714 Status = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);
\r
715 if (EFI_ERROR (Status)) {
\r
719 if (Foreground == NULL || Background == NULL) {
\r
720 Status = Hii->GlyphToBlt (
\r
723 mEfiColors[Sto->Mode->Attribute & 0x0f],
\r
724 mEfiColors[Sto->Mode->Attribute >> 4],
\r
728 &LineBuffer[Index * GLYPH_WIDTH]
\r
731 Status = Hii->GlyphToBlt (
\r
739 &LineBuffer[Index * GLYPH_WIDTH]
\r
745 // Blt a character to the screen
\r
747 BufferGlyphWidth = GLYPH_WIDTH * StrLen (Buffer);
\r
748 if (GraphicsOutput != NULL) {
\r
749 Status = GraphicsOutput->Blt (
\r
752 EfiBltBufferToVideo,
\r
759 BufferGlyphWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
\r
762 Status = UgaDraw->Blt (
\r
764 (EFI_UGA_PIXEL *) (UINTN) LineBuffer,
\r
765 EfiUgaBltBufferToVideo,
\r
772 BufferGlyphWidth * sizeof (EFI_UGA_PIXEL)
\r
777 gBS->FreePool (LineBuffer);
\r
778 gBS->FreePool (Buffer);
\r
787 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL
\r
788 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL
\r
794 Routine Description:
\r
796 Prints a formatted unicode string to the default console
\r
800 X - X coordinate to start printing
\r
802 Y - Y coordinate to start printing
\r
804 ForeGround - Foreground color
\r
806 BackGround - Background color
\r
808 Fmt - Format string
\r
810 ... - Print arguments
\r
814 Length of string printed to the console
\r
820 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
\r
821 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
\r
822 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;
\r
826 VA_START (Args, Fmt);
\r
830 Handle = gST->ConsoleOutHandle;
\r
832 Status = gBS->HandleProtocol (
\r
834 &gEfiGraphicsOutputProtocolGuid,
\r
835 (VOID **) &GraphicsOutput
\r
838 if (EFI_ERROR (Status)) {
\r
839 GraphicsOutput = NULL;
\r
841 Status = gBS->HandleProtocol (
\r
843 &gEfiUgaDrawProtocolGuid,
\r
847 if (EFI_ERROR (Status)) {
\r
852 Status = gBS->HandleProtocol (
\r
854 &gEfiSimpleTextOutProtocolGuid,
\r
858 if (EFI_ERROR (Status)) {
\r
862 return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);
\r