From 5cc83981d7cba1ea406432cd9ca9e030a482a3ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Mon, 1 May 2023 02:54:09 -0400
Subject: [PATCH] Only erase black bars and use BitBlt()

I expect BitBlt(..., BLACKNESS) to be the better optimized of the
two, and there's no reason to actually reat the source bitmap.
---
 src/conio/win32gdi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/conio/win32gdi.c b/src/conio/win32gdi.c
index ce9cfae8e7..001e12d1ff 100644
--- a/src/conio/win32gdi.c
+++ b/src/conio/win32gdi.c
@@ -323,7 +323,6 @@ gdi_handle_wm_paint(HWND hwnd)
 	else
 		SetDIBits(winDC, di, 0, dih, data, (BITMAPINFO *)&b5hdr, DIB_RGB_COLORS);
 	// Clear to black first
-	StretchBlt(winDC, 0, 0, w, h, memDC, 0, 0, 1, 1, BLACKNESS);
 	di = SelectObject(memDC, di);
 	pthread_mutex_lock(&off_lock);
 	if (ciolib_scaling) {
@@ -332,6 +331,14 @@ gdi_handle_wm_paint(HWND hwnd)
 	else {
 		StretchBlt(winDC, xoff, yoff, dwidth, dheight, memDC, 0, 0, diw, dih, SRCCOPY);
 	}
+	if (xoff > 0) {
+		BitBlt(winDC, 0, 0, xoff - 1, dheight, memDC, 0, 0, BLACKNESS);
+		BitBlt(winDC, xoff + dwidth, 0, w, h, memDC, 0, 0, BLACKNESS);
+	}
+	else if (yoff > 0) {
+		BitBlt(winDC, 0, 0, w, yoff - 1, memDC, 0, 0, BLACKNESS);
+		BitBlt(winDC, 0, yoff + dheight, w, h, memDC, 0, 0, BLACKNESS);
+	}
 	pthread_mutex_unlock(&off_lock);
 	EndPaint(hwnd, &ps);
 	di = SelectObject(memDC, di);
-- 
GitLab