[PATCH v2] win32u: Only retrieve the dc size if needed.

Huw Davies huw at codeweavers.com
Fri Nov 26 03:20:26 CST 2021


From: Florian Will <florian.will at gmail.com>

SetMapMode(.., MM_TEXT) is called a lot in common gdiplus use cases via
gdi_transform_acquire(). Querying the size and resolution can be
expensive, so skip it when its not needed.

When running the "ZusiDisplay" ET423 diagnostic display, which uses
gdiplus heavily, this change increases the "indicator blinking speed"
from 0.6 per second to 1 per second and probably hits the FPS limit now.
Also, CPU usage of the ZusiDisplay.exe process goes down from ~75% to
~42% of one core according to "top", and wineserver CPU usage goes down
from ~48% to ~3%.

Signed-off-by: Florian Will <florian.will at gmail.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
I'm not exactly overjoyed with this patch as we should strive
to make GetDeviceCaps() faster.  However, it does make a
difference to an application and isn't too horrendous.

 dlls/win32u/mapping.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/dlls/win32u/mapping.c b/dlls/win32u/mapping.c
index 6c20f50a302..6e7c42fe7cc 100644
--- a/dlls/win32u/mapping.c
+++ b/dlls/win32u/mapping.c
@@ -117,8 +117,6 @@ BOOL set_map_mode( DC *dc, int mode )
     if (mode == dc->attr->map_mode && (mode == MM_ISOTROPIC || mode == MM_ANISOTROPIC))
         return TRUE;
 
-    virtual_size = get_dc_virtual_size( dc );
-    virtual_res = get_dc_virtual_res( dc );
     switch (mode)
     {
     case MM_TEXT:
@@ -129,30 +127,40 @@ BOOL set_map_mode( DC *dc, int mode )
         break;
     case MM_LOMETRIC:
     case MM_ISOTROPIC:
+        virtual_size           = get_dc_virtual_size( dc );
+        virtual_res            = get_dc_virtual_res( dc );
         dc->attr->wnd_ext.cx   = virtual_size.cx * 10;
         dc->attr->wnd_ext.cy   = virtual_size.cy * 10;
         dc->attr->vport_ext.cx = virtual_res.cx;
         dc->attr->vport_ext.cy = -virtual_res.cy;
         break;
     case MM_HIMETRIC:
+        virtual_size           = get_dc_virtual_size( dc );
+        virtual_res            = get_dc_virtual_res( dc );
         dc->attr->wnd_ext.cx   = virtual_size.cx * 100;
         dc->attr->wnd_ext.cy   = virtual_size.cy * 100;
         dc->attr->vport_ext.cx = virtual_res.cx;
         dc->attr->vport_ext.cy = -virtual_res.cy;
         break;
     case MM_LOENGLISH:
+        virtual_size           = get_dc_virtual_size( dc );
+        virtual_res            = get_dc_virtual_res( dc );
         dc->attr->wnd_ext.cx   = muldiv(1000, virtual_size.cx, 254);
         dc->attr->wnd_ext.cy   = muldiv(1000, virtual_size.cy, 254);
         dc->attr->vport_ext.cx = virtual_res.cx;
         dc->attr->vport_ext.cy = -virtual_res.cy;
         break;
     case MM_HIENGLISH:
+        virtual_size           = get_dc_virtual_size( dc );
+        virtual_res            = get_dc_virtual_res( dc );
         dc->attr->wnd_ext.cx   = muldiv(10000, virtual_size.cx, 254);
         dc->attr->wnd_ext.cy   = muldiv(10000, virtual_size.cy, 254);
         dc->attr->vport_ext.cx = virtual_res.cx;
         dc->attr->vport_ext.cy = -virtual_res.cy;
         break;
     case MM_TWIPS:
+        virtual_size           = get_dc_virtual_size( dc );
+        virtual_res            = get_dc_virtual_res( dc );
         dc->attr->wnd_ext.cx   = muldiv(14400, virtual_size.cx, 254);
         dc->attr->wnd_ext.cy   = muldiv(14400, virtual_size.cy, 254);
         dc->attr->vport_ext.cx = virtual_res.cx;
-- 
2.23.0




More information about the wine-devel mailing list