/*++\r
\r
-Copyright (c) 2004 - 2006, Intel Corporation \r
-All rights reserved. This program and the accompanying materials \r
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials \r
are licensed and made available under the terms and conditions of the BSD License \r
which accompanies this distribution. The full text of the license may be found at \r
http://opensource.org/licenses/bsd-license.php \r
#include "PrintWidth.h"\r
#include "EfiPrintLib.h"\r
#include "Print.h"\r
+#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
+#include EFI_PROTOCOL_DEFINITION (HiiFont)\r
+#else\r
#include EFI_PROTOCOL_DEFINITION (Hii)\r
+#endif\r
\r
static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r
- 0x00, 0x00, 0x00, 0x00,\r
- 0x98, 0x00, 0x00, 0x00,\r
- 0x00, 0x98, 0x00, 0x00,\r
- 0x98, 0x98, 0x00, 0x00,\r
- 0x00, 0x00, 0x98, 0x00,\r
- 0x98, 0x00, 0x98, 0x00,\r
- 0x00, 0x98, 0x98, 0x00,\r
- 0x98, 0x98, 0x98, 0x00,\r
- 0x10, 0x10, 0x10, 0x00,\r
- 0xff, 0x10, 0x10, 0x00,\r
- 0x10, 0xff, 0x10, 0x00,\r
- 0xff, 0xff, 0x10, 0x00,\r
- 0x10, 0x10, 0xff, 0x00,\r
- 0xf0, 0x10, 0xff, 0x00,\r
- 0x10, 0xff, 0xff, 0x00,\r
- 0xff, 0xff, 0xff, 0x00,\r
+ {0x00, 0x00, 0x00, 0x00},\r
+ {0x98, 0x00, 0x00, 0x00},\r
+ {0x00, 0x98, 0x00, 0x00},\r
+ {0x98, 0x98, 0x00, 0x00},\r
+ {0x00, 0x00, 0x98, 0x00},\r
+ {0x98, 0x00, 0x98, 0x00},\r
+ {0x00, 0x98, 0x98, 0x00},\r
+ {0x98, 0x98, 0x98, 0x00},\r
+ {0x10, 0x10, 0x10, 0x00},\r
+ {0xff, 0x10, 0x10, 0x00},\r
+ {0x10, 0xff, 0x10, 0x00},\r
+ {0xff, 0xff, 0x10, 0x00},\r
+ {0x10, 0x10, 0xff, 0x00},\r
+ {0xf0, 0x10, 0xff, 0x00},\r
+ {0x10, 0xff, 0xff, 0x00},\r
+ {0xff, 0xff, 0xff, 0x00},\r
};\r
\r
\r
\r
Returns: \r
\r
- EFI_SUCCESS - success\r
- EFI_OUT_OF_RESOURCES - out of resources\r
+ Length of string printed to the console\r
\r
--*/\r
{\r
VOID *Buffer;\r
EFI_STATUS Status;\r
- UINT16 GlyphWidth;\r
- UINT32 GlyphStatus;\r
- UINT16 StringIndex;\r
UINTN Index;\r
CHAR16 *UnicodeWeight;\r
- EFI_NARROW_GLYPH *Glyph;\r
- EFI_HII_PROTOCOL *Hii;\r
- EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LineBuffer;\r
UINT32 HorizontalResolution;\r
UINT32 VerticalResolution;\r
UINT32 ColorDepth;\r
UINT32 RefreshRate;\r
UINTN BufferLen;\r
UINTN LineBufferLen;\r
-\r
- GlyphStatus = 0;\r
+#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
+ EFI_HII_FONT_PROTOCOL *HiiFont;\r
+ EFI_IMAGE_OUTPUT *Blt;\r
+ EFI_FONT_DISPLAY_INFO *FontInfo; \r
+#else\r
+ EFI_HII_PROTOCOL *Hii;\r
+ UINT16 GlyphWidth;\r
+ UINT32 GlyphStatus;\r
+ UINT16 StringIndex;\r
+ EFI_NARROW_GLYPH *Glyph;\r
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL *LineBuffer;\r
+#endif\r
\r
//\r
// For now, allocate an arbitrarily long buffer\r
//\r
+ BufferLen = 0;\r
Buffer = EfiLibAllocateZeroPool (0x10000);\r
if (Buffer == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
+ return 0;\r
}\r
\r
if (GraphicsOutput != NULL) {\r
}\r
ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));\r
\r
+#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
+ Blt = NULL;\r
+ FontInfo = NULL;\r
+ ASSERT (GraphicsOutput != NULL);\r
+ Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &HiiFont);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ } \r
+#else \r
+ LineBuffer = NULL;\r
+ Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, (VOID**)&Hii);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ }\r
LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_HEIGHT;\r
LineBuffer = EfiLibAllocatePool (LineBufferLen);\r
if (LineBuffer == NULL) {\r
- gBS->FreePool (Buffer);\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, &Hii);\r
- if (EFI_ERROR (Status)) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
goto Error;\r
- }\r
+ } \r
+#endif\r
\r
VSPrint (Buffer, 0x10000, fmt, args);\r
\r
\r
BufferLen = EfiStrLen (Buffer);\r
\r
+#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
+ LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * EFI_GLYPH_HEIGHT;\r
+ if (EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Error;\r
+ }\r
+\r
+ Blt = (EFI_IMAGE_OUTPUT *) EfiLibAllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
+ if (Blt == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Error;\r
+ }\r
+\r
+ Blt->Width = (UINT16) (HorizontalResolution);\r
+ Blt->Height = (UINT16) (VerticalResolution);\r
+ Blt->Image.Screen = GraphicsOutput;\r
+ \r
+ FontInfo = (EFI_FONT_DISPLAY_INFO *) EfiLibAllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));\r
+ if (FontInfo == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Error;\r
+ }\r
+ if (Foreground != NULL) {\r
+ EfiCopyMem (&FontInfo->ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+ } else {\r
+ EfiCopyMem (\r
+ &FontInfo->ForegroundColor, \r
+ &mEfiColors[Sto->Mode->Attribute & 0x0f], \r
+ sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+ );\r
+ }\r
+ if (Background != NULL) {\r
+ EfiCopyMem (&FontInfo->BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+ } else {\r
+ EfiCopyMem (\r
+ &FontInfo->BackgroundColor, \r
+ &mEfiColors[Sto->Mode->Attribute >> 4], \r
+ sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+ );\r
+ }\r
+\r
+ Status = HiiFont->StringToImage (\r
+ HiiFont,\r
+ EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,\r
+ Buffer,\r
+ FontInfo,\r
+ &Blt,\r
+ X,\r
+ Y,\r
+ NULL,\r
+ NULL,\r
+ NULL\r
+ );\r
+ \r
+#else\r
+ GlyphStatus = 0;\r
+\r
if (GLYPH_WIDTH * GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {\r
Status = EFI_INVALID_PARAMETER;\r
goto Error;\r
);\r
}\r
\r
+#endif\r
+\r
Error:\r
- gBS->FreePool (LineBuffer);\r
+#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)\r
+ EfiLibSafeFreePool (Blt);\r
+ EfiLibSafeFreePool (FontInfo);\r
+#else\r
+ EfiLibSafeFreePool (LineBuffer);\r
+#endif \r
gBS->FreePool (Buffer);\r
- return Status;\r
+ \r
+ if (EFI_ERROR (Status)) {\r
+ return 0;\r
+ }\r
+\r
+ return BufferLen;\r
}\r
\r
\r
EFI_SIMPLE_TEXT_OUT_PROTOCOL *Sto;\r
EFI_STATUS Status;\r
VA_LIST Args;\r
-\r
- VA_START (Args, Fmt);\r
+ UINTN LengthOfPrinted;\r
\r
Handle = gST->ConsoleOutHandle;\r
\r
+ GraphicsOutput = NULL;\r
+ UgaDraw = NULL;\r
Status = gBS->HandleProtocol (\r
Handle,\r
&gEfiGraphicsOutputProtocolGuid,\r
- &GraphicsOutput\r
+ (VOID **) &GraphicsOutput\r
);\r
\r
- UgaDraw = NULL;\r
- if (EFI_ERROR (Status)) {\r
+ if (EFI_ERROR (Status) || (GraphicsOutput == NULL)) {\r
GraphicsOutput = NULL;\r
\r
Status = gBS->HandleProtocol (\r
Handle,\r
&gEfiUgaDrawProtocolGuid,\r
- &UgaDraw\r
+ (VOID **) &UgaDraw\r
);\r
\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
+ if (EFI_ERROR (Status) || (UgaDraw == NULL)) {\r
+ return 0;\r
}\r
}\r
\r
+ Sto = NULL;\r
Status = gBS->HandleProtocol (\r
Handle,\r
&gEfiSimpleTextOutProtocolGuid,\r
- &Sto\r
+ (VOID **) &Sto\r
);\r
\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
+ if (EFI_ERROR (Status) || (Sto == NULL)) {\r
+ return 0;\r
}\r
\r
- return _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
+ VA_START (Args, Fmt);\r
+ LengthOfPrinted = _IPrint (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
+ VA_END (Args);\r
+ return LengthOfPrinted;\r
}\r
\r
\r
}\r
\r
UINTN\r
+EFIAPI\r
VSPrint (\r
OUT CHAR_W *StartOfBuffer,\r
IN UINTN BufferSize,\r
Status = gBS->LocateProtocol (\r
&gEfiPrintProtocolGuid,\r
NULL,\r
- &PrintProtocol\r
+ (VOID **) &PrintProtocol\r
);\r
if (EFI_ERROR (Status)) {\r
return 0;\r