2 This is the main routine for initializing the Graphics Console support routines.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 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, 0 }, // Mode 0
46 { 80, 50, 0, 0, 0, 0, 0 }, // Mode 1
47 { 100,31, 0, 0, 0, 0, 0 }, // Mode 2
48 { 0, 0, 0, 0, 0, 0, 0 }, // Mode 3
49 { 0, 0, 0, 0, 0, 0, 0 } // Mode 4
51 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
54 EFI_HII_DATABASE_PROTOCOL
*mHiiDatabase
;
55 EFI_HII_FONT_PROTOCOL
*mHiiFont
;
56 EFI_HII_HANDLE mHiiHandle
;
57 EFI_EVENT mHiiRegistration
;
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 mGraphicsEfiColors
[16] = {
67 {0x00, 0x00, 0x00, 0x00}, // BLACK
68 {0x98, 0x00, 0x00, 0x00}, // LIGHTBLUE
69 {0x00, 0x98, 0x00, 0x00}, // LIGHGREEN
70 {0x98, 0x98, 0x00, 0x00}, // LIGHCYAN
71 {0x00, 0x00, 0x98, 0x00}, // LIGHRED
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}, // BLUE
77 {0x00, 0xff, 0x00, 0x00}, // LIME
78 {0xff, 0xff, 0x00, 0x00}, // CYAN
79 {0x00, 0x00, 0xff, 0x00}, // RED
80 {0xff, 0x00, 0xff, 0x00}, // FUCHSIA
81 {0x00, 0xff, 0xff, 0x00}, // YELLOW
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 Test to see if Graphics Console could be supported on the Controller.
105 Graphics Console could be supported if Graphics Output Protocol or UGA Draw
106 Protocol exists on the Controller. (UGA Draw Protocol could be skipped
107 if PcdUgaConsumeSupport is set to FALSE.)
109 @param This Protocol instance pointer.
110 @param Controller Handle of device to test.
111 @param RemainingDevicePath Optional parameter use to pick a specific child
114 @retval EFI_SUCCESS This driver supports this device.
115 @retval other This driver does not support this device.
120 GraphicsConsoleControllerDriverSupported (
121 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
122 IN EFI_HANDLE Controller
,
123 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
127 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
128 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
129 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
131 GraphicsOutput
= NULL
;
134 // Open the IO Abstraction(s) needed to perform the supported test
136 Status
= gBS
->OpenProtocol (
138 &gEfiGraphicsOutputProtocolGuid
,
139 (VOID
**) &GraphicsOutput
,
140 This
->DriverBindingHandle
,
142 EFI_OPEN_PROTOCOL_BY_DRIVER
145 if (EFI_ERROR (Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
147 // Open Graphics Output Protocol failed, try to open UGA Draw Protocol
149 Status
= gBS
->OpenProtocol (
151 &gEfiUgaDrawProtocolGuid
,
153 This
->DriverBindingHandle
,
155 EFI_OPEN_PROTOCOL_BY_DRIVER
158 if (EFI_ERROR (Status
)) {
163 // We need to ensure that we do not layer on top of a virtual handle.
164 // We need to ensure that the handles produced by the conspliter do not
167 Status
= gBS
->OpenProtocol (
169 &gEfiDevicePathProtocolGuid
,
170 (VOID
**) &DevicePath
,
171 This
->DriverBindingHandle
,
173 EFI_OPEN_PROTOCOL_BY_DRIVER
175 if (!EFI_ERROR (Status
)) {
178 &gEfiDevicePathProtocolGuid
,
179 This
->DriverBindingHandle
,
187 // Does Hii Exist? If not, we aren't ready to run
189 Status
= EfiLocateHiiProtocol ();
192 // Close the I/O Abstraction(s) used to perform the supported test
195 if (GraphicsOutput
!= NULL
) {
198 &gEfiGraphicsOutputProtocolGuid
,
199 This
->DriverBindingHandle
,
202 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
205 &gEfiUgaDrawProtocolGuid
,
206 This
->DriverBindingHandle
,
215 Start this driver on Controller by opening Graphics Output protocol or
216 UGA Draw protocol, and installing Simple Text Out protocol on Controller.
217 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
219 @param This Protocol instance pointer.
220 @param Controller Handle of device to bind driver to
221 @param RemainingDevicePath Optional parameter use to pick a specific child
224 @retval EFI_SUCCESS This driver is added to Controller.
225 @retval other This driver does not support this device.
230 GraphicsConsoleControllerDriverStart (
231 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
232 IN EFI_HANDLE Controller
,
233 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
237 GRAPHICS_CONSOLE_DEV
*Private
;
238 UINT32 HorizontalResolution
;
239 UINT32 VerticalResolution
;
247 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*Mode
;
248 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
250 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
251 BOOLEAN TextModeFound
;
256 // Initialize the Graphics Console device instance
258 Private
= AllocateCopyPool (
259 sizeof (GRAPHICS_CONSOLE_DEV
),
260 &mGraphicsConsoleDevTemplate
262 if (Private
== NULL
) {
263 return EFI_OUT_OF_RESOURCES
;
266 Private
->SimpleTextOutput
.Mode
= &(Private
->SimpleTextOutputMode
);
268 Status
= gBS
->OpenProtocol (
270 &gEfiGraphicsOutputProtocolGuid
,
271 (VOID
**) &Private
->GraphicsOutput
,
272 This
->DriverBindingHandle
,
274 EFI_OPEN_PROTOCOL_BY_DRIVER
277 if (EFI_ERROR(Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
278 Status
= gBS
->OpenProtocol (
280 &gEfiUgaDrawProtocolGuid
,
281 (VOID
**) &Private
->UgaDraw
,
282 This
->DriverBindingHandle
,
284 EFI_OPEN_PROTOCOL_BY_DRIVER
288 if (EFI_ERROR (Status
)) {
292 HorizontalResolution
= PcdGet32 (PcdVideoHorizontalResolution
);
293 VerticalResolution
= PcdGet32 (PcdVideoVerticalResolution
);
295 if (Private
->GraphicsOutput
!= NULL
) {
297 // The console is build on top of Graphics Output Protocol, find the mode number
298 // for the user-defined mode; if there are multiple video devices,
299 // graphic console driver will set all the video devices to the same mode.
301 if ((HorizontalResolution
== 0x0) || (VerticalResolution
== 0x0)) {
303 // Find the highest resolution which GOP supports.
305 MaxMode
= Private
->GraphicsOutput
->Mode
->MaxMode
;
307 for (ModeIndex
= 0; ModeIndex
< MaxMode
; ModeIndex
++) {
308 Status
= Private
->GraphicsOutput
->QueryMode (
309 Private
->GraphicsOutput
,
314 if (!EFI_ERROR (Status
)) {
315 if ((Info
->HorizontalResolution
>= HorizontalResolution
) &&
316 (Info
->VerticalResolution
>= VerticalResolution
)) {
317 HorizontalResolution
= Info
->HorizontalResolution
;
318 VerticalResolution
= Info
->VerticalResolution
;
319 ModeNumber
= ModeIndex
;
324 if ((HorizontalResolution
== 0x0) || (VerticalResolution
== 0x0)) {
325 Status
= EFI_UNSUPPORTED
;
330 // Use user-defined resolution
332 Status
= CheckModeSupported (
333 Private
->GraphicsOutput
,
334 HorizontalResolution
,
338 if (EFI_ERROR (Status
)) {
340 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
342 Status
= CheckModeSupported (
343 Private
->GraphicsOutput
,
348 Mode
= Private
->GraphicsOutput
->Mode
;
349 if (EFI_ERROR (Status
) && Mode
->MaxMode
!= 0) {
351 // Set default mode failed or device don't support default mode, then get the current mode information
353 HorizontalResolution
= Mode
->Info
->HorizontalResolution
;
354 VerticalResolution
= Mode
->Info
->VerticalResolution
;
355 ModeNumber
= Mode
->Mode
;
359 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
361 // At first try to set user-defined resolution
365 Status
= Private
->UgaDraw
->SetMode (
367 HorizontalResolution
,
372 if (EFI_ERROR (Status
)) {
374 // Try to set 800*600 which is required by UEFI/EFI spec
376 Status
= Private
->UgaDraw
->SetMode (
383 if (EFI_ERROR (Status
)) {
384 Status
= Private
->UgaDraw
->GetMode (
386 &HorizontalResolution
,
391 if (EFI_ERROR (Status
)) {
396 Status
= EFI_UNSUPPORTED
;
402 // Include the existing pre-defined 80x25, 80x50 and 100x31
403 // in mGraphicsConsoleDevTemplate.
408 // Compute the maximum number of text Rows and Columns that this current graphics mode can support
410 MaxColumns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
411 MaxRows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
414 // Add Mode #3 that uses the entire display for user-defined mode
416 Private
->ModeData
[MaxMode
].Columns
= MaxColumns
;
417 Private
->ModeData
[MaxMode
].Rows
= MaxRows
;
421 // Add Mode #4 that uses the PCD values
423 Private
->ModeData
[MaxMode
].Columns
= (UINTN
) PcdGet32 (PcdConOutColumn
);
424 Private
->ModeData
[MaxMode
].Rows
= (UINTN
) PcdGet32 (PcdConOutRow
);
425 if ((Private
->ModeData
[MaxMode
].Columns
!= 0) && (Private
->ModeData
[MaxMode
].Rows
!= 0)) {
430 // Here we make sure that mode 0 is valid
432 if (MaxColumns
< Private
->ModeData
[0].Columns
||
433 MaxRows
< Private
->ModeData
[0].Rows
) {
435 // 80x25 cannot be supported.
437 if ((Private
->ModeData
[4].Columns
!= 0) && (Private
->ModeData
[4].Rows
!= 0)) {
439 // Fallback to using the Mode 4 for mode 0 if PcdConOutColumn and PcdConOutRow
440 // are not 0. If the PCDs are also too large, then mode 0
441 // will be shrunk to fit as needed. If the PCDs are all 0,
442 // then mode 0 will be the entire display.
444 Private
->ModeData
[0].Columns
= MIN (Private
->ModeData
[4].Columns
, MaxColumns
);
445 Private
->ModeData
[0].Rows
= MIN (Private
->ModeData
[4].Rows
, MaxRows
);
447 Private
->ModeData
[0].Columns
= MaxColumns
;
448 Private
->ModeData
[0].Rows
= MaxRows
;
452 TextModeFound
= FALSE
;
453 for (ModeIndex
= 0; ModeIndex
< GRAPHICS_MAX_MODE
; ModeIndex
++) {
454 ModeData
= &Private
->ModeData
[ModeIndex
];
455 ModeData
->GopWidth
= HorizontalResolution
;
456 ModeData
->GopHeight
= VerticalResolution
;
457 ModeData
->GopModeNumber
= ModeNumber
;
458 if ((ModeData
->Columns
!= 0) && (ModeData
->Rows
!= 0) &&
459 (MaxColumns
>= ModeData
->Columns
) && (MaxRows
>= ModeData
->Rows
)) {
460 ModeData
->DeltaX
= (HorizontalResolution
- (ModeData
->Columns
* EFI_GLYPH_WIDTH
)) >> 1;
461 ModeData
->DeltaY
= (VerticalResolution
- (ModeData
->Rows
* EFI_GLYPH_HEIGHT
)) >> 1;
462 TextModeFound
= TRUE
;
464 ModeData
->Columns
= 0;
466 ModeData
->DeltaX
= 0;
467 ModeData
->DeltaY
= 0;
472 // See if the resolution was too small to support any text modes
474 if (!TextModeFound
) {
475 Status
= EFI_UNSUPPORTED
;
480 // Update the maximum number of modes
482 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
485 // Determine the number of text modes that this protocol can support
487 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
488 if (EFI_ERROR (Status
)) {
493 GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
497 // Install protocol interfaces for the Graphics Console device.
499 Status
= gBS
->InstallMultipleProtocolInterfaces (
501 &gEfiSimpleTextOutProtocolGuid
,
502 &Private
->SimpleTextOutput
,
507 if (EFI_ERROR (Status
)) {
509 // Close the GOP and UGA Draw Protocol
511 if (Private
->GraphicsOutput
!= NULL
) {
514 &gEfiGraphicsOutputProtocolGuid
,
515 This
->DriverBindingHandle
,
518 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
521 &gEfiUgaDrawProtocolGuid
,
522 This
->DriverBindingHandle
,
527 if (Private
->LineBuffer
!= NULL
) {
528 FreePool (Private
->LineBuffer
);
541 Stop this driver on Controller by removing Simple Text Out protocol
542 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
543 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
546 @param This Protocol instance pointer.
547 @param Controller Handle of device to stop driver on
548 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
549 children is zero stop the entire bus driver.
550 @param ChildHandleBuffer List of Child Handles to Stop.
552 @retval EFI_SUCCESS This driver is removed Controller.
553 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
555 @retval other This driver was not removed from this device.
560 GraphicsConsoleControllerDriverStop (
561 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
562 IN EFI_HANDLE Controller
,
563 IN UINTN NumberOfChildren
,
564 IN EFI_HANDLE
*ChildHandleBuffer
568 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
569 GRAPHICS_CONSOLE_DEV
*Private
;
571 Status
= gBS
->OpenProtocol (
573 &gEfiSimpleTextOutProtocolGuid
,
574 (VOID
**) &SimpleTextOutput
,
575 This
->DriverBindingHandle
,
577 EFI_OPEN_PROTOCOL_GET_PROTOCOL
579 if (EFI_ERROR (Status
)) {
580 return EFI_NOT_STARTED
;
583 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
585 Status
= gBS
->UninstallProtocolInterface (
587 &gEfiSimpleTextOutProtocolGuid
,
588 &Private
->SimpleTextOutput
591 if (!EFI_ERROR (Status
)) {
593 // Close the GOP or UGA IO Protocol
595 if (Private
->GraphicsOutput
!= NULL
) {
598 &gEfiGraphicsOutputProtocolGuid
,
599 This
->DriverBindingHandle
,
602 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
605 &gEfiUgaDrawProtocolGuid
,
606 This
->DriverBindingHandle
,
611 if (Private
->LineBuffer
!= NULL
) {
612 FreePool (Private
->LineBuffer
);
616 // Free our instance data
625 Check if the current specific mode supported the user defined resolution
626 for the Graphics Console device based on Graphics Output Protocol.
628 If yes, set the graphic devcice's current mode to this specific mode.
630 @param GraphicsOutput Graphics Output Protocol instance pointer.
631 @param HorizontalResolution User defined horizontal resolution
632 @param VerticalResolution User defined vertical resolution.
633 @param CurrentModeNumber Current specific mode to be check.
635 @retval EFI_SUCCESS The mode is supported.
636 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
638 @retval other The specific mode does not support user defined
639 resolution or failed to set the current mode to the
640 specific mode on graphics device.
645 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
646 IN UINT32 HorizontalResolution
,
647 IN UINT32 VerticalResolution
,
648 OUT UINT32
*CurrentModeNumber
654 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
657 Status
= EFI_SUCCESS
;
658 MaxMode
= GraphicsOutput
->Mode
->MaxMode
;
660 for (ModeNumber
= 0; ModeNumber
< MaxMode
; ModeNumber
++) {
661 Status
= GraphicsOutput
->QueryMode (
667 if (!EFI_ERROR (Status
)) {
668 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
669 (Info
->VerticalResolution
== VerticalResolution
)) {
670 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== HorizontalResolution
) &&
671 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== VerticalResolution
)) {
673 // If video device has been set to this mode, we do not need to SetMode again
677 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
678 if (!EFI_ERROR (Status
)) {
688 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
689 Status
= EFI_UNSUPPORTED
;
692 *CurrentModeNumber
= ModeNumber
;
698 Locate HII Database protocol and HII Font protocol.
700 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
701 are located successfully.
702 @return other Failed to locate HII Database protocol or
707 EfiLocateHiiProtocol (
716 // There should only be one - so buffer size is this
718 Size
= sizeof (EFI_HANDLE
);
720 Status
= gBS
->LocateHandle (
722 &gEfiHiiDatabaseProtocolGuid
,
728 if (EFI_ERROR (Status
)) {
732 Status
= gBS
->HandleProtocol (
734 &gEfiHiiDatabaseProtocolGuid
,
735 (VOID
**) &mHiiDatabase
738 if (EFI_ERROR (Status
)) {
742 Status
= gBS
->HandleProtocol (
744 &gEfiHiiFontProtocolGuid
,
751 // Body of the STO functions
755 Reset the text output device hardware and optionally run diagnostics.
757 Implements SIMPLE_TEXT_OUTPUT.Reset().
758 If ExtendeVerification is TRUE, then perform dependent Graphics Console
759 device reset, and set display mode to mode 0.
760 If ExtendedVerification is FALSE, only set display mode to mode 0.
762 @param This Protocol instance pointer.
763 @param ExtendedVerification Indicates that the driver may perform a more
764 exhaustive verification operation of the device
767 @retval EFI_SUCCESS The text output device was reset.
768 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
774 GraphicsConsoleConOutReset (
775 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
776 IN BOOLEAN ExtendedVerification
779 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
780 return This
->SetMode (This
, 0);
785 Write a Unicode string to the output device.
787 Implements SIMPLE_TEXT_OUTPUT.OutputString().
788 The Unicode string will be converted to Glyphs and will be
789 sent to the Graphics Console.
791 @param This Protocol instance pointer.
792 @param WString The NULL-terminated Unicode string to be displayed
793 on the output device(s). All output devices must
794 also support the Unicode drawing defined in this file.
796 @retval EFI_SUCCESS The string was output to the device.
797 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
799 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
801 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
802 characters in the Unicode string could not be
803 rendered and were skipped.
808 GraphicsConsoleConOutOutputString (
809 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
813 GRAPHICS_CONSOLE_DEV
*Private
;
814 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
815 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
824 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
825 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
830 INT32 OriginAttribute
;
833 Status
= EFI_SUCCESS
;
835 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
839 Mode
= This
->Mode
->Mode
;
840 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
841 GraphicsOutput
= Private
->GraphicsOutput
;
842 UgaDraw
= Private
->UgaDraw
;
844 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
845 MaxRow
= Private
->ModeData
[Mode
].Rows
;
846 DeltaX
= (UINTN
) Private
->ModeData
[Mode
].DeltaX
;
847 DeltaY
= (UINTN
) Private
->ModeData
[Mode
].DeltaY
;
848 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
849 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
850 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
853 // The Attributes won't change when during the time OutputString is called
855 GetTextColors (This
, &Foreground
, &Background
);
864 OriginAttribute
= This
->Mode
->Attribute
;
866 while (*WString
!= L
'\0') {
868 if (*WString
== CHAR_BACKSPACE
) {
870 // If the cursor is at the left edge of the display, then move the cursor
873 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
874 This
->Mode
->CursorRow
--;
875 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
876 This
->OutputString (This
, SpaceStr
);
878 This
->Mode
->CursorRow
--;
879 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
880 } else if (This
->Mode
->CursorColumn
> 0) {
882 // If the cursor is not at the left edge of the display, then move the cursor
885 This
->Mode
->CursorColumn
--;
886 This
->OutputString (This
, SpaceStr
);
888 This
->Mode
->CursorColumn
--;
893 } else if (*WString
== CHAR_LINEFEED
) {
895 // If the cursor is at the bottom of the display, then scroll the display one
896 // row, and do not update the cursor position. Otherwise, move the cursor
899 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
900 if (GraphicsOutput
!= NULL
) {
902 // Scroll Screen Up One Row
904 GraphicsOutput
->Blt (
909 DeltaY
+ EFI_GLYPH_HEIGHT
,
918 // Print Blank Line at last line
920 GraphicsOutput
->Blt (
932 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
934 // Scroll Screen Up One Row
941 DeltaY
+ EFI_GLYPH_HEIGHT
,
950 // Print Blank Line at last line
954 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
966 This
->Mode
->CursorRow
++;
971 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
973 // Move the cursor to the beginning of the current row.
975 This
->Mode
->CursorColumn
= 0;
978 } else if (*WString
== WIDE_CHAR
) {
980 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
983 } else if (*WString
== NARROW_CHAR
) {
985 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
990 // Print the character at the current cursor position and move the cursor
991 // right one column. If this moves the cursor past the right edge of the
992 // display, then the line should wrap to the beginning of the next line. This
993 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
994 // bottom of the display, and the line wraps, then the display will be scrolled
996 // If wide char is going to be displayed, need to display one character at a time
997 // Or, need to know the display length of a certain string.
999 // Index is used to determine how many character width units (wide = 2, narrow = 1)
1000 // Count is used to determine how many characters are used regardless of their attributes
1002 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
1003 if (WString
[Count
] == CHAR_NULL
||
1004 WString
[Count
] == CHAR_BACKSPACE
||
1005 WString
[Count
] == CHAR_LINEFEED
||
1006 WString
[Count
] == CHAR_CARRIAGE_RETURN
||
1007 WString
[Count
] == WIDE_CHAR
||
1008 WString
[Count
] == NARROW_CHAR
) {
1012 // Is the wide attribute on?
1014 if ((This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) != 0) {
1016 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
1020 // This is the end-case where if we are at column 79 and about to print a wide character
1021 // We should prevent this from happening because we will wrap inappropriately. We should
1022 // not print this character until the next line.
1024 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
1031 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
1032 if (EFI_ERROR (Status
)) {
1036 // At the end of line, output carriage return and line feed
1039 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1040 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1041 This
->Mode
->CursorColumn
-= 2;
1042 This
->OutputString (This
, SpaceStr
);
1045 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1047 This
->OutputString (This
, mCrLfString
);
1053 This
->Mode
->Attribute
= OriginAttribute
;
1058 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1061 gBS
->RestoreTPL (OldTpl
);
1067 Verifies that all characters in a Unicode string can be output to the
1070 Implements SIMPLE_TEXT_OUTPUT.TestString().
1071 If one of the characters in the *Wstring is neither valid valid Unicode
1072 drawing characters, not ASCII code, then this function will return
1075 @param This Protocol instance pointer.
1076 @param WString The NULL-terminated Unicode string to be examined for the output
1079 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1080 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1081 rendered by one or more of the output devices mapped
1087 GraphicsConsoleConOutTestString (
1088 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1095 EFI_IMAGE_OUTPUT
*Blt
;
1100 while (WString
[Count
] != 0) {
1101 Status
= mHiiFont
->GetGlyph (
1114 if (EFI_ERROR (Status
)) {
1115 return EFI_UNSUPPORTED
;
1124 Returns information for an available text mode that the output device(s)
1127 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1128 It returnes information for an available text mode that the Graphics Console supports.
1129 In this driver,we only support text mode 80x25, which is defined as mode 0.
1131 @param This Protocol instance pointer.
1132 @param ModeNumber The mode number to return information on.
1133 @param Columns The returned columns of the requested mode.
1134 @param Rows The returned rows of the requested mode.
1136 @retval EFI_SUCCESS The requested mode information is returned.
1137 @retval EFI_UNSUPPORTED The mode number is not valid.
1142 GraphicsConsoleConOutQueryMode (
1143 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1144 IN UINTN ModeNumber
,
1149 GRAPHICS_CONSOLE_DEV
*Private
;
1153 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1154 return EFI_UNSUPPORTED
;
1157 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1158 Status
= EFI_SUCCESS
;
1160 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1162 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1163 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1165 if (*Columns
<= 0 && *Rows
<= 0) {
1166 Status
= EFI_UNSUPPORTED
;
1172 gBS
->RestoreTPL (OldTpl
);
1178 Sets the output device(s) to a specified mode.
1180 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1181 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1183 @param This Protocol instance pointer.
1184 @param ModeNumber The text mode to set.
1186 @retval EFI_SUCCESS The requested text mode is set.
1187 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1188 Graphics Console device error.
1189 @retval EFI_UNSUPPORTED The text mode number is not valid.
1194 GraphicsConsoleConOutSetMode (
1195 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1200 GRAPHICS_CONSOLE_DEV
*Private
;
1201 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1202 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1203 UINT32 HorizontalResolution
;
1204 UINT32 VerticalResolution
;
1205 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1206 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1211 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1213 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1214 GraphicsOutput
= Private
->GraphicsOutput
;
1215 UgaDraw
= Private
->UgaDraw
;
1216 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1219 // Make sure the requested mode number is supported
1221 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1222 Status
= EFI_UNSUPPORTED
;
1226 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1227 Status
= EFI_UNSUPPORTED
;
1231 // Attempt to allocate a line buffer for the requested mode number
1233 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1235 if (NewLineBuffer
== NULL
) {
1237 // The new line buffer could not be allocated, so return an error.
1238 // No changes to the state of the current console have been made, so the current console is still valid
1240 Status
= EFI_OUT_OF_RESOURCES
;
1244 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1246 if (Private
->LineBuffer
!= NULL
) {
1248 // Clear the current text window on the current graphics console
1250 This
->ClearScreen (This
);
1253 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1255 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1256 FreePool (NewLineBuffer
);
1257 Status
= EFI_SUCCESS
;
1261 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1262 // so erase the cursor, and free the LineBuffer for the current mode
1266 FreePool (Private
->LineBuffer
);
1269 // Assign the current line buffer to the newly allocated line buffer
1271 Private
->LineBuffer
= NewLineBuffer
;
1273 if (GraphicsOutput
!= NULL
) {
1274 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1276 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1278 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1279 if (EFI_ERROR (Status
)) {
1281 // The mode set operation failed
1287 // The current graphics mode is correct, so simply clear the entire display
1289 Status
= GraphicsOutput
->Blt (
1291 &mGraphicsEfiColors
[0],
1298 ModeData
->GopHeight
,
1302 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1304 // Get the current UGA Draw mode information
1306 Status
= UgaDraw
->GetMode (
1308 &HorizontalResolution
,
1309 &VerticalResolution
,
1313 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1315 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1317 Status
= UgaDraw
->SetMode (
1320 ModeData
->GopHeight
,
1324 if (EFI_ERROR (Status
)) {
1326 // The mode set operation failed
1332 // The current graphics mode is correct, so simply clear the entire display
1334 Status
= UgaDraw
->Blt (
1336 (EFI_UGA_PIXEL
*) (UINTN
) &mGraphicsEfiColors
[0],
1343 ModeData
->GopHeight
,
1350 // The new mode is valid, so commit the mode change
1352 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1355 // Move the text cursor to the upper left hand corner of the display and flush it
1357 This
->Mode
->CursorColumn
= 0;
1358 This
->Mode
->CursorRow
= 0;
1362 Status
= EFI_SUCCESS
;
1365 gBS
->RestoreTPL (OldTpl
);
1371 Sets the background and foreground colors for the OutputString () and
1372 ClearScreen () functions.
1374 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1376 @param This Protocol instance pointer.
1377 @param Attribute The attribute to set. Bits 0..3 are the foreground
1378 color, and bits 4..6 are the background color.
1379 All other bits are undefined and must be zero.
1381 @retval EFI_SUCCESS The requested attribute is set.
1382 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1383 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1388 GraphicsConsoleConOutSetAttribute (
1389 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1395 if ((Attribute
| 0xFF) != 0xFF) {
1396 return EFI_UNSUPPORTED
;
1399 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1403 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1407 This
->Mode
->Attribute
= (INT32
) Attribute
;
1411 gBS
->RestoreTPL (OldTpl
);
1418 Clears the output device(s) display to the currently selected background
1421 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1423 @param This Protocol instance pointer.
1425 @retval EFI_SUCCESS The operation completed successfully.
1426 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1427 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1432 GraphicsConsoleConOutClearScreen (
1433 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1437 GRAPHICS_CONSOLE_DEV
*Private
;
1438 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1439 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1440 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1441 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1442 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1445 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1447 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1448 GraphicsOutput
= Private
->GraphicsOutput
;
1449 UgaDraw
= Private
->UgaDraw
;
1450 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1452 GetTextColors (This
, &Foreground
, &Background
);
1453 if (GraphicsOutput
!= NULL
) {
1454 Status
= GraphicsOutput
->Blt (
1463 ModeData
->GopHeight
,
1466 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1467 Status
= UgaDraw
->Blt (
1469 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1476 ModeData
->GopHeight
,
1480 Status
= EFI_UNSUPPORTED
;
1483 This
->Mode
->CursorColumn
= 0;
1484 This
->Mode
->CursorRow
= 0;
1488 gBS
->RestoreTPL (OldTpl
);
1495 Sets the current coordinates of the cursor position.
1497 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1499 @param This Protocol instance pointer.
1500 @param Column The position to set the cursor to. Must be greater than or
1501 equal to zero and less than the number of columns and rows
1503 @param Row The position to set the cursor to. Must be greater than or
1504 equal to zero and less than the number of columns and rows
1507 @retval EFI_SUCCESS The operation completed successfully.
1508 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1509 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1510 cursor position is invalid for the current mode.
1515 GraphicsConsoleConOutSetCursorPosition (
1516 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1521 GRAPHICS_CONSOLE_DEV
*Private
;
1522 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1526 Status
= EFI_SUCCESS
;
1528 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1530 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1531 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1533 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1534 Status
= EFI_UNSUPPORTED
;
1538 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1539 Status
= EFI_SUCCESS
;
1545 This
->Mode
->CursorColumn
= (INT32
) Column
;
1546 This
->Mode
->CursorRow
= (INT32
) Row
;
1551 gBS
->RestoreTPL (OldTpl
);
1558 Makes the cursor visible or invisible.
1560 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1562 @param This Protocol instance pointer.
1563 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1564 the cursor is set to be invisible.
1566 @retval EFI_SUCCESS The operation completed successfully.
1571 GraphicsConsoleConOutEnableCursor (
1572 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1578 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1582 This
->Mode
->CursorVisible
= Visible
;
1586 gBS
->RestoreTPL (OldTpl
);
1591 Gets Graphics Console devcie's foreground color and background color.
1593 @param This Protocol instance pointer.
1594 @param Foreground Returned text foreground color.
1595 @param Background Returned text background color.
1597 @retval EFI_SUCCESS It returned always.
1602 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1603 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1604 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1609 Attribute
= This
->Mode
->Attribute
& 0x7F;
1611 *Foreground
= mGraphicsEfiColors
[Attribute
& 0x0f];
1612 *Background
= mGraphicsEfiColors
[Attribute
>> 4];
1618 Draw Unicode string on the Graphics Console device's screen.
1620 @param This Protocol instance pointer.
1621 @param UnicodeWeight One Unicode string to be displayed.
1622 @param Count The count of Unicode string.
1624 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1625 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1627 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1631 DrawUnicodeWeightAtCursorN (
1632 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1633 IN CHAR16
*UnicodeWeight
,
1638 GRAPHICS_CONSOLE_DEV
*Private
;
1639 EFI_IMAGE_OUTPUT
*Blt
;
1641 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1642 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1643 EFI_HII_ROW_INFO
*RowInfoArray
;
1644 UINTN RowInfoArraySize
;
1646 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1647 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1649 return EFI_OUT_OF_RESOURCES
;
1652 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1653 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1655 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1656 if (String
== NULL
) {
1658 return EFI_OUT_OF_RESOURCES
;
1661 // Set the end character
1663 *(String
+ Count
) = L
'\0';
1665 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1666 if (FontInfo
== NULL
) {
1669 return EFI_OUT_OF_RESOURCES
;
1672 // Get current foreground and background colors.
1674 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1676 if (Private
->GraphicsOutput
!= NULL
) {
1678 // If Graphics Output protocol exists, using HII Font protocol to draw.
1680 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1682 Status
= mHiiFont
->StringToImage (
1684 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
| EFI_HII_IGNORE_LINE_BREAK
,
1688 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1689 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1695 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1697 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1698 // using UGA Draw protocol to draw.
1700 ASSERT (Private
->UgaDraw
!= NULL
);
1702 UgaDraw
= Private
->UgaDraw
;
1704 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1705 if (Blt
->Image
.Bitmap
== NULL
) {
1708 return EFI_OUT_OF_RESOURCES
;
1711 RowInfoArray
= NULL
;
1713 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1714 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1716 Status
= mHiiFont
->StringToImage (
1718 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_IGNORE_LINE_BREAK
,
1722 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1723 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1729 if (!EFI_ERROR (Status
)) {
1731 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1732 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1734 ASSERT (RowInfoArraySize
<= 1);
1736 Status
= UgaDraw
->Blt (
1738 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1739 EfiUgaBltBufferToVideo
,
1740 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1741 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1742 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1743 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1744 RowInfoArray
[0].LineWidth
,
1745 RowInfoArray
[0].LineHeight
,
1746 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1750 FreePool (RowInfoArray
);
1751 FreePool (Blt
->Image
.Bitmap
);
1753 Status
= EFI_UNSUPPORTED
;
1759 if (String
!= NULL
) {
1762 if (FontInfo
!= NULL
) {
1763 FreePool (FontInfo
);
1769 Flush the cursor on the screen.
1771 If CursorVisible is FALSE, nothing to do and return directly.
1772 If CursorVisible is TRUE,
1773 i) If the cursor shows on screen, it will be erased.
1774 ii) If the cursor does not show on screen, it will be shown.
1776 @param This Protocol instance pointer.
1778 @retval EFI_SUCCESS The cursor is erased successfully.
1783 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1786 GRAPHICS_CONSOLE_DEV
*Private
;
1787 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1790 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1791 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1792 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1793 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1794 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1798 CurrentMode
= This
->Mode
;
1800 if (!CurrentMode
->CursorVisible
) {
1804 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1805 GraphicsOutput
= Private
->GraphicsOutput
;
1806 UgaDraw
= Private
->UgaDraw
;
1809 // In this driver, only narrow character was supported.
1812 // Blt a character to the screen
1814 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1815 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1816 if (GraphicsOutput
!= NULL
) {
1817 GraphicsOutput
->Blt (
1819 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1820 EfiBltVideoToBltBuffer
,
1827 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1829 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1832 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1833 EfiUgaVideoToBltBuffer
,
1840 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1844 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1847 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1849 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1850 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1851 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1852 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1857 if (GraphicsOutput
!= NULL
) {
1858 GraphicsOutput
->Blt (
1860 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1861 EfiBltBufferToVideo
,
1868 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1870 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1873 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1874 EfiUgaBltBufferToVideo
,
1881 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1889 HII Database Protocol notification event handler.
1891 Register font package when HII Database Protocol has been installed.
1893 @param[in] Event Event whose notification function is being invoked.
1894 @param[in] Context Pointer to the notification function's context.
1898 RegisterFontPackage (
1904 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
1905 UINT32 PackageLength
;
1908 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1911 // Locate HII Database Protocol
1913 Status
= gBS
->LocateProtocol (
1914 &gEfiHiiDatabaseProtocolGuid
,
1916 (VOID
**) &HiiDatabase
1918 ASSERT_EFI_ERROR (Status
);
1921 // Add 4 bytes to the header for entire length for HiiAddPackages use only.
1923 // +--------------------------------+ <-- Package
1925 // | PackageLength(4 bytes) |
1927 // |--------------------------------| <-- SimplifiedFont
1929 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
1931 // |--------------------------------| <-- Location
1933 // | gUsStdNarrowGlyphData |
1935 // +--------------------------------+
1937 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + mNarrowFontSize
+ 4;
1938 Package
= AllocateZeroPool (PackageLength
);
1939 ASSERT (Package
!= NULL
);
1941 WriteUnaligned32((UINT32
*) Package
,PackageLength
);
1942 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
1943 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
1944 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
1945 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (mNarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
1947 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
1948 CopyMem (Location
, gUsStdNarrowGlyphData
, mNarrowFontSize
);
1951 // Add this simplified font package to a package list then install it.
1953 mHiiHandle
= HiiAddPackages (
1954 &mFontPackageListGuid
,
1959 ASSERT (mHiiHandle
!= NULL
);
1964 The user Entry Point for module GraphicsConsole. The user code starts with this function.
1966 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1967 @param[in] SystemTable A pointer to the EFI System Table.
1969 @retval EFI_SUCCESS The entry point is executed successfully.
1970 @return other Some error occurs when executing this entry point.
1975 InitializeGraphicsConsole (
1976 IN EFI_HANDLE ImageHandle
,
1977 IN EFI_SYSTEM_TABLE
*SystemTable
1983 // Register notify function on HII Database Protocol to add font package.
1985 EfiCreateProtocolNotifyEvent (
1986 &gEfiHiiDatabaseProtocolGuid
,
1988 RegisterFontPackage
,
1994 // Install driver model protocol(s).
1996 Status
= EfiLibInstallDriverBindingComponentName2 (
1999 &gGraphicsConsoleDriverBinding
,
2001 &gGraphicsConsoleComponentName
,
2002 &gGraphicsConsoleComponentName2
2004 ASSERT_EFI_ERROR (Status
);