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
;
767 Status
= EFI_SUCCESS
;
769 for (ModeNumber
= 0; ModeNumber
< GraphicsOutput
->Mode
->MaxMode
; ModeNumber
++) {
770 Status
= GraphicsOutput
->QueryMode (
776 if (!EFI_ERROR (Status
)) {
777 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
778 (Info
->VerticalResolution
== VerticalResolution
)) {
779 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
780 if (!EFI_ERROR (Status
)) {
781 gBS
->FreePool (Info
);
785 gBS
->FreePool (Info
);
789 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
790 Status
= EFI_UNSUPPORTED
;
793 *CurrentModeNumber
= ModeNumber
;
799 Locate HII Database protocol and HII Font protocol.
801 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
802 are located successfully.
803 @return other Failed to locate HII Database protocol or
808 EfiLocateHiiProtocol (
817 // There should only be one - so buffer size is this
819 Size
= sizeof (EFI_HANDLE
);
821 Status
= gBS
->LocateHandle (
823 &gEfiHiiDatabaseProtocolGuid
,
829 if (EFI_ERROR (Status
)) {
833 Status
= gBS
->HandleProtocol (
835 &gEfiHiiDatabaseProtocolGuid
,
836 (VOID
**) &mHiiDatabase
839 if (EFI_ERROR (Status
)) {
843 Status
= gBS
->HandleProtocol (
845 &gEfiHiiFontProtocolGuid
,
852 // Body of the STO functions
856 Reset the text output device hardware and optionally run diagnostics.
858 Implements SIMPLE_TEXT_OUTPUT.Reset().
859 If ExtendeVerification is TRUE, then perform dependent Graphics Console
860 device reset, and set display mode to mode 0.
861 If ExtendedVerification is FALSE, only set display mode to mode 0.
863 @param This Protocol instance pointer.
864 @param ExtendedVerification Indicates that the driver may perform a more
865 exhaustive verification operation of the device
868 @retval EFI_SUCCESS The text output device was reset.
869 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
875 GraphicsConsoleConOutReset (
876 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
877 IN BOOLEAN ExtendedVerification
880 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
881 return This
->SetMode (This
, 0);
886 Write a Unicode string to the output device.
888 Implements SIMPLE_TEXT_OUTPUT.OutputString().
889 The Unicode string will be converted to Glyphs and will be
890 sent to the Graphics Console.
892 @param This Protocol instance pointer.
893 @param WString The NULL-terminated Unicode string to be displayed
894 on the output device(s). All output devices must
895 also support the Unicode drawing defined in this file.
897 @retval EFI_SUCCESS The string was output to the device.
898 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
900 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
902 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
903 characters in the Unicode string could not be
904 rendered and were skipped.
909 GraphicsConsoleConOutOutputString (
910 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
914 GRAPHICS_CONSOLE_DEV
*Private
;
915 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
916 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
925 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
926 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
931 INT32 OriginAttribute
;
934 Status
= EFI_SUCCESS
;
936 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
940 Mode
= This
->Mode
->Mode
;
941 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
942 GraphicsOutput
= Private
->GraphicsOutput
;
943 UgaDraw
= Private
->UgaDraw
;
945 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
946 MaxRow
= Private
->ModeData
[Mode
].Rows
;
947 DeltaX
= Private
->ModeData
[Mode
].DeltaX
;
948 DeltaY
= Private
->ModeData
[Mode
].DeltaY
;
949 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
950 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
951 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
954 // The Attributes won't change when during the time OutputString is called
956 GetTextColors (This
, &Foreground
, &Background
);
965 OriginAttribute
= This
->Mode
->Attribute
;
967 while (*WString
!= L
'\0') {
969 if (*WString
== CHAR_BACKSPACE
) {
971 // If the cursor is at the left edge of the display, then move the cursor
974 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
975 This
->Mode
->CursorRow
--;
976 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
977 This
->OutputString (This
, SpaceStr
);
979 This
->Mode
->CursorRow
--;
980 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
981 } else if (This
->Mode
->CursorColumn
> 0) {
983 // If the cursor is not at the left edge of the display, then move the cursor
986 This
->Mode
->CursorColumn
--;
987 This
->OutputString (This
, SpaceStr
);
989 This
->Mode
->CursorColumn
--;
994 } else if (*WString
== CHAR_LINEFEED
) {
996 // If the cursor is at the bottom of the display, then scroll the display one
997 // row, and do not update the cursor position. Otherwise, move the cursor
1000 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
1001 if (GraphicsOutput
!= NULL
) {
1003 // Scroll Screen Up One Row
1005 GraphicsOutput
->Blt (
1010 DeltaY
+ EFI_GLYPH_HEIGHT
,
1019 // Print Blank Line at last line
1021 GraphicsOutput
->Blt (
1033 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1035 // Scroll Screen Up One Row
1042 DeltaY
+ EFI_GLYPH_HEIGHT
,
1051 // Print Blank Line at last line
1055 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1067 This
->Mode
->CursorRow
++;
1072 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1074 // Move the cursor to the beginning of the current row.
1076 This
->Mode
->CursorColumn
= 0;
1079 } else if (*WString
== WIDE_CHAR
) {
1081 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1084 } else if (*WString
== NARROW_CHAR
) {
1086 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1091 // Print the character at the current cursor position and move the cursor
1092 // right one column. If this moves the cursor past the right edge of the
1093 // display, then the line should wrap to the beginning of the next line. This
1094 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1095 // bottom of the display, and the line wraps, then the display will be scrolled
1097 // If wide char is going to be displayed, need to display one character at a time
1098 // Or, need to know the display length of a certain string.
1100 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1101 // Count is used to determine how many characters are used regardless of their attributes
1103 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1104 if (WString
[Count
] == CHAR_NULL
||
1105 WString
[Count
] == CHAR_BACKSPACE
||
1106 WString
[Count
] == CHAR_LINEFEED
||
1107 WString
[Count
] == CHAR_CARRIAGE_RETURN
||
1108 WString
[Count
] == WIDE_CHAR
||
1109 WString
[Count
] == NARROW_CHAR
) {
1113 // Is the wide attribute on?
1115 if (This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) {
1117 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1121 // This is the end-case where if we are at column 79 and about to print a wide character
1122 // We should prevent this from happening because we will wrap inappropriately. We should
1123 // not print this character until the next line.
1125 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1132 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1133 if (EFI_ERROR (Status
)) {
1137 // At the end of line, output carriage return and line feed
1140 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1141 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1142 This
->Mode
->CursorColumn
-= 2;
1143 This
->OutputString (This
, SpaceStr
);
1146 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1148 This
->OutputString (This
, mCrLfString
);
1154 This
->Mode
->Attribute
= OriginAttribute
;
1159 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1162 gBS
->RestoreTPL (OldTpl
);
1168 Verifies that all characters in a Unicode string can be output to the
1171 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1172 If one of the characters in the *Wstring is neither valid valid Unicode
1173 drawing characters, not ASCII code, then this function will return
1176 @param This Protocol instance pointer.
1177 @param WString The NULL-terminated Unicode string to be examined for the output
1180 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1181 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1182 rendered by one or more of the output devices mapped
1188 GraphicsConsoleConOutTestString (
1189 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1196 EFI_IMAGE_OUTPUT
*Blt
;
1201 while (WString
[Count
] != 0) {
1202 Status
= mHiiFont
->GetGlyph (
1215 if (EFI_ERROR (Status
)) {
1216 return EFI_UNSUPPORTED
;
1225 Returns information for an available text mode that the output device(s)
1228 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1229 It returnes information for an available text mode that the Graphics Console supports.
1230 In this driver,we only support text mode 80x25, which is defined as mode 0.
1232 @param This Protocol instance pointer.
1233 @param ModeNumber The mode number to return information on.
1234 @param Columns The returned columns of the requested mode.
1235 @param Rows The returned rows of the requested mode.
1237 @retval EFI_SUCCESS The requested mode information is returned.
1238 @retval EFI_UNSUPPORTED The mode number is not valid.
1243 GraphicsConsoleConOutQueryMode (
1244 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1245 IN UINTN ModeNumber
,
1250 GRAPHICS_CONSOLE_DEV
*Private
;
1254 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1255 return EFI_UNSUPPORTED
;
1258 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1259 Status
= EFI_SUCCESS
;
1261 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1263 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1264 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1266 if (*Columns
<= 0 && *Rows
<= 0) {
1267 Status
= EFI_UNSUPPORTED
;
1273 gBS
->RestoreTPL (OldTpl
);
1279 Sets the output device(s) to a specified mode.
1281 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1282 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1284 @param This Protocol instance pointer.
1285 @param ModeNumber The text mode to set.
1287 @retval EFI_SUCCESS The requested text mode is set.
1288 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1289 Graphics Console device error.
1290 @retval EFI_UNSUPPORTED The text mode number is not valid.
1295 GraphicsConsoleConOutSetMode (
1296 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1301 GRAPHICS_CONSOLE_DEV
*Private
;
1302 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1303 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1304 UINT32 HorizontalResolution
;
1305 UINT32 VerticalResolution
;
1306 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1307 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1312 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1314 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1315 GraphicsOutput
= Private
->GraphicsOutput
;
1316 UgaDraw
= Private
->UgaDraw
;
1317 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1319 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1320 Status
= EFI_UNSUPPORTED
;
1325 // Make sure the requested mode number is supported
1327 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1328 Status
= EFI_UNSUPPORTED
;
1332 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1333 Status
= EFI_UNSUPPORTED
;
1337 // Attempt to allocate a line buffer for the requested mode number
1339 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1341 if (NewLineBuffer
== NULL
) {
1343 // The new line buffer could not be allocated, so return an error.
1344 // No changes to the state of the current console have been made, so the current console is still valid
1346 Status
= EFI_OUT_OF_RESOURCES
;
1350 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1352 if (Private
->LineBuffer
!= NULL
) {
1354 // Clear the current text window on the current graphics console
1356 This
->ClearScreen (This
);
1359 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1361 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1362 FreePool (NewLineBuffer
);
1363 Status
= EFI_SUCCESS
;
1367 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1368 // so erase the cursor, and free the LineBuffer for the current mode
1372 FreePool (Private
->LineBuffer
);
1375 // Assign the current line buffer to the newly allocated line buffer
1377 Private
->LineBuffer
= NewLineBuffer
;
1379 if (GraphicsOutput
!= NULL
) {
1380 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1382 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1384 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1385 if (EFI_ERROR (Status
)) {
1387 // The mode set operation failed
1393 // The current graphics mode is correct, so simply clear the entire display
1395 Status
= GraphicsOutput
->Blt (
1404 ModeData
->GopHeight
,
1408 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1410 // Get the current UGA Draw mode information
1412 Status
= UgaDraw
->GetMode (
1414 &HorizontalResolution
,
1415 &VerticalResolution
,
1419 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1421 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1423 Status
= UgaDraw
->SetMode (
1426 ModeData
->GopHeight
,
1430 if (EFI_ERROR (Status
)) {
1432 // The mode set operation failed
1438 // The current graphics mode is correct, so simply clear the entire display
1440 Status
= UgaDraw
->Blt (
1442 (EFI_UGA_PIXEL
*) (UINTN
) &mEfiColors
[0],
1449 ModeData
->GopHeight
,
1456 // The new mode is valid, so commit the mode change
1458 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1461 // Move the text cursor to the upper left hand corner of the display and enable it
1463 This
->SetCursorPosition (This
, 0, 0);
1465 Status
= EFI_SUCCESS
;
1468 gBS
->RestoreTPL (OldTpl
);
1474 Sets the background and foreground colors for the OutputString () and
1475 ClearScreen () functions.
1477 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1479 @param This Protocol instance pointer.
1480 @param Attribute The attribute to set. Bits 0..3 are the foreground
1481 color, and bits 4..6 are the background color.
1482 All other bits are undefined and must be zero.
1484 @retval EFI_SUCCESS The requested attribute is set.
1485 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1486 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1491 GraphicsConsoleConOutSetAttribute (
1492 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1498 if ((Attribute
| 0xFF) != 0xFF) {
1499 return EFI_UNSUPPORTED
;
1502 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1506 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1510 This
->Mode
->Attribute
= (INT32
) Attribute
;
1514 gBS
->RestoreTPL (OldTpl
);
1521 Clears the output device(s) display to the currently selected background
1524 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1526 @param This Protocol instance pointer.
1528 @retval EFI_SUCCESS The operation completed successfully.
1529 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1530 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1535 GraphicsConsoleConOutClearScreen (
1536 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1540 GRAPHICS_CONSOLE_DEV
*Private
;
1541 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1542 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1543 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1544 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1545 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1548 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1550 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1551 GraphicsOutput
= Private
->GraphicsOutput
;
1552 UgaDraw
= Private
->UgaDraw
;
1553 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1555 GetTextColors (This
, &Foreground
, &Background
);
1556 if (GraphicsOutput
!= NULL
) {
1557 Status
= GraphicsOutput
->Blt (
1566 ModeData
->GopHeight
,
1569 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1570 Status
= UgaDraw
->Blt (
1572 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1579 ModeData
->GopHeight
,
1583 Status
= EFI_UNSUPPORTED
;
1586 This
->Mode
->CursorColumn
= 0;
1587 This
->Mode
->CursorRow
= 0;
1591 gBS
->RestoreTPL (OldTpl
);
1598 Sets the current coordinates of the cursor position.
1600 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1602 @param This Protocol instance pointer.
1603 @param Column 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
1606 @param Row The position to set the cursor to. Must be greater than or
1607 equal to zero and less than the number of columns and rows
1610 @retval EFI_SUCCESS The operation completed successfully.
1611 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1612 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1613 cursor position is invalid for the current mode.
1618 GraphicsConsoleConOutSetCursorPosition (
1619 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1624 GRAPHICS_CONSOLE_DEV
*Private
;
1625 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1629 Status
= EFI_SUCCESS
;
1631 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1633 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1634 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1636 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1637 Status
= EFI_UNSUPPORTED
;
1641 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1642 Status
= EFI_SUCCESS
;
1648 This
->Mode
->CursorColumn
= (INT32
) Column
;
1649 This
->Mode
->CursorRow
= (INT32
) Row
;
1654 gBS
->RestoreTPL (OldTpl
);
1661 Makes the cursor visible or invisible.
1663 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1665 @param This Protocol instance pointer.
1666 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1667 the cursor is set to be invisible.
1669 @retval EFI_SUCCESS The operation completed successfully.
1674 GraphicsConsoleConOutEnableCursor (
1675 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1681 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1685 This
->Mode
->CursorVisible
= Visible
;
1689 gBS
->RestoreTPL (OldTpl
);
1694 Gets Graphics Console devcie's foreground color and background color.
1696 @param This Protocol instance pointer.
1697 @param Foreground Returned text foreground color.
1698 @param Background Returned text background color.
1700 @retval EFI_SUCCESS It returned always.
1705 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1706 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1707 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1712 Attribute
= This
->Mode
->Attribute
& 0x7F;
1714 *Foreground
= mEfiColors
[Attribute
& 0x0f];
1715 *Background
= mEfiColors
[Attribute
>> 4];
1721 Draw Unicode string on the Graphics Console device's screen.
1723 @param This Protocol instance pointer.
1724 @param UnicodeWeight One Unicode string to be displayed.
1725 @param Count The count of Unicode string.
1727 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1728 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1730 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1734 DrawUnicodeWeightAtCursorN (
1735 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1736 IN CHAR16
*UnicodeWeight
,
1741 GRAPHICS_CONSOLE_DEV
*Private
;
1742 EFI_IMAGE_OUTPUT
*Blt
;
1744 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1745 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1746 EFI_HII_ROW_INFO
*RowInfoArray
;
1747 UINTN RowInfoArraySize
;
1749 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1750 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1752 return EFI_OUT_OF_RESOURCES
;
1755 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1756 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1758 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1759 if (String
== NULL
) {
1761 return EFI_OUT_OF_RESOURCES
;
1764 // Set the end character
1766 *(String
+ Count
) = L
'\0';
1768 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1769 if (FontInfo
== NULL
) {
1772 return EFI_OUT_OF_RESOURCES
;
1775 // Get current foreground and background colors.
1777 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1779 if (Private
->GraphicsOutput
!= NULL
) {
1781 // If Graphics Output protocol exists, using HII Font protocol to draw.
1783 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1785 Status
= mHiiFont
->StringToImage (
1787 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
,
1791 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1792 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1798 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1800 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1801 // using UGA Draw protocol to draw.
1803 ASSERT (Private
->UgaDraw
!= NULL
);
1805 UgaDraw
= Private
->UgaDraw
;
1807 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1808 if (Blt
->Image
.Bitmap
== NULL
) {
1811 return EFI_OUT_OF_RESOURCES
;
1814 RowInfoArray
= NULL
;
1816 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1817 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1819 Status
= mHiiFont
->StringToImage (
1821 EFI_HII_IGNORE_IF_NO_GLYPH
,
1825 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1826 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1832 if (!EFI_ERROR (Status
)) {
1834 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1835 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1837 ASSERT (RowInfoArraySize
<= 1);
1839 Status
= UgaDraw
->Blt (
1841 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1842 EfiUgaBltBufferToVideo
,
1843 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1844 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
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 RowInfoArray
[0].LineWidth
,
1848 RowInfoArray
[0].LineHeight
,
1849 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1853 FreePool (RowInfoArray
);
1854 FreePool (Blt
->Image
.Bitmap
);
1856 Status
= EFI_UNSUPPORTED
;
1862 if (String
!= NULL
) {
1865 if (FontInfo
!= NULL
) {
1866 FreePool (FontInfo
);
1872 Erase the cursor on the screen.
1874 @param This Protocol instance pointer.
1876 @retval EFI_SUCCESS The cursor is erased successfully.
1881 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1884 GRAPHICS_CONSOLE_DEV
*Private
;
1885 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1888 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1889 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1890 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1891 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1892 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1896 CurrentMode
= This
->Mode
;
1898 if (!CurrentMode
->CursorVisible
) {
1902 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1903 GraphicsOutput
= Private
->GraphicsOutput
;
1904 UgaDraw
= Private
->UgaDraw
;
1907 // In this driver, only narrow character was supported.
1910 // Blt a character to the screen
1912 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1913 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1914 if (GraphicsOutput
!= NULL
) {
1915 GraphicsOutput
->Blt (
1917 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1918 EfiBltVideoToBltBuffer
,
1925 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1927 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1930 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1931 EfiUgaVideoToBltBuffer
,
1938 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1942 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1945 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1947 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1948 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1949 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1950 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1955 if (GraphicsOutput
!= NULL
) {
1956 GraphicsOutput
->Blt (
1958 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1959 EfiBltBufferToVideo
,
1966 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1968 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1971 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1972 EfiUgaBltBufferToVideo
,
1979 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1987 The user Entry Point for module GraphicsConsole. The user code starts with this function.
1989 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1990 @param[in] SystemTable A pointer to the EFI System Table.
1992 @retval EFI_SUCCESS The entry point is executed successfully.
1993 @retval other Some error occurs when executing this entry point.
1998 InitializeGraphicsConsole (
1999 IN EFI_HANDLE ImageHandle
,
2000 IN EFI_SYSTEM_TABLE
*SystemTable
2006 // Install driver model protocol(s).
2008 Status
= EfiLibInstallDriverBindingComponentName2 (
2011 &gGraphicsConsoleDriverBinding
,
2013 &gGraphicsConsoleComponentName
,
2014 &gGraphicsConsoleComponentName2
2016 ASSERT_EFI_ERROR (Status
);