]> code.delx.au - refind/blobdiff - refind/screen.c
Moved ExtractLegacyLoaderPaths() from lib.c to legacy.c
[refind] / refind / screen.c
index 2ac7cebc506cbcabe56db986744741a2ae921d79..29d11c80b4582bddd504e522a8517a35416ab616 100644 (file)
@@ -34,7 +34,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 /*
- * Modifications copyright (c) 2012 Roderick W. Smith
+ * Modifications copyright (c) 2012-2014 Roderick W. Smith
  *
  * Modifications distributed under the terms of the GNU General Public
  * License (GPL) version 3 (GPLv3), a copy of which must be distributed
@@ -47,6 +47,7 @@
 #include "config.h"
 #include "libegint.h"
 #include "lib.h"
+#include "menu.h"
 #include "../include/refit_call_wrapper.h"
 
 #include "../include/egemb_refind_banner.h"
@@ -100,6 +101,7 @@ VOID InitScreen(VOID)
         AllowGraphicsMode = TRUE;
     } else {
         AllowGraphicsMode = FALSE;
+        egSetTextMode(GlobalConfig.RequestedTextMode);
         egSetGraphicsModeEnabled(FALSE);   // just to be sure we are in text mode
     }
     GraphicsScreenDirty = TRUE;
@@ -117,35 +119,43 @@ VOID InitScreen(VOID)
     PrepareBlankLine();
 
     // show the banner if in text mode
-    if (GlobalConfig.TextOnly)
+    if (GlobalConfig.TextOnly && (GlobalConfig.ScreensaverTime != -1))
        DrawScreenHeader(L"Initializing...");
 }
 
+// Set the screen resolution and mode (text vs. graphics).
 VOID SetupScreen(VOID)
 {
     UINTN NewWidth, NewHeight;
 
+    // Convert mode number to horizontal & vertical resolution values
+    if ((GlobalConfig.RequestedScreenWidth > 0) && (GlobalConfig.RequestedScreenHeight == 0))
+       egGetResFromMode(&(GlobalConfig.RequestedScreenWidth), &(GlobalConfig.RequestedScreenHeight));
+
+    // Set the believed-to-be current resolution to the LOWER of the current
+    // believed-to-be resolution and the requested resolution. This is done to
+    // enable setting a lower-than-default resolution.
     if ((GlobalConfig.RequestedScreenWidth > 0) && (GlobalConfig.RequestedScreenHeight > 0)) {
        UGAWidth = (UGAWidth < GlobalConfig.RequestedScreenWidth) ? UGAWidth : GlobalConfig.RequestedScreenWidth;
        UGAHeight = (UGAHeight < GlobalConfig.RequestedScreenHeight) ? UGAHeight : GlobalConfig.RequestedScreenHeight;
     }
+
+    // Set text mode. If this requires increasing the size of the graphics mode, do so.
     if (egSetTextMode(GlobalConfig.RequestedTextMode)) {
        egGetScreenSize(&NewWidth, &NewHeight);
        if ((NewWidth > UGAWidth) || (NewHeight > UGAHeight)) {
           UGAWidth = NewWidth;
           UGAHeight = NewHeight;
        }
-       if (UGAWidth > GlobalConfig.RequestedScreenWidth) {
+       if ((UGAWidth > GlobalConfig.RequestedScreenWidth) || (UGAHeight > GlobalConfig.RequestedScreenHeight)) {
            // Requested text mode forces us to use a bigger graphics mode
-           // TODO: Convert single mode # to width & height to check it
            GlobalConfig.RequestedScreenWidth = UGAWidth;
            GlobalConfig.RequestedScreenHeight = UGAHeight;
        } // if
     }
 
     if (GlobalConfig.RequestedScreenWidth > 0) {
-       if (!egSetScreenSize(&GlobalConfig.RequestedScreenWidth, &GlobalConfig.RequestedScreenHeight))
-          Print(L"Error setting screen size!\n");
+       egSetScreenSize(&(GlobalConfig.RequestedScreenWidth), &(GlobalConfig.RequestedScreenHeight));
        egGetScreenSize(&UGAWidth, &UGAHeight);
     } // if user requested a particular screen resolution
 
@@ -158,7 +168,11 @@ VOID SetupScreen(VOID)
         // clear screen and show banner
         // (now we know we'll stay in graphics mode)
         SwitchToGraphics();
-        BltClearScreen(TRUE);
+        if (GlobalConfig.ScreensaverTime != -1) {
+           BltClearScreen(TRUE);
+        } else { // start with screen blanked
+           GraphicsScreenDirty = TRUE;
+        }
     }
 } // VOID SetupScreen()
 
@@ -281,7 +295,7 @@ static VOID DrawScreenHeader(IN CHAR16 *Title)
 // Keyboard input
 //
 
-static BOOLEAN ReadAllKeyStrokes(VOID)
+BOOLEAN ReadAllKeyStrokes(VOID)
 {
     BOOLEAN       GotKeyStrokes;
     EFI_STATUS    Status;
@@ -384,7 +398,6 @@ BOOLEAN CheckFatalError(IN EFI_STATUS Status, IN CHAR16 *where)
     if (!EFI_ERROR(Status))
         return FALSE;
 
-//    StatusToString(ErrorName, Status);
     gST->ConOut->SetAttribute (gST->ConOut, ATTR_ERROR);
     Print(L"Fatal Error: %r %s\n", Status, where);
     gST->ConOut->SetAttribute (gST->ConOut, ATTR_BASIC);
@@ -397,12 +410,9 @@ BOOLEAN CheckFatalError(IN EFI_STATUS Status, IN CHAR16 *where)
 
 BOOLEAN CheckError(IN EFI_STATUS Status, IN CHAR16 *where)
 {
-//    CHAR16 ErrorName[64];
-
     if (!EFI_ERROR(Status))
         return FALSE;
 
-//    StatusToString(ErrorName, Status);
     gST->ConOut->SetAttribute (gST->ConOut, ATTR_ERROR);
     Print(L"Error: %r %s\n", Status, where);
     gST->ConOut->SetAttribute (gST->ConOut, ATTR_BASIC);
@@ -423,34 +433,64 @@ VOID SwitchToGraphicsAndClear(VOID)
         BltClearScreen(TRUE);
 }
 
-VOID BltClearScreen(IN BOOLEAN ShowBanner)
+VOID BltClearScreen(BOOLEAN ShowBanner)
 {
     static EG_IMAGE *Banner = NULL;
+    EG_IMAGE *NewBanner = NULL;
+    INTN BannerPosX, BannerPosY;
+    EG_PIXEL Black = { 0x0, 0x0, 0x0, 0 };
 
     if (ShowBanner && !(GlobalConfig.HideUIFlags & HIDEUI_FLAG_BANNER)) {
         // load banner on first call
         if (Banner == NULL) {
-            if (GlobalConfig.BannerFileName == NULL)
-                Banner = egPrepareEmbeddedImage(&egemb_refind_banner, FALSE);
-            else
+            if (GlobalConfig.BannerFileName)
                 Banner = egLoadImage(SelfDir, GlobalConfig.BannerFileName, FALSE);
-            if (Banner != NULL)
-                MenuBackgroundPixel = Banner->PixelData[0];
+            if (Banner == NULL)
+                Banner = egPrepareEmbeddedImage(&egemb_refind_banner, FALSE);
         }
 
+        if (Banner) {
+           if (GlobalConfig.BannerScale == BANNER_FILLSCREEN) {
+              if ((Banner->Height != UGAHeight) || (Banner->Width != UGAWidth)) {
+                 NewBanner = egScaleImage(Banner, UGAWidth, UGAHeight);
+              } // if
+           } else if ((Banner->Width > UGAWidth) || (Banner->Height > UGAHeight)) {
+              NewBanner = egCropImage(Banner, 0, 0, (Banner->Width > UGAWidth) ? UGAWidth : Banner->Width,
+                                      (Banner->Height > UGAHeight) ? UGAHeight : Banner->Height);
+           } // if/elseif
+           if (NewBanner) {
+              MyFreePool(Banner);
+              Banner = NewBanner;
+           }
+           MenuBackgroundPixel = Banner->PixelData[0];
+        } // if Banner exists
+
         // clear and draw banner
-        egClearScreen(&MenuBackgroundPixel);
-        if (Banner != NULL)
-            BltImage(Banner, (UGAWidth - Banner->Width) >> 1,
-                     ((UGAHeight - LAYOUT_TOTAL_HEIGHT) >> 1) + LAYOUT_BANNER_HEIGHT - Banner->Height);
+        if (GlobalConfig.ScreensaverTime != -1)
+           egClearScreen(&MenuBackgroundPixel);
+        else
+           egClearScreen(&Black);
+
+        if (Banner != NULL) {
+            BannerPosX = (Banner->Width < UGAWidth) ? ((UGAWidth - Banner->Width) / 2) : 0;
+            BannerPosY = (INTN) (ComputeRow0PosY() / 2) - (INTN) Banner->Height;
+            if (BannerPosY < 0)
+               BannerPosY = 0;
+            GlobalConfig.BannerBottomEdge = BannerPosY + Banner->Height;
+            if (GlobalConfig.ScreensaverTime != -1)
+               BltImage(Banner, (UINTN) BannerPosX, (UINTN) BannerPosY);
+        }
 
-    } else {
-        // clear to standard background color
-        egClearScreen(&StdBackgroundPixel);
+    } else { // not showing banner
+        // clear to menu background color
+        egClearScreen(&MenuBackgroundPixel);
     }
 
     GraphicsScreenDirty = FALSE;
-}
+    egFreeImage(GlobalConfig.ScreenBackground);
+    GlobalConfig.ScreenBackground = egCopyScreen();
+} // VOID BltClearScreen()
+
 
 VOID BltImage(IN EG_IMAGE *Image, IN UINTN XPos, IN UINTN YPos)
 {
@@ -532,9 +572,14 @@ VOID BltImageCompositeBadge(IN EG_IMAGE *BaseImage, IN EG_IMAGE *TopImage, IN EG
      }
 
      // blit to screen and clean up
-     egDrawImage(CompImage, XPos, YPos);
-     egFreeImage(CompImage);
-     GraphicsScreenDirty = TRUE;
+     if (CompImage != NULL) {
+         if (CompImage->HasAlpha)
+             egDrawImageWithTransparency(CompImage, NULL, XPos, YPos, CompImage->Width, CompImage->Height);
+         else
+             egDrawImage(CompImage, XPos, YPos);
+         egFreeImage(CompImage);
+         GraphicsScreenDirty = TRUE;
+     }
 }
 
 // Line-editing functions borrowed from gummiboot (cursor_left(), cursor_right(), & line_edit()).