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