Jacek Caban : gdi32: Don't use MulDiv in ntgdi functions.
Alexandre Julliard
julliard at winehq.org
Fri Sep 24 15:31:59 CDT 2021
Module: wine
Branch: master
Commit: 9ca7966aed4318599cd600564382d7b43b616289
URL: https://source.winehq.org/git/wine.git/?a=commit;h=9ca7966aed4318599cd600564382d7b43b616289
Author: Jacek Caban <jacek at codeweavers.com>
Date: Fri Sep 24 12:56:00 2021 +0200
gdi32: Don't use MulDiv in ntgdi functions.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/gdi32/clipping.c | 4 ++--
dlls/gdi32/driver.c | 4 ++--
dlls/gdi32/font.c | 4 ++--
dlls/gdi32/gdiobj.c | 2 +-
dlls/gdi32/mapping.c | 36 ++++++++++++++++++++++++++++++------
dlls/gdi32/ntgdi_private.h | 1 +
6 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/dlls/gdi32/clipping.c b/dlls/gdi32/clipping.c
index 4fefa834b58..115de908cf6 100644
--- a/dlls/gdi32/clipping.c
+++ b/dlls/gdi32/clipping.c
@@ -237,8 +237,8 @@ INT WINAPI NtGdiOffsetClipRgn( HDC hdc, INT x, INT y )
if (dc->hClipRgn)
{
- x = MulDiv( x, dc->attr->vport_ext.cx, dc->attr->wnd_ext.cx );
- y = MulDiv( y, dc->attr->vport_ext.cy, dc->attr->wnd_ext.cy );
+ x = muldiv( x, dc->attr->vport_ext.cx, dc->attr->wnd_ext.cx );
+ y = muldiv( y, dc->attr->vport_ext.cy, dc->attr->wnd_ext.cy );
if (dc->attr->layout & LAYOUT_RTL) x = -x;
ret = NtGdiOffsetRgn( dc->hClipRgn, x, y );
update_dc_clipping( dc );
diff --git a/dlls/gdi32/driver.c b/dlls/gdi32/driver.c
index 09e369bf27f..712dce06af6 100644
--- a/dlls/gdi32/driver.c
+++ b/dlls/gdi32/driver.c
@@ -382,9 +382,9 @@ static INT CDECL nulldrv_GetDeviceCaps( PHYSDEV dev, INT cap )
{
case DRIVERVERSION: return 0x4000;
case TECHNOLOGY: return DT_RASDISPLAY;
- case HORZSIZE: return MulDiv( NtGdiGetDeviceCaps( dev->hdc, HORZRES ), 254,
+ case HORZSIZE: return muldiv( NtGdiGetDeviceCaps( dev->hdc, HORZRES ), 254,
NtGdiGetDeviceCaps( dev->hdc, LOGPIXELSX ) * 10 );
- case VERTSIZE: return MulDiv( NtGdiGetDeviceCaps( dev->hdc, VERTRES ), 254,
+ case VERTSIZE: return muldiv( NtGdiGetDeviceCaps( dev->hdc, VERTRES ), 254,
NtGdiGetDeviceCaps( dev->hdc, LOGPIXELSY ) * 10 );
case HORZRES:
{
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 6011f258499..805fbe7abcc 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -2874,9 +2874,9 @@ static BOOL get_face_enum_data( struct gdi_font_face *face, ENUMLOGFONTEXW *elf,
UINT cell_height;
#define TM font->otm.otmTextMetrics
-#define SCALE_NTM(value) (MulDiv( ntm->ntmTm.tmHeight, (value), TM.tmHeight ))
+#define SCALE_NTM(value) (muldiv( ntm->ntmTm.tmHeight, (value), TM.tmHeight ))
cell_height = TM.tmHeight / ( -lf.lfHeight / font->otm.otmEMSquare );
- ntm->ntmTm.tmHeight = MulDiv( ntm_ppem, cell_height, font->otm.otmEMSquare );
+ ntm->ntmTm.tmHeight = muldiv( ntm_ppem, cell_height, font->otm.otmEMSquare );
ntm->ntmTm.tmAscent = SCALE_NTM( TM.tmAscent );
ntm->ntmTm.tmDescent = ntm->ntmTm.tmHeight - ntm->ntmTm.tmAscent;
ntm->ntmTm.tmInternalLeading = SCALE_NTM( TM.tmInternalLeading );
diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c
index 2a245b4596f..cf8fbb8ebb4 100644
--- a/dlls/gdi32/gdiobj.c
+++ b/dlls/gdi32/gdiobj.c
@@ -592,7 +592,7 @@ static HFONT create_scaled_font( const LOGFONTW *deffont )
}
lf = *deffont;
- lf.lfHeight = MulDiv( lf.lfHeight, dpi, 96 );
+ lf.lfHeight = muldiv( lf.lfHeight, dpi, 96 );
return create_font( &lf );
}
diff --git a/dlls/gdi32/mapping.c b/dlls/gdi32/mapping.c
index c9a20602e13..6156a64a825 100644
--- a/dlls/gdi32/mapping.c
+++ b/dlls/gdi32/mapping.c
@@ -29,6 +29,30 @@
WINE_DEFAULT_DEBUG_CHANNEL(dc);
+/* copied from kernelbase */
+int muldiv( int a, int b, int c )
+{
+ LONGLONG ret;
+
+ if (!c) return -1;
+
+ /* We want to deal with a positive divisor to simplify the logic. */
+ if (c < 0)
+ {
+ a = -a;
+ c = -c;
+ }
+
+ /* If the result is positive, we "add" to round. else, we subtract to round. */
+ if ((a < 0 && b < 0) || (a >= 0 && b >= 0))
+ ret = (((LONGLONG)a * b) + (c / 2)) / c;
+ else
+ ret = (((LONGLONG)a * b) - (c / 2)) / c;
+
+ if (ret > 2147483647 || ret < -2147483647) return -1;
+ return ret;
+}
+
static SIZE get_dc_virtual_size( DC *dc )
{
SIZE ret = dc->attr->virtual_size;
@@ -113,20 +137,20 @@ BOOL set_map_mode( DC *dc, int mode )
dc->attr->vport_ext.cy = -virtual_res.cy;
break;
case MM_LOENGLISH:
- dc->attr->wnd_ext.cx = MulDiv(1000, virtual_size.cx, 254);
- dc->attr->wnd_ext.cy = MulDiv(1000, virtual_size.cy, 254);
+ 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:
- dc->attr->wnd_ext.cx = MulDiv(10000, virtual_size.cx, 254);
- dc->attr->wnd_ext.cy = MulDiv(10000, virtual_size.cy, 254);
+ 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:
- dc->attr->wnd_ext.cx = MulDiv(14400, virtual_size.cx, 254);
- dc->attr->wnd_ext.cy = MulDiv(14400, virtual_size.cy, 254);
+ 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;
dc->attr->vport_ext.cy = -virtual_res.cy;
break;
diff --git a/dlls/gdi32/ntgdi_private.h b/dlls/gdi32/ntgdi_private.h
index afdbad24f4a..595387e0aef 100644
--- a/dlls/gdi32/ntgdi_private.h
+++ b/dlls/gdi32/ntgdi_private.h
@@ -391,6 +391,7 @@ extern void lp_to_dp( DC *dc, POINT *points, INT count ) DECLSPEC_HIDDEN;
extern BOOL set_map_mode( DC *dc, int mode ) DECLSPEC_HIDDEN;
extern void combine_transform( XFORM *result, const XFORM *xform1,
const XFORM *xform2 ) DECLSPEC_HIDDEN;
+extern int muldiv( int a, int b, int c ) DECLSPEC_HIDDEN;
/* driver.c */
extern BOOL is_display_device( LPCWSTR name ) DECLSPEC_HIDDEN;
More information about the wine-cvs
mailing list