]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdateProgressLibText.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / DisplayUpdateProgressLibText / DisplayUpdateProgressLibText.c
CommitLineData
ec50f753 1/** @file\r
72b0a9be
MK
2 Provides services to display completion progress of a firmware update on a\r
3 text console.\r
4\r
5 Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>\r
6 Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r
7\r
9d510e61 8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
72b0a9be
MK
9\r
10**/\r
11\r
12#include <PiDxe.h>\r
13#include <Library/DebugLib.h>\r
14#include <Library/UefiBootServicesTableLib.h>\r
15#include <Library/UefiLib.h>\r
16\r
17//\r
18// Control Style. Set to 100 so it is reset on first call.\r
19//\r
20UINTN mPreviousProgress = 100;\r
21\r
22//\r
23// Text foreground color of progress bar\r
24//\r
25UINTN mProgressBarForegroundColor;\r
26\r
27/**\r
28 Function indicates the current completion progress of a firmware update.\r
29 Platform may override with its own specific function.\r
30\r
31 @param[in] Completion A value between 0 and 100 indicating the current\r
32 completion progress of a firmware update. This\r
33 value must the the same or higher than previous\r
34 calls to this service. The first call of 0 or a\r
35 value of 0 after reaching a value of 100 resets\r
36 the progress indicator to 0.\r
37 @param[in] Color Color of the progress indicator. Only used when\r
38 Completion is 0 to set the color of the progress\r
39 indicator. If Color is NULL, then the default color\r
40 is used.\r
41\r
42 @retval EFI_SUCCESS Progress displayed successfully.\r
43 @retval EFI_INVALID_PARAMETER Completion is not in range 0..100.\r
44 @retval EFI_INVALID_PARAMETER Completion is less than Completion value from\r
45 a previous call to this service.\r
46 @retval EFI_NOT_READY The device used to indicate progress is not\r
47 available.\r
48**/\r
49EFI_STATUS\r
50EFIAPI\r
51DisplayUpdateProgress (\r
52 IN UINTN Completion,\r
53 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Color OPTIONAL\r
54 )\r
55{\r
56 UINTN Index;\r
57 UINTN CurrentAttribute;\r
58\r
59 //\r
60 // Check range\r
61 //\r
62 if (Completion > 100) {\r
63 return EFI_INVALID_PARAMETER;\r
64 }\r
65\r
66 //\r
67 // Check to see if this Completion percentage has already been displayed\r
68 //\r
69 if (Completion == mPreviousProgress) {\r
70 return EFI_SUCCESS;\r
71 }\r
72\r
73 //\r
74 // Do special init on first call of each progress session\r
75 //\r
76 if (mPreviousProgress == 100) {\r
77 Print (L"\n");\r
78\r
79 //\r
80 // Convert pixel color to text foreground color\r
81 //\r
82 if (Color == NULL) {\r
83 mProgressBarForegroundColor = EFI_WHITE;\r
84 } else {\r
85 mProgressBarForegroundColor = EFI_BLACK;\r
86 if (Color->Pixel.Blue >= 0x40) {\r
87 mProgressBarForegroundColor |= EFI_BLUE;\r
88 }\r
89 if (Color->Pixel.Green >= 0x40) {\r
90 mProgressBarForegroundColor |= EFI_GREEN;\r
91 }\r
92 if (Color->Pixel.Red >= 0x40) {\r
93 mProgressBarForegroundColor |= EFI_RED;\r
94 }\r
95 if (Color->Pixel.Blue >= 0xC0 || Color->Pixel.Green >= 0xC0 || Color->Pixel.Red >= 0xC0) {\r
96 mProgressBarForegroundColor |= EFI_BRIGHT;\r
97 }\r
98 if (mProgressBarForegroundColor == EFI_BLACK) {\r
99 mProgressBarForegroundColor = EFI_WHITE;\r
100 }\r
101 }\r
102\r
103 //\r
104 // Clear previous\r
105 //\r
106 mPreviousProgress = 0;\r
107 }\r
108\r
109 //\r
110 // Can not update progress bar if Completion is less than previous\r
111 //\r
112 if (Completion < mPreviousProgress) {\r
113 DEBUG ((DEBUG_WARN, "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n", Completion, mPreviousProgress));\r
114 return EFI_INVALID_PARAMETER;\r
115 }\r
116\r
117 //\r
118 // Save current text color\r
119 //\r
120 CurrentAttribute = (UINTN)gST->ConOut->Mode->Attribute;\r
121\r
122 //\r
123 // Print progress percentage\r
124 //\r
125 Print (L"\rUpdate Progress - %3d%% ", Completion);\r
126\r
127 //\r
128 // Set progress bar color\r
129 //\r
130 gST->ConOut->SetAttribute (\r
131 gST->ConOut,\r
132 EFI_TEXT_ATTR (mProgressBarForegroundColor, EFI_BLACK)\r
133 );\r
134\r
135 //\r
136 // Print completed portion of progress bar\r
137 //\r
138 for (Index = 0; Index < Completion / 2; Index++) {\r
139 Print (L"%c", BLOCKELEMENT_FULL_BLOCK);\r
140 }\r
141\r
142 //\r
143 // Restore text color\r
144 //\r
145 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
146\r
147 //\r
148 // Print remaining portion of progress bar\r
149 //\r
150 for (; Index < 50; Index++) {\r
151 Print (L"%c", BLOCKELEMENT_LIGHT_SHADE);\r
152 }\r
153\r
154 mPreviousProgress = Completion;\r
155\r
156 return EFI_SUCCESS;\r
157}\r