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