ReactOS  0.4.14-dev-815-ge410a12
clientobj.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS WIN32 subsystem
4  * PURPOSE: Support functions for GDI client objects
5  * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
6  */
7 
8 #include <precomp.h>
9 
12 
13 typedef struct _CLIENTOBJLINK
14 {
19 
21 
22 BOOL
23 WINAPI
26  _In_ PVOID pvObject)
27 {
28  PCLIENTOBJLINK pcol;
29  ULONG iHashIndex;
30 
31  /* Allocate a link structure */
32  pcol = HeapAlloc(GetProcessHeap(), 0, sizeof(*pcol));
33  if (pcol == NULL)
34  {
35  return FALSE;
36  }
37 
38  /* Setup the link structure */
39  pcol->hobj = hobj;
40  pcol->pvObj = pvObject;
41 
42  /* Calculate the hash index */
43  iHashIndex = (ULONG_PTR)hobj % _countof(gapcolHashTable);
44 
45  /* Enter the critical section */
47 
48  /* Insert the link structure */
49  pcol->pcolNext = gapcolHashTable[iHashIndex];
50  gapcolHashTable[iHashIndex] = pcol;
51  gcClientObj++;
52 
53  /* Leave the critical section */
55 
56  return TRUE;
57 }
58 
59 PVOID
60 WINAPI
63 {
64  ULONG iHashIndex;
65  PCLIENTOBJLINK pcol;
66  PVOID pvObject = NULL;
67 
68  /* Calculate the hash index */
69  iHashIndex = (ULONG_PTR)hobj % _countof(gapcolHashTable);
70 
71  /* Enter the critical section */
73 
74  /* Loop the link entries in this hash bucket */
75  pcol = gapcolHashTable[iHashIndex];
76  while (pcol != NULL)
77  {
78  /* Check if this is the object we want */
79  if (pcol->hobj == hobj)
80  {
81  /* Get the object pointer and bail out */
82  pvObject = pcol->pvObj;
83  break;
84  }
85 
86  /* Go to the next entry */
87  pcol = pcol->pcolNext;
88  }
89 
90  /* Leave the critical section */
92 
93  return pvObject;
94 }
95 
96 PVOID
97 WINAPI
100 {
101  PCLIENTOBJLINK pcol, *ppcol;
102  ULONG iHashIndex;
103  PVOID pvObject = NULL;
104 
105  /* Calculate the hash index */
106  iHashIndex = (ULONG_PTR)hobj % _countof(gapcolHashTable);
107 
108  /* Enter the critical section */
110 
111  /* Loop the link entries in this hash bucket */
112  ppcol = &gapcolHashTable[iHashIndex];
113  while (*ppcol != NULL)
114  {
115  /* Get the current client object link */
116  pcol = *ppcol;
117 
118  /* Check if this is the one we want */
119  if (pcol->hobj == hobj)
120  {
121  /* Update the link pointer, removing this link */
122  *ppcol = pcol->pcolNext;
123  gcClientObj--;
124 
125  /* Get the object pointer */
126  pvObject = pcol->pvObj;
127 
128  /* Free the link structure */
129  HeapFree(GetProcessHeap(), 0, pcol);
130 
131  /* We're done */
132  break;
133  }
134 
135  /* Go to the next link pointer */
136  ppcol = &(pcol->pcolNext);
137  }
138 
139  /* Leave the critical section */
141 
142  /* Return the object pointer, or NULL if we did not find it */
143  return pvObject;
144 }
145 
146 HGDIOBJ
147 WINAPI
149  _In_ PVOID pvObject,
150  _In_ GDILOOBJTYPE eObjType)
151 {
152  HGDIOBJ hobj;
153 
154  /* Call win32k to create a client object handle */
155  hobj = NtGdiCreateClientObj(eObjType);
156  if (hobj == NULL)
157  {
158  return NULL;
159  }
160 
161  /* Create the client object link */
162  if (!GdiCreateClientObjLink(hobj, pvObject))
163  {
165  return NULL;
166  }
167 
168  return hobj;
169 }
170 
171 PVOID
172 WINAPI
174  _In_ HGDIOBJ hobj)
175 {
176  PVOID pvObject;
177 
178  /* Remove the client object link */
179  pvObject = GdiRemoveClientObjLink(hobj);
180  if (pvObject == NULL)
181  {
182  return NULL;
183  }
184 
185  /* Call win32k to delete the handle */
187  {
188  ASSERT(FALSE);
189  }
190 
191  return pvObject;
192 }
#define TRUE
Definition: types.h:120
PVOID WINAPI GdiDeleteClientObj(_In_ HGDIOBJ hobj)
Definition: clientobj.c:173
ULONG gcClientObj
Definition: clientobj.c:11
__kernel_entry W32KAPI BOOL APIENTRY NtGdiDeleteClientObj(_In_ HANDLE h)
#define _countof(array)
Definition: fontsub.cpp:30
PVOID WINAPI GdiRemoveClientObjLink(_In_ HGDIOBJ hobj)
Definition: clientobj.c:98
BOOL WINAPI GdiCreateClientObjLink(_In_ HGDIOBJ hobj, _In_ PVOID pvObject)
Definition: clientobj.c:24
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
__kernel_entry W32KAPI HANDLE APIENTRY NtGdiCreateClientObj(_In_ ULONG ulType)
unsigned int BOOL
Definition: ntddk_ex.h:94
HGDIOBJ WINAPI GdiCreateClientObj(_In_ PVOID pvObject, _In_ GDILOOBJTYPE eObjType)
Definition: clientobj.c:148
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define WINAPI
Definition: msvc.h:6
CRITICAL_SECTION gcsClientObjLinks
Definition: clientobj.c:10
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PVOID WINAPI GdiGetClientObjLink(_In_ HGDIOBJ hobj)
Definition: clientobj.c:61
PCLIENTOBJLINK gapcolHashTable[127]
Definition: clientobj.c:20
#define _In_
Definition: no_sal2.h:204
struct _CLIENTOBJLINK CLIENTOBJLINK
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
struct _CLIENTOBJLINK * PCLIENTOBJLINK
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
enum GDILoObjType GDILOOBJTYPE
#define HeapFree(x, y, z)
Definition: compat.h:402