Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / d3d9 / tests / surface.c
blob396e0c43d795fad0e084aa5b85c36366e0e7dfab
1 /*
2 * Copyright 2006-2007 Henri Verbeet
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 #define COBJMACROS
19 #include <d3d9.h>
20 #include "wine/test.h"
22 static HWND create_window(void)
24 WNDCLASS wc = {0};
25 wc.lpfnWndProc = DefWindowProc;
26 wc.lpszClassName = "d3d9_test_wc";
27 RegisterClass(&wc);
29 return CreateWindow("d3d9_test_wc", "d3d9_test",
30 0, 0, 0, 0, 0, 0, 0, 0, 0);
33 static IDirect3DDevice9 *init_d3d9(HMODULE d3d9_handle)
35 IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
36 IDirect3D9 *d3d9_ptr = 0;
37 IDirect3DDevice9 *device_ptr = 0;
38 D3DPRESENT_PARAMETERS present_parameters;
39 HRESULT hr;
41 d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
42 ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
43 if (!d3d9_create) return NULL;
45 d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
46 if (!d3d9_ptr)
48 skip("could not create D3D9\n");
49 return NULL;
52 ZeroMemory(&present_parameters, sizeof(present_parameters));
53 present_parameters.Windowed = TRUE;
54 present_parameters.hDeviceWindow = create_window();
55 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
57 hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
58 NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
60 if(FAILED(hr))
62 skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr);
63 return NULL;
66 return device_ptr;
69 static void test_surface_get_container(IDirect3DDevice9 *device_ptr)
71 IDirect3DTexture9 *texture_ptr = 0;
72 IDirect3DSurface9 *surface_ptr = 0;
73 void *container_ptr;
74 HRESULT hr;
76 hr = IDirect3DDevice9_CreateTexture(device_ptr, 128, 128, 1, 0,
77 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture_ptr, 0);
78 ok(SUCCEEDED(hr) && texture_ptr != NULL, "CreateTexture returned: hr %#x, texture_ptr %p. "
79 "Expected hr %#x, texture_ptr != %p\n", hr, texture_ptr, D3D_OK, NULL);
80 if (!texture_ptr || FAILED(hr)) goto cleanup;
82 hr = IDirect3DTexture9_GetSurfaceLevel(texture_ptr, 0, &surface_ptr);
83 ok(SUCCEEDED(hr) && surface_ptr != NULL, "GetSurfaceLevel returned: hr %#x, surface_ptr %p. "
84 "Expected hr %#x, surface_ptr != %p\n", hr, surface_ptr, D3D_OK, NULL);
85 if (!surface_ptr || FAILED(hr)) goto cleanup;
87 /* These should work... */
88 container_ptr = (void *)0x1337c0d3;
89 hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IUnknown, &container_ptr);
90 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
91 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
92 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
94 container_ptr = (void *)0x1337c0d3;
95 hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IDirect3DResource9, &container_ptr);
96 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
97 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
98 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
100 container_ptr = (void *)0x1337c0d3;
101 hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IDirect3DBaseTexture9, &container_ptr);
102 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
103 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
104 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
106 container_ptr = (void *)0x1337c0d3;
107 hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IDirect3DTexture9, &container_ptr);
108 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
109 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
110 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
112 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container_ptr to NULL */
113 container_ptr = (void *)0x1337c0d3;
114 hr = IDirect3DSurface9_GetContainer(surface_ptr, &IID_IDirect3DSurface9, &container_ptr);
115 ok(hr == E_NOINTERFACE && container_ptr == NULL, "GetContainer returned: hr %#x, container_ptr %p. "
116 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, E_NOINTERFACE, NULL);
117 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
119 cleanup:
120 if (texture_ptr) IDirect3DTexture9_Release(texture_ptr);
121 if (surface_ptr) IDirect3DSurface9_Release(surface_ptr);
124 static void test_surface_alignment(IDirect3DDevice9 *device_ptr)
126 IDirect3DSurface9 *surface_ptr = 0;
127 HRESULT hr;
128 int i;
130 /* Test a sysmem surface as those aren't affected by the hardware's np2 restrictions */
131 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device_ptr, 5, 5, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &surface_ptr, 0);
132 ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %08x\n", hr);
134 if(surface_ptr)
136 D3DLOCKED_RECT lockedRect;
137 hr = IDirect3DSurface9_LockRect(surface_ptr, &lockedRect, NULL, 0);
138 ok(hr == D3D_OK, "IDirect3DSurface9_LockRect returned %08x\n", hr);
139 ok(!(lockedRect.Pitch & 3), "Surface pitch %d is not 32-bit aligned\n", lockedRect.Pitch);
140 /* Some applications also depend on the exact pitch, rather than just
141 * the alignment.
143 ok(lockedRect.Pitch == 12, "Got pitch %d, expected 12\n", lockedRect.Pitch);
144 hr = IDirect3DSurface9_UnlockRect(surface_ptr);
145 ok(SUCCEEDED(hr), "IDirect3DSurface9_UnlockRect returned %#x.\n", hr);
146 IDirect3DSurface9_Release(surface_ptr);
149 for (i = 0; i < 5; i++)
151 IDirect3DTexture9 *pTexture;
152 int j, pitch;
154 hr = IDirect3DDevice9_CreateTexture(device_ptr, 64, 64, 0, 0, MAKEFOURCC('D', 'X', 'T', '1'+i),
155 D3DPOOL_MANAGED, &pTexture, NULL);
156 ok(SUCCEEDED(hr) || hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_CreateTexture: %08x\n", hr);
157 if (FAILED(hr)) {
158 skip("DXT%d surfaces are not supported\n", i + 1);
159 continue;
162 for (j = IDirect3DBaseTexture9_GetLevelCount(pTexture) - 1; j >= 0; j--)
164 D3DLOCKED_RECT rc;
165 D3DSURFACE_DESC descr;
167 IDirect3DTexture9_GetLevelDesc(pTexture, j, &descr);
168 hr = IDirect3DTexture9_LockRect(pTexture, j, &rc, NULL, 0);
169 ok(SUCCEEDED(hr), "IDirect3DTexture9_LockRect: %08x\n", hr);
170 hr = IDirect3DTexture9_UnlockRect(pTexture, j);
171 ok(SUCCEEDED(hr), "IDirect3DTexture9_UnLockRect: %08x\n", hr);
172 hr = IDirect3DTexture9_UnlockRect(pTexture, j);
173 todo_wine ok(SUCCEEDED(hr), "Double IDirect3DTexture9_UnLockRect failed with %08x\n", hr);
175 pitch = ((descr.Width + 3) >> 2) << 3;
176 if (i > 0) pitch <<= 1;
177 ok(rc.Pitch == pitch, "Wrong pitch for DXT%d lvl[%d (%dx%d)]: expected %d got %d\n",
178 i + 1, j, descr.Width, descr.Height, pitch, rc.Pitch);
180 IUnknown_Release( pTexture );
184 /* Since the DXT formats are based on 4x4 blocks, locking works slightly
185 * different than with regular formats. This patch verifies we return the
186 * correct memory offsets */
187 static void test_lockrect_offset(IDirect3DDevice9 *device)
189 IDirect3DSurface9 *surface = 0;
190 const RECT rect = {60, 60, 68, 68};
191 D3DLOCKED_RECT locked_rect;
192 unsigned int expected_offset;
193 unsigned int offset;
194 unsigned int i;
195 BYTE *base;
196 HRESULT hr;
198 const struct {
199 D3DFORMAT fmt;
200 const char *name;
201 unsigned int block_width;
202 unsigned int block_height;
203 unsigned int block_size;
204 } dxt_formats[] = {
205 {D3DFMT_DXT1, "D3DFMT_DXT1", 4, 4, 8},
206 {D3DFMT_DXT2, "D3DFMT_DXT2", 4, 4, 16},
207 {D3DFMT_DXT3, "D3DFMT_DXT3", 4, 4, 16},
208 {D3DFMT_DXT4, "D3DFMT_DXT4", 4, 4, 16},
209 {D3DFMT_DXT5, "D3DFMT_DXT5", 4, 4, 16},
212 for (i = 0; i < (sizeof(dxt_formats) / sizeof(*dxt_formats)); ++i) {
213 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 128, 128, dxt_formats[i].fmt, D3DPOOL_SCRATCH, &surface, 0);
214 ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed (%08x)\n", hr);
216 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
217 ok(SUCCEEDED(hr), "LockRect failed (%08x)\n", hr);
219 base = locked_rect.pBits;
221 hr = IDirect3DSurface9_UnlockRect(surface);
222 ok(SUCCEEDED(hr), "UnlockRect failed (%08x)\n", hr);
223 hr = IDirect3DSurface9_UnlockRect(surface);
224 ok(hr == D3DERR_INVALIDCALL, "Double UnlockRect returned %08x, expected D3DERR_INVALIDCALL\n", hr);
226 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &rect, 0);
227 ok(SUCCEEDED(hr), "LockRect failed (%08x)\n", hr);
229 offset = (BYTE *)locked_rect.pBits - base;
230 expected_offset = (rect.top / dxt_formats[i].block_height) * locked_rect.Pitch
231 + (rect.left / dxt_formats[i].block_width) * dxt_formats[i].block_size;
232 ok(offset == expected_offset, "Got offset %u, expected offset %u for format %s\n", offset, expected_offset, dxt_formats[i].name);
234 hr = IDirect3DSurface9_UnlockRect(surface);
235 ok(SUCCEEDED(hr), "UnlockRect failed (%08x)\n", hr);
237 IDirect3DSurface9_Release(surface);
241 static void test_lockrect_invalid(IDirect3DDevice9 *device)
243 IDirect3DSurface9 *surface = 0;
244 D3DLOCKED_RECT locked_rect;
245 unsigned int i;
246 BYTE *base;
247 HRESULT hr;
249 const RECT test_rect_2 = { 0, 0, 8, 8 };
250 const RECT test_data[] = {
251 {60, 60, 68, 68}, /* Valid */
252 {60, 60, 60, 68}, /* 0 height */
253 {60, 60, 68, 60}, /* 0 width */
254 {68, 60, 60, 68}, /* left > right */
255 {60, 68, 68, 60}, /* top > bottom */
256 {-8, 60, 0, 68}, /* left < surface */
257 {60, -8, 68, 0}, /* top < surface */
258 {-16, 60, -8, 68}, /* right < surface */
259 {60, -16, 68, -8}, /* bottom < surface */
260 {60, 60, 136, 68}, /* right > surface */
261 {60, 60, 68, 136}, /* bottom > surface */
262 {136, 60, 144, 68}, /* left > surface */
263 {60, 136, 68, 144}, /* top > surface */
266 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 128, 128, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, 0);
267 ok(SUCCEEDED(hr), "CreateOffscreenPlainSurface failed (0x%08x)\n", hr);
269 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
270 ok(SUCCEEDED(hr), "LockRect failed (0x%08x)\n", hr);
272 base = locked_rect.pBits;
274 hr = IDirect3DSurface9_UnlockRect(surface);
275 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
277 for (i = 0; i < (sizeof(test_data) / sizeof(*test_data)); ++i)
279 unsigned int offset, expected_offset;
280 const RECT *rect = &test_data[i];
282 locked_rect.pBits = (BYTE *)0xdeadbeef;
283 locked_rect.Pitch = 0xdeadbeef;
285 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, rect, 0);
286 ok(SUCCEEDED(hr), "LockRect failed (0x%08x) for rect [%d, %d]->[%d, %d]\n",
287 hr, rect->left, rect->top, rect->right, rect->bottom);
289 offset = (BYTE *)locked_rect.pBits - base;
290 expected_offset = rect->top * locked_rect.Pitch + rect->left * 4;
291 ok(offset == expected_offset, "Got offset %u, expected offset %u for rect [%d, %d]->[%d, %d]\n",
292 offset, expected_offset, rect->left, rect->top, rect->right, rect->bottom);
294 hr = IDirect3DSurface9_UnlockRect(surface);
295 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
298 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
299 ok(SUCCEEDED(hr), "LockRect failed (0x%08x) for rect NULL\n", hr);
300 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, 0);
301 ok(hr == D3DERR_INVALIDCALL, "Double LockRect for rect NULL returned 0x%08x\n", hr);
302 hr = IDirect3DSurface9_UnlockRect(surface);
303 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
305 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &test_data[0], 0);
306 ok(hr == D3D_OK, "LockRect failed (0x%08x) for rect [%d, %d]->[%d, %d]"
307 ", expected D3D_OK (0x%08x)\n", hr, test_data[0].left, test_data[0].top,
308 test_data[0].right, test_data[0].bottom, D3D_OK);
309 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &test_data[0], 0);
310 ok(hr == D3DERR_INVALIDCALL, "Double LockRect failed (0x%08x) for rect [%d, %d]->[%d, %d]"
311 ", expected D3DERR_INVALIDCALL (0x%08x)\n", hr, test_data[0].left, test_data[0].top,
312 test_data[0].right, test_data[0].bottom, D3DERR_INVALIDCALL);
313 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, &test_rect_2, 0);
314 ok(hr == D3DERR_INVALIDCALL, "Double LockRect failed (0x%08x) for rect [%d, %d]->[%d, %d]"
315 ", expected D3DERR_INVALIDCALL (0x%08x)\n", hr, test_rect_2.left, test_rect_2.top,
316 test_rect_2.right, test_rect_2.bottom, D3DERR_INVALIDCALL);
317 hr = IDirect3DSurface9_UnlockRect(surface);
318 ok(SUCCEEDED(hr), "UnlockRect failed (0x%08x)\n", hr);
320 IDirect3DSurface9_Release(surface);
323 static ULONG getref(IUnknown *iface)
325 IUnknown_AddRef(iface);
326 return IUnknown_Release(iface);
329 static void test_private_data(IDirect3DDevice9 *device)
331 HRESULT hr;
332 IDirect3DSurface9 *surface;
333 ULONG ref, ref2;
334 IUnknown *ptr;
335 DWORD size = sizeof(IUnknown *);
337 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, 0);
338 ok(SUCCEEDED(hr), "CreateImageSurface failed (0x%08x)\n", hr);
339 if(!surface)
341 return;
344 /* This fails */
345 hr = IDirect3DSurface9_SetPrivateData(surface, &IID_IDirect3DSurface9 /* Abuse this tag */, device, 0, D3DSPD_IUNKNOWN);
346 ok(hr == D3DERR_INVALIDCALL, "IDirect3DSurface9_SetPrivateData failed with %08x\n", hr);
347 hr = IDirect3DSurface9_SetPrivateData(surface, &IID_IDirect3DSurface9 /* Abuse this tag */, device, 5, D3DSPD_IUNKNOWN);
348 ok(hr == D3DERR_INVALIDCALL, "IDirect3DSurface9_SetPrivateData failed with %08x\n", hr);
349 hr = IDirect3DSurface9_SetPrivateData(surface, &IID_IDirect3DSurface9 /* Abuse this tag */, device, sizeof(IUnknown *) * 2, D3DSPD_IUNKNOWN);
350 ok(hr == D3DERR_INVALIDCALL, "IDirect3DSurface9_SetPrivateData failed with %08x\n", hr);
352 ref = getref((IUnknown *) device);
353 hr = IDirect3DSurface9_SetPrivateData(surface, &IID_IDirect3DSurface9 /* Abuse this tag */, device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
354 ok(hr == D3D_OK, "IDirect3DSurface9_SetPrivateData failed with %08x\n", hr);
355 ref2 = getref((IUnknown *) device);
356 ok(ref2 == ref + 1, "Object reference is %d, expected %d\n", ref2, ref + 1);
357 hr = IDirect3DSurface9_FreePrivateData(surface, &IID_IDirect3DSurface9);
358 ok(hr == D3D_OK, "IDirect3DSurface9_FreePrivateData returned %08x\n", hr);
359 ref2 = getref((IUnknown *) device);
360 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
362 hr = IDirect3DSurface9_SetPrivateData(surface, &IID_IDirect3DSurface9, device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
363 ok(hr == D3D_OK, "IDirect3DSurface9_SetPrivateData failed with %08x\n", hr);
364 hr = IDirect3DSurface9_SetPrivateData(surface, &IID_IDirect3DSurface9, surface, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
365 ok(hr == D3D_OK, "IDirect3DSurface9_SetPrivateData failed with %08x\n", hr);
366 ref2 = getref((IUnknown *) device);
367 ok(ref2 == ref, "Object reference is %d, expected %d\n", ref2, ref);
369 hr = IDirect3DSurface9_SetPrivateData(surface, &IID_IDirect3DSurface9, device, sizeof(IUnknown *), D3DSPD_IUNKNOWN);
370 ok(hr == D3D_OK, "IDirect3DSurface9_SetPrivateData failed with %08x\n", hr);
371 hr = IDirect3DSurface9_GetPrivateData(surface, &IID_IDirect3DSurface9, &ptr, &size);
372 ok(hr == D3D_OK, "IDirect3DSurface9_GetPrivateData failed with %08x\n", hr);
373 ref2 = getref((IUnknown *) device);
374 /* Object is addrefed */
375 ok(ptr == (IUnknown *) device, "Returned interface pointer is %p, expected %p\n", ptr, device);
376 ok(ref2 == ref + 2, "Object reference is %d, expected %d. ptr at %p, orig at %p\n", ref2, ref + 2, ptr, device);
377 IUnknown_Release(ptr);
379 IDirect3DSurface9_Release(surface);
381 /* Destroying the surface frees the held reference */
382 ref2 = getref((IUnknown *) device);
383 /* -1 because the surface was released and held a reference before */
384 ok(ref2 == (ref - 1), "Object reference is %d, expected %d\n", ref2, (ref - 1));
387 static void test_getdc(IDirect3DDevice9 *device)
389 IDirect3DSurface9 *surface;
390 IDirect3DTexture9 *texture;
391 HRESULT hr;
392 unsigned int i;
393 HDC dc;
395 struct
397 const char *name;
398 D3DFORMAT fmt;
399 BOOL getdc_supported;
400 } testdata[] = {
401 { "D3DFMT_A8R8G8B8", D3DFMT_A8R8G8B8, TRUE },
402 { "D3DFMT_X8R8G8B8", D3DFMT_X8R8G8B8, TRUE },
403 { "D3DFMT_R5G6B5", D3DFMT_R5G6B5, TRUE },
404 { "D3DFMT_X1R5G5B5", D3DFMT_X1R5G5B5, TRUE },
405 { "D3DFMT_A1R5G5B5", D3DFMT_A1R5G5B5, TRUE },
406 { "D3DFMT_R8G8B8", D3DFMT_R8G8B8, TRUE },
407 { "D3DFMT_A2R10G10B10", D3DFMT_A2R10G10B10, FALSE }, /* Untested, card on windows didn't support it */
408 { "D3DFMT_V8U8", D3DFMT_V8U8, FALSE },
409 { "D3DFMT_Q8W8V8U8", D3DFMT_Q8W8V8U8, FALSE },
410 { "D3DFMT_A8B8G8R8", D3DFMT_A8B8G8R8, FALSE },
411 { "D3DFMT_X8B8G8R8", D3DFMT_A8B8G8R8, FALSE },
412 { "D3DFMT_R3G3B2", D3DFMT_R3G3B2, FALSE },
413 { "D3DFMT_P8", D3DFMT_P8, FALSE },
414 { "D3DFMT_L8", D3DFMT_L8, FALSE },
415 { "D3DFMT_A8L8", D3DFMT_A8L8, FALSE },
416 { "D3DFMT_DXT1", D3DFMT_DXT1, FALSE },
417 { "D3DFMT_DXT2", D3DFMT_DXT2, FALSE },
418 { "D3DFMT_DXT3", D3DFMT_DXT3, FALSE },
419 { "D3DFMT_DXT4", D3DFMT_DXT4, FALSE },
420 { "D3DFMT_DXT5", D3DFMT_DXT5, FALSE },
423 for(i = 0; i < (sizeof(testdata) / sizeof(testdata[0])); i++)
425 texture = NULL;
426 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 64, 64, testdata[i].fmt, D3DPOOL_SYSTEMMEM, &surface, NULL);
427 if(FAILED(hr))
429 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, testdata[i].fmt, D3DPOOL_MANAGED, &texture, NULL);
430 if(FAILED(hr))
432 skip("IDirect3DDevice9_CreateOffscreenPlainSurface failed, hr = 0x%08x, fmt %s\n", hr, testdata[i].name);
433 continue;
435 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
438 dc = (void *) 0x1234;
439 hr = IDirect3DSurface9_GetDC(surface, &dc);
441 if(testdata[i].getdc_supported)
443 ok(SUCCEEDED(hr), "GetDC on format %s failed(hr=0x%08x), but was expected to work\n",
444 testdata[i].name, hr);
446 else
448 ok(FAILED(hr), "GetDC on format %s worked(hr=0x%08x), but was expected to fail\n",
449 testdata[i].name, hr);
452 if(SUCCEEDED(hr))
454 hr = IDirect3DSurface9_ReleaseDC(surface, dc);
455 ok(hr == D3D_OK, "IDirect3DSurface9_ReleaseDC failed, hr = 0x%08x\n", hr);
457 else
459 ok(dc == (void *) 0x1234, "After failed getDC dc is %p\n", dc);
462 IDirect3DSurface9_Release(surface);
463 if(texture) IDirect3DTexture9_Release(texture);
467 START_TEST(surface)
469 HMODULE d3d9_handle;
470 IDirect3DDevice9 *device_ptr;
471 ULONG refcount;
473 d3d9_handle = LoadLibraryA("d3d9.dll");
474 if (!d3d9_handle)
476 skip("Could not load d3d9.dll\n");
477 return;
480 device_ptr = init_d3d9(d3d9_handle);
481 if (!device_ptr) return;
483 test_surface_get_container(device_ptr);
484 test_surface_alignment(device_ptr);
485 test_lockrect_offset(device_ptr);
486 test_lockrect_invalid(device_ptr);
487 test_private_data(device_ptr);
488 test_getdc(device_ptr);
490 refcount = IDirect3DDevice9_Release(device_ptr);
491 ok(!refcount, "Device has %u references left\n", refcount);