2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Native driver for dxg implementation
5 * FILE: win32ss/reactx/dxg/eng.c
6 * PROGRAMER: Magnus olsen (magnus@greatlord.com)
8 * 30/12-2007 Magnus Olsen
14 * @name intDdGetDriverInfo
17 * The function intDdGetDriverInfo is used internally in dxg.sys
18 * It retrieves driver information structures
20 * @param PEDD_DIRECTDRAW_GLOBAL peDdGl
21 * DirectDraw global structure
24 * GUID of InfoData to read
26 * @param PVOID callbackStruct
27 * Callback structure pointer
29 * @param ULONG callbackSize
30 * Size of allocated callback structure
32 * @param ULONG *returnSize
33 * Desired structure size returned by driver
36 * Returns true on successful execution, false when error.
39 * Only used internally in dxg.sys
41 BOOL
intDdGetDriverInfo(PEDD_DIRECTDRAW_GLOBAL peDdGl
, GUID guid
, PVOID callbackStruct
, ULONG callbackSize
, ULONG
*returnSize
)
43 DD_GETDRIVERINFODATA ddGetDriverInfoData
;
45 if (peDdGl
->ddHalInfo
.dwFlags
& DDHALINFO_GETDRIVERINFOSET
&& peDdGl
->ddHalInfo
.GetDriverInfo
)
47 memset(&ddGetDriverInfoData
, 0, sizeof(DD_GETDRIVERINFODATA
));
48 ddGetDriverInfoData
.dwSize
= sizeof(DD_GETDRIVERINFODATA
);
49 ddGetDriverInfoData
.dhpdev
= peDdGl
->dhpdev
;
50 memcpy(&ddGetDriverInfoData
.guidInfo
, &guid
, sizeof(GUID
));
51 ddGetDriverInfoData
.dwExpectedSize
= callbackSize
;
52 ddGetDriverInfoData
.lpvData
= callbackStruct
;
53 ddGetDriverInfoData
.ddRVal
= DDERR_CURRENTLYNOTAVAIL
;
54 if (peDdGl
->ddHalInfo
.GetDriverInfo(&ddGetDriverInfoData
) && !ddGetDriverInfoData
.ddRVal
)
57 *returnSize
= ddGetDriverInfoData
.dwActualSize
;
63 /* cleanup on error */
64 memset(callbackStruct
, 0, callbackSize
);
73 intDdCreateDirectDrawLocal(HDEV hDev
)
75 PEDD_DIRECTDRAW_GLOBAL peDdGl
= NULL
;
76 PEDD_DIRECTDRAW_LOCAL peDdL
= NULL
;
79 peDdGl
= (PEDD_DIRECTDRAW_GLOBAL
)gpEngFuncs
.DxEngGetHdevData(hDev
, DxEGShDevData_eddg
);
81 AllocRet
= DdHmgAlloc(sizeof(EDD_DIRECTDRAW_LOCAL
), ObjType_DDLOCAL_TYPE
, TRUE
);
85 peDdL
= (PEDD_DIRECTDRAW_LOCAL
)AllocRet
;
87 /* initialize DIRECTDRAW_LOCAL */
88 peDdL
->peDirectDrawLocal_prev
= peDdGl
->peDirectDrawLocalList
;
89 peDdL
->UniqueProcess
= PsGetCurrentThreadProcessId();
90 peDdL
->Process
= PsGetCurrentProcess();
92 // link DirectDrawGlobal and DirectDrawLocal
93 peDdGl
->peDirectDrawLocalList
= peDdL
;
94 peDdL
->peDirectDrawGlobal
= peDdGl
;
95 peDdL
->peDirectDrawGlobal2
= peDdGl
;
97 gpEngFuncs
.DxEngReferenceHdev(hDev
);
99 InterlockedExchangeAdd((LONG
*)&peDdL
->pobj
.cExclusiveLock
, 0xFFFFFFFF);
101 return peDdL
->pobj
.hHmgr
;
107 DxDdLockDirectDrawSurface(HANDLE hDdSurface
)
109 PEDD_SURFACE pEDDSurface
= NULL
;
110 PDD_SURFACE_LOCAL pSurfacelcl
= NULL
;
112 pEDDSurface
= DdHmgLock(hDdSurface
, ObjType_DDSURFACE_TYPE
, FALSE
);
113 if (pEDDSurface
!= NULL
)
115 pSurfacelcl
= &pEDDSurface
->ddsSurfaceLocal
;
123 DxDdUnlockDirectDrawSurface(PDD_SURFACE_LOCAL pSurface
)
126 //PEDD_SURFACE pEDDSurface = NULL;
130 // pEDDSurface = (PEDD_SURFACE)( ((PBYTE)pSurface) - sizeof(DD_BASEOBJECT));
131 // InterlockedDecrement(&pEDDSurface->pobj.cExclusiveLock);
139 * @name intDdGetAllDriverInfo
142 * The function intDdGetAllDriverInfo is used internally in dxg.sys
143 * It retrieves all possible driver information structures
145 * @param PEDD_DIRECTDRAW_GLOBAL peDdGl
146 * Pointer to destination DirectDrawGlobal structure
149 * Only used internally in dxg.sys
150 * Missing some callbacks (VideoPort, DxApi, AGP)
152 VOID
intDdGetAllDriverInfo(PEDD_DIRECTDRAW_GLOBAL peDdGl
)
154 if (peDdGl
->ddHalInfo
.GetDriverInfo
&& peDdGl
->ddHalInfo
.dwFlags
& DDHALINFO_GETDRIVERINFOSET
)
156 intDdGetDriverInfo(peDdGl
, GUID_KernelCaps
, &peDdGl
->ddKernelCaps
, sizeof(peDdGl
->ddKernelCaps
), 0);
157 intDdGetDriverInfo(peDdGl
, GUID_KernelCallbacks
, &peDdGl
->ddKernelCallbacks
, sizeof(peDdGl
->ddKernelCallbacks
), 0);
159 if (intDdGetDriverInfo(peDdGl
, GUID_D3DCallbacks3
, &peDdGl
->d3dNtHalCallbacks3
, sizeof(peDdGl
->d3dNtHalCallbacks3
), 0))
160 peDdGl
->dwCallbackFlags
|= EDDDGBL_D3DCALLBACKS3
;
162 if (intDdGetDriverInfo(peDdGl
, GUID_ColorControlCallbacks
, &peDdGl
->ddColorControlCallbacks
, sizeof(peDdGl
->ddColorControlCallbacks
), 0))
163 peDdGl
->dwCallbackFlags
|= EDDDGBL_COLORCONTROLCALLBACKS
;
165 if (intDdGetDriverInfo(peDdGl
, GUID_MiscellaneousCallbacks
, &peDdGl
->ddMiscellanousCallbacks
, sizeof(peDdGl
->ddMiscellanousCallbacks
), 0))
166 peDdGl
->dwCallbackFlags
|= EDDDGBL_MISCCALLBACKS
;
168 if (intDdGetDriverInfo(peDdGl
, GUID_Miscellaneous2Callbacks
, &peDdGl
->ddMiscellanous2Callbacks
, sizeof(peDdGl
->ddMiscellanous2Callbacks
), 0))
169 peDdGl
->dwCallbackFlags
|= EDDDGBL_MISC2CALLBACKS
;
171 if (intDdGetDriverInfo(peDdGl
, GUID_NTCallbacks
, &peDdGl
->ddNtCallbacks
, sizeof(peDdGl
->ddNtCallbacks
), 0) )
172 peDdGl
->dwCallbackFlags
|= EDDDGBL_NTCALLBACKS
;
174 if (intDdGetDriverInfo(peDdGl
, GUID_DDMoreCaps
, &peDdGl
->ddMoreCaps
, sizeof(peDdGl
->ddMoreCaps
), 0) )
175 peDdGl
->dwCallbackFlags
|= EDDDGBL_DDMORECAPS
;
177 if (intDdGetDriverInfo(peDdGl
, GUID_NTPrivateDriverCaps
, &peDdGl
->ddNtPrivateDriverCaps
, sizeof(peDdGl
->ddNtPrivateDriverCaps
), 0) )
178 peDdGl
->dwCallbackFlags
|= EDDDGBL_PRIVATEDRIVERCAPS
;
180 if (intDdGetDriverInfo(peDdGl
, GUID_MotionCompCallbacks
, &peDdGl
->ddMotionCompCallbacks
, sizeof(peDdGl
->ddMotionCompCallbacks
), 0) )
181 peDdGl
->dwCallbackFlags
|= EDDDGBL_MOTIONCOMPCALLBACKS
;
187 * @name intDdEnableDriver
190 * The function intDdEnableDriver is used internally in dxg.sys
191 * Fills in all EDD_DIRECTDRAW_GLOBAL structures and enables DirectDraw acceleration when possible
193 * @param PEDD_DIRECTDRAW_GLOBAL peDdGl
194 * Pointer to destination DirectDrawGlobal structure
197 * Only used internally in dxg.sys
199 VOID
intDdEnableDriver(PEDD_DIRECTDRAW_GLOBAL peDdGl
)
201 PDRIVER_FUNCTIONS DriverFunctions
;
202 LPD3DNTHAL_GLOBALDRIVERDATA GlobalDriverData
;
203 LPD3DNTHAL_CALLBACKS HalCallbacks
;
204 PDD_D3DBUFCALLBACKS D3DBufCallbacks
;
207 gpEngFuncs
.DxEngLockHdev(peDdGl
->hDev
);
208 DriverFunctions
= (PDRIVER_FUNCTIONS
)gpEngFuncs
.DxEngGetHdevData(peDdGl
->hDev
, DxEGShDevData_DrvFuncs
);
210 // check if driver has DirectDraw functions
211 if ((!DriverFunctions
->GetDirectDrawInfo
)||(!DriverFunctions
->EnableDirectDraw
)||(!DriverFunctions
->DisableDirectDraw
))
215 // reset acceleration flag
216 peDdGl
->fl
= peDdGl
->fl
& 0xFFFFFFFE;
218 // ask for structure sizes
219 if ((peDdGl
->dhpdev
)&&(DriverFunctions
->GetDirectDrawInfo(peDdGl
->dhpdev
, &peDdGl
->ddHalInfo
, &peDdGl
->dwNumHeaps
, NULL
, &peDdGl
->dwNumFourCC
, NULL
)))
221 // allocate memory for DX data
222 if (peDdGl
->dwNumHeaps
)
223 peDdGl
->pvmList
= EngAllocMem(FL_ZERO_MEMORY
, peDdGl
->dwNumHeaps
*sizeof(VIDEOMEMORY
), TAG_GDDV
);
224 if (peDdGl
->dwNumFourCC
)
225 peDdGl
->pdwFourCC
= EngAllocMem(FL_ZERO_MEMORY
, peDdGl
->dwNumFourCC
* 4, TAG_GDDF
);
227 // get data from driver
228 if (!DriverFunctions
->GetDirectDrawInfo(peDdGl
->dhpdev
, &peDdGl
->ddHalInfo
, &peDdGl
->dwNumHeaps
, peDdGl
->pvmList
, &peDdGl
->dwNumFourCC
, peDdGl
->pdwFourCC
))
230 // failed - cleanup and exit
232 EngFreeMem(peDdGl
->pvmList
);
233 if (peDdGl
->pdwFourCC
)
234 EngFreeMem(peDdGl
->pdwFourCC
);
235 gpEngFuncs
.DxEngUnlockHdev(peDdGl
->hDev
);
239 // check if we can enable DirectDraw acceleration
240 if ((peDdGl
->ddHalInfo
.vmiData
.pvPrimary
) &&
241 (DriverFunctions
->EnableDirectDraw(peDdGl
->dhpdev
, &peDdGl
->ddCallbacks
, &peDdGl
->ddSurfaceCallbacks
, &peDdGl
->ddPaletteCallbacks
))&&
242 !(gpEngFuncs
.DxEngGetHdevData(peDdGl
->hDev
, DxEGShDevData_dd_flags
) & CapOver_DisableD3DAccel
)&&
243 (peDdGl
->ddHalInfo
.dwSize
== sizeof(DD_HALINFO
)))
245 GlobalDriverData
= peDdGl
->ddHalInfo
.lpD3DGlobalDriverData
;
246 HalCallbacks
= peDdGl
->ddHalInfo
.lpD3DHALCallbacks
;
247 D3DBufCallbacks
= peDdGl
->ddHalInfo
.lpD3DHALCallbacks
;
249 if (GlobalDriverData
&& GlobalDriverData
->dwSize
== sizeof(D3DNTHAL_GLOBALDRIVERDATA
))
250 memcpy(&peDdGl
->d3dNtGlobalDriverData
, GlobalDriverData
, sizeof(D3DNTHAL_GLOBALDRIVERDATA
));
252 if (HalCallbacks
&& HalCallbacks
->dwSize
== sizeof(D3DNTHAL_CALLBACKS
))
253 memcpy(&peDdGl
->d3dNtHalCallbacks
, HalCallbacks
, sizeof(D3DNTHAL_CALLBACKS
));
255 if (D3DBufCallbacks
&& D3DBufCallbacks
->dwSize
== sizeof(DD_D3DBUFCALLBACKS
))
256 memcpy(&peDdGl
->d3dBufCallbacks
, D3DBufCallbacks
, sizeof(DD_D3DBUFCALLBACKS
));
258 intDdGetAllDriverInfo(peDdGl
);
260 // enable DirectDraw acceleration
265 // failed - cleanup and exit
267 EngFreeMem(peDdGl
->pvmList
);
268 if (peDdGl
->pdwFourCC
)
269 EngFreeMem(peDdGl
->pdwFourCC
);
273 gpEngFuncs
.DxEngUnlockHdev(peDdGl
->hDev
);
277 * @name DxDdEnableDirectDraw
280 * Function enables DirectDraw
282 * @param PEDD_DIRECTDRAW_GLOBAL peDdGl
283 * Pointer to destination DirectDrawGlobal structure
287 DxDdEnableDirectDraw(HANDLE hDev
, BOOL arg2
/*What for?*/)
289 PEDD_DIRECTDRAW_GLOBAL peDdGl
= NULL
;
291 if (gpEngFuncs
.DxEngGetHdevData(hDev
, DxEGShDevData_display
))
293 peDdGl
= (PEDD_DIRECTDRAW_GLOBAL
)gpEngFuncs
.DxEngGetHdevData(hDev
, DxEGShDevData_eddg
);
295 peDdGl
->bSuspended
= FALSE
;
296 peDdGl
->dhpdev
= (PVOID
)gpEngFuncs
.DxEngGetHdevData(hDev
, DxEGShDevData_dhpdev
);
297 intDdEnableDriver(peDdGl
);
305 * @name DxDdCreateDirectDrawObject
308 * Function creates new DirectDraw object
311 * Device context handle
314 * Newly created DirectDraw object handle.
317 * Missing all AGP stuff
321 DxDdCreateDirectDrawObject(
328 pDC
= gpEngFuncs
.DxEngLockDC(hDC
);
332 // get driver hDev from DC
333 hDev
= (HDEV
)gpEngFuncs
.DxEngGetDCState(hDC
, 3);
335 gpEngFuncs
.DxEngUnlockDC(pDC
);
339 // is this primary display?
340 if (!gpEngFuncs
.DxEngGetHdevData(hDev
, DxEGShDevData_display
))
342 gpEngFuncs
.DxEngUnlockDC(pDC
);
346 gpEngFuncs
.DxEngLockHdev(hDev
);
348 // create object only for 8BPP and more
349 if (gpEngFuncs
.DxEngGetHdevData(hDev
, DxEGShDevData_DitherFmt
) >= BMF_8BPP
)
350 retVal
= (DWORD
)intDdCreateDirectDrawLocal(hDev
);
352 gpEngFuncs
.DxEngUnlockHdev(hDev
);
353 gpEngFuncs
.DxEngUnlockDC(pDC
);