Zhiyi Zhang : user32: Optimize getting primary monitor rectangle with GetSystemMetrics().
Alexandre Julliard
julliard at winehq.org
Tue May 18 15:42:38 CDT 2021
Module: wine
Branch: master
Commit: ab431c70b4537ce62ead8d79939d801932327159
URL: https://source.winehq.org/git/wine.git/?a=commit;h=ab431c70b4537ce62ead8d79939d801932327159
Author: Zhiyi Zhang <zzhang at codeweavers.com>
Date: Tue May 18 17:11:10 2021 +0800
user32: Optimize getting primary monitor rectangle with GetSystemMetrics().
This saves calls to GetMonitorInfo() and return from EnumDisplayMonitors() immediately
after the primary monitor is found.
Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/user32/sysparams.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 7dc2a8df645..ab1c5af0c1b 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -371,6 +371,27 @@ RECT get_virtual_screen_rect(void)
return info.virtual_rect;
}
+static BOOL CALLBACK get_primary_monitor_proc( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp )
+{
+ RECT *primary_rect = (RECT *)lp;
+
+ if (!rect->top && !rect->left && rect->right && rect->bottom)
+ {
+ *primary_rect = *rect;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static RECT get_primary_monitor_rect(void)
+{
+ RECT rect = {0};
+
+ EnumDisplayMonitors( 0, NULL, get_primary_monitor_proc, (LPARAM)&rect );
+ return rect;
+}
+
static BOOL CALLBACK get_monitor_count_proc( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp )
{
INT *count = (INT *)lp;
@@ -2510,6 +2531,7 @@ INT WINAPI GetSystemMetrics( INT index )
NONCLIENTMETRICSW ncm;
MINIMIZEDMETRICS mm;
ICONMETRICSW im;
+ RECT rect;
UINT ret;
HDC hdc;
@@ -2715,11 +2737,11 @@ INT WINAPI GetSystemMetrics( INT index )
case SM_MOUSEWHEELPRESENT:
return 1;
case SM_CXSCREEN:
- get_monitors_info( &info );
- return info.primary_rect.right - info.primary_rect.left;
+ rect = get_primary_monitor_rect();
+ return rect.right - rect.left;
case SM_CYSCREEN:
- get_monitors_info( &info );
- return info.primary_rect.bottom - info.primary_rect.top;
+ rect = get_primary_monitor_rect();
+ return rect.bottom - rect.top;
case SM_XVIRTUALSCREEN:
get_monitors_info( &info );
return info.virtual_rect.left;
More information about the wine-cvs
mailing list