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

Huw Davies huw at codeweavers.com
Fri Jul 8 06:57:14 CDT 2016


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 at codeweavers.com>
---
 dlls/gdi32/dc.c          |  5 +++--
 dlls/gdi32/gdi_private.h |  1 +
 dlls/gdi32/gdiobj.c      | 29 ++++++++++++++++++++++++-----
 dlls/gdi32/pen.c         | 10 ++++++----
 4 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c
index 5146f5b..2e54671 100644
--- a/dlls/gdi32/dc.c
+++ b/dlls/gdi32/dc.c
@@ -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:
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index 9c58747..79a7a74 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -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;
diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c
index 237544d..46b2241 100644
--- a/dlls/gdi32/gdiobj.c
+++ b/dlls/gdi32/gdiobj.c
@@ -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
diff --git a/dlls/gdi32/pen.c b/dlls/gdi32/pen.c
index cf4b080..d6c1dc4 100644
--- a/dlls/gdi32/pen.c
+++ b/dlls/gdi32/pen.c
@@ -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:
     {
-- 
2.7.4




More information about the wine-patches mailing list