From fd2547c281d55f0a01956db19c991db5b69a584e Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Thu, 9 Apr 2020 21:04:35 +0300 Subject: [PATCH] safe draw Signed-off-by: Sergey Isakov --- rEFIt_UEFI/libeg/XImage.cpp | 32 +++++++------------------------- rEFIt_UEFI/libeg/XTheme.cpp | 12 +++++++++++- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/rEFIt_UEFI/libeg/XImage.cpp b/rEFIt_UEFI/libeg/XImage.cpp index 503e30583..5989273f1 100644 --- a/rEFIt_UEFI/libeg/XImage.cpp +++ b/rEFIt_UEFI/libeg/XImage.cpp @@ -562,6 +562,13 @@ void XImage::Draw(INTN x, INTN y, float scale, bool Opaque) return; } + if (x < 0) { + x = 0; + } + if (y < 0) { + y = 0; + } + XImage Top(*this, scale); //can accept 0 as scale XImage Background(Width, Height); UINTN AreaWidth = (x + Width > (UINTN)UGAWidth) ? (UGAWidth - x) : Width; @@ -569,32 +576,7 @@ void XImage::Draw(INTN x, INTN y, float scale, bool Opaque) Background.GetArea(x, y, AreaWidth, AreaHeight); //it will resize the Background image Background.Compose(0, 0, Top, Opaque); Background.DrawWithoutCompose(x, y); -#if 0 - // prepare protocols - EFI_STATUS Status; - EFI_GUID UgaDrawProtocolGuid = EFI_UGA_DRAW_PROTOCOL_GUID; - EFI_UGA_DRAW_PROTOCOL *UgaDraw = NULL; - EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; - EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL; - Status = EfiLibLocateProtocol(&GraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput); - if (EFI_ERROR(Status)) { - GraphicsOutput = NULL; - Status = EfiLibLocateProtocol(&UgaDrawProtocolGuid, (VOID **)&UgaDraw); - if (EFI_ERROR(Status)) - UgaDraw = NULL; - } - //output combined image - if (GraphicsOutput != NULL) { - GraphicsOutput->Blt(GraphicsOutput, Background.GetPixelPtr(0, 0), - EfiBltBufferToVideo, - 0, 0, x, y, AreaWidth, AreaHeight, AreaWidth*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - } - else if (UgaDraw != NULL) { - UgaDraw->Blt(UgaDraw, (EFI_UGA_PIXEL *)Background.GetPixelPtr(0, 0), EfiUgaBltBufferToVideo, - 0, 0, x, y, AreaWidth, AreaHeight, AreaWidth*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - } -#endif } void XImage::DrawOnBack(INTN XPos, INTN YPos, const XImage& Plate) diff --git a/rEFIt_UEFI/libeg/XTheme.cpp b/rEFIt_UEFI/libeg/XTheme.cpp index 8d6999f17..d8652b3ab 100644 --- a/rEFIt_UEFI/libeg/XTheme.cpp +++ b/rEFIt_UEFI/libeg/XTheme.cpp @@ -861,9 +861,19 @@ void XTheme::InitBar() //TODO replace by some existing procedure VOID XTheme::FillRectAreaOfScreen(IN INTN XPos, IN INTN YPos, IN INTN Width, IN INTN Height) { - XImage TmpBuffer(Width, Height); // TmpBuffer.CopyScaled(Background, 1.f); INTN X = XPos - (Width >> 1); //X_IS_CENTRE + if (X < 0) { + X = 0; + } + if (X + Width > UGAWidth) { + Width = UGAWidth - X; + } + if (YPos + Height > UGAHeight) { + Height = UGAHeight - YPos; + } + + XImage TmpBuffer(Width, Height); TmpBuffer.CopyRect(Background, X, YPos); //a part of BackGround image TmpBuffer.DrawWithoutCompose(X, YPos); // TmpBuffer.Draw(X, YPos, 0, true);