]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/GraphicsLib/Graphics.c
Remove the unnecessary include, such as PiDxe.h, PiPei.h, Base.h and Uefi.h in header...
[mirror_edk2.git] / MdeModulePkg / Library / GraphicsLib / Graphics.c
CommitLineData
2f50ef83 1/** @file\r
eb91f2f8 2 Library supports diplaying graphical splash screen,\r
3 locking of keyboard input and printing character on\r
4 screen. These basic graphics operations are based on UEFI HII, \r
5 Graphics Output protocol or UGA Draw protocol.\r
93e3992d 6\r
2f50ef83 7Copyright (c) 2006 - 2008, Intel Corporation\r
93e3992d 8All rights reserved. This program and the accompanying materials\r
9are licensed and made available under the terms and conditions of the BSD License\r
10which accompanies this distribution. The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
12\r
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18\r
19034421 19#include <PiDxe.h>\r
93e3992d 20\r
21#include <Protocol/SimpleTextOut.h>\r
22#include <Protocol/OEMBadging.h>\r
23#include <Protocol/ConsoleControl.h>\r
24#include <Protocol/GraphicsOutput.h>\r
93e3992d 25#include <Protocol/UgaDraw.h>\r
26#include <Protocol/HiiFont.h>\r
27#include <Protocol/HiiImage.h>\r
28\r
29#include <Guid/Bmp.h>\r
30\r
31#include <Library/GraphicsLib.h>\r
32#include <Library/PrintLib.h>\r
33#include <Library/BaseLib.h>\r
34#include <Library/MemoryAllocationLib.h>\r
35#include <Library/UefiBootServicesTableLib.h>\r
36#include <Library/DebugLib.h>\r
37#include <Library/BaseMemoryLib.h>\r
38#include <Library/DxePiLib.h>\r
8541adab 39#include <Library/PcdLib.h>\r
93e3992d 40\r
41STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r
42 { 0x00, 0x00, 0x00, 0x00 },\r
43 { 0x98, 0x00, 0x00, 0x00 },\r
44 { 0x00, 0x98, 0x00, 0x00 },\r
45 { 0x98, 0x98, 0x00, 0x00 },\r
46 { 0x00, 0x00, 0x98, 0x00 },\r
47 { 0x98, 0x00, 0x98, 0x00 },\r
48 { 0x00, 0x98, 0x98, 0x00 },\r
49 { 0x98, 0x98, 0x98, 0x00 },\r
50 { 0x10, 0x10, 0x10, 0x00 },\r
51 { 0xff, 0x10, 0x10, 0x00 },\r
52 { 0x10, 0xff, 0x10, 0x00 },\r
53 { 0xff, 0xff, 0x10, 0x00 },\r
54 { 0x10, 0x10, 0xff, 0x00 },\r
55 { 0xf0, 0x10, 0xff, 0x00 },\r
56 { 0x10, 0xff, 0xff, 0x00 },\r
57 { 0xff, 0xff, 0xff, 0x00 }\r
58};\r
59\r
60\r
2f50ef83 61/**\r
62 Return the graphics image file named FileNameGuid into Image and return it's\r
63 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the\r
64 file name.\r
65\r
66 @param FileNameGuid File Name of graphics file in the FV(s).\r
67 @param Image Pointer to pointer to return graphics image. If NULL, a \r
68 buffer will be allocated.\r
69 @param ImageSize Size of the graphics Image in bytes. Zero if no image found.\r
70\r
71 @retval EFI_SUCCESS Image and ImageSize are valid. \r
72 @retval EFI_BUFFER_TOO_SMALL Image not big enough. ImageSize has required size\r
73 @retval EFI_NOT_FOUND FileNameGuid not found\r
74\r
75**/\r
93e3992d 76EFI_STATUS\r
2f50ef83 77EFIAPI\r
93e3992d 78GetGraphicsBitMapFromFV (\r
79 IN EFI_GUID *FileNameGuid,\r
80 OUT VOID **Image,\r
81 OUT UINTN *ImageSize\r
82 )\r
2f50ef83 83{\r
84 return GetGraphicsBitMapFromFVEx (NULL, FileNameGuid, Image, ImageSize);\r
85}\r
93e3992d 86\r
2f50ef83 87/**\r
93e3992d 88 Return the graphics image file named FileNameGuid into Image and return it's\r
89 size in ImageSize. All Firmware Volumes (FV) in the system are searched for the\r
90 file name.\r
91\r
2f50ef83 92 @param ImageHandle The driver image handle of the caller. The parameter is used to\r
93 optimize the loading of the image file so that the FV from which\r
94 the driver image is loaded will be tried first. \r
95 @param FileNameGuid File Name of graphics file in the FV(s).\r
96 @param Image Pointer to pointer to return graphics image. If NULL, a \r
97 buffer will be allocated.\r
98 @param ImageSize Size of the graphics Image in bytes. Zero if no image found.\r
93e3992d 99\r
2f50ef83 100 @retval EFI_SUCCESS Image and ImageSize are valid. \r
101 @retval EFI_BUFFER_TOO_SMALL Image not big enough. ImageSize has required size\r
102 @retval EFI_NOT_FOUND FileNameGuid not found\r
93e3992d 103\r
2f50ef83 104**/\r
93e3992d 105EFI_STATUS\r
2f50ef83 106EFIAPI\r
93e3992d 107GetGraphicsBitMapFromFVEx (\r
108 IN EFI_HANDLE ImageHandle,\r
109 IN EFI_GUID *FileNameGuid,\r
110 OUT VOID **Image,\r
111 OUT UINTN *ImageSize\r
112 )\r
93e3992d 113{\r
72215954 114 return PiLibGetSectionFromAnyFv (\r
93e3992d 115 FileNameGuid,\r
116 EFI_SECTION_RAW,\r
117 0,\r
118 Image,\r
119 ImageSize\r
120 );\r
121}\r
122\r
2f50ef83 123/**\r
aaf14379 124 Convert a *.BMP graphics image to a GOP blt buffer. If a NULL Blt buffer\r
2f50ef83 125 is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt\r
126 buffer is passed in it will be used if it is big enough.\r
127\r
128 @param BmpImage Pointer to BMP file\r
129 @param BmpImageSize Number of bytes in BmpImage\r
130 @param GopBlt Buffer containing GOP version of BmpImage.\r
131 @param GopBltSize Size of GopBlt in bytes.\r
132 @param PixelHeight Height of GopBlt/BmpImage in pixels\r
133 @param PixelWidth Width of GopBlt/BmpImage in pixels\r
134\r
135 @retval EFI_SUCCESS GopBlt and GopBltSize are returned. \r
136 @retval EFI_UNSUPPORTED BmpImage is not a valid *.BMP image\r
137 @retval EFI_BUFFER_TOO_SMALL The passed in GopBlt buffer is not big enough.\r
138 GopBltSize will contain the required size.\r
aaf14379 139 @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate.\r
93e3992d 140\r
2f50ef83 141**/\r
93e3992d 142EFI_STATUS\r
2f50ef83 143EFIAPI\r
93e3992d 144ConvertBmpToGopBlt (\r
aaf14379 145 IN VOID *BmpImage,\r
146 IN UINTN BmpImageSize,\r
147 IN OUT VOID **GopBlt,\r
148 IN OUT UINTN *GopBltSize,\r
149 OUT UINTN *PixelHeight,\r
150 OUT UINTN *PixelWidth\r
93e3992d 151 )\r
93e3992d 152{\r
aaf14379 153 UINT8 *Image;\r
154 UINT8 *ImageHeader;\r
155 BMP_IMAGE_HEADER *BmpHeader;\r
156 BMP_COLOR_MAP *BmpColorMap;\r
93e3992d 157 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;\r
158 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;\r
aaf14379 159 UINTN BltBufferSize;\r
160 UINTN Index;\r
161 UINTN Height;\r
162 UINTN Width;\r
163 UINTN ImageIndex;\r
164 BOOLEAN IsAllocated;\r
93e3992d 165\r
166 BmpHeader = (BMP_IMAGE_HEADER *) BmpImage;\r
aaf14379 167\r
93e3992d 168 if (BmpHeader->CharB != 'B' || BmpHeader->CharM != 'M') {\r
169 return EFI_UNSUPPORTED;\r
170 }\r
171\r
aaf14379 172 //\r
173 // Doesn't support compress.\r
174 //\r
93e3992d 175 if (BmpHeader->CompressionType != 0) {\r
176 return EFI_UNSUPPORTED;\r
177 }\r
178\r
179 //\r
180 // Calculate Color Map offset in the image.\r
181 //\r
182 Image = BmpImage;\r
183 BmpColorMap = (BMP_COLOR_MAP *) (Image + sizeof (BMP_IMAGE_HEADER));\r
184\r
185 //\r
186 // Calculate graphics image data address in the image\r
187 //\r
188 Image = ((UINT8 *) BmpImage) + BmpHeader->ImageOffset;\r
189 ImageHeader = Image;\r
190\r
aaf14379 191 //\r
192 // Calculate the BltBuffer needed size.\r
193 //\r
93e3992d 194 BltBufferSize = BmpHeader->PixelWidth * BmpHeader->PixelHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
195 IsAllocated = FALSE;\r
196 if (*GopBlt == NULL) {\r
aaf14379 197 //\r
198 // GopBlt is not allocated by caller.\r
199 //\r
93e3992d 200 *GopBltSize = BltBufferSize;\r
201 *GopBlt = AllocatePool (*GopBltSize);\r
202 IsAllocated = TRUE;\r
203 if (*GopBlt == NULL) {\r
204 return EFI_OUT_OF_RESOURCES;\r
205 }\r
206 } else {\r
aaf14379 207 //\r
208 // GopBlt has been allocated by caller.\r
209 //\r
93e3992d 210 if (*GopBltSize < BltBufferSize) {\r
211 *GopBltSize = BltBufferSize;\r
212 return EFI_BUFFER_TOO_SMALL;\r
213 }\r
214 }\r
215\r
216 *PixelWidth = BmpHeader->PixelWidth;\r
217 *PixelHeight = BmpHeader->PixelHeight;\r
218\r
219 //\r
220 // Convert image from BMP to Blt buffer format\r
221 //\r
222 BltBuffer = *GopBlt;\r
223 for (Height = 0; Height < BmpHeader->PixelHeight; Height++) {\r
224 Blt = &BltBuffer[(BmpHeader->PixelHeight - Height - 1) * BmpHeader->PixelWidth];\r
225 for (Width = 0; Width < BmpHeader->PixelWidth; Width++, Image++, Blt++) {\r
226 switch (BmpHeader->BitPerPixel) {\r
227 case 1:\r
228 //\r
aaf14379 229 // Convert 1-bit (2 colors) BMP to 24-bit color\r
93e3992d 230 //\r
231 for (Index = 0; Index < 8 && Width < BmpHeader->PixelWidth; Index++) {\r
232 Blt->Red = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Red;\r
233 Blt->Green = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Green;\r
234 Blt->Blue = BmpColorMap[((*Image) >> (7 - Index)) & 0x1].Blue;\r
235 Blt++;\r
236 Width++;\r
237 }\r
238\r
239 Blt --;\r
240 Width --;\r
241 break;\r
242\r
243 case 4:\r
244 //\r
aaf14379 245 // Convert 4-bit (16 colors) BMP Palette to 24-bit color\r
93e3992d 246 //\r
247 Index = (*Image) >> 4;\r
248 Blt->Red = BmpColorMap[Index].Red;\r
249 Blt->Green = BmpColorMap[Index].Green;\r
250 Blt->Blue = BmpColorMap[Index].Blue;\r
251 if (Width < (BmpHeader->PixelWidth - 1)) {\r
252 Blt++;\r
253 Width++;\r
254 Index = (*Image) & 0x0f;\r
255 Blt->Red = BmpColorMap[Index].Red;\r
256 Blt->Green = BmpColorMap[Index].Green;\r
257 Blt->Blue = BmpColorMap[Index].Blue;\r
258 }\r
259 break;\r
260\r
261 case 8:\r
262 //\r
aaf14379 263 // Convert 8-bit (256 colors) BMP Palette to 24-bit color\r
93e3992d 264 //\r
265 Blt->Red = BmpColorMap[*Image].Red;\r
266 Blt->Green = BmpColorMap[*Image].Green;\r
267 Blt->Blue = BmpColorMap[*Image].Blue;\r
268 break;\r
269\r
270 case 24:\r
aaf14379 271 //\r
272 // It is 24-bit BMP.\r
273 //\r
93e3992d 274 Blt->Blue = *Image++;\r
275 Blt->Green = *Image++;\r
276 Blt->Red = *Image;\r
277 break;\r
278\r
279 default:\r
aaf14379 280 //\r
281 // Other bit format BMP is not supported.\r
282 //\r
93e3992d 283 if (IsAllocated) {\r
aaf14379 284 FreePool (*GopBlt);\r
93e3992d 285 *GopBlt = NULL;\r
286 }\r
287 return EFI_UNSUPPORTED;\r
288 break;\r
289 };\r
290\r
291 }\r
292\r
293 ImageIndex = (UINTN) (Image - ImageHeader);\r
294 if ((ImageIndex % 4) != 0) {\r
295 //\r
296 // Bmp Image starts each row on a 32-bit boundary!\r
297 //\r
298 Image = Image + (4 - (ImageIndex % 4));\r
299 }\r
300 }\r
301\r
302 return EFI_SUCCESS;\r
303}\r
304\r
305\r
2f50ef83 306/**\r
307 Use Console Control Protocol to lock the Console In Spliter virtual handle. \r
93e3992d 308 This is the ConInHandle and ConIn handle in the EFI system table. All key\r
309 presses will be ignored until the Password is typed in. The only way to\r
310 disable the password is to type it in to a ConIn device.\r
311\r
2f50ef83 312 @param Password Password used to lock ConIn device.\r
93e3992d 313\r
6cb26293 314 @retval EFI_SUCCESS lock the Console In Spliter virtual handle successfully.\r
aaf14379 315 @retval EFI_UNSUPPORTED Password not found.\r
93e3992d 316\r
2f50ef83 317**/\r
318EFI_STATUS\r
319EFIAPI\r
320LockKeyboards (\r
321 IN CHAR16 *Password\r
322 )\r
93e3992d 323{\r
324 EFI_STATUS Status;\r
325 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
326\r
327 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
328 if (EFI_ERROR (Status)) {\r
329 return EFI_UNSUPPORTED;\r
330 }\r
331\r
332 Status = ConsoleControl->LockStdIn (ConsoleControl, Password);\r
333 return Status;\r
334}\r
335\r
336\r
2f50ef83 337/**\r
93e3992d 338 Use Console Control to turn off UGA based Simple Text Out consoles from going\r
aaf14379 339 to the UGA device. Put up LogoFile on every UGA device that is a console.\r
93e3992d 340\r
aaf14379 341 @param LogoFile File name of logo to display on the center of the screen.\r
93e3992d 342\r
2f50ef83 343 @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed.\r
aaf14379 344 @retval EFI_UNSUPPORTED Logo not found.\r
93e3992d 345\r
2f50ef83 346**/\r
347EFI_STATUS\r
348EFIAPI\r
349EnableQuietBoot (\r
350 IN EFI_GUID *LogoFile\r
351 )\r
93e3992d 352{\r
353 return EnableQuietBootEx (LogoFile, NULL);\r
354}\r
355\r
2f50ef83 356/**\r
aaf14379 357 Use Console Control to turn off UGA based Simple Text Out consoles from going\r
2f50ef83 358 to the UGA device. Put up LogoFile on every UGA device that is a console\r
359\r
360 @param LogoFile File name of logo to display on the center of the screen.\r
361 @param ImageHandle The driver image handle of the caller. The parameter is used to\r
362 optimize the loading of the logo file so that the FV from which\r
363 the driver image is loaded will be tried first.\r
364\r
365 @retval EFI_SUCCESS ConsoleControl has been flipped to graphics and logo displayed.\r
aaf14379 366 @retval EFI_UNSUPPORTED Logo not found.\r
2f50ef83 367\r
368**/\r
93e3992d 369EFI_STATUS\r
2f50ef83 370EFIAPI\r
93e3992d 371EnableQuietBootEx (\r
372 IN EFI_GUID *LogoFile,\r
373 IN EFI_HANDLE ImageHandle\r
374 )\r
93e3992d 375{\r
376 EFI_STATUS Status;\r
377 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
378 EFI_OEM_BADGING_PROTOCOL *Badging;\r
379 UINT32 SizeOfX;\r
380 UINT32 SizeOfY;\r
381 INTN DestX;\r
382 INTN DestY;\r
383 UINT8 *ImageData;\r
384 UINTN ImageSize;\r
385 UINTN BltSize;\r
386 UINT32 Instance;\r
387 EFI_BADGING_FORMAT Format;\r
388 EFI_BADGING_DISPLAY_ATTRIBUTE Attribute;\r
389 UINTN CoordinateX;\r
390 UINTN CoordinateY;\r
391 UINTN Height;\r
392 UINTN Width;\r
393 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;\r
394 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
395 UINT32 ColorDepth;\r
396 UINT32 RefreshRate;\r
397 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
398\r
aaf14379 399 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
93e3992d 400 if (EFI_ERROR (Status)) {\r
401 return EFI_UNSUPPORTED;\r
402 }\r
403\r
404 UgaDraw = NULL;\r
405 //\r
406 // Try to open GOP first\r
407 //\r
aaf14379 408 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiGraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);\r
8541adab 409 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
93e3992d 410 GraphicsOutput = NULL;\r
411 //\r
2758d1ea 412 // Open GOP failed, try to open UGA\r
93e3992d 413 //\r
aaf14379 414 Status = gBS->HandleProtocol (gST->ConsoleOutHandle, &gEfiUgaDrawProtocolGuid, (VOID **) &UgaDraw);\r
8541adab 415 }\r
416 if (EFI_ERROR (Status)) {\r
417 return EFI_UNSUPPORTED;\r
93e3992d 418 }\r
419\r
420 Badging = NULL;\r
aaf14379 421 Status = gBS->LocateProtocol (&gEfiOEMBadgingProtocolGuid, NULL, (VOID **) &Badging);\r
93e3992d 422\r
aaf14379 423 //\r
424 // Set console control to graphics mode.\r
425 //\r
43670511 426 Status = ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenGraphics);\r
427 if (EFI_ERROR (Status)) {\r
428 return EFI_UNSUPPORTED;\r
429 }\r
93e3992d 430\r
431 if (GraphicsOutput != NULL) {\r
432 SizeOfX = GraphicsOutput->Mode->Info->HorizontalResolution;\r
433 SizeOfY = GraphicsOutput->Mode->Info->VerticalResolution;\r
8541adab 434 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
93e3992d 435 Status = UgaDraw->GetMode (UgaDraw, &SizeOfX, &SizeOfY, &ColorDepth, &RefreshRate);\r
436 if (EFI_ERROR (Status)) {\r
437 return EFI_UNSUPPORTED;\r
438 }\r
695f7e98 439 } else {\r
440 return EFI_UNSUPPORTED;\r
93e3992d 441 }\r
442\r
443 Instance = 0;\r
444 while (1) {\r
445 ImageData = NULL;\r
446 ImageSize = 0;\r
447\r
448 if (Badging != NULL) {\r
aaf14379 449 //\r
450 // Get image from OEMBadging protocol.\r
451 //\r
93e3992d 452 Status = Badging->GetImage (\r
453 Badging,\r
454 &Instance,\r
455 &Format,\r
456 &ImageData,\r
457 &ImageSize,\r
458 &Attribute,\r
459 &CoordinateX,\r
460 &CoordinateY\r
461 );\r
462 if (EFI_ERROR (Status)) {\r
463 return Status;\r
464 }\r
465\r
466 //\r
aaf14379 467 // Currently only support BMP format.\r
93e3992d 468 //\r
469 if (Format != EfiBadgingFormatBMP) {\r
aaf14379 470 SafeFreePool (ImageData);\r
93e3992d 471 continue;\r
472 }\r
473 } else {\r
aaf14379 474 //\r
475 // Get the specified image from FV.\r
476 //\r
93e3992d 477 Status = GetGraphicsBitMapFromFVEx (ImageHandle, LogoFile, (VOID **) &ImageData, &ImageSize);\r
478 if (EFI_ERROR (Status)) {\r
479 return EFI_UNSUPPORTED;\r
480 }\r
481\r
482 CoordinateX = 0;\r
483 CoordinateY = 0;\r
484 Attribute = EfiBadgingDisplayAttributeCenter;\r
485 }\r
486\r
487 Blt = NULL;\r
488 Status = ConvertBmpToGopBlt (\r
489 ImageData,\r
490 ImageSize,\r
aaf14379 491 (VOID **) &Blt,\r
93e3992d 492 &BltSize,\r
493 &Height,\r
494 &Width\r
495 );\r
496 if (EFI_ERROR (Status)) {\r
aaf14379 497 SafeFreePool (ImageData);\r
93e3992d 498 if (Badging == NULL) {\r
499 return Status;\r
500 } else {\r
501 continue;\r
502 }\r
503 }\r
504\r
aaf14379 505 //\r
506 // Caculate the display position according to Attribute.\r
507 //\r
93e3992d 508 switch (Attribute) {\r
509 case EfiBadgingDisplayAttributeLeftTop:\r
510 DestX = CoordinateX;\r
511 DestY = CoordinateY;\r
512 break;\r
513\r
514 case EfiBadgingDisplayAttributeCenterTop:\r
515 DestX = (SizeOfX - Width) / 2;\r
516 DestY = CoordinateY;\r
517 break;\r
518\r
519 case EfiBadgingDisplayAttributeRightTop:\r
520 DestX = (SizeOfX - Width - CoordinateX);\r
521 DestY = CoordinateY;;\r
522 break;\r
523\r
524 case EfiBadgingDisplayAttributeCenterRight:\r
525 DestX = (SizeOfX - Width - CoordinateX);\r
526 DestY = (SizeOfY - Height) / 2;\r
527 break;\r
528\r
529 case EfiBadgingDisplayAttributeRightBottom:\r
530 DestX = (SizeOfX - Width - CoordinateX);\r
531 DestY = (SizeOfY - Height - CoordinateY);\r
532 break;\r
533\r
534 case EfiBadgingDisplayAttributeCenterBottom:\r
535 DestX = (SizeOfX - Width) / 2;\r
536 DestY = (SizeOfY - Height - CoordinateY);\r
537 break;\r
538\r
539 case EfiBadgingDisplayAttributeLeftBottom:\r
540 DestX = CoordinateX;\r
541 DestY = (SizeOfY - Height - CoordinateY);\r
542 break;\r
543\r
544 case EfiBadgingDisplayAttributeCenterLeft:\r
545 DestX = CoordinateX;\r
546 DestY = (SizeOfY - Height) / 2;\r
547 break;\r
548\r
549 case EfiBadgingDisplayAttributeCenter:\r
550 DestX = (SizeOfX - Width) / 2;\r
551 DestY = (SizeOfY - Height) / 2;\r
552 break;\r
553\r
554 default:\r
555 DestX = CoordinateX;\r
556 DestY = CoordinateY;\r
557 break;\r
558 }\r
559\r
560 if ((DestX >= 0) && (DestY >= 0)) {\r
561 if (GraphicsOutput != NULL) {\r
562 Status = GraphicsOutput->Blt (\r
563 GraphicsOutput,\r
564 Blt,\r
565 EfiBltBufferToVideo,\r
566 0,\r
567 0,\r
568 (UINTN) DestX,\r
569 (UINTN) DestY,\r
570 Width,\r
571 Height,\r
572 Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
573 );\r
8541adab 574 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
93e3992d 575 Status = UgaDraw->Blt (\r
576 UgaDraw,\r
577 (EFI_UGA_PIXEL *) Blt,\r
578 EfiUgaBltBufferToVideo,\r
579 0,\r
580 0,\r
581 (UINTN) DestX,\r
582 (UINTN) DestY,\r
583 Width,\r
584 Height,\r
585 Width * sizeof (EFI_UGA_PIXEL)\r
586 );\r
695f7e98 587 } else {\r
588 Status = EFI_UNSUPPORTED;\r
93e3992d 589 }\r
590 }\r
591\r
aaf14379 592 SafeFreePool (ImageData);\r
593 SafeFreePool (Blt);\r
93e3992d 594\r
595 if (Badging == NULL) {\r
596 break;\r
597 }\r
598 }\r
599\r
600 return Status;\r
601}\r
602\r
2f50ef83 603/**\r
604 Use Console Control to turn on UGA based Simple Text Out consoles. The UGA \r
605 Simple Text Out screens will now be synced up with all non UGA output devices\r
93e3992d 606\r
2f50ef83 607 @retval EFI_SUCCESS UGA devices are back in text mode and synced up.\r
608 @retval EFI_UNSUPPORTED Logo not found\r
609\r
610**/\r
93e3992d 611EFI_STATUS\r
2f50ef83 612EFIAPI\r
93e3992d 613DisableQuietBoot (\r
614 VOID\r
615 )\r
93e3992d 616{\r
617 EFI_STATUS Status;\r
618 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;\r
619\r
620 Status = gBS->LocateProtocol (&gEfiConsoleControlProtocolGuid, NULL, (VOID **) &ConsoleControl);\r
621 if (EFI_ERROR (Status)) {\r
622 return EFI_UNSUPPORTED;\r
623 }\r
624\r
aaf14379 625 //\r
626 // Set console control to text mode.\r
627 //\r
93e3992d 628 return ConsoleControl->SetMode (ConsoleControl, EfiConsoleControlScreenText);\r
629}\r
630\r
2f50ef83 631/**\r
aaf14379 632 Internal display string worker function.\r
2f50ef83 633\r
aaf14379 634 @param GraphicsOutput Graphics output protocol interface.\r
635 @param UgaDraw UGA draw protocol interface.\r
636 @param Sto Simple text out protocol interface.\r
637 @param X X coordinate to start printing.\r
638 @param Y Y coordinate to start printing.\r
639 @param Foreground Foreground color.\r
640 @param Background Background color.\r
641 @param fmt Format string.\r
642 @param args Print arguments.\r
2f50ef83 643\r
aaf14379 644 @return Number of Characters printed. Zero means no any character \r
645 displayed successfully.\r
2f50ef83 646\r
647**/\r
93e3992d 648UINTN\r
2f50ef83 649Print (\r
93e3992d 650 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,\r
651 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw,\r
8541adab 652 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto,\r
93e3992d 653 IN UINTN X,\r
654 IN UINTN Y,\r
655 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Foreground,\r
656 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Background,\r
657 IN CHAR16 *fmt,\r
658 IN VA_LIST args\r
659 )\r
93e3992d 660{\r
661 VOID *Buffer;\r
662 EFI_STATUS Status;\r
663 UINTN Index;\r
664 CHAR16 *UnicodeWeight;\r
665 UINT32 HorizontalResolution;\r
666 UINT32 VerticalResolution;\r
667 UINT32 ColorDepth;\r
668 UINT32 RefreshRate;\r
669 UINTN BufferLen;\r
670 UINTN LineBufferLen;\r
671 EFI_HII_FONT_PROTOCOL *HiiFont;\r
672 EFI_IMAGE_OUTPUT *Blt;\r
8541adab 673 EFI_FONT_DISPLAY_INFO *FontInfo;\r
2f50ef83 674 EFI_HII_ROW_INFO *RowInfoArray;\r
675 UINTN RowInfoArraySize;\r
aaf14379 676 UINTN PrintNum; \r
93e3992d 677\r
678 //\r
679 // For now, allocate an arbitrarily long buffer\r
680 //\r
681 Buffer = AllocateZeroPool (0x10000);\r
682 if (Buffer == NULL) {\r
aaf14379 683 return 0;\r
93e3992d 684 }\r
685\r
8541adab 686 HorizontalResolution = 0;\r
687 VerticalResolution = 0;\r
688 Blt = NULL;\r
689 FontInfo = NULL;\r
37965030 690 PrintNum = 0;\r
8541adab 691\r
93e3992d 692 if (GraphicsOutput != NULL) {\r
693 HorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;\r
694 VerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;\r
8541adab 695 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
93e3992d 696 UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r
8541adab 697 } else {\r
698 Status = EFI_UNSUPPORTED;\r
699 goto Error;\r
93e3992d 700 }\r
93e3992d 701\r
8541adab 702 ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));\r
703\r
93e3992d 704 Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &HiiFont);\r
705 if (EFI_ERROR (Status)) {\r
706 goto Error;\r
8541adab 707 }\r
93e3992d 708\r
aaf14379 709 PrintNum = UnicodeVSPrint (Buffer, 0x10000, fmt, args);\r
8541adab 710\r
93e3992d 711 UnicodeWeight = (CHAR16 *) Buffer;\r
712\r
713 for (Index = 0; UnicodeWeight[Index] != 0; Index++) {\r
714 if (UnicodeWeight[Index] == CHAR_BACKSPACE ||\r
715 UnicodeWeight[Index] == CHAR_LINEFEED ||\r
716 UnicodeWeight[Index] == CHAR_CARRIAGE_RETURN) {\r
717 UnicodeWeight[Index] = 0;\r
718 }\r
719 }\r
720\r
721 BufferLen = StrLen (Buffer);\r
8541adab 722\r
93e3992d 723 LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * EFI_GLYPH_HEIGHT;\r
724 if (EFI_GLYPH_WIDTH * EFI_GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {\r
725 Status = EFI_INVALID_PARAMETER;\r
726 goto Error;\r
727 }\r
728\r
729 Blt = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
730 if (Blt == NULL) {\r
731 Status = EFI_OUT_OF_RESOURCES;\r
732 goto Error;\r
733 }\r
734\r
735 Blt->Width = (UINT16) (HorizontalResolution);\r
736 Blt->Height = (UINT16) (VerticalResolution);\r
8541adab 737\r
93e3992d 738 FontInfo = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (sizeof (EFI_FONT_DISPLAY_INFO));\r
739 if (FontInfo == NULL) {\r
740 Status = EFI_OUT_OF_RESOURCES;\r
741 goto Error;\r
742 }\r
743 if (Foreground != NULL) {\r
744 CopyMem (&FontInfo->ForegroundColor, Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
745 } else {\r
746 CopyMem (\r
8541adab 747 &FontInfo->ForegroundColor,\r
748 &mEfiColors[Sto->Mode->Attribute & 0x0f],\r
93e3992d 749 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
750 );\r
751 }\r
752 if (Background != NULL) {\r
753 CopyMem (&FontInfo->BackgroundColor, Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
754 } else {\r
755 CopyMem (\r
8541adab 756 &FontInfo->BackgroundColor,\r
757 &mEfiColors[Sto->Mode->Attribute >> 4],\r
93e3992d 758 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
759 );\r
760 }\r
761\r
2f50ef83 762 if (GraphicsOutput != NULL) {\r
763 Blt->Image.Screen = GraphicsOutput;\r
764 \r
765 Status = HiiFont->StringToImage (\r
766 HiiFont,\r
767 EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_DIRECT_TO_SCREEN,\r
768 Buffer,\r
769 FontInfo,\r
770 &Blt,\r
771 X,\r
772 Y,\r
773 NULL,\r
774 NULL,\r
775 NULL\r
776 );\r
777\r
778 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {\r
779 ASSERT (UgaDraw!= NULL);\r
780\r
781 Blt->Image.Bitmap = AllocateZeroPool (Blt->Width * Blt->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
782 if (Blt->Image.Bitmap == NULL) {\r
783 SafeFreePool (Blt);\r
784 SafeFreePool (Buffer);\r
785 return EFI_OUT_OF_RESOURCES;\r
786 }\r
787\r
788 RowInfoArray = NULL;\r
789 //\r
790 // StringToImage only support blt'ing image to device using GOP protocol. If GOP is not supported in this platform,\r
791 // we ask StringToImage to print the string to blt buffer, then blt to device using UgaDraw.\r
792 //\r
793 Status = HiiFont->StringToImage (\r
794 HiiFont,\r
795 EFI_HII_IGNORE_IF_NO_GLYPH,\r
796 Buffer,\r
797 FontInfo,\r
798 &Blt,\r
799 X,\r
800 Y,\r
801 &RowInfoArray,\r
802 &RowInfoArraySize,\r
803 NULL\r
804 );\r
805\r
806 if (!EFI_ERROR (Status)) {\r
807 //\r
808 // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will\r
809 // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.\r
810 //\r
811 ASSERT (RowInfoArraySize <= 1);\r
812\r
813 Status = UgaDraw->Blt (\r
814 UgaDraw,\r
815 (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r
816 EfiUgaBltBufferToVideo,\r
817 X,\r
818 Y,\r
819 X,\r
820 Y,\r
821 RowInfoArray[0].LineWidth,\r
822 RowInfoArray[0].LineHeight,\r
823 Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
824 );\r
825 }\r
8541adab 826\r
2f50ef83 827 SafeFreePool (RowInfoArray);\r
828 SafeFreePool (Blt->Image.Bitmap);\r
829 } else {\r
830 Status = EFI_UNSUPPORTED;\r
831 }\r
93e3992d 832\r
833Error:\r
834 SafeFreePool (Blt);\r
835 SafeFreePool (FontInfo);\r
aaf14379 836 FreePool (Buffer);\r
837\r
37965030 838 if (EFI_ERROR (Status)) {\r
aaf14379 839 return PrintNum;\r
840 } else {\r
841 return 0;\r
842 }\r
93e3992d 843}\r
844\r
2f50ef83 845/**\r
6cb26293 846 Print Unicode string to graphics screen at the given X,Y coordinates of the graphics screen.\r
2f50ef83 847 see definition of Print to find rules for constructing Fmt.\r
848\r
aaf14379 849 @param X Row to start printing at.\r
850 @param Y Column to start printing at.\r
851 @param ForeGround Foreground color.\r
852 @param BackGround background color.\r
853 @param Fmt Print format sting. See definition of Print.\r
854 @param ... Argumnet stream defined by Fmt string.\r
2f50ef83 855\r
aaf14379 856 @return Number of Characters printed. Zero means no any character \r
857 displayed successfully.\r
2f50ef83 858\r
859**/\r
93e3992d 860UINTN\r
2f50ef83 861EFIAPI\r
93e3992d 862PrintXY (\r
863 IN UINTN X,\r
864 IN UINTN Y,\r
865 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *ForeGround, OPTIONAL\r
866 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BackGround, OPTIONAL\r
867 IN CHAR16 *Fmt,\r
868 ...\r
869 )\r
93e3992d 870{\r
aaf14379 871 EFI_HANDLE Handle;\r
872 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
873 EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
93e3992d 874 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Sto;\r
aaf14379 875 EFI_STATUS Status;\r
876 VA_LIST Args;\r
93e3992d 877\r
878 VA_START (Args, Fmt);\r
879\r
880 Handle = gST->ConsoleOutHandle;\r
881\r
882 Status = gBS->HandleProtocol (\r
883 Handle,\r
884 &gEfiGraphicsOutputProtocolGuid,\r
aaf14379 885 (VOID **) &GraphicsOutput\r
93e3992d 886 );\r
887\r
888 UgaDraw = NULL;\r
8541adab 889 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {\r
aaf14379 890 //\r
891 // If no GOP available, try to open UGA Draw protocol if supported.\r
892 //\r
93e3992d 893 GraphicsOutput = NULL;\r
894\r
895 Status = gBS->HandleProtocol (\r
896 Handle,\r
897 &gEfiUgaDrawProtocolGuid,\r
aaf14379 898 (VOID **) &UgaDraw\r
93e3992d 899 );\r
8541adab 900 }\r
901 if (EFI_ERROR (Status)) {\r
aaf14379 902 return 0;\r
93e3992d 903 }\r
904\r
905 Status = gBS->HandleProtocol (\r
906 Handle,\r
907 &gEfiSimpleTextOutProtocolGuid,\r
aaf14379 908 (VOID **) &Sto\r
93e3992d 909 );\r
910\r
911 if (EFI_ERROR (Status)) {\r
aaf14379 912 return 0;\r
93e3992d 913 }\r
914\r
2f50ef83 915 return Print (GraphicsOutput, UgaDraw, Sto, X, Y, ForeGround, BackGround, Fmt, Args);\r
93e3992d 916}\r
917\r