From: Jacek Caban jacek@codeweavers.com
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/gdi32/bitblt.c | 9 ++++----- dlls/gdi32/dc.c | 49 +++++++++++++++++++++------------------------ dlls/gdi32/gdidc.c | 9 +++++++++ include/ntgdi.h | 1 + 4 files changed, 37 insertions(+), 31 deletions(-)
diff --git a/dlls/gdi32/bitblt.c b/dlls/gdi32/bitblt.c index dcc2c932453..7f66d2f66fe 100644 --- a/dlls/gdi32/bitblt.c +++ b/dlls/gdi32/bitblt.c @@ -1019,7 +1019,7 @@ BOOL WINAPI PlgBlt( HDC hdcDest, const POINT *lpPoint, HDC hdcSrc, INT nXSrc, INT nYSrc, INT nWidth, INT nHeight, HBITMAP hbmMask, INT xMask, INT yMask) { - int oldgMode; + DWORD prev_mode; /* parallelogram coords */ POINT plg[3]; /* rect coords */ @@ -1030,8 +1030,7 @@ BOOL WINAPI PlgBlt( HDC hdcDest, const POINT *lpPoint, double det;
/* save actual mode, set GM_ADVANCED */ - oldgMode = SetGraphicsMode(hdcDest,GM_ADVANCED); - if (oldgMode == 0) + if (!NtGdiGetAndSetDCDword( hdcDest, NtGdiSetGraphicsMode, GM_ADVANCED, &prev_mode )) return FALSE;
memcpy(plg,lpPoint,sizeof(POINT)*3); @@ -1047,7 +1046,7 @@ BOOL WINAPI PlgBlt( HDC hdcDest, const POINT *lpPoint,
if (fabs(det) < 1e-5) { - SetGraphicsMode(hdcDest,oldgMode); + NtGdiGetAndSetDCDword( hdcDest, NtGdiSetGraphicsMode, prev_mode, NULL ); return FALSE; }
@@ -1084,7 +1083,7 @@ BOOL WINAPI PlgBlt( HDC hdcDest, const POINT *lpPoint, SRCCOPY); /* restore dest DC */ SetWorldTransform(hdcDest,&oldDestXf); - SetGraphicsMode(hdcDest,oldgMode); + NtGdiGetAndSetDCDword( hdcDest, NtGdiSetGraphicsMode, prev_mode, NULL );
return TRUE; } diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c index 7e9dff645b1..420754b555e 100644 --- a/dlls/gdi32/dc.c +++ b/dlls/gdi32/dc.c @@ -806,6 +806,24 @@ INT WINAPI NtGdiGetDeviceCaps( HDC hdc, INT cap ) }
+static BOOL set_graphics_mode( DC *dc, int mode ) +{ + if (mode == dc->attr->graphics_mode) return TRUE; + if (mode <= 0 || mode > GM_LAST) return FALSE; + + /* One would think that setting the graphics mode to GM_COMPATIBLE + * would also reset the world transformation matrix to the unity + * matrix. However, in Windows, this is not the case. This doesn't + * make a lot of sense to me, but that's the way it is. + */ + dc->attr->graphics_mode = mode; + + /* font metrics depend on the graphics mode */ + NtGdiSelectFont(dc->hSelf, dc->hFont); + return TRUE; +} + + /*********************************************************************** * NtGdiGetAndSetDCDword (win32u.@) */ @@ -848,6 +866,11 @@ BOOL WINAPI NtGdiGetAndSetDCDword( HDC hdc, UINT method, DWORD value, DWORD *pre if (value != CLR_INVALID) dc->attr->pen_color = value; break;
+ case NtGdiSetGraphicsMode: + if (prev_value) *prev_value = dc->attr->graphics_mode; + ret = set_graphics_mode( dc, value ); + break; + default: WARN( "unknown method %u\n", method ); ret = FALSE; @@ -859,32 +882,6 @@ BOOL WINAPI NtGdiGetAndSetDCDword( HDC hdc, UINT method, DWORD value, DWORD *pre }
-/*********************************************************************** - * SetGraphicsMode (GDI32.@) - */ -INT WINAPI SetGraphicsMode( HDC hdc, INT mode ) -{ - INT ret = 0; - DC *dc = get_dc_ptr( hdc ); - - /* One would think that setting the graphics mode to GM_COMPATIBLE - * would also reset the world transformation matrix to the unity - * matrix. However, in Windows, this is not the case. This doesn't - * make a lot of sense to me, but that's the way it is. - */ - if (!dc) return 0; - if ((mode > 0) && (mode <= GM_LAST)) - { - ret = dc->attr->graphics_mode; - dc->attr->graphics_mode = mode; - } - /* font metrics depend on the graphics mode */ - if (ret != mode) NtGdiSelectFont(dc->hSelf, dc->hFont); - release_dc_ptr( dc ); - return ret; -} - - /*********************************************************************** * NtGdiGetTransform (win32u.@) * diff --git a/dlls/gdi32/gdidc.c b/dlls/gdi32/gdidc.c index c3c7ad710f2..0be21c75d58 100644 --- a/dlls/gdi32/gdidc.c +++ b/dlls/gdi32/gdidc.c @@ -436,6 +436,15 @@ INT WINAPI GetGraphicsMode( HDC hdc ) return dc_attr ? dc_attr->graphics_mode : 0; }
+/*********************************************************************** + * SetGraphicsMode (GDI32.@) + */ +INT WINAPI SetGraphicsMode( HDC hdc, INT mode ) +{ + DWORD ret; + return NtGdiGetAndSetDCDword( hdc, NtGdiSetGraphicsMode, mode, &ret ) ? ret : 0; +} + /*********************************************************************** * GetArcDirection (GDI32.@) */ diff --git a/include/ntgdi.h b/include/ntgdi.h index 25ac5ee505f..63f65e04794 100644 --- a/include/ntgdi.h +++ b/include/ntgdi.h @@ -111,6 +111,7 @@ enum NtGdiSetTextColor, NtGdiSetDCBrushColor, NtGdiSetDCPenColor, + NtGdiSetGraphicsMode, };
enum