2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Native DirectDraw implementation
5 * FILE: subsys/win32k/ntddraw/d3d.c
6 * PROGRAMER: Magnus olsen (magnus@greatlord.com)
8 * 19/1-2006 Magnus Olsen
12 * NtGdiDdLock and NtGdiDdLockD3D ultimately call the same function in dxg.sys
13 * NtGdiDdUnlock and NtGdiDdUnlockD3D ultimately call the same function in dxg.sys
21 * @name NtGdiDdCanCreateD3DBuffer
24 * The function NtGdiDdCanCreateD3DBuffer checks if you can create a
25 * surface for DirectX. it redirects to dxg.sys in windows XP/2003,
26 * dxkrnl.sys in vista and is fully implemented in win32k.sys in windows 2000 and below
28 * @param HANDLE hDirectDraw
29 * The handle we got from NtGdiDdCreateDirectDrawObject
31 * @param PDD_CANCREATESURFACEDATA puCanCreateSurfaceData
32 * This contains information to check if the driver can create the buffers,
33 * surfaces, textures and vertexes, and how many of each the driver can create.
37 * Depending on if the driver supports this function or not, DDHAL_DRIVER_HANDLED
38 * or DDHAL_DRIVER_NOTHANDLED is returned.
39 * To check if the function has been successful, do a full check.
40 * A full check is done by checking if the return value is DDHAL_DRIVER_HANDLED
41 * and puCanCreateSurfaceData->ddRVal is set to DD_OK.
44 * dxg.sys NtGdiDdCanCreateD3DBuffer and NtGdiDdCanCreateSurface calls are redirected to dxg.sys.
45 * Inside the dxg.sys they are redirected to the same function. Examine the memory addresses on the driver list functions
46 * table and you will see they are pointed to the same memory address.
48 * Before calling this function please set the puCanCreateSurfaceData->ddRVal to an error value such as DDERR_NOTUSPORTED,
49 * for the ddRVal will otherwise be unchanged even if an error occurs inside the driver.
50 * puCanCreateSurfaceData->lpDD is a pointer to DDRAWI_DIRECTDRAW_GBL, not PDD_DIRECTDRAW_GLOBAL as MSDN claims.
51 * puCanCreateSurfaceData->lpDD->hDD also needs be filled in with the handle we got from NtGdiDdCreateDirectDrawObject.
52 * puCreateSurfaceData->CanCreateSurface is a pointer to the real functions in the HAL or HEL, that you need fill in.
53 * Do not forget PDD_CANCREATESURFACEDATA is typecast of LPDDHAL_CANCREATESURFACEDATA and thuse two struct are different size,
54 * the correct struct is LPDDHAL_CANCREATESURFACEDATA.
60 NtGdiDdCanCreateD3DBuffer(HANDLE hDirectDraw
,
61 PDD_CANCREATESURFACEDATA puCanCreateSurfaceData
)
63 PGD_DDCANCREATED3DBUFFER pfnDdCanCreateD3DBuffer
= (PGD_DDCANCREATED3DBUFFER
)gpDxFuncs
[DXG_INDEX_DxDdCanCreateD3DBuffer
].pfn
;
65 if (pfnDdCanCreateD3DBuffer
== NULL
)
67 DPRINT1("Warring no pfnDdCanCreateD3DBuffer");
68 return DDHAL_DRIVER_NOTHANDLED
;
71 DPRINT1("Calling on dxg.sys DdCanCreateD3DBuffer");
72 return pfnDdCanCreateD3DBuffer(hDirectDraw
,puCanCreateSurfaceData
);
76 * @name NtGdiD3dContextCreate
79 * The Function NtGdiD3dContextCreate checks if you can create a
80 * context for Directx. It redirects to dxg.sys in windows XP/2003,
81 * dxkrnl.sys in vista and is fully implemented in win32k.sys in windows 2000 and below
83 * @param HANDLE hDirectDrawLocal
84 * The handle we got from NtGdiDdCreateDirectDrawObject
86 * @param HANDLE hSurfColor
87 * Handle to DD_SURFACE_LOCAL to be used for the rendering target
89 * @param HANDLE hSurfZ
90 * Handle to a DD_SURFACE_LOCAL. It is the Z deep buffer. According MSDN if it is set to NULL nothing should happen.
92 * @param LPD3DNTHAL_CONTEXTCREATEDATA pdcci
93 * The buffer to create the context data
96 * DDHAL_DRIVER_HANDLED or DDHAL_DRIVER_NOTHANDLED if the driver supports this function.
97 * A full check is done by checking if the return value is DDHAL_DRIVER_HANDLED
98 * and pdcci->ddRVal is set to DD_OK.
102 * dxg.sys NtGdiD3dContextCreate calls are redirected to the same function in the dxg.sys. As such they all work the same way.
104 * Before calling this function please set the pdcci->ddRVal to an error value such as DDERR_NOTSUPORTED,
105 * for the ddRVal will otherwise be unchanged even if an error occurs inside the driver.
107 * pdcci->lpDDLcl is a pointer to DDRAWI_DIRECTDRAW_LCL, not DD_DIRECTDRAW_LOCAL as MSDN claims.
108 * pdcci->lpDDSLcl is a pointer to DDRAWI_DDRAWSURFACE_LCL, not DD_DDDRAWSURFACE_LOCAL as MSDN claims.
109 * pdcci->lpDDSZLcl is a pointer to DDRAWI_DDRAWSURFACE_LCL, not DD_DDRAWSURFACE_LOCAL as MSDN claims.
110 * pdcci->dwhContext also needs be filled in with the handle we receive from NtGdiDdCreateDirectDrawObject.
111 * pdcci->dwPID the processid it belong to, that you need to fill in.
112 * Do not forget LPD3DNTHAL_CONTEXTCREATEDATA is typecast of LPD3DHAL_CONTEXTCREATEDATA and thuse two struct are different size,
113 * the correct struct is LPD3DHAL_CONTEXTCREATEDATA.
117 NtGdiD3dContextCreate(HANDLE hDirectDrawLocal
,
120 LPD3DNTHAL_CONTEXTCREATEDATA pdcci
)
122 PGD_D3DCONTEXTCREATE pfnD3dContextCreate
= (PGD_D3DCONTEXTCREATE
)gpDxFuncs
[DXG_INDEX_DxD3dContextCreate
].pfn
;
124 if (pfnD3dContextCreate
== NULL
)
126 DPRINT1("Warning: no pfnD3dContextCreate");
130 DPRINT1("Calling dxg.sys D3dContextCreate");
131 return pfnD3dContextCreate(hDirectDrawLocal
, hSurfColor
, hSurfZ
, pdcci
);
135 * @name NtGdiD3dContextDestroy
138 * The Function NtGdiD3dContextDestroy destorys the context data we got from NtGdiD3dContextCreate
139 * It redirects to dxg.sys in windows XP/2003, dxkrnl.sys in vista and is fully implemented
140 * in win32k.sys in windows 2000 and below
142 * @param LPD3DNTHAL_CONTEXTDESTROYDATA pContextDestroyData
143 * The context data we want to destroy
146 * dxg.sys NtGdiD3dContextDestroy calls are redirected to the same functions in the dxg.sys. As such they all work the same way.
148 * Before calling this function please set the pContextDestroyData->ddRVal to an error value such DDERR_NOTUSPORTED,
149 * for the ddRVal will otherwise be unchanged even if an error occurs inside the driver.
150 * pContextDestroyData->dwhContext also needs to be filled in with the handle we got from NtGdiDdCreateDirectDrawObject
155 NtGdiD3dContextDestroy(LPD3DNTHAL_CONTEXTDESTROYDATA pContextDestroyData
)
157 PGD_D3DCONTEXTDESTROY pfnD3dContextDestroy
= (PGD_D3DCONTEXTDESTROY
)gpDxFuncs
[DXG_INDEX_DxD3dContextDestroy
].pfn
;
159 if ( pfnD3dContextDestroy
== NULL
)
161 DPRINT1("Warning: no pfnD3dContextDestroy");
162 return DDHAL_DRIVER_NOTHANDLED
;
165 DPRINT1("Calling dxg.sys D3dContextDestroy");
166 return pfnD3dContextDestroy(pContextDestroyData
);
170 * @name NtGdiD3dContextDestroyAll
173 * The Function NtGdiD3dContextDestroyAll destroys all the context data in a process
174 * The data having been allocated with NtGdiD3dContextCreate
175 * It redirects to dxg.sys in windows XP/2003, dxkrnl.sys in vista and is fully implemented
176 * in win32k.sys in windows 2000 and below
178 * @param LPD3DNTHAL_CONTEXTDESTROYALLDATA pdcad
179 * The context data we want to destory
182 * dxg.sys NtGdiD3dContextDestroy calls are redirected to the same function in the dxg.sys. As such they all work the same way.
184 * Before calling this function please set the pdcad->ddRVal to an error value such as DDERR_NOTUSPORTED,
185 * for the ddRVal will otherwise be unchanged even if an error occurs inside the driver.
186 * pdcad->dwPID also needs to be filled in with the ID of the process that needs its context data destroyed.
188 * Warning: MSDN is wrong about this function. It claims the function queries free memory and does not accept
189 * any parameters. Last time MSDN checked: 19/10-2007
193 NtGdiD3dContextDestroyAll(LPD3DNTHAL_CONTEXTDESTROYALLDATA pdcad
)
195 PGD_D3DCONTEXTDESTROYALL pfnD3dContextDestroyAll
= (PGD_D3DCONTEXTDESTROYALL
)gpDxFuncs
[DXG_INDEX_DxD3dContextDestroyAll
].pfn
;
197 if (pfnD3dContextDestroyAll
== NULL
)
199 DPRINT1("Warning: no pfnD3dContextDestroyAll");
200 return DDHAL_DRIVER_NOTHANDLED
;
203 DPRINT1("Calling dxg.sys D3dContextDestroyAll");
204 return pfnD3dContextDestroyAll(pdcad
);
208 * @name NtGdiDdCreateD3DBuffer
211 * The function NtGdiDdCreateD3DBuffer creates a surface for DirectX.
212 * It redirects to dxg.sys in windows XP/2003, dxkrnl.sys in vista and is fully implemented
213 * in win32k.sys in windows 2000 and below
215 * @param HANDLE hDirectDraw
216 * The handle we got from NtGdiDdCreateDirectDrawObject
218 * @param HANDLE *hSurface
221 * @param DDSURFACEDESC puSurfaceDescription
222 * Surface description: what kind of surface it should be. Examples: RGB, compress, deep, and etc
223 * See DDSURFACEDESC for more information
225 * @param DD_SURFACE_GLOBAL *puSurfaceGlobalData
228 * @param DD_SURFACE_LOCAL *puSurfaceLocalData
231 * @param DD_SURFACE_MORE *puSurfaceMoreData
234 * @param PDD_CREATESURFACEDATA puCreateSurfaceData
237 * @param HANDLE *puhSurface
241 * Depending on if the driver supports this function or not, DDHAL_DRIVER_HANDLED
242 * or DDHAL_DRIVER_NOTHANDLED is returned.
243 * To check if the function was successful, do a full check.
244 * A full check is done by checking if the return value is DDHAL_DRIVER_HANDLED
245 * and puCanCreateSurfaceData->ddRVal is set to DD_OK.
248 * dxg.sys NtGdiDdCreateD3DBuffer and NtGdiDdCreateSurface calls are redirected to dxg.sys.
249 * Inside the dxg.sys they are redirected to the same function. Examine the memory addresses on the driver list functions
250 * table and you will see they are pointed to the same memory address.
252 * Before calling this function please set the puCreateSurfaceData->ddRVal to an error value such as DDERR_NOTUSPORTED,
253 * for the ddRVal will otherwise be unchanged even if an error occurs inside the driver.
254 * puCreateSurfaceData->lpDD is a pointer to DDRAWI_DIRECTDRAW_GBL. MSDN claims it is PDD_DIRECTDRAW_GLOBAL but it is not.
255 * puCreateSurfaceData->lpDD->hDD also needs to be filled in with the handle we got from NtGdiDdCreateDirectDrawObject
256 * puCreateSurfaceData->CreateSurface is a pointer to the real functions in the HAL or HEL, that you need fill in
261 NtGdiDdCreateD3DBuffer(HANDLE hDirectDraw
,
263 DDSURFACEDESC
*puSurfaceDescription
,
264 DD_SURFACE_GLOBAL
*puSurfaceGlobalData
,
265 DD_SURFACE_LOCAL
*puSurfaceLocalData
,
266 DD_SURFACE_MORE
*puSurfaceMoreData
,
267 PDD_CREATESURFACEDATA puCreateSurfaceData
,
270 PGD_DDCREATED3DBUFFER pfnDdCreateD3DBuffer
= (PGD_DDCREATED3DBUFFER
)gpDxFuncs
[DXG_INDEX_DxDdCreateD3DBuffer
].pfn
;
272 if (pfnDdCreateD3DBuffer
== NULL
)
274 DPRINT1("Warning no pfnDdCreateD3DBuffer");
275 return DDHAL_DRIVER_NOTHANDLED
;
278 DPRINT1("Calling dxg.sys DdCreateD3DBuffer");
279 return pfnDdCreateD3DBuffer(hDirectDraw
, hSurface
,
280 puSurfaceDescription
, puSurfaceGlobalData
,
281 puSurfaceLocalData
, puSurfaceMoreData
,
282 puCreateSurfaceData
, puhSurface
);
285 /************************************************************************/
286 /* NtGdiDdDestroyD3DBuffer */
287 /************************************************************************/
290 NtGdiDdDestroyD3DBuffer(HANDLE hSurface
)
292 PGD_DXDDDESTROYD3DBUFFER pfnDdDestroyD3DBuffer
= (PGD_DXDDDESTROYD3DBUFFER
)gpDxFuncs
[DXG_INDEX_DxDdDestroyD3DBuffer
].pfn
;
294 if (pfnDdDestroyD3DBuffer
== NULL
)
296 DPRINT1("Warning no pfnDdDestroyD3DBuffer");
297 return DDHAL_DRIVER_NOTHANDLED
;
300 DPRINT1("Calling dxg.sys pfnDdDestroyD3DBuffer");
301 return pfnDdDestroyD3DBuffer(hSurface
);
304 /************************************************************************/
305 /* NtGdiD3dDrawPrimitives2 */
306 /************************************************************************/
309 NtGdiD3dDrawPrimitives2(HANDLE hCmdBuf
,
311 LPD3DNTHAL_DRAWPRIMITIVES2DATA pded
,
312 FLATPTR
*pfpVidMemCmd
,
314 FLATPTR
*pfpVidMemVtx
,
317 PGD_D3DDRAWPRIMITIVES2 pfnD3dDrawPrimitives2
= (PGD_D3DDRAWPRIMITIVES2
)gpDxFuncs
[DXG_INDEX_DxD3dDrawPrimitives2
].pfn
;
319 if (pfnD3dDrawPrimitives2
== NULL
)
321 DPRINT1("Warning: no pfnD3dDrawPrimitives2");
322 return DDHAL_DRIVER_NOTHANDLED
;
325 DPRINT1("Calling dxg.sys D3dDrawPrimitives2");
326 return pfnD3dDrawPrimitives2(hCmdBuf
,hVBuf
,pded
,pfpVidMemCmd
,pdwSizeCmd
,pfpVidMemVtx
,pdwSizeVtx
);
330 /************************************************************************/
331 /* NtGdiD3dValidateTextureStageState */
332 /************************************************************************/
335 NtGdiDdLockD3D(HANDLE hSurface
,
336 PDD_LOCKDATA puLockData
)
338 PGD_DXDDLOCKD3D pfnDdLockD3D
= (PGD_DXDDLOCKD3D
)gpDxFuncs
[DXG_INDEX_DxDdLockD3D
].pfn
;
340 if (pfnDdLockD3D
== NULL
)
342 DPRINT1("Warning: no pfnDdLockD3D");
343 return DDHAL_DRIVER_NOTHANDLED
;
346 DPRINT1("Calling dxg.sys pfnDdLockD3D");
347 return pfnDdLockD3D(hSurface
, puLockData
);
350 /************************************************************************/
351 /* NtGdiD3dValidateTextureStageState */
352 /************************************************************************/
355 NtGdiD3dValidateTextureStageState(LPD3DNTHAL_VALIDATETEXTURESTAGESTATEDATA pData
)
357 PGD_D3DVALIDATETEXTURESTAGESTATE pfnD3dValidateTextureStageState
= (PGD_D3DVALIDATETEXTURESTAGESTATE
)gpDxFuncs
[DXG_INDEX_DxD3dValidateTextureStageState
].pfn
;
359 if (pfnD3dValidateTextureStageState
== NULL
)
361 DPRINT1("Warning: no pfnD3dValidateTextureStageState");
362 return DDHAL_DRIVER_NOTHANDLED
;
365 DPRINT1("Calling dxg.sys D3dValidateTextureStageState");
366 return pfnD3dValidateTextureStageState(pData
);
369 /************************************************************************/
370 /* NtGdiDdUnlockD3D */
371 /************************************************************************/
374 NtGdiDdUnlockD3D(HANDLE hSurface
,
375 PDD_UNLOCKDATA puUnlockData
)
377 PGD_DXDDUNLOCKD3D pfnDdUnlockD3D
= (PGD_DXDDUNLOCKD3D
)gpDxFuncs
[DXG_INDEX_DxDdUnlockD3D
].pfn
;
379 if (pfnDdUnlockD3D
== NULL
)
381 DPRINT1("Warning: no pfnDdUnlockD3D");
382 return DDHAL_DRIVER_NOTHANDLED
;
385 DPRINT1("Calling dxg.sys pfnDdUnlockD3D");
386 return pfnDdUnlockD3D(hSurface
, puUnlockData
);