2 This is the main routine for initializing the Graphics Console support routines.
4 Add all standard Glyphs from UEFI 2.0 Specification
5 Implement optimal automatic Mode creation algorithm
6 Solve palette issues for mixed graphics and text
7 When does this protocol reset the palette?
9 Copyright (c) 2006 - 2008 Intel Corporation. <BR>
10 All rights reserved. This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "GraphicsConsole.h"
23 Gets Graphics Console devcie's foreground color and background color.
25 @param This Protocol instance pointer.
26 @param Foreground Returned text foreground color.
27 @param Background Returned text background color.
29 @retval EFI_SUCCESS It returned always.
34 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
35 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
36 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
40 Draw Unicode string on the Graphice Console device's screen.
42 @param This Protocol instance pointer.
43 @param UnicodeWeight One Unicode string to be displayed.
44 @param Count The count of Unicode string.
46 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
47 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
49 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
53 DrawUnicodeWeightAtCursorN (
54 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
55 IN CHAR16
*UnicodeWeight
,
60 Erase the cursor on the screen.
62 @param This Protocol instance pointer.
64 @retval EFI_SUCCESS The cursor is erased successfully.
69 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
73 Check if the current specific mode supported the user defined resolution
74 for the Graphice Console devcie based on Graphics Output Protocol.
76 If yes, set the graphic devcice's current mode to this specific mode.
78 @param GraphicsOutput Graphics Output Protocol instance pointer.
79 @param HorizontalResolution User defined horizontal resolution
80 @param VerticalResolution User defined vertical resolution.
81 @param CurrentModeNumber Current specific mode to be check.
83 @retval EFI_SUCCESS This driver is removed ControllerHandle.
84 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
86 @retval other The specific mode does not support user defined
87 resolution or failed to set the current mode to the
88 specific mode on graphics device.
93 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
94 IN UINT32 HorizontalResolution
,
95 IN UINT32 VerticalResolution
,
96 OUT UINT32
*CurrentModeNumber
102 GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate
= {
103 GRAPHICS_CONSOLE_DEV_SIGNATURE
,
104 (EFI_GRAPHICS_OUTPUT_PROTOCOL
*) NULL
,
105 (EFI_UGA_DRAW_PROTOCOL
*) NULL
,
107 GraphicsConsoleConOutReset
,
108 GraphicsConsoleConOutOutputString
,
109 GraphicsConsoleConOutTestString
,
110 GraphicsConsoleConOutQueryMode
,
111 GraphicsConsoleConOutSetMode
,
112 GraphicsConsoleConOutSetAttribute
,
113 GraphicsConsoleConOutClearScreen
,
114 GraphicsConsoleConOutSetCursorPosition
,
115 GraphicsConsoleConOutEnableCursor
,
116 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
121 EFI_TEXT_ATTR(EFI_LIGHTGRAY
, EFI_BLACK
),
127 { 80, 25, 0, 0, 0, 0 }, // Mode 0
128 { 80, 50, 0, 0, 0, 0 }, // Mode 1
129 { 100,31, 0, 0, 0, 0 }, // Mode 2
130 { 0, 0, 0, 0, 0, 0 } // Mode 3
132 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
,
136 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
137 EFI_HII_FONT_PROTOCOL
*mHiiFont
;
138 BOOLEAN mFirstAccessFlag
= TRUE
;
140 STATIC EFI_GUID mFontPackageListGuid
= {0xf5f219d3, 0x7006, 0x4648, 0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad};
142 STATIC CHAR16 mCrLfString
[3] = { CHAR_CARRIAGE_RETURN
, CHAR_LINEFEED
, CHAR_NULL
};
144 STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors
[16] = {
148 {0x00, 0x00, 0x00, 0x00}, // BLACK
149 {0x98, 0x00, 0x00, 0x00}, // BLUE
150 {0x00, 0x98, 0x00, 0x00}, // GREEN
151 {0x98, 0x98, 0x00, 0x00}, // CYAN
152 {0x00, 0x00, 0x98, 0x00}, // RED
153 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
154 {0x00, 0x98, 0x98, 0x00}, // BROWN
155 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
156 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
157 {0xff, 0x00, 0x00, 0x00}, // LIGHTBLUE - ?
158 {0x00, 0xff, 0x00, 0x00}, // LIGHTGREEN - ?
159 {0xff, 0xff, 0x00, 0x00}, // LIGHTCYAN
160 {0x00, 0x00, 0xff, 0x00}, // LIGHTRED
161 {0xff, 0x00, 0xff, 0x00}, // LIGHTMAGENTA
162 {0x00, 0xff, 0xff, 0x00}, // LIGHTBROWN
163 {0xff, 0xff, 0xff, 0x00} // WHITE
166 STATIC EFI_NARROW_GLYPH mCursorGlyph
= {
169 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }
172 STATIC CHAR16 SpaceStr
[] = { NARROW_CHAR
, ' ', 0 };
174 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding
= {
175 GraphicsConsoleControllerDriverSupported
,
176 GraphicsConsoleControllerDriverStart
,
177 GraphicsConsoleControllerDriverStop
,
185 Test to see if Graphics Console could be supported on the ControllerHandle.
187 Graphics Console could be supported if Graphics Output Protocol or UGA Draw
188 Protocol exists on the ControllerHandle. (UGA Draw Protocol could be shipped
189 if PcdUgaConsumeSupport is set to FALSE.)
191 @param This Protocol instance pointer.
192 @param ControllerHandle Handle of device to test.
193 @param RemainingDevicePath Optional parameter use to pick a specific child
196 @retval EFI_SUCCESS This driver supports this device
197 @retval other This driver does not support this device
202 GraphicsConsoleControllerDriverSupported (
203 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
204 IN EFI_HANDLE Controller
,
205 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
209 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
210 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
211 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
213 GraphicsOutput
= NULL
;
216 // Open the IO Abstraction(s) needed to perform the supported test
218 Status
= gBS
->OpenProtocol (
220 &gEfiGraphicsOutputProtocolGuid
,
221 (VOID
**) &GraphicsOutput
,
222 This
->DriverBindingHandle
,
224 EFI_OPEN_PROTOCOL_BY_DRIVER
227 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
229 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
231 Status
= gBS
->OpenProtocol (
233 &gEfiUgaDrawProtocolGuid
,
235 This
->DriverBindingHandle
,
237 EFI_OPEN_PROTOCOL_BY_DRIVER
240 if (EFI_ERROR (Status
)) {
245 // We need to ensure that we do not layer on top of a virtual handle.
246 // We need to ensure that the handles produced by the conspliter do not
249 Status
= gBS
->OpenProtocol (
251 &gEfiDevicePathProtocolGuid
,
252 (VOID
**) &DevicePath
,
253 This
->DriverBindingHandle
,
255 EFI_OPEN_PROTOCOL_BY_DRIVER
257 if (!EFI_ERROR (Status
)) {
260 &gEfiDevicePathProtocolGuid
,
261 This
->DriverBindingHandle
,
269 // Does Hii Exist? If not, we aren't ready to run
271 Status
= EfiLocateHiiProtocol ();
274 // Close the I/O Abstraction(s) used to perform the supported test
277 if (GraphicsOutput
!= NULL
) {
280 &gEfiGraphicsOutputProtocolGuid
,
281 This
->DriverBindingHandle
,
284 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
287 &gEfiUgaDrawProtocolGuid
,
288 This
->DriverBindingHandle
,
297 Start this driver on ControllerHandle by opening Graphics Output protocol or
298 UGA Draw protocol, and installing Simple Text Out protocol on ControllerHandle.
299 (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)
301 @param This Protocol instance pointer.
302 @param ControllerHandle Handle of device to bind driver to
303 @param RemainingDevicePath Optional parameter use to pick a specific child
306 @retval EFI_SUCCESS This driver is added to ControllerHandle
307 @retval other This driver does not support this device
312 GraphicsConsoleControllerDriverStart (
313 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
314 IN EFI_HANDLE Controller
,
315 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
319 GRAPHICS_CONSOLE_DEV
*Private
;
320 UINTN NarrowFontSize
;
321 UINT32 HorizontalResolution
;
322 UINT32 VerticalResolution
;
329 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
331 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
338 // Initialize the Graphics Console device instance
340 Private
= AllocateCopyPool (
341 sizeof (GRAPHICS_CONSOLE_DEV
),
342 &mGraphicsConsoleDevTemplate
344 if (Private
== NULL
) {
345 return EFI_OUT_OF_RESOURCES
;
348 Private
->SimpleTextOutput
.Mode
= &(Private
->SimpleTextOutputMode
);
350 Status
= gBS
->OpenProtocol (
352 &gEfiGraphicsOutputProtocolGuid
,
353 (VOID
**) &Private
->GraphicsOutput
,
354 This
->DriverBindingHandle
,
356 EFI_OPEN_PROTOCOL_BY_DRIVER
359 if (EFI_ERROR(Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
360 Status
= gBS
->OpenProtocol (
362 &gEfiUgaDrawProtocolGuid
,
363 (VOID
**) &Private
->UgaDraw
,
364 This
->DriverBindingHandle
,
366 EFI_OPEN_PROTOCOL_BY_DRIVER
370 if (EFI_ERROR (Status
)) {
374 NarrowFontSize
= ReturnNarrowFontSize ();
376 if (mFirstAccessFlag
) {
378 // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only.
379 // Looks ugly. Might be updated when font tool is ready.
381 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + NarrowFontSize
+ 4;
382 Package
= AllocateZeroPool (PackageLength
);
383 if (Package
== NULL
) {
384 return EFI_OUT_OF_RESOURCES
;
386 CopyMem (Package
, &PackageLength
, 4);
387 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
388 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
389 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
390 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (NarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
392 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
393 CopyMem (Location
, UsStdNarrowGlyphData
, NarrowFontSize
);
396 // Add this simplified font package to a package list then install it.
398 PackageList
= HiiLibPreparePackageList (1, &mFontPackageListGuid
, Package
);
399 Status
= mHiiDatabase
->NewPackageList (mHiiDatabase
, PackageList
, NULL
, &(Private
->HiiHandle
));
400 ASSERT_EFI_ERROR (Status
);
401 SafeFreePool (PackageList
);
402 SafeFreePool (Package
);
404 mFirstAccessFlag
= FALSE
;
407 // If the current mode information can not be retrieved, then attemp to set the default mode
408 // of 800x600, 32 bit colot, 60 Hz refresh.
410 HorizontalResolution
= 800;
411 VerticalResolution
= 600;
413 if (Private
->GraphicsOutput
!= NULL
) {
415 // The console is build on top of Graphics Output Protocol, find the mode number
416 // for the user-defined mode; if there are multiple video devices,
417 // graphic console driver will set all the video devices to the same mode.
419 Status
= CheckModeSupported (
420 Private
->GraphicsOutput
,
421 CURRENT_HORIZONTAL_RESOLUTION
,
422 CURRENT_VERTICAL_RESOLUTION
,
425 if (!EFI_ERROR(Status
)) {
427 // Update default mode to current mode
429 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
430 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
433 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
435 Status
= CheckModeSupported (
436 Private
->GraphicsOutput
,
443 if (EFI_ERROR (Status
) || (ModeNumber
== Private
->GraphicsOutput
->Mode
->MaxMode
)) {
445 // Set default mode failed or device don't support default mode, then get the current mode information
447 HorizontalResolution
= Private
->GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
448 VerticalResolution
= Private
->GraphicsOutput
->Mode
->Info
->VerticalResolution
;
449 ModeNumber
= Private
->GraphicsOutput
->Mode
->Mode
;
451 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
453 // At first try to set user-defined resolution
457 Status
= Private
->UgaDraw
->SetMode (
459 CURRENT_HORIZONTAL_RESOLUTION
,
460 CURRENT_VERTICAL_RESOLUTION
,
464 if (!EFI_ERROR (Status
)) {
465 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
466 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
467 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
469 // Try to set 800*600 which is required by UEFI/EFI spec
471 Status
= Private
->UgaDraw
->SetMode (
473 HorizontalResolution
,
478 if (EFI_ERROR (Status
)) {
479 Status
= Private
->UgaDraw
->GetMode (
481 &HorizontalResolution
,
486 if (EFI_ERROR (Status
)) {
491 Status
= EFI_UNSUPPORTED
;
497 // Compute the maximum number of text Rows and Columns that this current graphics mode can support
499 Columns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
500 Rows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
503 // See if the mode is too small to support the required 80x25 text mode
505 if (Columns
< 80 || Rows
< 25) {
509 // Add Mode #0 that must be 80x25
512 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
513 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
514 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
515 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
516 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (25 * EFI_GLYPH_HEIGHT
)) >> 1;
520 // If it is possible to support Mode #1 - 80x50, than add it as an active mode
523 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
524 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
525 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
526 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
527 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (50 * EFI_GLYPH_HEIGHT
)) >> 1;
532 // If it is not to support Mode #1 - 80x50, then skip it
535 Private
->ModeData
[MaxMode
].Columns
= 0;
536 Private
->ModeData
[MaxMode
].Rows
= 0;
537 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
538 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
539 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
540 Private
->ModeData
[MaxMode
].DeltaX
= 0;
541 Private
->ModeData
[MaxMode
].DeltaY
= 0;
546 // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)
548 if (Columns
>= 100 && Rows
>= 31) {
549 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
550 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
551 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
552 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (100 * EFI_GLYPH_WIDTH
)) >> 1;
553 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (31 * EFI_GLYPH_HEIGHT
)) >> 1;
558 // Add Mode #3 that uses the entire display for user-defined mode
560 if (HorizontalResolution
> 800 && VerticalResolution
> 600) {
561 Private
->ModeData
[MaxMode
].Columns
= HorizontalResolution
/EFI_GLYPH_WIDTH
;
562 Private
->ModeData
[MaxMode
].Rows
= VerticalResolution
/EFI_GLYPH_HEIGHT
;
563 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
564 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
565 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
566 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
% EFI_GLYPH_WIDTH
) >> 1;
567 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
% EFI_GLYPH_HEIGHT
) >> 1;
572 // Update the maximum number of modes
574 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
577 // Determine the number of text modes that this protocol can support
579 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
580 if (EFI_ERROR (Status
)) {
585 GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
589 // Install protocol interfaces for the Graphics Console device.
591 Status
= gBS
->InstallMultipleProtocolInterfaces (
593 &gEfiSimpleTextOutProtocolGuid
,
594 &Private
->SimpleTextOutput
,
599 if (EFI_ERROR (Status
)) {
601 // Close the GOP or UGA IO Protocol
603 if (Private
->GraphicsOutput
!= NULL
) {
606 &gEfiGraphicsOutputProtocolGuid
,
607 This
->DriverBindingHandle
,
610 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
613 &gEfiUgaDrawProtocolGuid
,
614 This
->DriverBindingHandle
,
622 if (Private
!= NULL
) {
623 if (Private
->LineBuffer
!= NULL
) {
624 FreePool (Private
->LineBuffer
);
634 Stop this driver on ControllerHandle by removing Simple Text Out protocol
635 and closing the Graphics Output Protocol or UGA Draw protocol on ControllerHandle.
636 (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)
639 @param This Protocol instance pointer.
640 @param ControllerHandle Handle of device to stop driver on
641 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
642 children is zero stop the entire bus driver.
643 @param ChildHandleBuffer List of Child Handles to Stop.
645 @retval EFI_SUCCESS This driver is removed ControllerHandle.
646 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
648 @retval other This driver was not removed from this device.
653 GraphicsConsoleControllerDriverStop (
654 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
655 IN EFI_HANDLE Controller
,
656 IN UINTN NumberOfChildren
,
657 IN EFI_HANDLE
*ChildHandleBuffer
661 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
662 GRAPHICS_CONSOLE_DEV
*Private
;
664 Status
= gBS
->OpenProtocol (
666 &gEfiSimpleTextOutProtocolGuid
,
667 (VOID
**) &SimpleTextOutput
,
668 This
->DriverBindingHandle
,
670 EFI_OPEN_PROTOCOL_GET_PROTOCOL
672 if (EFI_ERROR (Status
)) {
673 return EFI_NOT_STARTED
;
676 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
678 Status
= gBS
->UninstallProtocolInterface (
680 &gEfiSimpleTextOutProtocolGuid
,
681 &Private
->SimpleTextOutput
684 if (!EFI_ERROR (Status
)) {
686 // Close the GOP or UGA IO Protocol
688 if (Private
->GraphicsOutput
!= NULL
) {
691 &gEfiGraphicsOutputProtocolGuid
,
692 This
->DriverBindingHandle
,
695 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
698 &gEfiUgaDrawProtocolGuid
,
699 This
->DriverBindingHandle
,
705 // Remove the font pack
707 if (Private
->HiiHandle
!= NULL
) {
708 HiiLibRemovePackages (Private
->HiiHandle
);
709 mFirstAccessFlag
= TRUE
;
713 // Free our instance data
715 if (Private
!= NULL
) {
716 FreePool (Private
->LineBuffer
);
725 Check if the current specific mode supported the user defined resolution
726 for the Graphice Console devcie based on Graphics Output Protocol.
728 If yes, set the graphic devcice's current mode to this specific mode.
730 @param GraphicsOutput Graphics Output Protocol instance pointer.
731 @param HorizontalResolution User defined horizontal resolution
732 @param VerticalResolution User defined vertical resolution.
733 @param CurrentModeNumber Current specific mode to be check.
735 @retval EFI_SUCCESS This driver is removed ControllerHandle.
736 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
738 @retval other The specific mode does not support user defined
739 resolution or failed to set the current mode to the
740 specific mode on graphics device.
745 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
746 IN UINT32 HorizontalResolution
,
747 IN UINT32 VerticalResolution
,
748 OUT UINT32
*CurrentModeNumber
754 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
756 Status
= EFI_SUCCESS
;
758 for (ModeNumber
= 0; ModeNumber
< GraphicsOutput
->Mode
->MaxMode
; ModeNumber
++) {
759 Status
= GraphicsOutput
->QueryMode (
765 if (!EFI_ERROR (Status
)) {
766 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
767 (Info
->VerticalResolution
== VerticalResolution
)) {
768 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
769 if (!EFI_ERROR (Status
)) {
770 gBS
->FreePool (Info
);
774 gBS
->FreePool (Info
);
778 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
779 Status
= EFI_UNSUPPORTED
;
782 *CurrentModeNumber
= ModeNumber
;
788 Locate HII Database protocol and HII Font protocol.
790 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
791 are located successfully.
792 @return other Failed to locate HII Database protocol or
797 EfiLocateHiiProtocol (
806 // There should only be one - so buffer size is this
808 Size
= sizeof (EFI_HANDLE
);
810 Status
= gBS
->LocateHandle (
812 &gEfiHiiDatabaseProtocolGuid
,
818 if (EFI_ERROR (Status
)) {
822 Status
= gBS
->HandleProtocol (
824 &gEfiHiiDatabaseProtocolGuid
,
825 (VOID
**) &mHiiDatabase
828 if (EFI_ERROR (Status
)) {
832 Status
= gBS
->HandleProtocol (
834 &gEfiHiiFontProtocolGuid
,
841 // Body of the STO functions
845 Reset the text output device hardware and optionaly run diagnostics.
847 Implements SIMPLE_TEXT_OUTPUT.Reset().
848 If ExtendeVerification is TRUE, then perform dependent Graphics Console
849 device reset, and set display mode to mode 0.
850 If ExtendedVerification is FALSE, only set display mode to mode 0.
852 @param This Protocol instance pointer.
853 @param ExtendedVerification Indicates that the driver may perform a more
854 exhaustive verification operation of the device
857 @retval EFI_SUCCESS The text output device was reset.
858 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
864 GraphicsConsoleConOutReset (
865 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
866 IN BOOLEAN ExtendedVerification
869 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
870 return This
->SetMode (This
, 0);
875 Write a Unicode string to the output device.
877 Implements SIMPLE_TEXT_OUTPUT.OutputString().
878 The Unicode string will be converted to Glyphs and will be
879 sent to the Graphics Console.
881 @param This Protocol instance pointer.
882 @param WString The NULL-terminated Unicode string to be displayed
883 on the output device(s). All output devices must
884 also support the Unicode drawing defined in this file.
886 @retval EFI_SUCCESS The string was output to the device.
887 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
889 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
891 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
892 characters in the Unicode string could not be
893 rendered and were skipped.
898 GraphicsConsoleConOutOutputString (
899 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
903 GRAPHICS_CONSOLE_DEV
*Private
;
904 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
905 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
914 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
915 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
920 INT32 OriginAttribute
;
923 Status
= EFI_SUCCESS
;
925 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
929 Mode
= This
->Mode
->Mode
;
930 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
931 GraphicsOutput
= Private
->GraphicsOutput
;
932 UgaDraw
= Private
->UgaDraw
;
934 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
935 MaxRow
= Private
->ModeData
[Mode
].Rows
;
936 DeltaX
= Private
->ModeData
[Mode
].DeltaX
;
937 DeltaY
= Private
->ModeData
[Mode
].DeltaY
;
938 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
939 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
940 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
943 // The Attributes won't change when during the time OutputString is called
945 GetTextColors (This
, &Foreground
, &Background
);
954 OriginAttribute
= This
->Mode
->Attribute
;
956 while (*WString
!= L
'\0') {
958 if (*WString
== CHAR_BACKSPACE
) {
960 // If the cursor is at the left edge of the display, then move the cursor
963 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
964 This
->Mode
->CursorRow
--;
965 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
966 This
->OutputString (This
, SpaceStr
);
968 This
->Mode
->CursorRow
--;
969 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
970 } else if (This
->Mode
->CursorColumn
> 0) {
972 // If the cursor is not at the left edge of the display, then move the cursor
975 This
->Mode
->CursorColumn
--;
976 This
->OutputString (This
, SpaceStr
);
978 This
->Mode
->CursorColumn
--;
983 } else if (*WString
== CHAR_LINEFEED
) {
985 // If the cursor is at the bottom of the display, then scroll the display one
986 // row, and do not update the cursor position. Otherwise, move the cursor
989 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
990 if (GraphicsOutput
!= NULL
) {
992 // Scroll Screen Up One Row
994 GraphicsOutput
->Blt (
999 DeltaY
+ EFI_GLYPH_HEIGHT
,
1008 // Print Blank Line at last line
1010 GraphicsOutput
->Blt (
1022 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1024 // Scroll Screen Up One Row
1031 DeltaY
+ EFI_GLYPH_HEIGHT
,
1040 // Print Blank Line at last line
1044 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1056 This
->Mode
->CursorRow
++;
1061 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1063 // Move the cursor to the beginning of the current row.
1065 This
->Mode
->CursorColumn
= 0;
1068 } else if (*WString
== WIDE_CHAR
) {
1070 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1073 } else if (*WString
== NARROW_CHAR
) {
1075 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1080 // Print the character at the current cursor position and move the cursor
1081 // right one column. If this moves the cursor past the right edge of the
1082 // display, then the line should wrap to the beginning of the next line. This
1083 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1084 // bottom of the display, and the line wraps, then the display will be scrolled
1086 // If wide char is going to be displayed, need to display one character at a time
1087 // Or, need to know the display length of a certain string.
1089 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1090 // Count is used to determine how many characters are used regardless of their attributes
1092 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1093 if (WString
[Count
] == CHAR_NULL
) {
1097 if (WString
[Count
] == CHAR_BACKSPACE
) {
1101 if (WString
[Count
] == CHAR_LINEFEED
) {
1105 if (WString
[Count
] == CHAR_CARRIAGE_RETURN
) {
1109 if (WString
[Count
] == WIDE_CHAR
) {
1113 if (WString
[Count
] == NARROW_CHAR
) {
1117 // Is the wide attribute on?
1119 if (This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) {
1121 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1125 // This is the end-case where if we are at column 79 and about to print a wide character
1126 // We should prevent this from happening because we will wrap inappropriately. We should
1127 // not print this character until the next line.
1129 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1136 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1137 if (EFI_ERROR (Status
)) {
1141 // At the end of line, output carriage return and line feed
1144 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1145 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1146 This
->Mode
->CursorColumn
-= 2;
1147 This
->OutputString (This
, SpaceStr
);
1150 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1152 This
->OutputString (This
, mCrLfString
);
1158 This
->Mode
->Attribute
= OriginAttribute
;
1163 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1166 gBS
->RestoreTPL (OldTpl
);
1172 Verifies that all characters in a Unicode string can be output to the
1175 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1176 If one of the characters in the *Wstring is neither valid valid Unicode
1177 drawing characters, not ASCII code, then this function will return
1180 @param This Protocol instance pointer.
1181 @param WString The NULL-terminated Unicode string to be examined for the output
1184 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1185 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1186 rendered by one or more of the output devices mapped
1192 GraphicsConsoleConOutTestString (
1193 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1200 EFI_IMAGE_OUTPUT
*Blt
;
1205 while (WString
[Count
] != 0) {
1206 Status
= mHiiFont
->GetGlyph (
1217 if (EFI_ERROR (Status
)) {
1218 return EFI_UNSUPPORTED
;
1227 Returns information for an available text mode that the output device(s)
1230 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1231 It returnes information for an available text mode that the Graphics Console supports.
1232 In this driver,we only support text mode 80x25, which is defined as mode 0.
1234 @param This Protocol instance pointer.
1235 @param ModeNumber The mode number to return information on.
1236 @param Columns The returned columns of the requested mode.
1237 @param Rows The returned rows of the requested mode.
1239 @retval EFI_SUCCESS The requested mode information is returned.
1240 @retval EFI_UNSUPPORTED The mode number is not valid.
1245 GraphicsConsoleConOutQueryMode (
1246 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1247 IN UINTN ModeNumber
,
1252 GRAPHICS_CONSOLE_DEV
*Private
;
1256 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1257 return EFI_UNSUPPORTED
;
1260 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1261 Status
= EFI_SUCCESS
;
1263 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1265 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1266 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1268 if (*Columns
<= 0 && *Rows
<= 0) {
1269 Status
= EFI_UNSUPPORTED
;
1275 gBS
->RestoreTPL (OldTpl
);
1281 Sets the output device(s) to a specified mode.
1283 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1284 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1286 @param This Protocol instance pointer.
1287 @param ModeNumber The text mode to set.
1289 @retval EFI_SUCCESS The requested text mode is set.
1290 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1291 Graphics Console device error.
1292 @retval EFI_UNSUPPORTED The text mode number is not valid.
1297 GraphicsConsoleConOutSetMode (
1298 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1303 GRAPHICS_CONSOLE_DEV
*Private
;
1304 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1305 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1306 UINT32 HorizontalResolution
;
1307 UINT32 VerticalResolution
;
1308 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1309 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1314 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1316 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1317 GraphicsOutput
= Private
->GraphicsOutput
;
1318 UgaDraw
= Private
->UgaDraw
;
1319 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1321 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1322 Status
= EFI_UNSUPPORTED
;
1327 // Make sure the requested mode number is supported
1329 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1330 Status
= EFI_UNSUPPORTED
;
1334 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1335 Status
= EFI_UNSUPPORTED
;
1339 // Attempt to allocate a line buffer for the requested mode number
1341 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1343 if (NewLineBuffer
== NULL
) {
1345 // The new line buffer could not be allocated, so return an error.
1346 // No changes to the state of the current console have been made, so the current console is still valid
1348 Status
= EFI_OUT_OF_RESOURCES
;
1352 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1354 if (Private
->LineBuffer
!= NULL
) {
1356 // Clear the current text window on the current graphics console
1358 This
->ClearScreen (This
);
1361 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1363 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1364 FreePool (NewLineBuffer
);
1365 Status
= EFI_SUCCESS
;
1369 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1370 // so erase the cursor, and free the LineBuffer for the current mode
1374 FreePool (Private
->LineBuffer
);
1377 // Assign the current line buffer to the newly allocated line buffer
1379 Private
->LineBuffer
= NewLineBuffer
;
1381 if (GraphicsOutput
!= NULL
) {
1382 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1384 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode
1386 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1387 if (EFI_ERROR (Status
)) {
1389 // The mode set operation failed
1395 // The current graphics mode is correct, so simply clear the entire display
1397 Status
= GraphicsOutput
->Blt (
1406 ModeData
->GopHeight
,
1410 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1412 // Get the current UGA Draw mode information
1414 Status
= UgaDraw
->GetMode (
1416 &HorizontalResolution
,
1417 &VerticalResolution
,
1421 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1423 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new grapghics mode
1425 Status
= UgaDraw
->SetMode (
1428 ModeData
->GopHeight
,
1432 if (EFI_ERROR (Status
)) {
1434 // The mode set operation failed
1440 // The current graphics mode is correct, so simply clear the entire display
1442 Status
= UgaDraw
->Blt (
1444 (EFI_UGA_PIXEL
*) (UINTN
) &mEfiColors
[0],
1451 ModeData
->GopHeight
,
1458 // The new mode is valid, so commit the mode change
1460 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1463 // Move the text cursor to the upper left hand corner of the displat and enable it
1465 This
->SetCursorPosition (This
, 0, 0);
1467 Status
= EFI_SUCCESS
;
1470 gBS
->RestoreTPL (OldTpl
);
1476 Sets the background and foreground colors for the OutputString () and
1477 ClearScreen () functions.
1479 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1481 @param This Protocol instance pointer.
1482 @param Attribute The attribute to set. Bits 0..3 are the foreground
1483 color, and bits 4..6 are the background color.
1484 All other bits are undefined and must be zero.
1486 @retval EFI_SUCCESS The requested attribute is set.
1487 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1488 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1493 GraphicsConsoleConOutSetAttribute (
1494 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1500 if ((Attribute
| 0xFF) != 0xFF) {
1501 return EFI_UNSUPPORTED
;
1504 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1508 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1512 This
->Mode
->Attribute
= (INT32
) Attribute
;
1516 gBS
->RestoreTPL (OldTpl
);
1523 Clears the output device(s) display to the currently selected background
1526 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1528 @param This Protocol instance pointer.
1530 @retval EFI_SUCCESS The operation completed successfully.
1531 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1532 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1537 GraphicsConsoleConOutClearScreen (
1538 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1542 GRAPHICS_CONSOLE_DEV
*Private
;
1543 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1544 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1545 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1546 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1547 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1550 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1552 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1553 GraphicsOutput
= Private
->GraphicsOutput
;
1554 UgaDraw
= Private
->UgaDraw
;
1555 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1557 GetTextColors (This
, &Foreground
, &Background
);
1558 if (GraphicsOutput
!= NULL
) {
1559 Status
= GraphicsOutput
->Blt (
1568 ModeData
->GopHeight
,
1571 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1572 Status
= UgaDraw
->Blt (
1574 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1581 ModeData
->GopHeight
,
1585 Status
= EFI_UNSUPPORTED
;
1588 This
->Mode
->CursorColumn
= 0;
1589 This
->Mode
->CursorRow
= 0;
1593 gBS
->RestoreTPL (OldTpl
);
1600 Sets the current coordinates of the cursor position.
1602 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1604 @param This Protocol instance pointer.
1605 @param Column The position to set the cursor to. Must be greater than or
1606 equal to zero and less than the number of columns and rows
1608 @param Row The position to set the cursor to. Must be greater than or
1609 equal to zero and less than the number of columns and rows
1612 @retval EFI_SUCCESS The operation completed successfully.
1613 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1614 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1615 cursor position is invalid for the current mode.
1620 GraphicsConsoleConOutSetCursorPosition (
1621 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1626 GRAPHICS_CONSOLE_DEV
*Private
;
1627 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1631 Status
= EFI_SUCCESS
;
1633 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1635 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1636 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1638 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1639 Status
= EFI_UNSUPPORTED
;
1643 if (((INT32
) Column
== This
->Mode
->CursorColumn
) && ((INT32
) Row
== This
->Mode
->CursorRow
)) {
1644 Status
= EFI_SUCCESS
;
1650 This
->Mode
->CursorColumn
= (INT32
) Column
;
1651 This
->Mode
->CursorRow
= (INT32
) Row
;
1656 gBS
->RestoreTPL (OldTpl
);
1663 Makes the cursor visible or invisible.
1665 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1667 @param This Protocol instance pointer.
1668 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1669 the cursor is set to be invisible.
1671 @retval EFI_SUCCESS The operation completed successfully.
1676 GraphicsConsoleConOutEnableCursor (
1677 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1683 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1687 This
->Mode
->CursorVisible
= Visible
;
1691 gBS
->RestoreTPL (OldTpl
);
1696 Gets Graphics Console devcie's foreground color and background color.
1698 @param This Protocol instance pointer.
1699 @param Foreground Returned text foreground color.
1700 @param Background Returned text background color.
1702 @retval EFI_SUCCESS It returned always.
1707 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1708 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1709 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1714 Attribute
= This
->Mode
->Attribute
& 0x7F;
1716 *Foreground
= mEfiColors
[Attribute
& 0x0f];
1717 *Background
= mEfiColors
[Attribute
>> 4];
1723 Draw Unicode string on the Graphice Console device's screen.
1725 @param This Protocol instance pointer.
1726 @param UnicodeWeight One Unicode string to be displayed.
1727 @param Count The count of Unicode string.
1729 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1730 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1732 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1736 DrawUnicodeWeightAtCursorN (
1737 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1738 IN CHAR16
*UnicodeWeight
,
1743 GRAPHICS_CONSOLE_DEV
*Private
;
1744 EFI_IMAGE_OUTPUT
*Blt
;
1746 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1747 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1748 EFI_HII_ROW_INFO
*RowInfoArray
;
1749 UINTN RowInfoArraySize
;
1751 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1752 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1754 return EFI_OUT_OF_RESOURCES
;
1757 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1758 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1760 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1761 if (String
== NULL
) {
1763 return EFI_OUT_OF_RESOURCES
;
1765 *(String
+ Count
) = 0;
1767 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1768 if (FontInfo
== NULL
) {
1770 SafeFreePool (String
);
1771 return EFI_OUT_OF_RESOURCES
;
1773 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1775 if (Private
->GraphicsOutput
!= NULL
) {
1776 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1778 Status
= mHiiFont
->StringToImage (
1780 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
,
1784 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1785 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1791 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1792 ASSERT (Private
->UgaDraw
!= NULL
);
1794 UgaDraw
= Private
->UgaDraw
;
1796 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1797 if (Blt
->Image
.Bitmap
== NULL
) {
1799 SafeFreePool (String
);
1800 return EFI_OUT_OF_RESOURCES
;
1803 RowInfoArray
= NULL
;
1805 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1806 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1808 Status
= mHiiFont
->StringToImage (
1810 EFI_HII_IGNORE_IF_NO_GLYPH
,
1814 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1815 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1821 if (!EFI_ERROR (Status
)) {
1823 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1824 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1826 ASSERT (RowInfoArraySize
<= 1);
1828 Status
= UgaDraw
->Blt (
1830 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1831 EfiUgaBltBufferToVideo
,
1832 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1833 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1834 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1835 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1836 RowInfoArray
[0].LineWidth
,
1837 RowInfoArray
[0].LineHeight
,
1838 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1842 SafeFreePool (RowInfoArray
);
1843 SafeFreePool (Blt
->Image
.Bitmap
);
1845 Status
= EFI_UNSUPPORTED
;
1849 SafeFreePool (String
);
1850 SafeFreePool (FontInfo
);
1855 Erase the cursor on the screen.
1857 @param This Protocol instance pointer.
1859 @retval EFI_SUCCESS The cursor is erased successfully.
1864 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1867 GRAPHICS_CONSOLE_DEV
*Private
;
1868 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1871 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1872 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1873 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1874 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1875 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1879 CurrentMode
= This
->Mode
;
1881 if (!CurrentMode
->CursorVisible
) {
1885 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1886 GraphicsOutput
= Private
->GraphicsOutput
;
1887 UgaDraw
= Private
->UgaDraw
;
1890 // In this driver, only narrow character was supported.
1893 // Blt a character to the screen
1895 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1896 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1897 if (GraphicsOutput
!= NULL
) {
1898 GraphicsOutput
->Blt (
1900 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1901 EfiBltVideoToBltBuffer
,
1908 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1910 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1913 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1914 EfiUgaVideoToBltBuffer
,
1921 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1925 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1928 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1930 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1931 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1932 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (1 << PosX
)) != 0) {
1933 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1938 if (GraphicsOutput
!= NULL
) {
1939 GraphicsOutput
->Blt (
1941 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1942 EfiBltBufferToVideo
,
1949 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1951 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1954 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1955 EfiUgaBltBufferToVideo
,
1962 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1970 The user Entry Point for module GraphicsConsole. The user code starts with this function.
1972 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1973 @param[in] SystemTable A pointer to the EFI System Table.
1975 @retval EFI_SUCCESS The entry point is executed successfully.
1976 @retval other Some error occurs when executing this entry point.
1981 InitializeGraphicsConsole (
1982 IN EFI_HANDLE ImageHandle
,
1983 IN EFI_SYSTEM_TABLE
*SystemTable
1989 // Install driver model protocol(s).
1991 Status
= EfiLibInstallDriverBindingComponentName2 (
1994 &gGraphicsConsoleDriverBinding
,
1996 &gGraphicsConsoleComponentName
,
1997 &gGraphicsConsoleComponentName2
1999 ASSERT_EFI_ERROR (Status
);