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"
19 // Graphics Console Devcie Private Data template
21 GRAPHICS_CONSOLE_DEV mGraphicsConsoleDevTemplate
= {
22 GRAPHICS_CONSOLE_DEV_SIGNATURE
,
23 (EFI_GRAPHICS_OUTPUT_PROTOCOL
*) NULL
,
24 (EFI_UGA_DRAW_PROTOCOL
*) NULL
,
26 GraphicsConsoleConOutReset
,
27 GraphicsConsoleConOutOutputString
,
28 GraphicsConsoleConOutTestString
,
29 GraphicsConsoleConOutQueryMode
,
30 GraphicsConsoleConOutSetMode
,
31 GraphicsConsoleConOutSetAttribute
,
32 GraphicsConsoleConOutClearScreen
,
33 GraphicsConsoleConOutSetCursorPosition
,
34 GraphicsConsoleConOutEnableCursor
,
35 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
40 EFI_TEXT_ATTR(EFI_LIGHTGRAY
, EFI_BLACK
),
46 { 80, 25, 0, 0, 0, 0 }, // Mode 0
47 { 80, 50, 0, 0, 0, 0 }, // Mode 1
48 { 100,31, 0, 0, 0, 0 }, // Mode 2
49 { 0, 0, 0, 0, 0, 0 } // Mode 3
51 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
,
55 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
56 EFI_HII_FONT_PROTOCOL
*mHiiFont
;
57 BOOLEAN mFirstAccessFlag
= TRUE
;
59 EFI_GUID mFontPackageListGuid
= {0xf5f219d3, 0x7006, 0x4648, {0xac, 0x8d, 0xd6, 0x1d, 0xfb, 0x7b, 0xc6, 0xad}};
61 CHAR16 mCrLfString
[3] = { CHAR_CARRIAGE_RETURN
, CHAR_LINEFEED
, CHAR_NULL
};
63 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors
[16] = {
67 {0x00, 0x00, 0x00, 0x00}, // BLACK
68 {0x98, 0x00, 0x00, 0x00}, // BLUE
69 {0x00, 0x98, 0x00, 0x00}, // GREEN
70 {0x98, 0x98, 0x00, 0x00}, // CYAN
71 {0x00, 0x00, 0x98, 0x00}, // RED
72 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
73 {0x00, 0x98, 0x98, 0x00}, // BROWN
74 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
75 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
76 {0xff, 0x00, 0x00, 0x00}, // LIGHTBLUE - ?
77 {0x00, 0xff, 0x00, 0x00}, // LIGHTGREEN - ?
78 {0xff, 0xff, 0x00, 0x00}, // LIGHTCYAN
79 {0x00, 0x00, 0xff, 0x00}, // LIGHTRED
80 {0xff, 0x00, 0xff, 0x00}, // LIGHTMAGENTA
81 {0x00, 0xff, 0xff, 0x00}, // LIGHTBROWN
82 {0xff, 0xff, 0xff, 0x00} // WHITE
85 EFI_NARROW_GLYPH mCursorGlyph
= {
88 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF }
91 CHAR16 SpaceStr
[] = { NARROW_CHAR
, ' ', 0 };
93 EFI_DRIVER_BINDING_PROTOCOL gGraphicsConsoleDriverBinding
= {
94 GraphicsConsoleControllerDriverSupported
,
95 GraphicsConsoleControllerDriverStart
,
96 GraphicsConsoleControllerDriverStop
,
103 Gets Graphics Console devcie's foreground color and background color.
105 @param This Protocol instance pointer.
106 @param Foreground Returned text foreground color.
107 @param Background Returned text background color.
109 @retval EFI_SUCCESS It returned always.
114 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
115 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
116 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
120 Draw Unicode string on the Graphice Console device's screen.
122 @param This Protocol instance pointer.
123 @param UnicodeWeight One Unicode string to be displayed.
124 @param Count The count of Unicode string.
126 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
127 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
129 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
133 DrawUnicodeWeightAtCursorN (
134 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
135 IN CHAR16
*UnicodeWeight
,
140 Erase the cursor on the screen.
142 @param This Protocol instance pointer.
144 @retval EFI_SUCCESS The cursor is erased successfully.
149 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
153 Check if the current specific mode supported the user defined resolution
154 for the Graphice Console devcie based on Graphics Output Protocol.
156 If yes, set the graphic devcice's current mode to this specific mode.
158 @param GraphicsOutput Graphics Output Protocol instance pointer.
159 @param HorizontalResolution User defined horizontal resolution
160 @param VerticalResolution User defined vertical resolution.
161 @param CurrentModeNumber Current specific mode to be check.
163 @retval EFI_SUCCESS The mode is supported.
164 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
166 @retval other The specific mode does not support user defined
167 resolution or failed to set the current mode to the
168 specific mode on graphics device.
173 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
174 IN UINT32 HorizontalResolution
,
175 IN UINT32 VerticalResolution
,
176 OUT UINT32
*CurrentModeNumber
181 Test to see if Graphics Console could be supported on the Controller.
183 Graphics Console could be supported if Graphics Output Protocol or UGA Draw
184 Protocol exists on the Controller. (UGA Draw Protocol could be skipped
185 if PcdUgaConsumeSupport is set to FALSE.)
187 @param This Protocol instance pointer.
188 @param Controller Handle of device to test.
189 @param RemainingDevicePath Optional parameter use to pick a specific child
192 @retval EFI_SUCCESS This driver supports this device.
193 @retval other This driver does not support this device.
198 GraphicsConsoleControllerDriverSupported (
199 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
200 IN EFI_HANDLE Controller
,
201 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
205 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
206 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
207 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
209 GraphicsOutput
= NULL
;
212 // Open the IO Abstraction(s) needed to perform the supported test
214 Status
= gBS
->OpenProtocol (
216 &gEfiGraphicsOutputProtocolGuid
,
217 (VOID
**) &GraphicsOutput
,
218 This
->DriverBindingHandle
,
220 EFI_OPEN_PROTOCOL_BY_DRIVER
223 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
225 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
227 Status
= gBS
->OpenProtocol (
229 &gEfiUgaDrawProtocolGuid
,
231 This
->DriverBindingHandle
,
233 EFI_OPEN_PROTOCOL_BY_DRIVER
236 if (EFI_ERROR (Status
)) {
241 // We need to ensure that we do not layer on top of a virtual handle.
242 // We need to ensure that the handles produced by the conspliter do not
245 Status
= gBS
->OpenProtocol (
247 &gEfiDevicePathProtocolGuid
,
248 (VOID
**) &DevicePath
,
249 This
->DriverBindingHandle
,
251 EFI_OPEN_PROTOCOL_BY_DRIVER
253 if (!EFI_ERROR (Status
)) {
256 &gEfiDevicePathProtocolGuid
,
257 This
->DriverBindingHandle
,
265 // Does Hii Exist? If not, we aren't ready to run
267 Status
= EfiLocateHiiProtocol ();
270 // Close the I/O Abstraction(s) used to perform the supported test
273 if (GraphicsOutput
!= NULL
) {
276 &gEfiGraphicsOutputProtocolGuid
,
277 This
->DriverBindingHandle
,
280 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
283 &gEfiUgaDrawProtocolGuid
,
284 This
->DriverBindingHandle
,
293 Start this driver on Controller by opening Graphics Output protocol or
294 UGA Draw protocol, and installing Simple Text Out protocol on Controller.
295 (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)
297 @param This Protocol instance pointer.
298 @param Controller Handle of device to bind driver to
299 @param RemainingDevicePath Optional parameter use to pick a specific child
302 @retval EFI_SUCCESS This driver is added to Controller.
303 @retval other This driver does not support this device.
308 GraphicsConsoleControllerDriverStart (
309 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
310 IN EFI_HANDLE Controller
,
311 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
315 GRAPHICS_CONSOLE_DEV
*Private
;
316 UINTN NarrowFontSize
;
317 UINT32 HorizontalResolution
;
318 UINT32 VerticalResolution
;
325 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
327 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
334 // Initialize the Graphics Console device instance
336 Private
= AllocateCopyPool (
337 sizeof (GRAPHICS_CONSOLE_DEV
),
338 &mGraphicsConsoleDevTemplate
340 if (Private
== NULL
) {
341 return EFI_OUT_OF_RESOURCES
;
344 Private
->SimpleTextOutput
.Mode
= &(Private
->SimpleTextOutputMode
);
346 Status
= gBS
->OpenProtocol (
348 &gEfiGraphicsOutputProtocolGuid
,
349 (VOID
**) &Private
->GraphicsOutput
,
350 This
->DriverBindingHandle
,
352 EFI_OPEN_PROTOCOL_BY_DRIVER
355 if (EFI_ERROR(Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
356 Status
= gBS
->OpenProtocol (
358 &gEfiUgaDrawProtocolGuid
,
359 (VOID
**) &Private
->UgaDraw
,
360 This
->DriverBindingHandle
,
362 EFI_OPEN_PROTOCOL_BY_DRIVER
366 if (EFI_ERROR (Status
)) {
370 NarrowFontSize
= ReturnNarrowFontSize ();
372 if (mFirstAccessFlag
) {
374 // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only.
375 // Looks ugly. Might be updated when font tool is ready.
377 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + NarrowFontSize
+ 4;
378 Package
= AllocateZeroPool (PackageLength
);
379 if (Package
== NULL
) {
380 return EFI_OUT_OF_RESOURCES
;
382 CopyMem (Package
, &PackageLength
, 4);
383 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
384 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
385 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
386 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (NarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
388 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
389 CopyMem (Location
, gUsStdNarrowGlyphData
, NarrowFontSize
);
392 // Add this simplified font package to a package list then install it.
394 PackageList
= HiiLibPreparePackageList (1, &mFontPackageListGuid
, Package
);
395 Status
= mHiiDatabase
->NewPackageList (mHiiDatabase
, PackageList
, NULL
, &(Private
->HiiHandle
));
396 ASSERT_EFI_ERROR (Status
);
397 FreePool (PackageList
);
400 mFirstAccessFlag
= FALSE
;
403 // If the current mode information can not be retrieved, then attemp to set the default mode
404 // of 800x600, 32 bit colot, 60 Hz refresh.
406 HorizontalResolution
= 800;
407 VerticalResolution
= 600;
409 if (Private
->GraphicsOutput
!= NULL
) {
411 // The console is build on top of Graphics Output Protocol, find the mode number
412 // for the user-defined mode; if there are multiple video devices,
413 // graphic console driver will set all the video devices to the same mode.
415 Status
= CheckModeSupported (
416 Private
->GraphicsOutput
,
417 CURRENT_HORIZONTAL_RESOLUTION
,
418 CURRENT_VERTICAL_RESOLUTION
,
421 if (!EFI_ERROR(Status
)) {
423 // Update default mode to current mode
425 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
426 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
429 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
431 Status
= CheckModeSupported (
432 Private
->GraphicsOutput
,
439 if (EFI_ERROR (Status
) || (ModeNumber
== Private
->GraphicsOutput
->Mode
->MaxMode
)) {
441 // Set default mode failed or device don't support default mode, then get the current mode information
443 HorizontalResolution
= Private
->GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
444 VerticalResolution
= Private
->GraphicsOutput
->Mode
->Info
->VerticalResolution
;
445 ModeNumber
= Private
->GraphicsOutput
->Mode
->Mode
;
447 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
449 // At first try to set user-defined resolution
453 Status
= Private
->UgaDraw
->SetMode (
455 CURRENT_HORIZONTAL_RESOLUTION
,
456 CURRENT_VERTICAL_RESOLUTION
,
460 if (!EFI_ERROR (Status
)) {
461 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
462 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
463 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
465 // Try to set 800*600 which is required by UEFI/EFI spec
467 Status
= Private
->UgaDraw
->SetMode (
469 HorizontalResolution
,
474 if (EFI_ERROR (Status
)) {
475 Status
= Private
->UgaDraw
->GetMode (
477 &HorizontalResolution
,
482 if (EFI_ERROR (Status
)) {
487 Status
= EFI_UNSUPPORTED
;
493 // Compute the maximum number of text Rows and Columns that this current graphics mode can support
495 Columns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
496 Rows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
499 // See if the mode is too small to support the required 80x25 text mode
501 if (Columns
< 80 || Rows
< 25) {
505 // Add Mode #0 that must be 80x25
508 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
509 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
510 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
511 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
512 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (25 * EFI_GLYPH_HEIGHT
)) >> 1;
516 // If it is possible to support Mode #1 - 80x50, than add it as an active mode
519 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
520 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
521 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
522 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (80 * EFI_GLYPH_WIDTH
)) >> 1;
523 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (50 * EFI_GLYPH_HEIGHT
)) >> 1;
528 // If it is not to support Mode #1 - 80x50, then skip it
531 Private
->ModeData
[MaxMode
].Columns
= 0;
532 Private
->ModeData
[MaxMode
].Rows
= 0;
533 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
534 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
535 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
536 Private
->ModeData
[MaxMode
].DeltaX
= 0;
537 Private
->ModeData
[MaxMode
].DeltaY
= 0;
542 // Add Mode #2 that must be 100x31 (graphic mode >= 800x600)
544 if (Columns
>= 100 && Rows
>= 31) {
545 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
546 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
547 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
548 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
- (100 * EFI_GLYPH_WIDTH
)) >> 1;
549 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
- (31 * EFI_GLYPH_HEIGHT
)) >> 1;
554 // Add Mode #3 that uses the entire display for user-defined mode
556 if (HorizontalResolution
> 800 && VerticalResolution
> 600) {
557 Private
->ModeData
[MaxMode
].Columns
= HorizontalResolution
/EFI_GLYPH_WIDTH
;
558 Private
->ModeData
[MaxMode
].Rows
= VerticalResolution
/EFI_GLYPH_HEIGHT
;
559 Private
->ModeData
[MaxMode
].GopWidth
= HorizontalResolution
;
560 Private
->ModeData
[MaxMode
].GopHeight
= VerticalResolution
;
561 Private
->ModeData
[MaxMode
].GopModeNumber
= ModeNumber
;
562 Private
->ModeData
[MaxMode
].DeltaX
= (HorizontalResolution
% EFI_GLYPH_WIDTH
) >> 1;
563 Private
->ModeData
[MaxMode
].DeltaY
= (VerticalResolution
% EFI_GLYPH_HEIGHT
) >> 1;
568 // Update the maximum number of modes
570 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
573 // Determine the number of text modes that this protocol can support
575 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
576 if (EFI_ERROR (Status
)) {
581 GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
585 // Install protocol interfaces for the Graphics Console device.
587 Status
= gBS
->InstallMultipleProtocolInterfaces (
589 &gEfiSimpleTextOutProtocolGuid
,
590 &Private
->SimpleTextOutput
,
595 if (EFI_ERROR (Status
)) {
597 // Close the GOP and UGA Draw Protocol
599 if (Private
->GraphicsOutput
!= NULL
) {
602 &gEfiGraphicsOutputProtocolGuid
,
603 This
->DriverBindingHandle
,
606 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
609 &gEfiUgaDrawProtocolGuid
,
610 This
->DriverBindingHandle
,
618 if (Private
!= NULL
) {
619 if (Private
->LineBuffer
!= NULL
) {
620 FreePool (Private
->LineBuffer
);
630 Stop this driver on Controller by removing Simple Text Out protocol
631 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
632 (UGA Draw protocol could be shkipped if PcdUgaConsumeSupport is set to FALSE.)
635 @param This Protocol instance pointer.
636 @param Controller Handle of device to stop driver on
637 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
638 children is zero stop the entire bus driver.
639 @param ChildHandleBuffer List of Child Handles to Stop.
641 @retval EFI_SUCCESS This driver is removed Controller.
642 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
644 @retval other This driver was not removed from this device.
649 GraphicsConsoleControllerDriverStop (
650 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
651 IN EFI_HANDLE Controller
,
652 IN UINTN NumberOfChildren
,
653 IN EFI_HANDLE
*ChildHandleBuffer
657 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
658 GRAPHICS_CONSOLE_DEV
*Private
;
660 Status
= gBS
->OpenProtocol (
662 &gEfiSimpleTextOutProtocolGuid
,
663 (VOID
**) &SimpleTextOutput
,
664 This
->DriverBindingHandle
,
666 EFI_OPEN_PROTOCOL_GET_PROTOCOL
668 if (EFI_ERROR (Status
)) {
669 return EFI_NOT_STARTED
;
672 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
674 Status
= gBS
->UninstallProtocolInterface (
676 &gEfiSimpleTextOutProtocolGuid
,
677 &Private
->SimpleTextOutput
680 if (!EFI_ERROR (Status
)) {
682 // Close the GOP or UGA IO Protocol
684 if (Private
->GraphicsOutput
!= NULL
) {
687 &gEfiGraphicsOutputProtocolGuid
,
688 This
->DriverBindingHandle
,
691 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
694 &gEfiUgaDrawProtocolGuid
,
695 This
->DriverBindingHandle
,
701 // Remove the font pack
703 if (Private
->HiiHandle
!= NULL
) {
704 HiiLibRemovePackages (Private
->HiiHandle
);
705 mFirstAccessFlag
= TRUE
;
709 // Free our instance data
711 if (Private
!= NULL
) {
712 FreePool (Private
->LineBuffer
);
721 Check if the current specific mode supported the user defined resolution
722 for the Graphice Console devcie based on Graphics Output Protocol.
724 If yes, set the graphic devcice's current mode to this specific mode.
726 @param GraphicsOutput Graphics Output Protocol instance pointer.
727 @param HorizontalResolution User defined horizontal resolution
728 @param VerticalResolution User defined vertical resolution.
729 @param CurrentModeNumber Current specific mode to be check.
731 @retval EFI_SUCCESS The mode is supported.
732 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
734 @retval other The specific mode does not support user defined
735 resolution or failed to set the current mode to the
736 specific mode on graphics device.
741 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
742 IN UINT32 HorizontalResolution
,
743 IN UINT32 VerticalResolution
,
744 OUT UINT32
*CurrentModeNumber
750 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
752 Status
= EFI_SUCCESS
;
754 for (ModeNumber
= 0; ModeNumber
< GraphicsOutput
->Mode
->MaxMode
; ModeNumber
++) {
755 Status
= GraphicsOutput
->QueryMode (
761 if (!EFI_ERROR (Status
)) {
762 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
763 (Info
->VerticalResolution
== VerticalResolution
)) {
764 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
765 if (!EFI_ERROR (Status
)) {
766 gBS
->FreePool (Info
);
770 gBS
->FreePool (Info
);
774 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
775 Status
= EFI_UNSUPPORTED
;
778 *CurrentModeNumber
= ModeNumber
;
784 Locate HII Database protocol and HII Font protocol.
786 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
787 are located successfully.
788 @return other Failed to locate HII Database protocol or
793 EfiLocateHiiProtocol (
802 // There should only be one - so buffer size is this
804 Size
= sizeof (EFI_HANDLE
);
806 Status
= gBS
->LocateHandle (
808 &gEfiHiiDatabaseProtocolGuid
,
814 if (EFI_ERROR (Status
)) {
818 Status
= gBS
->HandleProtocol (
820 &gEfiHiiDatabaseProtocolGuid
,
821 (VOID
**) &mHiiDatabase
824 if (EFI_ERROR (Status
)) {
828 Status
= gBS
->HandleProtocol (
830 &gEfiHiiFontProtocolGuid
,
837 // Body of the STO functions
841 Reset the text output device hardware and optionaly run diagnostics.
843 Implements SIMPLE_TEXT_OUTPUT.Reset().
844 If ExtendeVerification is TRUE, then perform dependent Graphics Console
845 device reset, and set display mode to mode 0.
846 If ExtendedVerification is FALSE, only set display mode to mode 0.
848 @param This Protocol instance pointer.
849 @param ExtendedVerification Indicates that the driver may perform a more
850 exhaustive verification operation of the device
853 @retval EFI_SUCCESS The text output device was reset.
854 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
860 GraphicsConsoleConOutReset (
861 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
862 IN BOOLEAN ExtendedVerification
865 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
866 return This
->SetMode (This
, 0);
871 Write a Unicode string to the output device.
873 Implements SIMPLE_TEXT_OUTPUT.OutputString().
874 The Unicode string will be converted to Glyphs and will be
875 sent to the Graphics Console.
877 @param This Protocol instance pointer.
878 @param WString The NULL-terminated Unicode string to be displayed
879 on the output device(s). All output devices must
880 also support the Unicode drawing defined in this file.
882 @retval EFI_SUCCESS The string was output to the device.
883 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
885 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
887 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
888 characters in the Unicode string could not be
889 rendered and were skipped.
894 GraphicsConsoleConOutOutputString (
895 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
899 GRAPHICS_CONSOLE_DEV
*Private
;
900 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
901 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
910 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
911 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
916 INT32 OriginAttribute
;
919 Status
= EFI_SUCCESS
;
921 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
925 Mode
= This
->Mode
->Mode
;
926 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
927 GraphicsOutput
= Private
->GraphicsOutput
;
928 UgaDraw
= Private
->UgaDraw
;
930 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
931 MaxRow
= Private
->ModeData
[Mode
].Rows
;
932 DeltaX
= Private
->ModeData
[Mode
].DeltaX
;
933 DeltaY
= Private
->ModeData
[Mode
].DeltaY
;
934 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
935 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
936 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
939 // The Attributes won't change when during the time OutputString is called
941 GetTextColors (This
, &Foreground
, &Background
);
950 OriginAttribute
= This
->Mode
->Attribute
;
952 while (*WString
!= L
'\0') {
954 if (*WString
== CHAR_BACKSPACE
) {
956 // If the cursor is at the left edge of the display, then move the cursor
959 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
960 This
->Mode
->CursorRow
--;
961 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
962 This
->OutputString (This
, SpaceStr
);
964 This
->Mode
->CursorRow
--;
965 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
966 } else if (This
->Mode
->CursorColumn
> 0) {
968 // If the cursor is not at the left edge of the display, then move the cursor
971 This
->Mode
->CursorColumn
--;
972 This
->OutputString (This
, SpaceStr
);
974 This
->Mode
->CursorColumn
--;
979 } else if (*WString
== CHAR_LINEFEED
) {
981 // If the cursor is at the bottom of the display, then scroll the display one
982 // row, and do not update the cursor position. Otherwise, move the cursor
985 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
986 if (GraphicsOutput
!= NULL
) {
988 // Scroll Screen Up One Row
990 GraphicsOutput
->Blt (
995 DeltaY
+ EFI_GLYPH_HEIGHT
,
1004 // Print Blank Line at last line
1006 GraphicsOutput
->Blt (
1018 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1020 // Scroll Screen Up One Row
1027 DeltaY
+ EFI_GLYPH_HEIGHT
,
1036 // Print Blank Line at last line
1040 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1052 This
->Mode
->CursorRow
++;
1057 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
1059 // Move the cursor to the beginning of the current row.
1061 This
->Mode
->CursorColumn
= 0;
1064 } else if (*WString
== WIDE_CHAR
) {
1066 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
1069 } else if (*WString
== NARROW_CHAR
) {
1071 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
1076 // Print the character at the current cursor position and move the cursor
1077 // right one column. If this moves the cursor past the right edge of the
1078 // display, then the line should wrap to the beginning of the next line. This
1079 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
1080 // bottom of the display, and the line wraps, then the display will be scrolled
1082 // If wide char is going to be displayed, need to display one character at a time
1083 // Or, need to know the display length of a certain string.
1085 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1086 // Count is used to determine how many characters are used regardless of their attributes
1088 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1089 if (WString
[Count
] == CHAR_NULL
) {
1093 if (WString
[Count
] == CHAR_BACKSPACE
) {
1097 if (WString
[Count
] == CHAR_LINEFEED
) {
1101 if (WString
[Count
] == CHAR_CARRIAGE_RETURN
) {
1105 if (WString
[Count
] == WIDE_CHAR
) {
1109 if (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 grapghics 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 grapghics 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 displat 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 Graphice 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 Graphcis 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
] & (1 << 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
);