TianoCore EDK2 master
Loading...
Searching...
No Matches
DisplayUpdateProgressLibText.c
Go to the documentation of this file.
1
12#include <PiDxe.h>
13#include <Library/DebugLib.h>
15#include <Library/UefiLib.h>
16
17//
18// Control Style. Set to 100 so it is reset on first call.
19//
20UINTN mPreviousProgress = 100;
21
22//
23// Text foreground color of progress bar
24//
25UINTN mProgressBarForegroundColor;
26
50EFIAPI
52 IN UINTN Completion,
54 )
55{
56 UINTN Index;
57 UINTN CurrentAttribute;
58
59 //
60 // Check range
61 //
62 if (Completion > 100) {
63 return EFI_INVALID_PARAMETER;
64 }
65
66 //
67 // Check to see if this Completion percentage has already been displayed
68 //
69 if (Completion == mPreviousProgress) {
70 return EFI_SUCCESS;
71 }
72
73 //
74 // Do special init on first call of each progress session
75 //
76 if (mPreviousProgress == 100) {
77 Print (L"\n");
78
79 //
80 // Convert pixel color to text foreground color
81 //
82 if (Color == NULL) {
83 mProgressBarForegroundColor = EFI_WHITE;
84 } else {
85 mProgressBarForegroundColor = EFI_BLACK;
86 if (Color->Pixel.Blue >= 0x40) {
87 mProgressBarForegroundColor |= EFI_BLUE;
88 }
89
90 if (Color->Pixel.Green >= 0x40) {
91 mProgressBarForegroundColor |= EFI_GREEN;
92 }
93
94 if (Color->Pixel.Red >= 0x40) {
95 mProgressBarForegroundColor |= EFI_RED;
96 }
97
98 if ((Color->Pixel.Blue >= 0xC0) || (Color->Pixel.Green >= 0xC0) || (Color->Pixel.Red >= 0xC0)) {
99 mProgressBarForegroundColor |= EFI_BRIGHT;
100 }
101
102 if (mProgressBarForegroundColor == EFI_BLACK) {
103 mProgressBarForegroundColor = EFI_WHITE;
104 }
105 }
106
107 //
108 // Clear previous
109 //
110 mPreviousProgress = 0;
111 }
112
113 //
114 // Can not update progress bar if Completion is less than previous
115 //
116 if (Completion < mPreviousProgress) {
117 DEBUG ((DEBUG_WARN, "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n", Completion, mPreviousProgress));
118 return EFI_INVALID_PARAMETER;
119 }
120
121 //
122 // Save current text color
123 //
124 CurrentAttribute = (UINTN)gST->ConOut->Mode->Attribute;
125
126 //
127 // Print progress percentage
128 //
129 Print (L"\rUpdate Progress - %3d%% ", Completion);
130
131 //
132 // Set progress bar color
133 //
134 gST->ConOut->SetAttribute (
135 gST->ConOut,
136 EFI_TEXT_ATTR (mProgressBarForegroundColor, EFI_BLACK)
137 );
138
139 //
140 // Print completed portion of progress bar
141 //
142 for (Index = 0; Index < Completion / 2; Index++) {
143 Print (L"%c", BLOCKELEMENT_FULL_BLOCK);
144 }
145
146 //
147 // Restore text color
148 //
149 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);
150
151 //
152 // Print remaining portion of progress bar
153 //
154 for ( ; Index < 50; Index++) {
155 Print (L"%c", BLOCKELEMENT_LIGHT_SHADE);
156 }
157
158 mPreviousProgress = Completion;
159
160 return EFI_SUCCESS;
161}
UINT64 UINTN
EFI_STATUS EFIAPI DisplayUpdateProgress(IN UINTN Completion, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Color OPTIONAL)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064