Commit af6c0a09 authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Move the object refcount handling to the SelectObject backend functions.

parent a1e31397
...@@ -593,9 +593,11 @@ static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, HDC hdc ) ...@@ -593,9 +593,11 @@ static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, HDC hdc )
if (handle) if (handle)
{ {
dc->hBitmap = handle; dc->hBitmap = handle;
GDI_inc_ref_count( handle );
dc->dirty = 0; dc->dirty = 0;
SetRectRgn( dc->hVisRgn, 0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight); SetRectRgn( dc->hVisRgn, 0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight);
DC_InitDC( dc ); DC_InitDC( dc );
GDI_dec_ref_count( ret );
} }
else ret = 0; else ret = 0;
......
...@@ -381,10 +381,14 @@ static HGDIOBJ BRUSH_SelectObject( HGDIOBJ handle, HDC hdc ) ...@@ -381,10 +381,14 @@ static HGDIOBJ BRUSH_SelectObject( HGDIOBJ handle, HDC hdc )
if (brush->logbrush.lbStyle == BS_PATTERN) if (brush->logbrush.lbStyle == BS_PATTERN)
BITMAP_SetOwnerDC( (HBITMAP)brush->logbrush.lbHatch, dc ); BITMAP_SetOwnerDC( (HBITMAP)brush->logbrush.lbHatch, dc );
ret = dc->hBrush;
if (dc->funcs->pSelectBrush) handle = dc->funcs->pSelectBrush( dc->physDev, handle ); if (dc->funcs->pSelectBrush) handle = dc->funcs->pSelectBrush( dc->physDev, handle );
if (handle) dc->hBrush = handle; if (handle)
else ret = 0; {
ret = dc->hBrush;
dc->hBrush = handle;
GDI_inc_ref_count( handle );
GDI_dec_ref_count( ret );
}
GDI_ReleaseObj( handle ); GDI_ReleaseObj( handle );
} }
release_dc_ptr( dc ); release_dc_ptr( dc );
......
...@@ -608,6 +608,8 @@ static HGDIOBJ FONT_SelectObject( HGDIOBJ handle, HDC hdc ) ...@@ -608,6 +608,8 @@ static HGDIOBJ FONT_SelectObject( HGDIOBJ handle, HDC hdc )
{ {
ret = dc->hFont; ret = dc->hFont;
dc->hFont = handle; dc->hFont = handle;
GDI_inc_ref_count( handle );
GDI_dec_ref_count( ret );
} }
DC_ReleaseDCPtr( dc ); DC_ReleaseDCPtr( dc );
return ret; return ret;
......
...@@ -456,6 +456,8 @@ extern BOOL GDI_FreeObject( HGDIOBJ, void *obj ); ...@@ -456,6 +456,8 @@ extern BOOL GDI_FreeObject( HGDIOBJ, void *obj );
extern void *GDI_GetObjPtr( HGDIOBJ, WORD ); extern void *GDI_GetObjPtr( HGDIOBJ, WORD );
extern void GDI_ReleaseObj( HGDIOBJ ); extern void GDI_ReleaseObj( HGDIOBJ );
extern void GDI_CheckNotLock(void); extern void GDI_CheckNotLock(void);
extern BOOL GDI_inc_ref_count( HGDIOBJ handle );
extern BOOL GDI_dec_ref_count( HGDIOBJ handle );
extern BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc); extern BOOL GDI_hdc_using_object(HGDIOBJ obj, HDC hdc);
extern BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc); extern BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc);
......
...@@ -524,22 +524,29 @@ static DWORD get_dpi( void ) ...@@ -524,22 +524,29 @@ static DWORD get_dpi( void )
/*********************************************************************** /***********************************************************************
* inc_ref_count * GDI_inc_ref_count
* *
* Increment the reference count of a GDI object. * Increment the reference count of a GDI object.
*/ */
static inline void inc_ref_count( GDIOBJHDR *header ) BOOL GDI_inc_ref_count( HGDIOBJ handle )
{ {
GDIOBJHDR *header;
if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE )))
{
header->dwCount++; header->dwCount++;
GDI_ReleaseObj( handle );
}
return header != NULL;
} }
/*********************************************************************** /***********************************************************************
* dec_ref_count * GDI_dec_ref_count
* *
* Decrement the reference count of a GDI object. * Decrement the reference count of a GDI object.
*/ */
static inline void dec_ref_count( HGDIOBJ handle ) BOOL GDI_dec_ref_count( HGDIOBJ handle )
{ {
GDIOBJHDR *header; GDIOBJHDR *header;
...@@ -556,6 +563,7 @@ static inline void dec_ref_count( HGDIOBJ handle ) ...@@ -556,6 +563,7 @@ static inline void dec_ref_count( HGDIOBJ handle )
DeleteObject( handle ); DeleteObject( handle );
} }
} }
return header != NULL;
} }
...@@ -1149,14 +1157,7 @@ HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ hObj ) ...@@ -1149,14 +1157,7 @@ HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ hObj )
if (header) if (header)
{ {
if (header->funcs && header->funcs->pSelectObject) if (header->funcs && header->funcs->pSelectObject)
{
ret = header->funcs->pSelectObject( hObj, hdc ); ret = header->funcs->pSelectObject( hObj, hdc );
if (ret && ret != hObj && HandleToULong(ret) > COMPLEXREGION)
{
inc_ref_count( header );
dec_ref_count( ret );
}
}
GDI_ReleaseObj( hObj ); GDI_ReleaseObj( hObj );
} }
} }
......
...@@ -217,14 +217,19 @@ HPEN WINAPI ExtCreatePen( DWORD style, DWORD width, ...@@ -217,14 +217,19 @@ HPEN WINAPI ExtCreatePen( DWORD style, DWORD width,
*/ */
static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc ) static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc )
{ {
HGDIOBJ ret; HGDIOBJ ret = 0;
DC *dc = DC_GetDCPtr( hdc ); DC *dc = DC_GetDCPtr( hdc );
if (!dc) return 0; if (!dc) return 0;
ret = dc->hPen;
if (dc->funcs->pSelectPen) handle = dc->funcs->pSelectPen( dc->physDev, handle ); if (dc->funcs->pSelectPen) handle = dc->funcs->pSelectPen( dc->physDev, handle );
if (handle) dc->hPen = handle; if (handle)
else ret = 0; {
ret = dc->hPen;
dc->hPen = handle;
GDI_inc_ref_count( handle );
GDI_dec_ref_count( ret );
}
DC_ReleaseDCPtr( dc ); DC_ReleaseDCPtr( dc );
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment