1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for NtGdiDdCreateDirectDrawObject
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
10 #include <ddrawi.h>
11 
12 /* Note : OsThunkDdQueryDirectDrawObject is the usermode name of NtGdiDdQueryDirectDrawObject
13  *        it lives in d3d8thk.dll and in windows 2000 it doing syscall direcly to win32k.sus
14  *        in windows xp and higher it call to gdi32.dll to DdEntry41 and it doing the syscall
15  */
16 START_TEST(NtGdiDdQueryDirectDrawObject)
17 {
18     HANDLE  hDirectDraw = NULL;
19     DD_HALINFO *pHalInfo = NULL;
20     DWORD *pCallBackFlags = NULL;
21     LPD3DNTHAL_CALLBACKS puD3dCallbacks = NULL;
22     LPD3DNTHAL_GLOBALDRIVERDATA puD3dDriverData = NULL;
23     PDD_D3DBUFCALLBACKS puD3dBufferCallbacks = NULL;
24     LPDDSURFACEDESC puD3dTextureFormats = NULL;
25     DWORD *puNumHeaps = NULL;
26     VIDEOMEMORY *puvmList = NULL;
27     DWORD *puNumFourCC = NULL;
28     DWORD *puFourCC = NULL;
29 
30     DD_HALINFO HalInfo;
31     DD_HALINFO oldHalInfo;
32     DWORD CallBackFlags[4];
33 
34     D3DNTHAL_CALLBACKS D3dCallbacks;
35     D3DNTHAL_CALLBACKS oldD3dCallbacks;
36 
37     D3DNTHAL_GLOBALDRIVERDATA D3dDriverData;
38     D3DNTHAL_GLOBALDRIVERDATA oldD3dDriverData;
39 
40     DD_D3DBUFCALLBACKS D3dBufferCallbacks;
41     DD_D3DBUFCALLBACKS oldD3dBufferCallbacks;
42 
43     DDSURFACEDESC2 D3dTextureFormats[100];
44     DWORD NumHeaps = 0;
45     VIDEOMEMORY vmList;
46     //DWORD NumFourCC = 0;
47     //DWORD FourCC = 0;
48     DEVMODE devmode;
49     HDC hdc;
50 
51     DWORD dwTextureCounter = 0;
52     DDSURFACEDESC *myDesc = NULL;
53 
54     /* clear data */
55     memset(&vmList,0,sizeof(VIDEOMEMORY));
56     memset(&D3dTextureFormats,0,sizeof(DDSURFACEDESC));
57     memset(&D3dBufferCallbacks,0,sizeof(DD_D3DBUFCALLBACKS));
58     memset(&D3dDriverData,0,sizeof(D3DNTHAL_GLOBALDRIVERDATA));
59     memset(&D3dCallbacks,0,sizeof(D3DNTHAL_CALLBACKS));
60     memset(&HalInfo,0,sizeof(DD_HALINFO));
61     memset(CallBackFlags,0,sizeof(DWORD)*3);
62 
63     /* Get current display mode */
64     EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &devmode);
65 
66     /* Create hdc that we can use */
67     hdc = CreateDCW(L"DISPLAY",NULL,NULL,NULL);
68     ASSERT(hdc != NULL);
69 
70 
71     /* Create ReactX handle */
72     hDirectDraw = (HANDLE) NtGdiDdCreateDirectDrawObject(hdc);
73     RTEST(hDirectDraw != NULL);
74     if (hDirectDraw == NULL)
75     {
76         DeleteDC(hdc);
77         return;
78     }
79 
80     /* Start Test ReactX NtGdiDdQueryDirectDrawObject function */
81 
82     /* testing  OsThunkDdQueryDirectDrawObject( NULL, ....  */
83     RTEST(NtGdiDdQueryDirectDrawObject( NULL, pHalInfo,
84                                         pCallBackFlags, puD3dCallbacks,
85                                         puD3dDriverData, puD3dBufferCallbacks,
86                                         puD3dTextureFormats, puNumHeaps,
87                                         puvmList, puNumFourCC,
88                                         puFourCC) == FALSE);
89 
90     RTEST(pHalInfo == NULL);
91     RTEST(pCallBackFlags == NULL);
92     RTEST(puD3dCallbacks == NULL);
93     RTEST(puD3dDriverData == NULL);
94     RTEST(puD3dBufferCallbacks == NULL);
95     RTEST(puD3dTextureFormats == NULL);
96     RTEST(puNumFourCC == NULL);
97     RTEST(puFourCC == NULL);
98     RTEST(puNumHeaps == NULL);
99     RTEST(puvmList == NULL);
100 
101     /* testing  NtGdiDdQueryDirectDrawObject( hDirectDrawLocal, NULL, ....  */
102     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
103                                         pCallBackFlags, puD3dCallbacks,
104                                         puD3dDriverData, puD3dBufferCallbacks,
105                                         puD3dTextureFormats, puNumHeaps,
106                                         puvmList, puNumFourCC,
107                                         puFourCC) == FALSE);
108 
109     RTEST(pHalInfo == NULL);
110     RTEST(pCallBackFlags == NULL);
111     RTEST(puD3dCallbacks == NULL);
112     RTEST(puD3dDriverData == NULL);
113     RTEST(puD3dBufferCallbacks == NULL);
114     RTEST(puD3dTextureFormats == NULL);
115     RTEST(puNumFourCC == NULL);
116     RTEST(puFourCC == NULL);
117     RTEST(puNumHeaps == NULL);
118     RTEST(puvmList == NULL);
119 
120     /* testing  NtGdiDdQueryDirectDrawObject( hDirectDrawLocal, pHalInfo, NULL, ....  */
121     pHalInfo = &HalInfo;
122     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
123                                         pCallBackFlags, puD3dCallbacks,
124                                         puD3dDriverData, puD3dBufferCallbacks,
125                                         puD3dTextureFormats, puNumHeaps,
126                                         puvmList, puNumFourCC,
127                                         puFourCC)== FALSE);
128 
129     RTEST(pHalInfo != NULL);
130     ASSERT(pHalInfo != NULL);
131 
132     RTEST(pCallBackFlags == NULL);
133     RTEST(puD3dCallbacks == NULL);
134     RTEST(puD3dDriverData == NULL);
135     RTEST(puD3dBufferCallbacks == NULL);
136     RTEST(puD3dTextureFormats == NULL);
137     RTEST(puNumFourCC == NULL);
138     RTEST(puFourCC == NULL);
139     RTEST(puNumHeaps == NULL);
140     RTEST(puvmList == NULL);
141 
142     if ((pHalInfo->dwSize != sizeof(DD_HALINFO)) &&
143         (pHalInfo->dwSize != sizeof(DD_HALINFO_V4)))
144     {
145         RTEST(pHalInfo->dwSize != sizeof(DD_HALINFO));
146         ASSERT(pHalInfo->dwSize != sizeof(DD_HALINFO));
147     }
148 
149     if (pHalInfo->dwSize == sizeof(DD_HALINFO))
150     {
151         /*the offset, in bytes, to primary surface in the display memory  */
152         /* some graphic card like  sis 760 GX, Nvida GF7900GS does not set any offset at all */
153         // RTEST(pHalInfo->vmiData.fpPrimary != 0 );
154 
155         /* unsuse always 0 */
156         RTEST(pHalInfo->vmiData.dwFlags == 0 );
157 
158         /* Check the res */
159         RTEST(pHalInfo->vmiData.dwDisplayWidth == devmode.dmPelsWidth );
160         RTEST(pHalInfo->vmiData.dwDisplayHeight == devmode.dmPelsHeight );
161 
162         /*  This can never be test for it is who big the line is after it been align displayPitch */
163         RTEST(pHalInfo->vmiData.lDisplayPitch != 0);
164 
165         RTEST(pHalInfo->vmiData.ddpfDisplay.dwSize == sizeof(DDPIXELFORMAT) );
166         ASSERT(pHalInfo->vmiData.ddpfDisplay.dwSize == sizeof(DDPIXELFORMAT));
167 
168         /* We can not check if it DDPF_RGB flags been set for primary surface
169          * for it can be DDPF_PALETTEINDEXED1,DDPF_PALETTEINDEXED2,DDPF_PALETTEINDEXED4,DDPF_PALETTEINDEXED8, DDPF_PALETTEINDEXEDTO8, DDPF_RGB, DDPF_YUV
170          */
171         RTEST( (pHalInfo->vmiData.ddpfDisplay.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4 |
172                                                          DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8 | DDPF_RGB | DDPF_YUV)) != 0);
173 
174 
175         /* No fourcc are use on primary screen */
176         RTEST(pHalInfo->vmiData.ddpfDisplay.dwFourCC == 0 );
177 
178         /* Count RGB Bits 8/16/24/32 */
179         RTEST(pHalInfo->vmiData.ddpfDisplay.dwRGBBitCount == devmode.dmBitsPerPel );
180 
181         /* The rgb mask can not be detected in user mode, for it can be 15Bpp convert to 16Bpp mode, so we have no way detect correct mask
182          * But the mask can never be Zero
183          */
184         RTEST(pHalInfo->vmiData.ddpfDisplay.dwRBitMask  !=  0 );
185         RTEST(pHalInfo->vmiData.ddpfDisplay.dwGBitMask !=  0 );
186         RTEST(pHalInfo->vmiData.ddpfDisplay.dwBBitMask != 0 );
187 
188         /* primary never set the alpha blend mask */
189         RTEST(pHalInfo->vmiData.ddpfDisplay.dwRGBAlphaBitMask ==  0 );
190 
191         /* This can not be test at usermode it is each hardware drv that fill in it,
192          * only way to found them is to use this call  */
193         // pHalInfo->vmiData->dwOffscreenAlign
194         // pHalInfo->vmiData->dwOverlayAlign
195         // pHalInfo->vmiData->dwTextureAlign
196         // pHalInfo->vmiData->dwZBufferAlign
197         // pHalInfo->vmiData->dwAlphaAlign
198 
199         /* the primary display address */
200         RTEST( ( (DWORD)pHalInfo->vmiData.pvPrimary & (~0x80000000)) != 0 );
201 
202         /* test see if we got back the pvmList here
203          * acording msdn vmiData.dwNumHeaps and vmiData.pvmList
204          * exists for _VIDEOMEMORYINFO but they do not, it reviews
205          * in ddk and wdk and own testcase
206          */
207          // RTEST(pHalInfo->vmiData.dwNumHeaps  != 0 );
208          // RTEST(pHalInfo->vmiData.pvmList  != 0 );
209 
210         /* Test see if we got any hardware acclartions for 2d or 3d, this always fill in
211          * that mean we found a bugi drv and dx does not work on this drv
212          */
213 
214         /* the SIS 760 GX will never fill it in, it is a bugi drv */
215         RTEST(pHalInfo->ddCaps.dwSize == sizeof(DDCORECAPS));
216 
217         /* Testing see if we got any hw support for
218          * This test can fail on video card that does not support 2d/overlay/3d
219          */
220         RTEST( pHalInfo->ddCaps.dwCaps != 0);
221         RTEST( pHalInfo->ddCaps.ddsCaps.dwCaps != 0);
222 
223         /* This flags is obsolete and should not be used by the driver */
224         RTEST( pHalInfo->ddCaps.dwFXAlphaCaps == 0);
225 
226 
227         /* basic dx 2 is found if this flags not set
228          * if this fail we do not have a dx driver install acodring ms, some version of windows it
229          * is okay this fail and drv does then only support basic dx
230          *
231          */
232         if (pHalInfo->dwFlags != 0)
233         {
234             RTEST( (pHalInfo->dwFlags & (DDHALINFO_GETDRIVERINFOSET | DDHALINFO_GETDRIVERINFO2)) != 0 );
235             RTEST( ( (DWORD)pHalInfo->GetDriverInfo & 0x80000000) != 0 );
236             ASSERT( ((DWORD)pHalInfo->GetDriverInfo & 0x80000000) != 0 );
237         }
238 
239         /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
240 
241 
242        /* the pHalInfo->ddCaps.ddsCaps.dwCaps & DDSCAPS_3DDEVICE will be ignore, only way detect it proper follow code,
243         * this will be fill in of all drv, it is not only for 3d stuff, this always fill by win32k.sys or dxg.sys depns
244         * if it windows 2000 or windows xp/2003
245         *
246         * point to kmode direcly to the win32k.sys, win32k.sys is kmode and it is kmode address we getting back
247         */
248         RTEST( ( (DWORD)pHalInfo->lpD3DGlobalDriverData & (~0x80000000)) != 0 );
249         RTEST( ( (DWORD)pHalInfo->lpD3DHALCallbacks & (~0x80000000)) != 0 );
250         RTEST( ( (DWORD)pHalInfo->lpD3DHALCallbacks & (~0x80000000)) != 0 );
251     }
252 
253     /* Backup DD_HALINFO so we do not need resting it */
254     RtlCopyMemory(&oldHalInfo, &HalInfo, sizeof(DD_HALINFO));
255 
256     /* testing  NtGdiDdQueryDirectDrawObject( hDirectDrawLocal, pHalInfo, pCallBackFlags, NULL, ....  */
257     pHalInfo = &HalInfo;
258     pCallBackFlags = CallBackFlags;
259     RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
260 
261     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
262                                         pCallBackFlags, puD3dCallbacks,
263                                         puD3dDriverData, puD3dBufferCallbacks,
264                                         puD3dTextureFormats, puNumHeaps,
265                                         puvmList, puNumFourCC,
266                                         puFourCC)== FALSE);
267     RTEST(pHalInfo != NULL);
268     ASSERT(pHalInfo != NULL);
269 
270     RTEST(pCallBackFlags != NULL);
271     ASSERT(pCallBackFlags != NULL);
272 
273     RTEST(puD3dCallbacks == NULL);
274     RTEST(puD3dDriverData == NULL);
275     RTEST(puD3dBufferCallbacks == NULL);
276     RTEST(puD3dTextureFormats == NULL);
277     RTEST(puNumFourCC == NULL);
278     RTEST(puFourCC == NULL);
279     RTEST(puNumHeaps == NULL);
280     RTEST(puvmList == NULL);
281 
282     /* We do not retesting DD_HALINFO, instead we compare it */
283     RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
284 
285     /* Rember on some nivida drv the pCallBackFlags will not be set even they api exists in the drv
286      * known workaround is to check if the drv really return a kmode pointer for the drv functions
287      * we want to use.
288      */
289     RTEST(pCallBackFlags[0] != 0);
290     RTEST(pCallBackFlags[1] != 0);
291     RTEST(pCallBackFlags[2] == 0);
292 
293     /* testing  NtGdiDdQueryDirectDrawObject( hDirectDrawLocal, pHalInfo, pCallBackFlags, D3dCallbacks, NULL, ....  */
294     pHalInfo = &HalInfo;
295     pCallBackFlags = CallBackFlags;
296     puD3dCallbacks = &D3dCallbacks;
297 
298     RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
299     RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
300 
301     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
302                                         pCallBackFlags, puD3dCallbacks,
303                                         puD3dDriverData, puD3dBufferCallbacks,
304                                         puD3dTextureFormats, puNumHeaps,
305                                         puvmList, puNumFourCC,
306                                         puFourCC)== FALSE);
307     RTEST(pHalInfo != NULL);
308     ASSERT(pHalInfo != NULL);
309 
310     RTEST(pCallBackFlags != NULL);
311     ASSERT(pCallBackFlags != NULL);
312 
313     /* rember puD3dCallbacks shall never return NULL */
314     RTEST(puD3dCallbacks != NULL);
315     ASSERT(puD3dCallbacks != NULL);
316 
317     /* the pHalInfo->ddCaps.ddsCaps.dwCaps & DDSCAPS_3DDEVICE will be ignore, only way detect it proper follow code,
318      * this will be fill in of all drv, it is not only for 3d stuff, this always fill by win32k.sys or dxg.sys depns
319      * if it windows 2000 or windows xp/2003
320      */
321     RTEST(puD3dCallbacks->dwSize == sizeof(D3DNTHAL_CALLBACKS));
322 
323     /* Nivda like GF7900GS will not follow ms design rule here,
324      * ContextDestroyAll must alwyas be NULL for it is not longer inuse in windows 2000 and higher
325      */
326     RTEST(puD3dCallbacks->ContextDestroyAll == NULL);
327 
328     /* Nivda like GF7900GS will not follow ms design rule here,
329      * SceneCapture must alwyas be NULL for it is not longer inuse in windows 2000 and higher
330      */
331     RTEST(puD3dCallbacks->SceneCapture  == NULL);
332     RTEST(puD3dCallbacks->dwReserved10 == 0);
333     RTEST(puD3dCallbacks->dwReserved11 == 0);
334     RTEST(puD3dCallbacks->dwReserved22 == 0);
335     RTEST(puD3dCallbacks->dwReserved23 == 0);
336     RTEST(puD3dCallbacks->dwReserved == 0);
337     RTEST(puD3dCallbacks->TextureCreate  == NULL);
338     RTEST(puD3dCallbacks->TextureDestroy  == NULL);
339     RTEST(puD3dCallbacks->TextureSwap  == NULL);
340     RTEST(puD3dCallbacks->TextureGetSurf  == NULL);
341     RTEST(puD3dCallbacks->dwReserved12 == 0);
342     RTEST(puD3dCallbacks->dwReserved13 == 0);
343     RTEST(puD3dCallbacks->dwReserved14 == 0);
344     RTEST(puD3dCallbacks->dwReserved15 == 0);
345     RTEST(puD3dCallbacks->dwReserved16 == 0);
346     RTEST(puD3dCallbacks->dwReserved17 == 0);
347     RTEST(puD3dCallbacks->dwReserved18 == 0);
348     RTEST(puD3dCallbacks->dwReserved19 == 0);
349     RTEST(puD3dCallbacks->dwReserved20 == 0);
350     RTEST(puD3dCallbacks->dwReserved21 == 0);
351     RTEST(puD3dCallbacks->dwReserved24 == 0);
352     RTEST(puD3dCallbacks->dwReserved0 == 0);
353     RTEST(puD3dCallbacks->dwReserved1 == 0);
354     RTEST(puD3dCallbacks->dwReserved2 == 0);
355     RTEST(puD3dCallbacks->dwReserved3 == 0);
356     RTEST(puD3dCallbacks->dwReserved4 == 0);
357     RTEST(puD3dCallbacks->dwReserved5 == 0);
358     RTEST(puD3dCallbacks->dwReserved6 == 0);
359     RTEST(puD3dCallbacks->dwReserved7 == 0);
360     RTEST(puD3dCallbacks->dwReserved8 == 0);
361     RTEST(puD3dCallbacks->dwReserved9 == 0);
362 
363     /* how detect puD3dCallbacks->ContextCreate and puD3dCallbacks->ContextDestroy shall be set for bugi drv like nivda ? */
364     /* pointer direcly to the graphic drv, it is kmode pointer */
365     // RTEST( ( (DWORD)puD3dCallbacks->ContextCreate & (~0x80000000)) != 0 );
366     // RTEST( ( (DWORD)puD3dCallbacks->ContextDestroy & (~0x80000000)) != 0 );
367 
368     RTEST(puD3dDriverData == NULL);
369     RTEST(puD3dBufferCallbacks == NULL);
370     RTEST(puD3dTextureFormats == NULL);
371     RTEST(puNumFourCC == NULL);
372     RTEST(puFourCC == NULL);
373     RTEST(puNumHeaps == NULL);
374     RTEST(puvmList == NULL);
375 
376     /* We do not retesting DD_HALINFO, instead we compare it */
377     RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
378     RTEST(pCallBackFlags[0] != 0);
379     RTEST(pCallBackFlags[1] != 0);
380     RTEST(pCallBackFlags[2] == 0);
381 
382     /* Backup D3DNTHAL_CALLBACKS so we do not need resting it */
383     RtlCopyMemory(&oldD3dCallbacks, &D3dCallbacks, sizeof(D3DNTHAL_CALLBACKS));
384 
385 
386 /* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, NULL, */
387     pHalInfo = &HalInfo;
388     pCallBackFlags = CallBackFlags;
389     puD3dCallbacks = &D3dCallbacks;
390     puD3dDriverData = &D3dDriverData;
391 
392     RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
393     RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
394     RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
395 
396     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
397                                         pCallBackFlags, puD3dCallbacks,
398                                         puD3dDriverData, puD3dBufferCallbacks,
399                                         puD3dTextureFormats, puNumHeaps,
400                                         puvmList, puNumFourCC,
401                                         puFourCC)== FALSE);
402     RTEST(pHalInfo != NULL);
403     ASSERT(pHalInfo != NULL);
404 
405     RTEST(pCallBackFlags != NULL);
406     ASSERT(pCallBackFlags != NULL);
407 
408     RTEST(puD3dCallbacks != NULL);
409     ASSERT(puD3dCallbacks != NULL);
410 
411     RTEST(puD3dDriverData != NULL);
412     ASSERT(puD3dDriverData != NULL);
413 
414     RTEST(puD3dBufferCallbacks == NULL);
415     RTEST(puD3dTextureFormats == NULL);
416     RTEST(puNumFourCC == NULL);
417     RTEST(puFourCC == NULL);
418     RTEST(puNumHeaps == NULL);
419     RTEST(puvmList == NULL);
420 
421     /* We retesting pCallBackFlags  */
422     RTEST(pCallBackFlags[0] != 0);
423     RTEST(pCallBackFlags[1] != 0);
424     RTEST(pCallBackFlags[2] == 0);
425 
426     /* We do not retesting instead we compare it */
427     RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
428     RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
429 
430     /* start test of puD3dDriverData */
431 
432     RTEST(puD3dDriverData->dwSize == sizeof(D3DNTHAL_GLOBALDRIVERDATA));
433     RTEST(puD3dDriverData->hwCaps.dwSize == sizeof(D3DNTHALDEVICEDESC_V1));
434     RTEST(puD3dDriverData->hwCaps.dtcTransformCaps.dwSize == sizeof(D3DTRANSFORMCAPS));
435     RTEST(puD3dDriverData->hwCaps.dlcLightingCaps.dwSize == sizeof(D3DLIGHTINGCAPS));
436     RTEST(puD3dDriverData->hwCaps.dpcLineCaps.dwSize == sizeof(D3DPRIMCAPS));
437     RTEST(puD3dDriverData->hwCaps.dpcTriCaps.dwSize  == sizeof(D3DPRIMCAPS));
438     RTEST(puD3dDriverData->hwCaps.dwMaxBufferSize == 0);
439     RTEST(puD3dDriverData->hwCaps.dwMaxVertexCount == 0);
440 
441     /* Backup D3DHAL_GLOBALDRIVERDATA so we do not need resting it */
442     RtlCopyMemory(&oldD3dDriverData, &D3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA));
443 
444 /* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, puD3dBufferCallbacks, NULL, */
445     pHalInfo = &HalInfo;
446     pCallBackFlags = CallBackFlags;
447     puD3dCallbacks = &D3dCallbacks;
448     puD3dDriverData = &D3dDriverData;
449     puD3dBufferCallbacks = &D3dBufferCallbacks;
450 
451     RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
452     RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
453     RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
454     RtlZeroMemory(puD3dDriverData,sizeof(D3DNTHAL_CALLBACKS));
455 
456     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
457                                         pCallBackFlags, puD3dCallbacks,
458                                         puD3dDriverData, puD3dBufferCallbacks,
459                                         puD3dTextureFormats, puNumHeaps,
460                                         puvmList, puNumFourCC,
461                                         puFourCC)== FALSE);
462     RTEST(pHalInfo != NULL);
463     RTEST(pCallBackFlags != NULL);
464 
465     if (pHalInfo->ddCaps.ddsCaps.dwCaps  & DDSCAPS_3DDEVICE )
466     {
467         RTEST(puD3dCallbacks != NULL);
468         RTEST(puD3dDriverData != NULL);
469         RTEST(puD3dBufferCallbacks != NULL);
470     }
471 
472     RTEST(pHalInfo != NULL);
473     ASSERT(pHalInfo != NULL);
474 
475     RTEST(pCallBackFlags != NULL);
476     ASSERT(pCallBackFlags != NULL);
477 
478     RTEST(puD3dCallbacks != NULL);
479     ASSERT(puD3dCallbacks != NULL);
480 
481     RTEST(puD3dDriverData != NULL);
482     ASSERT(puD3dDriverData != NULL);
483 
484     RTEST(puD3dBufferCallbacks != NULL);
485     ASSERT(puD3dDriverData != NULL);
486 
487     RTEST(puD3dTextureFormats == NULL);
488     RTEST(puNumFourCC == NULL);
489     RTEST(puFourCC == NULL);
490     RTEST(puNumHeaps == NULL);
491     RTEST(puvmList == NULL);
492 
493     /* We retesting the flags */
494     RTEST(pCallBackFlags[0] != 0);
495     RTEST(pCallBackFlags[1] != 0);
496     RTEST(pCallBackFlags[2] == 0);
497 
498     /* We do not retesting instead we compare it */
499     RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
500     RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
501     RTEST(memcmp(&oldD3dDriverData, puD3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA)) == 0);
502 
503     /* start test of puD3dBufferCallbacks */
504     RTEST(puD3dBufferCallbacks->dwSize == sizeof(DD_D3DBUFCALLBACKS));
505     if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_CANCREATED3DBUF)
506     {
507         /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
508         RTEST( ( (DWORD)puD3dBufferCallbacks->CanCreateD3DBuffer & (~0x80000000)) != 0 );
509     }
510     else
511     {
512         RTEST( puD3dBufferCallbacks->CanCreateD3DBuffer == NULL);
513     }
514 
515     if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_CREATED3DBUF)
516     {
517         /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
518         RTEST( ( (DWORD)puD3dBufferCallbacks->CreateD3DBuffer & (~0x80000000)) != 0 );
519     }
520     else
521     {
522         RTEST( puD3dBufferCallbacks->CreateD3DBuffer == NULL);
523     }
524 
525     if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_DESTROYD3DBUF)
526     {
527         /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
528         RTEST( ( (DWORD)puD3dBufferCallbacks->DestroyD3DBuffer & (~0x80000000)) != 0 );
529     }
530     else
531     {
532         RTEST( puD3dBufferCallbacks->DestroyD3DBuffer == NULL);
533     }
534 
535     if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_LOCKD3DBUF)
536     {
537         /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
538         RTEST( ( (DWORD)puD3dBufferCallbacks->LockD3DBuffer & (~0x80000000)) != 0 );
539     }
540     else
541     {
542         RTEST( puD3dBufferCallbacks->LockD3DBuffer == NULL);
543     }
544 
545     if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_UNLOCKD3DBUF)
546     {
547         /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
548         RTEST( ( (DWORD)puD3dBufferCallbacks->UnlockD3DBuffer & (~0x80000000)) != 0 );
549     }
550     else
551     {
552         RTEST( puD3dBufferCallbacks->UnlockD3DBuffer == NULL);
553     }
554 
555     /* Backup DD_D3DBUFCALLBACKS so we do not need resting it */
556     RtlCopyMemory(&oldD3dBufferCallbacks, &D3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS));
557 
558 
559 /* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, puD3dBufferCallbacks, puD3dTextureFormats, NULL, */
560     pHalInfo = &HalInfo;
561     pCallBackFlags = CallBackFlags;
562     puD3dCallbacks = &D3dCallbacks;
563     puD3dDriverData = &D3dDriverData;
564     puD3dBufferCallbacks = &D3dBufferCallbacks;
565 
566     /* It is forbein to return a  DDSURFACEDESC2 it should always be DDSURFACEDESC
567         This is only for detected bad drivers that does not follow the rules, if they
568         does not follow tthe rules, not everthing being copy then in gdi32.dll
569         gdi32.dll always assume it is DDSURFACEDESC size
570     */
571     if (puD3dDriverData->dwNumTextureFormats != 0)
572     {
573         puD3dTextureFormats = malloc (puD3dDriverData->dwNumTextureFormats * sizeof(DDSURFACEDESC2));
574     }
575 
576     RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
577     RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
578     RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
579     RtlZeroMemory(puD3dDriverData,sizeof(D3DNTHAL_GLOBALDRIVERDATA));
580     RtlZeroMemory(&D3dBufferCallbacks,sizeof(DD_D3DBUFCALLBACKS));
581 
582     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
583                                         pCallBackFlags, puD3dCallbacks,
584                                         puD3dDriverData, puD3dBufferCallbacks,
585                                         puD3dTextureFormats, puNumHeaps,
586                                         puvmList, puNumFourCC,
587                                         puFourCC)== FALSE);
588 
589     RTEST(pHalInfo != NULL);
590     ASSERT(pHalInfo != NULL);
591 
592     RTEST(pCallBackFlags != NULL);
593     ASSERT(pCallBackFlags != NULL);
594 
595     RTEST(puD3dCallbacks != NULL);
596     ASSERT(puD3dCallbacks != NULL);
597 
598     RTEST(puD3dDriverData != NULL);
599     ASSERT(puD3dDriverData != NULL);
600 
601     RTEST(puD3dBufferCallbacks != NULL);
602     ASSERT(puD3dDriverData != NULL);
603 
604     RTEST(puD3dTextureFormats != NULL);
605     ASSERT(puD3dTextureFormats != NULL);
606 
607     RTEST(puNumFourCC == NULL);
608     RTEST(puFourCC == NULL);
609     RTEST(puNumHeaps == NULL);
610     RTEST(puvmList == NULL);
611 
612     /* We retesting the flags */
613     RTEST(pCallBackFlags[0] != 0);
614     RTEST(pCallBackFlags[1] != 0);
615     RTEST(pCallBackFlags[2] == 0);
616 
617     /* We do not retesting instead we compare it */
618     RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
619     RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
620     RTEST(memcmp(&oldD3dDriverData, puD3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA)) == 0);
621     RTEST(memcmp(&oldD3dBufferCallbacks, puD3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS)) == 0);
622 
623     /* start test of dwNumTextureFormats */
624     if (puD3dDriverData->dwNumTextureFormats != 0)
625     {
626         myDesc = puD3dTextureFormats;
627         for (dwTextureCounter=0;dwTextureCounter<puD3dDriverData->dwNumTextureFormats;dwTextureCounter++)
628         {
629             RTEST(myDesc->dwSize == sizeof(DDSURFACEDESC));
630             ASSERT(myDesc->dwSize == sizeof(DDSURFACEDESC));
631 
632             RTEST( (myDesc->dwFlags & (~(DDSD_CAPS|DDSD_PIXELFORMAT))) == 0);
633             RTEST(myDesc->dwHeight == 0);
634             RTEST(myDesc->dwWidth == 0);
635             RTEST(myDesc->dwLinearSize == 0);
636             RTEST(myDesc->dwBackBufferCount == 0);
637             RTEST(myDesc->dwZBufferBitDepth == 0);
638             RTEST(myDesc->dwAlphaBitDepth == 0);
639             RTEST(myDesc->dwReserved == 0);
640             RTEST(myDesc->lpSurface == 0);
641             RTEST(myDesc->ddckCKDestOverlay.dwColorSpaceLowValue == 0);
642             RTEST(myDesc->ddckCKDestOverlay.dwColorSpaceHighValue == 0);
643             RTEST(myDesc->ddckCKDestBlt.dwColorSpaceLowValue == 0);
644             RTEST(myDesc->ddckCKDestBlt.dwColorSpaceHighValue == 0);
645             RTEST(myDesc->ddckCKSrcOverlay.dwColorSpaceLowValue == 0);
646             RTEST(myDesc->ddckCKSrcOverlay.dwColorSpaceHighValue == 0);
647             RTEST(myDesc->ddckCKSrcBlt.dwColorSpaceLowValue == 0);
648             RTEST(myDesc->ddckCKSrcBlt.dwColorSpaceHighValue == 0);
649             RTEST(myDesc->ddpfPixelFormat.dwSize == sizeof(DDPIXELFORMAT));
650             RTEST(myDesc->ddpfPixelFormat.dwFlags != 0);
651             if (myDesc->ddpfPixelFormat.dwFlags & DDPF_FOURCC)
652             {
653                 RTEST(myDesc->ddpfPixelFormat.dwFourCC != 0);
654             }
655             RTEST(myDesc->ddsCaps.dwCaps == DDSCAPS_TEXTURE);
656 
657             myDesc = (DDSURFACEDESC *) (((DWORD) myDesc) + sizeof(DDSURFACEDESC));
658         }
659     }
660 
661 
662     /* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, puD3dBufferCallbacks, puD3dTextureFormats, puNumHeaps, NULL, */
663     pHalInfo = &HalInfo;
664     pCallBackFlags = CallBackFlags;
665     puD3dCallbacks = &D3dCallbacks;
666     puD3dDriverData = &D3dDriverData;
667     puD3dBufferCallbacks = &D3dBufferCallbacks;
668     puNumHeaps = &NumHeaps;
669 
670     if (puD3dDriverData->dwNumTextureFormats != 0)
671     {
672         RtlZeroMemory(puD3dTextureFormats, puD3dDriverData->dwNumTextureFormats * sizeof(DDSURFACEDESC2));
673     }
674     RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
675     RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
676     RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
677     RtlZeroMemory(puD3dDriverData,sizeof(D3DNTHAL_GLOBALDRIVERDATA));
678     RtlZeroMemory(&D3dBufferCallbacks,sizeof(DD_D3DBUFCALLBACKS));
679 
680     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
681                                         pCallBackFlags, puD3dCallbacks,
682                                         puD3dDriverData, puD3dBufferCallbacks,
683                                         puD3dTextureFormats, puNumHeaps,
684                                         puvmList, puNumFourCC,
685                                         puFourCC)== FALSE);
686 
687     RTEST(pHalInfo != NULL);
688     ASSERT(pHalInfo != NULL);
689 
690     RTEST(pCallBackFlags != NULL);
691     ASSERT(pCallBackFlags != NULL);
692 
693     RTEST(puD3dCallbacks != NULL);
694     ASSERT(puD3dCallbacks != NULL);
695 
696     RTEST(puD3dDriverData != NULL);
697     ASSERT(puD3dDriverData != NULL);
698 
699     RTEST(puD3dBufferCallbacks != NULL);
700     ASSERT(puD3dDriverData != NULL);
701 
702     RTEST(puD3dTextureFormats != NULL);
703     ASSERT(puD3dTextureFormats != NULL);
704 
705     RTEST(puNumHeaps != NULL);
706     ASSERT(puNumHeaps != NULL);
707     RTEST(NumHeaps == 0);
708 
709     RTEST(puNumFourCC == NULL);
710     RTEST(puFourCC == NULL);
711 
712     RTEST(puvmList == NULL);
713 
714     /* We retesting the flags */
715     RTEST(pCallBackFlags[0] != 0);
716     RTEST(pCallBackFlags[1] != 0);
717     RTEST(pCallBackFlags[2] == 0);
718 
719     /* We do not retesting instead we compare it */
720     RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
721     RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
722     RTEST(memcmp(&oldD3dDriverData, puD3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA)) == 0);
723     RTEST(memcmp(&oldD3dBufferCallbacks, puD3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS)) == 0);
724     /* we skip resting texture */
725 
726 
727     /* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, puD3dBufferCallbacks, puD3dTextureFormats, puNumHeaps, puvmList, NULL, */
728     pHalInfo = &HalInfo;
729     pCallBackFlags = CallBackFlags;
730     puD3dCallbacks = &D3dCallbacks;
731     puD3dDriverData = &D3dDriverData;
732     puD3dBufferCallbacks = &D3dBufferCallbacks;
733     puNumHeaps = &NumHeaps;
734     puvmList = &vmList;
735 
736     if (puD3dDriverData->dwNumTextureFormats != 0)
737     {
738         RtlZeroMemory(puD3dTextureFormats, puD3dDriverData->dwNumTextureFormats * sizeof(DDSURFACEDESC2));
739     }
740     RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
741     RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
742     RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
743     RtlZeroMemory(puD3dDriverData,sizeof(D3DNTHAL_GLOBALDRIVERDATA));
744     RtlZeroMemory(&D3dBufferCallbacks,sizeof(DD_D3DBUFCALLBACKS));
745 
746     RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
747                                         pCallBackFlags, puD3dCallbacks,
748                                         puD3dDriverData, puD3dBufferCallbacks,
749                                         puD3dTextureFormats, puNumHeaps,
750                                         puvmList, puNumFourCC,
751                                         puFourCC)== FALSE);
752 
753     RTEST(pHalInfo != NULL);
754     ASSERT(pHalInfo != NULL);
755 
756     RTEST(pCallBackFlags != NULL);
757     ASSERT(pCallBackFlags != NULL);
758 
759     RTEST(puD3dCallbacks != NULL);
760     ASSERT(puD3dCallbacks != NULL);
761 
762     RTEST(puD3dDriverData != NULL);
763     ASSERT(puD3dDriverData != NULL);
764 
765     RTEST(puD3dBufferCallbacks != NULL);
766     ASSERT(puD3dDriverData != NULL);
767 
768     RTEST(puD3dTextureFormats != NULL);
769     ASSERT(puD3dTextureFormats != NULL);
770 
771     RTEST(puNumHeaps != NULL);
772     ASSERT(puNumHeaps != NULL);
773     RTEST(NumHeaps == 0);
774 
775     RTEST(puvmList != NULL);
776 
777     RTEST(puNumFourCC == NULL);
778     RTEST(puFourCC == NULL);
779 
780 
781 
782     /* We retesting the flags */
783     RTEST(pCallBackFlags[0] != 0);
784     RTEST(pCallBackFlags[1] != 0);
785     RTEST(pCallBackFlags[2] == 0);
786 
787     /* We do not retesting instead we compare it */
788     RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
789     RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
790     RTEST(memcmp(&oldD3dDriverData, puD3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA)) == 0);
791     RTEST(memcmp(&oldD3dBufferCallbacks, puD3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS)) == 0);
792     /* we skip resting texture */
793 
794     /* Todo
795     * adding test for
796     * puNumFourCC
797     * puFourCC
798     */
799 
800     /* Cleanup ReactX setup */
801     DeleteDC(hdc);
802     NtGdiDdDeleteDirectDrawObject(hDirectDraw);
803 }
804