Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / d3d9 / tests / device.c
blob7994a2a6318eb7c778d7805a78276681bf6242c3
1 /*
2 * Copyright (C) 2006 Vitaliy Margolen
3 * Copyright (C) 2006 Chris Robinson
4 * Copyright (C) 2006-2007 Stefan Dösinger(For CodeWeavers)
5 * Copyright 2007 Henri Verbeet
6 * Copyright (C) 2008 Rico Schüller
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define COBJMACROS
24 #include <windowsx.h>
25 #include <d3d9.h>
26 #include "wine/test.h"
28 static INT screen_width;
29 static INT screen_height;
31 static IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT);
33 static int get_refcount(IUnknown *object)
35 IUnknown_AddRef( object );
36 return IUnknown_Release( object );
39 /* try to make sure pending X events have been processed before continuing */
40 static void flush_events(void)
42 MSG msg;
43 int diff = 200;
44 int min_timeout = 100;
45 DWORD time = GetTickCount() + diff;
47 while (diff > 0)
49 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
50 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
51 diff = time - GetTickCount();
55 static IDirect3DDevice9 *create_device(IDirect3D9 *d3d9, HWND device_window, HWND focus_window, BOOL windowed)
57 D3DPRESENT_PARAMETERS present_parameters = {0};
58 IDirect3DDevice9 *device;
60 present_parameters.Windowed = windowed;
61 present_parameters.hDeviceWindow = device_window;
62 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
63 present_parameters.BackBufferWidth = screen_width;
64 present_parameters.BackBufferHeight = screen_height;
65 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
66 present_parameters.EnableAutoDepthStencil = TRUE;
67 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
69 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
70 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
72 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
73 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
74 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
76 if (SUCCEEDED(IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, focus_window,
77 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device))) return device;
79 return NULL;
82 static HRESULT reset_device(IDirect3DDevice9 *device, HWND device_window, BOOL windowed)
84 D3DPRESENT_PARAMETERS present_parameters = {0};
86 present_parameters.Windowed = windowed;
87 present_parameters.hDeviceWindow = device_window;
88 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
89 present_parameters.BackBufferWidth = screen_width;
90 present_parameters.BackBufferHeight = screen_height;
91 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
92 present_parameters.EnableAutoDepthStencil = TRUE;
93 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
95 return IDirect3DDevice9_Reset(device, &present_parameters);
98 #define CHECK_CALL(r,c,d,rc) \
99 if (SUCCEEDED(r)) {\
100 int tmp1 = get_refcount( (IUnknown *)d ); \
101 int rc_new = rc; \
102 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
103 } else {\
104 trace("%s failed: %08x\n", c, r); \
107 #define CHECK_RELEASE(obj,d,rc) \
108 if (obj) { \
109 int tmp1, rc_new = rc; \
110 IUnknown_Release( obj ); \
111 tmp1 = get_refcount( (IUnknown *)d ); \
112 ok(tmp1 == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, tmp1); \
115 #define CHECK_REFCOUNT(obj,rc) \
117 int rc_new = rc; \
118 int count = get_refcount( (IUnknown *)obj ); \
119 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
122 #define CHECK_RELEASE_REFCOUNT(obj,rc) \
124 int rc_new = rc; \
125 int count = IUnknown_Release( (IUnknown *)obj ); \
126 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
129 #define CHECK_ADDREF_REFCOUNT(obj,rc) \
131 int rc_new = rc; \
132 int count = IUnknown_AddRef( (IUnknown *)obj ); \
133 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
136 #define CHECK_SURFACE_CONTAINER(obj,iid,expected) \
138 void *container_ptr = (void *)0x1337c0d3; \
139 hr = IDirect3DSurface9_GetContainer(obj, &iid, &container_ptr); \
140 ok(SUCCEEDED(hr) && container_ptr == expected, "GetContainer returned: hr %#x, container_ptr %p. " \
141 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, expected); \
142 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr); \
145 static void check_mipmap_levels(IDirect3DDevice9 *device, UINT width, UINT height, UINT count)
147 IDirect3DBaseTexture9* texture = NULL;
148 HRESULT hr = IDirect3DDevice9_CreateTexture( device, width, height, 0, 0,
149 D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture9**) &texture, NULL );
151 if (SUCCEEDED(hr)) {
152 DWORD levels = IDirect3DBaseTexture9_GetLevelCount(texture);
153 ok(levels == count, "Invalid level count. Expected %d got %u\n", count, levels);
154 } else
155 trace("CreateTexture failed: %08x\n", hr);
157 if (texture) IUnknown_Release( texture );
160 static void test_mipmap_levels(void)
163 HRESULT hr;
164 HWND hwnd = NULL;
166 IDirect3D9 *pD3d = NULL;
167 IDirect3DDevice9 *pDevice = NULL;
168 D3DPRESENT_PARAMETERS d3dpp;
169 D3DDISPLAYMODE d3ddm;
171 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
172 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
173 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
174 ok(hwnd != NULL, "Failed to create window\n");
175 if (!pD3d || !hwnd) goto cleanup;
177 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
178 ZeroMemory( &d3dpp, sizeof(d3dpp) );
179 d3dpp.Windowed = TRUE;
180 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
181 d3dpp.BackBufferFormat = d3ddm.Format;
183 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, hwnd,
184 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
185 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to create IDirect3D9Device (%08x)\n", hr);
186 if (FAILED(hr)) {
187 skip("failed to create a d3d device\n");
188 goto cleanup;
191 check_mipmap_levels(pDevice, 32, 32, 6);
192 check_mipmap_levels(pDevice, 256, 1, 9);
193 check_mipmap_levels(pDevice, 1, 256, 9);
194 check_mipmap_levels(pDevice, 1, 1, 1);
196 cleanup:
197 if (pDevice)
199 UINT refcount = IUnknown_Release( pDevice );
200 ok(!refcount, "Device has %u references left.\n", refcount);
202 if (pD3d) IUnknown_Release( pD3d );
203 DestroyWindow( hwnd );
206 static void test_checkdevicemultisampletype(void)
209 HRESULT hr;
210 HWND hwnd = NULL;
212 IDirect3D9 *pD3d = NULL;
213 IDirect3DDevice9 *pDevice = NULL;
214 D3DPRESENT_PARAMETERS d3dpp;
215 D3DDISPLAYMODE d3ddm;
216 DWORD qualityLevels;
218 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
219 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
220 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
221 ok(hwnd != NULL, "Failed to create window\n");
222 if (!pD3d || !hwnd) goto cleanup;
224 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
225 ZeroMemory( &d3dpp, sizeof(d3dpp) );
226 d3dpp.Windowed = TRUE;
227 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
228 d3dpp.BackBufferFormat = d3ddm.Format;
230 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, hwnd,
231 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
232 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "Failed to create IDirect3D9Device (%08x)\n", hr);
233 if (FAILED(hr)) {
234 skip("failed to create a d3d device\n");
235 goto cleanup;
238 qualityLevels = 0;
240 hr = IDirect3D9_CheckDeviceMultiSampleType(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, TRUE,
241 D3DMULTISAMPLE_NONE, &qualityLevels);
242 ok(SUCCEEDED(hr) || hr == D3DERR_NOTAVAILABLE, "CheckDeviceMultiSampleType failed with (%08x)\n", hr);
243 if(hr == D3DERR_NOTAVAILABLE)
245 skip("IDirect3D9_CheckDeviceMultiSampleType not available\n");
246 goto cleanup;
248 ok(qualityLevels == 1,"qualitylevel is not 1 but %d\n",qualityLevels);
250 hr = IDirect3D9_CheckDeviceMultiSampleType(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, FALSE,
251 D3DMULTISAMPLE_NONE, &qualityLevels);
252 ok(SUCCEEDED(hr), "CheckDeviceMultiSampleType failed with (%08x)\n", hr);
253 ok(qualityLevels == 1,"qualitylevel is not 1 but %d\n",qualityLevels);
255 cleanup:
256 if (pDevice)
258 UINT refcount = IUnknown_Release( pDevice );
259 ok(!refcount, "Device has %u references left.\n", refcount);
261 if (pD3d) IUnknown_Release( pD3d );
262 DestroyWindow( hwnd );
265 static void test_swapchain(void)
267 HRESULT hr;
268 HWND hwnd = NULL;
269 IDirect3D9 *pD3d = NULL;
270 IDirect3DDevice9 *pDevice = NULL;
271 IDirect3DSwapChain9 *swapchain0 = NULL;
272 IDirect3DSwapChain9 *swapchain1 = NULL;
273 IDirect3DSwapChain9 *swapchain2 = NULL;
274 IDirect3DSwapChain9 *swapchain3 = NULL;
275 IDirect3DSwapChain9 *swapchainX = NULL;
276 IDirect3DSurface9 *backbuffer = NULL;
277 D3DPRESENT_PARAMETERS d3dpp;
278 D3DDISPLAYMODE d3ddm;
280 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
281 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
282 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
283 ok(hwnd != NULL, "Failed to create window\n");
284 if (!pD3d || !hwnd) goto cleanup;
286 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
287 ZeroMemory( &d3dpp, sizeof(d3dpp) );
288 d3dpp.Windowed = TRUE;
289 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
290 d3dpp.BackBufferFormat = d3ddm.Format;
291 d3dpp.BackBufferCount = 0;
293 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
294 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
295 ok(hr == S_OK || hr == D3DERR_NOTAVAILABLE,
296 "Failed to create IDirect3D9Device (%08x)\n", hr);
297 if (FAILED(hr)) goto cleanup;
299 /* Check if the back buffer count was modified */
300 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
302 /* Get the implicit swapchain */
303 hr = IDirect3DDevice9_GetSwapChain(pDevice, 0, &swapchain0);
304 ok(SUCCEEDED(hr), "Failed to get the implicit swapchain (%08x)\n", hr);
305 if(swapchain0) IDirect3DSwapChain9_Release(swapchain0);
307 /* Check if there is a back buffer */
308 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
309 ok(SUCCEEDED(hr), "Failed to get the back buffer (%08x)\n", hr);
310 ok(backbuffer != NULL, "The back buffer is NULL\n");
311 if(backbuffer) IDirect3DSurface9_Release(backbuffer);
313 /* Try to get a nonexistent swapchain */
314 hr = IDirect3DDevice9_GetSwapChain(pDevice, 1, &swapchainX);
315 ok(hr == D3DERR_INVALIDCALL, "GetSwapChain on an nonexistent swapchain returned (%08x)\n", hr);
316 ok(swapchainX == NULL, "Swapchain 1 is %p\n", swapchainX);
317 if(swapchainX) IDirect3DSwapChain9_Release(swapchainX);
319 /* Create a bunch of swapchains */
320 d3dpp.BackBufferCount = 0;
321 hr = IDirect3DDevice9_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain1);
322 ok(SUCCEEDED(hr), "Failed to create a swapchain (%08x)\n", hr);
323 ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
325 d3dpp.BackBufferCount = 1;
326 hr = IDirect3DDevice9_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain2);
327 ok(SUCCEEDED(hr), "Failed to create a swapchain (%08x)\n", hr);
329 d3dpp.BackBufferCount = 2;
330 hr = IDirect3DDevice9_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain3);
331 ok(SUCCEEDED(hr), "Failed to create a swapchain (%08x)\n", hr);
332 if(SUCCEEDED(hr)) {
333 /* Swapchain 3, created with backbuffercount 2 */
334 backbuffer = (void *) 0xdeadbeef;
335 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
336 ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%08x)\n", hr);
337 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
338 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
340 backbuffer = (void *) 0xdeadbeef;
341 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
342 ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%08x)\n", hr);
343 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
344 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
346 backbuffer = (void *) 0xdeadbeef;
347 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
348 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %08x\n", hr);
349 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
350 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
352 backbuffer = (void *) 0xdeadbeef;
353 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
354 ok(FAILED(hr), "Failed to get the back buffer (%08x)\n", hr);
355 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
356 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
359 /* Check the back buffers of the swapchains */
360 /* Swapchain 1, created with backbuffercount 0 */
361 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
362 ok(SUCCEEDED(hr), "Failed to get the back buffer (%08x)\n", hr);
363 ok(backbuffer != NULL, "The back buffer is NULL (%08x)\n", hr);
364 if(backbuffer) IDirect3DSurface9_Release(backbuffer);
366 backbuffer = (void *) 0xdeadbeef;
367 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
368 ok(FAILED(hr), "Failed to get the back buffer (%08x)\n", hr);
369 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
370 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
372 /* Swapchain 2 - created with backbuffercount 1 */
373 backbuffer = (void *) 0xdeadbeef;
374 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
375 ok(SUCCEEDED(hr), "Failed to get the back buffer (%08x)\n", hr);
376 ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
377 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
379 backbuffer = (void *) 0xdeadbeef;
380 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
381 ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %08x\n", hr);
382 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
383 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
385 backbuffer = (void *) 0xdeadbeef;
386 hr = IDirect3DSwapChain9_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
387 ok(FAILED(hr), "Failed to get the back buffer (%08x)\n", hr);
388 ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
389 if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
391 /* Try getSwapChain on a manually created swapchain
392 * it should fail, apparently GetSwapChain only returns implicit swapchains
394 swapchainX = (void *) 0xdeadbeef;
395 hr = IDirect3DDevice9_GetSwapChain(pDevice, 1, &swapchainX);
396 ok(hr == D3DERR_INVALIDCALL, "Failed to get the second swapchain (%08x)\n", hr);
397 ok(swapchainX == NULL, "The swapchain pointer is %p\n", swapchainX);
398 if(swapchainX && swapchainX != (void *) 0xdeadbeef ) IDirect3DSwapChain9_Release(swapchainX);
400 cleanup:
401 if(swapchain1) IDirect3DSwapChain9_Release(swapchain1);
402 if(swapchain2) IDirect3DSwapChain9_Release(swapchain2);
403 if(swapchain3) IDirect3DSwapChain9_Release(swapchain3);
404 if (pDevice)
406 UINT refcount = IDirect3DDevice9_Release(pDevice);
407 ok(!refcount, "Device has %u references left.\n", refcount);
409 if (pD3d) IDirect3D9_Release(pD3d);
410 DestroyWindow( hwnd );
413 /* Shared between two functions */
414 static const DWORD simple_vs[] = {0xFFFE0101, /* vs_1_1 */
415 0x0000001F, 0x80000000, 0x900F0000, /* dcl_position0 v0 */
416 0x00000009, 0xC0010000, 0x90E40000, 0xA0E40000, /* dp4 oPos.x, v0, c0 */
417 0x00000009, 0xC0020000, 0x90E40000, 0xA0E40001, /* dp4 oPos.y, v0, c1 */
418 0x00000009, 0xC0040000, 0x90E40000, 0xA0E40002, /* dp4 oPos.z, v0, c2 */
419 0x00000009, 0xC0080000, 0x90E40000, 0xA0E40003, /* dp4 oPos.w, v0, c3 */
420 0x0000FFFF}; /* END */
422 static void test_refcount(void)
424 HRESULT hr;
425 HWND hwnd = NULL;
426 IDirect3D9 *pD3d = NULL;
427 IDirect3D9 *pD3d2 = NULL;
428 IDirect3DDevice9 *pDevice = NULL;
429 IDirect3DVertexBuffer9 *pVertexBuffer = NULL;
430 IDirect3DIndexBuffer9 *pIndexBuffer = NULL;
431 IDirect3DVertexDeclaration9 *pVertexDeclaration = NULL;
432 IDirect3DVertexShader9 *pVertexShader = NULL;
433 IDirect3DPixelShader9 *pPixelShader = NULL;
434 IDirect3DCubeTexture9 *pCubeTexture = NULL;
435 IDirect3DTexture9 *pTexture = NULL;
436 IDirect3DVolumeTexture9 *pVolumeTexture = NULL;
437 IDirect3DVolume9 *pVolumeLevel = NULL;
438 IDirect3DSurface9 *pStencilSurface = NULL;
439 IDirect3DSurface9 *pOffscreenSurface = NULL;
440 IDirect3DSurface9 *pRenderTarget = NULL;
441 IDirect3DSurface9 *pRenderTarget2 = NULL;
442 IDirect3DSurface9 *pRenderTarget3 = NULL;
443 IDirect3DSurface9 *pTextureLevel = NULL;
444 IDirect3DSurface9 *pBackBuffer = NULL;
445 IDirect3DStateBlock9 *pStateBlock = NULL;
446 IDirect3DStateBlock9 *pStateBlock1 = NULL;
447 IDirect3DSwapChain9 *pSwapChain = NULL;
448 IDirect3DQuery9 *pQuery = NULL;
449 D3DPRESENT_PARAMETERS d3dpp;
450 D3DDISPLAYMODE d3ddm;
451 int refcount = 0, tmp;
453 D3DVERTEXELEMENT9 decl[] =
455 D3DDECL_END()
457 static DWORD simple_ps[] = {0xFFFF0101, /* ps_1_1 */
458 0x00000051, 0xA00F0001, 0x3F800000, 0x00000000, 0x00000000, 0x00000000, /* def c1 = 1.0, 0.0, 0.0, 0.0 */
459 0x00000042, 0xB00F0000, /* tex t0 */
460 0x00000008, 0x800F0000, 0xA0E40001, 0xA0E40000, /* dp3 r0, c1, c0 */
461 0x00000005, 0x800F0000, 0x90E40000, 0x80E40000, /* mul r0, v0, r0 */
462 0x00000005, 0x800F0000, 0xB0E40000, 0x80E40000, /* mul r0, t0, r0 */
463 0x0000FFFF}; /* END */
466 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
467 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
468 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
469 ok(hwnd != NULL, "Failed to create window\n");
470 if (!pD3d || !hwnd) goto cleanup;
472 CHECK_REFCOUNT( pD3d, 1 );
474 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
475 ZeroMemory( &d3dpp, sizeof(d3dpp) );
476 d3dpp.Windowed = TRUE;
477 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
478 d3dpp.BackBufferFormat = d3ddm.Format;
479 d3dpp.EnableAutoDepthStencil = TRUE;
480 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
482 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
483 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
484 ok(hr == S_OK || hr == D3DERR_NOTAVAILABLE,
485 "Failed to create IDirect3D9Device (%08x)\n", hr);
486 if (FAILED(hr)) goto cleanup;
488 refcount = get_refcount( (IUnknown *)pDevice );
489 ok(refcount == 1, "Invalid device RefCount %d\n", refcount);
491 CHECK_REFCOUNT( pD3d, 2 );
493 hr = IDirect3DDevice9_GetDirect3D(pDevice, &pD3d2);
494 CHECK_CALL( hr, "GetDirect3D", pDevice, refcount );
496 ok(pD3d2 == pD3d, "Expected IDirect3D9 pointers to be equal\n");
497 CHECK_REFCOUNT( pD3d, 3 );
498 CHECK_RELEASE_REFCOUNT( pD3d, 2 );
501 * Check refcount of implicit surfaces and implicit swapchain. Findings:
502 * - the container is the device OR swapchain
503 * - they hold a reference to the device
504 * - they are created with a refcount of 0 (Get/Release returns original refcount)
505 * - they are not freed if refcount reaches 0.
506 * - the refcount is not forwarded to the container.
508 hr = IDirect3DDevice9_GetSwapChain(pDevice, 0, &pSwapChain);
509 CHECK_CALL( hr, "GetSwapChain", pDevice, ++refcount);
510 if (pSwapChain)
512 CHECK_REFCOUNT( pSwapChain, 1);
514 hr = IDirect3DDevice9_GetRenderTarget(pDevice, 0, &pRenderTarget);
515 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
516 CHECK_REFCOUNT( pSwapChain, 1);
517 if(pRenderTarget)
519 CHECK_SURFACE_CONTAINER( pRenderTarget, IID_IDirect3DSwapChain9, pSwapChain);
520 CHECK_REFCOUNT( pRenderTarget, 1);
522 CHECK_ADDREF_REFCOUNT(pRenderTarget, 2);
523 CHECK_REFCOUNT(pDevice, refcount);
524 CHECK_RELEASE_REFCOUNT(pRenderTarget, 1);
525 CHECK_REFCOUNT(pDevice, refcount);
527 hr = IDirect3DDevice9_GetRenderTarget(pDevice, 0, &pRenderTarget);
528 CHECK_CALL( hr, "GetRenderTarget", pDevice, refcount);
529 CHECK_REFCOUNT( pRenderTarget, 2);
530 CHECK_RELEASE_REFCOUNT( pRenderTarget, 1);
531 CHECK_RELEASE_REFCOUNT( pRenderTarget, 0);
532 CHECK_REFCOUNT( pDevice, --refcount);
534 /* The render target is released with the device, so AddRef with refcount=0 is fine here. */
535 CHECK_ADDREF_REFCOUNT(pRenderTarget, 1);
536 CHECK_REFCOUNT(pDevice, ++refcount);
537 CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
538 CHECK_REFCOUNT(pDevice, --refcount);
541 /* Render target and back buffer are identical. */
542 hr = IDirect3DDevice9_GetBackBuffer(pDevice, 0, 0, 0, &pBackBuffer);
543 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
544 if(pBackBuffer)
546 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
547 ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
548 pRenderTarget, pBackBuffer);
549 pBackBuffer = NULL;
551 CHECK_REFCOUNT( pDevice, --refcount);
553 hr = IDirect3DDevice9_GetDepthStencilSurface(pDevice, &pStencilSurface);
554 CHECK_CALL( hr, "GetDepthStencilSurface", pDevice, ++refcount);
555 CHECK_REFCOUNT( pSwapChain, 1);
556 if(pStencilSurface)
558 CHECK_SURFACE_CONTAINER( pStencilSurface, IID_IDirect3DDevice9, pDevice);
559 CHECK_REFCOUNT( pStencilSurface, 1);
561 CHECK_ADDREF_REFCOUNT(pStencilSurface, 2);
562 CHECK_REFCOUNT(pDevice, refcount);
563 CHECK_RELEASE_REFCOUNT(pStencilSurface, 1);
564 CHECK_REFCOUNT(pDevice, refcount);
566 CHECK_RELEASE_REFCOUNT( pStencilSurface, 0);
567 CHECK_REFCOUNT( pDevice, --refcount);
569 /* The stencil surface is released with the device, so AddRef with refcount=0 is fine here. */
570 CHECK_ADDREF_REFCOUNT(pStencilSurface, 1);
571 CHECK_REFCOUNT(pDevice, ++refcount);
572 CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
573 CHECK_REFCOUNT(pDevice, --refcount);
574 pStencilSurface = NULL;
577 CHECK_RELEASE_REFCOUNT( pSwapChain, 0);
578 CHECK_REFCOUNT( pDevice, --refcount);
580 /* The implicit swapchwin is released with the device, so AddRef with refcount=0 is fine here. */
581 CHECK_ADDREF_REFCOUNT(pSwapChain, 1);
582 CHECK_REFCOUNT(pDevice, ++refcount);
583 CHECK_RELEASE_REFCOUNT(pSwapChain, 0);
584 CHECK_REFCOUNT(pDevice, --refcount);
585 pSwapChain = NULL;
588 /* Buffers */
589 hr = IDirect3DDevice9_CreateIndexBuffer( pDevice, 16, 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &pIndexBuffer, NULL );
590 CHECK_CALL( hr, "CreateIndexBuffer", pDevice, ++refcount );
591 if(pIndexBuffer)
593 tmp = get_refcount( (IUnknown *)pIndexBuffer );
595 hr = IDirect3DDevice9_SetIndices(pDevice, pIndexBuffer);
596 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
597 hr = IDirect3DDevice9_SetIndices(pDevice, NULL);
598 CHECK_CALL( hr, "SetIndices", pIndexBuffer, tmp);
601 hr = IDirect3DDevice9_CreateVertexBuffer( pDevice, 16, 0, D3DFVF_XYZ, D3DPOOL_DEFAULT, &pVertexBuffer, NULL );
602 CHECK_CALL( hr, "CreateVertexBuffer", pDevice, ++refcount );
603 if(pVertexBuffer)
605 IDirect3DVertexBuffer9 *pVBuf = (void*)~0;
606 UINT offset = ~0;
607 UINT stride = ~0;
609 tmp = get_refcount( (IUnknown *)pVertexBuffer );
611 hr = IDirect3DDevice9_SetStreamSource(pDevice, 0, pVertexBuffer, 0, 3 * sizeof(float));
612 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
613 hr = IDirect3DDevice9_SetStreamSource(pDevice, 0, NULL, 0, 0);
614 CHECK_CALL( hr, "SetStreamSource", pVertexBuffer, tmp);
616 hr = IDirect3DDevice9_GetStreamSource(pDevice, 0, &pVBuf, &offset, &stride);
617 ok(SUCCEEDED(hr), "GetStreamSource did not succeed with NULL stream!\n");
618 ok(pVBuf==NULL, "pVBuf not NULL (%p)!\n", pVBuf);
619 ok(stride==3*sizeof(float), "stride not 3 floats (got %u)!\n", stride);
620 ok(offset==0, "offset not 0 (got %u)!\n", offset);
622 /* Shaders */
623 hr = IDirect3DDevice9_CreateVertexDeclaration( pDevice, decl, &pVertexDeclaration );
624 CHECK_CALL( hr, "CreateVertexDeclaration", pDevice, ++refcount );
625 hr = IDirect3DDevice9_CreateVertexShader( pDevice, simple_vs, &pVertexShader );
626 CHECK_CALL( hr, "CreateVertexShader", pDevice, ++refcount );
627 hr = IDirect3DDevice9_CreatePixelShader( pDevice, simple_ps, &pPixelShader );
628 CHECK_CALL( hr, "CreatePixelShader", pDevice, ++refcount );
629 /* Textures */
630 hr = IDirect3DDevice9_CreateTexture( pDevice, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pTexture, NULL );
631 CHECK_CALL( hr, "CreateTexture", pDevice, ++refcount );
632 if (pTexture)
634 tmp = get_refcount( (IUnknown *)pTexture );
636 /* SetTexture should not increase refcounts */
637 hr = IDirect3DDevice9_SetTexture(pDevice, 0, (IDirect3DBaseTexture9 *) pTexture);
638 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
639 hr = IDirect3DDevice9_SetTexture(pDevice, 0, NULL);
640 CHECK_CALL( hr, "SetTexture", pTexture, tmp);
642 /* This should not increment device refcount */
643 hr = IDirect3DTexture9_GetSurfaceLevel( pTexture, 1, &pTextureLevel );
644 CHECK_CALL( hr, "GetSurfaceLevel", pDevice, refcount );
645 /* But should increment texture's refcount */
646 CHECK_REFCOUNT( pTexture, tmp+1 );
647 /* Because the texture and surface refcount are identical */
648 if (pTextureLevel)
650 CHECK_REFCOUNT ( pTextureLevel, tmp+1 );
651 CHECK_ADDREF_REFCOUNT ( pTextureLevel, tmp+2 );
652 CHECK_REFCOUNT ( pTexture , tmp+2 );
653 CHECK_RELEASE_REFCOUNT( pTextureLevel, tmp+1 );
654 CHECK_REFCOUNT ( pTexture , tmp+1 );
655 CHECK_RELEASE_REFCOUNT( pTexture , tmp );
656 CHECK_REFCOUNT ( pTextureLevel, tmp );
659 hr = IDirect3DDevice9_CreateCubeTexture( pDevice, 32, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pCubeTexture, NULL );
660 CHECK_CALL( hr, "CreateCubeTexture", pDevice, ++refcount );
661 hr = IDirect3DDevice9_CreateVolumeTexture( pDevice, 32, 32, 2, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pVolumeTexture, NULL );
662 CHECK_CALL( hr, "CreateVolumeTexture", pDevice, ++refcount );
663 if (pVolumeTexture)
665 tmp = get_refcount( (IUnknown *)pVolumeTexture );
667 /* This should not increment device refcount */
668 hr = IDirect3DVolumeTexture9_GetVolumeLevel(pVolumeTexture, 0, &pVolumeLevel);
669 CHECK_CALL( hr, "GetVolumeLevel", pDevice, refcount );
670 /* But should increment volume texture's refcount */
671 CHECK_REFCOUNT( pVolumeTexture, tmp+1 );
672 /* Because the volume texture and volume refcount are identical */
673 if (pVolumeLevel)
675 CHECK_REFCOUNT ( pVolumeLevel , tmp+1 );
676 CHECK_ADDREF_REFCOUNT ( pVolumeLevel , tmp+2 );
677 CHECK_REFCOUNT ( pVolumeTexture, tmp+2 );
678 CHECK_RELEASE_REFCOUNT( pVolumeLevel , tmp+1 );
679 CHECK_REFCOUNT ( pVolumeTexture, tmp+1 );
680 CHECK_RELEASE_REFCOUNT( pVolumeTexture, tmp );
681 CHECK_REFCOUNT ( pVolumeLevel , tmp );
684 /* Surfaces */
685 hr = IDirect3DDevice9_CreateDepthStencilSurface( pDevice, 32, 32, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, TRUE, &pStencilSurface, NULL );
686 CHECK_CALL( hr, "CreateDepthStencilSurface", pDevice, ++refcount );
687 CHECK_REFCOUNT( pStencilSurface, 1 );
688 hr = IDirect3DDevice9_CreateOffscreenPlainSurface( pDevice, 32, 32, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &pOffscreenSurface, NULL );
689 CHECK_CALL( hr, "CreateOffscreenPlainSurface", pDevice, ++refcount );
690 CHECK_REFCOUNT( pOffscreenSurface, 1 );
691 hr = IDirect3DDevice9_CreateRenderTarget( pDevice, 32, 32, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &pRenderTarget3, NULL );
692 CHECK_CALL( hr, "CreateRenderTarget", pDevice, ++refcount );
693 CHECK_REFCOUNT( pRenderTarget3, 1 );
694 /* Misc */
695 hr = IDirect3DDevice9_CreateStateBlock( pDevice, D3DSBT_ALL, &pStateBlock );
696 CHECK_CALL( hr, "CreateStateBlock", pDevice, ++refcount );
697 hr = IDirect3DDevice9_CreateAdditionalSwapChain( pDevice, &d3dpp, &pSwapChain );
698 CHECK_CALL( hr, "CreateAdditionalSwapChain", pDevice, ++refcount );
699 if(pSwapChain)
701 /* check implicit back buffer */
702 hr = IDirect3DSwapChain9_GetBackBuffer(pSwapChain, 0, 0, &pBackBuffer);
703 CHECK_CALL( hr, "GetBackBuffer", pDevice, ++refcount);
704 CHECK_REFCOUNT( pSwapChain, 1);
705 if(pBackBuffer)
707 CHECK_SURFACE_CONTAINER( pBackBuffer, IID_IDirect3DSwapChain9, pSwapChain);
708 CHECK_REFCOUNT( pBackBuffer, 1);
709 CHECK_RELEASE_REFCOUNT( pBackBuffer, 0);
710 CHECK_REFCOUNT( pDevice, --refcount);
712 /* The back buffer is released with the swapchain, so AddRef with refcount=0 is fine here. */
713 CHECK_ADDREF_REFCOUNT(pBackBuffer, 1);
714 CHECK_REFCOUNT(pDevice, ++refcount);
715 CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
716 CHECK_REFCOUNT(pDevice, --refcount);
717 pBackBuffer = NULL;
719 CHECK_REFCOUNT( pSwapChain, 1);
721 hr = IDirect3DDevice9_CreateQuery( pDevice, D3DQUERYTYPE_EVENT, &pQuery );
722 CHECK_CALL( hr, "CreateQuery", pDevice, ++refcount );
724 hr = IDirect3DDevice9_BeginStateBlock( pDevice );
725 CHECK_CALL( hr, "BeginStateBlock", pDevice, refcount );
726 hr = IDirect3DDevice9_EndStateBlock( pDevice, &pStateBlock1 );
727 CHECK_CALL( hr, "EndStateBlock", pDevice, ++refcount );
729 /* The implicit render target is not freed if refcount reaches 0.
730 * Otherwise GetRenderTarget would re-allocate it and the pointer would change.*/
731 hr = IDirect3DDevice9_GetRenderTarget(pDevice, 0, &pRenderTarget2);
732 CHECK_CALL( hr, "GetRenderTarget", pDevice, ++refcount);
733 if(pRenderTarget2)
735 CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
736 ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
737 pRenderTarget, pRenderTarget2);
738 CHECK_REFCOUNT( pDevice, --refcount);
739 pRenderTarget2 = NULL;
741 pRenderTarget = NULL;
743 cleanup:
744 CHECK_RELEASE(pDevice, pDevice, --refcount);
746 /* Buffers */
747 CHECK_RELEASE(pVertexBuffer, pDevice, --refcount);
748 CHECK_RELEASE(pIndexBuffer, pDevice, --refcount);
749 /* Shaders */
750 CHECK_RELEASE(pVertexDeclaration, pDevice, --refcount);
751 CHECK_RELEASE(pVertexShader, pDevice, --refcount);
752 CHECK_RELEASE(pPixelShader, pDevice, --refcount);
753 /* Textures */
754 CHECK_RELEASE(pTextureLevel, pDevice, --refcount);
755 CHECK_RELEASE(pCubeTexture, pDevice, --refcount);
756 CHECK_RELEASE(pVolumeTexture, pDevice, --refcount);
757 /* Surfaces */
758 CHECK_RELEASE(pStencilSurface, pDevice, --refcount);
759 CHECK_RELEASE(pOffscreenSurface, pDevice, --refcount);
760 CHECK_RELEASE(pRenderTarget3, pDevice, --refcount);
761 /* Misc */
762 CHECK_RELEASE(pStateBlock, pDevice, --refcount);
763 CHECK_RELEASE(pSwapChain, pDevice, --refcount);
764 CHECK_RELEASE(pQuery, pDevice, --refcount);
765 /* This will destroy device - cannot check the refcount here */
766 if (pStateBlock1) CHECK_RELEASE_REFCOUNT( pStateBlock1, 0);
768 if (pD3d) CHECK_RELEASE_REFCOUNT( pD3d, 0);
770 DestroyWindow( hwnd );
773 static void test_cursor(void)
775 HRESULT hr;
776 HWND hwnd = NULL;
777 IDirect3D9 *pD3d = NULL;
778 IDirect3DDevice9 *pDevice = NULL;
779 D3DPRESENT_PARAMETERS d3dpp;
780 D3DDISPLAYMODE d3ddm;
781 CURSORINFO info;
782 IDirect3DSurface9 *cursor = NULL;
783 HCURSOR cur;
785 memset(&info, 0, sizeof(info));
786 info.cbSize = sizeof(info);
787 ok(GetCursorInfo(&info), "GetCursorInfo failed\n");
788 cur = info.hCursor;
790 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
791 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
792 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
793 ok(hwnd != NULL, "Failed to create window\n");
794 if (!pD3d || !hwnd) goto cleanup;
796 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
797 ZeroMemory( &d3dpp, sizeof(d3dpp) );
798 d3dpp.Windowed = TRUE;
799 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
800 d3dpp.BackBufferFormat = d3ddm.Format;
802 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
803 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
804 ok(hr == S_OK || hr == D3DERR_NOTAVAILABLE,
805 "Failed to create IDirect3D9Device (%08x)\n", hr);
806 if (FAILED(hr)) goto cleanup;
808 IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice, 32, 32, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &cursor, 0);
809 ok(cursor != NULL, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr);
811 /* Initially hidden */
812 hr = IDirect3DDevice9_ShowCursor(pDevice, TRUE);
813 ok(hr == FALSE, "IDirect3DDevice9_ShowCursor returned %08x\n", hr);
815 /* Not enabled without a surface*/
816 hr = IDirect3DDevice9_ShowCursor(pDevice, TRUE);
817 ok(hr == FALSE, "IDirect3DDevice9_ShowCursor returned %08x\n", hr);
819 /* Fails */
820 hr = IDirect3DDevice9_SetCursorProperties(pDevice, 0, 0, NULL);
821 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr);
823 hr = IDirect3DDevice9_SetCursorProperties(pDevice, 0, 0, cursor);
824 ok(hr == D3D_OK, "IDirect3DDevice9_SetCursorProperties returned %08x\n", hr);
826 IDirect3DSurface9_Release(cursor);
828 memset(&info, 0, sizeof(info));
829 info.cbSize = sizeof(info);
830 ok(GetCursorInfo(&info), "GetCursorInfo failed\n");
831 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
832 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
834 /* Still hidden */
835 hr = IDirect3DDevice9_ShowCursor(pDevice, TRUE);
836 ok(hr == FALSE, "IDirect3DDevice9_ShowCursor returned %08x\n", hr);
838 /* Enabled now*/
839 hr = IDirect3DDevice9_ShowCursor(pDevice, TRUE);
840 ok(hr == TRUE, "IDirect3DDevice9_ShowCursor returned %08x\n", hr);
842 /* GDI cursor unchanged */
843 memset(&info, 0, sizeof(info));
844 info.cbSize = sizeof(info);
845 ok(GetCursorInfo(&info), "GetCursorInfo failed\n");
846 ok(info.flags & CURSOR_SHOWING, "The gdi cursor is hidden (%08x)\n", info.flags);
847 ok(info.hCursor == cur, "The cursor handle is %p\n", info.hCursor); /* unchanged */
849 cleanup:
850 if (pDevice)
852 UINT refcount = IDirect3DDevice9_Release(pDevice);
853 ok(!refcount, "Device has %u references left.\n", refcount);
855 if (pD3d) IDirect3D9_Release(pD3d);
856 DestroyWindow( hwnd );
859 static void test_reset(void)
861 HRESULT hr;
862 HWND hwnd = NULL;
863 IDirect3D9 *pD3d = NULL;
864 D3DPRESENT_PARAMETERS d3dpp;
865 D3DDISPLAYMODE d3ddm, d3ddm2;
866 D3DVIEWPORT9 vp;
867 DWORD width, orig_width = GetSystemMetrics(SM_CXSCREEN);
868 DWORD height, orig_height = GetSystemMetrics(SM_CYSCREEN);
869 IDirect3DSwapChain9 *pSwapchain;
870 IDirect3DSurface9 *surface;
871 IDirect3DTexture9 *texture;
872 IDirect3DVertexShader9 *shader;
873 UINT i, adapter_mode_count;
874 D3DLOCKED_RECT lockrect;
875 IDirect3DDevice9 *device1 = NULL;
876 IDirect3DDevice9 *device2 = NULL;
877 D3DCAPS9 caps;
878 struct
880 UINT w;
881 UINT h;
882 } *modes = NULL;
883 UINT mode_count = 0;
885 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
886 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
887 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
888 ok(hwnd != NULL, "Failed to create window\n");
889 if (!pD3d || !hwnd) goto cleanup;
891 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
892 adapter_mode_count = IDirect3D9_GetAdapterModeCount(pD3d, D3DADAPTER_DEFAULT, d3ddm.Format);
893 modes = HeapAlloc(GetProcessHeap(), 0, sizeof(*modes) * adapter_mode_count);
894 for(i = 0; i < adapter_mode_count; ++i)
896 UINT j;
897 ZeroMemory( &d3ddm2, sizeof(d3ddm2) );
898 hr = IDirect3D9_EnumAdapterModes(pD3d, D3DADAPTER_DEFAULT, d3ddm.Format, i, &d3ddm2);
899 ok(hr == D3D_OK, "IDirect3D9_EnumAdapterModes returned %#x\n", hr);
901 for (j = 0; j < mode_count; ++j)
903 if (modes[j].w == d3ddm2.Width && modes[j].h == d3ddm2.Height)
904 break;
906 if (j == mode_count)
908 modes[j].w = d3ddm2.Width;
909 modes[j].h = d3ddm2.Height;
910 ++mode_count;
913 /* We use them as invalid modes */
914 if((d3ddm2.Width == 801 && d3ddm2.Height == 600) ||
915 (d3ddm2.Width == 32 && d3ddm2.Height == 32)) {
916 skip("This system supports a screen resolution of %dx%d, not running mode tests\n",
917 d3ddm2.Width, d3ddm2.Height);
918 goto cleanup;
922 if (mode_count < 2)
924 skip("Less than 2 modes supported, skipping mode tests\n");
925 goto cleanup;
928 i = 0;
929 if (modes[i].w == orig_width && modes[i].h == orig_height) ++i;
931 ZeroMemory( &d3dpp, sizeof(d3dpp) );
932 d3dpp.Windowed = FALSE;
933 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
934 d3dpp.BackBufferWidth = modes[i].w;
935 d3dpp.BackBufferHeight = modes[i].h;
936 d3dpp.BackBufferFormat = d3ddm.Format;
937 d3dpp.EnableAutoDepthStencil = TRUE;
938 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
940 hr = IDirect3D9_CreateDevice(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
941 hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device1);
942 if (FAILED(hr))
944 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr);
945 goto cleanup;
947 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
948 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr);
950 hr = IDirect3DDevice9_GetDeviceCaps(device1, &caps);
951 ok(SUCCEEDED(hr), "GetDeviceCaps failed, hr %#x.\n", hr);
953 width = GetSystemMetrics(SM_CXSCREEN);
954 height = GetSystemMetrics(SM_CYSCREEN);
955 ok(width == modes[i].w, "Screen width is %u, expected %u\n", width, modes[i].w);
956 ok(height == modes[i].h, "Screen height is %u, expected %u\n", height, modes[i].h);
958 hr = IDirect3DDevice9_GetViewport(device1, &vp);
959 ok(hr == D3D_OK, "IDirect3DDevice9_GetViewport failed with %08x\n", hr);
960 if(SUCCEEDED(hr))
962 ok(vp.X == 0, "D3DVIEWPORT->X = %d\n", vp.X);
963 ok(vp.Y == 0, "D3DVIEWPORT->Y = %d\n", vp.Y);
964 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u\n", vp.Width, modes[i].w);
965 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u\n", vp.Height, modes[i].h);
966 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %f\n", vp.MinZ);
967 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %f\n", vp.MaxZ);
970 i = 1;
971 vp.X = 10;
972 vp.Y = 20;
973 vp.MinZ = 2;
974 vp.MaxZ = 3;
975 hr = IDirect3DDevice9_SetViewport(device1, &vp);
976 ok(hr == D3D_OK, "IDirect3DDevice9_SetViewport failed with %08x\n", hr);
978 ZeroMemory( &d3dpp, sizeof(d3dpp) );
979 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
980 d3dpp.Windowed = FALSE;
981 d3dpp.BackBufferWidth = modes[i].w;
982 d3dpp.BackBufferHeight = modes[i].h;
983 d3dpp.BackBufferFormat = d3ddm.Format;
984 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
985 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
986 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
987 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
989 ZeroMemory(&vp, sizeof(vp));
990 hr = IDirect3DDevice9_GetViewport(device1, &vp);
991 ok(hr == D3D_OK, "IDirect3DDevice9_GetViewport failed with %08x\n", hr);
992 if(SUCCEEDED(hr))
994 ok(vp.X == 0, "D3DVIEWPORT->X = %d\n", vp.X);
995 ok(vp.Y == 0, "D3DVIEWPORT->Y = %d\n", vp.Y);
996 ok(vp.Width == modes[i].w, "D3DVIEWPORT->Width = %u, expected %u\n", vp.Width, modes[i].w);
997 ok(vp.Height == modes[i].h, "D3DVIEWPORT->Height = %u, expected %u\n", vp.Height, modes[i].h);
998 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %f\n", vp.MinZ);
999 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %f\n", vp.MaxZ);
1002 width = GetSystemMetrics(SM_CXSCREEN);
1003 height = GetSystemMetrics(SM_CYSCREEN);
1004 ok(width == modes[i].w, "Screen width is %u, expected %u\n", width, modes[i].w);
1005 ok(height == modes[i].h, "Screen height is %u, expected %u\n", height, modes[i].h);
1007 hr = IDirect3DDevice9_GetSwapChain(device1, 0, &pSwapchain);
1008 ok(hr == D3D_OK, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr);
1009 if(SUCCEEDED(hr))
1011 ZeroMemory(&d3dpp, sizeof(d3dpp));
1012 hr = IDirect3DSwapChain9_GetPresentParameters(pSwapchain, &d3dpp);
1013 ok(hr == D3D_OK, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr);
1014 if(SUCCEEDED(hr))
1016 ok(d3dpp.BackBufferWidth == modes[i].w, "Back buffer width is %u, expected %u\n",
1017 d3dpp.BackBufferWidth, modes[i].w);
1018 ok(d3dpp.BackBufferHeight == modes[i].h, "Back buffer height is %u, expected %u\n",
1019 d3dpp.BackBufferHeight, modes[i].h);
1021 IDirect3DSwapChain9_Release(pSwapchain);
1024 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1025 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1026 d3dpp.Windowed = TRUE;
1027 d3dpp.BackBufferWidth = 400;
1028 d3dpp.BackBufferHeight = 300;
1029 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1030 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1031 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1032 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
1034 width = GetSystemMetrics(SM_CXSCREEN);
1035 height = GetSystemMetrics(SM_CYSCREEN);
1036 ok(width == orig_width, "Screen width is %d\n", width);
1037 ok(height == orig_height, "Screen height is %d\n", height);
1039 ZeroMemory(&vp, sizeof(vp));
1040 hr = IDirect3DDevice9_GetViewport(device1, &vp);
1041 ok(hr == D3D_OK, "IDirect3DDevice9_GetViewport failed with %08x\n", hr);
1042 if(SUCCEEDED(hr))
1044 ok(vp.X == 0, "D3DVIEWPORT->X = %d\n", vp.X);
1045 ok(vp.Y == 0, "D3DVIEWPORT->Y = %d\n", vp.Y);
1046 ok(vp.Width == 400, "D3DVIEWPORT->Width = %d\n", vp.Width);
1047 ok(vp.Height == 300, "D3DVIEWPORT->Height = %d\n", vp.Height);
1048 ok(vp.MinZ == 0, "D3DVIEWPORT->MinZ = %f\n", vp.MinZ);
1049 ok(vp.MaxZ == 1, "D3DVIEWPORT->MaxZ = %f\n", vp.MaxZ);
1052 hr = IDirect3DDevice9_GetSwapChain(device1, 0, &pSwapchain);
1053 ok(hr == D3D_OK, "IDirect3DDevice9_GetSwapChain returned %08x\n", hr);
1054 if(SUCCEEDED(hr))
1056 ZeroMemory(&d3dpp, sizeof(d3dpp));
1057 hr = IDirect3DSwapChain9_GetPresentParameters(pSwapchain, &d3dpp);
1058 ok(hr == D3D_OK, "IDirect3DSwapChain9_GetPresentParameters returned %08x\n", hr);
1059 if(SUCCEEDED(hr))
1061 ok(d3dpp.BackBufferWidth == 400, "Back buffer width is %d\n", d3dpp.BackBufferWidth);
1062 ok(d3dpp.BackBufferHeight == 300, "Back buffer height is %d\n", d3dpp.BackBufferHeight);
1064 IDirect3DSwapChain9_Release(pSwapchain);
1067 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1068 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1069 d3dpp.Windowed = TRUE;
1070 d3dpp.BackBufferWidth = 400;
1071 d3dpp.BackBufferHeight = 300;
1073 /* _Reset fails if there is a resource in the default pool */
1074 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device1, 16, 16, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &surface, NULL);
1075 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr);
1076 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1077 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1078 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1079 ok(hr == D3DERR_DEVICENOTRESET, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr);
1080 IDirect3DSurface9_Release(surface);
1081 /* Reset again to get the device out of the lost state */
1082 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1083 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1084 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1085 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
1087 if (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)
1089 IDirect3DVolumeTexture9 *volume_texture;
1091 hr = IDirect3DDevice9_CreateVolumeTexture(device1, 16, 16, 4, 1, 0,
1092 D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &volume_texture, NULL);
1093 ok(SUCCEEDED(hr), "CreateVolumeTexture failed, hr %#x.\n", hr);
1094 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1095 ok(hr == D3DERR_INVALIDCALL, "Reset returned %#x, expected %#x.\n", hr, D3DERR_INVALIDCALL);
1096 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1097 ok(hr == D3DERR_DEVICENOTRESET, "TestCooperativeLevel returned %#x, expected %#x.\n",
1098 hr, D3DERR_DEVICENOTRESET);
1099 IDirect3DVolumeTexture9_Release(volume_texture);
1100 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1101 ok(SUCCEEDED(hr), "Reset failed, hr %#x.\n", hr);
1102 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1103 ok(SUCCEEDED(hr), "TestCooperativeLevel failed, hr %#x.\n", hr);
1105 else
1107 skip("Volume textures not supported.\n");
1110 /* Scratch, sysmem and managed pools are fine */
1111 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device1, 16, 16, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &surface, NULL);
1112 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr);
1113 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1114 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1115 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1116 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
1117 IDirect3DSurface9_Release(surface);
1119 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device1, 16, 16,
1120 D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &surface, NULL);
1121 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr);
1122 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1123 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1124 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1125 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
1126 IDirect3DSurface9_Release(surface);
1128 /* The depth stencil should get reset to the auto depth stencil when present. */
1129 hr = IDirect3DDevice9_SetDepthStencilSurface(device1, NULL);
1130 ok(hr == D3D_OK, "SetDepthStencilSurface failed with 0x%08x\n", hr);
1132 hr = IDirect3DDevice9_GetDepthStencilSurface(device1, &surface);
1133 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1134 ok(surface == NULL, "Depth stencil should be NULL\n");
1136 d3dpp.EnableAutoDepthStencil = TRUE;
1137 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1138 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1139 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr);
1141 hr = IDirect3DDevice9_GetDepthStencilSurface(device1, &surface);
1142 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1143 ok(surface != NULL, "Depth stencil should not be NULL\n");
1144 if (surface) IDirect3DSurface9_Release(surface);
1146 d3dpp.EnableAutoDepthStencil = FALSE;
1147 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1148 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr);
1150 hr = IDirect3DDevice9_GetDepthStencilSurface(device1, &surface);
1151 ok(hr == D3DERR_NOTFOUND, "GetDepthStencilSurface returned 0x%08x, expected D3DERR_NOTFOUND\n", hr);
1152 ok(surface == NULL, "Depth stencil should be NULL\n");
1154 /* Will a sysmem or scratch survive while locked */
1155 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device1, 16, 16,
1156 D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &surface, NULL);
1157 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr);
1158 hr = IDirect3DSurface9_LockRect(surface, &lockrect, NULL, D3DLOCK_DISCARD);
1159 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned %08x\n", hr);
1160 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1161 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1162 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1163 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
1164 IDirect3DSurface9_UnlockRect(surface);
1165 IDirect3DSurface9_Release(surface);
1167 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device1, 16, 16, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &surface, NULL);
1168 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr);
1169 hr = IDirect3DSurface9_LockRect(surface, &lockrect, NULL, D3DLOCK_DISCARD);
1170 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned %08x\n", hr);
1171 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1172 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1173 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1174 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
1175 IDirect3DSurface9_UnlockRect(surface);
1176 IDirect3DSurface9_Release(surface);
1178 hr = IDirect3DDevice9_CreateTexture(device1, 16, 16, 0, 0, D3DFMT_R5G6B5, D3DPOOL_MANAGED, &texture, NULL);
1179 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %08x\n", hr);
1180 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1181 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1182 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1183 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
1184 IDirect3DTexture9_Release(texture);
1186 /* A reference held to an implicit surface causes failures as well */
1187 hr = IDirect3DDevice9_GetBackBuffer(device1, 0, 0, D3DBACKBUFFER_TYPE_MONO, &surface);
1188 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer returned %08x\n", hr);
1189 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1190 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1191 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1192 ok(hr == D3DERR_DEVICENOTRESET, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr);
1193 IDirect3DSurface9_Release(surface);
1194 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1195 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1196 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1197 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
1199 /* Shaders are fine as well */
1200 hr = IDirect3DDevice9_CreateVertexShader(device1, simple_vs, &shader);
1201 ok(hr == D3D_OK, "IDirect3DDevice9_CreateVertexShader returned %08x\n", hr);
1202 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1203 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
1204 IDirect3DVertexShader9_Release(shader);
1206 /* Try setting invalid modes */
1207 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1208 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1209 d3dpp.Windowed = FALSE;
1210 d3dpp.BackBufferWidth = 32;
1211 d3dpp.BackBufferHeight = 32;
1212 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1213 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Reset to w=32, h=32, windowed=FALSE failed with %08x\n", hr);
1214 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1215 ok(hr == D3DERR_DEVICENOTRESET, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr);
1217 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1218 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1219 d3dpp.Windowed = FALSE;
1220 d3dpp.BackBufferWidth = 801;
1221 d3dpp.BackBufferHeight = 600;
1222 hr = IDirect3DDevice9_Reset(device1, &d3dpp);
1223 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Reset to w=801, h=600, windowed=FALSE failed with %08x\n", hr);
1224 hr = IDirect3DDevice9_TestCooperativeLevel(device1);
1225 ok(hr == D3DERR_DEVICENOTRESET, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr);
1227 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1229 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1230 d3dpp.Windowed = TRUE;
1231 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1232 d3dpp.BackBufferFormat = d3ddm.Format;
1233 d3dpp.EnableAutoDepthStencil = FALSE;
1234 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1236 hr = IDirect3D9_CreateDevice(pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1237 hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device2);
1238 if (FAILED(hr))
1240 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr);
1241 goto cleanup;
1244 hr = IDirect3DDevice9_TestCooperativeLevel(device2);
1245 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr);
1247 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1248 d3dpp.Windowed = TRUE;
1249 d3dpp.BackBufferWidth = 400;
1250 d3dpp.BackBufferHeight = 300;
1251 d3dpp.EnableAutoDepthStencil = TRUE;
1252 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
1254 hr = IDirect3DDevice9_Reset(device2, &d3dpp);
1255 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with 0x%08x\n", hr);
1257 if (FAILED(hr)) goto cleanup;
1259 hr = IDirect3DDevice9_GetDepthStencilSurface(device2, &surface);
1260 ok(hr == D3D_OK, "GetDepthStencilSurface failed with 0x%08x\n", hr);
1261 ok(surface != NULL, "Depth stencil should not be NULL\n");
1262 if (surface) IDirect3DSurface9_Release(surface);
1264 cleanup:
1265 HeapFree(GetProcessHeap(), 0, modes);
1266 if (device2)
1268 UINT refcount = IDirect3DDevice9_Release(device2);
1269 ok(!refcount, "Device has %u references left.\n", refcount);
1271 if (device1)
1273 UINT refcount = IDirect3DDevice9_Release(device1);
1274 ok(!refcount, "Device has %u references left.\n", refcount);
1276 if (pD3d) IDirect3D9_Release(pD3d);
1277 if (hwnd) DestroyWindow(hwnd);
1280 /* Test adapter display modes */
1281 static void test_display_modes(void)
1283 D3DDISPLAYMODE dmode;
1284 IDirect3D9 *pD3d;
1286 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
1287 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
1288 if(!pD3d) return;
1290 #define TEST_FMT(x,r) do { \
1291 HRESULT res = IDirect3D9_EnumAdapterModes(pD3d, 0, (x), 0, &dmode); \
1292 ok(res==(r), "EnumAdapterModes("#x") did not return "#r" (got %08x)!\n", res); \
1293 } while(0)
1295 TEST_FMT(D3DFMT_R8G8B8, D3DERR_INVALIDCALL);
1296 TEST_FMT(D3DFMT_A8R8G8B8, D3DERR_INVALIDCALL);
1297 TEST_FMT(D3DFMT_X8B8G8R8, D3DERR_INVALIDCALL);
1298 /* D3DFMT_R5G6B5 */
1299 TEST_FMT(D3DFMT_X1R5G5B5, D3DERR_INVALIDCALL);
1300 TEST_FMT(D3DFMT_A1R5G5B5, D3DERR_INVALIDCALL);
1301 TEST_FMT(D3DFMT_A4R4G4B4, D3DERR_INVALIDCALL);
1302 TEST_FMT(D3DFMT_R3G3B2, D3DERR_INVALIDCALL);
1303 TEST_FMT(D3DFMT_A8, D3DERR_INVALIDCALL);
1304 TEST_FMT(D3DFMT_A8R3G3B2, D3DERR_INVALIDCALL);
1305 TEST_FMT(D3DFMT_X4R4G4B4, D3DERR_INVALIDCALL);
1306 TEST_FMT(D3DFMT_A2B10G10R10, D3DERR_INVALIDCALL);
1307 TEST_FMT(D3DFMT_A8B8G8R8, D3DERR_INVALIDCALL);
1308 TEST_FMT(D3DFMT_X8B8G8R8, D3DERR_INVALIDCALL);
1309 TEST_FMT(D3DFMT_G16R16, D3DERR_INVALIDCALL);
1310 TEST_FMT(D3DFMT_A16B16G16R16, D3DERR_INVALIDCALL);
1312 TEST_FMT(D3DFMT_A8P8, D3DERR_INVALIDCALL);
1313 TEST_FMT(D3DFMT_P8, D3DERR_INVALIDCALL);
1315 TEST_FMT(D3DFMT_L8, D3DERR_INVALIDCALL);
1316 TEST_FMT(D3DFMT_A8L8, D3DERR_INVALIDCALL);
1317 TEST_FMT(D3DFMT_A4L4, D3DERR_INVALIDCALL);
1319 TEST_FMT(D3DFMT_V8U8, D3DERR_INVALIDCALL);
1320 TEST_FMT(D3DFMT_L6V5U5, D3DERR_INVALIDCALL);
1321 TEST_FMT(D3DFMT_X8L8V8U8, D3DERR_INVALIDCALL);
1322 TEST_FMT(D3DFMT_Q8W8V8U8, D3DERR_INVALIDCALL);
1323 TEST_FMT(D3DFMT_V16U16, D3DERR_INVALIDCALL);
1324 TEST_FMT(D3DFMT_A2W10V10U10, D3DERR_INVALIDCALL);
1326 TEST_FMT(D3DFMT_UYVY, D3DERR_INVALIDCALL);
1327 TEST_FMT(D3DFMT_YUY2, D3DERR_INVALIDCALL);
1328 TEST_FMT(D3DFMT_DXT1, D3DERR_INVALIDCALL);
1329 TEST_FMT(D3DFMT_DXT2, D3DERR_INVALIDCALL);
1330 TEST_FMT(D3DFMT_DXT3, D3DERR_INVALIDCALL);
1331 TEST_FMT(D3DFMT_DXT4, D3DERR_INVALIDCALL);
1332 TEST_FMT(D3DFMT_DXT5, D3DERR_INVALIDCALL);
1333 TEST_FMT(D3DFMT_MULTI2_ARGB8, D3DERR_INVALIDCALL);
1334 TEST_FMT(D3DFMT_G8R8_G8B8, D3DERR_INVALIDCALL);
1335 TEST_FMT(D3DFMT_R8G8_B8G8, D3DERR_INVALIDCALL);
1337 TEST_FMT(D3DFMT_D16_LOCKABLE, D3DERR_INVALIDCALL);
1338 TEST_FMT(D3DFMT_D32, D3DERR_INVALIDCALL);
1339 TEST_FMT(D3DFMT_D15S1, D3DERR_INVALIDCALL);
1340 TEST_FMT(D3DFMT_D24S8, D3DERR_INVALIDCALL);
1341 TEST_FMT(D3DFMT_D24X8, D3DERR_INVALIDCALL);
1342 TEST_FMT(D3DFMT_D24X4S4, D3DERR_INVALIDCALL);
1343 TEST_FMT(D3DFMT_D16, D3DERR_INVALIDCALL);
1344 TEST_FMT(D3DFMT_L16, D3DERR_INVALIDCALL);
1345 TEST_FMT(D3DFMT_D32F_LOCKABLE, D3DERR_INVALIDCALL);
1346 TEST_FMT(D3DFMT_D24FS8, D3DERR_INVALIDCALL);
1348 TEST_FMT(D3DFMT_VERTEXDATA, D3DERR_INVALIDCALL);
1349 TEST_FMT(D3DFMT_INDEX16, D3DERR_INVALIDCALL);
1350 TEST_FMT(D3DFMT_INDEX32, D3DERR_INVALIDCALL);
1351 TEST_FMT(D3DFMT_Q16W16V16U16, D3DERR_INVALIDCALL);
1352 /* Floating point formats */
1353 TEST_FMT(D3DFMT_R16F, D3DERR_INVALIDCALL);
1354 TEST_FMT(D3DFMT_G16R16F, D3DERR_INVALIDCALL);
1355 TEST_FMT(D3DFMT_A16B16G16R16F, D3DERR_INVALIDCALL);
1357 /* IEEE formats */
1358 TEST_FMT(D3DFMT_R32F, D3DERR_INVALIDCALL);
1359 TEST_FMT(D3DFMT_G32R32F, D3DERR_INVALIDCALL);
1360 TEST_FMT(D3DFMT_A32B32G32R32F, D3DERR_INVALIDCALL);
1362 TEST_FMT(D3DFMT_CxV8U8, D3DERR_INVALIDCALL);
1364 TEST_FMT(0, D3DERR_INVALIDCALL);
1366 IDirect3D9_Release(pD3d);
1369 static void test_scene(void)
1371 HRESULT hr;
1372 HWND hwnd = NULL;
1373 IDirect3D9 *pD3d = NULL;
1374 IDirect3DDevice9 *pDevice = NULL;
1375 D3DPRESENT_PARAMETERS d3dpp;
1376 D3DDISPLAYMODE d3ddm;
1377 IDirect3DSurface9 *pSurface1 = NULL, *pSurface2 = NULL, *pSurface3 = NULL, *pRenderTarget = NULL;
1378 IDirect3DSurface9 *pBackBuffer = NULL, *pDepthStencil = NULL;
1379 RECT rect = {0, 0, 128, 128};
1380 D3DCAPS9 caps;
1382 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
1383 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
1384 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1385 ok(hwnd != NULL, "Failed to create window\n");
1386 if (!pD3d || !hwnd) goto cleanup;
1388 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1389 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1390 d3dpp.Windowed = TRUE;
1391 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1392 d3dpp.BackBufferWidth = 800;
1393 d3dpp.BackBufferHeight = 600;
1394 d3dpp.BackBufferFormat = d3ddm.Format;
1395 d3dpp.EnableAutoDepthStencil = TRUE;
1396 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1398 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1399 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1400 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "IDirect3D9_CreateDevice failed with %08x\n", hr);
1401 if(!pDevice)
1403 skip("Failed to create a d3d device\n");
1404 goto cleanup;
1407 /* Get the caps, they will be needed to tell if an operation is supposed to be valid */
1408 memset(&caps, 0, sizeof(caps));
1409 hr = IDirect3DDevice9_GetDeviceCaps(pDevice, &caps);
1410 ok(hr == D3D_OK, "IDirect3DDevice9_GetCaps failed with %08x\n", hr);
1411 if(FAILED(hr)) goto cleanup;
1413 /* Test an EndScene without BeginScene. Should return an error */
1414 hr = IDirect3DDevice9_EndScene(pDevice);
1415 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_EndScene returned %08x\n", hr);
1417 /* Test a normal BeginScene / EndScene pair, this should work */
1418 hr = IDirect3DDevice9_BeginScene(pDevice);
1419 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
1420 if(SUCCEEDED(hr))
1422 hr = IDirect3DDevice9_EndScene(pDevice);
1423 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
1426 /* Test another EndScene without having begun a new scene. Should return an error */
1427 hr = IDirect3DDevice9_EndScene(pDevice);
1428 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_EndScene returned %08x\n", hr);
1430 /* Two nested BeginScene and EndScene calls */
1431 hr = IDirect3DDevice9_BeginScene(pDevice);
1432 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
1433 hr = IDirect3DDevice9_BeginScene(pDevice);
1434 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_BeginScene returned %08x\n", hr);
1435 hr = IDirect3DDevice9_EndScene(pDevice);
1436 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
1437 hr = IDirect3DDevice9_EndScene(pDevice);
1438 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_EndScene returned %08x\n", hr);
1440 /* Create some surfaces to test stretchrect between the scenes */
1441 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice, 128, 128, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pSurface1, NULL);
1442 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr);
1443 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice, 128, 128, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pSurface2, NULL);
1444 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface failed with %08x\n", hr);
1445 hr = IDirect3DDevice9_CreateDepthStencilSurface(pDevice, 800, 600, D3DFMT_D16, D3DMULTISAMPLE_NONE, 0, FALSE, &pSurface3, NULL);
1446 ok(hr == D3D_OK, "IDirect3DDevice9_CreateDepthStencilSurface failed with %08x\n", hr);
1447 hr = IDirect3DDevice9_CreateRenderTarget(pDevice, 128, 128, d3ddm.Format, D3DMULTISAMPLE_NONE, 0, FALSE, &pRenderTarget, NULL);
1448 ok(hr == D3D_OK, "IDirect3DDevice9_CreateRenderTarget failed with %08x\n", hr);
1450 hr = IDirect3DDevice9_GetBackBuffer(pDevice, 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
1451 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr);
1452 hr = IDirect3DDevice9_GetDepthStencilSurface(pDevice, &pDepthStencil);
1453 ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer failed with %08x\n", hr);
1455 /* First make sure a simple StretchRect call works */
1456 if(pSurface1 && pSurface2) {
1457 hr = IDirect3DDevice9_StretchRect(pDevice, pSurface1, NULL, pSurface2, NULL, 0);
1458 ok( hr == D3D_OK, "IDirect3DDevice9_StretchRect failed with %08x\n", hr);
1460 if(pBackBuffer && pRenderTarget) {
1461 hr = IDirect3DDevice9_StretchRect(pDevice, pBackBuffer, &rect, pRenderTarget, NULL, 0);
1462 ok( hr == D3D_OK, "IDirect3DDevice9_StretchRect failed with %08x\n", hr);
1464 if(pDepthStencil && pSurface3) {
1465 HRESULT expected;
1466 if(0) /* Disabled for now because it crashes in wine */ {
1467 expected = caps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES ? D3D_OK : D3DERR_INVALIDCALL;
1468 hr = IDirect3DDevice9_StretchRect(pDevice, pDepthStencil, NULL, pSurface3, NULL, 0);
1469 ok( hr == expected, "IDirect3DDevice9_StretchRect returned %08x, expected %08x\n", hr, expected);
1473 /* Now try it in a BeginScene - EndScene pair. Seems to be allowed in a beginScene - Endscene pair
1474 * with normal surfaces and render targets, but not depth stencil surfaces.
1476 hr = IDirect3DDevice9_BeginScene(pDevice);
1477 ok( hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
1479 if(pSurface1 && pSurface2)
1481 hr = IDirect3DDevice9_StretchRect(pDevice, pSurface1, NULL, pSurface2, NULL, 0);
1482 ok( hr == D3D_OK, "IDirect3DDevice9_StretchRect failed with %08x\n", hr);
1484 if(pBackBuffer && pRenderTarget)
1486 hr = IDirect3DDevice9_StretchRect(pDevice, pBackBuffer, &rect, pRenderTarget, NULL, 0);
1487 ok( hr == D3D_OK, "IDirect3DDevice9_StretchRect failed with %08x\n", hr);
1489 if(pDepthStencil && pSurface3)
1491 /* This is supposed to fail inside a BeginScene - EndScene pair. */
1492 hr = IDirect3DDevice9_StretchRect(pDevice, pDepthStencil, NULL, pSurface3, NULL, 0);
1493 ok( hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_StretchRect returned %08x, expected D3DERR_INVALIDCALL\n", hr);
1496 hr = IDirect3DDevice9_EndScene(pDevice);
1497 ok( hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
1499 /* Does a SetRenderTarget influence BeginScene / EndScene ?
1500 * Set a new render target, then see if it started a new scene. Flip the rt back and see if that maybe
1501 * ended the scene. Expected result is that the scene is not affected by SetRenderTarget
1503 hr = IDirect3DDevice9_SetRenderTarget(pDevice, 0, pRenderTarget);
1504 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr);
1505 hr = IDirect3DDevice9_BeginScene(pDevice);
1506 ok( hr == D3D_OK, "IDirect3DDevice9_BeginScene failed with %08x\n", hr);
1507 hr = IDirect3DDevice9_SetRenderTarget(pDevice, 0, pBackBuffer);
1508 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderTarget failed with %08x\n", hr);
1509 hr = IDirect3DDevice9_EndScene(pDevice);
1510 ok( hr == D3D_OK, "IDirect3DDevice9_EndScene failed with %08x\n", hr);
1512 cleanup:
1513 if(pRenderTarget) IDirect3DSurface9_Release(pRenderTarget);
1514 if(pDepthStencil) IDirect3DSurface9_Release(pDepthStencil);
1515 if(pBackBuffer) IDirect3DSurface9_Release(pBackBuffer);
1516 if(pSurface1) IDirect3DSurface9_Release(pSurface1);
1517 if(pSurface2) IDirect3DSurface9_Release(pSurface2);
1518 if(pSurface3) IDirect3DSurface9_Release(pSurface3);
1519 if (pDevice)
1521 UINT refcount = IDirect3DDevice9_Release(pDevice);
1522 ok(!refcount, "Device has %u references left.\n", refcount);
1524 if (pD3d) IDirect3D9_Release(pD3d);
1525 if(hwnd) DestroyWindow(hwnd);
1528 static void test_limits(void)
1530 HRESULT hr;
1531 HWND hwnd = NULL;
1532 IDirect3D9 *pD3d = NULL;
1533 IDirect3DDevice9 *pDevice = NULL;
1534 D3DPRESENT_PARAMETERS d3dpp;
1535 D3DDISPLAYMODE d3ddm;
1536 IDirect3DTexture9 *pTexture = NULL;
1537 int i;
1539 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
1540 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
1541 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1542 ok(hwnd != NULL, "Failed to create window\n");
1543 if (!pD3d || !hwnd) goto cleanup;
1545 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1546 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1547 d3dpp.Windowed = TRUE;
1548 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1549 d3dpp.BackBufferWidth = 800;
1550 d3dpp.BackBufferHeight = 600;
1551 d3dpp.BackBufferFormat = d3ddm.Format;
1552 d3dpp.EnableAutoDepthStencil = TRUE;
1553 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1555 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1556 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1557 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "IDirect3D9_CreateDevice failed with %08x\n", hr);
1558 if(!pDevice)
1560 skip("Failed to create a d3d device\n");
1561 goto cleanup;
1564 hr = IDirect3DDevice9_CreateTexture(pDevice, 16, 16, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTexture, NULL);
1565 ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed with %08x\n", hr);
1566 if(!pTexture) goto cleanup;
1568 /* There are 16 pixel samplers. We should be able to access all of them */
1569 for(i = 0; i < 16; i++) {
1570 hr = IDirect3DDevice9_SetTexture(pDevice, i, (IDirect3DBaseTexture9 *) pTexture);
1571 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i, hr);
1572 hr = IDirect3DDevice9_SetTexture(pDevice, i, NULL);
1573 ok(hr == D3D_OK, "IDirect3DDevice9_SetTexture for sampler %d failed with %08x\n", i, hr);
1574 hr = IDirect3DDevice9_SetSamplerState(pDevice, i, D3DSAMP_SRGBTEXTURE, TRUE);
1575 ok(hr == D3D_OK, "IDirect3DDevice9_SetSamplerState for sampler %d failed with %08x\n", i, hr);
1578 /* Now test all 8 textures stage states */
1579 for(i = 0; i < 8; i++) {
1580 hr = IDirect3DDevice9_SetTextureStageState(pDevice, i, D3DTSS_COLOROP, D3DTOP_ADD);
1581 ok(hr == D3D_OK, "IDirect3DDevice9_SetTextureStageState for texture %d failed with %08x\n", i, hr);
1584 /* Investigations show that accessing higher samplers / textures stage states does not return an error either. Writing
1585 * to too high samplers(approximately sampler 40) causes memory corruption in windows, so there is no bounds checking
1586 * but how do I test that?
1588 cleanup:
1589 if(pTexture) IDirect3DTexture9_Release(pTexture);
1590 if (pDevice)
1592 UINT refcount = IDirect3D9_Release(pDevice);
1593 ok(!refcount, "Device has %u references left.\n", refcount);
1595 if (pD3d) IDirect3D9_Release(pD3d);
1596 if(hwnd) DestroyWindow(hwnd);
1599 static void test_depthstenciltest(void)
1601 HRESULT hr;
1602 HWND hwnd = NULL;
1603 IDirect3D9 *pD3d = NULL;
1604 IDirect3DDevice9 *pDevice = NULL;
1605 D3DPRESENT_PARAMETERS d3dpp;
1606 D3DDISPLAYMODE d3ddm;
1607 IDirect3DSurface9 *pDepthStencil = NULL;
1608 IDirect3DSurface9 *pDepthStencil2 = NULL;
1609 DWORD state;
1611 pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
1612 ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
1613 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1614 ok(hwnd != NULL, "Failed to create window\n");
1615 if (!pD3d || !hwnd) goto cleanup;
1617 IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
1618 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1619 d3dpp.Windowed = TRUE;
1620 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1621 d3dpp.BackBufferWidth = 800;
1622 d3dpp.BackBufferHeight = 600;
1623 d3dpp.BackBufferFormat = d3ddm.Format;
1624 d3dpp.EnableAutoDepthStencil = TRUE;
1625 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1627 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1628 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1629 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "IDirect3D9_CreateDevice failed with %08x\n", hr);
1630 if(!pDevice)
1632 skip("Failed to create a d3d device\n");
1633 goto cleanup;
1636 hr = IDirect3DDevice9_GetDepthStencilSurface(pDevice, &pDepthStencil);
1637 ok(hr == D3D_OK && pDepthStencil != NULL, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr);
1639 /* Try to clear */
1640 hr = IDirect3DDevice9_Clear(pDevice, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 1.0, 0);
1641 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1643 hr = IDirect3DDevice9_SetDepthStencilSurface(pDevice, NULL);
1644 ok(hr == D3D_OK, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr);
1646 /* Check if the set buffer is returned on a get. WineD3D had a bug with that once, prevent it from coming back */
1647 hr = IDirect3DDevice9_GetDepthStencilSurface(pDevice, &pDepthStencil2);
1648 ok(hr == D3DERR_NOTFOUND && pDepthStencil2 == NULL, "IDirect3DDevice9_GetDepthStencilSurface failed with %08x\n", hr);
1649 if(pDepthStencil2) IDirect3DSurface9_Release(pDepthStencil2);
1651 /* This left the render states untouched! */
1652 hr = IDirect3DDevice9_GetRenderState(pDevice, D3DRS_ZENABLE, &state);
1653 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
1654 ok(state == D3DZB_TRUE, "D3DRS_ZENABLE is %s\n", state == D3DZB_FALSE ? "D3DZB_FALSE" : (state == D3DZB_TRUE ? "D3DZB_TRUE" : "D3DZB_USEW"));
1655 hr = IDirect3DDevice9_GetRenderState(pDevice, D3DRS_ZWRITEENABLE, &state);
1656 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
1657 ok(state == TRUE, "D3DRS_ZWRITEENABLE is %s\n", state ? "TRUE" : "FALSE");
1658 hr = IDirect3DDevice9_GetRenderState(pDevice, D3DRS_STENCILENABLE, &state);
1659 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
1660 ok(state == FALSE, "D3DRS_STENCILENABLE is %s\n", state ? "TRUE" : "FALSE");
1661 hr = IDirect3DDevice9_GetRenderState(pDevice, D3DRS_STENCILWRITEMASK, &state);
1662 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
1663 ok(state == 0xffffffff, "D3DRS_STENCILWRITEMASK is 0x%08x\n", state);
1665 /* This is supposed to fail now */
1666 hr = IDirect3DDevice9_Clear(pDevice, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 1.0, 0);
1667 ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1669 hr = IDirect3DDevice9_SetRenderState(pDevice, D3DRS_ZENABLE, D3DZB_FALSE);
1670 ok(hr == D3D_OK, "IDirect3DDevice9_SetRenderState failed with %08x\n", hr);
1672 hr = IDirect3DDevice9_SetDepthStencilSurface(pDevice, pDepthStencil);
1673 ok(hr == D3D_OK, "IDirect3DDevice9_SetDepthStencilSurface failed with %08x\n", hr);
1675 hr = IDirect3DDevice9_GetRenderState(pDevice, D3DRS_ZENABLE, &state);
1676 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
1677 ok(state == D3DZB_FALSE, "D3DRS_ZENABLE is %s\n", state == D3DZB_FALSE ? "D3DZB_FALSE" : (state == D3DZB_TRUE ? "D3DZB_TRUE" : "D3DZB_USEW"));
1679 /* Now it works again */
1680 hr = IDirect3DDevice9_Clear(pDevice, 0, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 1.0, 0);
1681 ok(hr == D3D_OK, "IDirect3DDevice9_Clear failed with %08x\n", hr);
1683 if(pDepthStencil) IDirect3DSurface9_Release(pDepthStencil);
1684 if(pDevice) IDirect3D9_Release(pDevice);
1686 /* Now see if autodepthstencil disable is honored. First, without a format set */
1687 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1688 d3dpp.Windowed = TRUE;
1689 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1690 d3dpp.BackBufferWidth = 800;
1691 d3dpp.BackBufferHeight = 600;
1692 d3dpp.BackBufferFormat = d3ddm.Format;
1693 d3dpp.EnableAutoDepthStencil = FALSE;
1694 d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
1696 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1697 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1698 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "IDirect3D9_CreateDevice failed with %08x\n", hr);
1699 if(!pDevice)
1701 skip("Failed to create a d3d device\n");
1702 goto cleanup;
1705 pDepthStencil = NULL;
1706 hr = IDirect3DDevice9_GetDepthStencilSurface(pDevice, &pDepthStencil);
1707 ok(hr == D3DERR_NOTFOUND && pDepthStencil == NULL, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr, pDepthStencil);
1708 if(pDepthStencil) {
1709 IDirect3DSurface9_Release(pDepthStencil);
1710 pDepthStencil = NULL;
1713 /* Check the depth test state */
1714 hr = IDirect3DDevice9_GetRenderState(pDevice, D3DRS_ZENABLE, &state);
1715 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
1716 ok(state == D3DZB_FALSE, "D3DRS_ZENABLE is %s\n", state == D3DZB_FALSE ? "D3DZB_FALSE" : (state == D3DZB_TRUE ? "D3DZB_TRUE" : "D3DZB_USEW"));
1718 if(pDevice) IDirect3D9_Release(pDevice);
1720 /* Next, try EnableAutoDepthStencil FALSE with a depth stencil format set */
1721 ZeroMemory( &d3dpp, sizeof(d3dpp) );
1722 d3dpp.Windowed = TRUE;
1723 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1724 d3dpp.BackBufferWidth = 800;
1725 d3dpp.BackBufferHeight = 600;
1726 d3dpp.BackBufferFormat = d3ddm.Format;
1727 d3dpp.EnableAutoDepthStencil = FALSE;
1728 d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
1730 hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1731 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
1732 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "IDirect3D9_CreateDevice failed with %08x\n", hr);
1733 if(!pDevice)
1735 skip("Failed to create a d3d device\n");
1736 goto cleanup;
1739 pDepthStencil = NULL;
1740 hr = IDirect3DDevice9_GetDepthStencilSurface(pDevice, &pDepthStencil);
1741 ok(hr == D3DERR_NOTFOUND && pDepthStencil == NULL, "IDirect3DDevice9_GetDepthStencilSurface returned %08x, surface = %p\n", hr, pDepthStencil);
1742 if(pDepthStencil) {
1743 IDirect3DSurface9_Release(pDepthStencil);
1744 pDepthStencil = NULL;
1747 hr = IDirect3DDevice9_GetRenderState(pDevice, D3DRS_ZENABLE, &state);
1748 ok(hr == D3D_OK, "IDirect3DDevice9_GetRenderState failed with %08x\n", hr);
1749 ok(state == D3DZB_FALSE, "D3DRS_ZENABLE is %s\n", state == D3DZB_FALSE ? "D3DZB_FALSE" : (state == D3DZB_TRUE ? "D3DZB_TRUE" : "D3DZB_USEW"));
1751 cleanup:
1752 if(pDepthStencil) IDirect3DSurface9_Release(pDepthStencil);
1753 if (pDevice)
1755 UINT refcount = IDirect3D9_Release(pDevice);
1756 ok(!refcount, "Device has %u references left.\n", refcount);
1758 if (pD3d) IDirect3D9_Release(pD3d);
1759 if(hwnd) DestroyWindow(hwnd);
1762 static void test_get_rt(void)
1764 IDirect3DSurface9 *backbuffer, *rt;
1765 IDirect3DDevice9 *device;
1766 IDirect3D9 *d3d9;
1767 D3DCAPS9 caps;
1768 HWND window;
1769 HRESULT hr;
1770 ULONG ref;
1771 UINT i;
1773 if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
1775 skip("Failed to create IDirect3D9 object, skipping tests.\n");
1776 return;
1779 window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
1780 0, 0, 128, 128, 0, 0, 0, 0);
1781 device = create_device(d3d9, window, window, TRUE);
1782 if (!device)
1784 skip("Failed to create a D3D device, skipping tests.\n");
1785 goto done;
1788 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &backbuffer);
1789 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1790 ok(!!backbuffer, "Got a NULL backbuffer.\n");
1792 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
1793 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
1795 for (i = 1; i < caps.NumSimultaneousRTs; ++i)
1797 rt = backbuffer;
1798 hr = IDirect3DDevice9_GetRenderTarget(device, i, &rt);
1799 ok(hr == D3DERR_NOTFOUND, "IDirect3DDevice9_GetRenderTarget returned %#x.\n", hr);
1800 ok(!rt, "Got rt %p.\n", rt);
1803 IDirect3DSurface9_Release(backbuffer);
1805 ref = IDirect3DDevice9_Release(device);
1806 ok(!ref, "The device was not properly freed: refcount %u.\n", ref);
1807 done:
1808 IDirect3D9_Release(d3d9);
1809 DestroyWindow(window);
1812 /* Test what happens when IDirect3DDevice9_DrawIndexedPrimitive is called without a valid index buffer set. */
1813 static void test_draw_indexed(void)
1815 static const struct {
1816 float position[3];
1817 DWORD color;
1818 } quad[] = {
1819 {{-1.0f, -1.0f, 0.0f}, 0xffff0000},
1820 {{-1.0f, 1.0f, 0.0f}, 0xffff0000},
1821 {{ 1.0f, 1.0f, 0.0f}, 0xffff0000},
1822 {{ 1.0f, -1.0f, 0.0f}, 0xffff0000},
1824 WORD indices[] = {0, 1, 2, 3, 0, 2};
1826 static const D3DVERTEXELEMENT9 decl_elements[] = {
1827 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
1828 {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
1829 D3DDECL_END()
1832 IDirect3DVertexDeclaration9 *vertex_declaration = NULL;
1833 IDirect3DVertexBuffer9 *vertex_buffer = NULL;
1834 IDirect3DIndexBuffer9 *index_buffer = NULL;
1835 D3DPRESENT_PARAMETERS present_parameters;
1836 IDirect3DDevice9 *device = NULL;
1837 IDirect3D9 *d3d9;
1838 HRESULT hr;
1839 HWND hwnd;
1840 void *ptr;
1842 hwnd = CreateWindow("d3d9_test_wc", "d3d9_test",
1843 0, 0, 0, 10, 10, 0, 0, 0, 0);
1844 if (!hwnd)
1846 skip("Failed to create window\n");
1847 return;
1850 d3d9 = pDirect3DCreate9(D3D_SDK_VERSION);
1851 if (!d3d9)
1853 skip("Failed to create IDirect3D9 object\n");
1854 goto cleanup;
1857 ZeroMemory(&present_parameters, sizeof(present_parameters));
1858 present_parameters.Windowed = TRUE;
1859 present_parameters.hDeviceWindow = hwnd;
1860 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1862 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1863 NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
1864 if (FAILED(hr) || !device)
1866 skip("Failed to create device\n");
1867 goto cleanup;
1870 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &vertex_declaration);
1871 ok(SUCCEEDED(hr), "CreateVertexDeclaration failed (0x%08x)\n", hr);
1872 hr = IDirect3DDevice9_SetVertexDeclaration(device, NULL);
1873 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr);
1875 hr = IDirect3DDevice9_CreateVertexBuffer(device, sizeof(quad), 0, 0, D3DPOOL_DEFAULT, &vertex_buffer, NULL);
1876 ok(SUCCEEDED(hr), "CreateVertexBuffer failed (0x%08x)\n", hr);
1877 hr = IDirect3DVertexBuffer9_Lock(vertex_buffer, 0, 0, &ptr, D3DLOCK_DISCARD);
1878 ok(SUCCEEDED(hr), "Lock failed (0x%08x)\n", hr);
1879 memcpy(ptr, quad, sizeof(quad));
1880 hr = IDirect3DVertexBuffer9_Unlock(vertex_buffer);
1881 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1882 hr = IDirect3DDevice9_SetStreamSource(device, 0, vertex_buffer, 0, sizeof(*quad));
1883 ok(SUCCEEDED(hr), "SetStreamSource failed (0x%08x)\n", hr);
1885 hr = IDirect3DDevice9_CreateIndexBuffer(device, sizeof(indices), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &index_buffer, NULL);
1886 ok(SUCCEEDED(hr), "CreateIndexBuffer failed (0x%08x)\n", hr);
1887 hr = IDirect3DIndexBuffer9_Lock(index_buffer, 0, 0, &ptr, D3DLOCK_DISCARD);
1888 ok(SUCCEEDED(hr), "Lock failed (0x%08x)\n", hr);
1889 memcpy(ptr, indices, sizeof(indices));
1890 hr = IDirect3DIndexBuffer9_Unlock(index_buffer);
1891 ok(SUCCEEDED(hr), "Unlock failed (0x%08x)\n", hr);
1892 hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
1893 ok(SUCCEEDED(hr), "SetRenderState D3DRS_LIGHTING failed (0x%08x)\n", hr);
1894 hr = IDirect3DDevice9_BeginScene(device);
1895 ok(SUCCEEDED(hr), "BeginScene failed (0x%08x)\n", hr);
1897 /* NULL index buffer. Should fail */
1898 hr = IDirect3DDevice9_SetIndices(device, NULL);
1899 ok(SUCCEEDED(hr), "SetIndices failed (0x%08x)\n", hr);
1900 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1901 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1902 ok(hr == D3DERR_INVALIDCALL, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1903 hr, D3DERR_INVALIDCALL);
1905 /* Valid index buffer, NULL vertex declaration. Should fail */
1906 hr = IDirect3DDevice9_SetIndices(device, index_buffer);
1907 ok(SUCCEEDED(hr), "SetIndices failed (0x%08x)\n", hr);
1908 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1909 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1910 ok(hr == D3DERR_INVALIDCALL, "DrawIndexedPrimitive returned 0x%08x, expected D3DERR_INVALIDCALL (0x%08x)\n",
1911 hr, D3DERR_INVALIDCALL);
1913 /* Valid index buffer and vertex declaration. Should succeed */
1914 hr = IDirect3DDevice9_SetVertexDeclaration(device, vertex_declaration);
1915 ok(SUCCEEDED(hr), "SetVertexDeclaration failed (0x%08x)\n", hr);
1916 hr = IDirect3DDevice9_DrawIndexedPrimitive(device, D3DPT_TRIANGLELIST, 0 /* BaseVertexIndex */, 0 /* MinIndex */,
1917 4 /* NumVerts */, 0 /* StartIndex */, 2 /*PrimCount */);
1918 ok(SUCCEEDED(hr), "DrawIndexedPrimitive failed (0x%08x)\n", hr);
1920 hr = IDirect3DDevice9_EndScene(device);
1921 ok(SUCCEEDED(hr), "EndScene failed (0x%08x)\n", hr);
1923 hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
1924 ok(SUCCEEDED(hr), "Present failed (0x%08x)\n", hr);
1926 IDirect3DVertexBuffer9_Release(vertex_buffer);
1927 IDirect3DIndexBuffer9_Release(index_buffer);
1928 IDirect3DVertexDeclaration9_Release(vertex_declaration);
1930 cleanup:
1931 if (device)
1933 UINT refcount = IDirect3DDevice9_Release(device);
1934 ok(!refcount, "Device has %u references left.\n", refcount);
1936 if (d3d9) IDirect3D9_Release(d3d9);
1937 if (hwnd) DestroyWindow(hwnd);
1940 static void test_null_stream(void)
1942 IDirect3DVertexBuffer9 *buffer = NULL;
1943 D3DPRESENT_PARAMETERS present_parameters;
1944 IDirect3DDevice9 *device = NULL;
1945 IDirect3D9 *d3d9;
1946 HWND hwnd;
1947 HRESULT hr;
1948 IDirect3DVertexShader9 *shader = NULL;
1949 IDirect3DVertexDeclaration9 *decl = NULL;
1950 DWORD shader_code[] = {
1951 0xfffe0101, /* vs_1_1 */
1952 0x0000001f, 0x80000000, 0x900f0000, /* dcl_position v0 */
1953 0x00000001, 0xc00f0000, 0x90e40000, /* mov oPos, v0 */
1954 0x0000ffff /* end */
1956 static const D3DVERTEXELEMENT9 decl_elements[] = {
1957 {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
1958 {1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
1959 D3DDECL_END()
1962 d3d9 = pDirect3DCreate9( D3D_SDK_VERSION );
1963 ok(d3d9 != NULL, "Failed to create IDirect3D9 object\n");
1964 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
1965 ok(hwnd != NULL, "Failed to create window\n");
1966 if (!d3d9 || !hwnd) goto cleanup;
1968 ZeroMemory(&present_parameters, sizeof(present_parameters));
1969 present_parameters.Windowed = TRUE;
1970 present_parameters.hDeviceWindow = hwnd;
1971 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1973 hr = IDirect3D9_CreateDevice( d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL /* no NULLREF here */, hwnd,
1974 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device );
1975 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "IDirect3D9_CreateDevice failed with %08x\n", hr);
1976 if(!device)
1978 skip("Failed to create a d3d device\n");
1979 goto cleanup;
1982 hr = IDirect3DDevice9_CreateVertexShader(device, shader_code, &shader);
1983 if(FAILED(hr)) {
1984 skip("No vertex shader support\n");
1985 goto cleanup;
1987 hr = IDirect3DDevice9_CreateVertexDeclaration(device, decl_elements, &decl);
1988 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexDeclaration failed (0x%08x)\n", hr);
1989 if (FAILED(hr)) {
1990 skip("Vertex declaration handling not possible.\n");
1991 goto cleanup;
1993 hr = IDirect3DDevice9_CreateVertexBuffer(device, 12 * sizeof(float), 0, 0, D3DPOOL_MANAGED, &buffer, NULL);
1994 ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateVertexBuffer failed (0x%08x)\n", hr);
1995 if (FAILED(hr)) {
1996 skip("Vertex buffer handling not possible.\n");
1997 goto cleanup;
2000 hr = IDirect3DDevice9_SetStreamSource(device, 0, buffer, 0, sizeof(float) * 3);
2001 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr);
2002 hr = IDirect3DDevice9_SetStreamSource(device, 1, NULL, 0, 0);
2003 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetStreamSource failed (0x%08x)\n", hr);
2004 hr = IDirect3DDevice9_SetVertexShader(device, shader);
2005 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexShader failed (0x%08x)\n", hr);
2006 hr = IDirect3DDevice9_SetVertexDeclaration(device, decl);
2007 ok(SUCCEEDED(hr), "IDirect3DDevice9_SetVertexDeclaration failed (0x%08x)\n", hr);
2009 hr = IDirect3DDevice9_BeginScene(device);
2010 ok(hr == D3D_OK, "IDirect3DDevice9_BeginScene failed (0x%08x)\n", hr);
2011 if(SUCCEEDED(hr)) {
2012 hr = IDirect3DDevice9_DrawPrimitive(device, D3DPT_POINTLIST, 0, 1);
2013 ok(SUCCEEDED(hr), "IDirect3DDevice9_DrawPrimitive failed (0x%08x)\n", hr);
2015 hr = IDirect3DDevice9_EndScene(device);
2016 ok(hr == D3D_OK, "IDirect3DDevice9_EndScene failed (0x%08x)\n", hr);
2019 IDirect3DDevice9_SetStreamSource(device, 0, NULL, 0, 0);
2020 IDirect3DDevice9_SetVertexShader(device, NULL);
2021 IDirect3DDevice9_SetVertexDeclaration(device, NULL);
2023 cleanup:
2024 if (buffer) IDirect3DVertexBuffer9_Release(buffer);
2025 if(decl) IDirect3DVertexDeclaration9_Release(decl);
2026 if(shader) IDirect3DVertexShader9_Release(shader);
2027 if (device)
2029 UINT refcount = IDirect3DDevice9_Release(device);
2030 ok(!refcount, "Device has %u references left.\n", refcount);
2032 if(d3d9) IDirect3D9_Release(d3d9);
2035 static void test_lights(void)
2037 D3DPRESENT_PARAMETERS present_parameters;
2038 IDirect3DDevice9 *device = NULL;
2039 IDirect3D9 *d3d9;
2040 HWND hwnd;
2041 HRESULT hr;
2042 unsigned int i;
2043 BOOL enabled;
2044 D3DCAPS9 caps;
2046 d3d9 = pDirect3DCreate9( D3D_SDK_VERSION );
2047 ok(d3d9 != NULL, "Failed to create IDirect3D9 object\n");
2048 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2049 ok(hwnd != NULL, "Failed to create window\n");
2050 if (!d3d9 || !hwnd) goto cleanup;
2052 ZeroMemory(&present_parameters, sizeof(present_parameters));
2053 present_parameters.Windowed = TRUE;
2054 present_parameters.hDeviceWindow = hwnd;
2055 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2057 hr = IDirect3D9_CreateDevice( d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2058 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device );
2059 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
2060 "IDirect3D9_CreateDevice failed with %08x\n", hr);
2061 if(!device)
2063 skip("Failed to create a d3d device\n");
2064 goto cleanup;
2067 memset(&caps, 0, sizeof(caps));
2068 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
2069 ok(hr == D3D_OK, "IDirect3DDevice9_GetDeviceCaps failed with %08x\n", hr);
2071 for(i = 1; i <= caps.MaxActiveLights; i++) {
2072 hr = IDirect3DDevice9_LightEnable(device, i, TRUE);
2073 ok(hr == D3D_OK, "Enabling light %u failed with %08x\n", i, hr);
2074 hr = IDirect3DDevice9_GetLightEnable(device, i, &enabled);
2075 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i, hr);
2076 ok(enabled, "Light %d is %s\n", i, enabled ? "enabled" : "disabled");
2079 /* TODO: Test the rendering results in this situation */
2080 hr = IDirect3DDevice9_LightEnable(device, i + 1, TRUE);
2081 ok(hr == D3D_OK, "Enabling one light more than supported returned %08x\n", hr);
2082 hr = IDirect3DDevice9_GetLightEnable(device, i + 1, &enabled);
2083 ok(hr == D3D_OK, "GetLightEnable on light %u failed with %08x\n", i + 1, hr);
2084 ok(enabled, "Light %d is %s\n", i + 1, enabled ? "enabled" : "disabled");
2085 hr = IDirect3DDevice9_LightEnable(device, i + 1, FALSE);
2086 ok(hr == D3D_OK, "Disabling the additional returned %08x\n", hr);
2088 for(i = 1; i <= caps.MaxActiveLights; i++) {
2089 hr = IDirect3DDevice9_LightEnable(device, i, FALSE);
2090 ok(hr == D3D_OK, "Disabling light %u failed with %08x\n", i, hr);
2093 cleanup:
2094 if (device)
2096 UINT refcount = IDirect3DDevice9_Release(device);
2097 ok(!refcount, "Device has %u references left.\n", refcount);
2099 if(d3d9) IDirect3D9_Release(d3d9);
2102 static void test_set_stream_source(void)
2104 D3DPRESENT_PARAMETERS present_parameters;
2105 IDirect3DDevice9 *device = NULL;
2106 IDirect3D9 *d3d9;
2107 HWND hwnd;
2108 HRESULT hr;
2109 IDirect3DVertexBuffer9 *pVertexBuffer = NULL;
2111 d3d9 = pDirect3DCreate9( D3D_SDK_VERSION );
2112 ok(d3d9 != NULL, "Failed to create IDirect3D9 object\n");
2113 hwnd = CreateWindow( "d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
2114 ok(hwnd != NULL, "Failed to create window\n");
2115 if (!d3d9 || !hwnd) goto cleanup;
2117 ZeroMemory(&present_parameters, sizeof(present_parameters));
2118 present_parameters.Windowed = TRUE;
2119 present_parameters.hDeviceWindow = hwnd;
2120 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2122 hr = IDirect3D9_CreateDevice( d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
2123 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device );
2124 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
2125 "IDirect3D9_CreateDevice failed with %08x\n", hr);
2126 if(!device)
2128 hr = IDirect3D9_CreateDevice( d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hwnd,
2129 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device );
2130 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE || hr == D3DERR_INVALIDCALL,
2131 "IDirect3D9_CreateDevice failed with %08x\n", hr);
2132 if(!device)
2134 skip("Failed to create a d3d device\n");
2135 goto cleanup;
2139 hr = IDirect3DDevice9_CreateVertexBuffer( device, 512, 0, 0, D3DPOOL_DEFAULT, &pVertexBuffer, NULL );
2140 ok(hr == D3D_OK, "Failed to create a vertex buffer, hr = %08x\n", hr);
2141 if (SUCCEEDED(hr)) {
2142 /* Some cards(Geforce 7400 at least) accept non-aligned offsets, others(radeon 9000 verified) reject it,
2143 * so accept both results. Wine currently rejects this to be able to optimize the vbo conversion, but writes
2144 * a WARN
2146 hr = IDirect3DDevice9_SetStreamSource(device, 0, pVertexBuffer, 0, 32);
2147 ok(hr == D3D_OK, "Failed to set the stream source, offset 0, hr = %08x\n", hr);
2148 hr = IDirect3DDevice9_SetStreamSource(device, 0, pVertexBuffer, 1, 32);
2149 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Unexpected result when setting the stream source, offset 1, hr = %08x\n", hr);
2150 hr = IDirect3DDevice9_SetStreamSource(device, 0, pVertexBuffer, 2, 32);
2151 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Unexpected result when setting the stream source, offset 2, hr = %08x\n", hr);
2152 hr = IDirect3DDevice9_SetStreamSource(device, 0, pVertexBuffer, 3, 32);
2153 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Unexpected result when setting the stream source, offset 3, hr = %08x\n", hr);
2154 hr = IDirect3DDevice9_SetStreamSource(device, 0, pVertexBuffer, 4, 32);
2155 ok(hr == D3D_OK, "Failed to set the stream source, offset 4, hr = %08x\n", hr);
2157 /* Try to set the NULL buffer with an offset and stride 0 */
2158 hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 0, 0);
2159 ok(hr == D3D_OK, "Failed to set the stream source, offset 0, hr = %08x\n", hr);
2160 hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 1, 0);
2161 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Unexpected result when setting the stream source, offset 1, hr = %08x\n", hr);
2162 hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 2, 0);
2163 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Unexpected result when setting the stream source, offset 2, hr = %08x\n", hr);
2164 hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 3, 0);
2165 ok(hr == D3DERR_INVALIDCALL || hr == D3D_OK, "Unexpected result when setting the stream source, offset 3, hr = %08x\n", hr);
2166 hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 4, 0);
2167 ok(hr == D3D_OK, "Failed to set the stream source, offset 4, hr = %08x\n", hr);
2169 hr = IDirect3DDevice9_SetStreamSource(device, 0, NULL, 0, 0);
2170 ok(hr == D3D_OK, "Failed to set the stream source, offset 4, hr = %08x\n", hr);
2172 cleanup:
2173 if (pVertexBuffer) IDirect3DVertexBuffer9_Release(pVertexBuffer);
2174 if (device)
2176 UINT refcount = IDirect3DDevice9_Release(device);
2177 ok(!refcount, "Device has %u references left.\n", refcount);
2179 if(d3d9) IDirect3D9_Release(d3d9);
2182 struct formats {
2183 D3DFORMAT DisplayFormat;
2184 D3DFORMAT BackBufferFormat;
2185 BOOL shouldPass;
2188 static const struct formats r5g6b5_format_list[] =
2190 { D3DFMT_R5G6B5, D3DFMT_R5G6B5, TRUE },
2191 { D3DFMT_R5G6B5, D3DFMT_X1R5G5B5, FALSE },
2192 { D3DFMT_R5G6B5, D3DFMT_A1R5G5B5, FALSE },
2193 { D3DFMT_R5G6B5, D3DFMT_X8R8G8B8, FALSE },
2194 { D3DFMT_R5G6B5, D3DFMT_A8R8G8B8, FALSE },
2195 { 0, 0, 0}
2198 static const struct formats x1r5g5b5_format_list[] =
2200 { D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, FALSE },
2201 { D3DFMT_X1R5G5B5, D3DFMT_X1R5G5B5, TRUE },
2202 { D3DFMT_X1R5G5B5, D3DFMT_A1R5G5B5, TRUE },
2203 { D3DFMT_X1R5G5B5, D3DFMT_X8R8G8B8, FALSE },
2204 { D3DFMT_X1R5G5B5, D3DFMT_A8R8G8B8, FALSE },
2206 /* A1R5G5B5 should not be usable as a display format, it is backbuffer-only */
2207 { D3DFMT_A1R5G5B5, D3DFMT_R5G6B5, FALSE },
2208 { D3DFMT_A1R5G5B5, D3DFMT_X1R5G5B5, FALSE },
2209 { D3DFMT_A1R5G5B5, D3DFMT_A1R5G5B5, FALSE },
2210 { D3DFMT_A1R5G5B5, D3DFMT_X8R8G8B8, FALSE },
2211 { D3DFMT_A1R5G5B5, D3DFMT_A8R8G8B8, FALSE },
2212 { 0, 0, 0}
2215 static const struct formats x8r8g8b8_format_list[] =
2217 { D3DFMT_X8R8G8B8, D3DFMT_R5G6B5, FALSE },
2218 { D3DFMT_X8R8G8B8, D3DFMT_X1R5G5B5, FALSE },
2219 { D3DFMT_X8R8G8B8, D3DFMT_A1R5G5B5, FALSE },
2220 { D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, TRUE },
2221 { D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, TRUE },
2223 /* A1R8G8B8 should not be usable as a display format, it is backbuffer-only */
2224 { D3DFMT_A8R8G8B8, D3DFMT_R5G6B5, FALSE },
2225 { D3DFMT_A8R8G8B8, D3DFMT_X1R5G5B5, FALSE },
2226 { D3DFMT_A8R8G8B8, D3DFMT_A1R5G5B5, FALSE },
2227 { D3DFMT_A8R8G8B8, D3DFMT_X8R8G8B8, FALSE },
2228 { D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE },
2229 { 0, 0, 0}
2232 static void test_display_formats(void)
2234 /* Direct3D9 offers 4 display formats R5G6B5, X1R5G5B5, X8R8G8B8 and A2R10G10B10.
2235 * Next to these there are 6 different backbuffer formats. Only a fixed number of
2236 * combinations are possible in FULLSCREEN mode. In windowed mode more combinations are
2237 * allowed due to depth conversion and this is likely driver dependent.
2238 * This test checks which combinations are possible in fullscreen mode and this should not be driver dependent.
2239 * TODO: handle A2R10G10B10 but what hardware supports it? Parhelia? It is very rare. */
2241 UINT Adapter = D3DADAPTER_DEFAULT;
2242 D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
2243 int i, nmodes;
2244 HRESULT hr;
2246 IDirect3D9 *d3d9 = pDirect3DCreate9( D3D_SDK_VERSION );
2247 ok(d3d9 != NULL, "Failed to create IDirect3D9 object\n");
2248 if(!d3d9) return;
2250 nmodes = IDirect3D9_GetAdapterModeCount(d3d9, D3DADAPTER_DEFAULT, D3DFMT_R5G6B5);
2251 if(!nmodes) {
2252 skip("Display format R5G6B5 not supported, skipping\n");
2253 } else {
2254 trace("Testing display format R5G6B5\n");
2255 for(i=0; r5g6b5_format_list[i].DisplayFormat != 0; i++)
2257 hr = IDirect3D9_CheckDeviceType(d3d9, Adapter, DeviceType, r5g6b5_format_list[i].DisplayFormat, r5g6b5_format_list[i].BackBufferFormat, FALSE);
2259 if(r5g6b5_format_list[i].shouldPass)
2260 ok(hr == D3D_OK ||
2261 broken(hr == D3DERR_NOTAVAILABLE),
2262 "format %d %d didn't pass with hr=%#08x\n", r5g6b5_format_list[i].DisplayFormat, r5g6b5_format_list[i].BackBufferFormat, hr);
2263 else
2264 ok(hr != D3D_OK, "format %d %d didn't pass while it was expected to\n", r5g6b5_format_list[i].DisplayFormat, r5g6b5_format_list[i].BackBufferFormat);
2268 nmodes = IDirect3D9_GetAdapterModeCount(d3d9, D3DADAPTER_DEFAULT, D3DFMT_X1R5G5B5);
2269 if(!nmodes) {
2270 skip("Display format X1R5G5B5 not supported, skipping\n");
2271 } else {
2272 trace("Testing display format X1R5G5B5\n");
2273 for(i=0; x1r5g5b5_format_list[i].DisplayFormat != 0; i++)
2275 hr = IDirect3D9_CheckDeviceType(d3d9, Adapter, DeviceType, x1r5g5b5_format_list[i].DisplayFormat, x1r5g5b5_format_list[i].BackBufferFormat, FALSE);
2277 if(x1r5g5b5_format_list[i].shouldPass)
2278 ok(hr == D3D_OK, "format %d %d didn't pass with hr=%#08x\n", x1r5g5b5_format_list[i].DisplayFormat, x1r5g5b5_format_list[i].BackBufferFormat, hr);
2279 else
2280 ok(hr != D3D_OK, "format %d %d didn't pass while it was expected to\n", x1r5g5b5_format_list[i].DisplayFormat, x1r5g5b5_format_list[i].BackBufferFormat);
2284 nmodes = IDirect3D9_GetAdapterModeCount(d3d9, D3DADAPTER_DEFAULT, D3DFMT_X8R8G8B8);
2285 if(!nmodes) {
2286 skip("Display format X8R8G8B8 not supported, skipping\n");
2287 } else {
2288 trace("Testing display format X8R8G8B8\n");
2289 for(i=0; x8r8g8b8_format_list[i].DisplayFormat != 0; i++)
2291 hr = IDirect3D9_CheckDeviceType(d3d9, Adapter, DeviceType, x8r8g8b8_format_list[i].DisplayFormat, x8r8g8b8_format_list[i].BackBufferFormat, FALSE);
2293 if(x8r8g8b8_format_list[i].shouldPass)
2294 ok(hr == D3D_OK ||
2295 broken(hr == D3DERR_NOTAVAILABLE),
2296 "format %d %d didn't pass with hr=%#08x\n", x8r8g8b8_format_list[i].DisplayFormat, x8r8g8b8_format_list[i].BackBufferFormat, hr);
2297 else
2298 ok(hr != D3D_OK, "format %d %d didn't pass while it was expected to\n", x8r8g8b8_format_list[i].DisplayFormat, x8r8g8b8_format_list[i].BackBufferFormat);
2302 if(d3d9) IDirect3D9_Release(d3d9);
2305 static void test_scissor_size(void)
2307 IDirect3D9 *d3d9_ptr = 0;
2308 unsigned int i;
2309 static struct {
2310 int winx; int winy; int backx; int backy; BOOL window;
2311 } scts[] = { /* scissor tests */
2312 {800, 600, 640, 480, TRUE},
2313 {800, 600, 640, 480, FALSE},
2314 {640, 480, 800, 600, TRUE},
2315 {640, 480, 800, 600, FALSE},
2318 d3d9_ptr = pDirect3DCreate9(D3D_SDK_VERSION);
2319 ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
2320 if (!d3d9_ptr){
2321 skip("Failed to create IDirect3D9 object\n");
2322 return;
2325 for(i=0; i<sizeof(scts)/sizeof(scts[0]); i++) {
2326 IDirect3DDevice9 *device_ptr = 0;
2327 D3DPRESENT_PARAMETERS present_parameters;
2328 HRESULT hr;
2329 HWND hwnd = 0;
2330 RECT scissorrect;
2332 hwnd = CreateWindow("d3d9_test_wc", "d3d9_test",
2333 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION , 0, 0, scts[i].winx, scts[i].winy, 0, 0, 0, 0);
2335 if (!scts[i].window)
2337 scts[i].backx = screen_width;
2338 scts[i].backy = screen_height;
2341 ZeroMemory(&present_parameters, sizeof(present_parameters));
2342 present_parameters.Windowed = scts[i].window;
2343 present_parameters.hDeviceWindow = hwnd;
2344 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2345 present_parameters.BackBufferWidth = scts[i].backx;
2346 present_parameters.BackBufferHeight = scts[i].backy;
2347 present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
2348 present_parameters.EnableAutoDepthStencil = TRUE;
2349 present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8;
2351 hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
2352 if(FAILED(hr)) {
2353 present_parameters.AutoDepthStencilFormat = D3DFMT_D16;
2354 hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
2355 if(FAILED(hr)) {
2356 hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
2359 ok(hr == D3D_OK || hr == D3DERR_NOTAVAILABLE, "IDirect3D_CreateDevice returned: %08x\n", hr);
2361 if (!device_ptr)
2363 DestroyWindow(hwnd);
2364 skip("Creating the device failed\n");
2365 goto err_out;
2368 /* Check for the default scissor rect size */
2369 hr = IDirect3DDevice9_GetScissorRect(device_ptr, &scissorrect);
2370 ok(hr == D3D_OK, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr);
2371 ok(scissorrect.right == scts[i].backx && scissorrect.bottom == scts[i].backy && scissorrect.top == 0 && scissorrect.left == 0, "Scissorrect missmatch (%d, %d) should be (%d, %d)\n", scissorrect.right, scissorrect.bottom, scts[i].backx, scts[i].backy);
2373 /* check the scissorrect values after a reset */
2374 present_parameters.BackBufferWidth = screen_width;
2375 present_parameters.BackBufferHeight = screen_height;
2376 hr = IDirect3DDevice9_Reset(device_ptr, &present_parameters);
2377 ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %08x\n", hr);
2378 hr = IDirect3DDevice9_TestCooperativeLevel(device_ptr);
2379 ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successful reset returned %#x\n", hr);
2381 hr = IDirect3DDevice9_GetScissorRect(device_ptr, &scissorrect);
2382 ok(hr == D3D_OK, "IDirect3DDevice9_GetScissorRect failed with: %08x\n", hr);
2383 ok(scissorrect.right == screen_width && scissorrect.bottom == screen_height && scissorrect.top == 0 && scissorrect.left == 0, "Scissorrect missmatch (%d, %d) should be (%d, %d)\n", scissorrect.right, scissorrect.bottom, screen_width, screen_height);
2385 if(device_ptr) {
2386 ULONG ref;
2388 ref = IDirect3DDevice9_Release(device_ptr);
2389 DestroyWindow(hwnd);
2390 ok(ref == 0, "The device was not properly freed: refcount %u\n", ref);
2394 err_out:
2395 if(d3d9_ptr) IDirect3D9_Release(d3d9_ptr);
2396 return;
2399 static void test_multi_device(void)
2401 IDirect3DDevice9 *device1 = NULL, *device2 = NULL;
2402 D3DPRESENT_PARAMETERS present_parameters;
2403 HWND hwnd1 = NULL, hwnd2 = NULL;
2404 IDirect3D9 *d3d9;
2405 ULONG refcount;
2406 HRESULT hr;
2408 d3d9 = pDirect3DCreate9(D3D_SDK_VERSION);
2409 ok(d3d9 != NULL, "Failed to create a d3d9 object.\n");
2410 if (!d3d9) goto fail;
2412 hwnd1 = CreateWindow("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL);
2413 ok(hwnd1 != NULL, "Failed to create a window.\n");
2414 if (!hwnd1) goto fail;
2416 memset(&present_parameters, 0, sizeof(present_parameters));
2417 present_parameters.Windowed = TRUE;
2418 present_parameters.hDeviceWindow = hwnd1;
2419 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2421 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd1,
2422 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device1);
2423 IDirect3D9_Release(d3d9);
2424 d3d9 = NULL;
2425 if (FAILED(hr)) {
2426 skip("Failed to create a device\n");
2427 goto fail;
2430 d3d9 = pDirect3DCreate9(D3D_SDK_VERSION);
2431 ok(d3d9 != NULL, "Failed to create a d3d9 object.\n");
2432 if (!d3d9) goto fail;
2434 hwnd2 = CreateWindow("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL);
2435 ok(hwnd2 != NULL, "Failed to create a window.\n");
2436 if (!hwnd2) goto fail;
2438 memset(&present_parameters, 0, sizeof(present_parameters));
2439 present_parameters.Windowed = TRUE;
2440 present_parameters.hDeviceWindow = hwnd2;
2441 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
2443 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd2,
2444 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device2);
2445 ok(SUCCEEDED(hr), "Failed to create a device, hr %#x\n", hr);
2446 IDirect3D9_Release(d3d9);
2447 d3d9 = NULL;
2448 if (FAILED(hr)) goto fail;
2450 fail:
2451 if (d3d9) IDirect3D9_Release(d3d9);
2452 if (device1)
2454 refcount = IDirect3DDevice9_Release(device1);
2455 ok(!refcount, "Device has %u references left.\n", refcount);
2457 if (device2)
2459 refcount = IDirect3DDevice9_Release(device2);
2460 ok(!refcount, "Device has %u references left.\n", refcount);
2462 if (hwnd1) DestroyWindow(hwnd1);
2463 if (hwnd2) DestroyWindow(hwnd2);
2466 static HWND filter_messages;
2468 enum message_window
2470 DEVICE_WINDOW,
2471 FOCUS_WINDOW,
2474 struct message
2476 UINT message;
2477 enum message_window window;
2480 static const struct message *expect_messages;
2481 static HWND device_window, focus_window;
2483 struct wndproc_thread_param
2485 HWND dummy_window;
2486 HANDLE window_created;
2487 HANDLE test_finished;
2488 BOOL running_in_foreground;
2491 static LRESULT CALLBACK test_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
2493 if (filter_messages && filter_messages == hwnd)
2495 if (message != WM_DISPLAYCHANGE && message != WM_IME_NOTIFY)
2496 todo_wine ok( 0, "Received unexpected message %#x for window %p.\n", message, hwnd);
2499 if (expect_messages)
2501 HWND w;
2503 switch (expect_messages->window)
2505 case DEVICE_WINDOW:
2506 w = device_window;
2507 break;
2509 case FOCUS_WINDOW:
2510 w = focus_window;
2511 break;
2513 default:
2514 w = NULL;
2515 break;
2518 if (hwnd == w && expect_messages->message == message) ++expect_messages;
2521 return DefWindowProcA(hwnd, message, wparam, lparam);
2524 static DWORD WINAPI wndproc_thread(void *param)
2526 struct wndproc_thread_param *p = param;
2527 DWORD res;
2528 BOOL ret;
2530 p->dummy_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2531 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2532 p->running_in_foreground = SetForegroundWindow(p->dummy_window);
2534 ret = SetEvent(p->window_created);
2535 ok(ret, "SetEvent failed, last error %#x.\n", GetLastError());
2537 for (;;)
2539 MSG msg;
2541 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
2542 res = WaitForSingleObject(p->test_finished, 100);
2543 if (res == WAIT_OBJECT_0) break;
2544 if (res != WAIT_TIMEOUT)
2546 ok(0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2547 break;
2551 DestroyWindow(p->dummy_window);
2553 return 0;
2556 static void test_wndproc(void)
2558 struct wndproc_thread_param thread_params;
2559 IDirect3DDevice9 *device;
2560 WNDCLASSA wc = {0};
2561 IDirect3D9 *d3d9;
2562 HANDLE thread;
2563 LONG_PTR proc;
2564 ULONG ref;
2565 DWORD res, tid;
2566 HWND tmp;
2568 static const struct message messages[] =
2570 {WM_WINDOWPOSCHANGING, FOCUS_WINDOW},
2571 {WM_ACTIVATE, FOCUS_WINDOW},
2572 {WM_SETFOCUS, FOCUS_WINDOW},
2573 {0, 0},
2576 if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
2578 skip("Failed to create IDirect3D9 object, skipping tests.\n");
2579 return;
2582 wc.lpfnWndProc = test_proc;
2583 wc.lpszClassName = "d3d9_test_wndproc_wc";
2584 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2586 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2587 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2588 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2589 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2591 focus_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2592 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2593 device_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2594 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2595 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2596 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2598 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2599 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2601 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2602 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2603 (LONG_PTR)test_proc, proc);
2604 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2605 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2606 (LONG_PTR)test_proc, proc);
2608 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2609 device_window, focus_window, thread_params.dummy_window);
2611 tmp = GetFocus();
2612 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2613 if (thread_params.running_in_foreground)
2615 tmp = GetForegroundWindow();
2616 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2617 thread_params.dummy_window, tmp);
2619 else
2620 skip("Not running in foreground, skip foreground window test\n");
2622 flush_events();
2624 expect_messages = messages;
2626 device = create_device(d3d9, device_window, focus_window, FALSE);
2627 if (!device)
2629 skip("Failed to create a D3D device, skipping tests.\n");
2630 goto done;
2633 ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n",
2634 expect_messages->message, expect_messages->window);
2635 expect_messages = NULL;
2637 if (0) /* Disabled until we can make this work in a reliable way on Wine. */
2639 tmp = GetFocus();
2640 ok(tmp == focus_window, "Expected focus %p, got %p.\n", focus_window, tmp);
2641 tmp = GetForegroundWindow();
2642 ok(tmp == focus_window, "Expected foreground window %p, got %p.\n", focus_window, tmp);
2644 SetForegroundWindow(focus_window);
2645 flush_events();
2647 filter_messages = focus_window;
2649 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2650 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2651 (LONG_PTR)test_proc, proc);
2653 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2654 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2655 (LONG_PTR)test_proc, proc);
2657 ref = IDirect3DDevice9_Release(device);
2658 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2660 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2661 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2662 (LONG_PTR)test_proc, proc);
2664 device = create_device(d3d9, focus_window, focus_window, FALSE);
2665 if (!device)
2667 skip("Failed to create a D3D device, skipping tests.\n");
2668 goto done;
2671 ref = IDirect3DDevice9_Release(device);
2672 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2674 device = create_device(d3d9, device_window, focus_window, FALSE);
2675 if (!device)
2677 skip("Failed to create a D3D device, skipping tests.\n");
2678 goto done;
2681 proc = SetWindowLongPtrA(focus_window, GWLP_WNDPROC, (LONG_PTR)DefWindowProcA);
2682 ok(proc != (LONG_PTR)test_proc, "Expected wndproc != %#lx, got %#lx.\n",
2683 (LONG_PTR)test_proc, proc);
2685 ref = IDirect3DDevice9_Release(device);
2686 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2688 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2689 ok(proc == (LONG_PTR)DefWindowProcA, "Expected wndproc %#lx, got %#lx.\n",
2690 (LONG_PTR)DefWindowProcA, proc);
2692 done:
2693 filter_messages = NULL;
2694 IDirect3D9_Release(d3d9);
2696 SetEvent(thread_params.test_finished);
2697 WaitForSingleObject(thread, INFINITE);
2698 CloseHandle(thread_params.test_finished);
2699 CloseHandle(thread_params.window_created);
2700 CloseHandle(thread);
2702 DestroyWindow(device_window);
2703 DestroyWindow(focus_window);
2704 UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL));
2707 static void test_wndproc_windowed(void)
2709 struct wndproc_thread_param thread_params;
2710 IDirect3DDevice9 *device;
2711 WNDCLASSA wc = {0};
2712 IDirect3D9 *d3d9;
2713 HANDLE thread;
2714 LONG_PTR proc;
2715 HRESULT hr;
2716 ULONG ref;
2717 DWORD res, tid;
2718 HWND tmp;
2720 if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
2722 skip("Failed to create IDirect3D9 object, skipping tests.\n");
2723 return;
2726 wc.lpfnWndProc = test_proc;
2727 wc.lpszClassName = "d3d9_test_wndproc_wc";
2728 ok(RegisterClassA(&wc), "Failed to register window class.\n");
2730 thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
2731 ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
2732 thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
2733 ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
2735 focus_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2736 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2737 device_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test",
2738 WS_MAXIMIZE | WS_VISIBLE | WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
2739 thread = CreateThread(NULL, 0, wndproc_thread, &thread_params, 0, &tid);
2740 ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
2742 res = WaitForSingleObject(thread_params.window_created, INFINITE);
2743 ok(res == WAIT_OBJECT_0, "Wait failed (%#x), last error %#x.\n", res, GetLastError());
2745 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2746 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2747 (LONG_PTR)test_proc, proc);
2748 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2749 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2750 (LONG_PTR)test_proc, proc);
2752 trace("device_window %p, focus_window %p, dummy_window %p.\n",
2753 device_window, focus_window, thread_params.dummy_window);
2755 tmp = GetFocus();
2756 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2757 if (thread_params.running_in_foreground)
2759 tmp = GetForegroundWindow();
2760 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2761 thread_params.dummy_window, tmp);
2763 else
2764 skip("Not running in foreground, skip foreground window test\n");
2766 filter_messages = focus_window;
2768 device = create_device(d3d9, device_window, focus_window, TRUE);
2769 if (!device)
2771 skip("Failed to create a D3D device, skipping tests.\n");
2772 goto done;
2775 tmp = GetFocus();
2776 ok(tmp == device_window, "Expected focus %p, got %p.\n", device_window, tmp);
2777 tmp = GetForegroundWindow();
2778 ok(tmp == thread_params.dummy_window, "Expected foreground window %p, got %p.\n",
2779 thread_params.dummy_window, tmp);
2781 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2782 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2783 (LONG_PTR)test_proc, proc);
2785 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2786 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2787 (LONG_PTR)test_proc, proc);
2789 filter_messages = NULL;
2791 hr = reset_device(device, device_window, FALSE);
2792 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2794 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2795 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2796 (LONG_PTR)test_proc, proc);
2798 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2799 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2800 (LONG_PTR)test_proc, proc);
2802 hr = reset_device(device, device_window, TRUE);
2803 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2805 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2806 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2807 (LONG_PTR)test_proc, proc);
2809 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2810 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2811 (LONG_PTR)test_proc, proc);
2813 filter_messages = focus_window;
2815 ref = IDirect3DDevice9_Release(device);
2816 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2818 filter_messages = device_window;
2820 device = create_device(d3d9, focus_window, focus_window, TRUE);
2821 if (!device)
2823 skip("Failed to create a D3D device, skipping tests.\n");
2824 goto done;
2827 filter_messages = NULL;
2829 hr = reset_device(device, focus_window, FALSE);
2830 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2832 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2833 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2834 (LONG_PTR)test_proc, proc);
2836 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2837 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2838 (LONG_PTR)test_proc, proc);
2840 hr = reset_device(device, focus_window, TRUE);
2841 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2843 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2844 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2845 (LONG_PTR)test_proc, proc);
2847 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2848 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2849 (LONG_PTR)test_proc, proc);
2851 filter_messages = device_window;
2853 ref = IDirect3DDevice9_Release(device);
2854 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2856 device = create_device(d3d9, device_window, focus_window, TRUE);
2857 if (!device)
2859 skip("Failed to create a D3D device, skipping tests.\n");
2860 goto done;
2863 filter_messages = NULL;
2865 hr = reset_device(device, device_window, FALSE);
2866 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2868 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2869 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2870 (LONG_PTR)test_proc, proc);
2872 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2873 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2874 (LONG_PTR)test_proc, proc);
2876 hr = reset_device(device, device_window, TRUE);
2877 ok(SUCCEEDED(hr), "Failed to reset device, hr %#x.\n", hr);
2879 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
2880 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2881 (LONG_PTR)test_proc, proc);
2883 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
2884 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
2885 (LONG_PTR)test_proc, proc);
2887 filter_messages = device_window;
2889 ref = IDirect3DDevice9_Release(device);
2890 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
2892 done:
2893 filter_messages = NULL;
2894 IDirect3D9_Release(d3d9);
2896 SetEvent(thread_params.test_finished);
2897 WaitForSingleObject(thread, INFINITE);
2898 CloseHandle(thread_params.test_finished);
2899 CloseHandle(thread_params.window_created);
2900 CloseHandle(thread);
2902 DestroyWindow(device_window);
2903 DestroyWindow(focus_window);
2904 UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL));
2907 static void test_reset_fullscreen(void)
2909 WNDCLASSEX wc = {0};
2910 IDirect3DDevice9 *device = NULL;
2911 IDirect3D9 *d3d = NULL;
2912 ATOM atom;
2913 static const struct message messages[] =
2915 {WM_ACTIVATEAPP, FOCUS_WINDOW},
2916 {0, 0},
2919 d3d = pDirect3DCreate9(D3D_SDK_VERSION);
2920 ok(d3d != NULL, "Failed to create an IDirect3D object.\n");
2921 expect_messages = messages;
2923 wc.cbSize = sizeof(WNDCLASSEX);
2924 wc.lpfnWndProc = test_proc;
2925 wc.lpszClassName = "test_reset_fullscreen";
2927 atom = RegisterClassEx(&wc);
2928 ok(atom, "Failed to register a new window class. GetLastError:%d\n", GetLastError());
2930 device_window = focus_window = CreateWindowEx(0, wc.lpszClassName, "Test Reset Fullscreen", 0, 0, 0, screen_width, screen_height, NULL, NULL, NULL, NULL);
2931 ok(device_window != NULL, "Failed to create a window. GetLastError:%d\n", GetLastError());
2934 * Create a device in windowed mode.
2935 * Since the device is windowed and we haven't called any methods that
2936 * could show the window (such as ShowWindow or SetWindowPos) yet,
2937 * WM_ACTIVATEAPP will not have been sent.
2939 device = create_device(d3d, device_window, focus_window, TRUE);
2940 if (!device)
2942 skip("Unable to create device. Skipping test.\n");
2943 goto cleanup;
2947 * Switch to fullscreen mode.
2948 * This will force the window to be shown and will cause the WM_ACTIVATEAPP
2949 * message to be sent.
2951 ok(SUCCEEDED(reset_device(device, device_window, FALSE)), "Failed to reset device.\n");
2953 flush_events();
2954 ok(expect_messages->message == 0, "Expected to receive message %#x.\n", expect_messages->message);
2955 expect_messages = NULL;
2957 cleanup:
2958 if (device) IDirect3DDevice9_Release(device);
2959 if (d3d) IDirect3D9_Release(d3d);
2960 DestroyWindow(device_window);
2961 device_window = focus_window = NULL;
2962 UnregisterClass(wc.lpszClassName, GetModuleHandle(NULL));
2966 static inline void set_fpu_cw(WORD cw)
2968 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2969 #define D3D9_TEST_SET_FPU_CW 1
2970 __asm__ volatile ("fnclex");
2971 __asm__ volatile ("fldcw %0" : : "m" (cw));
2972 #elif defined(__i386__) && defined(_MSC_VER)
2973 #define D3D9_TEST_SET_FPU_CW 1
2974 __asm fnclex;
2975 __asm fldcw cw;
2976 #endif
2979 static inline WORD get_fpu_cw(void)
2981 WORD cw = 0;
2982 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
2983 #define D3D9_TEST_GET_FPU_CW 1
2984 __asm__ volatile ("fnstcw %0" : "=m" (cw));
2985 #elif defined(__i386__) && defined(_MSC_VER)
2986 #define D3D9_TEST_GET_FPU_CW 1
2987 __asm fnstcw cw;
2988 #endif
2989 return cw;
2992 static void test_fpu_setup(void)
2994 #if defined(D3D9_TEST_SET_FPU_CW) && defined(D3D9_TEST_GET_FPU_CW)
2995 D3DPRESENT_PARAMETERS present_parameters;
2996 IDirect3DDevice9 *device;
2997 HWND window = NULL;
2998 IDirect3D9 *d3d9;
2999 HRESULT hr;
3000 WORD cw;
3002 d3d9 = pDirect3DCreate9(D3D_SDK_VERSION);
3003 ok(!!d3d9, "Failed to create a d3d9 object.\n");
3004 if (!d3d9) return;
3006 window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_CAPTION, 0, 0, screen_width, screen_height, 0, 0, 0, 0);
3007 ok(!!window, "Failed to create a window.\n");
3008 if (!window) goto done;
3010 memset(&present_parameters, 0, sizeof(present_parameters));
3011 present_parameters.Windowed = TRUE;
3012 present_parameters.hDeviceWindow = window;
3013 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
3015 set_fpu_cw(0xf60);
3016 cw = get_fpu_cw();
3017 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3019 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
3020 D3DCREATE_HARDWARE_VERTEXPROCESSING, &present_parameters, &device);
3021 if (FAILED(hr))
3023 skip("Failed to create a device, hr %#x.\n", hr);
3024 set_fpu_cw(0x37f);
3025 goto done;
3028 cw = get_fpu_cw();
3029 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3031 IDirect3DDevice9_Release(device);
3033 cw = get_fpu_cw();
3034 ok(cw == 0x7f, "cw is %#x, expected 0x7f.\n", cw);
3035 set_fpu_cw(0xf60);
3036 cw = get_fpu_cw();
3037 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3039 hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
3040 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &present_parameters, &device);
3041 ok(SUCCEEDED(hr), "CreateDevice failed, hr %#x.\n", hr);
3043 cw = get_fpu_cw();
3044 ok(cw == 0xf60, "cw is %#x, expected 0xf60.\n", cw);
3045 set_fpu_cw(0x37f);
3047 IDirect3DDevice9_Release(device);
3049 done:
3050 if (window) DestroyWindow(window);
3051 if (d3d9) IDirect3D9_Release(d3d9);
3052 #endif
3055 static void test_window_style(void)
3057 RECT focus_rect, fullscreen_rect, r;
3058 LONG device_style, device_exstyle;
3059 LONG focus_style, focus_exstyle;
3060 LONG style, expected_style;
3061 IDirect3DDevice9 *device;
3062 IDirect3D9 *d3d9;
3063 ULONG ref;
3066 if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
3068 skip("Failed to create IDirect3D9 object, skipping tests.\n");
3069 return;
3072 focus_window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
3073 0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
3074 device_window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
3075 0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
3077 device_style = GetWindowLongA(device_window, GWL_STYLE);
3078 device_exstyle = GetWindowLongA(device_window, GWL_EXSTYLE);
3079 focus_style = GetWindowLongA(focus_window, GWL_STYLE);
3080 focus_exstyle = GetWindowLongA(focus_window, GWL_EXSTYLE);
3082 SetRect(&fullscreen_rect, 0, 0, screen_width, screen_height);
3083 GetWindowRect(focus_window, &focus_rect);
3085 device = create_device(d3d9, device_window, focus_window, FALSE);
3086 if (!device)
3088 skip("Failed to create a D3D device, skipping tests.\n");
3089 goto done;
3092 style = GetWindowLongA(device_window, GWL_STYLE);
3093 expected_style = device_style | WS_VISIBLE;
3094 todo_wine ok(style == expected_style, "Expected device window style %#x, got %#x.\n",
3095 expected_style, style);
3096 style = GetWindowLongA(device_window, GWL_EXSTYLE);
3097 expected_style = device_exstyle | WS_EX_TOPMOST;
3098 todo_wine ok(style == expected_style, "Expected device window extended style %#x, got %#x.\n",
3099 expected_style, style);
3101 style = GetWindowLongA(focus_window, GWL_STYLE);
3102 ok(style == focus_style, "Expected focus window style %#x, got %#x.\n",
3103 focus_style, style);
3104 style = GetWindowLongA(focus_window, GWL_EXSTYLE);
3105 ok(style == focus_exstyle, "Expected focus window extended style %#x, got %#x.\n",
3106 focus_exstyle, style);
3108 GetWindowRect(device_window, &r);
3109 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3110 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3111 r.left, r.top, r.right, r.bottom);
3112 GetClientRect(device_window, &r);
3113 todo_wine ok(!EqualRect(&r, &fullscreen_rect), "Client rect and window rect are equal.\n");
3114 GetWindowRect(focus_window, &r);
3115 ok(EqualRect(&r, &focus_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3116 focus_rect.left, focus_rect.top, focus_rect.right, focus_rect.bottom,
3117 r.left, r.top, r.right, r.bottom);
3119 ref = IDirect3DDevice9_Release(device);
3120 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3122 done:
3123 IDirect3D9_Release(d3d9);
3125 DestroyWindow(device_window);
3126 DestroyWindow(focus_window);
3129 static const POINT *expect_pos;
3131 static LRESULT CALLBACK test_cursor_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
3133 if (message == WM_MOUSEMOVE)
3135 if (expect_pos && expect_pos->x && expect_pos->y)
3137 POINT p = {GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)};
3139 ClientToScreen(window, &p);
3140 if (expect_pos->x == p.x && expect_pos->y == p.y)
3141 ++expect_pos;
3145 return DefWindowProcA(window, message, wparam, lparam);
3148 static void test_cursor_pos(void)
3150 IDirect3DSurface9 *cursor;
3151 IDirect3DDevice9 *device;
3152 WNDCLASSA wc = {0};
3153 IDirect3D9 *d3d9;
3154 UINT refcount;
3155 HWND window;
3156 HRESULT hr;
3157 BOOL ret;
3159 /* Note that we don't check for movement we're not supposed to receive.
3160 * That's because it's hard to distinguish from the user accidentally
3161 * moving the mouse. */
3162 static const POINT points[] =
3164 {50, 50},
3165 {75, 75},
3166 {100, 100},
3167 {125, 125},
3168 {150, 150},
3169 {125, 125},
3170 {150, 150},
3171 {150, 150},
3172 {0, 0},
3175 if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
3177 skip("Failed to create IDirect3D9 object, skipping cursor tests.\n");
3178 return;
3181 wc.lpfnWndProc = test_cursor_proc;
3182 wc.lpszClassName = "d3d9_test_cursor_wc";
3183 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3184 window = CreateWindow("d3d9_test_cursor_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
3185 0, 0, 320, 240, NULL, NULL, NULL, NULL);
3186 ShowWindow(window, SW_SHOW);
3188 device = create_device(d3d9, window, window, TRUE);
3189 if (!device)
3191 skip("Failed to create a D3D device, skipping tests.\n");
3192 goto done;
3195 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32,
3196 D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &cursor, NULL);
3197 ok(SUCCEEDED(hr), "Failed to create cursor surface, hr %#x.\n", hr);
3198 hr = IDirect3DDevice9_SetCursorProperties(device, 0, 0, cursor);
3199 ok(SUCCEEDED(hr), "Failed to set cursor properties, hr %#x.\n", hr);
3200 IDirect3DSurface9_Release(cursor);
3201 ret = IDirect3DDevice9_ShowCursor(device, TRUE);
3202 ok(!ret, "Failed to show cursor, hr %#x.\n", ret);
3204 flush_events();
3205 expect_pos = points;
3207 ret = SetCursorPos(50, 50);
3208 ok(ret, "Failed to set cursor position.\n");
3209 flush_events();
3211 IDirect3DDevice9_SetCursorPosition(device, 75, 75, 0);
3212 flush_events();
3213 /* SetCursorPosition() eats duplicates. */
3214 IDirect3DDevice9_SetCursorPosition(device, 75, 75, 0);
3215 flush_events();
3217 ret = SetCursorPos(100, 100);
3218 ok(ret, "Failed to set cursor position.\n");
3219 flush_events();
3220 /* Even if the position was set with SetCursorPos(). */
3221 IDirect3DDevice9_SetCursorPosition(device, 100, 100, 0);
3222 flush_events();
3224 IDirect3DDevice9_SetCursorPosition(device, 125, 125, 0);
3225 flush_events();
3226 ret = SetCursorPos(150, 150);
3227 ok(ret, "Failed to set cursor position.\n");
3228 flush_events();
3229 IDirect3DDevice9_SetCursorPosition(device, 125, 125, 0);
3230 flush_events();
3232 IDirect3DDevice9_SetCursorPosition(device, 150, 150, 0);
3233 flush_events();
3234 /* SetCursorPos() doesn't. */
3235 ret = SetCursorPos(150, 150);
3236 ok(ret, "Failed to set cursor position.\n");
3237 flush_events();
3239 ok(!expect_pos->x && !expect_pos->y, "Didn't receive MOUSEMOVE %u (%d, %d).\n",
3240 (unsigned)(expect_pos - points), expect_pos->x, expect_pos->y);
3242 refcount = IDirect3DDevice9_Release(device);
3243 ok(!refcount, "Device has %u references left.\n", refcount);
3244 done:
3245 DestroyWindow(window);
3246 UnregisterClassA("d3d9_test_cursor_wc", GetModuleHandleA(NULL));
3247 if (d3d9)
3248 IDirect3D9_Release(d3d9);
3251 static void test_mode_change(void)
3253 RECT fullscreen_rect, focus_rect, r;
3254 IDirect3DSurface9 *backbuffer;
3255 IDirect3DDevice9 *device;
3256 D3DSURFACE_DESC desc;
3257 IDirect3D9 *d3d9;
3258 DEVMODEW devmode;
3259 UINT refcount;
3260 HRESULT hr;
3261 DWORD ret;
3263 if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
3265 skip("Failed to create IDirect3D9 object, skipping mode change tests.\n");
3266 return;
3269 focus_window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
3270 0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
3271 device_window = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
3272 0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
3274 SetRect(&fullscreen_rect, 0, 0, screen_width, screen_height);
3275 GetWindowRect(focus_window, &focus_rect);
3277 device = create_device(d3d9, device_window, focus_window, FALSE);
3278 if (!device)
3280 skip("Failed to create a D3D device, skipping tests.\n");
3281 goto done;
3284 memset(&devmode, 0, sizeof(devmode));
3285 devmode.dmSize = sizeof(devmode);
3286 devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
3287 devmode.dmPelsWidth = 640;
3288 devmode.dmPelsHeight = 480;
3290 ret = ChangeDisplaySettingsW(&devmode, CDS_FULLSCREEN);
3291 ok(ret == DISP_CHANGE_SUCCESSFUL, "Failed to change display mode, ret %#x.\n", ret);
3293 memset(&devmode, 0, sizeof(devmode));
3294 devmode.dmSize = sizeof(devmode);
3295 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3296 ok(ret, "Failed to get display mode.\n");
3297 ok(devmode.dmPelsWidth == 640, "Got unexpect width %u.\n", devmode.dmPelsWidth);
3298 ok(devmode.dmPelsHeight == 480, "Got unexpect height %u.\n", devmode.dmPelsHeight);
3300 GetWindowRect(device_window, &r);
3301 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3302 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3303 r.left, r.top, r.right, r.bottom);
3304 GetWindowRect(focus_window, &r);
3305 ok(EqualRect(&r, &focus_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3306 focus_rect.left, focus_rect.top, focus_rect.right, focus_rect.bottom,
3307 r.left, r.top, r.right, r.bottom);
3309 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
3310 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
3311 hr = IDirect3DSurface9_GetDesc(backbuffer, &desc);
3312 ok(SUCCEEDED(hr), "Failed to get backbuffer desc, hr %#x.\n", hr);
3313 ok(desc.Width == screen_width, "Got unexpected backbuffer width %u.\n", desc.Width);
3314 ok(desc.Height == screen_height, "Got unexpected backbuffer height %u.\n", desc.Height);
3315 IDirect3DSurface9_Release(backbuffer);
3317 refcount = IDirect3DDevice9_Release(device);
3318 ok(!refcount, "Device has %u references left.\n", refcount);
3320 memset(&devmode, 0, sizeof(devmode));
3321 devmode.dmSize = sizeof(devmode);
3322 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3323 ok(ret, "Failed to get display mode.\n");
3324 ok(devmode.dmPelsWidth == screen_width, "Got unexpect width %u.\n", devmode.dmPelsWidth);
3325 ok(devmode.dmPelsHeight == screen_height, "Got unexpect height %u.\n", devmode.dmPelsHeight);
3327 done:
3328 DestroyWindow(device_window);
3329 DestroyWindow(focus_window);
3330 if (d3d9)
3331 IDirect3D9_Release(d3d9);
3333 memset(&devmode, 0, sizeof(devmode));
3334 devmode.dmSize = sizeof(devmode);
3335 ret = EnumDisplaySettingsW(NULL, ENUM_CURRENT_SETTINGS, &devmode);
3336 ok(ret, "Failed to get display mode.\n");
3337 ok(devmode.dmPelsWidth == screen_width, "Got unexpect width %u.\n", devmode.dmPelsWidth);
3338 ok(devmode.dmPelsHeight == screen_height, "Got unexpect height %u.\n", devmode.dmPelsHeight);
3341 static void test_device_window_reset(void)
3343 RECT fullscreen_rect, device_rect, r;
3344 IDirect3DDevice9 *device;
3345 WNDCLASSA wc = {0};
3346 IDirect3D9 *d3d9;
3347 LONG_PTR proc;
3348 HRESULT hr;
3349 ULONG ref;
3351 if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
3353 skip("Failed to create IDirect3D9 object, skipping tests.\n");
3354 return;
3357 wc.lpfnWndProc = test_proc;
3358 wc.lpszClassName = "d3d9_test_wndproc_wc";
3359 ok(RegisterClassA(&wc), "Failed to register window class.\n");
3361 focus_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
3362 0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
3363 device_window = CreateWindowA("d3d9_test_wndproc_wc", "d3d9_test", WS_OVERLAPPEDWINDOW,
3364 0, 0, screen_width / 2, screen_height / 2, 0, 0, 0, 0);
3366 SetRect(&fullscreen_rect, 0, 0, screen_width, screen_height);
3367 GetWindowRect(device_window, &device_rect);
3369 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3370 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3371 (LONG_PTR)test_proc, proc);
3372 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3373 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3374 (LONG_PTR)test_proc, proc);
3376 device = create_device(d3d9, NULL, focus_window, FALSE);
3377 if (!device)
3379 skip("Failed to create a D3D device, skipping tests.\n");
3380 goto done;
3383 GetWindowRect(focus_window, &r);
3384 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3385 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3386 r.left, r.top, r.right, r.bottom);
3387 GetWindowRect(device_window, &r);
3388 ok(EqualRect(&r, &device_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3389 device_rect.left, device_rect.top, device_rect.right, device_rect.bottom,
3390 r.left, r.top, r.right, r.bottom);
3392 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3393 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3394 (LONG_PTR)test_proc, proc);
3395 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3396 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3397 (LONG_PTR)test_proc, proc);
3399 hr = reset_device(device, device_window, FALSE);
3400 ok(SUCCEEDED(hr), "Failed to reset device.\n");
3402 GetWindowRect(focus_window, &r);
3403 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3404 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3405 r.left, r.top, r.right, r.bottom);
3406 GetWindowRect(device_window, &r);
3407 ok(EqualRect(&r, &fullscreen_rect), "Expected {%d, %d, %d, %d}, got {%d, %d, %d, %d}.\n",
3408 fullscreen_rect.left, fullscreen_rect.top, fullscreen_rect.right, fullscreen_rect.bottom,
3409 r.left, r.top, r.right, r.bottom);
3411 proc = GetWindowLongPtrA(device_window, GWLP_WNDPROC);
3412 ok(proc == (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3413 (LONG_PTR)test_proc, proc);
3414 proc = GetWindowLongPtrA(focus_window, GWLP_WNDPROC);
3415 ok(proc != (LONG_PTR)test_proc, "Expected wndproc %#lx, got %#lx.\n",
3416 (LONG_PTR)test_proc, proc);
3418 ref = IDirect3DDevice9_Release(device);
3419 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3421 done:
3422 IDirect3D9_Release(d3d9);
3423 DestroyWindow(device_window);
3424 DestroyWindow(focus_window);
3425 UnregisterClassA("d3d9_test_wndproc_wc", GetModuleHandleA(NULL));
3428 static void test_reset_resources(void)
3430 IDirect3DSurface9 *surface, *rt;
3431 IDirect3DTexture9 *texture;
3432 IDirect3DDevice9 *device;
3433 IDirect3D9 *d3d9;
3434 unsigned int i;
3435 D3DCAPS9 caps;
3436 HWND window;
3437 HRESULT hr;
3438 ULONG ref;
3440 window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
3441 0, 0, 640, 480, 0, 0, 0, 0);
3443 if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
3445 skip("Failed to create IDirect3D9 object, skipping tests.\n");
3446 DestroyWindow(window);
3447 return;
3450 if (!(device = create_device(d3d9, window, window, TRUE)))
3452 skip("Failed to create a D3D device, skipping tests.\n");
3453 goto done;
3456 hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
3457 ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
3459 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_DEPTHSTENCIL,
3460 D3DFMT_D24S8, D3DPOOL_DEFAULT, &texture, NULL);
3461 ok(SUCCEEDED(hr), "Failed to create depth/stencil texture, hr %#x.\n", hr);
3462 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
3463 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
3464 IDirect3DTexture9_Release(texture);
3465 hr = IDirect3DDevice9_SetDepthStencilSurface(device, surface);
3466 ok(SUCCEEDED(hr), "Failed to set depth/stencil surface, hr %#x.\n", hr);
3467 IDirect3DSurface9_Release(surface);
3469 for (i = 0; i < caps.NumSimultaneousRTs; ++i)
3471 hr = IDirect3DDevice9_CreateTexture(device, 128, 128, 1, D3DUSAGE_RENDERTARGET,
3472 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);
3473 ok(SUCCEEDED(hr), "Failed to create render target texture %u, hr %#x.\n", i, hr);
3474 hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
3475 ok(SUCCEEDED(hr), "Failed to get surface %u, hr %#x.\n", i, hr);
3476 IDirect3DTexture9_Release(texture);
3477 hr = IDirect3DDevice9_SetRenderTarget(device, i, surface);
3478 ok(SUCCEEDED(hr), "Failed to set render target surface %u, hr %#x.\n", i, hr);
3479 IDirect3DSurface9_Release(surface);
3482 hr = reset_device(device, device_window, TRUE);
3483 ok(SUCCEEDED(hr), "Failed to reset device.\n");
3485 hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &rt);
3486 ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
3487 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &surface);
3488 ok(SUCCEEDED(hr), "Failed to get render target surface, hr %#x.\n", hr);
3489 ok(surface == rt, "Got unexpected surface %p for render target.\n", surface);
3490 IDirect3DSurface9_Release(surface);
3491 IDirect3DSurface9_Release(rt);
3493 for (i = 1; i < caps.NumSimultaneousRTs; ++i)
3495 hr = IDirect3DDevice9_GetRenderTarget(device, i, &surface);
3496 ok(hr == D3DERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
3499 ref = IDirect3DDevice9_Release(device);
3500 ok(ref == 0, "The device was not properly freed: refcount %u.\n", ref);
3502 done:
3503 IDirect3D9_Release(d3d9);
3504 DestroyWindow(window);
3507 START_TEST(device)
3509 HMODULE d3d9_handle = LoadLibraryA( "d3d9.dll" );
3510 WNDCLASS wc = {0};
3512 wc.lpfnWndProc = DefWindowProc;
3513 wc.lpszClassName = "d3d9_test_wc";
3514 RegisterClass(&wc);
3516 if (!d3d9_handle)
3518 skip("Could not load d3d9.dll\n");
3519 goto out;
3522 pDirect3DCreate9 = (void *)GetProcAddress( d3d9_handle, "Direct3DCreate9" );
3523 ok(pDirect3DCreate9 != NULL, "Failed to get address of Direct3DCreate9\n");
3524 if (pDirect3DCreate9)
3526 IDirect3D9 *d3d9 = pDirect3DCreate9( D3D_SDK_VERSION );
3527 if(!d3d9)
3529 skip("could not create D3D9 object\n");
3530 goto out;
3532 IDirect3D9_Release(d3d9);
3534 screen_width = GetSystemMetrics(SM_CXSCREEN);
3535 screen_height = GetSystemMetrics(SM_CYSCREEN);
3537 test_fpu_setup();
3538 test_multi_device();
3539 test_display_formats();
3540 test_display_modes();
3541 test_swapchain();
3542 test_refcount();
3543 test_mipmap_levels();
3544 test_checkdevicemultisampletype();
3545 test_cursor();
3546 test_cursor_pos();
3547 test_reset_fullscreen();
3548 test_reset();
3549 test_scene();
3550 test_limits();
3551 test_depthstenciltest();
3552 test_get_rt();
3553 test_draw_indexed();
3554 test_null_stream();
3555 test_lights();
3556 test_set_stream_source();
3557 test_scissor_size();
3558 test_wndproc();
3559 test_wndproc_windowed();
3560 test_window_style();
3561 test_mode_change();
3562 test_device_window_reset();
3563 test_reset_resources();
3566 out:
3567 UnregisterClassA("d3d9_test_wc", GetModuleHandleA(NULL));