gdi32: Add get_any_obj_ptr() to retrieve the ptr and type of a GDI handle.

This enables get_dc_obj() to check the type without calling GetObjectType()
and thus it saves additional calls to Enter/LeaveCriticalSection().

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Huw Davies 2016-07-08 12:57:14 +01:00 committed by Alexandre Julliard
parent b0664560d4
commit fc2d310949
4 changed files with 34 additions and 11 deletions

View File

@ -52,10 +52,11 @@ static const struct gdi_obj_funcs dc_funcs =
static inline DC *get_dc_obj( HDC hdc )
{
DC *dc = GDI_GetObjPtr( hdc, 0 );
WORD type;
DC *dc = get_any_obj_ptr( hdc, &type );
if (!dc) return NULL;
switch (GetObjectType( hdc ))
switch (type)
{
case OBJ_DC:
case OBJ_MEMDC:

View File

@ -299,6 +299,7 @@ extern HGDIOBJ alloc_gdi_handle( void *obj, WORD type, const struct gdi_obj_func
extern void *free_gdi_handle( HGDIOBJ handle ) DECLSPEC_HIDDEN;
extern HGDIOBJ get_full_gdi_handle( HGDIOBJ handle ) DECLSPEC_HIDDEN;
extern void *GDI_GetObjPtr( HGDIOBJ, WORD ) DECLSPEC_HIDDEN;
extern void *get_any_obj_ptr( HGDIOBJ, WORD * ) DECLSPEC_HIDDEN;
extern void GDI_ReleaseObj( HGDIOBJ ) DECLSPEC_HIDDEN;
extern void GDI_CheckNotLock(void) DECLSPEC_HIDDEN;
extern UINT GDI_get_ref_count( HGDIOBJ handle ) DECLSPEC_HIDDEN;

View File

@ -829,13 +829,13 @@ HGDIOBJ get_full_gdi_handle( HGDIOBJ handle )
}
/***********************************************************************
* GDI_GetObjPtr
* get_any_obj_ptr
*
* Return a pointer to the GDI object associated to the handle.
* Return NULL if the object has the wrong magic number.
* Return a pointer to, and the type of, the GDI object
* associated with the handle.
* The object must be released with GDI_ReleaseObj.
*/
void *GDI_GetObjPtr( HGDIOBJ handle, WORD type )
void *get_any_obj_ptr( HGDIOBJ handle, WORD *type )
{
void *ptr = NULL;
struct gdi_handle_entry *entry;
@ -844,13 +844,32 @@ void *GDI_GetObjPtr( HGDIOBJ handle, WORD type )
if ((entry = handle_entry( handle )))
{
if (!type || entry->type == type) ptr = entry->obj;
ptr = entry->obj;
*type = entry->type;
}
if (!ptr) LeaveCriticalSection( &gdi_section );
return ptr;
}
/***********************************************************************
* GDI_GetObjPtr
*
* Return a pointer to the GDI object associated with the handle.
* Return NULL if the object has the wrong type.
* The object must be released with GDI_ReleaseObj.
*/
void *GDI_GetObjPtr( HGDIOBJ handle, WORD type )
{
WORD ret_type;
void *ptr = get_any_obj_ptr( handle, &ret_type );
if (ptr && ret_type != type)
{
GDI_ReleaseObj( handle );
ptr = NULL;
}
return ptr;
}
/***********************************************************************
* GDI_ReleaseObj

View File

@ -223,6 +223,7 @@ static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc )
PENOBJ *pen;
HGDIOBJ ret = 0;
DC *dc = get_dc_ptr( hdc );
WORD type;
if (!dc)
{
@ -230,12 +231,12 @@ static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc )
return 0;
}
if ((pen = GDI_GetObjPtr( handle, 0 )))
if ((pen = get_any_obj_ptr( handle, &type )))
{
struct brush_pattern *pattern;
PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSelectPen );
switch (GetObjectType( handle ))
switch (type)
{
case OBJ_PEN:
pattern = NULL;
@ -287,12 +288,13 @@ static BOOL PEN_DeleteObject( HGDIOBJ handle )
*/
static INT PEN_GetObject( HGDIOBJ handle, INT count, LPVOID buffer )
{
PENOBJ *pen = GDI_GetObjPtr( handle, 0 );
WORD type;
PENOBJ *pen = get_any_obj_ptr( handle, &type );
INT ret = 0;
if (!pen) return 0;
switch (GetObjectType( handle ))
switch (type)
{
case OBJ_PEN:
{