From 9a53f3ae11a17dd218e69a51c9b5000071f084a3 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 23 Aug 2021 13:51:01 +0200 Subject: [PATCH] gdi32: Use NtGdiDeleteObjectApp for DeleteDC. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/gdi32/bitblt.c | 8 ++--- dlls/gdi32/dc.c | 73 +++++++++++++++++++------------------------- dlls/gdi32/dib.c | 4 +-- dlls/gdi32/gdidc.c | 9 ++++++ dlls/gdi32/objects.c | 9 +++++- 5 files changed, 54 insertions(+), 49 deletions(-) diff --git a/dlls/gdi32/bitblt.c b/dlls/gdi32/bitblt.c index 09bb7a4c683..54c923236ee 100644 --- a/dlls/gdi32/bitblt.c +++ b/dlls/gdi32/bitblt.c @@ -827,8 +827,8 @@ BOOL WINAPI MaskBlt(HDC hdcDest, INT nXDest, INT nYDest, DeleteObject(hBitmap2); DeleteObject(hbrMask); - DeleteDC(hDC1); - DeleteDC(hDC2); + NtGdiDeleteObjectApp( hDC1 ); + NtGdiDeleteObjectApp( hDC2 ); return TRUE; } @@ -923,12 +923,12 @@ error: SetTextColor(hdcDest, oldForeground); if(hdcWork) { NtGdiSelectBitmap(hdcWork, oldWork); - DeleteDC(hdcWork); + NtGdiDeleteObjectApp( hdcWork ); } if(bmpWork) DeleteObject(bmpWork); if(hdcMask) { NtGdiSelectBitmap(hdcMask, oldMask); - DeleteDC(hdcMask); + NtGdiDeleteObjectApp( hdcMask ); } if(bmpMask) DeleteObject(bmpMask); return ret; diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c index fa15b43fc8b..2414c41d785 100644 --- a/dlls/gdi32/dc.c +++ b/dlls/gdi32/dc.c @@ -256,15 +256,6 @@ void update_dc( DC *dc ) } -/*********************************************************************** - * DC_DeleteObject - */ -static BOOL DC_DeleteObject( HGDIOBJ handle ) -{ - return DeleteDC( handle ); -} - - static void set_bk_color( DC *dc, COLORREF color ) { PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetBkColor ); @@ -431,6 +422,37 @@ static BOOL reset_dc_state( HDC hdc ) } +/*********************************************************************** + * DC_DeleteObject + */ +static BOOL DC_DeleteObject( HGDIOBJ handle ) +{ + DC *dc; + + TRACE( "%p\n", handle ); + + GDI_CheckNotLock(); + + if (!(dc = get_dc_ptr( handle ))) return FALSE; + if (dc->refcount != 1) + { + FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount ); + release_dc_ptr( dc ); + return FALSE; + } + + /* Call hook procedure to check whether is it OK to delete this DC */ + if (dc->hookProc && !dc->hookProc( dc->hSelf, DCHC_DELETEDC, dc->dwHookData, 0 )) + { + release_dc_ptr( dc ); + return TRUE; + } + reset_dc_state( handle ); + free_dc_ptr( dc ); + return TRUE; +} + + /*********************************************************************** * NtGdiSaveDC (win32u.@) */ @@ -736,39 +758,6 @@ HDC WINAPI NtGdiCreateCompatibleDC( HDC hdc ) } -/*********************************************************************** - * DeleteDC (GDI32.@) - */ -BOOL WINAPI DeleteDC( HDC hdc ) -{ - DC * dc; - - TRACE("%p\n", hdc ); - - if (is_meta_dc( hdc )) return METADC_DeleteDC( hdc ); - - GDI_CheckNotLock(); - - if (!(dc = get_dc_ptr( hdc ))) return FALSE; - if (dc->refcount != 1) - { - FIXME( "not deleting busy DC %p refcount %u\n", dc->hSelf, dc->refcount ); - release_dc_ptr( dc ); - return FALSE; - } - - /* Call hook procedure to check whether is it OK to delete this DC */ - if (dc->hookProc && !dc->hookProc( dc->hSelf, DCHC_DELETEDC, dc->dwHookData, 0 )) - { - release_dc_ptr( dc ); - return TRUE; - } - reset_dc_state( hdc ); - free_dc_ptr( dc ); - return TRUE; -} - - /*********************************************************************** * NtGdiResetDC (win32u.@) */ diff --git a/dlls/gdi32/dib.c b/dlls/gdi32/dib.c index 7da248079b2..de1942894de 100644 --- a/dlls/gdi32/dib.c +++ b/dlls/gdi32/dib.c @@ -1687,7 +1687,7 @@ NTSTATUS WINAPI D3DKMTCreateDCFromMemory( D3DKMT_CREATEDCFROMMEMORY *desc ) error: if (bmp) HeapFree( GetProcessHeap(), 0, bmp->color_table ); HeapFree( GetProcessHeap(), 0, bmp ); - DeleteDC( dc ); + NtGdiDeleteObjectApp( dc ); return STATUS_INVALID_PARAMETER; } @@ -1704,7 +1704,7 @@ NTSTATUS WINAPI D3DKMTDestroyDCFromMemory( const D3DKMT_DESTROYDCFROMMEMORY *des if (GetObjectType( desc->hDc ) != OBJ_MEMDC || GetObjectType( desc->hBitmap ) != OBJ_BITMAP) return STATUS_INVALID_PARAMETER; DeleteObject( desc->hBitmap ); - DeleteDC( desc->hDc ); + NtGdiDeleteObjectApp( desc->hDc ); return STATUS_SUCCESS; } diff --git a/dlls/gdi32/gdidc.c b/dlls/gdi32/gdidc.c index 0b005944f93..af529fdb8e9 100644 --- a/dlls/gdi32/gdidc.c +++ b/dlls/gdi32/gdidc.c @@ -95,6 +95,15 @@ HDC WINAPI CreateICW( const WCHAR *driver, const WCHAR *device, const WCHAR *out return CreateDCW( driver, device, output, init_data ); } +/*********************************************************************** + * DeleteDC (GDI32.@) + */ +BOOL WINAPI DeleteDC( HDC hdc ) +{ + if (is_meta_dc( hdc )) return METADC_DeleteDC( hdc ); + return NtGdiDeleteObjectApp( hdc ); +} + /*********************************************************************** * ResetDCA (GDI32.@) */ diff --git a/dlls/gdi32/objects.c b/dlls/gdi32/objects.c index 3ae836612c4..3acafbc9331 100644 --- a/dlls/gdi32/objects.c +++ b/dlls/gdi32/objects.c @@ -153,7 +153,14 @@ BOOL WINAPI DeleteObject( HGDIOBJ obj ) struct hdc_list *hdc_list = NULL; struct wine_rb_entry *entry; - if (is_meta_dc( obj )) return METADC_DeleteDC( obj ); + switch (gdi_handle_type( obj )) + { + case NTGDI_OBJ_DC: + case NTGDI_OBJ_MEMDC: + case NTGDI_OBJ_ENHMETADC: + case NTGDI_OBJ_METADC: + return DeleteDC( obj ); + } EnterCriticalSection( &obj_map_cs );