]> code.delx.au - refind/blob - libeg/screen.c
BIOS-mode boot support now works when compiled with GNU-EFI
[refind] / libeg / screen.c
1 /*
2 * libeg/screen.c
3 * Screen handling functions
4 *
5 * Copyright (c) 2006 Christoph Pfisterer
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36 /*
37 * Modifications copyright (c) 2012-2014 Roderick W. Smith
38 *
39 * Modifications distributed under the terms of the GNU General Public
40 * License (GPL) version 3 (GPLv3), a copy of which must be distributed
41 * with this source code or binaries made from it.
42 *
43 */
44
45 #include "libegint.h"
46 #include "../refind/screen.h"
47 #include "../refind/lib.h"
48 #include "../include/refit_call_wrapper.h"
49 #include "libeg.h"
50 #include "Handle.h"
51
52 #include <efiUgaDraw.h>
53 #include <efiConsoleControl.h>
54
55 #ifndef __MAKEWITH_GNUEFI
56 #define LibLocateProtocol EfiLibLocateProtocol
57 #endif
58
59 // Console defines and variables
60
61 static EFI_GUID ConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
62 static EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
63
64 static EFI_GUID UgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID;
65 static EFI_UGA_DRAW_PROTOCOL *UgaDraw = NULL;
66
67 static EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
68 static EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL;
69
70 static BOOLEAN egHasGraphics = FALSE;
71 static UINTN egScreenWidth = 800;
72 static UINTN egScreenHeight = 600;
73
74 //
75 // Screen handling
76 //
77
78 // Make the necessary system calls to identify the current graphics mode.
79 // Stores the results in the file-global variables egScreenWidth,
80 // egScreenHeight, and egHasGraphics. The first two of these will be
81 // unchanged if neither GraphicsOutput nor UgaDraw is a valid pointer.
82 static VOID egDetermineScreenSize(VOID) {
83 EFI_STATUS Status = EFI_SUCCESS;
84 UINT32 UGAWidth, UGAHeight, UGADepth, UGARefreshRate;
85
86 // get screen size
87 egHasGraphics = FALSE;
88 if (GraphicsOutput != NULL) {
89 egScreenWidth = GraphicsOutput->Mode->Info->HorizontalResolution;
90 egScreenHeight = GraphicsOutput->Mode->Info->VerticalResolution;
91 egHasGraphics = TRUE;
92 } else if (UgaDraw != NULL) {
93 Status = refit_call5_wrapper(UgaDraw->GetMode, UgaDraw, &UGAWidth, &UGAHeight, &UGADepth, &UGARefreshRate);
94 if (EFI_ERROR(Status)) {
95 UgaDraw = NULL; // graphics not available
96 } else {
97 egScreenWidth = UGAWidth;
98 egScreenHeight = UGAHeight;
99 egHasGraphics = TRUE;
100 }
101 }
102 } // static VOID egDetermineScreenSize()
103
104 VOID egGetScreenSize(OUT UINTN *ScreenWidth, OUT UINTN *ScreenHeight)
105 {
106 egDetermineScreenSize();
107
108 if (ScreenWidth != NULL)
109 *ScreenWidth = egScreenWidth;
110 if (ScreenHeight != NULL)
111 *ScreenHeight = egScreenHeight;
112 }
113
114 VOID egInitScreen(VOID)
115 {
116 EFI_STATUS Status = EFI_SUCCESS;
117
118 // get protocols
119 Status = LibLocateProtocol(&ConsoleControlProtocolGuid, (VOID **) &ConsoleControl);
120 if (EFI_ERROR(Status))
121 ConsoleControl = NULL;
122
123 Status = LibLocateProtocol(&UgaDrawProtocolGuid, (VOID **) &UgaDraw);
124 if (EFI_ERROR(Status))
125 UgaDraw = NULL;
126
127 Status = LibLocateProtocol(&GraphicsOutputProtocolGuid, (VOID **) &GraphicsOutput);
128 if (EFI_ERROR(Status))
129 GraphicsOutput = NULL;
130
131 egDetermineScreenSize();
132 }
133
134 // Convert a graphics mode (in *ModeWidth) to a width and height (returned in
135 // *ModeWidth and *Height, respectively).
136 // Returns TRUE if successful, FALSE if not (invalid mode, typically)
137 BOOLEAN egGetResFromMode(UINTN *ModeWidth, UINTN *Height) {
138 UINTN Size;
139 EFI_STATUS Status;
140 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info = NULL;
141
142 if ((ModeWidth != NULL) && (Height != NULL)) {
143 Status = refit_call4_wrapper(GraphicsOutput->QueryMode, GraphicsOutput, *ModeWidth, &Size, &Info);
144 if ((Status == EFI_SUCCESS) && (Info != NULL)) {
145 *ModeWidth = Info->HorizontalResolution;
146 *Height = Info->VerticalResolution;
147 return TRUE;
148 }
149 }
150 return FALSE;
151 } // BOOLEAN egGetResFromMode()
152
153 // Sets the screen resolution to the specified value, if possible. If *ScreenHeight
154 // is 0 and GOP mode is detected, assume that *ScreenWidth contains a GOP mode
155 // number rather than a horizontal resolution. If the specified resolution is not
156 // valid, displays a warning with the valid modes on GOP (UEFI) systems, or silently
157 // fails on UGA (EFI 1.x) systems. Note that this function attempts to set ANY screen
158 // resolution, even 0x0 or ridiculously large values.
159 // Upon success, returns actual screen resolution in *ScreenWidth and *ScreenHeight.
160 // These values are unchanged upon failure.
161 // Returns TRUE if successful, FALSE if not.
162 BOOLEAN egSetScreenSize(IN OUT UINTN *ScreenWidth, IN OUT UINTN *ScreenHeight) {
163 EFI_STATUS Status = EFI_SUCCESS;
164 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
165 UINTN Size;
166 UINT32 ModeNum = 0;
167 UINT32 UGAWidth, UGAHeight, UGADepth, UGARefreshRate;
168 BOOLEAN ModeSet = FALSE;
169
170 if ((ScreenWidth == NULL) || (ScreenHeight == NULL))
171 return FALSE;
172
173 if (GraphicsOutput != NULL) { // GOP mode (UEFI)
174 if (*ScreenHeight == 0) { // User specified a mode number (stored in *ScreenWidth); use it directly
175 ModeNum = (UINT32) *ScreenWidth;
176 if (egGetResFromMode(ScreenWidth, ScreenHeight) &&
177 (refit_call2_wrapper(GraphicsOutput->SetMode, GraphicsOutput, ModeNum) == EFI_SUCCESS)) {
178 ModeSet = TRUE;
179 }
180
181 // User specified width & height; must find mode...
182 } else {
183 // Do a loop through the modes to see if the specified one is available;
184 // and if so, switch to it....
185 do {
186 Status = refit_call4_wrapper(GraphicsOutput->QueryMode, GraphicsOutput, ModeNum, &Size, &Info);
187 if ((Status == EFI_SUCCESS) && (Size >= sizeof(*Info) && (Info != NULL)) &&
188 (Info->HorizontalResolution == *ScreenWidth) && (Info->VerticalResolution == *ScreenHeight)) {
189 Status = refit_call2_wrapper(GraphicsOutput->SetMode, GraphicsOutput, ModeNum);
190 ModeSet = (Status == EFI_SUCCESS);
191 } // if
192 } while ((++ModeNum < GraphicsOutput->Mode->MaxMode) && !ModeSet);
193 } // if/else
194
195 if (ModeSet) {
196 egScreenWidth = *ScreenWidth;
197 egScreenHeight = *ScreenHeight;
198 } else {// If unsuccessful, display an error message for the user....
199 SwitchToText(FALSE);
200 Print(L"Error setting graphics mode %d x %d; using default mode!\nAvailable modes are:\n", *ScreenWidth, *ScreenHeight);
201 ModeNum = 0;
202 do {
203 Status = refit_call4_wrapper(GraphicsOutput->QueryMode, GraphicsOutput, ModeNum, &Size, &Info);
204 if ((Status == EFI_SUCCESS) && (Info != NULL)) {
205 Print(L"Mode %d: %d x %d\n", ModeNum, Info->HorizontalResolution, Info->VerticalResolution);
206 } // else
207 } while (++ModeNum < GraphicsOutput->Mode->MaxMode);
208 PauseForKey();
209 SwitchToGraphics();
210 } // if GOP mode (UEFI)
211
212 } else if (UgaDraw != NULL) { // UGA mode (EFI 1.x)
213 // Try to use current color depth & refresh rate for new mode. Maybe not the best choice
214 // in all cases, but I don't know how to probe for alternatives....
215 Status = refit_call5_wrapper(UgaDraw->GetMode, UgaDraw, &UGAWidth, &UGAHeight, &UGADepth, &UGARefreshRate);
216 Status = refit_call5_wrapper(UgaDraw->SetMode, UgaDraw, *ScreenWidth, *ScreenHeight, UGADepth, UGARefreshRate);
217 if (Status == EFI_SUCCESS) {
218 egScreenWidth = *ScreenWidth;
219 egScreenHeight = *ScreenHeight;
220 ModeSet = TRUE;
221 } else {
222 // TODO: Find a list of supported modes and display it.
223 // NOTE: Below doesn't actually appear unless we explicitly switch to text mode.
224 // This is just a placeholder until something better can be done....
225 Print(L"Error setting graphics mode %d x %d; unsupported mode!\n");
226 } // if/else
227 } // if/else if UGA mode (EFI 1.x)
228 return (ModeSet);
229 } // BOOLEAN egSetScreenSize()
230
231 // Set a text mode.
232 // Returns TRUE if the mode actually changed, FALSE otherwise.
233 // Note that a FALSE return value can mean either an error or no change
234 // necessary.
235 BOOLEAN egSetTextMode(UINT32 RequestedMode) {
236 UINTN i = 0, Width, Height;
237 EFI_STATUS Status;
238 BOOLEAN ChangedIt = FALSE;
239
240 if ((RequestedMode != DONT_CHANGE_TEXT_MODE) && (RequestedMode != ST->ConOut->Mode->Mode)) {
241 Status = refit_call2_wrapper(ST->ConOut->SetMode, ST->ConOut, RequestedMode);
242 if (Status == EFI_SUCCESS) {
243 ChangedIt = TRUE;
244 } else {
245 SwitchToText(FALSE);
246 Print(L"\nError setting text mode %d; available modes are:\n", RequestedMode);
247 do {
248 Status = refit_call4_wrapper(ST->ConOut->QueryMode, ST->ConOut, i, &Width, &Height);
249 if (Status == EFI_SUCCESS)
250 Print(L"Mode %d: %d x %d\n", i, Width, Height);
251 } while (++i < ST->ConOut->Mode->MaxMode);
252 Print(L"Mode %d: Use default mode\n", DONT_CHANGE_TEXT_MODE);
253
254 PauseForKey();
255 SwitchToGraphics();
256 } // if/else successful change
257 } // if need to change mode
258 return ChangedIt;
259 } // BOOLEAN egSetTextMode()
260
261 CHAR16 * egScreenDescription(VOID)
262 {
263 CHAR16 *GraphicsInfo, *TextInfo = NULL;
264
265 GraphicsInfo = AllocateZeroPool(256 * sizeof(CHAR16));
266 if (GraphicsInfo == NULL)
267 return L"memory allocation error";
268
269 if (egHasGraphics) {
270 if (GraphicsOutput != NULL) {
271 SPrint(GraphicsInfo, 255, L"Graphics Output (UEFI), %dx%d", egScreenWidth, egScreenHeight);
272 } else if (UgaDraw != NULL) {
273 GraphicsInfo = AllocateZeroPool(256 * sizeof(CHAR16));
274 SPrint(GraphicsInfo, 255, L"UGA Draw (EFI 1.10), %dx%d", egScreenWidth, egScreenHeight);
275 } else {
276 MyFreePool(GraphicsInfo);
277 MyFreePool(TextInfo);
278 return L"Internal Error";
279 }
280 if (!AllowGraphicsMode) { // graphics-capable HW, but in text mode
281 TextInfo = AllocateZeroPool(256 * sizeof(CHAR16));
282 SPrint(TextInfo, 255, L"(in %dx%d text mode)", ConWidth, ConHeight);
283 MergeStrings(&GraphicsInfo, TextInfo, L' ');
284 }
285 } else {
286 SPrint(GraphicsInfo, 255, L"Text-foo console, %dx%d", ConWidth, ConHeight);
287 }
288 MyFreePool(TextInfo);
289 return GraphicsInfo;
290 }
291
292 BOOLEAN egHasGraphicsMode(VOID)
293 {
294 return egHasGraphics;
295 }
296
297 BOOLEAN egIsGraphicsModeEnabled(VOID)
298 {
299 EFI_CONSOLE_CONTROL_SCREEN_MODE CurrentMode;
300
301 if (ConsoleControl != NULL) {
302 refit_call4_wrapper(ConsoleControl->GetMode, ConsoleControl, &CurrentMode, NULL, NULL);
303 return (CurrentMode == EfiConsoleControlScreenGraphics) ? TRUE : FALSE;
304 }
305
306 return FALSE;
307 }
308
309 VOID egSetGraphicsModeEnabled(IN BOOLEAN Enable)
310 {
311 EFI_CONSOLE_CONTROL_SCREEN_MODE CurrentMode;
312 EFI_CONSOLE_CONTROL_SCREEN_MODE NewMode;
313
314 if (ConsoleControl != NULL) {
315 refit_call4_wrapper(ConsoleControl->GetMode, ConsoleControl, &CurrentMode, NULL, NULL);
316
317 NewMode = Enable ? EfiConsoleControlScreenGraphics
318 : EfiConsoleControlScreenText;
319 if (CurrentMode != NewMode)
320 refit_call2_wrapper(ConsoleControl->SetMode, ConsoleControl, NewMode);
321 }
322 }
323
324 //
325 // Drawing to the screen
326 //
327
328 VOID egClearScreen(IN EG_PIXEL *Color)
329 {
330 EFI_UGA_PIXEL FillColor;
331
332 if (!egHasGraphics)
333 return;
334
335 if (Color != NULL) {
336 FillColor.Red = Color->r;
337 FillColor.Green = Color->g;
338 FillColor.Blue = Color->b;
339 } else {
340 FillColor.Red = 0x0;
341 FillColor.Green = 0x0;
342 FillColor.Blue = 0x0;
343 }
344 FillColor.Reserved = 0;
345
346 if (GraphicsOutput != NULL) {
347 // EFI_GRAPHICS_OUTPUT_BLT_PIXEL and EFI_UGA_PIXEL have the same
348 // layout, and the header from TianoCore actually defines them
349 // to be the same type.
350 refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)&FillColor, EfiBltVideoFill,
351 0, 0, 0, 0, egScreenWidth, egScreenHeight, 0);
352 } else if (UgaDraw != NULL) {
353 refit_call10_wrapper(UgaDraw->Blt, UgaDraw, &FillColor, EfiUgaVideoFill, 0, 0, 0, 0, egScreenWidth, egScreenHeight, 0);
354 }
355 }
356
357 VOID egDrawImage(IN EG_IMAGE *Image, IN UINTN ScreenPosX, IN UINTN ScreenPosY)
358 {
359 EG_IMAGE *CompImage = NULL;
360
361 // NOTE: Weird seemingly redundant tests because some placement code can "wrap around" and
362 // send "negative" values, which of course become very large unsigned ints that can then
363 // wrap around AGAIN if values are added to them.....
364 if (!egHasGraphics || ((ScreenPosX + Image->Width) > egScreenWidth) || ((ScreenPosY + Image->Height) > egScreenHeight) ||
365 (ScreenPosX > egScreenWidth) || (ScreenPosY > egScreenHeight))
366 return;
367
368 if ((GlobalConfig.ScreenBackground == NULL) || ((Image->Width == egScreenWidth) && (Image->Height == egScreenHeight))) {
369 CompImage = Image;
370 } else if (GlobalConfig.ScreenBackground == Image) {
371 CompImage = GlobalConfig.ScreenBackground;
372 } else {
373 CompImage = egCropImage(GlobalConfig.ScreenBackground, ScreenPosX, ScreenPosY, Image->Width, Image->Height);
374 if (CompImage == NULL) {
375 Print(L"Error! Can't crop image in egDrawImage()!\n");
376 return;
377 }
378 egComposeImage(CompImage, Image, 0, 0);
379 }
380
381 if (GraphicsOutput != NULL) {
382 refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)CompImage->PixelData,
383 EfiBltBufferToVideo, 0, 0, ScreenPosX, ScreenPosY, CompImage->Width, CompImage->Height, 0);
384 } else if (UgaDraw != NULL) {
385 refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)CompImage->PixelData, EfiUgaBltBufferToVideo,
386 0, 0, ScreenPosX, ScreenPosY, CompImage->Width, CompImage->Height, 0);
387 }
388 if ((CompImage != GlobalConfig.ScreenBackground) && (CompImage != Image))
389 egFreeImage(CompImage);
390 } /* VOID egDrawImage() */
391
392 // Display an unselected icon on the screen, so that the background image shows
393 // through the transparency areas. The BadgeImage may be NULL, in which case
394 // it's not composited in.
395 VOID egDrawImageWithTransparency(EG_IMAGE *Image, EG_IMAGE *BadgeImage, UINTN XPos, UINTN YPos, UINTN Width, UINTN Height) {
396 EG_IMAGE *Background;
397
398 Background = egCropImage(GlobalConfig.ScreenBackground, XPos, YPos, Width, Height);
399 if (Background != NULL) {
400 BltImageCompositeBadge(Background, Image, BadgeImage, XPos, YPos);
401 egFreeImage(Background);
402 }
403 } // VOID DrawImageWithTransparency()
404
405 VOID egDrawImageArea(IN EG_IMAGE *Image,
406 IN UINTN AreaPosX, IN UINTN AreaPosY,
407 IN UINTN AreaWidth, IN UINTN AreaHeight,
408 IN UINTN ScreenPosX, IN UINTN ScreenPosY)
409 {
410 if (!egHasGraphics)
411 return;
412
413 egRestrictImageArea(Image, AreaPosX, AreaPosY, &AreaWidth, &AreaHeight);
414 if (AreaWidth == 0)
415 return;
416
417 if (GraphicsOutput != NULL) {
418 refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData,
419 EfiBltBufferToVideo, AreaPosX, AreaPosY, ScreenPosX, ScreenPosY, AreaWidth, AreaHeight,
420 Image->Width * 4);
421 } else if (UgaDraw != NULL) {
422 refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaBltBufferToVideo,
423 AreaPosX, AreaPosY, ScreenPosX, ScreenPosY, AreaWidth, AreaHeight, Image->Width * 4);
424 }
425 }
426
427 // Display a message in the center of the screen, surrounded by a box of the
428 // specified color. For the moment, uses graphics calls only. (It still works
429 // in text mode on GOP/UEFI systems, but not on UGA/EFI 1.x systems.)
430 VOID egDisplayMessage(IN CHAR16 *Text, EG_PIXEL *BGColor) {
431 UINTN BoxWidth, BoxHeight;
432 EG_IMAGE *Box;
433
434 if ((Text != NULL) && (BGColor != NULL)) {
435 egMeasureText(Text, &BoxWidth, &BoxHeight);
436 BoxWidth += 14;
437 BoxHeight *= 2;
438 if (BoxWidth > egScreenWidth)
439 BoxWidth = egScreenWidth;
440 Box = egCreateFilledImage(BoxWidth, BoxHeight, FALSE, BGColor);
441 egRenderText(Text, Box, 7, BoxHeight / 4, (BGColor->r + BGColor->g + BGColor->b) / 3);
442 egDrawImage(Box, (egScreenWidth - BoxWidth) / 2, (egScreenHeight - BoxHeight) / 2);
443 } // if non-NULL inputs
444 } // VOID egDisplayMessage()
445
446 // Copy the current contents of the display into an EG_IMAGE....
447 // Returns pointer if successful, NULL if not.
448 EG_IMAGE * egCopyScreen(VOID) {
449 EG_IMAGE *Image = NULL;
450
451 if (!egHasGraphics)
452 return NULL;
453
454 // allocate a buffer for the whole screen
455 Image = egCreateImage(egScreenWidth, egScreenHeight, FALSE);
456 if (Image == NULL) {
457 return NULL;
458 }
459
460 // get full screen image
461 if (GraphicsOutput != NULL) {
462 refit_call10_wrapper(GraphicsOutput->Blt, GraphicsOutput, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)Image->PixelData,
463 EfiBltVideoToBltBuffer, 0, 0, 0, 0, Image->Width, Image->Height, 0);
464 } else if (UgaDraw != NULL) {
465 refit_call10_wrapper(UgaDraw->Blt, UgaDraw, (EFI_UGA_PIXEL *)Image->PixelData, EfiUgaVideoToBltBuffer,
466 0, 0, 0, 0, Image->Width, Image->Height, 0);
467 }
468 return Image;
469 } // EG_IMAGE * egCopyScreen()
470
471 //
472 // Make a screenshot
473 //
474
475 VOID egScreenShot(VOID)
476 {
477 EFI_STATUS Status;
478 EG_IMAGE *Image;
479 UINT8 *FileData;
480 UINTN FileDataLength;
481 UINTN Index;
482 UINTN ssNum;
483 CHAR16 Filename[80];
484 EFI_FILE* BaseDir;
485
486 Image = egCopyScreen();
487 if (Image == NULL) {
488 Print(L"Error: Unable to take screen shot\n");
489 goto bailout_wait;
490 }
491
492 // encode as BMP
493 egEncodeBMP(Image, &FileData, &FileDataLength);
494 egFreeImage(Image);
495 if (FileData == NULL) {
496 Print(L"Error egEncodeBMP returned NULL\n");
497 goto bailout_wait;
498 }
499
500 Status = egFindESP(&BaseDir);
501 if (EFI_ERROR(Status))
502 return;
503
504 // Search for existing screen shot files; increment number to an unused value...
505 ssNum = 001;
506 do {
507 SPrint(Filename, 80, L"screenshot_%03d.bmp", ssNum++);
508 } while (FileExists(BaseDir, Filename));
509
510 // save to file on the ESP
511 Status = egSaveFile(BaseDir, Filename, FileData, FileDataLength);
512 FreePool(FileData);
513 if (CheckError(Status, L"in egSaveFile()")) {
514 goto bailout_wait;
515 }
516
517 return;
518
519 // DEBUG: switch to text mode
520 bailout_wait:
521 egSetGraphicsModeEnabled(FALSE);
522 refit_call3_wrapper(BS->WaitForEvent, 1, &ST->ConIn->WaitForKey, &Index);
523 }
524
525 /* EOF */