TianoCore EDK2 master
Loading...
Searching...
No Matches
BootLogoLib.c
Go to the documentation of this file.
1
11#include <Uefi.h>
15#include <Protocol/BootLogo.h>
16#include <Protocol/BootLogo2.h>
17#include <Library/BaseLib.h>
18#include <Library/UefiLib.h>
21#include <Library/PcdLib.h>
23#include <Library/DebugLib.h>
24
32EFIAPI
34 VOID
35 )
36{
37 EFI_STATUS Status;
38 EDKII_PLATFORM_LOGO_PROTOCOL *PlatformLogo;
39 EDKII_PLATFORM_LOGO_DISPLAY_ATTRIBUTE Attribute;
40 INTN OffsetX;
41 INTN OffsetY;
42 UINT32 SizeOfX;
43 UINT32 SizeOfY;
44 INTN DestX;
45 INTN DestY;
46 UINT32 Instance;
47 EFI_IMAGE_INPUT Image;
49 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
50 EFI_BOOT_LOGO_PROTOCOL *BootLogo;
52 UINTN NumberOfLogos;
54 UINTN LogoDestX;
55 UINTN LogoDestY;
56 UINTN LogoHeight;
57 UINTN LogoWidth;
58 UINTN NewDestX;
59 UINTN NewDestY;
60 UINTN BufferSize;
61
62 Status = gBS->LocateProtocol (&gEdkiiPlatformLogoProtocolGuid, NULL, (VOID **)&PlatformLogo);
63 if (EFI_ERROR (Status)) {
64 return EFI_UNSUPPORTED;
65 }
66
67 //
68 // Try to open GOP first
69 //
70 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
71 if (EFI_ERROR (Status)) {
72 return EFI_UNSUPPORTED;
73 }
74
75 //
76 // Try to open Boot Logo Protocol.
77 //
78 Status = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **)&BootLogo);
79 if (EFI_ERROR (Status)) {
80 BootLogo = NULL;
81 }
82
83 //
84 // Try to open Boot Logo 2 Protocol.
85 //
86 Status = gBS->LocateProtocol (&gEdkiiBootLogo2ProtocolGuid, NULL, (VOID **)&BootLogo2);
87 if (EFI_ERROR (Status)) {
88 BootLogo2 = NULL;
89 }
90
91 //
92 // Erase Cursor from screen
93 //
94 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
95
96 SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
97 SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
98
99 Blt = NULL;
100 NumberOfLogos = 0;
101 LogoDestX = 0;
102 LogoDestY = 0;
103 LogoHeight = 0;
104 LogoWidth = 0;
105 NewDestX = 0;
106 NewDestY = 0;
107 Instance = 0;
108 DestX = 0;
109 DestY = 0;
110 while (TRUE) {
111 //
112 // Get image from PlatformLogo protocol.
113 //
114 Status = PlatformLogo->GetImage (
115 PlatformLogo,
116 &Instance,
117 &Image,
118 &Attribute,
119 &OffsetX,
120 &OffsetY
121 );
122 if (EFI_ERROR (Status)) {
123 break;
124 }
125
126 if (Blt != NULL) {
127 FreePool (Blt);
128 }
129
130 Blt = Image.Bitmap;
131
132 //
133 // Calculate the display position according to Attribute.
134 //
135 switch (Attribute) {
136 case EdkiiPlatformLogoDisplayAttributeLeftTop:
137 DestX = 0;
138 DestY = 0;
139 break;
140 case EdkiiPlatformLogoDisplayAttributeCenterTop:
141 DestX = (SizeOfX - Image.Width) / 2;
142 DestY = 0;
143 break;
144 case EdkiiPlatformLogoDisplayAttributeRightTop:
145 DestX = SizeOfX - Image.Width;
146 DestY = 0;
147 break;
148
149 case EdkiiPlatformLogoDisplayAttributeCenterLeft:
150 DestX = 0;
151 DestY = (SizeOfY - Image.Height) / 2;
152 break;
153 case EdkiiPlatformLogoDisplayAttributeCenter:
154 DestX = (SizeOfX - Image.Width) / 2;
155 DestY = (SizeOfY - Image.Height) / 2;
156 break;
157 case EdkiiPlatformLogoDisplayAttributeCenterRight:
158 DestX = SizeOfX - Image.Width;
159 DestY = (SizeOfY - Image.Height) / 2;
160 break;
161
162 case EdkiiPlatformLogoDisplayAttributeLeftBottom:
163 DestX = 0;
164 DestY = SizeOfY - Image.Height;
165 break;
166 case EdkiiPlatformLogoDisplayAttributeCenterBottom:
167 DestX = (SizeOfX - Image.Width) / 2;
168 DestY = SizeOfY - Image.Height;
169 break;
170 case EdkiiPlatformLogoDisplayAttributeRightBottom:
171 DestX = SizeOfX - Image.Width;
172 DestY = SizeOfY - Image.Height;
173 break;
174
175 default:
176 ASSERT (FALSE);
177 continue;
178 break;
179 }
180
181 DestX += OffsetX;
182 DestY += OffsetY;
183
184 if ((DestX >= 0) && (DestY >= 0)) {
185 Status = GraphicsOutput->Blt (
186 GraphicsOutput,
187 Blt,
189 0,
190 0,
191 (UINTN)DestX,
192 (UINTN)DestY,
193 Image.Width,
194 Image.Height,
195 Image.Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
196 );
197
198 //
199 // Report displayed Logo information.
200 //
201 if (!EFI_ERROR (Status)) {
202 NumberOfLogos++;
203
204 if (NumberOfLogos == 1) {
205 //
206 // The first Logo.
207 //
208 LogoDestX = (UINTN)DestX;
209 LogoDestY = (UINTN)DestY;
210 LogoWidth = Image.Width;
211 LogoHeight = Image.Height;
212 } else {
213 //
214 // Merge new logo with old one.
215 //
216 NewDestX = MIN ((UINTN)DestX, LogoDestX);
217 NewDestY = MIN ((UINTN)DestY, LogoDestY);
218 LogoWidth = MAX ((UINTN)DestX + Image.Width, LogoDestX + LogoWidth) - NewDestX;
219 LogoHeight = MAX ((UINTN)DestY + Image.Height, LogoDestY + LogoHeight) - NewDestY;
220
221 LogoDestX = NewDestX;
222 LogoDestY = NewDestY;
223 }
224 }
225 }
226 }
227
228 if (((BootLogo == NULL) && (BootLogo2 == NULL)) || (NumberOfLogos == 0)) {
229 //
230 // No logo displayed.
231 //
232 if (Blt != NULL) {
233 FreePool (Blt);
234 }
235
236 return Status;
237 }
238
239 //
240 // Advertise displayed Logo information.
241 //
242 if (NumberOfLogos == 1) {
243 //
244 // Only one logo displayed, use its Blt buffer directly for BootLogo protocol.
245 //
246 LogoBlt = Blt;
247 Status = EFI_SUCCESS;
248 } else {
249 //
250 // More than one Logo displayed, get merged BltBuffer using VideoToBuffer operation.
251 //
252 if (Blt != NULL) {
253 FreePool (Blt);
254 }
255
256 //
257 // Ensure the LogoHeight * LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) doesn't overflow
258 //
259 if (LogoHeight > MAX_UINTN / LogoWidth / sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) {
260 return EFI_UNSUPPORTED;
261 }
262
263 BufferSize = LogoWidth * LogoHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
264
265 LogoBlt = AllocatePool (BufferSize);
266 if (LogoBlt == NULL) {
267 return EFI_OUT_OF_RESOURCES;
268 }
269
270 Status = GraphicsOutput->Blt (
271 GraphicsOutput,
272 LogoBlt,
274 LogoDestX,
275 LogoDestY,
276 0,
277 0,
278 LogoWidth,
279 LogoHeight,
280 LogoWidth * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
281 );
282 }
283
284 if (!EFI_ERROR (Status)) {
285 //
286 // Attempt to register logo with Boot Logo 2 Protocol first
287 //
288 if (BootLogo2 != NULL) {
289 Status = BootLogo2->SetBootLogo (BootLogo2, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight);
290 }
291
292 //
293 // If Boot Logo 2 Protocol is not available or registration with Boot Logo 2
294 // Protocol failed, then attempt to register logo with Boot Logo Protocol
295 //
296 if (EFI_ERROR (Status) && (BootLogo != NULL)) {
297 Status = BootLogo->SetBootLogo (BootLogo, LogoBlt, LogoDestX, LogoDestY, LogoWidth, LogoHeight);
298 }
299
300 //
301 // Status of this function is EFI_SUCCESS even if registration with Boot
302 // Logo 2 Protocol or Boot Logo Protocol fails.
303 //
304 Status = EFI_SUCCESS;
305 }
306
307 FreePool (LogoBlt);
308
309 return Status;
310}
311
320EFIAPI
322 VOID
323 )
324{
325 //
326 // Enable Cursor on Screen
327 //
328 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
329 return EFI_SUCCESS;
330}
331
347EFIAPI
349 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,
350 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,
351 IN CHAR16 *Title,
352 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,
353 IN UINTN Progress,
354 IN UINTN PreviousValue
355 )
356{
357 EFI_STATUS Status;
358 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
359 UINT32 SizeOfX;
360 UINT32 SizeOfY;
362 UINTN BlockHeight;
363 UINTN BlockWidth;
364 UINTN BlockNum;
365 UINTN PosX;
366 UINTN PosY;
367 UINTN Index;
368
369 if (Progress > 100) {
370 return EFI_INVALID_PARAMETER;
371 }
372
373 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
374 if (EFI_ERROR (Status)) {
375 return EFI_UNSUPPORTED;
376 }
377
378 SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;
379 SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;
380
381 BlockWidth = SizeOfX / 100;
382 BlockHeight = SizeOfY / 50;
383
384 BlockNum = Progress;
385
386 PosX = 0;
387 PosY = SizeOfY * 48 / 50;
388
389 if (BlockNum == 0) {
390 //
391 // Clear progress area
392 //
393 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);
394
395 Status = GraphicsOutput->Blt (
396 GraphicsOutput,
397 &Color,
399 0,
400 0,
401 0,
402 PosY - EFI_GLYPH_HEIGHT - 1,
403 SizeOfX,
404 SizeOfY - (PosY - EFI_GLYPH_HEIGHT - 1),
405 SizeOfX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
406 );
407 }
408
409 //
410 // Show progress by drawing blocks
411 //
412 for (Index = PreviousValue; Index < BlockNum; Index++) {
413 PosX = Index * BlockWidth;
414 Status = GraphicsOutput->Blt (
415 GraphicsOutput,
416 &ProgressColor,
418 0,
419 0,
420 PosX,
421 PosY,
422 BlockWidth - 1,
423 BlockHeight,
424 (BlockWidth) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
425 );
426 }
427
428 PrintXY (
429 (SizeOfX - StrLen (Title) * EFI_GLYPH_WIDTH) / 2,
430 PosY - EFI_GLYPH_HEIGHT - 1,
431 &TitleForeground,
432 &TitleBackground,
433 Title
434 );
435
436 return EFI_SUCCESS;
437}
UINT64 UINTN
INT64 INTN
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
EFI_STATUS EFIAPI BootLogoUpdateProgress(IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground, IN CHAR16 *Title, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor, IN UINTN Progress, IN UINTN PreviousValue)
Definition: BootLogoLib.c:348
EFI_STATUS EFIAPI BootLogoDisableLogo(VOID)
Definition: BootLogoLib.c:321
EFI_STATUS EFIAPI BootLogoEnableLogo(VOID)
Definition: BootLogoLib.c:33
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define MIN(a, b)
Definition: Base.h:1007
#define VOID
Definition: Base.h:269
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define MAX(a, b)
Definition: Base.h:992
@ EfiBltVideoToBltBuffer
@ EfiBltBufferToVideo
@ EfiBltVideoFill
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
UINTN EFIAPI PrintXY(IN UINTN PointX, IN UINTN PointY, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround OPTIONAL, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround OPTIONAL, IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:527
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * Info
EFI_HANDLE ConsoleOutHandle
Definition: UefiSpec.h:2072
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2077