2 This is the main routine for initializing the Graphics Console support routines.
4 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "GraphicsConsole.h"
18 Gets Graphics Console devcie's foreground color and background color.
20 @param This Protocol instance pointer.
21 @param Foreground Returned text foreground color.
22 @param Background Returned text background color.
24 @retval EFI_SUCCESS It returned always.
29 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
30 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
31 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
35 Draw Unicode string on the Graphice Console device's screen.
37 @param This Protocol instance pointer.
38 @param UnicodeWeight One Unicode string to be displayed.
39 @param Count The count of Unicode string.
41 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
42 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
44 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
48 DrawUnicodeWeightAtCursorN (
49 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
50 IN CHAR16
*UnicodeWeight
,
55 Erase the cursor on the screen.
57 @param This Protocol instance pointer.
59 @retval EFI_SUCCESS The cursor is erased successfully.
64 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
68 Check if the current specific mode supported the user defined resolution
69 for the Graphice Console devcie based on Graphics Output Protocol.
71 If yes, set the graphic devcice's current mode to this specific mode.
73 @param GraphicsOutput Graphics Output Protocol instance pointer.
74 @param HorizontalResolution User defined horizontal resolution
75 @param VerticalResolution User defined vertical resolution.
76 @param CurrentModeNumber Current specific mode to be check.
78 @retval EFI_SUCCESS The mode is supported.
79 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
81 @retval other The specific mode does not support user defined
82 resolution or failed to set the current mode to the
83 specific mode on graphics device.
88 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
89 IN UINT32 HorizontalResolution
,
90 IN UINT32 VerticalResolution
,
91 OUT UINT32
*CurrentModeNumber
95 // Graphics Console Devcie Private Data template
97 STATIC GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate
= {
98 GRAPHICS_CONSOLE_DEV_SIGNATURE
,
99 (EFI_GRAPHICS_OUTPUT_PROTOCOL
*) NULL
,
100 (EFI_UGA_DRAW_PROTOCOL
*) NULL
,
102 GraphicsConsoleConOutReset
,
103 GraphicsConsoleConOutOutputString
,
104 GraphicsConsoleConOutTestString
,
105 GraphicsConsoleConOutQueryMode
,
106 GraphicsConsoleConOutSetMode
,
107 GraphicsConsoleConOutSetAttribute
,
108 GraphicsConsoleConOutClearScreen
,
109 GraphicsConsoleConOutSetCursorPosition
,
110 GraphicsConsoleConOutEnableCursor
,
111 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
116 EFI_TEXT_ATTR(EFI_LIGHTGRAY
, EFI_BLACK
),
122 { 80, 25, 0, 0, 0, 0 }, // Mode 0
123 { 80, 50, 0, 0, 0, 0 }, // Mode 1
124 { 100,31, 0, 0, 0, 0 }, // Mode 2
125 { 0, 0, 0, 0, 0, 0 } // Mode 3
127 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
,
131 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
132 EFI_HII_FONT_PROTOCOL
*mHiiFont
;
133 BOOLEAN mFirstAccessFlag
= TRUE
;
135 STATIC EFI_GUID mFontPackageListGuid
= {0xf5f219d3, 0x7006, 0x4648, 0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad};
137 STATIC CHAR16 mCrLfString
[3] = { CHAR_CARRIAGE_RETURN
, CHAR_LINEFEED
, CHAR_NULL
};
139 STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors
[16] = {
143 {0x00, 0x00, 0x00, 0x00}, // BLACK
144 {0x98, 0x00, 0x00, 0x00}, // BLUE
145 {0x00, 0x98, 0x00, 0x00}, // GREEN
146 {0x98, 0x98, 0x00, 0x00}, // CYAN
147 {0x00, 0x00, 0x98, 0x00}, // RED
148 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
149 {0x00, 0x98, 0x98, 0x00}, // BROWN
150 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
151 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
152 {0xff, 0x00, 0x00, 0x00}, // LIGHTBLUE - ?
153 {0x00, 0xff, 0x00, 0x00}, // LIGHTGREEN - ?
154 {0xff, 0xff, 0x00, 0x00}, // LIGHTCYAN
155 {0x00, 0x00, 0xff, 0x00}, // LIGHTRED
156 {0xff, 0x00, 0xff, 0x00}, // LIGHTMAGENTA
157 {0x00, 0xff, 0xff, 0x00}, // LIGHTBROWN
158 {0xff, 0xff, 0xff, 0x00} // WHITE
161 STATIC EFI_NARROW_GLYPH mCursorGlyph
= {
164 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }
167 STATIC CHAR16 SpaceStr
[] = { NARROW_CHAR
, ' ', 0 };
169 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding
= {
170 GraphicsConsoleControllerDriverSupported
,
171 GraphicsConsoleControllerDriverStart
,
172 GraphicsConsoleControllerDriverStop
,
180 Test to see if Graphics Console could be supported on the Controller.
182 Graphics Console could be supported if Graphics Output Protocol or UGA Draw
183 Protocol exists on the Controller. (UGA Draw Protocol could be skipped
184 if PcdUgaConsumeSupport is set to FALSE.)
186 @param This Protocol instance pointer.
187 @param Controller Handle of device to test.
188 @param RemainingDevicePath Optional parameter use to pick a specific child
191 @retval EFI_SUCCESS This driver supports this device.
192 @retval other This driver does not support this device.
197 GraphicsConsoleControllerDriverSupported (
198 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
199 IN EFI_HANDLE Controller
,
200 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
204 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
205 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
206 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
208 GraphicsOutput
= NULL
;
211 // Open the IO Abstraction(s) needed to perform the supported test
213 Status
= gBS
->OpenProtocol (
215 &gEfiGraphicsOutputProtocolGuid
,
216 (VOID
**) &GraphicsOutput
,
217 This
->DriverBindingHandle
,
219 EFI_OPEN_PROTOCOL_BY_DRIVER
222 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
224 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
226 Status
= gBS
->OpenProtocol (
228 &gEfiUgaDrawProtocolGuid
,
230 This
->DriverBindingHandle
,
232 EFI_OPEN_PROTOCOL_BY_DRIVER
235 if (EFI_ERROR (Status
)) {
240 // We need to ensure that we do not layer on top of a virtual handle.
241 // We need to ensure that the handles produced by the conspliter do not
244 Status
= gBS
->OpenProtocol (
246 &gEfiDevicePathProtocolGuid
,
247 (VOID
**) &DevicePath
,
248 This
->DriverBindingHandle
,
250 EFI_OPEN_PROTOCOL_BY_DRIVER
252 if (!EFI_ERROR (Status
)) {
255 &gEfiDevicePathProtocolGuid
,
256 This
->DriverBindingHandle
,
264 // Does Hii Exist? If not, we aren't ready to run
266 Status
= EfiLocateHiiProtocol ();
269 // Close the I/O Abstraction(s) used to perform the supported test
272 if (GraphicsOutput
!= NULL
) {
275 &gEfiGraphicsOutputProtocolGuid
,
276 This
->DriverBindingHandle
,
279 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
282 &gEfiUgaDrawProtocolGuid
,
283 This
->DriverBindingHandle
,
292 Start this driver on Controller by opening Graphics Output protocol or
293 UGA Draw protocol, and installing Simple Text Out protocol on Controller.
294 (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)
296 @param This Protocol instance pointer.
297 @param Controller Handle of device to bind driver to
298 @param RemainingDevicePath Optional parameter use to pick a specific child
301 @retval EFI_SUCCESS This driver is added to Controller.
302 @retval other This driver does not support this device.
307 GraphicsConsoleControllerDriverStart (
308 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
309 IN EFI_HANDLE Controller
,
310 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
314 GRAPHICS_CONSOLE_DEV
*Private
;
315 UINTN NarrowFontSize
;
316 UINT32 HorizontalResolution
;
317 UINT32 VerticalResolution
;
324 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
326 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
333 // Initialize the Graphics Console device instance
335 Private
= AllocateCopyPool (
336 sizeof (GRAPHICS_CONSOLE_DEV
),
337 &mGraphicsConsoleDevTemplate
339 if (Private
== NULL
) {
340 return EFI_OUT_OF_RESOURCES
;
343 Private
->SimpleTextOutput
.Mode
= &(Private
->SimpleTextOutputMode
);
345 Status
= gBS
->OpenProtocol (
347 &gEfiGraphicsOutputProtocolGuid
,
348 (VOID
**) &Private
->GraphicsOutput
,
349 This
->DriverBindingHandle
,
351 EFI_OPEN_PROTOCOL_BY_DRIVER
354 if (EFI_ERROR(Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
355 Status
= gBS
->OpenProtocol (
357 &gEfiUgaDrawProtocolGuid
,
358 (VOID
**) &Private
->UgaDraw
,
359 This
->DriverBindingHandle
,
361 EFI_OPEN_PROTOCOL_BY_DRIVER
365 if (EFI_ERROR (Status
)) {
369 NarrowFontSize
= ReturnNarrowFontSize ();
371 if (mFirstAccessFlag
) {
373 // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only.
374 // Looks ugly. Might be updated when font tool is ready.
376 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + NarrowFontSize
+ 4;
377 Package
= AllocateZeroPool (PackageLength
);
378 if (Package
== NULL
) {
379 return EFI_OUT_OF_RESOURCES
;
381 CopyMem (Package
, &PackageLength
, 4);
382 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
383 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
384 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
385 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (NarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
387 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
388 CopyMem (Location
, gUsStdNarrowGlyphData
, NarrowFontSize
);
391 // Add this simplified font package to a package list then install it.
393 PackageList
= HiiLibPreparePackageList (1, &mFontPackageListGuid
, Package
);
394 Status
= mHiiDatabase
->NewPackageList (mHiiDatabase
, PackageList
, NULL
, &(Private
->HiiHandle
));
395 ASSERT_EFI_ERROR (Status
);
396 SafeFreePool (PackageList
);
397 SafeFreePool (Package
);
399 mFirstAccessFlag
= FALSE
;
402 // If the current mode information can not be retrieved, then attemp to set the default mode
403 // of 800x600, 32 bit colot, 60 Hz refresh.
405 HorizontalResolution
= 800;
406 VerticalResolution
= 600;
408 if (Private
->GraphicsOutput
!= NULL
) {
410 // The console is build on top of Graphics Output Protocol, find the mode number
411 // for the user-defined mode; if there are multiple video devices,
412 // graphic console driver will set all the video devices to the same mode.
414 Status
= CheckModeSupported (
415 Private
->GraphicsOutput
,
416 CURRENT_HORIZONTAL_RESOLUTION
,
417 CURRENT_VERTICAL_RESOLUTION
,
420 if (!EFI_ERROR(Status
)) {
422 // Update default mode to current mode
424 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
425 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
428 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
430 Status
= CheckModeSupported (
431 Private
->GraphicsOutput
,
438 if (EFI_ERROR (Status
) || (ModeNumber
== Private
->GraphicsOutput
->Mode
->MaxMode
)) {
440 // Set default mode failed or device don't support default mode, then get the current mode information
442 HorizontalResolution
= Private
->GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
443 VerticalResolution
= Private
->GraphicsOutput
->Mode
->Info
->VerticalResolution
;
444 ModeNumber
= Private
->GraphicsOutput
->Mode
->Mode
;
446 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
448 // At first try to set user-defined resolution
452 Status
= Private
->UgaDraw
->SetMode (
454 CURRENT_HORIZONTAL_RESOLUTION
,
455 CURRENT_VERTICAL_RESOLUTION
,
459 if (!EFI_ERROR (Status
)) {
460 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
461 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
462 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
464 // Try to set 800*600 which is required by UEFI/EFI spec
466 Status
= Private
->UgaDraw
->SetMode (
468 HorizontalResolution
,
473 if (EFI_ERROR (Status
)) {
474 Status
= Private
->UgaDraw
->GetMode (
476 &HorizontalResolution
,
481 if (EFI_ERROR (Status
)) {
486 Status
= EFI_UNSUPPORTED
;
492 // Compute the maximum number of text Rows and Columns that this current graphics mode can support
494 Columns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
495 Rows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
498 // See if the mode is too small to support the required 80x25 text mode
500 if (Columns
< 80 || Rows
< 25) {
504 // Add Mode #0 that must be 80x25
507 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
508 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
509 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
510 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
511 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (25 * EFI_GLYPH_HEIGHT
)) >> 1;
515 // If it is possible to support Mode #1 - 80x50, than add it as an active mode
518 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
519 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
520 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
521 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
522 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (50 * EFI_GLYPH_HEIGHT
)) >> 1;
527 // If it is not to support Mode #1 - 80x50, then skip it
530 Private
->ModeData
[MaxMode
].Columns
= 0;
531 Private
->ModeData
[MaxMode
].Rows
= 0;
532 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
533 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
534 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
535 Private
->ModeData
[MaxMode
].DeltaX
= 0;
536 Private
->ModeData
[MaxMode
].DeltaY
= 0;
541 // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)
543 if (Columns
>= 100 && Rows
>= 31) {
544 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
545 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
546 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
547 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (100 * EFI_GLYPH_WIDTH
)) >> 1;
548 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (31 * EFI_GLYPH_HEIGHT
)) >> 1;
553 // Add Mode #3 that uses the entire display for user-defined mode
555 if (HorizontalResolution
> 800 && VerticalResolution
> 600) {
556 Private
->ModeData
[MaxMode
].Columns
= HorizontalResolution
/EFI_GLYPH_WIDTH
;
557 Private
->ModeData
[MaxMode
].Rows
= VerticalResolution
/EFI_GLYPH_HEIGHT
;
558 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
559 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
560 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
561 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
% EFI_GLYPH_WIDTH
) >> 1;
562 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
% EFI_GLYPH_HEIGHT
) >> 1;
567 // Update the maximum number of modes
569 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
572 // Determine the number of text modes that this protocol can support
574 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
575 if (EFI_ERROR (Status
)) {
580 GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
584 // Install protocol interfaces for the Graphics Console device.
586 Status
= gBS
->InstallMultipleProtocolInterfaces (
588 &gEfiSimpleTextOutProtocolGuid
,
589 &Private
->SimpleTextOutput
,
594 if (EFI_ERROR (Status
)) {
596 // Close the GOP and UGA Draw Protocol
598 if (Private
->GraphicsOutput
!= NULL
) {
601 &gEfiGraphicsOutputProtocolGuid
,
602 This
->DriverBindingHandle
,
605 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
608 &gEfiUgaDrawProtocolGuid
,
609 This
->DriverBindingHandle
,
617 if (Private
!= NULL
) {
618 if (Private
->LineBuffer
!= NULL
) {
619 FreePool (Private
->LineBuffer
);
629 Stop this driver on Controller by removing Simple Text Out protocol
630 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
631 (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)
634 @param This Protocol instance pointer.
635 @param Controller Handle of device to stop driver on
636 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
637 children is zero stop the entire bus driver.
638 @param ChildHandleBuffer List of Child Handles to Stop.
640 @retval EFI_SUCCESS This driver is removed Controller.
641 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
643 @retval other This driver was not removed from this device.
648 GraphicsConsoleControllerDriverStop (
649 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
650 IN EFI_HANDLE Controller
,
651 IN UINTN NumberOfChildren
,
652 IN EFI_HANDLE
*ChildHandleBuffer
656 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
657 GRAPHICS_CONSOLE_DEV
*Private
;
659 Status
= gBS
->OpenProtocol (
661 &gEfiSimpleTextOutProtocolGuid
,
662 (VOID
**) &SimpleTextOutput
,
663 This
->DriverBindingHandle
,
665 EFI_OPEN_PROTOCOL_GET_PROTOCOL
667 if (EFI_ERROR (Status
)) {
668 return EFI_NOT_STARTED
;
671 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
673 Status
= gBS
->UninstallProtocolInterface (
675 &gEfiSimpleTextOutProtocolGuid
,
676 &Private
->SimpleTextOutput
679 if (!EFI_ERROR (Status
)) {
681 // Close the GOP or UGA IO Protocol
683 if (Private
->GraphicsOutput
!= NULL
) {
686 &gEfiGraphicsOutputProtocolGuid
,
687 This
->DriverBindingHandle
,
690 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
693 &gEfiUgaDrawProtocolGuid
,
694 This
->DriverBindingHandle
,
700 // Remove the font pack
702 if (Private
->HiiHandle
!= NULL
) {
703 HiiLibRemovePackages (Private
->HiiHandle
);
704 mFirstAccessFlag
= TRUE
;
708 // Free our instance data
710 if (Private
!= NULL
) {
711 FreePool (Private
->LineBuffer
);
720 Check if the current specific mode supported the user defined resolution
721 for the Graphice Console devcie based on Graphics Output Protocol.
723 If yes, set the graphic devcice's current mode to this specific mode.
725 @param GraphicsOutput Graphics Output Protocol instance pointer.
726 @param HorizontalResolution User defined horizontal resolution
727 @param VerticalResolution User defined vertical resolution.
728 @param CurrentModeNumber Current specific mode to be check.
730 @retval EFI_SUCCESS The mode is supported.
731 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
733 @retval other The specific mode does not support user defined
734 resolution or failed to set the current mode to the
735 specific mode on graphics device.
740 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
741 IN UINT32 HorizontalResolution
,
742 IN UINT32 VerticalResolution
,
743 OUT UINT32
*CurrentModeNumber
749 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
751 Status
= EFI_SUCCESS
;
753 for (ModeNumber
= 0; ModeNumber
< GraphicsOutput
->Mode
->MaxMode
; ModeNumber
++) {
754 Status
= GraphicsOutput
->QueryMode (
760 if (!EFI_ERROR (Status
)) {
761 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
762 (Info
->VerticalResolution
== VerticalResolution
)) {
763 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
764 if (!EFI_ERROR (Status
)) {
765 gBS
->FreePool (Info
);
769 gBS
->FreePool (Info
);
773 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
774 Status
= EFI_UNSUPPORTED
;
777 *CurrentModeNumber
= ModeNumber
;
783 Locate HII Database protocol and HII Font protocol.
785 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
786 are located successfully.
787 @return other Failed to locate HII Database protocol or
792 EfiLocateHiiProtocol (
801 // There should only be one - so buffer size is this
803 Size
= sizeof (EFI_HANDLE
);
805 Status
= gBS
->LocateHandle (
807 &gEfiHiiDatabaseProtocolGuid
,
813 if (EFI_ERROR (Status
)) {
817 Status
= gBS
->HandleProtocol (
819 &gEfiHiiDatabaseProtocolGuid
,
820 (VOID
**) &mHiiDatabase
823 if (EFI_ERROR (Status
)) {
827 Status
= gBS
->HandleProtocol (
829 &gEfiHiiFontProtocolGuid
,
836 // Body of the STO functions
840 Reset the text output device hardware and optionaly run diagnostics.
842 Implements SIMPLE_TEXT_OUTPUT.Reset().
843 If ExtendeVerification is TRUE, then perform dependent Graphics Console
844 device reset, and set display mode to mode 0.
845 If ExtendedVerification is FALSE, only set display mode to mode 0.
847 @param This Protocol instance pointer.
848 @param ExtendedVerification Indicates that the driver may perform a more
849 exhaustive verification operation of the device
852 @retval EFI_SUCCESS The text output device was reset.
853 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
859 GraphicsConsoleConOutReset (
860 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
861 IN BOOLEAN ExtendedVerification
864 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
865 return This
->SetMode (This
, 0);
870 Write a Unicode string to the output device.
872 Implements SIMPLE_TEXT_OUTPUT.OutputString().
873 The Unicode string will be converted to Glyphs and will be
874 sent to the Graphics Console.
876 @param This Protocol instance pointer.
877 @param WString The NULL-terminated Unicode string to be displayed
878 on the output device(s). All output devices must
879 also support the Unicode drawing defined in this file.
881 @retval EFI_SUCCESS The string was output to the device.
882 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
884 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
886 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
887 characters in the Unicode string could not be
888 rendered and were skipped.
893 GraphicsConsoleConOutOutputString (
894 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
898 GRAPHICS_CONSOLE_DEV
*Private
;
899 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
900 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
909 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
910 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
915 INT32 OriginAttribute
;
918 Status
= EFI_SUCCESS
;
920 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
924 Mode
= This
->Mode
->Mode
;
925 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
926 GraphicsOutput
= Private
->GraphicsOutput
;
927 UgaDraw
= Private
->UgaDraw
;
929 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
930 MaxRow
= Private
->ModeData
[Mode
].Rows
;
931 DeltaX
= Private
->ModeData
[Mode
].DeltaX
;
932 DeltaY
= Private
->ModeData
[Mode
].DeltaY
;
933 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
934 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
935 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
938 // The Attributes won't change when during the time OutputString is called
940 GetTextColors (This
, &Foreground
, &Background
);
949 OriginAttribute
= This
->Mode
->Attribute
;
951 while (*WString
!= L
'\0') {
953 if (*WString
== CHAR_BACKSPACE
) {
955 // If the cursor is at the left edge of the display, then move the cursor
958 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
959 This
->Mode
->CursorRow
--;
960 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
961 This
->OutputString (This
, SpaceStr
);
963 This
->Mode
->CursorRow
--;
964 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
965 } else if (This
->Mode
->CursorColumn
> 0) {
967 // If the cursor is not at the left edge of the display, then move the cursor
970 This
->Mode
->CursorColumn
--;
971 This
->OutputString (This
, SpaceStr
);
973 This
->Mode
->CursorColumn
--;
978 } else if (*WString
== CHAR_LINEFEED
) {
980 // If the cursor is at the bottom of the display, then scroll the display one
981 // row, and do not update the cursor position. Otherwise, move the cursor
984 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
985 if (GraphicsOutput
!= NULL
) {
987 // Scroll Screen Up One Row
989 GraphicsOutput
->Blt (
994 DeltaY
+ EFI_GLYPH_HEIGHT
,
1003 // Print Blank Line at last line
1005 GraphicsOutput
->Blt (
1017 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1019 // Scroll Screen Up One Row
1026 DeltaY
+ EFI_GLYPH_HEIGHT
,
1035 // Print Blank Line at last line
1039 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1051 This
->Mode
->CursorRow
++;
1056 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1058 // Move the cursor to the beginning of the current row.
1060 This
->Mode
->CursorColumn
= 0;
1063 } else if (*WString
== WIDE_CHAR
) {
1065 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1068 } else if (*WString
== NARROW_CHAR
) {
1070 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1075 // Print the character at the current cursor position and move the cursor
1076 // right one column. If this moves the cursor past the right edge of the
1077 // display, then the line should wrap to the beginning of the next line. This
1078 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1079 // bottom of the display, and the line wraps, then the display will be scrolled
1081 // If wide char is going to be displayed, need to display one character at a time
1082 // Or, need to know the display length of a certain string.
1084 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1085 // Count is used to determine how many characters are used regardless of their attributes
1087 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1088 if (WString
[Count
] == CHAR_NULL
) {
1092 if (WString
[Count
] == CHAR_BACKSPACE
) {
1096 if (WString
[Count
] == CHAR_LINEFEED
) {
1100 if (WString
[Count
] == CHAR_CARRIAGE_RETURN
) {
1104 if (WString
[Count
] == WIDE_CHAR
) {
1108 if (WString
[Count
] == NARROW_CHAR
) {
1112 // Is the wide attribute on?
1114 if (This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) {
1116 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1120 // This is the end-case where if we are at column 79 and about to print a wide character
1121 // We should prevent this from happening because we will wrap inappropriately. We should
1122 // not print this character until the next line.
1124 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1131 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1132 if (EFI_ERROR (Status
)) {
1136 // At the end of line, output carriage return and line feed
1139 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1140 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1141 This
->Mode
->CursorColumn
-= 2;
1142 This
->OutputString (This
, SpaceStr
);
1145 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1147 This
->OutputString (This
, mCrLfString
);
1153 This
->Mode
->Attribute
= OriginAttribute
;
1158 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1161 gBS
->RestoreTPL (OldTpl
);
1167 Verifies that all characters in a Unicode string can be output to the
1170 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1171 If one of the characters in the *Wstring is neither valid valid Unicode
1172 drawing characters, not ASCII code, then this function will return
1175 @param This Protocol instance pointer.
1176 @param WString The NULL-terminated Unicode string to be examined for the output
1179 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1180 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1181 rendered by one or more of the output devices mapped
1187 GraphicsConsoleConOutTestString (
1188 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1195 EFI_IMAGE_OUTPUT
*Blt
;
1200 while (WString
[Count
] != 0) {
1201 Status
= mHiiFont
->GetGlyph (
1212 if (EFI_ERROR (Status
)) {
1213 return EFI_UNSUPPORTED
;
1222 Returns information for an available text mode that the output device(s)
1225 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1226 It returnes information for an available text mode that the Graphics Console supports.
1227 In this driver,we only support text mode 80x25, which is defined as mode 0.
1229 @param This Protocol instance pointer.
1230 @param ModeNumber The mode number to return information on.
1231 @param Columns The returned columns of the requested mode.
1232 @param Rows The returned rows of the requested mode.
1234 @retval EFI_SUCCESS The requested mode information is returned.
1235 @retval EFI_UNSUPPORTED The mode number is not valid.
1240 GraphicsConsoleConOutQueryMode (
1241 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1242 IN UINTN ModeNumber
,
1247 GRAPHICS_CONSOLE_DEV
*Private
;
1251 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1252 return EFI_UNSUPPORTED
;
1255 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1256 Status
= EFI_SUCCESS
;
1258 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1260 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1261 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1263 if (*Columns
<= 0 && *Rows
<= 0) {
1264 Status
= EFI_UNSUPPORTED
;
1270 gBS
->RestoreTPL (OldTpl
);
1276 Sets the output device(s) to a specified mode.
1278 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1279 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1281 @param This Protocol instance pointer.
1282 @param ModeNumber The text mode to set.
1284 @retval EFI_SUCCESS The requested text mode is set.
1285 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1286 Graphics Console device error.
1287 @retval EFI_UNSUPPORTED The text mode number is not valid.
1292 GraphicsConsoleConOutSetMode (
1293 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1298 GRAPHICS_CONSOLE_DEV
*Private
;
1299 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1300 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1301 UINT32 HorizontalResolution
;
1302 UINT32 VerticalResolution
;
1303 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1304 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1309 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1311 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1312 GraphicsOutput
= Private
->GraphicsOutput
;
1313 UgaDraw
= Private
->UgaDraw
;
1314 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1316 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1317 Status
= EFI_UNSUPPORTED
;
1322 // Make sure the requested mode number is supported
1324 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1325 Status
= EFI_UNSUPPORTED
;
1329 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1330 Status
= EFI_UNSUPPORTED
;
1334 // Attempt to allocate a line buffer for the requested mode number
1336 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1338 if (NewLineBuffer
== NULL
) {
1340 // The new line buffer could not be allocated, so return an error.
1341 // No changes to the state of the current console have been made, so the current console is still valid
1343 Status
= EFI_OUT_OF_RESOURCES
;
1347 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1349 if (Private
->LineBuffer
!= NULL
) {
1351 // Clear the current text window on the current graphics console
1353 This
->ClearScreen (This
);
1356 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1358 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1359 FreePool (NewLineBuffer
);
1360 Status
= EFI_SUCCESS
;
1364 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1365 // so erase the cursor, and free the LineBuffer for the current mode
1369 FreePool (Private
->LineBuffer
);
1372 // Assign the current line buffer to the newly allocated line buffer
1374 Private
->LineBuffer
= NewLineBuffer
;
1376 if (GraphicsOutput
!= NULL
) {
1377 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1379 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode
1381 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1382 if (EFI_ERROR (Status
)) {
1384 // The mode set operation failed
1390 // The current graphics mode is correct, so simply clear the entire display
1392 Status
= GraphicsOutput
->Blt (
1401 ModeData
->GopHeight
,
1405 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1407 // Get the current UGA Draw mode information
1409 Status
= UgaDraw
->GetMode (
1411 &HorizontalResolution
,
1412 &VerticalResolution
,
1416 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1418 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode
1420 Status
= UgaDraw
->SetMode (
1423 ModeData
->GopHeight
,
1427 if (EFI_ERROR (Status
)) {
1429 // The mode set operation failed
1435 // The current graphics mode is correct, so simply clear the entire display
1437 Status
= UgaDraw
->Blt (
1439 (EFI_UGA_PIXEL
*) (UINTN
) &mEfiColors
[0],
1446 ModeData
->GopHeight
,
1453 // The new mode is valid, so commit the mode change
1455 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1458 // Move the text cursor to the upper left hand corner of the displat and enable it
1460 This
->SetCursorPosition (This
, 0, 0);
1462 Status
= EFI_SUCCESS
;
1465 gBS
->RestoreTPL (OldTpl
);
1471 Sets the background and foreground colors for the OutputString () and
1472 ClearScreen () functions.
1474 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1476 @param This Protocol instance pointer.
1477 @param Attribute The attribute to set. Bits 0..3 are the foreground
1478 color, and bits 4..6 are the background color.
1479 All other bits are undefined and must be zero.
1481 @retval EFI_SUCCESS The requested attribute is set.
1482 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1483 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1488 GraphicsConsoleConOutSetAttribute (
1489 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1495 if ((Attribute
| 0xFF) != 0xFF) {
1496 return EFI_UNSUPPORTED
;
1499 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1503 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1507 This
->Mode
->Attribute
= (INT32
) Attribute
;
1511 gBS
->RestoreTPL (OldTpl
);
1518 Clears the output device(s) display to the currently selected background
1521 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1523 @param This Protocol instance pointer.
1525 @retval EFI_SUCCESS The operation completed successfully.
1526 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1527 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1532 GraphicsConsoleConOutClearScreen (
1533 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1537 GRAPHICS_CONSOLE_DEV
*Private
;
1538 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1539 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1540 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1541 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1542 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1545 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1547 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1548 GraphicsOutput
= Private
->GraphicsOutput
;
1549 UgaDraw
= Private
->UgaDraw
;
1550 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1552 GetTextColors (This
, &Foreground
, &Background
);
1553 if (GraphicsOutput
!= NULL
) {
1554 Status
= GraphicsOutput
->Blt (
1563 ModeData
->GopHeight
,
1566 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1567 Status
= UgaDraw
->Blt (
1569 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1576 ModeData
->GopHeight
,
1580 Status
= EFI_UNSUPPORTED
;
1583 This
->Mode
->CursorColumn
= 0;
1584 This
->Mode
->CursorRow
= 0;
1588 gBS
->RestoreTPL (OldTpl
);
1595 Sets the current coordinates of the cursor position.
1597 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1599 @param This Protocol instance pointer.
1600 @param Column The position to set the cursor to. Must be greater than or
1601 equal to zero and less than the number of columns and rows
1603 @param Row The position to set the cursor to. Must be greater than or
1604 equal to zero and less than the number of columns and rows
1607 @retval EFI_SUCCESS The operation completed successfully.
1608 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1609 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1610 cursor position is invalid for the current mode.
1615 GraphicsConsoleConOutSetCursorPosition (
1616 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1621 GRAPHICS_CONSOLE_DEV
*Private
;
1622 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1626 Status
= EFI_SUCCESS
;
1628 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1630 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1631 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1633 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1634 Status
= EFI_UNSUPPORTED
;
1638 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1639 Status
= EFI_SUCCESS
;
1645 This
->Mode
->CursorColumn
= (INT32
) Column
;
1646 This
->Mode
->CursorRow
= (INT32
) Row
;
1651 gBS
->RestoreTPL (OldTpl
);
1658 Makes the cursor visible or invisible.
1660 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1662 @param This Protocol instance pointer.
1663 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1664 the cursor is set to be invisible.
1666 @retval EFI_SUCCESS The operation completed successfully.
1671 GraphicsConsoleConOutEnableCursor (
1672 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1678 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1682 This
->Mode
->CursorVisible
= Visible
;
1686 gBS
->RestoreTPL (OldTpl
);
1691 Gets Graphics Console devcie's foreground color and background color.
1693 @param This Protocol instance pointer.
1694 @param Foreground Returned text foreground color.
1695 @param Background Returned text background color.
1697 @retval EFI_SUCCESS It returned always.
1702 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1703 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1704 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1709 Attribute
= This
->Mode
->Attribute
& 0x7F;
1711 *Foreground
= mEfiColors
[Attribute
& 0x0f];
1712 *Background
= mEfiColors
[Attribute
>> 4];
1718 Draw Unicode string on the Graphice Console device's screen.
1720 @param This Protocol instance pointer.
1721 @param UnicodeWeight One Unicode string to be displayed.
1722 @param Count The count of Unicode string.
1724 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1725 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1727 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1731 DrawUnicodeWeightAtCursorN (
1732 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1733 IN CHAR16
*UnicodeWeight
,
1738 GRAPHICS_CONSOLE_DEV
*Private
;
1739 EFI_IMAGE_OUTPUT
*Blt
;
1741 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1742 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1743 EFI_HII_ROW_INFO
*RowInfoArray
;
1744 UINTN RowInfoArraySize
;
1746 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1747 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1749 return EFI_OUT_OF_RESOURCES
;
1752 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1753 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1755 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1756 if (String
== NULL
) {
1758 return EFI_OUT_OF_RESOURCES
;
1761 // Set the end character
1763 *(String
+ Count
) = L
'\0';
1765 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1766 if (FontInfo
== NULL
) {
1768 SafeFreePool (String
);
1769 return EFI_OUT_OF_RESOURCES
;
1772 // Get current foreground and background colors.
1774 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1776 if (Private
->GraphicsOutput
!= NULL
) {
1778 // If Graphcis Output protocol exists, using HII Font protocol to draw.
1780 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1782 Status
= mHiiFont
->StringToImage (
1784 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
,
1788 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1789 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1795 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1797 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1798 // using UGA Draw protocol to draw.
1800 ASSERT (Private
->UgaDraw
!= NULL
);
1802 UgaDraw
= Private
->UgaDraw
;
1804 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1805 if (Blt
->Image
.Bitmap
== NULL
) {
1807 SafeFreePool (String
);
1808 return EFI_OUT_OF_RESOURCES
;
1811 RowInfoArray
= NULL
;
1813 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1814 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1816 Status
= mHiiFont
->StringToImage (
1818 EFI_HII_IGNORE_IF_NO_GLYPH
,
1822 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1823 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1829 if (!EFI_ERROR (Status
)) {
1831 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1832 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1834 ASSERT (RowInfoArraySize
<= 1);
1836 Status
= UgaDraw
->Blt (
1838 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1839 EfiUgaBltBufferToVideo
,
1840 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1841 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1842 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1843 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1844 RowInfoArray
[0].LineWidth
,
1845 RowInfoArray
[0].LineHeight
,
1846 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1850 SafeFreePool (RowInfoArray
);
1851 SafeFreePool (Blt
->Image
.Bitmap
);
1853 Status
= EFI_UNSUPPORTED
;
1857 SafeFreePool (String
);
1858 SafeFreePool (FontInfo
);
1863 Erase the cursor on the screen.
1865 @param This Protocol instance pointer.
1867 @retval EFI_SUCCESS The cursor is erased successfully.
1872 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1875 GRAPHICS_CONSOLE_DEV
*Private
;
1876 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1879 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1880 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1881 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1882 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1883 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1887 CurrentMode
= This
->Mode
;
1889 if (!CurrentMode
->CursorVisible
) {
1893 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1894 GraphicsOutput
= Private
->GraphicsOutput
;
1895 UgaDraw
= Private
->UgaDraw
;
1898 // In this driver, only narrow character was supported.
1901 // Blt a character to the screen
1903 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1904 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1905 if (GraphicsOutput
!= NULL
) {
1906 GraphicsOutput
->Blt (
1908 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1909 EfiBltVideoToBltBuffer
,
1916 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1918 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1921 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1922 EfiUgaVideoToBltBuffer
,
1929 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1933 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1936 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1938 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1939 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1940 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (1 << PosX
)) != 0) {
1941 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1946 if (GraphicsOutput
!= NULL
) {
1947 GraphicsOutput
->Blt (
1949 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1950 EfiBltBufferToVideo
,
1957 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1959 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1962 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1963 EfiUgaBltBufferToVideo
,
1970 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1978 The user Entry Point for module GraphicsConsole. The user code starts with this function.
1980 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1981 @param[in] SystemTable A pointer to the EFI System Table.
1983 @retval EFI_SUCCESS The entry point is executed successfully.
1984 @retval other Some error occurs when executing this entry point.
1989 InitializeGraphicsConsole (
1990 IN EFI_HANDLE ImageHandle
,
1991 IN EFI_SYSTEM_TABLE
*SystemTable
1997 // Install driver model protocol(s).
1999 Status
= EfiLibInstallDriverBindingComponentName2 (
2002 &gGraphicsConsoleDriverBinding
,
2004 &gGraphicsConsoleComponentName
,
2005 &gGraphicsConsoleComponentName2
2007 ASSERT_EFI_ERROR (Status
);