f30f08cdae906c44f6aa64d1b8949f6ea123887a
[reactos.git] / reactos / subsystems / win32 / win32k / ntddraw / d3d.c
1 /*
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)
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
59 APIENTRY
60 NtGdiDdCanCreateD3DBuffer(HANDLE hDirectDraw,
61 PDD_CANCREATESURFACEDATA puCanCreateSurfaceData)
62 {
63 PGD_DDCANCREATED3DBUFFER pfnDdCanCreateD3DBuffer = (PGD_DDCANCREATED3DBUFFER)gpDxFuncs[DXG_INDEX_DxDdCanCreateD3DBuffer].pfn;
64
65 if (pfnDdCanCreateD3DBuffer == NULL)
66 {
67 DPRINT1("Warring no pfnDdCanCreateD3DBuffer");
68 return DDHAL_DRIVER_NOTHANDLED;
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,
120 LPD3DNTHAL_CONTEXTCREATEDATA pdcci)
121 {
122 PGD_D3DCONTEXTCREATE pfnD3dContextCreate = (PGD_D3DCONTEXTCREATE)gpDxFuncs[DXG_INDEX_DxD3dContextCreate].pfn;
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
155 NtGdiD3dContextDestroy(LPD3DNTHAL_CONTEXTDESTROYDATA pContextDestroyData)
156 {
157 PGD_D3DCONTEXTDESTROY pfnD3dContextDestroy = (PGD_D3DCONTEXTDESTROY)gpDxFuncs[DXG_INDEX_DxD3dContextDestroy].pfn;
158
159 if ( pfnD3dContextDestroy == NULL)
160 {
161 DPRINT1("Warning: no pfnD3dContextDestroy");
162 return DDHAL_DRIVER_NOTHANDLED;
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
193 NtGdiD3dContextDestroyAll(LPD3DNTHAL_CONTEXTDESTROYALLDATA pdcad)
194 {
195 PGD_D3DCONTEXTDESTROYALL pfnD3dContextDestroyAll = (PGD_D3DCONTEXTDESTROYALL)gpDxFuncs[DXG_INDEX_DxD3dContextDestroyAll].pfn;
196
197 if (pfnD3dContextDestroyAll == NULL)
198 {
199 DPRINT1("Warning: no pfnD3dContextDestroyAll");
200 return DDHAL_DRIVER_NOTHANDLED;
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
261 NtGdiDdCreateD3DBuffer(HANDLE hDirectDraw,
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 {
270 PGD_DDCREATED3DBUFFER pfnDdCreateD3DBuffer = (PGD_DDCREATED3DBUFFER)gpDxFuncs[DXG_INDEX_DxDdCreateD3DBuffer].pfn;
271
272 if (pfnDdCreateD3DBuffer == NULL)
273 {
274 DPRINT1("Warning no pfnDdCreateD3DBuffer");
275 return DDHAL_DRIVER_NOTHANDLED;
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
290 NtGdiDdDestroyD3DBuffer(HANDLE hSurface)
291 {
292 PGD_DXDDDESTROYD3DBUFFER pfnDdDestroyD3DBuffer = (PGD_DXDDDESTROYD3DBUFFER)gpDxFuncs[DXG_INDEX_DxDdDestroyD3DBuffer].pfn;
293
294 if (pfnDdDestroyD3DBuffer == NULL)
295 {
296 DPRINT1("Warning no pfnDdDestroyD3DBuffer");
297 return DDHAL_DRIVER_NOTHANDLED;
298 }
299
300 DPRINT1("Calling dxg.sys pfnDdDestroyD3DBuffer");
301 return pfnDdDestroyD3DBuffer(hSurface);
302 }
303
304 /************************************************************************/
305 /* NtGdiD3dDrawPrimitives2 */
306 /************************************************************************/
307 DWORD
308 APIENTRY
309 NtGdiD3dDrawPrimitives2(HANDLE hCmdBuf,
310 HANDLE hVBuf,
311 LPD3DNTHAL_DRAWPRIMITIVES2DATA pded,
312 FLATPTR *pfpVidMemCmd,
313 DWORD *pdwSizeCmd,
314 FLATPTR *pfpVidMemVtx,
315 DWORD *pdwSizeVtx)
316 {
317 PGD_D3DDRAWPRIMITIVES2 pfnD3dDrawPrimitives2 = (PGD_D3DDRAWPRIMITIVES2)gpDxFuncs[DXG_INDEX_DxD3dDrawPrimitives2].pfn;
318
319 if (pfnD3dDrawPrimitives2 == NULL)
320 {
321 DPRINT1("Warning: no pfnD3dDrawPrimitives2");
322 return DDHAL_DRIVER_NOTHANDLED;
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
335 NtGdiDdLockD3D(HANDLE hSurface,
336 PDD_LOCKDATA puLockData)
337 {
338 PGD_DXDDLOCKD3D pfnDdLockD3D = (PGD_DXDDLOCKD3D)gpDxFuncs[DXG_INDEX_DxDdLockD3D].pfn;
339
340 if (pfnDdLockD3D == NULL)
341 {
342 DPRINT1("Warning: no pfnDdLockD3D");
343 return DDHAL_DRIVER_NOTHANDLED;
344 }
345
346 DPRINT1("Calling dxg.sys pfnDdLockD3D");
347 return pfnDdLockD3D(hSurface, puLockData);
348 }
349
350 /************************************************************************/
351 /* NtGdiD3dValidateTextureStageState */
352 /************************************************************************/
353 DWORD
354 APIENTRY
355 NtGdiD3dValidateTextureStageState(LPD3DNTHAL_VALIDATETEXTURESTAGESTATEDATA pData)
356 {
357 PGD_D3DVALIDATETEXTURESTAGESTATE pfnD3dValidateTextureStageState = (PGD_D3DVALIDATETEXTURESTAGESTATE)gpDxFuncs[DXG_INDEX_DxD3dValidateTextureStageState].pfn;
358
359 if (pfnD3dValidateTextureStageState == NULL)
360 {
361 DPRINT1("Warning: no pfnD3dValidateTextureStageState");
362 return DDHAL_DRIVER_NOTHANDLED;
363 }
364
365 DPRINT1("Calling dxg.sys D3dValidateTextureStageState");
366 return pfnD3dValidateTextureStageState(pData);
367 }
368
369 /************************************************************************/
370 /* NtGdiDdUnlockD3D */
371 /************************************************************************/
372 DWORD
373 APIENTRY
374 NtGdiDdUnlockD3D(HANDLE hSurface,
375 PDD_UNLOCKDATA puUnlockData)
376 {
377 PGD_DXDDUNLOCKD3D pfnDdUnlockD3D = (PGD_DXDDUNLOCKD3D)gpDxFuncs[DXG_INDEX_DxDdUnlockD3D].pfn;
378
379 if (pfnDdUnlockD3D == NULL)
380 {
381 DPRINT1("Warning: no pfnDdUnlockD3D");
382 return DDHAL_DRIVER_NOTHANDLED;
383 }
384
385 DPRINT1("Calling dxg.sys pfnDdUnlockD3D");
386 return pfnDdUnlockD3D(hSurface, puUnlockData);
387
388 }
389
390
391
392