[PATCH v2 1/6] gdi32: Use shifted values for NTGDI_OBJ_* constants.

Huw Davies huw at codeweavers.com
Fri Sep 3 07:59:47 CDT 2021


From: Jacek Caban <jacek at codeweavers.com>

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/gdi32/dc.c            |  4 ++--
 dlls/gdi32/gdi_private.h   |  6 +++---
 dlls/gdi32/gdidc.c         |  4 ++--
 dlls/gdi32/gdiobj.c        | 24 ++++++++++++------------
 dlls/gdi32/ntgdi_private.h |  8 ++++----
 dlls/gdi32/objects.c       |  8 ++++----
 dlls/gdi32/pen.c           |  4 ++--
 dlls/gdi32/tests/gdiobj.c  |  9 ++++++---
 include/ntgdi.h            | 26 +++++++++++++-------------
 9 files changed, 48 insertions(+), 45 deletions(-)

diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c
index 73b2e74174a..739dc53d31d 100644
--- a/dlls/gdi32/dc.c
+++ b/dlls/gdi32/dc.c
@@ -47,7 +47,7 @@ static const struct gdi_obj_funcs dc_funcs =
 
 static inline DC *get_dc_obj( HDC hdc )
 {
-    WORD type;
+    DWORD type;
     DC *dc = get_any_obj_ptr( hdc, &type );
     if (!dc) return NULL;
 
@@ -118,7 +118,7 @@ static void set_initial_dc_state( DC *dc )
 /***********************************************************************
  *           alloc_dc_ptr
  */
-DC *alloc_dc_ptr( WORD magic )
+DC *alloc_dc_ptr( DWORD magic )
 {
     DC *dc;
 
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index ce89dbc6ff5..675a2990215 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -29,16 +29,16 @@
 #include "ntgdi.h"
 
 void set_gdi_client_ptr( HGDIOBJ handle, void *ptr ) DECLSPEC_HIDDEN;
-void *get_gdi_client_ptr( HGDIOBJ handle, WORD type ) DECLSPEC_HIDDEN;
+void *get_gdi_client_ptr( HGDIOBJ handle, DWORD type ) DECLSPEC_HIDDEN;
 DC_ATTR *get_dc_attr( HDC hdc ) DECLSPEC_HIDDEN;
 void GDI_hdc_using_object( HGDIOBJ obj, HDC hdc,
                            void (*delete)( HDC hdc, HGDIOBJ handle )) DECLSPEC_HIDDEN;
 void GDI_hdc_not_using_object( HGDIOBJ obj, HDC hdc ) DECLSPEC_HIDDEN;
 
-static inline WORD gdi_handle_type( HGDIOBJ obj )
+static inline DWORD gdi_handle_type( HGDIOBJ obj )
 {
     unsigned int handle = HandleToULong( obj );
-    return (handle & NTGDI_HANDLE_TYPE_MASK) >> NTGDI_HANDLE_TYPE_SHIFT;
+    return handle & NTGDI_HANDLE_TYPE_MASK;
 }
 
 static inline BOOL is_meta_dc( HDC hdc )
diff --git a/dlls/gdi32/gdidc.c b/dlls/gdi32/gdidc.c
index 0f9c8ede8c9..7f1a5a9cd24 100644
--- a/dlls/gdi32/gdidc.c
+++ b/dlls/gdi32/gdidc.c
@@ -31,9 +31,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(gdi);
 
 DC_ATTR *get_dc_attr( HDC hdc )
 {
-    WORD type = gdi_handle_type( hdc );
+    DWORD type = gdi_handle_type( hdc );
     DC_ATTR *dc_attr;
-    if ((type & 0x1f) != NTGDI_OBJ_DC || !(dc_attr = get_gdi_client_ptr( hdc, 0 )))
+    if ((type & 0x1f0000) != NTGDI_OBJ_DC || !(dc_attr = get_gdi_client_ptr( hdc, 0 )))
     {
         SetLastError( ERROR_INVALID_HANDLE );
         return NULL;
diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c
index ff3dd9807c2..cc68070674a 100644
--- a/dlls/gdi32/gdiobj.c
+++ b/dlls/gdi32/gdiobj.c
@@ -47,7 +47,7 @@ HMODULE gdi32_module = 0;
 static inline HGDIOBJ entry_to_handle( GDI_HANDLE_ENTRY *entry )
 {
     unsigned int idx = entry - gdi_shared.Handles;
-    return LongToHandle( idx | (entry->Unique << 16) );
+    return LongToHandle( idx | (entry->Unique << NTGDI_HANDLE_TYPE_SHIFT) );
 }
 
 static inline GDI_HANDLE_ENTRY *handle_entry( HGDIOBJ handle )
@@ -720,8 +720,8 @@ static void dump_gdi_objects( void )
         else
             TRACE( "handle %p obj %s type %s selcount %u deleted %u\n",
                    entry_to_handle( entry ), wine_dbgstr_longlong( entry->Object ),
-                   gdi_obj_type( entry->ExtType ), entry_obj( entry )->selcount,
-                   entry_obj( entry )->deleted );
+                   gdi_obj_type( entry->ExtType << NTGDI_HANDLE_TYPE_SHIFT ),
+                   entry_obj( entry )->selcount, entry_obj( entry )->deleted );
     }
     LeaveCriticalSection( &gdi_section );
 }
@@ -731,7 +731,7 @@ static void dump_gdi_objects( void )
  *
  * Allocate a GDI handle for an object, which must have been allocated on the process heap.
  */
-HGDIOBJ alloc_gdi_handle( struct gdi_obj_header *obj, WORD type, const struct gdi_obj_funcs *funcs )
+HGDIOBJ alloc_gdi_handle( struct gdi_obj_header *obj, DWORD type, const struct gdi_obj_funcs *funcs )
 {
     GDI_HANDLE_ENTRY *entry;
     HGDIOBJ ret;
@@ -757,8 +757,8 @@ HGDIOBJ alloc_gdi_handle( struct gdi_obj_header *obj, WORD type, const struct gd
     obj->system   = 0;
     obj->deleted  = 0;
     entry->Object  = (UINT_PTR)obj;
-    entry->Type    = type & 0x1f;
-    entry->ExtType = type;
+    entry->ExtType = type >> NTGDI_HANDLE_TYPE_SHIFT;
+    entry->Type    = entry->ExtType & 0x1f;
     if (++entry->Generation == 0xff) entry->Generation = 1;
     ret = entry_to_handle( entry );
     LeaveCriticalSection( &gdi_section );
@@ -781,8 +781,8 @@ void *free_gdi_handle( HGDIOBJ handle )
     EnterCriticalSection( &gdi_section );
     if ((entry = handle_entry( handle )))
     {
-        TRACE( "freed %s %p %u/%u\n", gdi_obj_type( entry->ExtType ), handle,
-               InterlockedDecrement( &debug_count ) + 1, GDI_MAX_HANDLE_COUNT );
+        TRACE( "freed %s %p %u/%u\n", gdi_obj_type( entry->ExtType << NTGDI_HANDLE_TYPE_SHIFT ),
+               handle, InterlockedDecrement( &debug_count ) + 1, GDI_MAX_HANDLE_COUNT );
         object = entry_obj( entry );
         entry->Type = 0;
         entry->Object = (UINT_PTR)next_free;
@@ -818,7 +818,7 @@ HGDIOBJ get_full_gdi_handle( HGDIOBJ handle )
  * associated with the handle.
  * The object must be released with GDI_ReleaseObj.
  */
-void *get_any_obj_ptr( HGDIOBJ handle, WORD *type )
+void *get_any_obj_ptr( HGDIOBJ handle, DWORD *type )
 {
     void *ptr = NULL;
     GDI_HANDLE_ENTRY *entry;
@@ -828,7 +828,7 @@ void *get_any_obj_ptr( HGDIOBJ handle, WORD *type )
     if ((entry = handle_entry( handle )))
     {
         ptr = entry_obj( entry );
-        *type = entry->ExtType;
+        *type = entry->ExtType << NTGDI_HANDLE_TYPE_SHIFT;
     }
 
     if (!ptr) LeaveCriticalSection( &gdi_section );
@@ -842,9 +842,9 @@ void *get_any_obj_ptr( HGDIOBJ handle, WORD *type )
  * Return NULL if the object has the wrong type.
  * The object must be released with GDI_ReleaseObj.
  */
-void *GDI_GetObjPtr( HGDIOBJ handle, WORD type )
+void *GDI_GetObjPtr( HGDIOBJ handle, DWORD type )
 {
-    WORD ret_type;
+    DWORD ret_type;
     void *ptr = get_any_obj_ptr( handle, &ret_type );
     if (ptr && ret_type != type)
     {
diff --git a/dlls/gdi32/ntgdi_private.h b/dlls/gdi32/ntgdi_private.h
index c2e45ab7ce0..a438a3f93ae 100644
--- a/dlls/gdi32/ntgdi_private.h
+++ b/dlls/gdi32/ntgdi_private.h
@@ -187,7 +187,7 @@ static inline HRGN get_dc_region( DC *dc )
 }
 
 /* dc.c */
-extern DC *alloc_dc_ptr( WORD magic ) DECLSPEC_HIDDEN;
+extern DC *alloc_dc_ptr( DWORD magic ) DECLSPEC_HIDDEN;
 extern void free_dc_ptr( DC *dc ) DECLSPEC_HIDDEN;
 extern DC *get_dc_ptr( HDC hdc ) DECLSPEC_HIDDEN;
 extern void release_dc_ptr( DC *dc ) DECLSPEC_HIDDEN;
@@ -390,12 +390,12 @@ extern BOOL opentype_get_properties( const void *data, size_t size, const struct
 extern BOOL translate_charset_info( DWORD *src, CHARSETINFO *cs, DWORD flags ) DECLSPEC_HIDDEN;
 
 /* gdiobj.c */
-extern HGDIOBJ alloc_gdi_handle( struct gdi_obj_header *obj, WORD type,
+extern HGDIOBJ alloc_gdi_handle( struct gdi_obj_header *obj, DWORD type,
                                  const struct gdi_obj_funcs *funcs ) DECLSPEC_HIDDEN;
 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_GetObjPtr( HGDIOBJ, DWORD ) DECLSPEC_HIDDEN;
+extern void *get_any_obj_ptr( HGDIOBJ, DWORD * ) 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/objects.c b/dlls/gdi32/objects.c
index 96ab3271034..b989a83daa1 100644
--- a/dlls/gdi32/objects.c
+++ b/dlls/gdi32/objects.c
@@ -95,10 +95,10 @@ static inline GDI_HANDLE_ENTRY *handle_entry( HGDIOBJ handle )
     return NULL;
 }
 
-static WORD get_object_type( HGDIOBJ obj )
+static DWORD get_object_type( HGDIOBJ obj )
 {
     GDI_HANDLE_ENTRY *entry = handle_entry( obj );
-    return entry ? entry->ExtType : 0;
+    return entry ? entry->ExtType << NTGDI_HANDLE_TYPE_SHIFT : 0;
 }
 
 void set_gdi_client_ptr( HGDIOBJ obj, void *ptr )
@@ -107,10 +107,10 @@ void set_gdi_client_ptr( HGDIOBJ obj, void *ptr )
     if (entry) entry->UserPointer = (UINT_PTR)ptr;
 }
 
-void *get_gdi_client_ptr( HGDIOBJ obj, WORD type )
+void *get_gdi_client_ptr( HGDIOBJ obj, DWORD type )
 {
     GDI_HANDLE_ENTRY *entry = handle_entry( obj );
-    if (!entry || (type && entry->ExtType != type) || !entry->UserPointer)
+    if (!entry || (type && entry->ExtType << NTGDI_HANDLE_TYPE_SHIFT != type))
         return NULL;
     return (void *)(UINT_PTR)entry->UserPointer;
 }
diff --git a/dlls/gdi32/pen.c b/dlls/gdi32/pen.c
index 684cc8375d1..ff2a766d40c 100644
--- a/dlls/gdi32/pen.c
+++ b/dlls/gdi32/pen.c
@@ -199,7 +199,7 @@ HGDIOBJ WINAPI NtGdiSelectPen( HDC hdc, HGDIOBJ handle )
 {
     PENOBJ *pen;
     HGDIOBJ ret = 0;
-    WORD type;
+    DWORD type;
     DC *dc;
 
     if (!(dc = get_dc_ptr( hdc ))) return 0;
@@ -262,7 +262,7 @@ static BOOL PEN_DeleteObject( HGDIOBJ handle )
  */
 static INT PEN_GetObject( HGDIOBJ handle, INT count, LPVOID buffer )
 {
-    WORD type;
+    DWORD type;
     PENOBJ *pen = get_any_obj_ptr( handle, &type );
     INT ret = 0;
 
diff --git a/dlls/gdi32/tests/gdiobj.c b/dlls/gdi32/tests/gdiobj.c
index 64d37e39ab6..e6efce8e552 100644
--- a/dlls/gdi32/tests/gdiobj.c
+++ b/dlls/gdi32/tests/gdiobj.c
@@ -389,15 +389,18 @@ static void test_shared_handle_entry( HGDIOBJ obj, unsigned int type, BOOL is_st
        entry->Unique, handle >> 16);
     if (type != NTGDI_OBJ_MEMDC)
     {
-        ok(entry->ExtType == type, "ExtType = %x, expected %x\n", entry->ExtType, type);
+        ok(entry->ExtType << NTGDI_HANDLE_TYPE_SHIFT == type, "ExtType = %x, expected %x\n",
+           entry->ExtType, type);
     }
     else
     {
         todo_wine
-        ok(entry->ExtType == NTGDI_OBJ_DC, "ExtType = %x, expected NTGDI_OBJ_DC\n", entry->ExtType);
+        ok(entry->ExtType << NTGDI_HANDLE_TYPE_SHIFT == NTGDI_OBJ_DC,
+           "ExtType = %x, expected NTGDI_OBJ_DC\n", entry->ExtType);
     }
     ok(entry->StockFlag == is_stock, "StockFlag = %x\n", entry->StockFlag);
-    ok(entry->Type == (type & 0x1f), "Type = %x, expected %x\n", entry->Type, type & 0x1f);
+    ok(entry->Type << NTGDI_HANDLE_TYPE_SHIFT == (type & 0x1f0000),
+       "Type = %x, expected %x\n", entry->Type, type & 0x1f);
     ok(entry->Object, "Object = NULL\n");
     ok(entry->Owner.Count == 0, "Count = %u\n", entry->Owner.Count);
 }
diff --git a/include/ntgdi.h b/include/ntgdi.h
index 23247c09e4a..2ee70cf3971 100644
--- a/include/ntgdi.h
+++ b/include/ntgdi.h
@@ -54,21 +54,21 @@ typedef struct _GDI_HANDLE_ENTRY
 
 #define GDI_MAX_HANDLE_COUNT 0x10000
 
-#define NTGDI_OBJ_DC              0x01
-#define NTGDI_OBJ_ENHMETADC       0x21
-#define NTGDI_OBJ_REGION          0x04
-#define NTGDI_OBJ_METAFILE        0x26
-#define NTGDI_OBJ_ENHMETAFILE     0x46
-#define NTGDI_OBJ_METADC          0x66
-#define NTGDI_OBJ_PAL             0x08
-#define NTGDI_OBJ_BITMAP          0x09
-#define NTGDI_OBJ_FONT            0x0a
-#define NTGDI_OBJ_BRUSH           0x10
-#define NTGDI_OBJ_PEN             0x30
-#define NTGDI_OBJ_EXTPEN          0x50
+#define NTGDI_OBJ_DC              0x010000
+#define NTGDI_OBJ_ENHMETADC       0x210000
+#define NTGDI_OBJ_REGION          0x040000
+#define NTGDI_OBJ_METAFILE        0x260000
+#define NTGDI_OBJ_ENHMETAFILE     0x460000
+#define NTGDI_OBJ_METADC          0x660000
+#define NTGDI_OBJ_PAL             0x080000
+#define NTGDI_OBJ_BITMAP          0x090000
+#define NTGDI_OBJ_FONT            0x0a0000
+#define NTGDI_OBJ_BRUSH           0x100000
+#define NTGDI_OBJ_PEN             0x300000
+#define NTGDI_OBJ_EXTPEN          0x500000
 
 /* Wine extension, native uses NTGDI_OBJ_DC */
-#define NTGDI_OBJ_MEMDC           0x41
+#define NTGDI_OBJ_MEMDC           0x410000
 
 #define NTGDI_HANDLE_TYPE_SHIFT    16
 #define NTGDI_HANDLE_TYPE_MASK     0x007f0000
-- 
2.23.0




More information about the wine-devel mailing list