ReactOS  0.4.14-dev-1115-gebeeb9d
d3d.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * PURPOSE: Native DirectDraw implementation
5  * FILE: win32ss/reactx/ntddraw/d3d.c
6  * PROGRAMER: Magnus olsen (magnus@greatlord.com)
7  * REVISION HISTORY:
8  * 19/1-2006 Magnus Olsen
9  */
10 
11 /* Comment
12  * NtGdiDdLock and NtGdiDdLockD3D ultimately call the same function in dxg.sys
13  * NtGdiDdUnlock and NtGdiDdUnlockD3D ultimately call the same function in dxg.sys
14  */
15 
16 #include <win32k.h>
17 #include <debug.h>
18 
19 
20 /*++
21 * @name NtGdiDdCanCreateD3DBuffer
22 * @implemented
23 *
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
27 *
28 * @param HANDLE hDirectDraw
29 * The handle we got from NtGdiDdCreateDirectDrawObject
30 *
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.
34 
35 *
36 * @return
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.
42 *
43 * @remarks.
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.
47 *
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.
55 *
56 *--*/
57 
58 DWORD
61  PDD_CANCREATESURFACEDATA puCanCreateSurfaceData)
62 {
64 
65  if (pfnDdCanCreateD3DBuffer == NULL)
66  {
67  DPRINT1("Warring no pfnDdCanCreateD3DBuffer");
69  }
70 
71  DPRINT1("Calling on dxg.sys DdCanCreateD3DBuffer");
72  return pfnDdCanCreateD3DBuffer(hDirectDraw,puCanCreateSurfaceData);
73 }
74 
75 /*++
76 * @name NtGdiD3dContextCreate
77 * @implemented
78 *
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
82 *
83 * @param HANDLE hDirectDrawLocal
84 * The handle we got from NtGdiDdCreateDirectDrawObject
85 *
86 * @param HANDLE hSurfColor
87 * Handle to DD_SURFACE_LOCAL to be used for the rendering target
88 *
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.
91 *
92 * @param LPD3DNTHAL_CONTEXTCREATEDATA pdcci
93 * The buffer to create the context data
94 *
95 * @return
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.
99 *
100 *
101 * @remarks.
102 * dxg.sys NtGdiD3dContextCreate calls are redirected to the same function in the dxg.sys. As such they all work the same way.
103 *
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.
106 *
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.
114 *--*/
115 BOOL
116 APIENTRY
117 NtGdiD3dContextCreate(HANDLE hDirectDrawLocal,
118  HANDLE hSurfColor,
119  HANDLE hSurfZ,
121 {
123 
124  if (pfnD3dContextCreate == NULL)
125  {
126  DPRINT1("Warning: no pfnD3dContextCreate");
127  return FALSE;
128  }
129 
130  DPRINT1("Calling dxg.sys D3dContextCreate");
131  return pfnD3dContextCreate(hDirectDrawLocal, hSurfColor, hSurfZ, pdcci);
132 }
133 
134 /*++
135 * @name NtGdiD3dContextDestroy
136 * @implemented
137 *
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
141 *
142 * @param LPD3DNTHAL_CONTEXTDESTROYDATA pContextDestroyData
143 * The context data we want to destroy
144 *
145 * @remarks.
146 * dxg.sys NtGdiD3dContextDestroy calls are redirected to the same functions in the dxg.sys. As such they all work the same way.
147 *
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
151 *
152 *--*/
153 DWORD
154 APIENTRY
156 {
158 
159  if ( pfnD3dContextDestroy == NULL)
160  {
161  DPRINT1("Warning: no pfnD3dContextDestroy");
163  }
164 
165  DPRINT1("Calling dxg.sys D3dContextDestroy");
166  return pfnD3dContextDestroy(pContextDestroyData);
167 }
168 
169 /*++
170 * @name NtGdiD3dContextDestroyAll
171 * @implemented
172 *
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
177 *
178 * @param LPD3DNTHAL_CONTEXTDESTROYALLDATA pdcad
179 * The context data we want to destory
180 *
181 * @remarks.
182 * dxg.sys NtGdiD3dContextDestroy calls are redirected to the same function in the dxg.sys. As such they all work the same way.
183 *
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.
187 *
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
190 *--*/
191 DWORD
192 APIENTRY
194 {
196 
197  if (pfnD3dContextDestroyAll == NULL)
198  {
199  DPRINT1("Warning: no pfnD3dContextDestroyAll");
201  }
202 
203  DPRINT1("Calling dxg.sys D3dContextDestroyAll");
204  return pfnD3dContextDestroyAll(pdcad);
205 }
206 
207 /*++
208 * @name NtGdiDdCreateD3DBuffer
209 * @implemented
210 *
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
214 *
215 * @param HANDLE hDirectDraw
216 * The handle we got from NtGdiDdCreateDirectDrawObject
217 *
218 * @param HANDLE *hSurface
219 * <FILLMEIN>
220 *
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
224 *
225 * @param DD_SURFACE_GLOBAL *puSurfaceGlobalData
226 * <FILLMEIN>
227 *
228 * @param DD_SURFACE_LOCAL *puSurfaceLocalData
229 * <FILLMEIN>
230 *
231 * @param DD_SURFACE_MORE *puSurfaceMoreData
232 * <FILLMEIN>
233 *
234 * @param PDD_CREATESURFACEDATA puCreateSurfaceData
235 * <FILLMEIN>
236 *
237 * @param HANDLE *puhSurface
238 * <FILLMEIN>
239 *
240 * @return
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.
246 *
247 * @remarks.
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.
251 *
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
257 *
258 *--*/
259 DWORD
260 APIENTRY
262  HANDLE *hSurface,
263  DDSURFACEDESC *puSurfaceDescription,
264  DD_SURFACE_GLOBAL *puSurfaceGlobalData,
265  DD_SURFACE_LOCAL *puSurfaceLocalData,
266  DD_SURFACE_MORE *puSurfaceMoreData,
267  PDD_CREATESURFACEDATA puCreateSurfaceData,
268  HANDLE *puhSurface)
269 {
271 
272  if (pfnDdCreateD3DBuffer == NULL)
273  {
274  DPRINT1("Warning: no pfnDdCreateD3DBuffer");
276  }
277 
278  DPRINT1("Calling dxg.sys DdCreateD3DBuffer");
279  return pfnDdCreateD3DBuffer(hDirectDraw, hSurface,
280  puSurfaceDescription, puSurfaceGlobalData,
281  puSurfaceLocalData, puSurfaceMoreData,
282  puCreateSurfaceData, puhSurface);
283 }
284 
285 /************************************************************************/
286 /* NtGdiDdDestroyD3DBuffer */
287 /************************************************************************/
288 DWORD
289 APIENTRY
291 {
293 
294  if (pfnDdDestroyD3DBuffer == NULL)
295  {
296  DPRINT1("Warning: no pfnDdDestroyD3DBuffer");
298  }
299 
300  DPRINT1("Calling dxg.sys pfnDdDestroyD3DBuffer");
301  return pfnDdDestroyD3DBuffer(hSurface);
302 }
303 
304 /************************************************************************/
305 /* NtGdiD3dDrawPrimitives2 */
306 /************************************************************************/
307 DWORD
308 APIENTRY
310  HANDLE hVBuf,
312  FLATPTR *pfpVidMemCmd,
313  DWORD *pdwSizeCmd,
314  FLATPTR *pfpVidMemVtx,
315  DWORD *pdwSizeVtx)
316 {
318 
319  if (pfnD3dDrawPrimitives2 == NULL)
320  {
321  DPRINT1("Warning: no pfnD3dDrawPrimitives2");
323  }
324 
325  DPRINT1("Calling dxg.sys D3dDrawPrimitives2");
326  return pfnD3dDrawPrimitives2(hCmdBuf,hVBuf,pded,pfpVidMemCmd,pdwSizeCmd,pfpVidMemVtx,pdwSizeVtx);
327 }
328 
329 
330 /************************************************************************/
331 /* NtGdiD3dValidateTextureStageState */
332 /************************************************************************/
333 DWORD
334 APIENTRY
336  PDD_LOCKDATA puLockData)
337 {
339 
340  if (pfnDdLockD3D == NULL)
341  {
342  DPRINT1("Warning: no pfnDdLockD3D");
344  }
345 
346  DPRINT1("Calling dxg.sys pfnDdLockD3D");
347  return pfnDdLockD3D(hSurface, puLockData);
348 }
349 
350 /************************************************************************/
351 /* NtGdiD3dValidateTextureStageState */
352 /************************************************************************/
353 DWORD
354 APIENTRY
356 {
358 
359  if (pfnD3dValidateTextureStageState == NULL)
360  {
361  DPRINT1("Warning: no pfnD3dValidateTextureStageState");
363  }
364 
365  DPRINT1("Calling dxg.sys D3dValidateTextureStageState");
366  return pfnD3dValidateTextureStageState(pData);
367 }
368 
369 /************************************************************************/
370 /* NtGdiDdUnlockD3D */
371 /************************************************************************/
372 DWORD
373 APIENTRY
375  PDD_UNLOCKDATA puUnlockData)
376 {
378 
379  if (pfnDdUnlockD3D == NULL)
380  {
381  DPRINT1("Warning: no pfnDdUnlockD3D");
383  }
384 
385  DPRINT1("Calling dxg.sys pfnDdUnlockD3D");
386  return pfnDdUnlockD3D(hSurface, puUnlockData);
387 
388 }
389 
390 
391 
392 
DWORD(APIENTRY * PGD_DDCANCREATED3DBUFFER)(HANDLE, PDD_CANCREATESURFACEDATA)
Definition: intddraw.h:39
DWORD(APIENTRY * PGD_DDCREATED3DBUFFER)(HANDLE, HANDLE *, DDSURFACEDESC *, DD_SURFACE_GLOBAL *, DD_SURFACE_LOCAL *, DD_SURFACE_MORE *, PDD_CREATESURFACEDATA, HANDLE *)
Definition: intddraw.h:44
#define DXG_INDEX_DxDdLockD3D
Definition: dxg.h:52
#define DDHAL_DRIVER_NOTHANDLED
Definition: ddrawi.h:320
DWORD(APIENTRY * PGD_DXDDUNLOCKD3D)(HANDLE, PDD_UNLOCKDATA)
Definition: intddraw.h:40
#define DXG_INDEX_DxDdCanCreateD3DBuffer
Definition: dxg.h:23
DWORD APIENTRY NtGdiDdUnlockD3D(HANDLE hSurface, PDD_UNLOCKDATA puUnlockData)
Definition: d3d.c:374
BOOL APIENTRY NtGdiD3dContextCreate(HANDLE hDirectDrawLocal, HANDLE hSurfColor, HANDLE hSurfZ, LPD3DNTHAL_CONTEXTCREATEDATA pdcci)
Definition: d3d.c:117
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD APIENTRY NtGdiD3dDrawPrimitives2(HANDLE hCmdBuf, HANDLE hVBuf, LPD3DNTHAL_DRAWPRIMITIVES2DATA pded, FLATPTR *pfpVidMemCmd, DWORD *pdwSizeCmd, FLATPTR *pfpVidMemVtx, DWORD *pdwSizeVtx)
Definition: d3d.c:309
#define DXG_INDEX_DxDdDestroyD3DBuffer
Definition: dxg.h:35
smooth NULL
Definition: ftsmooth.c:416
#define DXG_INDEX_DxD3dValidateTextureStageState
Definition: dxg.h:14
DWORD(APIENTRY * PGD_D3DCONTEXTDESTROYALL)(LPD3DNTHAL_CONTEXTDESTROYALLDATA)
Definition: intddraw.h:47
DWORD APIENTRY NtGdiD3dContextDestroyAll(LPD3DNTHAL_CONTEXTDESTROYALLDATA pdcad)
Definition: d3d.c:193
DWORD APIENTRY NtGdiD3dContextDestroy(LPD3DNTHAL_CONTEXTDESTROYDATA pContextDestroyData)
Definition: d3d.c:155
DWORD(APIENTRY * PGD_D3DCONTEXTDESTROY)(LPD3DNTHAL_CONTEXTDESTROYDATA)
Definition: intddraw.h:46
ULONG_PTR FLATPTR
Definition: ddrawint.h:76
DWORD(APIENTRY * PGD_DXDDLOCKD3D)(HANDLE, PDD_LOCKDATA)
Definition: intddraw.h:41
DWORD APIENTRY NtGdiDdLockD3D(HANDLE hSurface, PDD_LOCKDATA puLockData)
Definition: d3d.c:335
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DXG_INDEX_DxDdUnlockD3D
Definition: dxg.h:67
DWORD APIENTRY NtGdiDdDestroyD3DBuffer(HANDLE hSurface)
Definition: d3d.c:290
#define DXG_INDEX_DxD3dContextDestroyAll
Definition: dxg.h:13
DRVFN gpDxFuncs[DXG_INDEX_DxDdIoctl+1]
Definition: ddraw.c:23
DWORD APIENTRY NtGdiDdCreateD3DBuffer(HANDLE hDirectDraw, HANDLE *hSurface, DDSURFACEDESC *puSurfaceDescription, DD_SURFACE_GLOBAL *puSurfaceGlobalData, DD_SURFACE_LOCAL *puSurfaceLocalData, DD_SURFACE_MORE *puSurfaceMoreData, PDD_CREATESURFACEDATA puCreateSurfaceData, HANDLE *puhSurface)
Definition: d3d.c:261
BOOL(APIENTRY * PGD_D3DCONTEXTCREATE)(HANDLE, HANDLE, HANDLE, LPD3DNTHAL_CONTEXTCREATEDATA)
Definition: intddraw.h:45
#define DXG_INDEX_DxD3dContextDestroy
Definition: dxg.h:12
DWORD(APIENTRY * PGD_DXDDDESTROYD3DBUFFER)(HANDLE)
Definition: intddraw.h:38
DWORD(APIENTRY * PGD_D3DDRAWPRIMITIVES2)(HANDLE, HANDLE, LPD3DNTHAL_DRAWPRIMITIVES2DATA, FLATPTR *, DWORD *, FLATPTR *, DWORD *)
Definition: intddraw.h:43
#define DXG_INDEX_DxD3dDrawPrimitives2
Definition: dxg.h:15
DWORD APIENTRY NtGdiD3dValidateTextureStageState(LPD3DNTHAL_VALIDATETEXTURESTAGESTATEDATA pData)
Definition: d3d.c:355
#define DPRINT1
Definition: precomp.h:8
DWORD APIENTRY NtGdiDdCanCreateD3DBuffer(HANDLE hDirectDraw, PDD_CANCREATESURFACEDATA puCanCreateSurfaceData)
Definition: d3d.c:60
#define DXG_INDEX_DxDdCreateD3DBuffer
Definition: dxg.h:28
#define DXG_INDEX_DxD3dContextCreate
Definition: dxg.h:11
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
DWORD(APIENTRY * PGD_D3DVALIDATETEXTURESTAGESTATE)(LPD3DNTHAL_VALIDATETEXTURESTAGESTATEDATA)
Definition: intddraw.h:42
#define APIENTRY
Definition: api.h:79