2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Native driver for dxg implementation
5 * FILE: drivers/directx/dxg/ddhmg.c
6 * PROGRAMER: Magnus olsen (magnus@greatlord.com)
8 * 30/12-2007 Magnus Olsen
13 /* The DdHmgr manger stuff */
14 ULONG gcSizeDdHmgr
= 64 * sizeof(DD_ENTRY
);
15 PDD_ENTRY gpentDdHmgr
= NULL
;
17 ULONG gcMaxDdHmgr
= 0;
18 PDD_ENTRY gpentDdHmgrLast
= NULL
;
20 HANDLE ghFreeDdHmgr
= 0;
21 HSEMAPHORE ghsemHmgr
= NULL
;
25 VerifyObjectOwner(PDD_ENTRY pEntry
)
27 DWORD Pid
= (DWORD
)(DWORD_PTR
)PsGetCurrentProcessId() & 0xFFFFFFFC;
28 DWORD check
= pEntry
->ObjectOwner
.ulObj
& 0xFFFFFFFE;
29 return ( (check
== Pid
) || (!check
));
36 * The function DdHmgCreate is used internally in dxg.sys
37 * It creates all DX kernel objects that are need it for creation of DX objects.
40 * Return FALSE for failure and TRUE for success in creating the DX object
43 * Only used internally in dxg.sys
49 gpentDdHmgr
= EngAllocMem(FL_ZERO_MEMORY
, gcSizeDdHmgr
, TAG_THDD
);
55 ghsemHmgr
= EngCreateSemaphore();
59 gpLockShortDelay
= EngAllocMem(FL_ZERO_MEMORY
| FL_NONPAGED_MEMORY
, sizeof(LARGE_INTEGER
), TAG_GINI
);
63 gpLockShortDelay
->HighPart
= -1;
67 EngDeleteSemaphore(ghsemHmgr
);
71 EngFreeMem(gpentDdHmgr
);
82 * The function DdHmgDestroy is used internally in dxg.sys
83 * It destroys all DX kernel objects
86 * Always returns true, as a failure here would result in a BSOD.
89 * Only used internally in dxg.sys
98 gpentDdHmgrLast
= NULL
;
102 EngFreeMem(gpentDdHmgr
);
108 EngDeleteSemaphore(ghsemHmgr
);
119 * The function DdHmgLock is used internally in dxg.sys
120 * It locks a DX kernel object
122 * @param HANDLE DdHandle
123 * The handle we want locked
125 * @param UCHAR ObjectType
126 * The type of the object we expected the handle to contain
128 * value 1 is for EDD_DIRECTDRAW_LOCAL
129 * value 2 is for EDD_SURFACE
131 * value 4 is for EDD_VIDEOPORT
132 * value 5 is for EDD_MOTIONCOMP
134 * @param BOOLEAN LockOwned
135 * If it needs to call EngAcquireSemaphore or not
138 * Returns an EDD_* object, or NULL if it fails
141 * Only used internally in dxg.sys
145 DdHmgLock(HANDLE DdHandle
, UCHAR ObjectType
, BOOLEAN LockOwned
)
148 DWORD Index
= (DWORD
)(DWORD_PTR
)DdHandle
& 0x1FFFFF;
149 PDD_ENTRY pEntry
= NULL
;
154 EngAcquireSemaphore(ghsemHmgr
);
157 if ( Index
< gcMaxDdHmgr
)
159 pEntry
= (PDD_ENTRY
)((PBYTE
)gpentDdHmgr
+ (sizeof(DD_ENTRY
) * Index
));
160 if ( VerifyObjectOwner(pEntry
) )
163 if ( (pEntry->Objt == ObjectType ) &&
164 (pEntry->FullUnique == (((DWORD)DdHandle >> 21) & 0x7FF) ) &&
165 (pEntry->pobj->cExclusiveLock == 0) &&
166 (pEntry->pobj->Tid == PsGetCurrentThread()))
168 InterlockedIncrement(&pEntry->pobj->cExclusiveLock);
169 pEntry->pobj->Tid = PsGetCurrentThread();
170 Object = pEntry->pobj;
178 EngDeleteSemaphore(ghsemHmgr
);