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 // Graphics Console Device Private Data template
20 GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate
= {
21 GRAPHICS_CONSOLE_DEV_SIGNATURE
,
22 (EFI_GRAPHICS_OUTPUT_PROTOCOL
*) NULL
,
23 (EFI_UGA_DRAW_PROTOCOL
*) NULL
,
25 GraphicsConsoleConOutReset
,
26 GraphicsConsoleConOutOutputString
,
27 GraphicsConsoleConOutTestString
,
28 GraphicsConsoleConOutQueryMode
,
29 GraphicsConsoleConOutSetMode
,
30 GraphicsConsoleConOutSetAttribute
,
31 GraphicsConsoleConOutClearScreen
,
32 GraphicsConsoleConOutSetCursorPosition
,
33 GraphicsConsoleConOutEnableCursor
,
34 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
39 EFI_TEXT_ATTR(EFI_LIGHTGRAY
, EFI_BLACK
),
45 { 80, 25, 0, 0, 0, 0 }, // Mode 0
46 { 80, 50, 0, 0, 0, 0 }, // Mode 1
47 { 100,31, 0, 0, 0, 0 }, // Mode 2
48 { 0, 0, 0, 0, 0, 0 } // Mode 3
50 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
,
54 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
55 EFI_HII_FONT_PROTOCOL
*mHiiFont
;
56 BOOLEAN mFirstAccessFlag
= TRUE
;
58 EFI_GUID mFontPackageListGuid
= {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};
60 CHAR16 mCrLfString
[3] = { CHAR_CARRIAGE_RETURN
, CHAR_LINEFEED
, CHAR_NULL
};
62 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors
[16] = {
66 {0x00, 0x00, 0x00, 0x00}, // BLACK
67 {0x98, 0x00, 0x00, 0x00}, // LIGHTBLUE
68 {0x00, 0x98, 0x00, 0x00}, // LIGHGREEN
69 {0x98, 0x98, 0x00, 0x00}, // LIGHCYAN
70 {0x00, 0x00, 0x98, 0x00}, // LIGHRED
71 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
72 {0x00, 0x98, 0x98, 0x00}, // BROWN
73 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
74 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
75 {0xff, 0x00, 0x00, 0x00}, // BLUE
76 {0x00, 0xff, 0x00, 0x00}, // LIME
77 {0xff, 0xff, 0x00, 0x00}, // CYAN
78 {0x00, 0x00, 0xff, 0x00}, // RED
79 {0xff, 0x00, 0xff, 0x00}, // FUCHSIA
80 {0x00, 0xff, 0xff, 0x00}, // YELLOW
81 {0xff, 0xff, 0xff, 0x00} // WHITE
84 EFI_NARROW_GLYPH mCursorGlyph
= {
87 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }
90 CHAR16 SpaceStr
[] = { NARROW_CHAR
, ' ', 0 };
92 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding
= {
93 GraphicsConsoleControllerDriverSupported
,
94 GraphicsConsoleControllerDriverStart
,
95 GraphicsConsoleControllerDriverStop
,
102 Gets Graphics Console devcie's foreground color and background color.
104 @param This Protocol instance pointer.
105 @param Foreground Returned text foreground color.
106 @param Background Returned text background color.
108 @retval EFI_SUCCESS It returned always.
113 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
114 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
115 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
119 Draw Unicode string on the Graphics Console device's screen.
121 @param This Protocol instance pointer.
122 @param UnicodeWeight One Unicode string to be displayed.
123 @param Count The count of Unicode string.
125 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
126 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
128 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
132 DrawUnicodeWeightAtCursorN (
133 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
134 IN CHAR16
*UnicodeWeight
,
139 Erase the cursor on the screen.
141 @param This Protocol instance pointer.
143 @retval EFI_SUCCESS The cursor is erased successfully.
148 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
152 Check if the current specific mode supported the user defined resolution
153 for the Graphics Console device based on Graphics Output Protocol.
155 If yes, set the graphic device's current mode to this specific mode.
157 @param GraphicsOutput Graphics Output Protocol instance pointer.
158 @param HorizontalResolution User defined horizontal resolution
159 @param VerticalResolution User defined vertical resolution.
160 @param CurrentModeNumber Current specific mode to be check.
162 @retval EFI_SUCCESS The mode is supported.
163 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
165 @retval other The specific mode does not support user defined
166 resolution or failed to set the current mode to the
167 specific mode on graphics device.
172 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
173 IN UINT32 HorizontalResolution
,
174 IN UINT32 VerticalResolution
,
175 OUT UINT32
*CurrentModeNumber
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 skipped 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 UINT32 NarrowFontSize
;
316 UINT32 HorizontalResolution
;
317 UINT32 VerticalResolution
;
324 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
325 UINT32 PackageLength
;
326 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
329 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*Mode
;
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 // +--------------------------------+ <-- Package
378 // | PackageLength(4 bytes) |
380 // |--------------------------------| <-- SimplifiedFont
382 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
384 // |--------------------------------| <-- Location
386 // | gUsStdNarrowGlyphData |
388 // +--------------------------------+
390 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + NarrowFontSize
+ 4;
391 Package
= AllocateZeroPool (PackageLength
);
392 if (Package
== NULL
) {
393 return EFI_OUT_OF_RESOURCES
;
395 WriteUnaligned32((UINT32
*) Package
,PackageLength
);
396 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
397 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
398 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
399 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (NarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
401 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
402 CopyMem (Location
, gUsStdNarrowGlyphData
, NarrowFontSize
);
405 // Add this simplified font package to a package list then install it.
407 PackageList
= HiiLibPreparePackageList (1, &mFontPackageListGuid
, Package
);
408 Status
= mHiiDatabase
->NewPackageList (mHiiDatabase
, PackageList
, NULL
, &(Private
->HiiHandle
));
409 ASSERT_EFI_ERROR (Status
);
410 FreePool (PackageList
);
413 mFirstAccessFlag
= FALSE
;
416 // If the current mode information can not be retrieved, then attempt to set the default mode
417 // of 800x600, 32 bit color, 60 Hz refresh.
419 HorizontalResolution
= 800;
420 VerticalResolution
= 600;
422 if (Private
->GraphicsOutput
!= NULL
) {
424 // The console is build on top of Graphics Output Protocol, find the mode number
425 // for the user-defined mode; if there are multiple video devices,
426 // graphic console driver will set all the video devices to the same mode.
428 Status
= CheckModeSupported (
429 Private
->GraphicsOutput
,
430 CURRENT_HORIZONTAL_RESOLUTION
,
431 CURRENT_VERTICAL_RESOLUTION
,
434 if (!EFI_ERROR(Status
)) {
436 // Update default mode to current mode
438 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
439 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
442 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
444 Status
= CheckModeSupported (
445 Private
->GraphicsOutput
,
452 Mode
= Private
->GraphicsOutput
->Mode
;
454 if (EFI_ERROR (Status
) || (Mode
->MaxMode
)) {
456 // Set default mode failed or device don't support default mode, then get the current mode information
458 HorizontalResolution
= Mode
->Info
->HorizontalResolution
;
459 VerticalResolution
= Mode
->Info
->VerticalResolution
;
460 ModeNumber
= Mode
->Mode
;
462 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
464 // At first try to set user-defined resolution
468 Status
= Private
->UgaDraw
->SetMode (
470 CURRENT_HORIZONTAL_RESOLUTION
,
471 CURRENT_VERTICAL_RESOLUTION
,
475 if (!EFI_ERROR (Status
)) {
476 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
477 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
478 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
480 // Try to set 800*600 which is required by UEFI/EFI spec
482 Status
= Private
->UgaDraw
->SetMode (
484 HorizontalResolution
,
489 if (EFI_ERROR (Status
)) {
490 Status
= Private
->UgaDraw
->GetMode (
492 &HorizontalResolution
,
497 if (EFI_ERROR (Status
)) {
502 Status
= EFI_UNSUPPORTED
;
508 // Compute the maximum number of text Rows and Columns that this current graphics mode can support
510 Columns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
511 Rows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
514 // See if the mode is too small to support the required 80x25 text mode
516 if (Columns
< 80 || Rows
< 25) {
520 // Add Mode #0 that must be 80x25
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
- (25 * EFI_GLYPH_HEIGHT
)) >> 1;
531 // If it is possible to support Mode #1 - 80x50, than add it as an active mode
534 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
535 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
536 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
537 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
538 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (50 * EFI_GLYPH_HEIGHT
)) >> 1;
543 // If it is not to support Mode #1 - 80x50, then skip it
546 Private
->ModeData
[MaxMode
].Columns
= 0;
547 Private
->ModeData
[MaxMode
].Rows
= 0;
548 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
549 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
550 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
551 Private
->ModeData
[MaxMode
].DeltaX
= 0;
552 Private
->ModeData
[MaxMode
].DeltaY
= 0;
557 // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)
559 if (Columns
>= 100 && Rows
>= 31) {
560 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
561 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
562 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
563 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (100 * EFI_GLYPH_WIDTH
)) >> 1;
564 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (31 * EFI_GLYPH_HEIGHT
)) >> 1;
569 // Add Mode #3 that uses the entire display for user-defined mode
571 if (HorizontalResolution
> 800 && VerticalResolution
> 600) {
572 Private
->ModeData
[MaxMode
].Columns
= HorizontalResolution
/EFI_GLYPH_WIDTH
;
573 Private
->ModeData
[MaxMode
].Rows
= VerticalResolution
/EFI_GLYPH_HEIGHT
;
574 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
575 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
576 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
577 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
% EFI_GLYPH_WIDTH
) >> 1;
578 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
% EFI_GLYPH_HEIGHT
) >> 1;
583 // Update the maximum number of modes
585 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
588 // Determine the number of text modes that this protocol can support
590 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
591 if (EFI_ERROR (Status
)) {
596 GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
600 // Install protocol interfaces for the Graphics Console device.
602 Status
= gBS
->InstallMultipleProtocolInterfaces (
604 &gEfiSimpleTextOutProtocolGuid
,
605 &Private
->SimpleTextOutput
,
610 if (EFI_ERROR (Status
)) {
612 // Close the GOP and UGA Draw Protocol
614 if (Private
->GraphicsOutput
!= NULL
) {
617 &gEfiGraphicsOutputProtocolGuid
,
618 This
->DriverBindingHandle
,
621 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
624 &gEfiUgaDrawProtocolGuid
,
625 This
->DriverBindingHandle
,
633 if (Private
!= NULL
) {
634 if (Private
->LineBuffer
!= NULL
) {
635 FreePool (Private
->LineBuffer
);
645 Stop this driver on Controller by removing Simple Text Out protocol
646 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
647 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
650 @param This Protocol instance pointer.
651 @param Controller Handle of device to stop driver on
652 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
653 children is zero stop the entire bus driver.
654 @param ChildHandleBuffer List of Child Handles to Stop.
656 @retval EFI_SUCCESS This driver is removed Controller.
657 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
659 @retval other This driver was not removed from this device.
664 GraphicsConsoleControllerDriverStop (
665 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
666 IN EFI_HANDLE Controller
,
667 IN UINTN NumberOfChildren
,
668 IN EFI_HANDLE
*ChildHandleBuffer
672 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
673 GRAPHICS_CONSOLE_DEV
*Private
;
675 Status
= gBS
->OpenProtocol (
677 &gEfiSimpleTextOutProtocolGuid
,
678 (VOID
**) &SimpleTextOutput
,
679 This
->DriverBindingHandle
,
681 EFI_OPEN_PROTOCOL_GET_PROTOCOL
683 if (EFI_ERROR (Status
)) {
684 return EFI_NOT_STARTED
;
687 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
689 Status
= gBS
->UninstallProtocolInterface (
691 &gEfiSimpleTextOutProtocolGuid
,
692 &Private
->SimpleTextOutput
695 if (!EFI_ERROR (Status
)) {
697 // Close the GOP or UGA IO Protocol
699 if (Private
->GraphicsOutput
!= NULL
) {
702 &gEfiGraphicsOutputProtocolGuid
,
703 This
->DriverBindingHandle
,
706 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
709 &gEfiUgaDrawProtocolGuid
,
710 This
->DriverBindingHandle
,
716 // Remove the font pack
718 if (Private
->HiiHandle
!= NULL
) {
719 HiiLibRemovePackages (Private
->HiiHandle
);
720 mFirstAccessFlag
= TRUE
;
724 // Free our instance data
726 if (Private
!= NULL
) {
727 FreePool (Private
->LineBuffer
);
736 Check if the current specific mode supported the user defined resolution
737 for the Graphics Console device based on Graphics Output Protocol.
739 If yes, set the graphic devcice's current mode to this specific mode.
741 @param GraphicsOutput Graphics Output Protocol instance pointer.
742 @param HorizontalResolution User defined horizontal resolution
743 @param VerticalResolution User defined vertical resolution.
744 @param CurrentModeNumber Current specific mode to be check.
746 @retval EFI_SUCCESS The mode is supported.
747 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
749 @retval other The specific mode does not support user defined
750 resolution or failed to set the current mode to the
751 specific mode on graphics device.
756 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
757 IN UINT32 HorizontalResolution
,
758 IN UINT32 VerticalResolution
,
759 OUT UINT32
*CurrentModeNumber
765 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
768 Status
= EFI_SUCCESS
;
769 MaxMode
= GraphicsOutput
->Mode
->MaxMode
;
771 for (ModeNumber
= 0; ModeNumber
< MaxMode
; ModeNumber
++) {
772 Status
= GraphicsOutput
->QueryMode (
778 if (!EFI_ERROR (Status
)) {
779 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
780 (Info
->VerticalResolution
== VerticalResolution
)) {
781 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
782 if (!EFI_ERROR (Status
)) {
791 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
792 Status
= EFI_UNSUPPORTED
;
795 *CurrentModeNumber
= ModeNumber
;
801 Locate HII Database protocol and HII Font protocol.
803 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
804 are located successfully.
805 @return other Failed to locate HII Database protocol or
810 EfiLocateHiiProtocol (
819 // There should only be one - so buffer size is this
821 Size
= sizeof (EFI_HANDLE
);
823 Status
= gBS
->LocateHandle (
825 &gEfiHiiDatabaseProtocolGuid
,
831 if (EFI_ERROR (Status
)) {
835 Status
= gBS
->HandleProtocol (
837 &gEfiHiiDatabaseProtocolGuid
,
838 (VOID
**) &mHiiDatabase
841 if (EFI_ERROR (Status
)) {
845 Status
= gBS
->HandleProtocol (
847 &gEfiHiiFontProtocolGuid
,
854 // Body of the STO functions
858 Reset the text output device hardware and optionally run diagnostics.
860 Implements SIMPLE_TEXT_OUTPUT.Reset().
861 If ExtendeVerification is TRUE, then perform dependent Graphics Console
862 device reset, and set display mode to mode 0.
863 If ExtendedVerification is FALSE, only set display mode to mode 0.
865 @param This Protocol instance pointer.
866 @param ExtendedVerification Indicates that the driver may perform a more
867 exhaustive verification operation of the device
870 @retval EFI_SUCCESS The text output device was reset.
871 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
877 GraphicsConsoleConOutReset (
878 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
879 IN BOOLEAN ExtendedVerification
882 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
883 return This
->SetMode (This
, 0);
888 Write a Unicode string to the output device.
890 Implements SIMPLE_TEXT_OUTPUT.OutputString().
891 The Unicode string will be converted to Glyphs and will be
892 sent to the Graphics Console.
894 @param This Protocol instance pointer.
895 @param WString The NULL-terminated Unicode string to be displayed
896 on the output device(s). All output devices must
897 also support the Unicode drawing defined in this file.
899 @retval EFI_SUCCESS The string was output to the device.
900 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
902 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
904 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
905 characters in the Unicode string could not be
906 rendered and were skipped.
911 GraphicsConsoleConOutOutputString (
912 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
916 GRAPHICS_CONSOLE_DEV
*Private
;
917 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
918 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
927 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
928 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
933 INT32 OriginAttribute
;
936 Status
= EFI_SUCCESS
;
938 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
942 Mode
= This
->Mode
->Mode
;
943 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
944 GraphicsOutput
= Private
->GraphicsOutput
;
945 UgaDraw
= Private
->UgaDraw
;
947 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
948 MaxRow
= Private
->ModeData
[Mode
].Rows
;
949 DeltaX
= Private
->ModeData
[Mode
].DeltaX
;
950 DeltaY
= Private
->ModeData
[Mode
].DeltaY
;
951 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
952 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
953 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
956 // The Attributes won't change when during the time OutputString is called
958 GetTextColors (This
, &Foreground
, &Background
);
967 OriginAttribute
= This
->Mode
->Attribute
;
969 while (*WString
!= L
'\0') {
971 if (*WString
== CHAR_BACKSPACE
) {
973 // If the cursor is at the left edge of the display, then move the cursor
976 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
977 This
->Mode
->CursorRow
--;
978 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
979 This
->OutputString (This
, SpaceStr
);
981 This
->Mode
->CursorRow
--;
982 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
983 } else if (This
->Mode
->CursorColumn
> 0) {
985 // If the cursor is not at the left edge of the display, then move the cursor
988 This
->Mode
->CursorColumn
--;
989 This
->OutputString (This
, SpaceStr
);
991 This
->Mode
->CursorColumn
--;
996 } else if (*WString
== CHAR_LINEFEED
) {
998 // If the cursor is at the bottom of the display, then scroll the display one
999 // row, and do not update the cursor position. Otherwise, move the cursor
1002 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
1003 if (GraphicsOutput
!= NULL
) {
1005 // Scroll Screen Up One Row
1007 GraphicsOutput
->Blt (
1012 DeltaY
+ EFI_GLYPH_HEIGHT
,
1021 // Print Blank Line at last line
1023 GraphicsOutput
->Blt (
1035 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1037 // Scroll Screen Up One Row
1044 DeltaY
+ EFI_GLYPH_HEIGHT
,
1053 // Print Blank Line at last line
1057 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1069 This
->Mode
->CursorRow
++;
1074 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1076 // Move the cursor to the beginning of the current row.
1078 This
->Mode
->CursorColumn
= 0;
1081 } else if (*WString
== WIDE_CHAR
) {
1083 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1086 } else if (*WString
== NARROW_CHAR
) {
1088 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1093 // Print the character at the current cursor position and move the cursor
1094 // right one column. If this moves the cursor past the right edge of the
1095 // display, then the line should wrap to the beginning of the next line. This
1096 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1097 // bottom of the display, and the line wraps, then the display will be scrolled
1099 // If wide char is going to be displayed, need to display one character at a time
1100 // Or, need to know the display length of a certain string.
1102 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1103 // Count is used to determine how many characters are used regardless of their attributes
1105 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1106 if (WString
[Count
] == CHAR_NULL
||
1107 WString
[Count
] == CHAR_BACKSPACE
||
1108 WString
[Count
] == CHAR_LINEFEED
||
1109 WString
[Count
] == CHAR_CARRIAGE_RETURN
||
1110 WString
[Count
] == WIDE_CHAR
||
1111 WString
[Count
] == NARROW_CHAR
) {
1115 // Is the wide attribute on?
1117 if (This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) {
1119 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1123 // This is the end-case where if we are at column 79 and about to print a wide character
1124 // We should prevent this from happening because we will wrap inappropriately. We should
1125 // not print this character until the next line.
1127 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1134 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1135 if (EFI_ERROR (Status
)) {
1139 // At the end of line, output carriage return and line feed
1142 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1143 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1144 This
->Mode
->CursorColumn
-= 2;
1145 This
->OutputString (This
, SpaceStr
);
1148 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1150 This
->OutputString (This
, mCrLfString
);
1156 This
->Mode
->Attribute
= OriginAttribute
;
1161 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1164 gBS
->RestoreTPL (OldTpl
);
1170 Verifies that all characters in a Unicode string can be output to the
1173 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1174 If one of the characters in the *Wstring is neither valid valid Unicode
1175 drawing characters, not ASCII code, then this function will return
1178 @param This Protocol instance pointer.
1179 @param WString The NULL-terminated Unicode string to be examined for the output
1182 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1183 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1184 rendered by one or more of the output devices mapped
1190 GraphicsConsoleConOutTestString (
1191 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1198 EFI_IMAGE_OUTPUT
*Blt
;
1203 while (WString
[Count
] != 0) {
1204 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 graphics 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 graphics 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 display 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 ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
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 Graphics 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
;
1766 // Set the end character
1768 *(String
+ Count
) = L
'\0';
1770 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1771 if (FontInfo
== NULL
) {
1774 return EFI_OUT_OF_RESOURCES
;
1777 // Get current foreground and background colors.
1779 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1781 if (Private
->GraphicsOutput
!= NULL
) {
1783 // If Graphics Output protocol exists, using HII Font protocol to draw.
1785 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1787 Status
= mHiiFont
->StringToImage (
1789 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
,
1793 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1794 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1800 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1802 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1803 // using UGA Draw protocol to draw.
1805 ASSERT (Private
->UgaDraw
!= NULL
);
1807 UgaDraw
= Private
->UgaDraw
;
1809 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1810 if (Blt
->Image
.Bitmap
== NULL
) {
1813 return EFI_OUT_OF_RESOURCES
;
1816 RowInfoArray
= NULL
;
1818 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1819 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1821 Status
= mHiiFont
->StringToImage (
1823 EFI_HII_IGNORE_IF_NO_GLYPH
,
1827 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1828 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1834 if (!EFI_ERROR (Status
)) {
1836 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1837 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1839 ASSERT (RowInfoArraySize
<= 1);
1841 Status
= UgaDraw
->Blt (
1843 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1844 EfiUgaBltBufferToVideo
,
1845 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1846 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1847 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1848 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1849 RowInfoArray
[0].LineWidth
,
1850 RowInfoArray
[0].LineHeight
,
1851 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1855 FreePool (RowInfoArray
);
1856 FreePool (Blt
->Image
.Bitmap
);
1858 Status
= EFI_UNSUPPORTED
;
1864 if (String
!= NULL
) {
1867 if (FontInfo
!= NULL
) {
1868 FreePool (FontInfo
);
1874 Erase the cursor on the screen.
1876 @param This Protocol instance pointer.
1878 @retval EFI_SUCCESS The cursor is erased successfully.
1883 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1886 GRAPHICS_CONSOLE_DEV
*Private
;
1887 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1890 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1891 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1892 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1893 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1894 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1898 CurrentMode
= This
->Mode
;
1900 if (!CurrentMode
->CursorVisible
) {
1904 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1905 GraphicsOutput
= Private
->GraphicsOutput
;
1906 UgaDraw
= Private
->UgaDraw
;
1909 // In this driver, only narrow character was supported.
1912 // Blt a character to the screen
1914 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1915 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1916 if (GraphicsOutput
!= NULL
) {
1917 GraphicsOutput
->Blt (
1919 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1920 EfiBltVideoToBltBuffer
,
1927 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1929 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1932 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1933 EfiUgaVideoToBltBuffer
,
1940 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1944 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1947 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1949 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1950 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1951 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1952 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1957 if (GraphicsOutput
!= NULL
) {
1958 GraphicsOutput
->Blt (
1960 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1961 EfiBltBufferToVideo
,
1968 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1970 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1973 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1974 EfiUgaBltBufferToVideo
,
1981 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1989 The user Entry Point for module GraphicsConsole. The user code starts with this function.
1991 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1992 @param[in] SystemTable A pointer to the EFI System Table.
1994 @retval EFI_SUCCESS The entry point is executed successfully.
1995 @return other Some error occurs when executing this entry point.
2000 InitializeGraphicsConsole (
2001 IN EFI_HANDLE ImageHandle
,
2002 IN EFI_SYSTEM_TABLE
*SystemTable
2008 // Install driver model protocol(s).
2010 Status
= EfiLibInstallDriverBindingComponentName2 (
2013 &gGraphicsConsoleDriverBinding
,
2015 &gGraphicsConsoleComponentName
,
2016 &gGraphicsConsoleComponentName2
2018 ASSERT_EFI_ERROR (Status
);