2 This is the main routine for initializing the Graphics Console support routines.
4 Copyright (c) 2006 - 2010, 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
;
252 // Initialize the Graphics Console device instance
254 Private
= AllocateCopyPool (
255 sizeof (GRAPHICS_CONSOLE_DEV
),
256 &mGraphicsConsoleDevTemplate
258 if (Private
== NULL
) {
259 return EFI_OUT_OF_RESOURCES
;
262 Private
->SimpleTextOutput
.Mode
= &(Private
->SimpleTextOutputMode
);
264 Status
= gBS
->OpenProtocol (
266 &gEfiGraphicsOutputProtocolGuid
,
267 (VOID
**) &Private
->GraphicsOutput
,
268 This
->DriverBindingHandle
,
270 EFI_OPEN_PROTOCOL_BY_DRIVER
273 if (EFI_ERROR(Status
) && FeaturePcdGet (PcdUgaConsumeSupport
)) {
274 Status
= gBS
->OpenProtocol (
276 &gEfiUgaDrawProtocolGuid
,
277 (VOID
**) &Private
->UgaDraw
,
278 This
->DriverBindingHandle
,
280 EFI_OPEN_PROTOCOL_BY_DRIVER
284 if (EFI_ERROR (Status
)) {
289 // If the current mode information can not be retrieved, then attempt to set the default mode
290 // of 800x600, 32 bit color, 60 Hz refresh.
292 HorizontalResolution
= 800;
293 VerticalResolution
= 600;
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 Status
= CheckModeSupported (
302 Private
->GraphicsOutput
,
303 CURRENT_HORIZONTAL_RESOLUTION
,
304 CURRENT_VERTICAL_RESOLUTION
,
307 if (!EFI_ERROR(Status
)) {
309 // Update default mode to current mode
311 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
312 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
315 // if not supporting current mode, try 800x600 which is required by UEFI/EFI spec
317 Status
= CheckModeSupported (
318 Private
->GraphicsOutput
,
325 Mode
= Private
->GraphicsOutput
->Mode
;
327 if (EFI_ERROR (Status
) || (Mode
->MaxMode
!= 0)) {
329 // Set default mode failed or device don't support default mode, then get the current mode information
331 HorizontalResolution
= Mode
->Info
->HorizontalResolution
;
332 VerticalResolution
= Mode
->Info
->VerticalResolution
;
333 ModeNumber
= Mode
->Mode
;
335 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
337 // At first try to set user-defined resolution
341 Status
= Private
->UgaDraw
->SetMode (
343 CURRENT_HORIZONTAL_RESOLUTION
,
344 CURRENT_VERTICAL_RESOLUTION
,
348 if (!EFI_ERROR (Status
)) {
349 HorizontalResolution
= CURRENT_HORIZONTAL_RESOLUTION
;
350 VerticalResolution
= CURRENT_VERTICAL_RESOLUTION
;
351 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
353 // Try to set 800*600 which is required by UEFI/EFI spec
355 Status
= Private
->UgaDraw
->SetMode (
357 HorizontalResolution
,
362 if (EFI_ERROR (Status
)) {
363 Status
= Private
->UgaDraw
->GetMode (
365 &HorizontalResolution
,
370 if (EFI_ERROR (Status
)) {
375 Status
= EFI_UNSUPPORTED
;
381 // Add Mode #3 that uses the entire display for user-defined mode
383 Private
->ModeData
[3].Columns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
384 Private
->ModeData
[3].Rows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
387 // Add Mode #4 that uses the PCD values
389 Private
->ModeData
[4].Columns
= (UINTN
) PcdGet32 (PcdConOutColumn
);
390 Private
->ModeData
[4].Rows
= (UINTN
) PcdGet32 (PcdConOutRow
);
393 // Compute the maximum number of text Rows and Columns that this current graphics mode can support
395 Columns
= HorizontalResolution
/ EFI_GLYPH_WIDTH
;
396 Rows
= VerticalResolution
/ EFI_GLYPH_HEIGHT
;
399 // Here we make sure that mode 0 is valid
401 if (Columns
< Private
->ModeData
[0].Columns
||
402 Rows
< Private
->ModeData
[0].Rows
) {
404 // 80x25 cannot be supported.
406 // Fallback to using the PcdConOutColumn and PcdConOutRow
407 // for mode 0. If the PCDs are also to large, then mode 0
408 // will be shrunk to fit as needed.
410 Private
->ModeData
[0].Columns
= MIN (Private
->ModeData
[4].Columns
, Columns
);
411 Private
->ModeData
[0].Rows
= MIN (Private
->ModeData
[4].Rows
, Rows
);
415 for (ModeIndex
= 0; ModeIndex
< GRAPHICS_MAX_MODE
; ModeIndex
++) {
416 ModeData
= &Private
->ModeData
[ModeIndex
];
417 ModeData
->GopWidth
= HorizontalResolution
;
418 ModeData
->GopHeight
= VerticalResolution
;
419 ModeData
->GopModeNumber
= ModeNumber
;
420 if (Columns
>= ModeData
->Columns
&&
421 Rows
>= ModeData
->Rows
) {
422 ModeData
->DeltaX
= (HorizontalResolution
- (ModeData
->Columns
* EFI_GLYPH_WIDTH
)) >> 1;
423 ModeData
->DeltaY
= (VerticalResolution
- (ModeData
->Rows
* EFI_GLYPH_HEIGHT
)) >> 1;
424 MaxMode
= ModeIndex
+ 1;
426 ModeData
->Columns
= 0;
428 ModeData
->DeltaX
= 0;
429 ModeData
->DeltaY
= 0;
434 // See if the resolution was too small to support any text modes
441 // Update the maximum number of modes
443 Private
->SimpleTextOutputMode
.MaxMode
= (INT32
) MaxMode
;
446 // Determine the number of text modes that this protocol can support
448 Status
= GraphicsConsoleConOutSetMode (&Private
->SimpleTextOutput
, 0);
449 if (EFI_ERROR (Status
)) {
454 GraphicsConsoleConOutOutputString (&Private
->SimpleTextOutput
, (CHAR16
*)L
"Graphics Console Started\n\r");
458 // Install protocol interfaces for the Graphics Console device.
460 Status
= gBS
->InstallMultipleProtocolInterfaces (
462 &gEfiSimpleTextOutProtocolGuid
,
463 &Private
->SimpleTextOutput
,
468 if (EFI_ERROR (Status
)) {
470 // Close the GOP and UGA Draw Protocol
472 if (Private
->GraphicsOutput
!= NULL
) {
475 &gEfiGraphicsOutputProtocolGuid
,
476 This
->DriverBindingHandle
,
479 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
482 &gEfiUgaDrawProtocolGuid
,
483 This
->DriverBindingHandle
,
488 if (Private
->LineBuffer
!= NULL
) {
489 FreePool (Private
->LineBuffer
);
502 Stop this driver on Controller by removing Simple Text Out protocol
503 and closing the Graphics Output Protocol or UGA Draw protocol on Controller.
504 (UGA Draw protocol could be skipped if PcdUgaConsumeSupport is set to FALSE.)
507 @param This Protocol instance pointer.
508 @param Controller Handle of device to stop driver on
509 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
510 children is zero stop the entire bus driver.
511 @param ChildHandleBuffer List of Child Handles to Stop.
513 @retval EFI_SUCCESS This driver is removed Controller.
514 @retval EFI_NOT_STARTED Simple Text Out protocol could not be found the
516 @retval other This driver was not removed from this device.
521 GraphicsConsoleControllerDriverStop (
522 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
523 IN EFI_HANDLE Controller
,
524 IN UINTN NumberOfChildren
,
525 IN EFI_HANDLE
*ChildHandleBuffer
529 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
530 GRAPHICS_CONSOLE_DEV
*Private
;
532 Status
= gBS
->OpenProtocol (
534 &gEfiSimpleTextOutProtocolGuid
,
535 (VOID
**) &SimpleTextOutput
,
536 This
->DriverBindingHandle
,
538 EFI_OPEN_PROTOCOL_GET_PROTOCOL
540 if (EFI_ERROR (Status
)) {
541 return EFI_NOT_STARTED
;
544 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
546 Status
= gBS
->UninstallProtocolInterface (
548 &gEfiSimpleTextOutProtocolGuid
,
549 &Private
->SimpleTextOutput
552 if (!EFI_ERROR (Status
)) {
554 // Close the GOP or UGA IO Protocol
556 if (Private
->GraphicsOutput
!= NULL
) {
559 &gEfiGraphicsOutputProtocolGuid
,
560 This
->DriverBindingHandle
,
563 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
566 &gEfiUgaDrawProtocolGuid
,
567 This
->DriverBindingHandle
,
572 if (Private
->LineBuffer
!= NULL
) {
573 FreePool (Private
->LineBuffer
);
577 // Free our instance data
586 Check if the current specific mode supported the user defined resolution
587 for the Graphics Console device based on Graphics Output Protocol.
589 If yes, set the graphic devcice's current mode to this specific mode.
591 @param GraphicsOutput Graphics Output Protocol instance pointer.
592 @param HorizontalResolution User defined horizontal resolution
593 @param VerticalResolution User defined vertical resolution.
594 @param CurrentModeNumber Current specific mode to be check.
596 @retval EFI_SUCCESS The mode is supported.
597 @retval EFI_UNSUPPORTED The specific mode is out of range of graphics
599 @retval other The specific mode does not support user defined
600 resolution or failed to set the current mode to the
601 specific mode on graphics device.
606 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
607 IN UINT32 HorizontalResolution
,
608 IN UINT32 VerticalResolution
,
609 OUT UINT32
*CurrentModeNumber
615 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
618 Status
= EFI_SUCCESS
;
619 MaxMode
= GraphicsOutput
->Mode
->MaxMode
;
621 for (ModeNumber
= 0; ModeNumber
< MaxMode
; ModeNumber
++) {
622 Status
= GraphicsOutput
->QueryMode (
628 if (!EFI_ERROR (Status
)) {
629 if ((Info
->HorizontalResolution
== HorizontalResolution
) &&
630 (Info
->VerticalResolution
== VerticalResolution
)) {
631 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== HorizontalResolution
) &&
632 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== VerticalResolution
)) {
634 // If video device has been set to this mode, we do not need to SetMode again
638 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
639 if (!EFI_ERROR (Status
)) {
649 if (ModeNumber
== GraphicsOutput
->Mode
->MaxMode
) {
650 Status
= EFI_UNSUPPORTED
;
653 *CurrentModeNumber
= ModeNumber
;
659 Locate HII Database protocol and HII Font protocol.
661 @retval EFI_SUCCESS HII Database protocol and HII Font protocol
662 are located successfully.
663 @return other Failed to locate HII Database protocol or
668 EfiLocateHiiProtocol (
677 // There should only be one - so buffer size is this
679 Size
= sizeof (EFI_HANDLE
);
681 Status
= gBS
->LocateHandle (
683 &gEfiHiiDatabaseProtocolGuid
,
689 if (EFI_ERROR (Status
)) {
693 Status
= gBS
->HandleProtocol (
695 &gEfiHiiDatabaseProtocolGuid
,
696 (VOID
**) &mHiiDatabase
699 if (EFI_ERROR (Status
)) {
703 Status
= gBS
->HandleProtocol (
705 &gEfiHiiFontProtocolGuid
,
712 // Body of the STO functions
716 Reset the text output device hardware and optionally run diagnostics.
718 Implements SIMPLE_TEXT_OUTPUT.Reset().
719 If ExtendeVerification is TRUE, then perform dependent Graphics Console
720 device reset, and set display mode to mode 0.
721 If ExtendedVerification is FALSE, only set display mode to mode 0.
723 @param This Protocol instance pointer.
724 @param ExtendedVerification Indicates that the driver may perform a more
725 exhaustive verification operation of the device
728 @retval EFI_SUCCESS The text output device was reset.
729 @retval EFI_DEVICE_ERROR The text output device is not functioning correctly and
735 GraphicsConsoleConOutReset (
736 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
737 IN BOOLEAN ExtendedVerification
740 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
741 return This
->SetMode (This
, 0);
746 Write a Unicode string to the output device.
748 Implements SIMPLE_TEXT_OUTPUT.OutputString().
749 The Unicode string will be converted to Glyphs and will be
750 sent to the Graphics Console.
752 @param This Protocol instance pointer.
753 @param WString The NULL-terminated Unicode string to be displayed
754 on the output device(s). All output devices must
755 also support the Unicode drawing defined in this file.
757 @retval EFI_SUCCESS The string was output to the device.
758 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output
760 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
762 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
763 characters in the Unicode string could not be
764 rendered and were skipped.
769 GraphicsConsoleConOutOutputString (
770 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
774 GRAPHICS_CONSOLE_DEV
*Private
;
775 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
776 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
785 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
786 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
791 INT32 OriginAttribute
;
794 Status
= EFI_SUCCESS
;
796 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
800 Mode
= This
->Mode
->Mode
;
801 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
802 GraphicsOutput
= Private
->GraphicsOutput
;
803 UgaDraw
= Private
->UgaDraw
;
805 MaxColumn
= Private
->ModeData
[Mode
].Columns
;
806 MaxRow
= Private
->ModeData
[Mode
].Rows
;
807 DeltaX
= (UINTN
) Private
->ModeData
[Mode
].DeltaX
;
808 DeltaY
= (UINTN
) Private
->ModeData
[Mode
].DeltaY
;
809 Width
= MaxColumn
* EFI_GLYPH_WIDTH
;
810 Height
= (MaxRow
- 1) * EFI_GLYPH_HEIGHT
;
811 Delta
= Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
);
814 // The Attributes won't change when during the time OutputString is called
816 GetTextColors (This
, &Foreground
, &Background
);
825 OriginAttribute
= This
->Mode
->Attribute
;
827 while (*WString
!= L
'\0') {
829 if (*WString
== CHAR_BACKSPACE
) {
831 // If the cursor is at the left edge of the display, then move the cursor
834 if (This
->Mode
->CursorColumn
== 0 && This
->Mode
->CursorRow
> 0) {
835 This
->Mode
->CursorRow
--;
836 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
837 This
->OutputString (This
, SpaceStr
);
839 This
->Mode
->CursorRow
--;
840 This
->Mode
->CursorColumn
= (INT32
) (MaxColumn
- 1);
841 } else if (This
->Mode
->CursorColumn
> 0) {
843 // If the cursor is not at the left edge of the display, then move the cursor
846 This
->Mode
->CursorColumn
--;
847 This
->OutputString (This
, SpaceStr
);
849 This
->Mode
->CursorColumn
--;
854 } else if (*WString
== CHAR_LINEFEED
) {
856 // If the cursor is at the bottom of the display, then scroll the display one
857 // row, and do not update the cursor position. Otherwise, move the cursor
860 if (This
->Mode
->CursorRow
== (INT32
) (MaxRow
- 1)) {
861 if (GraphicsOutput
!= NULL
) {
863 // Scroll Screen Up One Row
865 GraphicsOutput
->Blt (
870 DeltaY
+ EFI_GLYPH_HEIGHT
,
879 // Print Blank Line at last line
881 GraphicsOutput
->Blt (
893 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
895 // Scroll Screen Up One Row
902 DeltaY
+ EFI_GLYPH_HEIGHT
,
911 // Print Blank Line at last line
915 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
927 This
->Mode
->CursorRow
++;
932 } else if (*WString
== CHAR_CARRIAGE_RETURN
) {
934 // Move the cursor to the beginning of the current row.
936 This
->Mode
->CursorColumn
= 0;
939 } else if (*WString
== WIDE_CHAR
) {
941 This
->Mode
->Attribute
|= EFI_WIDE_ATTRIBUTE
;
944 } else if (*WString
== NARROW_CHAR
) {
946 This
->Mode
->Attribute
&= (~ (UINT32
) EFI_WIDE_ATTRIBUTE
);
951 // Print the character at the current cursor position and move the cursor
952 // right one column. If this moves the cursor past the right edge of the
953 // display, then the line should wrap to the beginning of the next line. This
954 // is equivalent to inserting a CR and an LF. Note that if the cursor is at the
955 // bottom of the display, and the line wraps, then the display will be scrolled
957 // If wide char is going to be displayed, need to display one character at a time
958 // Or, need to know the display length of a certain string.
960 // Index is used to determine how many character width units (wide = 2, narrow = 1)
961 // Count is used to determine how many characters are used regardless of their attributes
963 for (Count
= 0, Index
= 0; (This
->Mode
->CursorColumn
+ Index
) < MaxColumn
; Count
++, Index
++) {
964 if (WString
[Count
] == CHAR_NULL
||
965 WString
[Count
] == CHAR_BACKSPACE
||
966 WString
[Count
] == CHAR_LINEFEED
||
967 WString
[Count
] == CHAR_CARRIAGE_RETURN
||
968 WString
[Count
] == WIDE_CHAR
||
969 WString
[Count
] == NARROW_CHAR
) {
973 // Is the wide attribute on?
975 if ((This
->Mode
->Attribute
& EFI_WIDE_ATTRIBUTE
) != 0) {
977 // If wide, add one more width unit than normal since we are going to increment at the end of the for loop
981 // This is the end-case where if we are at column 79 and about to print a wide character
982 // We should prevent this from happening because we will wrap inappropriately. We should
983 // not print this character until the next line.
985 if ((This
->Mode
->CursorColumn
+ Index
+ 1) > MaxColumn
) {
992 Status
= DrawUnicodeWeightAtCursorN (This
, WString
, Count
);
993 if (EFI_ERROR (Status
)) {
997 // At the end of line, output carriage return and line feed
1000 This
->Mode
->CursorColumn
+= (INT32
) Index
;
1001 if (This
->Mode
->CursorColumn
> (INT32
) MaxColumn
) {
1002 This
->Mode
->CursorColumn
-= 2;
1003 This
->OutputString (This
, SpaceStr
);
1006 if (This
->Mode
->CursorColumn
>= (INT32
) MaxColumn
) {
1008 This
->OutputString (This
, mCrLfString
);
1014 This
->Mode
->Attribute
= OriginAttribute
;
1019 Status
= EFI_WARN_UNKNOWN_GLYPH
;
1022 gBS
->RestoreTPL (OldTpl
);
1028 Verifies that all characters in a Unicode string can be output to the
1031 Implements SIMPLE_TEXT_OUTPUT.TestString().
1032 If one of the characters in the *Wstring is neither valid valid Unicode
1033 drawing characters, not ASCII code, then this function will return
1036 @param This Protocol instance pointer.
1037 @param WString The NULL-terminated Unicode string to be examined for the output
1040 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.
1041 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be
1042 rendered by one or more of the output devices mapped
1048 GraphicsConsoleConOutTestString (
1049 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1056 EFI_IMAGE_OUTPUT
*Blt
;
1061 while (WString
[Count
] != 0) {
1062 Status
= mHiiFont
->GetGlyph (
1075 if (EFI_ERROR (Status
)) {
1076 return EFI_UNSUPPORTED
;
1085 Returns information for an available text mode that the output device(s)
1088 Implements SIMPLE_TEXT_OUTPUT.QueryMode().
1089 It returnes information for an available text mode that the Graphics Console supports.
1090 In this driver,we only support text mode 80x25, which is defined as mode 0.
1092 @param This Protocol instance pointer.
1093 @param ModeNumber The mode number to return information on.
1094 @param Columns The returned columns of the requested mode.
1095 @param Rows The returned rows of the requested mode.
1097 @retval EFI_SUCCESS The requested mode information is returned.
1098 @retval EFI_UNSUPPORTED The mode number is not valid.
1103 GraphicsConsoleConOutQueryMode (
1104 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1105 IN UINTN ModeNumber
,
1110 GRAPHICS_CONSOLE_DEV
*Private
;
1114 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1115 return EFI_UNSUPPORTED
;
1118 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1119 Status
= EFI_SUCCESS
;
1121 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1123 *Columns
= Private
->ModeData
[ModeNumber
].Columns
;
1124 *Rows
= Private
->ModeData
[ModeNumber
].Rows
;
1126 if (*Columns
<= 0 && *Rows
<= 0) {
1127 Status
= EFI_UNSUPPORTED
;
1133 gBS
->RestoreTPL (OldTpl
);
1139 Sets the output device(s) to a specified mode.
1141 Implements SIMPLE_TEXT_OUTPUT.SetMode().
1142 Set the Graphics Console to a specified mode. In this driver, we only support mode 0.
1144 @param This Protocol instance pointer.
1145 @param ModeNumber The text mode to set.
1147 @retval EFI_SUCCESS The requested text mode is set.
1148 @retval EFI_DEVICE_ERROR The requested text mode cannot be set because of
1149 Graphics Console device error.
1150 @retval EFI_UNSUPPORTED The text mode number is not valid.
1155 GraphicsConsoleConOutSetMode (
1156 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1161 GRAPHICS_CONSOLE_DEV
*Private
;
1162 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1163 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*NewLineBuffer
;
1164 UINT32 HorizontalResolution
;
1165 UINT32 VerticalResolution
;
1166 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1167 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1172 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1174 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1175 GraphicsOutput
= Private
->GraphicsOutput
;
1176 UgaDraw
= Private
->UgaDraw
;
1177 ModeData
= &(Private
->ModeData
[ModeNumber
]);
1180 // Make sure the requested mode number is supported
1182 if (ModeNumber
>= (UINTN
) This
->Mode
->MaxMode
) {
1183 Status
= EFI_UNSUPPORTED
;
1187 if (ModeData
->Columns
<= 0 && ModeData
->Rows
<= 0) {
1188 Status
= EFI_UNSUPPORTED
;
1192 // Attempt to allocate a line buffer for the requested mode number
1194 NewLineBuffer
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
) * ModeData
->Columns
* EFI_GLYPH_WIDTH
* EFI_GLYPH_HEIGHT
);
1196 if (NewLineBuffer
== NULL
) {
1198 // The new line buffer could not be allocated, so return an error.
1199 // No changes to the state of the current console have been made, so the current console is still valid
1201 Status
= EFI_OUT_OF_RESOURCES
;
1205 // If the mode has been set at least one other time, then LineBuffer will not be NULL
1207 if (Private
->LineBuffer
!= NULL
) {
1209 // Clear the current text window on the current graphics console
1211 This
->ClearScreen (This
);
1214 // If the new mode is the same as the old mode, then just return EFI_SUCCESS
1216 if ((INT32
) ModeNumber
== This
->Mode
->Mode
) {
1217 FreePool (NewLineBuffer
);
1218 Status
= EFI_SUCCESS
;
1222 // Otherwise, the size of the text console and/or the GOP/UGA mode will be changed,
1223 // so erase the cursor, and free the LineBuffer for the current mode
1227 FreePool (Private
->LineBuffer
);
1230 // Assign the current line buffer to the newly allocated line buffer
1232 Private
->LineBuffer
= NewLineBuffer
;
1234 if (GraphicsOutput
!= NULL
) {
1235 if (ModeData
->GopModeNumber
!= GraphicsOutput
->Mode
->Mode
) {
1237 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1239 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeData
->GopModeNumber
);
1240 if (EFI_ERROR (Status
)) {
1242 // The mode set operation failed
1248 // The current graphics mode is correct, so simply clear the entire display
1250 Status
= GraphicsOutput
->Blt (
1252 &mGraphicsEfiColors
[0],
1259 ModeData
->GopHeight
,
1263 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1265 // Get the current UGA Draw mode information
1267 Status
= UgaDraw
->GetMode (
1269 &HorizontalResolution
,
1270 &VerticalResolution
,
1274 if (EFI_ERROR (Status
) || HorizontalResolution
!= ModeData
->GopWidth
|| VerticalResolution
!= ModeData
->GopHeight
) {
1276 // Either no graphics mode is currently set, or it is set to the wrong resolution, so set the new graphics mode
1278 Status
= UgaDraw
->SetMode (
1281 ModeData
->GopHeight
,
1285 if (EFI_ERROR (Status
)) {
1287 // The mode set operation failed
1293 // The current graphics mode is correct, so simply clear the entire display
1295 Status
= UgaDraw
->Blt (
1297 (EFI_UGA_PIXEL
*) (UINTN
) &mGraphicsEfiColors
[0],
1304 ModeData
->GopHeight
,
1311 // The new mode is valid, so commit the mode change
1313 This
->Mode
->Mode
= (INT32
) ModeNumber
;
1316 // Move the text cursor to the upper left hand corner of the display and flush it
1318 This
->Mode
->CursorColumn
= 0;
1319 This
->Mode
->CursorRow
= 0;
1323 Status
= EFI_SUCCESS
;
1326 gBS
->RestoreTPL (OldTpl
);
1332 Sets the background and foreground colors for the OutputString () and
1333 ClearScreen () functions.
1335 Implements SIMPLE_TEXT_OUTPUT.SetAttribute().
1337 @param This Protocol instance pointer.
1338 @param Attribute The attribute to set. Bits 0..3 are the foreground
1339 color, and bits 4..6 are the background color.
1340 All other bits are undefined and must be zero.
1342 @retval EFI_SUCCESS The requested attribute is set.
1343 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to Graphics Console port error.
1344 @retval EFI_UNSUPPORTED The attribute requested is not defined.
1349 GraphicsConsoleConOutSetAttribute (
1350 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1356 if ((Attribute
| 0xFF) != 0xFF) {
1357 return EFI_UNSUPPORTED
;
1360 if ((INT32
) Attribute
== This
->Mode
->Attribute
) {
1364 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1368 This
->Mode
->Attribute
= (INT32
) Attribute
;
1372 gBS
->RestoreTPL (OldTpl
);
1379 Clears the output device(s) display to the currently selected background
1382 Implements SIMPLE_TEXT_OUTPUT.ClearScreen().
1384 @param This Protocol instance pointer.
1386 @retval EFI_SUCCESS The operation completed successfully.
1387 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1388 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
1393 GraphicsConsoleConOutClearScreen (
1394 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1398 GRAPHICS_CONSOLE_DEV
*Private
;
1399 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1400 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1401 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1402 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1403 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1406 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1408 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1409 GraphicsOutput
= Private
->GraphicsOutput
;
1410 UgaDraw
= Private
->UgaDraw
;
1411 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1413 GetTextColors (This
, &Foreground
, &Background
);
1414 if (GraphicsOutput
!= NULL
) {
1415 Status
= GraphicsOutput
->Blt (
1424 ModeData
->GopHeight
,
1427 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1428 Status
= UgaDraw
->Blt (
1430 (EFI_UGA_PIXEL
*) (UINTN
) &Background
,
1437 ModeData
->GopHeight
,
1441 Status
= EFI_UNSUPPORTED
;
1444 This
->Mode
->CursorColumn
= 0;
1445 This
->Mode
->CursorRow
= 0;
1449 gBS
->RestoreTPL (OldTpl
);
1456 Sets the current coordinates of the cursor position.
1458 Implements SIMPLE_TEXT_OUTPUT.SetCursorPosition().
1460 @param This Protocol instance pointer.
1461 @param Column The position to set the cursor to. Must be greater than or
1462 equal to zero and less than the number of columns and rows
1464 @param Row The position to set the cursor to. Must be greater than or
1465 equal to zero and less than the number of columns and rows
1468 @retval EFI_SUCCESS The operation completed successfully.
1469 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
1470 @retval EFI_UNSUPPORTED The output device is not in a valid text mode, or the
1471 cursor position is invalid for the current mode.
1476 GraphicsConsoleConOutSetCursorPosition (
1477 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1482 GRAPHICS_CONSOLE_DEV
*Private
;
1483 GRAPHICS_CONSOLE_MODE_DATA
*ModeData
;
1487 Status
= EFI_SUCCESS
;
1489 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1491 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1492 ModeData
= &(Private
->ModeData
[This
->Mode
->Mode
]);
1494 if ((Column
>= ModeData
->Columns
) || (Row
>= ModeData
->Rows
)) {
1495 Status
= EFI_UNSUPPORTED
;
1499 if ((This
->Mode
->CursorColumn
== (INT32
) Column
) && (This
->Mode
->CursorRow
== (INT32
) Row
)) {
1500 Status
= EFI_SUCCESS
;
1506 This
->Mode
->CursorColumn
= (INT32
) Column
;
1507 This
->Mode
->CursorRow
= (INT32
) Row
;
1512 gBS
->RestoreTPL (OldTpl
);
1519 Makes the cursor visible or invisible.
1521 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
1523 @param This Protocol instance pointer.
1524 @param Visible If TRUE, the cursor is set to be visible, If FALSE,
1525 the cursor is set to be invisible.
1527 @retval EFI_SUCCESS The operation completed successfully.
1532 GraphicsConsoleConOutEnableCursor (
1533 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1539 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
1543 This
->Mode
->CursorVisible
= Visible
;
1547 gBS
->RestoreTPL (OldTpl
);
1552 Gets Graphics Console devcie's foreground color and background color.
1554 @param This Protocol instance pointer.
1555 @param Foreground Returned text foreground color.
1556 @param Background Returned text background color.
1558 @retval EFI_SUCCESS It returned always.
1563 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1564 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Foreground
,
1565 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Background
1570 Attribute
= This
->Mode
->Attribute
& 0x7F;
1572 *Foreground
= mGraphicsEfiColors
[Attribute
& 0x0f];
1573 *Background
= mGraphicsEfiColors
[Attribute
>> 4];
1579 Draw Unicode string on the Graphics Console device's screen.
1581 @param This Protocol instance pointer.
1582 @param UnicodeWeight One Unicode string to be displayed.
1583 @param Count The count of Unicode string.
1585 @retval EFI_OUT_OF_RESOURCES If no memory resource to use.
1586 @retval EFI_UNSUPPORTED If no Graphics Output protocol and UGA Draw
1588 @retval EFI_SUCCESS Drawing Unicode string implemented successfully.
1592 DrawUnicodeWeightAtCursorN (
1593 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
1594 IN CHAR16
*UnicodeWeight
,
1599 GRAPHICS_CONSOLE_DEV
*Private
;
1600 EFI_IMAGE_OUTPUT
*Blt
;
1602 EFI_FONT_DISPLAY_INFO
*FontInfo
;
1603 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1604 EFI_HII_ROW_INFO
*RowInfoArray
;
1605 UINTN RowInfoArraySize
;
1607 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1608 Blt
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1610 return EFI_OUT_OF_RESOURCES
;
1613 Blt
->Width
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopWidth
);
1614 Blt
->Height
= (UINT16
) (Private
->ModeData
[This
->Mode
->Mode
].GopHeight
);
1616 String
= AllocateCopyPool ((Count
+ 1) * sizeof (CHAR16
), UnicodeWeight
);
1617 if (String
== NULL
) {
1619 return EFI_OUT_OF_RESOURCES
;
1622 // Set the end character
1624 *(String
+ Count
) = L
'\0';
1626 FontInfo
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO
));
1627 if (FontInfo
== NULL
) {
1630 return EFI_OUT_OF_RESOURCES
;
1633 // Get current foreground and background colors.
1635 GetTextColors (This
, &FontInfo
->ForegroundColor
, &FontInfo
->BackgroundColor
);
1637 if (Private
->GraphicsOutput
!= NULL
) {
1639 // If Graphics Output protocol exists, using HII Font protocol to draw.
1641 Blt
->Image
.Screen
= Private
->GraphicsOutput
;
1643 Status
= mHiiFont
->StringToImage (
1645 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_DIRECT_TO_SCREEN
| EFI_HII_IGNORE_LINE_BREAK
,
1649 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1650 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1656 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1658 // If Graphics Output protocol cannot be found and PcdUgaConsumeSupport enabled,
1659 // using UGA Draw protocol to draw.
1661 ASSERT (Private
->UgaDraw
!= NULL
);
1663 UgaDraw
= Private
->UgaDraw
;
1665 Blt
->Image
.Bitmap
= AllocateZeroPool (Blt
->Width
* Blt
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1666 if (Blt
->Image
.Bitmap
== NULL
) {
1669 return EFI_OUT_OF_RESOURCES
;
1672 RowInfoArray
= NULL
;
1674 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,
1675 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.
1677 Status
= mHiiFont
->StringToImage (
1679 EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_IGNORE_LINE_BREAK
,
1683 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1684 This
->Mode
->CursorRow
* EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1690 if (!EFI_ERROR (Status
)) {
1692 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will
1693 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.
1695 ASSERT (RowInfoArraySize
<= 1);
1697 Status
= UgaDraw
->Blt (
1699 (EFI_UGA_PIXEL
*) Blt
->Image
.Bitmap
,
1700 EfiUgaBltBufferToVideo
,
1701 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1702 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1703 This
->Mode
->CursorColumn
* EFI_GLYPH_WIDTH
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaX
,
1704 (This
->Mode
->CursorRow
) * EFI_GLYPH_HEIGHT
+ Private
->ModeData
[This
->Mode
->Mode
].DeltaY
,
1705 RowInfoArray
[0].LineWidth
,
1706 RowInfoArray
[0].LineHeight
,
1707 Blt
->Width
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1711 FreePool (RowInfoArray
);
1712 FreePool (Blt
->Image
.Bitmap
);
1714 Status
= EFI_UNSUPPORTED
;
1720 if (String
!= NULL
) {
1723 if (FontInfo
!= NULL
) {
1724 FreePool (FontInfo
);
1730 Flush the cursor on the screen.
1732 If CursorVisible is FALSE, nothing to do and return directly.
1733 If CursorVisible is TRUE,
1734 i) If the cursor shows on screen, it will be erased.
1735 ii) If the cursor does not show on screen, it will be shown.
1737 @param This Protocol instance pointer.
1739 @retval EFI_SUCCESS The cursor is erased successfully.
1744 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
1747 GRAPHICS_CONSOLE_DEV
*Private
;
1748 EFI_SIMPLE_TEXT_OUTPUT_MODE
*CurrentMode
;
1751 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1752 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
1753 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Foreground
;
1754 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION Background
;
1755 EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION BltChar
[EFI_GLYPH_HEIGHT
][EFI_GLYPH_WIDTH
];
1759 CurrentMode
= This
->Mode
;
1761 if (!CurrentMode
->CursorVisible
) {
1765 Private
= GRAPHICS_CONSOLE_CON_OUT_DEV_FROM_THIS (This
);
1766 GraphicsOutput
= Private
->GraphicsOutput
;
1767 UgaDraw
= Private
->UgaDraw
;
1770 // In this driver, only narrow character was supported.
1773 // Blt a character to the screen
1775 GlyphX
= (CurrentMode
->CursorColumn
* EFI_GLYPH_WIDTH
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaX
;
1776 GlyphY
= (CurrentMode
->CursorRow
* EFI_GLYPH_HEIGHT
) + Private
->ModeData
[CurrentMode
->Mode
].DeltaY
;
1777 if (GraphicsOutput
!= NULL
) {
1778 GraphicsOutput
->Blt (
1780 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1781 EfiBltVideoToBltBuffer
,
1788 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1790 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1793 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1794 EfiUgaVideoToBltBuffer
,
1801 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1805 GetTextColors (This
, &Foreground
.Pixel
, &Background
.Pixel
);
1808 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
1810 for (PosY
= 0; PosY
< EFI_GLYPH_HEIGHT
; PosY
++) {
1811 for (PosX
= 0; PosX
< EFI_GLYPH_WIDTH
; PosX
++) {
1812 if ((mCursorGlyph
.GlyphCol1
[PosY
] & (BIT0
<< PosX
)) != 0) {
1813 BltChar
[PosY
][EFI_GLYPH_WIDTH
- PosX
- 1].Raw
^= Foreground
.Raw
;
1818 if (GraphicsOutput
!= NULL
) {
1819 GraphicsOutput
->Blt (
1821 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) BltChar
,
1822 EfiBltBufferToVideo
,
1829 EFI_GLYPH_WIDTH
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1831 } else if (FeaturePcdGet (PcdUgaConsumeSupport
)) {
1834 (EFI_UGA_PIXEL
*) (UINTN
) BltChar
,
1835 EfiUgaBltBufferToVideo
,
1842 EFI_GLYPH_WIDTH
* sizeof (EFI_UGA_PIXEL
)
1850 HII Database Protocol notification event handler.
1852 Register font package when HII Database Protocol has been installed.
1854 @param[in] Event Event whose notification function is being invoked.
1855 @param[in] Context Pointer to the notification function's context.
1859 RegisterFontPackage (
1865 EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*SimplifiedFont
;
1866 UINT32 PackageLength
;
1869 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
1872 // Locate HII Database Protocol
1874 Status
= gBS
->LocateProtocol (
1875 &gEfiHiiDatabaseProtocolGuid
,
1877 (VOID
**) &HiiDatabase
1879 ASSERT_EFI_ERROR (Status
);
1882 // Add 4 bytes to the header for entire length for HiiAddPackages use only.
1884 // +--------------------------------+ <-- Package
1886 // | PackageLength(4 bytes) |
1888 // |--------------------------------| <-- SimplifiedFont
1890 // |EFI_HII_SIMPLE_FONT_PACKAGE_HDR |
1892 // |--------------------------------| <-- Location
1894 // | gUsStdNarrowGlyphData |
1896 // +--------------------------------+
1898 PackageLength
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
) + mNarrowFontSize
+ 4;
1899 Package
= AllocateZeroPool (PackageLength
);
1900 ASSERT (Package
!= NULL
);
1902 WriteUnaligned32((UINT32
*) Package
,PackageLength
);
1903 SimplifiedFont
= (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
*) (Package
+ 4);
1904 SimplifiedFont
->Header
.Length
= (UINT32
) (PackageLength
- 4);
1905 SimplifiedFont
->Header
.Type
= EFI_HII_PACKAGE_SIMPLE_FONTS
;
1906 SimplifiedFont
->NumberOfNarrowGlyphs
= (UINT16
) (mNarrowFontSize
/ sizeof (EFI_NARROW_GLYPH
));
1908 Location
= (UINT8
*) (&SimplifiedFont
->NumberOfWideGlyphs
+ 1);
1909 CopyMem (Location
, gUsStdNarrowGlyphData
, mNarrowFontSize
);
1912 // Add this simplified font package to a package list then install it.
1914 mHiiHandle
= HiiAddPackages (
1915 &mFontPackageListGuid
,
1920 ASSERT (mHiiHandle
!= NULL
);
1925 The user Entry Point for module GraphicsConsole. The user code starts with this function.
1927 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1928 @param[in] SystemTable A pointer to the EFI System Table.
1930 @retval EFI_SUCCESS The entry point is executed successfully.
1931 @return other Some error occurs when executing this entry point.
1936 InitializeGraphicsConsole (
1937 IN EFI_HANDLE ImageHandle
,
1938 IN EFI_SYSTEM_TABLE
*SystemTable
1944 // Register notify function on HII Database Protocol to add font package.
1946 EfiCreateProtocolNotifyEvent (
1947 &gEfiHiiDatabaseProtocolGuid
,
1949 RegisterFontPackage
,
1955 // Install driver model protocol(s).
1957 Status
= EfiLibInstallDriverBindingComponentName2 (
1960 &gGraphicsConsoleDriverBinding
,
1962 &gGraphicsConsoleComponentName
,
1963 &gGraphicsConsoleComponentName2
1965 ASSERT_EFI_ERROR (Status
);