From d423244c1befbe41073d19e77032505a0acade31 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 30 Jul 2021 13:01:56 +0200 Subject: [PATCH] gdi32: Use NtGdiSaveDC for SaveDC implementation. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/gdi32/dc.c | 4 ++-- dlls/gdi32/enhmfdrv/dc.c | 17 +++++------------ dlls/gdi32/enhmfdrv/enhmetafiledrv.h | 1 - dlls/gdi32/enhmfdrv/init.c | 2 +- dlls/gdi32/gdi_private.h | 2 ++ dlls/gdi32/gdidc.c | 13 +++++++++++++ dlls/gdi32/mfdrv/dc.c | 4 ++-- dlls/gdi32/mfdrv/init.c | 10 +++++++++- dlls/gdi32/mfdrv/metafiledrv.h | 2 +- dlls/gdi32/tests/dc.c | 5 +++++ 10 files changed, 40 insertions(+), 20 deletions(-) diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c index 130a1ac99e1..6118e443a6f 100644 --- a/dlls/gdi32/dc.c +++ b/dlls/gdi32/dc.c @@ -577,9 +577,9 @@ static BOOL reset_dc_state( HDC hdc ) /*********************************************************************** - * SaveDC (GDI32.@) + * NtGdiSaveDC (win32u.@) */ -INT WINAPI SaveDC( HDC hdc ) +INT WINAPI NtGdiSaveDC( HDC hdc ) { DC * dc; INT ret = 0; diff --git a/dlls/gdi32/enhmfdrv/dc.c b/dlls/gdi32/enhmfdrv/dc.c index 1faf777c47e..5148e03a231 100644 --- a/dlls/gdi32/enhmfdrv/dc.c +++ b/dlls/gdi32/enhmfdrv/dc.c @@ -22,19 +22,12 @@ #include #include "enhmfdrv/enhmetafiledrv.h" -INT CDECL EMFDRV_SaveDC( PHYSDEV dev ) +BOOL EMFDC_SaveDC( DC_ATTR *dc_attr ) { - PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSaveDC ); - INT ret = next->funcs->pSaveDC( next ); - - if (ret) - { - EMRSAVEDC emr; - emr.emr.iType = EMR_SAVEDC; - emr.emr.nSize = sizeof(emr); - EMFDRV_WriteRecord( dev, &emr.emr ); - } - return ret; + EMRSAVEDC emr; + emr.emr.iType = EMR_SAVEDC; + emr.emr.nSize = sizeof(emr); + return EMFDRV_WriteRecord( dc_attr->emf, &emr.emr ); } BOOL CDECL EMFDRV_RestoreDC( PHYSDEV dev, INT level ) diff --git a/dlls/gdi32/enhmfdrv/enhmetafiledrv.h b/dlls/gdi32/enhmfdrv/enhmetafiledrv.h index 981cdea7887..35ff9af0e90 100644 --- a/dlls/gdi32/enhmfdrv/enhmetafiledrv.h +++ b/dlls/gdi32/enhmfdrv/enhmetafiledrv.h @@ -102,7 +102,6 @@ extern BOOL CDECL EMFDRV_Rectangle( PHYSDEV dev, INT left, INT top, INT righ extern BOOL CDECL EMFDRV_RestoreDC( PHYSDEV dev, INT level ) DECLSPEC_HIDDEN; extern BOOL CDECL EMFDRV_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom, INT ell_width, INT ell_height ) DECLSPEC_HIDDEN; -extern INT CDECL EMFDRV_SaveDC( PHYSDEV dev ) DECLSPEC_HIDDEN; extern BOOL CDECL EMFDRV_ScaleViewportExtEx( PHYSDEV dev, INT xNum, INT xDenom, INT yNum, INT yDenom, SIZE *size ) DECLSPEC_HIDDEN; extern BOOL CDECL EMFDRV_ScaleWindowExtEx( PHYSDEV dev, INT xNum, INT xDenom, diff --git a/dlls/gdi32/enhmfdrv/init.c b/dlls/gdi32/enhmfdrv/init.c index 516c6c4e884..2291e22348f 100644 --- a/dlls/gdi32/enhmfdrv/init.c +++ b/dlls/gdi32/enhmfdrv/init.c @@ -118,7 +118,7 @@ static const struct gdi_dc_funcs emfdrv_driver = NULL, /* pResetDC */ EMFDRV_RestoreDC, /* pRestoreDC */ EMFDRV_RoundRect, /* pRoundRect */ - EMFDRV_SaveDC, /* pSaveDC */ + NULL, /* pSaveDC */ EMFDRV_ScaleViewportExtEx, /* pScaleViewportExtEx */ EMFDRV_ScaleWindowExtEx, /* pScaleWindowExtEx */ EMFDRV_SelectBitmap, /* pSelectBitmap */ diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h index 105d72b23f0..197ee8942c5 100644 --- a/dlls/gdi32/gdi_private.h +++ b/dlls/gdi32/gdi_private.h @@ -66,6 +66,7 @@ extern BOOL METADC_Polyline( HDC hdc, const POINT *points,INT count) DECLSPEC_HI extern BOOL METADC_Rectangle( HDC hdc, INT left, INT top, INT right, INT bottom) DECLSPEC_HIDDEN; extern BOOL METADC_RoundRect( HDC hdc, INT left, INT top, INT right, INT bottom, INT ell_width, INT ell_height ) DECLSPEC_HIDDEN; +extern BOOL METADC_SaveDC( HDC hdc ) DECLSPEC_HIDDEN; extern BOOL METADC_SetBkMode( HDC hdc, INT mode ) DECLSPEC_HIDDEN; extern BOOL METADC_SetPixel( HDC hdc, INT x, INT y, COLORREF color ) DECLSPEC_HIDDEN; extern BOOL METADC_SetPolyFillMode( HDC hdc, INT mode ) DECLSPEC_HIDDEN; @@ -114,6 +115,7 @@ extern BOOL EMFDC_Rectangle( DC_ATTR *dc_attr, INT left, INT top, INT right, INT bottom) DECLSPEC_HIDDEN; extern BOOL EMFDC_RoundRect( DC_ATTR *dc_attr, INT left, INT top, INT right, INT bottom, INT ell_width, INT ell_height ) DECLSPEC_HIDDEN; +extern BOOL EMFDC_SaveDC( DC_ATTR *dc_attr ) DECLSPEC_HIDDEN; extern BOOL EMFDC_SetArcDirection( DC_ATTR *dc_attr, INT dir ) DECLSPEC_HIDDEN; extern BOOL EMFDC_SetBkMode( DC_ATTR *dc_attr, INT mode ) DECLSPEC_HIDDEN; extern BOOL EMFDC_SetPixel( DC_ATTR *dc_attr, INT x, INT y, COLORREF color ) DECLSPEC_HIDDEN; diff --git a/dlls/gdi32/gdidc.c b/dlls/gdi32/gdidc.c index 42df880f718..6dd5940d45a 100644 --- a/dlls/gdi32/gdidc.c +++ b/dlls/gdi32/gdidc.c @@ -113,6 +113,19 @@ HDC WINAPI ResetDCA( HDC hdc, const DEVMODEA *devmode ) } /*********************************************************************** + * SaveDC (GDI32.@) + */ +INT WINAPI SaveDC( HDC hdc ) +{ + DC_ATTR *dc_attr; + + if (is_meta_dc( hdc )) return METADC_SaveDC( hdc ); + if (!(dc_attr = get_dc_attr( hdc ))) return FALSE; + if (dc_attr->emf && !EMFDC_SaveDC( dc_attr )) return FALSE; + return NtGdiSaveDC( hdc ); +} + +/*********************************************************************** * GetTextAlign (GDI32.@) */ UINT WINAPI GetTextAlign( HDC hdc ) diff --git a/dlls/gdi32/mfdrv/dc.c b/dlls/gdi32/mfdrv/dc.c index 044e228b2bf..9513da7160c 100644 --- a/dlls/gdi32/mfdrv/dc.c +++ b/dlls/gdi32/mfdrv/dc.c @@ -20,9 +20,9 @@ #include "mfdrv/metafiledrv.h" -INT CDECL MFDRV_SaveDC( PHYSDEV dev ) +BOOL METADC_SaveDC( HDC hdc ) { - return MFDRV_MetaParam0( dev, META_SAVEDC ); + return metadc_param0( hdc, META_SAVEDC ); } BOOL CDECL MFDRV_RestoreDC( PHYSDEV dev, INT level ) diff --git a/dlls/gdi32/mfdrv/init.c b/dlls/gdi32/mfdrv/init.c index 31a0297c9e3..70442fac20f 100644 --- a/dlls/gdi32/mfdrv/init.c +++ b/dlls/gdi32/mfdrv/init.c @@ -181,7 +181,7 @@ static const struct gdi_dc_funcs MFDRV_Funcs = NULL, /* pResetDC */ MFDRV_RestoreDC, /* pRestoreDC */ NULL, /* pRoundRect */ - MFDRV_SaveDC, /* pSaveDC */ + NULL, /* pSaveDC */ MFDRV_ScaleViewportExtEx, /* pScaleViewportExtEx */ MFDRV_ScaleWindowExtEx, /* pScaleWindowExtEx */ MFDRV_SelectBitmap, /* pSelectBitmap */ @@ -613,6 +613,14 @@ BOOL metadc_param1( HDC hdc, short func, short param ) return MFDRV_MetaParam1( &dev->dev, func, param ); } +BOOL metadc_param0( HDC hdc, short func ) +{ + METAFILEDRV_PDEVICE *dev; + + if (!(dev = get_metadc_ptr( hdc ))) return FALSE; + return MFDRV_MetaParam0( &dev->dev, func ); +} + BOOL metadc_param2( HDC hdc, short func, short param1, short param2 ) { METAFILEDRV_PDEVICE *dev; diff --git a/dlls/gdi32/mfdrv/metafiledrv.h b/dlls/gdi32/mfdrv/metafiledrv.h index 567b60158b2..b3104318223 100644 --- a/dlls/gdi32/mfdrv/metafiledrv.h +++ b/dlls/gdi32/mfdrv/metafiledrv.h @@ -60,6 +60,7 @@ extern BOOL MFDRV_RemoveHandle( PHYSDEV dev, UINT index ) DECLSPEC_HIDDEN; extern INT16 MFDRV_CreateBrushIndirect( PHYSDEV dev, HBRUSH hBrush ) DECLSPEC_HIDDEN; extern METAFILEDRV_PDEVICE *get_metadc_ptr( HDC hdc ) DECLSPEC_HIDDEN; +extern BOOL metadc_param0( HDC hdc, short func ) DECLSPEC_HIDDEN; extern BOOL metadc_param1( HDC hdc, short func, short param ) DECLSPEC_HIDDEN; extern BOOL metadc_param2( HDC hdc, short func, short param1, short param2 ) DECLSPEC_HIDDEN; extern BOOL metadc_param4( HDC hdc, short func, short param1, short param2, @@ -95,7 +96,6 @@ extern BOOL CDECL MFDRV_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD ro extern BOOL CDECL MFDRV_PolyBezier( PHYSDEV dev, const POINT* pt, DWORD count ) DECLSPEC_HIDDEN; extern BOOL CDECL MFDRV_PolyBezierTo( PHYSDEV dev, const POINT* pt, DWORD count ) DECLSPEC_HIDDEN; extern BOOL CDECL MFDRV_RestoreDC( PHYSDEV dev, INT level ) DECLSPEC_HIDDEN; -extern INT CDECL MFDRV_SaveDC( PHYSDEV dev ) DECLSPEC_HIDDEN; extern BOOL CDECL MFDRV_ScaleViewportExtEx( PHYSDEV dev, INT xNum, INT xDenom, INT yNum, INT yDenom, SIZE *size ) DECLSPEC_HIDDEN; extern BOOL CDECL MFDRV_ScaleWindowExtEx( PHYSDEV dev, INT xNum, INT xDenom, INT yNum, INT yDenom, SIZE *size ) DECLSPEC_HIDDEN; extern HBITMAP CDECL MFDRV_SelectBitmap( PHYSDEV dev, HBITMAP handle ) DECLSPEC_HIDDEN; diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c index 054279bf46c..bdc8186bf76 100644 --- a/dlls/gdi32/tests/dc.c +++ b/dlls/gdi32/tests/dc.c @@ -234,6 +234,11 @@ static void test_savedc(void) "ret = %d\n", ret); DeleteDC(hdc); + + SetLastError(0xdeadbeef); + ret = SaveDC(ULongToHandle(0xdeadbeef)); + ok(!ret, "SaveDC returned %u\n", ret); + ok(GetLastError() == ERROR_INVALID_HANDLE, "GetLastError() = %u\n", GetLastError()); } static void test_GdiConvertToDevmodeW(void) -- 2.11.4.GIT