50ed2e6163f01b6e9f511ff5a97d5e14d3923a26
[reactos.git] / subsystems / win32 / win32k / include / gdiobj.h
1 /*
2 * GDI object common header definition
3 *
4 */
5
6 #pragma once
7
8 /* Public GDI Object/Handle definitions */
9 #include <win32k/ntgdihdl.h>
10 #include "win32.h"
11
12 typedef struct _GDI_HANDLE_TABLE
13 {
14 /* The table must be located at the beginning of this structure so it can be
15 * properly mapped!
16 */
17 //////////////////////////////////////////////////////////////////////////////
18 GDI_TABLE_ENTRY Entries[GDI_HANDLE_COUNT];
19 DEVCAPS DevCaps; // Device Capabilities.
20 FLONG flDeviceUniq; // Device settings uniqueness.
21 PVOID pvLangPack; // Language Pack.
22 CFONT cfPublic[GDI_CFONT_MAX]; // Public Fonts.
23 DWORD dwCFCount;
24 //////////////////////////////////////////////////////////////////////////////
25 PPAGED_LOOKASIDE_LIST LookasideLists;
26
27 ULONG FirstFree;
28 ULONG FirstUnused;
29
30 } GDI_HANDLE_TABLE, *PGDI_HANDLE_TABLE;
31
32 extern PGDI_HANDLE_TABLE GdiHandleTable;
33
34 typedef PVOID PGDIOBJ;
35
36 typedef BOOL (INTERNAL_CALL *GDICLEANUPPROC)(PVOID ObjectBody);
37
38 /* Every GDI Object must have this standard type of header.
39 * It's for thread locking. */
40 typedef struct _BASEOBJECT
41 {
42 HGDIOBJ hHmgr;
43 ULONG ulShareCount;
44 USHORT cExclusiveLock;
45 USHORT BaseFlags;
46 PTHREADINFO Tid;
47 } BASEOBJECT, *POBJ;
48
49 typedef struct _CLIENTOBJ
50 {
51 BASEOBJECT BaseObject;
52 } CLIENTOBJ, *PCLIENTOBJ;
53
54 enum BASEFLAGS
55 {
56 BASEFLAG_LOOKASIDE = 0x80,
57
58 /* ReactOS specific: */
59 BASEFLAG_READY_TO_DIE = 0x1000
60 };
61
62 BOOL INTERNAL_CALL GDIOBJ_OwnedByCurrentProcess(HGDIOBJ ObjectHandle);
63 BOOL INTERNAL_CALL GDIOBJ_SetOwnership(HGDIOBJ ObjectHandle, PEPROCESS Owner);
64 BOOL INTERNAL_CALL GDIOBJ_CopyOwnership(HGDIOBJ CopyFrom, HGDIOBJ CopyTo);
65 BOOL INTERNAL_CALL GDIOBJ_ConvertToStockObj(HGDIOBJ *hObj);
66 //VOID INTERNAL_CALL GDIOBJ_ShareUnlockObjByPtr(POBJ Object);
67 BOOL INTERNAL_CALL GDIOBJ_ValidateHandle(HGDIOBJ hObj, ULONG ObjectType);
68 POBJ INTERNAL_CALL GDIOBJ_AllocObj(UCHAR ObjectType);
69 POBJ INTERNAL_CALL GDIOBJ_AllocObjWithHandle(ULONG ObjectType);
70 VOID INTERNAL_CALL GDIOBJ_FreeObj (POBJ pObj, UCHAR ObjectType);
71 BOOL INTERNAL_CALL GDIOBJ_FreeObjByHandle (HGDIOBJ hObj, DWORD ObjectType);
72 PGDIOBJ INTERNAL_CALL GDIOBJ_LockObj (HGDIOBJ hObj, DWORD ObjectType);
73 PGDIOBJ INTERNAL_CALL GDIOBJ_ShareLockObj (HGDIOBJ hObj, DWORD ObjectType);
74
75 PVOID INTERNAL_CALL GDI_MapHandleTable(PSECTION_OBJECT SectionObject, PEPROCESS Process);
76
77 #define GDIOBJ_GetObjectType(Handle) \
78 GDI_HANDLE_GET_TYPE(Handle)
79
80 #define GDIOBJFLAG_DEFAULT (0x0)
81 #define GDIOBJFLAG_IGNOREPID (0x1)
82 #define GDIOBJFLAG_IGNORELOCK (0x2)
83
84 BOOL FASTCALL GreDeleteObject(HGDIOBJ hObject);
85 BOOL FASTCALL IsObjectDead(HGDIOBJ);
86 BOOL FASTCALL IntGdiSetDCOwnerEx( HDC, DWORD, BOOL);
87 BOOL FASTCALL IntGdiSetRegionOwner(HRGN,DWORD);
88
89 /*!
90 * Release GDI object. Every object locked by GDIOBJ_LockObj() must be unlocked.
91 * You should unlock the object
92 * as soon as you don't need to have access to it's data.
93
94 * \param Object Object pointer (as returned by GDIOBJ_LockObj).
95 */
96 ULONG
97 FORCEINLINE
98 GDIOBJ_UnlockObjByPtr(POBJ Object)
99 {
100 INT cLocks = InterlockedDecrement((PLONG)&Object->cExclusiveLock);
101 ASSERT(cLocks >= 0);
102 return cLocks;
103 }
104
105 ULONG
106 FORCEINLINE
107 GDIOBJ_ShareUnlockObjByPtr(POBJ Object)
108 {
109 HGDIOBJ hobj = Object->hHmgr;
110 USHORT flags = Object->BaseFlags;
111 INT cLocks = InterlockedDecrement((PLONG)&Object->ulShareCount);
112 ASSERT(cLocks >= 0);
113 if ((flags & BASEFLAG_READY_TO_DIE) && (cLocks == 0))
114 {
115 GDIOBJ_FreeObjByHandle(hobj, GDI_OBJECT_TYPE_DONTCARE);
116 }
117 return cLocks;
118 }
119
120 #ifdef GDI_DEBUG
121 ULONG FASTCALL GDIOBJ_IncrementShareCount(POBJ Object);
122 #else
123 ULONG
124 FORCEINLINE
125 GDIOBJ_IncrementShareCount(POBJ Object)
126 {
127 INT cLocks = InterlockedIncrement((PLONG)&Object->ulShareCount);
128 ASSERT(cLocks >= 1);
129 return cLocks;
130 }
131 #endif
132
133 INT FASTCALL GreGetObjectOwner(HGDIOBJ, GDIOBJTYPE);