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