diff mbox

[FFmpeg-devel] gdigrab: fix HIDPI support

Message ID 1bf60608-926b-9862-6535-ad9c50835421@gmail.com
State Superseded
Headers show

Commit Message

Dilshod Mukhtarov Jan. 27, 2019, 6:40 p.m. UTC
Hi Carl,

Thanks for advices. I split the patch to two distinct parts. The first 
part is here and the next one in a new message.


On 27.01.2019 4:45, Carl Eugen Hoyos wrote:
> 2019-01-26 18:53 GMT+01:00, Dilshod Mukhtarov <dilshodm@gmail.com>:
>> HI, this is the patch that fixes HIDPI support in gdigrab
>> +    double h_dpr;   // Horizontal device pixel ratio
>> +    double v_dpr;   // Vertical device pixel ratio
> I would expect these to be AVRational, if this is not
> possible, it should be explained why.
>
> Please put "else" on the same line as "}", no linebreak
> between "}" and "else".
>
>> 1) Mouse position was not calculated properly in area or window mode
>> 2) In window mode the size of window was not calculated properly (cropped)
> This may not apply here, but typically, if a patch says "fixes A and B",
> it should be split in two patches to ease review and future debugging.
>
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Comments

Carl Eugen Hoyos Jan. 27, 2019, 6:46 p.m. UTC | #1
2019-01-27 19:40 GMT+01:00, Dilshod Mukhtarov <dilshodm@gmail.com>:

> Thanks for advices. I split the patch to two distinct parts. The
> first part is here and the next one in a new message.

I am quite sure that this has to be implemented without
av_q2d().

Please avoid top-posting here, Carl Eugen
diff mbox

Patch

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(-)

diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c
index ab08c11788..f2c3077523 100644
--- a/libavdevice/gdigrab.c
+++ b/libavdevice/gdigrab.c
@@ -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