4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS kernel
6 * PURPOSE: Native driver for dxg implementation
7 * FILE: drivers/directx/dxg/ddhmg.c
8 * PROGRAMER: Magnus olsen (magnus@greatlord.com)
10 * 30/12-2007 Magnus Olsen
15 /* The DdHmgr manger stuff */
16 ULONG gcSizeDdHmgr
= 64 * sizeof(DD_ENTRY
);
17 PDD_ENTRY gpentDdHmgr
= NULL
;
19 ULONG gcMaxDdHmgr
= 0;
20 PDD_ENTRY gpentDdHmgrLast
= NULL
;
22 HANDLE ghFreeDdHmgr
= 0;
23 HSEMAPHORE ghsemHmgr
= NULL
;
27 VerifyObjectOwner(PDD_ENTRY pEntry
)
29 DWORD Pid
= (DWORD
) PsGetCurrentProcessId() & 0xFFFFFFFC;
30 DWORD check
= pEntry
->ObjectOwner
.ulObj
& 0xFFFFFFFE;
31 return ( (check
== Pid
) || (!check
));
38 * The function DdHmgCreate is internal use in dxg.sys
39 * It Create all DX kernel object that is need it, for create DX object.
42 * return FALSE for fail, return TRUE for sussess create DX object
45 * Only use internal in dxg.sys
51 gpentDdHmgr
= EngAllocMem(FL_ZERO_MEMORY
, gcSizeDdHmgr
, TAG_THDD
);
57 ghsemHmgr
= EngCreateSemaphore();
61 gpLockShortDelay
= EngAllocMem(FL_ZERO_MEMORY
| FL_NONPAGED_MEMORY
, sizeof(LARGE_INTEGER
), TAG_GINI
);
65 gpLockShortDelay
->HighPart
= -1;
69 EngDeleteSemaphore(ghsemHmgr
);
73 EngFreeMem(gpentDdHmgr
);
84 * The function DdHmgDestroy is internal use in dxg.sys
85 * It destore all DX kernel object
88 * return FALSE for fail or noting to destore, return TRUE for sussess destore all dx object
91 * Only use internal in dxg.sys
100 gpentDdHmgrLast
= NULL
;
104 EngFreeMem(gpentDdHmgr
);
110 EngDeleteSemaphore(ghsemHmgr
);
121 * The function DdHmgLock is internal use in dxg.sys
122 * it lock a Dx kernel object
124 * @param HANDLE DdHandle
125 * The handle we want lock
127 * @param UCHAR ObjectType
128 * The type of the object we expected the handle contain
129 * value 0 is for getting ?
130 * value 1 is for getting EDD_DIRECTDRAW_LOCAL
131 * value 2 is for getting EDD_SURFACE
132 * value 3 is for getting ?
133 * value 4 is for getting EDD_VIDEOPORT
134 * value 5 is for getting EDD_MOTIONCOMP
136 * @param BOOLEAN LockOwned
137 * if it need be EngAcquireSemaphore or not
140 * return a EDD_* object, or NULL depnes if it success or not.
143 * Only use internal in dxg.sys
147 DdHmgLock( HANDLE DdHandle
, UCHAR ObjectType
, BOOLEAN LockOwned
)
150 DWORD Index
= (DWORD
)DdHandle
& 0x1FFFFF;
151 PDD_ENTRY pEntry
= NULL
;
156 EngAcquireSemaphore(ghsemHmgr
);
159 if ( Index
< gcMaxDdHmgr
)
161 pEntry
= (PDD_ENTRY
)((PBYTE
)gpentDdHmgr
+ (sizeof(DD_ENTRY
) * Index
));
162 if ( VerifyObjectOwner(pEntry
) )
164 if ( (pEntry
->Objt
== ObjectType
) &&
165 (pEntry
->FullUnique
== (((DWORD
)DdHandle
>> 21) & 0x7FF) ) &&
166 (pEntry
->pobj
->cExclusiveLock
== 0) &&
167 (pEntry
->pobj
->Tid
== PsGetCurrentThread()))
169 InterlockedIncrement(&pEntry
->pobj
->cExclusiveLock
);
170 pEntry
->pobj
->Tid
= PsGetCurrentThread();
171 Object
= pEntry
->pobj
;
178 EngDeleteSemaphore(ghsemHmgr
);