From 618c77964c6d15f5482d7298c0639b3c3452203b Mon Sep 17 00:00:00 2001
From: Dilshod Mukhtarov <dilshodm@gmail.com>
Date: Sun, 27 Jan 2019 22:27:35 +0400
Subject: [PATCH 1/2] libavdevice/gdigrab: fix HIDPI support for window capture
In Windows if using scaling other than 100% then the grabbed window was not captured fully (cropped)
Signed-off-by: Dilshod Mukhtarov <dilshodm@gmail.com>
---
libavdevice/gdigrab.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
@@ -235,14 +235,12 @@ gdigrab_read_header(AVFormatContext *s1)
AVStream *st = NULL;
int bpp;
- int horzres;
- int vertres;
- int desktophorzres;
- int desktopvertres;
RECT virtual_rect;
RECT clip_rect;
BITMAP bmp;
int ret;
+ AVRational h_dpr; // Horizontal device pixel ratio
+ AVRational v_dpr; // Vertical device pixel ratio
if (!strncmp(filename, "title=", 6)) {
name = filename + 6;
@@ -277,18 +275,21 @@ gdigrab_read_header(AVFormatContext *s1)
}
bpp = GetDeviceCaps(source_hdc, BITSPIXEL);
+ h_dpr = av_make_q(GetDeviceCaps(source_hdc, DESKTOPHORZRES), GetDeviceCaps(source_hdc, HORZRES));
+ v_dpr = av_make_q(GetDeviceCaps(source_hdc, DESKTOPVERTRES), GetDeviceCaps(source_hdc, VERTRES));
+
if (hwnd) {
GetClientRect(hwnd, &virtual_rect);
+ virtual_rect.left *= av_q2d(h_dpr);
+ virtual_rect.right *= av_q2d(h_dpr);
+ virtual_rect.top *= av_q2d(v_dpr);
+ virtual_rect.bottom *= av_q2d(v_dpr);
} else {
/* desktop -- get the right height and width for scaling DPI */
- horzres = GetDeviceCaps(source_hdc, HORZRES);
- vertres = GetDeviceCaps(source_hdc, VERTRES);
- desktophorzres = GetDeviceCaps(source_hdc, DESKTOPHORZRES);
- desktopvertres = GetDeviceCaps(source_hdc, DESKTOPVERTRES);
virtual_rect.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
virtual_rect.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
- virtual_rect.right = (virtual_rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN)) * desktophorzres / horzres;
- virtual_rect.bottom = (virtual_rect.top + GetSystemMetrics(SM_CYVIRTUALSCREEN)) * desktopvertres / vertres;
+ virtual_rect.right = (virtual_rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN)) * av_q2d(h_dpr);
+ virtual_rect.bottom = (virtual_rect.top + GetSystemMetrics(SM_CYVIRTUALSCREEN)) * av_q2d(v_dpr);
}
/* If no width or height set, use full screen/window area */
--
2.17.1