d3drm/tests: Simplify a conditional expression.
[wine.git] / dlls / d3drm / tests / d3drm.c
blob1ab81e41afd289b02fdf359782897653181a1767
1 /*
2 * Copyright 2010, 2012 Christian Costa
3 * Copyright 2012 André Hentschel
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
5 * Copyright 2014-2015 Aaryaman Vasishta
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <limits.h>
24 #define COBJMACROS
25 #include <d3d.h>
26 #include <initguid.h>
27 #include <d3drm.h>
28 #include <d3drmwin.h>
30 #include "wine/test.h"
32 #define CHECK_REFCOUNT(obj,rc) \
33 { \
34 int rc_new = rc; \
35 int count = get_refcount( (IUnknown *)obj ); \
36 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
39 static ULONG get_refcount(IUnknown *object)
41 IUnknown_AddRef( object );
42 return IUnknown_Release( object );
45 static BOOL compare_float(float f, float g, unsigned int ulps)
47 int x = *(int *)&f;
48 int y = *(int *)&g;
50 if (x < 0)
51 x = INT_MIN - x;
52 if (y < 0)
53 y = INT_MIN - y;
55 if (abs(x - y) > ulps)
56 return FALSE;
58 return TRUE;
61 #define check_vector(a, b, c, d, e) check_vector_(__LINE__, a, b, c, d, e)
62 static void check_vector_(unsigned int line, const D3DVECTOR *v, float x, float y, float z, unsigned int ulps)
64 BOOL ret = compare_float(U1(v)->x, x, ulps)
65 && compare_float(U2(v)->y, y, ulps)
66 && compare_float(U3(v)->z, z, ulps);
68 ok_(__FILE__, line)(ret, "Got unexpected vector {%.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e}.\n",
69 U1(v)->x, U2(v)->y, U3(v)->z, x, y, z);
72 #define vector_eq(a, b) vector_eq_(__LINE__, a, b)
73 static void vector_eq_(unsigned int line, const D3DVECTOR *left, const D3DVECTOR *right)
75 check_vector_(line, left, U1(right)->x, U2(right)->y, U3(right)->z, 0);
78 static D3DRMMATRIX4D identity = {
79 { 1.0f, 0.0f, 0.0f, 0.0f },
80 { 0.0f, 1.0f, 0.0f, 0.0f },
81 { 0.0f, 0.0f, 1.0f, 0.0f },
82 { 0.0f, 0.0f, 0.0f, 1.0f }
85 static HWND create_window(void)
87 RECT r = {0, 0, 640, 480};
89 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
91 return CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
92 CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
95 #define test_class_name(a, b) test_class_name_(__LINE__, a, b)
96 static void test_class_name_(unsigned int line, IDirect3DRMObject *object, const char *name)
98 char cname[64] = {0};
99 DWORD size, size2;
100 HRESULT hr;
102 hr = IDirect3DRMObject_GetClassName(object, NULL, cname);
103 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
104 hr = IDirect3DRMViewport_GetClassName(object, NULL, NULL);
105 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
107 size = 0;
108 hr = IDirect3DRMObject_GetClassName(object, &size, NULL);
109 ok_(__FILE__, line)(hr == D3DRM_OK, "Failed to get classname size, hr %#x.\n", hr);
110 ok_(__FILE__, line)(size == strlen(name) + 1, "wrong size: %u\n", size);
112 size = size2 = !!*name;
113 hr = IDirect3DRMObject_GetClassName(object, &size, cname);
114 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
115 ok_(__FILE__, line)(size == size2, "Got size %u.\n", size);
117 size = sizeof(cname);
118 hr = IDirect3DRMObject_GetClassName(object, &size, cname);
119 ok_(__FILE__, line)(hr == D3DRM_OK, "Failed to get classname, hr %#x.\n", hr);
120 ok_(__FILE__, line)(size == strlen(name) + 1, "wrong size: %u\n", size);
121 ok_(__FILE__, line)(!strcmp(cname, name), "Expected cname to be \"%s\", but got \"%s\".\n", name, cname);
123 size = strlen(name) + 1;
124 hr = IDirect3DRMObject_GetClassName(object, &size, cname);
125 ok_(__FILE__, line)(hr == D3DRM_OK, "Failed to get classname, hr %#x.\n", hr);
126 ok_(__FILE__, line)(size == strlen(name) + 1, "wrong size: %u\n", size);
127 ok_(__FILE__, line)(!strcmp(cname, name), "Expected cname to be \"%s\", but got \"%s\".\n", name, cname);
129 size = strlen(name);
130 strcpy(cname, "XXX");
131 hr = IDirect3DRMObject_GetClassName(object, &size, cname);
132 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
133 ok_(__FILE__, line)(size == strlen(name), "Wrong classname size: %u.\n", size);
134 ok_(__FILE__, line)(!strcmp(cname, "XXX"), "Expected unchanged buffer, but got \"%s\".\n", cname);
137 #define test_object_name(a) test_object_name_(__LINE__, a)
138 static void test_object_name_(unsigned int line, IDirect3DRMObject *object)
140 char name[64] = {0};
141 HRESULT hr;
142 DWORD size;
144 hr = IDirect3DRMObject_GetName(object, NULL, NULL);
145 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
147 name[0] = 0x1f;
148 hr = IDirect3DRMObject_GetName(object, NULL, name);
149 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
150 ok_(__FILE__, line)(name[0] == 0x1f, "Unexpected buffer contents, %#x.\n", name[0]);
152 /* Name is not set yet. */
153 size = 100;
154 hr = IDirect3DRMObject_GetName(object, &size, NULL);
155 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get name size, hr %#x.\n", hr);
156 ok_(__FILE__, line)(size == 0, "Unexpected size %u.\n", size);
158 size = sizeof(name);
159 name[0] = 0x1f;
160 hr = IDirect3DRMObject_GetName(object, &size, name);
161 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get name size, hr %#x.\n", hr);
162 ok_(__FILE__, line)(size == 0, "Unexpected size %u.\n", size);
163 ok_(__FILE__, line)(name[0] == 0, "Unexpected name \"%s\".\n", name);
165 size = 0;
166 name[0] = 0x1f;
167 hr = IDirect3DRMObject_GetName(object, &size, name);
168 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get name size, hr %#x.\n", hr);
169 ok_(__FILE__, line)(size == 0, "Unexpected size %u.\n", size);
170 ok_(__FILE__, line)(name[0] == 0x1f, "Unexpected name \"%s\".\n", name);
172 hr = IDirect3DRMObject_SetName(object, NULL);
173 ok_(__FILE__, line)(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
175 hr = IDirect3DRMObject_SetName(object, "name");
176 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to set a name, hr %#x.\n", hr);
178 size = 0;
179 hr = IDirect3DRMObject_GetName(object, &size, NULL);
180 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get name size, hr %#x.\n", hr);
181 ok_(__FILE__, line)(size == strlen("name") + 1, "Unexpected size %u.\n", size);
183 size = strlen("name") + 1;
184 hr = IDirect3DRMObject_GetName(object, &size, name);
185 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get name size, hr %#x.\n", hr);
186 ok_(__FILE__, line)(size == strlen("name") + 1, "Unexpected size %u.\n", size);
187 ok_(__FILE__, line)(!strcmp(name, "name"), "Unexpected name \"%s\".\n", name);
189 size = 2;
190 name[0] = 0x1f;
191 hr = IDirect3DRMObject_GetName(object, &size, name);
192 ok_(__FILE__, line)(hr == E_INVALIDARG, "Failed to get object name, hr %#x.\n", hr);
193 ok_(__FILE__, line)(size == 2, "Unexpected size %u.\n", size);
194 ok_(__FILE__, line)(name[0] == 0x1f, "Got unexpected name \"%s\".\n", name);
196 hr = IDirect3DRMObject_SetName(object, NULL);
197 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to set object name, hr %#x.\n", hr);
199 size = 1;
200 hr = IDirect3DRMObject_GetName(object, &size, NULL);
201 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get name size, hr %#x.\n", hr);
202 ok_(__FILE__, line)(size == 0, "Unexpected size %u.\n", size);
204 size = 1;
205 name[0] = 0x1f;
206 hr = IDirect3DRMObject_GetName(object, &size, name);
207 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get name size, hr %#x.\n", hr);
208 ok_(__FILE__, line)(size == 0, "Unexpected size %u.\n", size);
209 ok_(__FILE__, line)(name[0] == 0, "Got unexpected name \"%s\".\n", name);
212 static char data_bad_version[] =
213 "xof 0302txt 0064\n"
214 "Header Object\n"
215 "{\n"
216 "1; 2; 3;\n"
217 "}\n";
219 static char data_no_mesh[] =
220 "xof 0302txt 0064\n"
221 "Header Object\n"
222 "{\n"
223 "1; 0; 1;\n"
224 "}\n";
226 static char data_ok[] =
227 "xof 0302txt 0064\n"
228 "Header Object\n"
229 "{\n"
230 "1; 0; 1;\n"
231 "}\n"
232 "Mesh Object\n"
233 "{\n"
234 "4;\n"
235 "1.0; 0.0; 0.0;,\n"
236 "0.0; 1.0; 0.0;,\n"
237 "0.0; 0.0; 1.0;,\n"
238 "1.0; 1.0; 1.0;;\n"
239 "3;\n"
240 "3; 0, 1, 2;,\n"
241 "3; 1, 2, 3;,\n"
242 "3; 3, 1, 2;;\n"
243 "}\n";
245 static char data_full[] =
246 "xof 0302txt 0064\n"
247 "Header { 1; 0; 1; }\n"
248 "Mesh {\n"
249 " 3;\n"
250 " 0.1; 0.2; 0.3;,\n"
251 " 0.4; 0.5; 0.6;,\n"
252 " 0.7; 0.8; 0.9;;\n"
253 " 1;\n"
254 " 3; 0, 1, 2;;\n"
255 " MeshMaterialList {\n"
256 " 1; 1; 0;\n"
257 " Material {\n"
258 " 0.0; 1.0; 0.0; 1.0;;\n"
259 " 30.0;\n"
260 " 1.0; 0.0; 0.0;;\n"
261 " 0.5; 0.5; 0.5;;\n"
262 " TextureFileName {\n"
263 " \"Texture.bmp\";\n"
264 " }\n"
265 " }\n"
266 " }\n"
267 " MeshNormals {\n"
268 " 3;\n"
269 " 1.1; 1.2; 1.3;,\n"
270 " 1.4; 1.5; 1.6;,\n"
271 " 1.7; 1.8; 1.9;;\n"
272 " 1;"
273 " 3; 0, 1, 2;;\n"
274 " }\n"
275 " MeshTextureCoords {\n"
276 " 3;\n"
277 " 0.13; 0.17;,\n"
278 " 0.23; 0.27;,\n"
279 " 0.33; 0.37;;\n"
280 " }\n"
281 "}\n";
283 static char data_d3drm_load[] =
284 "xof 0302txt 0064\n"
285 "Header Object\n"
286 "{\n"
287 "1; 0; 1;\n"
288 "}\n"
289 "Mesh Object1\n"
290 "{\n"
291 " 1;\n"
292 " 0.1; 0.2; 0.3;,\n"
293 " 1;\n"
294 " 3; 0, 1, 2;;\n"
295 "}\n"
296 "Mesh Object2\n"
297 "{\n"
298 " 1;\n"
299 " 0.1; 0.2; 0.3;,\n"
300 " 1;\n"
301 " 3; 0, 1, 2;;\n"
302 "}\n"
303 "Frame Scene\n"
304 "{\n"
305 " {Object1}\n"
306 " {Object2}\n"
307 "}\n"
308 "Material\n"
309 "{\n"
310 " 0.1, 0.2, 0.3, 0.4;;\n"
311 " 0.5;\n"
312 " 0.6, 0.7, 0.8;;\n"
313 " 0.9, 1.0, 1.1;;\n"
314 "}\n";
316 static char data_frame_mesh_materials[] =
317 "xof 0302txt 0064\n"
318 "Header { 1; 0; 1; }\n"
319 "Frame {\n"
320 " Mesh mesh1 {\n"
321 " 5;\n"
322 " 0.1; 0.2; 0.3;,\n"
323 " 0.4; 0.5; 0.6;,\n"
324 " 0.7; 0.8; 0.9;,\n"
325 " 1.1; 1.2; 1.3;,\n"
326 " 1.4; 1.5; 1.6;;\n"
327 " 6;\n"
328 " 3; 0, 1, 2;,\n"
329 " 3; 0, 2, 1;,\n"
330 " 3; 1, 2, 3;,\n"
331 " 3; 1, 3, 2;,\n"
332 " 3; 2, 3, 4;,\n"
333 " 3; 2, 4, 3;;\n"
334 " MeshMaterialList {\n"
335 " 3; 6; 0, 1, 1, 2, 2, 2;\n"
336 " Material mat1 {\n"
337 " 1.0; 0.0; 0.0; 0.1;;\n"
338 " 10.0;\n"
339 " 0.11; 0.12; 0.13;;\n"
340 " 0.14; 0.15; 0.16;;\n"
341 " }\n"
342 " Material mat2 {\n"
343 " 0.0; 1.0; 0.0; 0.2;;\n"
344 " 20.0;\n"
345 " 0.21; 0.22; 0.23;;\n"
346 " 0.24; 0.25; 0.26;;\n"
347 " }\n"
348 " Material mat3 {\n"
349 " 0.0; 0.0; 1.0; 0.3;;\n"
350 " 30.0;\n"
351 " 0.31; 0.32; 0.33;;\n"
352 " 0.34; 0.35; 0.36;;\n"
353 " }\n"
354 " }\n"
355 " }\n"
356 "}\n";
358 static void test_MeshBuilder(void)
360 HRESULT hr;
361 IDirect3DRM *d3drm;
362 IDirect3DRMMeshBuilder *pMeshBuilder;
363 IDirect3DRMMeshBuilder3 *meshbuilder3;
364 IDirect3DRMMesh *mesh;
365 D3DRMLOADMEMORY info;
366 int val;
367 DWORD val1, val2, val3;
368 D3DVALUE valu, valv;
369 D3DVECTOR v[3];
370 D3DVECTOR n[4];
371 DWORD f[8];
372 char name[10];
373 DWORD size;
374 D3DCOLOR color;
375 IUnknown *unk;
377 hr = Direct3DRMCreate(&d3drm);
378 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
380 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
381 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
383 hr = IDirect3DRMMeshBuilder_QueryInterface(pMeshBuilder, &IID_IDirect3DRMObject, (void **)&unk);
384 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
385 ok(unk == (IUnknown *)pMeshBuilder, "Unexpected interface pointer.\n");
386 IUnknown_Release(unk);
388 hr = IDirect3DRMMeshBuilder_QueryInterface(pMeshBuilder, &IID_IDirect3DRMVisual, (void **)&unk);
389 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMVisual, %#x.\n", hr);
390 ok(unk == (IUnknown *)pMeshBuilder, "Unexpected interface pointer.\n");
391 IUnknown_Release(unk);
393 hr = IDirect3DRMMeshBuilder_QueryInterface(pMeshBuilder, &IID_IDirect3DRMMeshBuilder3, (void **)&meshbuilder3);
394 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMMeshBuilder3, %#x.\n", hr);
396 hr = IDirect3DRMMeshBuilder3_QueryInterface(meshbuilder3, &IID_IDirect3DRMObject, (void **)&unk);
397 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
398 ok(unk == (IUnknown *)pMeshBuilder, "Unexpected interface pointer.\n");
399 IUnknown_Release(unk);
401 hr = IDirect3DRMMeshBuilder3_QueryInterface(meshbuilder3, &IID_IDirect3DRMVisual, (void **)&unk);
402 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMVisual, %#x.\n", hr);
403 ok(unk == (IUnknown *)pMeshBuilder, "Unexpected interface pointer.\n");
404 IUnknown_Release(unk);
406 IDirect3DRMMeshBuilder3_Release(meshbuilder3);
408 test_class_name((IDirect3DRMObject *)pMeshBuilder, "Builder");
409 test_object_name((IDirect3DRMObject *)pMeshBuilder);
411 info.lpMemory = data_bad_version;
412 info.dSize = strlen(data_bad_version);
413 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
414 ok(hr == D3DRMERR_BADFILE, "Should have returned D3DRMERR_BADFILE (hr = %x)\n", hr);
416 info.lpMemory = data_no_mesh;
417 info.dSize = strlen(data_no_mesh);
418 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
419 ok(hr == D3DRMERR_NOTFOUND, "Should have returned D3DRMERR_NOTFOUND (hr = %x)\n", hr);
421 info.lpMemory = data_ok;
422 info.dSize = strlen(data_ok);
423 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
424 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
426 size = sizeof(name);
427 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
428 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
429 ok(!strcmp(name, "Object"), "Retrieved name '%s' instead of 'Object'\n", name);
430 size = strlen("Object"); /* No space for null character */
431 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
432 ok(hr == E_INVALIDARG, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
433 hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, NULL);
434 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
435 size = sizeof(name);
436 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
437 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
438 ok(size == 0, "Size should be 0 instead of %u\n", size);
439 hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, "");
440 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
441 size = sizeof(name);
442 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
443 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
444 ok(!strcmp(name, ""), "Retrieved name '%s' instead of ''\n", name);
446 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
447 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
449 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
450 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
452 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, NULL, &val2, NULL, &val3, NULL);
453 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
454 ok(val1 == 4, "Wrong number of vertices %d (must be 4)\n", val1);
455 ok(val2 == 4, "Wrong number of normals %d (must be 4)\n", val2);
456 ok(val3 == 22, "Wrong number of face data bytes %d (must be 22)\n", val3);
458 /* Check that Load method generated default normals */
459 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, NULL, &val2, n, NULL, NULL);
460 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
461 check_vector(&n[0], 0.577350f, 0.577350f, 0.577350f, 32);
462 check_vector(&n[1], -0.229416f, 0.688247f, 0.688247f, 32);
463 check_vector(&n[2], -0.229416f, 0.688247f, 0.688247f, 32);
464 check_vector(&n[3], -0.577350f, 0.577350f, 0.577350f, 32);
466 /* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
467 valu = 1.23f;
468 valv = 3.21f;
469 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 0, &valu, &valv);
470 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
471 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
472 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
473 valu = 1.23f;
474 valv = 3.21f;
475 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 1, &valu, &valv);
476 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
477 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
478 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
479 valu = 1.23f;
480 valv = 3.21f;
481 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 2, &valu, &valv);
482 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
483 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
484 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
485 valu = 1.23f;
486 valv = 3.21f;
487 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 3, &valu, &valv);
488 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
489 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
490 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
491 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 4, &valu, &valv);
492 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
494 valu = 1.23f;
495 valv = 3.21f;
496 hr = IDirect3DRMMeshBuilder_SetTextureCoordinates(pMeshBuilder, 0, valu, valv);
497 ok(hr == D3DRM_OK, "Cannot set texture coordinates (hr = %x)\n", hr);
498 hr = IDirect3DRMMeshBuilder_SetTextureCoordinates(pMeshBuilder, 4, valu, valv);
499 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
501 valu = 0.0f;
502 valv = 0.0f;
503 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 0, &valu, &valv);
504 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
505 ok(valu == 1.23f, "Wrong coordinate %f (must be 1.23)\n", valu);
506 ok(valv == 3.21f, "Wrong coordinate %f (must be 3.21)\n", valv);
508 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
510 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
511 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
513 /* No group in mesh when mesh builder is not loaded */
514 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
515 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
516 if (hr == D3DRM_OK)
518 DWORD nb_groups;
520 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
521 ok(nb_groups == 0, "GetCroupCount returned %u\n", nb_groups);
523 IDirect3DRMMesh_Release(mesh);
526 info.lpMemory = data_full;
527 info.dSize = strlen(data_full);
528 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
529 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
531 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
532 ok(val == 3, "Wrong number of vertices %d (must be 3)\n", val);
534 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
535 ok(val == 1, "Wrong number of faces %d (must be 1)\n", val);
537 /* Check no buffer size and too small buffer size errors */
538 val1 = 1; val2 = 3; val3 = 8;
539 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
540 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
541 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, v, &val2, n, &val3, f);
542 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
543 val1 = 3; val2 = 1; val3 = 8;
544 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
545 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
546 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, NULL, n, &val3, f);
547 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
548 val1 = 3; val2 = 3; val3 = 1;
549 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
550 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
551 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, NULL, f);
552 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
554 val1 = 3; val2 = 3; val3 = 8;
555 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
556 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
557 ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
558 ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
559 ok(val3 == 8, "Wrong number of face data bytes %d (must be 8)\n", val3);
560 check_vector(&v[0], 0.1f, 0.2f, 0.3f, 32);
561 check_vector(&v[1], 0.4f, 0.5f, 0.6f, 32);
562 check_vector(&v[2], 0.7f, 0.8f, 0.9f, 32);
563 check_vector(&n[0], 1.1f, 1.2f, 1.3f, 32);
564 check_vector(&n[1], 1.4f, 1.5f, 1.6f, 32);
565 check_vector(&n[2], 1.7f, 1.8f, 1.9f, 32);
566 ok(f[0] == 3 , "Wrong component f[0] = %d (expected 3)\n", f[0]);
567 ok(f[1] == 0 , "Wrong component f[1] = %d (expected 0)\n", f[1]);
568 ok(f[2] == 0 , "Wrong component f[2] = %d (expected 0)\n", f[2]);
569 ok(f[3] == 1 , "Wrong component f[3] = %d (expected 1)\n", f[3]);
570 ok(f[4] == 1 , "Wrong component f[4] = %d (expected 1)\n", f[4]);
571 ok(f[5] == 2 , "Wrong component f[5] = %d (expected 2)\n", f[5]);
572 ok(f[6] == 2 , "Wrong component f[6] = %d (expected 2)\n", f[6]);
573 ok(f[7] == 0 , "Wrong component f[7] = %d (expected 0)\n", f[7]);
575 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
576 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
577 if (hr == D3DRM_OK)
579 DWORD nb_groups;
580 unsigned nb_vertices, nb_faces, nb_face_vertices;
581 DWORD data_size;
582 IDirect3DRMMaterial *material = (IDirect3DRMMaterial *)0xdeadbeef;
583 IDirect3DRMTexture *texture = (IDirect3DRMTexture *)0xdeadbeef;
584 D3DVALUE values[3];
586 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
587 ok(nb_groups == 1, "GetCroupCount returned %u\n", nb_groups);
588 hr = IDirect3DRMMesh_GetGroup(mesh, 1, &nb_vertices, &nb_faces, &nb_face_vertices, &data_size, NULL);
589 ok(hr == D3DRMERR_BADVALUE, "GetCroup returned hr = %x\n", hr);
590 hr = IDirect3DRMMesh_GetGroup(mesh, 0, &nb_vertices, &nb_faces, &nb_face_vertices, &data_size, NULL);
591 ok(hr == D3DRM_OK, "GetCroup failed returning hr = %x\n", hr);
592 ok(nb_vertices == 3, "Wrong number of vertices %u (must be 3)\n", nb_vertices);
593 ok(nb_faces == 1, "Wrong number of faces %u (must be 1)\n", nb_faces);
594 ok(nb_face_vertices == 3, "Wrong number of vertices per face %u (must be 3)\n", nb_face_vertices);
595 ok(data_size == 3, "Wrong number of face data bytes %u (must be 3)\n", data_size);
596 color = IDirect3DRMMesh_GetGroupColor(mesh, 0);
597 ok(color == 0xff00ff00, "Wrong color returned %#x instead of %#x\n", color, 0xff00ff00);
598 hr = IDirect3DRMMesh_GetGroupTexture(mesh, 0, &texture);
599 ok(hr == D3DRM_OK, "GetCroupTexture failed returning hr = %x\n", hr);
600 ok(texture == NULL, "No texture should be present\n");
601 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, 0, &material);
602 ok(hr == D3DRM_OK, "GetCroupMaterial failed returning hr = %x\n", hr);
603 ok(material != NULL, "No material present\n");
604 hr = IDirect3DRMMaterial_GetEmissive(material, &values[0], &values[1], &values[2]);
605 ok(hr == D3DRM_OK, "Failed to get emissive color, hr %#x.\n", hr);
606 ok(values[0] == 0.5f, "Got unexpected red component %.8e.\n", values[0]);
607 ok(values[1] == 0.5f, "Got unexpected green component %.8e.\n", values[1]);
608 ok(values[2] == 0.5f, "Got unexpected blue component %.8e.\n", values[2]);
609 hr = IDirect3DRMMaterial_GetSpecular(material, &values[0], &values[1], &values[2]);
610 ok(hr == D3DRM_OK, "Failed to get specular color, hr %#x.\n", hr);
611 ok(values[0] == 1.0f, "Got unexpected red component %.8e.\n", values[0]);
612 ok(values[1] == 0.0f, "Got unexpected green component %.8e.\n", values[1]);
613 ok(values[2] == 0.0f, "Got unexpected blue component %.8e.\n", values[2]);
614 values[0] = IDirect3DRMMaterial_GetPower(material);
615 ok(values[0] == 30.0f, "Got unexpected power value %.8e.\n", values[0]);
616 IDirect3DRMMaterial_Release(material);
618 IDirect3DRMMesh_Release(mesh);
621 hr = IDirect3DRMMeshBuilder_Scale(pMeshBuilder, 2, 3 ,4);
622 ok(hr == D3DRM_OK, "Scale failed returning hr = %x\n", hr);
624 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
625 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
626 ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
627 ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
629 check_vector(&v[0], 0.1f * 2, 0.2f * 3, 0.3f * 4, 32);
630 check_vector(&v[1], 0.4f * 2, 0.5f * 3, 0.6f * 4, 32);
631 check_vector(&v[2], 0.7f * 2, 0.8f * 3, 0.9f * 4, 32);
632 /* Normals are not affected by Scale */
633 check_vector(&n[0], 1.1f, 1.2f, 1.3f, 32);
634 check_vector(&n[1], 1.4f, 1.5f, 1.6f, 32);
635 check_vector(&n[2], 1.7f, 1.8f, 1.9f, 32);
637 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
639 IDirect3DRM_Release(d3drm);
642 static void test_MeshBuilder3(void)
644 HRESULT hr;
645 IDirect3DRM *d3drm;
646 IDirect3DRM3 *d3drm3;
647 IDirect3DRMMeshBuilder3 *pMeshBuilder3;
648 D3DRMLOADMEMORY info;
649 int val;
650 DWORD val1;
651 D3DVALUE valu, valv;
653 hr = Direct3DRMCreate(&d3drm);
654 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
656 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
658 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
659 IDirect3DRM_Release(d3drm);
660 return;
663 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &pMeshBuilder3);
664 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
666 test_class_name((IDirect3DRMObject *)pMeshBuilder3, "Builder");
667 test_object_name((IDirect3DRMObject *)pMeshBuilder3);
669 info.lpMemory = data_bad_version;
670 info.dSize = strlen(data_bad_version);
671 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
672 ok(hr == D3DRMERR_BADFILE, "Should have returned D3DRMERR_BADFILE (hr = %x)\n", hr);
674 info.lpMemory = data_no_mesh;
675 info.dSize = strlen(data_no_mesh);
676 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
677 ok(hr == D3DRMERR_NOTFOUND, "Should have returned D3DRMERR_NOTFOUND (hr = %x)\n", hr);
679 info.lpMemory = data_ok;
680 info.dSize = strlen(data_ok);
681 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
682 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
684 val = IDirect3DRMMeshBuilder3_GetVertexCount(pMeshBuilder3);
685 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
687 val = IDirect3DRMMeshBuilder3_GetFaceCount(pMeshBuilder3);
688 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
690 hr = IDirect3DRMMeshBuilder3_GetVertices(pMeshBuilder3, 0, &val1, NULL);
691 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
692 ok(val1 == 4, "Wrong number of vertices %d (must be 4)\n", val1);
694 /* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
695 valu = 1.23f;
696 valv = 3.21f;
697 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 0, &valu, &valv);
698 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
699 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
700 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
701 valu = 1.23f;
702 valv = 3.21f;
703 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 1, &valu, &valv);
704 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
705 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
706 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
707 valu = 1.23f;
708 valv = 3.21f;
709 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 2, &valu, &valv);
710 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
711 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
712 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
713 valu = 1.23f;
714 valv = 3.21f;
715 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 3, &valu, &valv);
716 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
717 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
718 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
719 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 4, &valu, &valv);
720 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
722 valu = 1.23f;
723 valv = 3.21f;
724 hr = IDirect3DRMMeshBuilder3_SetTextureCoordinates(pMeshBuilder3, 0, valu, valv);
725 ok(hr == D3DRM_OK, "Cannot set texture coordinates (hr = %x)\n", hr);
726 hr = IDirect3DRMMeshBuilder3_SetTextureCoordinates(pMeshBuilder3, 4, valu, valv);
727 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
729 valu = 0.0f;
730 valv = 0.0f;
731 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 0, &valu, &valv);
732 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
733 ok(valu == 1.23f, "Wrong coordinate %f (must be 1.23)\n", valu);
734 ok(valv == 3.21f, "Wrong coordinate %f (must be 3.21)\n", valv);
736 IDirect3DRMMeshBuilder3_Release(pMeshBuilder3);
737 IDirect3DRM3_Release(d3drm3);
738 IDirect3DRM_Release(d3drm);
741 static void test_Mesh(void)
743 HRESULT hr;
744 IDirect3DRM *d3drm;
745 IDirect3DRMMesh *mesh;
746 IUnknown *unk;
748 hr = Direct3DRMCreate(&d3drm);
749 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
751 hr = IDirect3DRM_CreateMesh(d3drm, &mesh);
752 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMesh interface (hr = %x)\n", hr);
754 test_class_name((IDirect3DRMObject *)mesh, "Mesh");
755 test_object_name((IDirect3DRMObject *)mesh);
757 hr = IDirect3DRMMesh_QueryInterface(mesh, &IID_IDirect3DRMObject, (void **)&unk);
758 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
759 IUnknown_Release(unk);
761 hr = IDirect3DRMMesh_QueryInterface(mesh, &IID_IDirect3DRMVisual, (void **)&unk);
762 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMVisual, %#x.\n", hr);
763 IUnknown_Release(unk);
765 IDirect3DRMMesh_Release(mesh);
767 IDirect3DRM_Release(d3drm);
770 static void test_Face(void)
772 HRESULT hr;
773 IDirect3DRM *d3drm;
774 IDirect3DRM2 *d3drm2;
775 IDirect3DRM3 *d3drm3;
776 IDirect3DRMMeshBuilder2 *MeshBuilder2;
777 IDirect3DRMMeshBuilder3 *MeshBuilder3;
778 IDirect3DRMFace *face1;
779 IDirect3DRMObject *obj;
780 IDirect3DRMFace2 *face2;
781 IDirect3DRMFaceArray *array1;
782 D3DRMLOADMEMORY info;
783 D3DVECTOR v1[4], n1[4], v2[4], n2[4];
784 D3DCOLOR color;
785 DWORD count;
786 int icount;
788 hr = Direct3DRMCreate(&d3drm);
789 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
791 hr = IDirect3DRM_CreateFace(d3drm, &face1);
792 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
793 if (FAILED(hr))
795 skip("Cannot get IDirect3DRMFace interface (hr = %x), skipping tests\n", hr);
796 IDirect3DRM_Release(d3drm);
797 return;
800 hr = IDirect3DRMFace_QueryInterface(face1, &IID_IDirect3DRMObject, (void **)&obj);
801 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
802 ok(obj == (IDirect3DRMObject *)face1, "Unexpected interface pointer.\n");
803 IDirect3DRMObject_Release(obj);
805 test_class_name((IDirect3DRMObject *)face1, "Face");
806 test_object_name((IDirect3DRMObject *)face1);
808 icount = IDirect3DRMFace_GetVertexCount(face1);
809 ok(!icount, "wrong VertexCount: %i\n", icount);
811 IDirect3DRMFace_Release(face1);
813 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM2, (void **)&d3drm2)))
815 win_skip("Cannot get IDirect3DRM2 interface (hr = %x), skipping tests\n", hr);
816 IDirect3DRM_Release(d3drm);
817 return;
820 hr = IDirect3DRM2_CreateMeshBuilder(d3drm2, &MeshBuilder2);
821 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder2 interface (hr = %x)\n", hr);
823 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
824 ok(!icount, "wrong FaceCount: %i\n", icount);
826 array1 = NULL;
827 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
828 todo_wine
829 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
831 hr = IDirect3DRMMeshBuilder2_CreateFace(MeshBuilder2, &face1);
832 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
834 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
835 todo_wine
836 ok(icount == 1, "wrong FaceCount: %i\n", icount);
838 array1 = NULL;
839 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
840 todo_wine
841 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
842 todo_wine
843 ok(array1 != NULL, "pArray = %p\n", array1);
844 if (array1)
846 IDirect3DRMFace *face;
847 count = IDirect3DRMFaceArray_GetSize(array1);
848 ok(count == 1, "count = %u\n", count);
849 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
850 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
851 IDirect3DRMFace_Release(face);
852 IDirect3DRMFaceArray_Release(array1);
855 icount = IDirect3DRMFace_GetVertexCount(face1);
856 ok(!icount, "wrong VertexCount: %i\n", icount);
858 IDirect3DRMFace_Release(face1);
859 IDirect3DRMMeshBuilder2_Release(MeshBuilder2);
861 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
863 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
864 IDirect3DRM_Release(d3drm);
865 return;
868 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &MeshBuilder3);
869 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
871 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
872 ok(!icount, "wrong FaceCount: %i\n", icount);
874 hr = IDirect3DRMMeshBuilder3_CreateFace(MeshBuilder3, &face2);
875 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace2 interface (hr = %x)\n", hr);
877 hr = IDirect3DRMFace2_QueryInterface(face2, &IID_IDirect3DRMObject, (void **)&obj);
878 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
880 hr = IDirect3DRMFace2_QueryInterface(face2, &IID_IDirect3DRMFace, (void **)&face1);
881 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
882 ok(obj == (IDirect3DRMObject *)face1, "Unexpected interface pointer.\n");
884 IDirect3DRMFace_Release(face1);
885 IDirect3DRMObject_Release(obj);
887 test_class_name((IDirect3DRMObject *)face2, "Face");
888 test_object_name((IDirect3DRMObject *)face2);
890 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
891 todo_wine
892 ok(icount == 1, "wrong FaceCount: %i\n", icount);
894 array1 = NULL;
895 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
896 todo_wine
897 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
898 todo_wine
899 ok(array1 != NULL, "pArray = %p\n", array1);
900 if (array1)
902 IDirect3DRMFace *face;
903 count = IDirect3DRMFaceArray_GetSize(array1);
904 ok(count == 1, "count = %u\n", count);
905 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
906 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
907 IDirect3DRMFace_Release(face);
908 IDirect3DRMFaceArray_Release(array1);
911 icount = IDirect3DRMFace2_GetVertexCount(face2);
912 ok(!icount, "wrong VertexCount: %i\n", icount);
914 info.lpMemory = data_ok;
915 info.dSize = strlen(data_ok);
916 hr = IDirect3DRMMeshBuilder3_Load(MeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
917 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
919 icount = IDirect3DRMMeshBuilder3_GetVertexCount(MeshBuilder3);
920 ok(icount == 4, "Wrong number of vertices %d (must be 4)\n", icount);
922 icount = IDirect3DRMMeshBuilder3_GetNormalCount(MeshBuilder3);
923 ok(icount == 4, "Wrong number of normals %d (must be 4)\n", icount);
925 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
926 todo_wine
927 ok(icount == 4, "Wrong number of faces %d (must be 4)\n", icount);
929 count = 4;
930 hr = IDirect3DRMMeshBuilder3_GetVertices(MeshBuilder3, 0, &count, v1);
931 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
932 ok(count == 4, "Wrong number of vertices %d (must be 4)\n", count);
934 hr = IDirect3DRMMeshBuilder3_GetNormals(MeshBuilder3, 0, &count, n1);
935 ok(hr == D3DRM_OK, "Cannot get normals information (hr = %x)\n", hr);
936 ok(count == 4, "Wrong number of normals %d (must be 4)\n", count);
938 array1 = NULL;
939 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
940 todo_wine
941 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
942 todo_wine
943 ok(array1 != NULL, "pArray = %p\n", array1);
944 if (array1)
946 IDirect3DRMFace *face;
947 count = IDirect3DRMFaceArray_GetSize(array1);
948 ok(count == 4, "count = %u\n", count);
949 hr = IDirect3DRMFaceArray_GetElement(array1, 1, &face);
950 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
951 hr = IDirect3DRMFace_GetVertices(face, &count, v2, n2);
952 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
953 ok(count == 3, "Wrong number of vertices %d (must be 3)\n", count);
955 vector_eq(&v1[0], &v2[0]);
956 vector_eq(&v1[1], &v2[1]);
957 vector_eq(&v1[2], &v2[2]);
959 vector_eq(&n1[0], &n2[0]);
960 vector_eq(&n1[1], &n2[1]);
961 vector_eq(&n1[2], &n2[2]);
963 IDirect3DRMFace_Release(face);
964 IDirect3DRMFaceArray_Release(array1);
967 /* Setting face color. */
968 hr = IDirect3DRMFace2_SetColor(face2, 0x1f180587);
969 ok(SUCCEEDED(hr), "Failed to set face color, hr %#x.\n", hr);
970 color = IDirect3DRMFace2_GetColor(face2);
971 ok(color == 0x1f180587, "Unexpected color %8x.\n", color);
973 hr = IDirect3DRMFace2_SetColorRGB(face2, 0.5f, 0.5f, 0.5f);
974 ok(SUCCEEDED(hr), "Failed to set color, hr %#x.\n", hr);
975 color = IDirect3DRMFace2_GetColor(face2);
976 ok(color == 0xff7f7f7f, "Unexpected color %8x.\n", color);
978 IDirect3DRMFace2_Release(face2);
979 IDirect3DRMMeshBuilder3_Release(MeshBuilder3);
980 IDirect3DRM3_Release(d3drm3);
981 IDirect3DRM2_Release(d3drm2);
982 IDirect3DRM_Release(d3drm);
985 static void test_Frame(void)
987 HRESULT hr;
988 IDirect3DRM *d3drm;
989 IDirect3DRMFrame *pFrameC;
990 IDirect3DRMFrame *pFrameP1;
991 IDirect3DRMFrame *pFrameP2;
992 IDirect3DRMFrame *pFrameTmp;
993 IDirect3DRMFrame *scene_frame;
994 IDirect3DRMFrameArray *frame_array;
995 IDirect3DRMMeshBuilder *mesh_builder;
996 IDirect3DRMVisual *visual1;
997 IDirect3DRMVisual *visual_tmp;
998 IDirect3DRMVisualArray *visual_array;
999 IDirect3DRMLight *light1;
1000 IDirect3DRMLight *light_tmp;
1001 IDirect3DRMLightArray *light_array;
1002 IDirect3DRMFrame3 *frame3;
1003 DWORD count, options;
1004 ULONG ref, ref2;
1005 D3DCOLOR color;
1007 hr = Direct3DRMCreate(&d3drm);
1008 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1010 ref = get_refcount((IUnknown *)d3drm);
1011 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameC);
1012 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1013 CHECK_REFCOUNT(pFrameC, 1);
1014 ref2 = get_refcount((IUnknown *)d3drm);
1015 ok(ref2 > ref, "Expected d3drm object to be referenced.\n");
1017 test_class_name((IDirect3DRMObject *)pFrameC, "Frame");
1018 test_object_name((IDirect3DRMObject *)pFrameC);
1020 hr = IDirect3DRMFrame_GetParent(pFrameC, NULL);
1021 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
1022 pFrameTmp = (void*)0xdeadbeef;
1023 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1024 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1025 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1026 CHECK_REFCOUNT(pFrameC, 1);
1028 frame_array = NULL;
1029 hr = IDirect3DRMFrame_GetChildren(pFrameC, &frame_array);
1030 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1031 ok(!!frame_array, "frame_array = %p\n", frame_array);
1032 if (frame_array)
1034 count = IDirect3DRMFrameArray_GetSize(frame_array);
1035 ok(count == 0, "count = %u\n", count);
1036 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1037 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1038 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1039 IDirect3DRMFrameArray_Release(frame_array);
1042 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP1);
1043 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1045 /* GetParent with NULL pointer */
1046 hr = IDirect3DRMFrame_GetParent(pFrameP1, NULL);
1047 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1048 CHECK_REFCOUNT(pFrameP1, 1);
1050 /* [Add/Delete]Child with NULL pointer */
1051 hr = IDirect3DRMFrame_AddChild(pFrameP1, NULL);
1052 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1053 CHECK_REFCOUNT(pFrameP1, 1);
1055 hr = IDirect3DRMFrame_DeleteChild(pFrameP1, NULL);
1056 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1057 CHECK_REFCOUNT(pFrameP1, 1);
1059 /* Add child to first parent */
1060 pFrameTmp = (void*)0xdeadbeef;
1061 hr = IDirect3DRMFrame_GetParent(pFrameP1, &pFrameTmp);
1062 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1063 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1065 hr = IDirect3DRMFrame_AddChild(pFrameP1, pFrameC);
1066 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1067 CHECK_REFCOUNT(pFrameP1, 1);
1068 CHECK_REFCOUNT(pFrameC, 2);
1070 hr = IDirect3DRMFrame_GetScene(pFrameC, NULL);
1071 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1072 hr = IDirect3DRMFrame_GetScene(pFrameC, &scene_frame);
1073 ok(SUCCEEDED(hr), "Cannot get scene (hr == %#x).\n", hr);
1074 ok(scene_frame == pFrameP1, "Expected scene frame == %p, got %p.\n", pFrameP1, scene_frame);
1075 CHECK_REFCOUNT(pFrameP1, 2);
1076 IDirect3DRMFrame_Release(scene_frame);
1077 hr = IDirect3DRMFrame_GetScene(pFrameP1, &scene_frame);
1078 ok(SUCCEEDED(hr), "Cannot get scene (hr == %#x).\n", hr);
1079 ok(scene_frame == pFrameP1, "Expected scene frame == %p, got %p.\n", pFrameP1, scene_frame);
1080 CHECK_REFCOUNT(pFrameP1, 2);
1081 IDirect3DRMFrame_Release(scene_frame);
1083 frame_array = NULL;
1084 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
1085 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1086 /* In some older version of d3drm, creating IDirect3DRMFrameArray object with GetChildren does not increment refcount of children frames */
1087 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
1088 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
1089 if (frame_array)
1091 count = IDirect3DRMFrameArray_GetSize(frame_array);
1092 ok(count == 1, "count = %u\n", count);
1093 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1094 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1095 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1096 ok((get_refcount((IUnknown*)pFrameC) == 4) || broken(get_refcount((IUnknown*)pFrameC) == 3),
1097 "Invalid refcount. Expected 4 (or 3) got %d\n", get_refcount((IUnknown*)pFrameC));
1098 IDirect3DRMFrame_Release(pFrameTmp);
1099 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
1100 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
1101 IDirect3DRMFrameArray_Release(frame_array);
1102 CHECK_REFCOUNT(pFrameC, 2);
1105 pFrameTmp = (void*)0xdeadbeef;
1106 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1107 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1108 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
1109 CHECK_REFCOUNT(pFrameP1, 2);
1110 IDirect3DRMFrame_Release(pFrameTmp);
1111 CHECK_REFCOUNT(pFrameP1, 1);
1113 /* Add child to second parent */
1114 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP2);
1115 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1117 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1118 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1119 CHECK_REFCOUNT(pFrameC, 2);
1121 frame_array = NULL;
1122 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1123 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1124 if (frame_array)
1126 count = IDirect3DRMFrameArray_GetSize(frame_array);
1127 ok(count == 1, "count = %u\n", count);
1128 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1129 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1130 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1131 IDirect3DRMFrame_Release(pFrameTmp);
1132 IDirect3DRMFrameArray_Release(frame_array);
1135 frame_array = NULL;
1136 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
1137 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1138 if (frame_array)
1140 count = IDirect3DRMFrameArray_GetSize(frame_array);
1141 ok(count == 0, "count = %u\n", count);
1142 pFrameTmp = (void*)0xdeadbeef;
1143 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1144 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1145 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1146 IDirect3DRMFrameArray_Release(frame_array);
1148 hr = IDirect3DRMFrame_GetScene(pFrameC, &scene_frame);
1149 ok(SUCCEEDED(hr), "Cannot get scene (hr == %#x).\n", hr);
1150 ok(scene_frame == pFrameP2, "Expected scene frame == %p, got %p.\n", pFrameP2, scene_frame);
1151 CHECK_REFCOUNT(pFrameP2, 2);
1152 IDirect3DRMFrame_Release(scene_frame);
1153 hr = IDirect3DRMFrame_GetScene(pFrameP2, &scene_frame);
1154 ok(SUCCEEDED(hr), "Cannot get scene (hr == %#x).\n", hr);
1155 ok(scene_frame == pFrameP2, "Expected scene frame == %p, got %p.\n", pFrameP2, scene_frame);
1156 CHECK_REFCOUNT(pFrameP2, 2);
1157 IDirect3DRMFrame_Release(scene_frame);
1159 pFrameTmp = (void*)0xdeadbeef;
1160 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1161 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1162 ok(pFrameTmp == pFrameP2, "pFrameTmp = %p\n", pFrameTmp);
1163 CHECK_REFCOUNT(pFrameP2, 2);
1164 CHECK_REFCOUNT(pFrameC, 2);
1165 IDirect3DRMFrame_Release(pFrameTmp);
1166 CHECK_REFCOUNT(pFrameP2, 1);
1168 /* Add child again */
1169 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1170 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1171 CHECK_REFCOUNT(pFrameC, 2);
1173 frame_array = NULL;
1174 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1175 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1176 if (frame_array)
1178 count = IDirect3DRMFrameArray_GetSize(frame_array);
1179 ok(count == 1, "count = %u\n", count);
1180 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1181 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1182 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1183 IDirect3DRMFrame_Release(pFrameTmp);
1184 IDirect3DRMFrameArray_Release(frame_array);
1187 /* Delete child */
1188 hr = IDirect3DRMFrame_DeleteChild(pFrameP2, pFrameC);
1189 ok(hr == D3DRM_OK, "Cannot delete child frame (hr = %x)\n", hr);
1190 CHECK_REFCOUNT(pFrameC, 1);
1192 frame_array = NULL;
1193 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1194 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1195 if (frame_array)
1197 count = IDirect3DRMFrameArray_GetSize(frame_array);
1198 ok(count == 0, "count = %u\n", count);
1199 pFrameTmp = (void*)0xdeadbeef;
1200 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1201 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1202 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1203 IDirect3DRMFrameArray_Release(frame_array);
1206 pFrameTmp = (void*)0xdeadbeef;
1207 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1208 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1209 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1211 /* Add two children */
1212 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1213 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1214 CHECK_REFCOUNT(pFrameC, 2);
1216 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameP1);
1217 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1218 CHECK_REFCOUNT(pFrameP1, 2);
1220 frame_array = NULL;
1221 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1222 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1223 if (frame_array)
1225 count = IDirect3DRMFrameArray_GetSize(frame_array);
1226 ok(count == 2, "count = %u\n", count);
1227 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1228 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1229 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1230 IDirect3DRMFrame_Release(pFrameTmp);
1231 hr = IDirect3DRMFrameArray_GetElement(frame_array, 1, &pFrameTmp);
1232 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1233 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
1234 IDirect3DRMFrame_Release(pFrameTmp);
1235 IDirect3DRMFrameArray_Release(frame_array);
1238 /* [Add/Delete]Visual with NULL pointer */
1239 hr = IDirect3DRMFrame_AddVisual(pFrameP1, NULL);
1240 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1241 CHECK_REFCOUNT(pFrameP1, 2);
1243 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, NULL);
1244 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1245 CHECK_REFCOUNT(pFrameP1, 2);
1247 /* Create Visual */
1248 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &mesh_builder);
1249 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
1250 visual1 = (IDirect3DRMVisual *)mesh_builder;
1252 /* Add Visual to first parent */
1253 hr = IDirect3DRMFrame_AddVisual(pFrameP1, visual1);
1254 ok(hr == D3DRM_OK, "Cannot add visual (hr = %x)\n", hr);
1255 CHECK_REFCOUNT(pFrameP1, 2);
1256 CHECK_REFCOUNT(visual1, 2);
1258 visual_array = NULL;
1259 hr = IDirect3DRMFrame_GetVisuals(pFrameP1, &visual_array);
1260 ok(hr == D3DRM_OK, "Cannot get visuals (hr = %x)\n", hr);
1261 if (visual_array)
1263 count = IDirect3DRMVisualArray_GetSize(visual_array);
1264 ok(count == 1, "count = %u\n", count);
1265 hr = IDirect3DRMVisualArray_GetElement(visual_array, 0, &visual_tmp);
1266 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1267 ok(visual_tmp == visual1, "visual_tmp = %p\n", visual_tmp);
1268 IDirect3DRMVisual_Release(visual_tmp);
1269 IDirect3DRMVisualArray_Release(visual_array);
1272 /* Delete Visual */
1273 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, visual1);
1274 ok(hr == D3DRM_OK, "Cannot delete visual (hr = %x)\n", hr);
1275 CHECK_REFCOUNT(pFrameP1, 2);
1276 IDirect3DRMMeshBuilder_Release(mesh_builder);
1278 /* [Add/Delete]Light with NULL pointer */
1279 hr = IDirect3DRMFrame_AddLight(pFrameP1, NULL);
1280 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1281 CHECK_REFCOUNT(pFrameP1, 2);
1283 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, NULL);
1284 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1285 CHECK_REFCOUNT(pFrameP1, 2);
1287 /* Create Light */
1288 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.1, 0.2, 0.3, &light1);
1289 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
1291 /* Add Light to first parent */
1292 hr = IDirect3DRMFrame_AddLight(pFrameP1, light1);
1293 ok(hr == D3DRM_OK, "Cannot add light (hr = %x)\n", hr);
1294 CHECK_REFCOUNT(pFrameP1, 2);
1295 CHECK_REFCOUNT(light1, 2);
1297 light_array = NULL;
1298 hr = IDirect3DRMFrame_GetLights(pFrameP1, &light_array);
1299 ok(hr == D3DRM_OK, "Cannot get lights (hr = %x)\n", hr);
1300 if (light_array)
1302 count = IDirect3DRMLightArray_GetSize(light_array);
1303 ok(count == 1, "count = %u\n", count);
1304 hr = IDirect3DRMLightArray_GetElement(light_array, 0, &light_tmp);
1305 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1306 ok(light_tmp == light1, "light_tmp = %p\n", light_tmp);
1307 IDirect3DRMLight_Release(light_tmp);
1308 IDirect3DRMLightArray_Release(light_array);
1311 /* Delete Light */
1312 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, light1);
1313 ok(hr == D3DRM_OK, "Cannot delete light (hr = %x)\n", hr);
1314 CHECK_REFCOUNT(pFrameP1, 2);
1315 IDirect3DRMLight_Release(light1);
1317 /* Test SceneBackground on first parent */
1318 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1319 ok(color == 0xff000000, "wrong color (%x)\n", color);
1321 hr = IDirect3DRMFrame_SetSceneBackground(pFrameP1, 0xff180587);
1322 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1323 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1324 ok(color == 0xff180587, "wrong color (%x)\n", color);
1326 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(pFrameP1, 0.5, 0.5, 0.5);
1327 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1328 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1329 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1331 /* Traversal options. */
1332 hr = IDirect3DRMFrame_QueryInterface(pFrameP2, &IID_IDirect3DRMFrame3, (void **)&frame3);
1333 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMFrame3 interface, hr %#x.\n", hr);
1335 hr = IDirect3DRMFrame3_GetTraversalOptions(frame3, NULL);
1336 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
1338 options = 0;
1339 hr = IDirect3DRMFrame3_GetTraversalOptions(frame3, &options);
1340 ok(SUCCEEDED(hr), "Failed to get traversal options, hr %#x.\n", hr);
1341 ok(options == (D3DRMFRAME_RENDERENABLE | D3DRMFRAME_PICKENABLE), "Unexpected default options %#x.\n", options);
1343 hr = IDirect3DRMFrame3_SetTraversalOptions(frame3, 0);
1344 ok(SUCCEEDED(hr), "Unexpected hr %#x.\n", hr);
1346 hr = IDirect3DRMFrame3_SetTraversalOptions(frame3, 0xf0000000);
1347 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
1349 hr = IDirect3DRMFrame3_SetTraversalOptions(frame3, 0xf0000000 | D3DRMFRAME_PICKENABLE);
1350 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
1352 options = 0xf;
1353 hr = IDirect3DRMFrame3_GetTraversalOptions(frame3, &options);
1354 ok(SUCCEEDED(hr), "Failed to get traversal options, hr %#x.\n", hr);
1355 ok(options == 0, "Unexpected traversal options %#x.\n", options);
1357 hr = IDirect3DRMFrame3_SetTraversalOptions(frame3, D3DRMFRAME_PICKENABLE);
1358 ok(SUCCEEDED(hr), "Failed to set traversal options, hr %#x.\n", hr);
1360 options = 0;
1361 hr = IDirect3DRMFrame3_GetTraversalOptions(frame3, &options);
1362 ok(SUCCEEDED(hr), "Failed to get traversal options, hr %#x.\n", hr);
1363 ok(options == D3DRMFRAME_PICKENABLE, "Unexpected traversal options %#x.\n", options);
1365 IDirect3DRMFrame3_Release(frame3);
1367 /* Cleanup */
1368 IDirect3DRMFrame_Release(pFrameP2);
1369 CHECK_REFCOUNT(pFrameC, 1);
1370 CHECK_REFCOUNT(pFrameP1, 1);
1372 IDirect3DRMFrame_Release(pFrameC);
1373 IDirect3DRMFrame_Release(pFrameP1);
1375 IDirect3DRM_Release(d3drm);
1378 struct destroy_context
1380 IDirect3DRMObject *obj;
1381 unsigned int test_idx;
1382 int called;
1385 struct callback_order
1387 void *callback;
1388 void *context;
1389 } corder[3], d3drm_corder[3];
1391 static void CDECL destroy_callback(IDirect3DRMObject *obj, void *arg)
1393 struct destroy_context *ctxt = arg;
1394 ok(ctxt->called == 1 || ctxt->called == 2, "got called counter %d\n", ctxt->called);
1395 ok(obj == ctxt->obj, "called with %p, expected %p\n", obj, ctxt->obj);
1396 d3drm_corder[ctxt->called].callback = &destroy_callback;
1397 d3drm_corder[ctxt->called++].context = ctxt;
1400 static void CDECL destroy_callback1(IDirect3DRMObject *obj, void *arg)
1402 struct destroy_context *ctxt = (struct destroy_context*)arg;
1403 ok(ctxt->called == 0, "got called counter %d\n", ctxt->called);
1404 ok(obj == ctxt->obj, "called with %p, expected %p\n", obj, ctxt->obj);
1405 d3drm_corder[ctxt->called].callback = &destroy_callback1;
1406 d3drm_corder[ctxt->called++].context = ctxt;
1409 static void test_destroy_callback(unsigned int test_idx, REFCLSID clsid, REFIID iid)
1411 struct destroy_context context;
1412 IDirect3DRMObject *obj;
1413 IUnknown *unknown;
1414 IDirect3DRM *d3drm;
1415 HRESULT hr;
1416 int i;
1418 hr = Direct3DRMCreate(&d3drm);
1419 ok(SUCCEEDED(hr), "Test %u: Cannot get IDirect3DRM interface (hr = %x).\n", test_idx, hr);
1421 hr = IDirect3DRM_CreateObject(d3drm, clsid, NULL, iid, (void **)&unknown);
1422 ok(hr == D3DRM_OK, "Test %u: Cannot get IDirect3DRMObject interface (hr = %x).\n", test_idx, hr);
1423 hr = IUnknown_QueryInterface(unknown, &IID_IDirect3DRMObject, (void**)&obj);
1424 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1425 IUnknown_Release(unknown);
1427 context.called = 0;
1428 context.test_idx = test_idx;
1429 context.obj = obj;
1431 hr = IDirect3DRMObject_AddDestroyCallback(obj, NULL, &context);
1432 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected D3DRMERR_BADVALUE (hr = %x).\n", test_idx, hr);
1434 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1435 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1436 corder[2].callback = &destroy_callback;
1437 corder[2].context = &context;
1439 /* same callback added twice */
1440 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1441 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1442 corder[1].callback = &destroy_callback;
1443 corder[1].context = &context;
1445 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback1, NULL);
1446 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1448 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback1, &context);
1449 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1451 /* add one more */
1452 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback1, &context);
1453 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1454 corder[0].callback = &destroy_callback1;
1455 corder[0].context = &context;
1457 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, NULL, NULL);
1458 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected D3DRM_BADVALUE (hr = %x).\n", test_idx, hr);
1460 context.called = 0;
1461 IDirect3DRMObject_Release(obj);
1462 ok(context.called == 3, "Test %u: got %d, expected 3.\n", test_idx, context.called);
1463 for (i = 0; i < context.called; i++)
1465 ok(corder[i].callback == d3drm_corder[i].callback
1466 && corder[i].context == d3drm_corder[i].context,
1467 "Expected callback = %p, context = %p. Got callback = %p, context = %p.\n", d3drm_corder[i].callback,
1468 d3drm_corder[i].context, corder[i].callback, corder[i].context);
1471 /* test this pattern - add cb1, add cb2, add cb1, delete cb1 */
1472 hr = IDirect3DRM_CreateObject(d3drm, clsid, NULL, iid, (void **)&unknown);
1473 ok(hr == D3DRM_OK, "Test %u: Cannot get IDirect3DRMObject interface (hr = %x).\n", test_idx, hr);
1474 hr = IUnknown_QueryInterface(unknown, &IID_IDirect3DRMObject, (void**)&obj);
1475 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1476 IUnknown_Release(unknown);
1478 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1479 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1480 corder[1].callback = &destroy_callback;
1481 corder[1].context = &context;
1483 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback1, &context);
1484 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1485 corder[0].callback = &destroy_callback1;
1486 corder[0].context = &context;
1488 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1489 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1491 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback, &context);
1492 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1494 context.called = 0;
1495 hr = IDirect3DRMObject_QueryInterface(obj, &IID_IDirect3DRMObject, (void**)&context.obj);
1496 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1497 IDirect3DRMObject_Release(context.obj);
1498 IUnknown_Release(unknown);
1499 ok(context.called == 2, "Test %u: got %d, expected 2.\n", test_idx, context.called);
1500 for (i = 0; i < context.called; i++)
1502 ok(corder[i].callback == d3drm_corder[i].callback
1503 && corder[i].context == d3drm_corder[i].context,
1504 "Expected callback = %p, context = %p. Got callback = %p, context = %p.\n", d3drm_corder[i].callback,
1505 d3drm_corder[i].context, corder[i].callback, corder[i].context);
1509 static void test_object(void)
1511 static const struct
1513 REFCLSID clsid;
1514 REFIID iid;
1515 BOOL takes_d3drm_ref;
1517 tests[] =
1519 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice },
1520 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice2 },
1521 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice3 },
1522 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMWinDevice },
1523 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture },
1524 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture2 },
1525 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture3 },
1526 { &CLSID_CDirect3DRMViewport, &IID_IDirect3DRMViewport },
1527 { &CLSID_CDirect3DRMViewport, &IID_IDirect3DRMViewport2 },
1528 { &CLSID_CDirect3DRMFace, &IID_IDirect3DRMFace },
1529 { &CLSID_CDirect3DRMFace, &IID_IDirect3DRMFace2 },
1530 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder, TRUE },
1531 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder2, TRUE },
1532 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder3, TRUE },
1533 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame, TRUE },
1534 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame2, TRUE },
1535 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame3, TRUE },
1536 { &CLSID_CDirect3DRMLight, &IID_IDirect3DRMLight, TRUE },
1537 { &CLSID_CDirect3DRMMaterial, &IID_IDirect3DRMMaterial, TRUE },
1538 { &CLSID_CDirect3DRMMaterial, &IID_IDirect3DRMMaterial2, TRUE },
1539 { &CLSID_CDirect3DRMMesh, &IID_IDirect3DRMMesh, TRUE },
1540 { &CLSID_CDirect3DRMAnimation, &IID_IDirect3DRMAnimation, TRUE },
1541 { &CLSID_CDirect3DRMAnimation, &IID_IDirect3DRMAnimation2, TRUE },
1542 { &CLSID_CDirect3DRMWrap, &IID_IDirect3DRMWrap },
1544 IDirect3DRM *d3drm1;
1545 IDirect3DRM2 *d3drm2;
1546 IDirect3DRM3 *d3drm3;
1547 IUnknown *unknown = (IUnknown *)0xdeadbeef;
1548 HRESULT hr;
1549 ULONG ref1, ref2, ref3, ref4;
1550 int i;
1552 hr = Direct3DRMCreate(&d3drm1);
1553 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
1554 ref1 = get_refcount((IUnknown *)d3drm1);
1555 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1556 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
1557 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1558 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
1560 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_DirectDraw, NULL, &IID_IDirectDraw, (void **)&unknown);
1561 ok(hr == CLASSFACTORY_E_FIRST, "Expected hr == CLASSFACTORY_E_FIRST, got %#x.\n", hr);
1562 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1564 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1566 unknown = (IUnknown *)0xdeadbeef;
1567 hr = IDirect3DRM_CreateObject(d3drm1, NULL, NULL, tests[i].iid, (void **)&unknown);
1568 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1569 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1570 unknown = (IUnknown *)0xdeadbeef;
1571 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, NULL, (void **)&unknown);
1572 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1573 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1574 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, NULL, NULL);
1575 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1577 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1578 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1579 if (SUCCEEDED(hr))
1581 ref2 = get_refcount((IUnknown *)d3drm1);
1582 if (tests[i].takes_d3drm_ref)
1583 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1584 else
1585 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1587 ref3 = get_refcount((IUnknown *)d3drm2);
1588 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1589 ref4 = get_refcount((IUnknown *)d3drm3);
1590 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1591 IUnknown_Release(unknown);
1592 ref2 = get_refcount((IUnknown *)d3drm1);
1593 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1594 ref3 = get_refcount((IUnknown *)d3drm2);
1595 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1596 ref4 = get_refcount((IUnknown *)d3drm3);
1597 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1599 /* test Add/Destroy callbacks */
1600 test_destroy_callback(i, tests[i].clsid, tests[i].iid);
1602 hr = IDirect3DRM2_CreateObject(d3drm2, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1603 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1604 ref2 = get_refcount((IUnknown *)d3drm1);
1605 if (tests[i].takes_d3drm_ref)
1606 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1607 else
1608 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1609 ref3 = get_refcount((IUnknown *)d3drm2);
1610 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1611 ref4 = get_refcount((IUnknown *)d3drm3);
1612 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1613 IUnknown_Release(unknown);
1614 ref2 = get_refcount((IUnknown *)d3drm1);
1615 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1616 ref3 = get_refcount((IUnknown *)d3drm2);
1617 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1618 ref4 = get_refcount((IUnknown *)d3drm3);
1619 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1621 hr = IDirect3DRM3_CreateObject(d3drm3, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1622 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1623 ref2 = get_refcount((IUnknown *)d3drm1);
1624 if (tests[i].takes_d3drm_ref)
1625 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1626 else
1627 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1628 ref3 = get_refcount((IUnknown *)d3drm2);
1629 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1630 ref4 = get_refcount((IUnknown *)d3drm3);
1631 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1632 IUnknown_Release(unknown);
1633 ref2 = get_refcount((IUnknown *)d3drm1);
1634 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1635 ref3 = get_refcount((IUnknown *)d3drm2);
1636 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1637 ref4 = get_refcount((IUnknown *)d3drm3);
1638 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1642 IDirect3DRM_Release(d3drm1);
1643 IDirect3DRM2_Release(d3drm2);
1644 IDirect3DRM3_Release(d3drm3);
1647 static void test_Viewport(void)
1649 IDirectDrawClipper *clipper;
1650 HRESULT hr;
1651 IDirect3DRM *d3drm1;
1652 IDirect3DRM2 *d3drm2;
1653 IDirect3DRM3 *d3drm3;
1654 IDirect3DRMDevice *device1, *d3drm_device1;
1655 IDirect3DRMDevice3 *device3, *d3drm_device3;
1656 IDirect3DRMFrame *frame;
1657 IDirect3DRMFrame3 *frame3;
1658 IDirect3DRMViewport *viewport;
1659 IDirect3DRMViewport2 *viewport2;
1660 IDirect3DViewport *d3d_viewport;
1661 D3DVIEWPORT vp;
1662 D3DVALUE expected_val;
1663 IDirect3DRMObject *obj, *obj2;
1664 GUID driver;
1665 HWND window;
1666 RECT rc;
1667 DWORD data, ref1, ref2, ref3, ref4;
1668 DWORD initial_ref1, initial_ref2, initial_ref3, device_ref, frame_ref, frame_ref2, viewport_ref;
1670 window = create_window();
1671 GetClientRect(window, &rc);
1673 hr = Direct3DRMCreate(&d3drm1);
1674 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1675 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1676 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
1677 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1678 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
1679 initial_ref1 = get_refcount((IUnknown *)d3drm1);
1680 initial_ref2 = get_refcount((IUnknown *)d3drm2);
1681 initial_ref3 = get_refcount((IUnknown *)d3drm3);
1683 hr = DirectDrawCreateClipper(0, &clipper, NULL);
1684 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1686 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
1687 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
1689 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
1690 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
1691 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1692 hr = IDirect3DRMDevice3_QueryInterface(device3, &IID_IDirect3DRMDevice, (void **)&device1);
1693 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
1695 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame);
1696 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1697 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
1698 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %x).\n", hr);
1700 ref1 = get_refcount((IUnknown *)d3drm1);
1701 ref2 = get_refcount((IUnknown *)d3drm2);
1702 ref3 = get_refcount((IUnknown *)d3drm3);
1703 device_ref = get_refcount((IUnknown *)device1);
1704 frame_ref = get_refcount((IUnknown *)frame);
1706 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, 0, 0, 0, 0, &viewport);
1707 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1708 ref4 = get_refcount((IUnknown *)d3drm1);
1709 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1710 ref4 = get_refcount((IUnknown *)d3drm2);
1711 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1712 ref4 = get_refcount((IUnknown *)d3drm3);
1713 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1714 ref4 = get_refcount((IUnknown *)device1);
1715 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1716 ref4 = get_refcount((IUnknown *)frame);
1717 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1719 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1720 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1721 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device1, d3drm_device1);
1722 IDirect3DRMDevice_Release(d3drm_device1);
1724 IDirect3DRMViewport_Release(viewport);
1725 ref4 = get_refcount((IUnknown *)d3drm1);
1726 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1727 ref4 = get_refcount((IUnknown *)d3drm2);
1728 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1729 ref4 = get_refcount((IUnknown *)d3drm3);
1730 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1731 ref4 = get_refcount((IUnknown *)device1);
1732 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1733 ref4 = get_refcount((IUnknown *)frame);
1734 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1736 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, 0, 0, 0, 0, &viewport);
1737 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1738 ref4 = get_refcount((IUnknown *)d3drm1);
1739 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1740 ref4 = get_refcount((IUnknown *)d3drm2);
1741 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1742 ref4 = get_refcount((IUnknown *)d3drm3);
1743 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1744 ref4 = get_refcount((IUnknown *)device1);
1745 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1746 ref4 = get_refcount((IUnknown *)frame);
1747 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1749 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1750 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1751 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device1, d3drm_device1);
1752 IDirect3DRMDevice_Release(d3drm_device1);
1754 IDirect3DRMViewport_Release(viewport);
1755 ref4 = get_refcount((IUnknown *)d3drm1);
1756 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1757 ref4 = get_refcount((IUnknown *)d3drm2);
1758 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1759 ref4 = get_refcount((IUnknown *)d3drm3);
1760 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1761 ref4 = get_refcount((IUnknown *)device1);
1762 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1763 ref4 = get_refcount((IUnknown *)frame);
1764 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1766 device_ref = get_refcount((IUnknown *)device3);
1767 frame_ref2 = get_refcount((IUnknown *)frame3);
1769 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, 0, 0, 0, 0, &viewport2);
1770 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
1771 ref4 = get_refcount((IUnknown *)d3drm1);
1772 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1773 ref4 = get_refcount((IUnknown *)d3drm2);
1774 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1775 ref4 = get_refcount((IUnknown *)d3drm3);
1776 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1777 ref4 = get_refcount((IUnknown *)device3);
1778 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1779 ref4 = get_refcount((IUnknown *)frame3);
1780 ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
1782 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
1783 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
1784 ok(device3 == d3drm_device3, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
1785 IDirect3DRMDevice3_Release(d3drm_device3);
1787 IDirect3DRMViewport2_Release(viewport2);
1788 ref4 = get_refcount((IUnknown *)d3drm1);
1789 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1790 ref4 = get_refcount((IUnknown *)d3drm2);
1791 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1792 ref4 = get_refcount((IUnknown *)d3drm3);
1793 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1794 ref4 = get_refcount((IUnknown *)device3);
1795 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1796 ref4 = get_refcount((IUnknown *)frame3);
1797 ok(ref4 == frame_ref2, "Expected ref4 == frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
1799 /* Test all failures together */
1800 hr = IDirect3DRM_CreateViewport(d3drm1, NULL, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1801 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1802 hr = IDirect3DRM_CreateViewport(d3drm1, device1, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1803 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1804 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &viewport);
1805 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1806 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom, &viewport);
1807 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1808 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right, rc.bottom + 1, &viewport);
1809 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1810 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right, rc.bottom, NULL);
1811 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1813 hr = IDirect3DRM2_CreateViewport(d3drm2, NULL, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1814 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1815 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1816 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1817 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &viewport);
1818 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1819 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom, &viewport);
1820 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1821 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right, rc.bottom + 1, &viewport);
1822 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1823 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right, rc.bottom, NULL);
1824 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1826 hr = IDirect3DRM3_CreateViewport(d3drm3, NULL, frame3, rc.left, rc.top, rc.right, rc.bottom, &viewport2);
1827 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1828 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport2);
1829 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1830 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &viewport2);
1831 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1832 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom, &viewport2);
1833 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1834 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right, rc.bottom + 1, &viewport2);
1835 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1836 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right, rc.bottom, NULL);
1837 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1839 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1840 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1841 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1842 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1843 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1844 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1845 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1846 ref4 = get_refcount((IUnknown *)d3d_viewport);
1847 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1848 IDirect3DViewport_Release(d3d_viewport);
1849 ref4 = get_refcount((IUnknown *)d3d_viewport);
1850 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1851 IDirect3DViewport_Release(d3d_viewport);
1853 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1854 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1855 vp.dwSize = sizeof(vp);
1856 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1857 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1858 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1859 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1860 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1861 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1862 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1863 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1864 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1865 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1866 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1867 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1868 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1869 IDirect3DViewport_Release(d3d_viewport);
1870 IDirect3DRMViewport_Release(viewport);
1872 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right, rc.bottom, &viewport2);
1873 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
1874 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1875 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1876 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1877 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1878 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1879 ref4 = get_refcount((IUnknown *)d3d_viewport);
1880 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1881 IDirect3DViewport_Release(d3d_viewport);
1882 ref4 = get_refcount((IUnknown *)d3d_viewport);
1883 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1884 IDirect3DViewport_Release(d3d_viewport);
1886 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1887 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1888 vp.dwSize = sizeof(vp);
1889 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1890 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1891 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1892 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1893 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1894 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1895 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1896 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1897 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1898 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1899 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1900 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1901 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1902 IDirect3DViewport_Release(d3d_viewport);
1903 IDirect3DRMViewport2_Release(viewport2);
1905 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1906 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %x)\n", hr);
1907 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1908 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1909 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1910 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1911 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1912 ref4 = get_refcount((IUnknown *)d3d_viewport);
1913 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1914 IDirect3DViewport_Release(d3d_viewport);
1915 ref4 = get_refcount((IUnknown *)d3d_viewport);
1916 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1917 IDirect3DViewport_Release(d3d_viewport);
1919 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1920 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1921 vp.dwSize = sizeof(vp);
1922 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1923 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1924 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1925 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1926 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1927 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1928 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1929 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1930 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1931 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1932 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1933 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1934 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1935 IDirect3DViewport_Release(d3d_viewport);
1937 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMObject, (void**)&obj);
1938 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1939 ok((IDirect3DRMObject*)viewport == obj, "got object pointer %p, expected %p\n", obj, viewport);
1941 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMViewport2, (void**)&viewport2);
1942 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1944 hr = IDirect3DRMViewport2_QueryInterface(viewport2, &IID_IDirect3DRMObject, (void**)&obj2);
1945 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1946 ok(obj == obj2, "got object pointer %p, expected %p\n", obj2, obj);
1947 ok((IUnknown*)viewport != (IUnknown*)viewport2, "got viewport1 %p, viewport2 %p\n", viewport, viewport2);
1949 IDirect3DRMViewport2_Release(viewport2);
1950 IDirect3DRMObject_Release(obj);
1951 IDirect3DRMObject_Release(obj2);
1953 test_class_name((IDirect3DRMObject *)viewport, "Viewport");
1954 test_object_name((IDirect3DRMObject *)viewport);
1956 /* AppData */
1957 hr = IDirect3DRMViewport_SetAppData(viewport, 0);
1958 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1960 hr = IDirect3DRMViewport_SetAppData(viewport, 0);
1961 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1963 hr = IDirect3DRMViewport_SetAppData(viewport, 1);
1964 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1966 hr = IDirect3DRMViewport_SetAppData(viewport, 1);
1967 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1969 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMViewport2, (void**)&viewport2);
1970 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1972 data = IDirect3DRMViewport2_GetAppData(viewport2);
1973 ok(data == 1, "got %x\n", data);
1974 IDirect3DRMViewport2_Release(viewport2);
1975 IDirect3DRMViewport_Release(viewport);
1977 /* IDirect3DRMViewport*::Init tests */
1978 ref1 = get_refcount((IUnknown *)d3drm1);
1979 ref2 = get_refcount((IUnknown *)d3drm2);
1980 ref3 = get_refcount((IUnknown *)d3drm3);
1981 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMViewport, NULL, &IID_IDirect3DRMViewport,
1982 (void **)&viewport);
1983 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x).\n", hr);
1984 ref4 = get_refcount((IUnknown *)d3drm1);
1985 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1986 ref4 = get_refcount((IUnknown *)d3drm2);
1987 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1988 ref4 = get_refcount((IUnknown *)d3drm3);
1989 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1991 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1992 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1993 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1994 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1996 /* Test all failures together */
1997 hr = IDirect3DRMViewport_Init(viewport, NULL, frame, rc.left, rc.top, rc.right, rc.bottom);
1998 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1999 hr = IDirect3DRMViewport_Init(viewport, device1, NULL, rc.left, rc.top, rc.right, rc.bottom);
2000 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2001 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2002 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2003 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom);
2004 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2005 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom + 1);
2006 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2008 device_ref = get_refcount((IUnknown *)device1);
2009 frame_ref = get_refcount((IUnknown *)frame);
2010 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom);
2011 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMViewport interface (hr = %#x).\n", hr);
2012 ref4 = get_refcount((IUnknown *)d3drm1);
2013 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2014 ref4 = get_refcount((IUnknown *)d3drm2);
2015 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2016 ref4 = get_refcount((IUnknown *)d3drm3);
2017 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2018 ref4 = get_refcount((IUnknown *)device1);
2019 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2020 ref4 = get_refcount((IUnknown *)frame);
2021 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
2023 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
2024 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
2025 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
2026 IDirect3DRMDevice_Release(d3drm_device1);
2028 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
2029 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2030 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
2031 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
2032 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2033 ref4 = get_refcount((IUnknown *)d3d_viewport);
2034 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
2035 IDirect3DViewport_Release(d3d_viewport);
2036 ref4 = get_refcount((IUnknown *)d3d_viewport);
2037 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
2038 IDirect3DViewport_Release(d3d_viewport);
2040 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
2041 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2042 vp.dwSize = sizeof(vp);
2043 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
2044 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
2045 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
2046 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
2047 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
2048 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
2049 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
2050 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
2051 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
2052 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
2053 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
2054 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
2055 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
2056 IDirect3DViewport_Release(d3d_viewport);
2058 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom);
2059 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2061 IDirect3DRMViewport_Release(viewport);
2062 ref4 = get_refcount((IUnknown *)d3drm1);
2063 todo_wine ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2064 ref4 = get_refcount((IUnknown *)d3drm2);
2065 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2066 ref4 = get_refcount((IUnknown *)d3drm3);
2067 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2068 ref4 = get_refcount((IUnknown *)device1);
2069 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2070 ref4 = get_refcount((IUnknown *)frame);
2071 todo_wine ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
2073 ref1 = get_refcount((IUnknown *)d3drm1);
2074 ref2 = get_refcount((IUnknown *)d3drm2);
2075 ref3 = get_refcount((IUnknown *)d3drm3);
2076 hr = IDirect3DRM3_CreateObject(d3drm2, &CLSID_CDirect3DRMViewport, NULL, &IID_IDirect3DRMViewport2,
2077 (void **)&viewport2);
2078 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x).\n", hr);
2079 ref4 = get_refcount((IUnknown *)d3drm1);
2080 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2081 ref4 = get_refcount((IUnknown *)d3drm2);
2082 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2083 ref4 = get_refcount((IUnknown *)d3drm3);
2084 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2086 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2087 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2088 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
2089 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2091 hr = IDirect3DRMViewport2_Init(viewport2, NULL, frame3, rc.left, rc.top, rc.right, rc.bottom);
2092 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2093 hr = IDirect3DRMViewport2_Init(viewport2, device3, NULL, rc.left, rc.top, rc.right, rc.bottom);
2094 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2095 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2096 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2097 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom);
2098 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2099 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom + 1);
2100 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2102 device_ref = get_refcount((IUnknown *)device3);
2103 frame_ref2 = get_refcount((IUnknown *)frame3);
2104 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom);
2105 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMViewport2 interface (hr = %#x).\n", hr);
2106 ref4 = get_refcount((IUnknown *)device3);
2107 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2108 ref4 = get_refcount((IUnknown *)frame3);
2109 ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2111 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
2112 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
2113 ok(device3 == d3drm_device3, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
2114 IDirect3DRMDevice3_Release(d3drm_device3);
2116 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2117 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2118 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
2119 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2120 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2121 ref4 = get_refcount((IUnknown *)d3d_viewport);
2122 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
2123 IDirect3DViewport_Release(d3d_viewport);
2124 ref4 = get_refcount((IUnknown *)d3d_viewport);
2125 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
2126 IDirect3DViewport_Release(d3d_viewport);
2128 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2129 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2130 vp.dwSize = sizeof(vp);
2131 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
2132 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
2133 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
2134 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
2135 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
2136 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
2137 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
2138 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
2139 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
2140 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
2141 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
2142 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
2143 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
2144 IDirect3DViewport_Release(d3d_viewport);
2146 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom);
2147 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2149 IDirect3DRMViewport2_Release(viewport2);
2150 ref4 = get_refcount((IUnknown *)d3drm1);
2151 todo_wine ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2152 ref4 = get_refcount((IUnknown *)d3drm2);
2153 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2154 ref4 = get_refcount((IUnknown *)d3drm3);
2155 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2156 ref4 = get_refcount((IUnknown *)device3);
2157 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2158 ref4 = get_refcount((IUnknown *)frame3);
2159 todo_wine ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2161 IDirect3DRMDevice3_Release(device3);
2162 IDirect3DRMDevice_Release(device1);
2163 ref4 = get_refcount((IUnknown *)d3drm1);
2164 ok(ref4 > initial_ref1, "Expected ref4 > initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2165 ref4 = get_refcount((IUnknown *)d3drm2);
2166 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2167 ref4 = get_refcount((IUnknown *)d3drm3);
2168 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2169 ref4 = get_refcount((IUnknown *)frame);
2170 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
2171 ref4 = get_refcount((IUnknown *)frame3);
2172 ok(ref4 == frame_ref2, "Expected ref4 == frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2174 IDirect3DRMFrame3_Release(frame3);
2175 ref4 = get_refcount((IUnknown *)d3drm1);
2176 ok(ref4 > initial_ref1, "Expected ref4 > initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2177 ref4 = get_refcount((IUnknown *)d3drm2);
2178 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2179 ref4 = get_refcount((IUnknown *)d3drm3);
2180 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2182 IDirect3DRMFrame_Release(frame);
2183 ref4 = get_refcount((IUnknown *)d3drm1);
2184 ok(ref4 == initial_ref1, "Expected ref4 == initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2185 ref4 = get_refcount((IUnknown *)d3drm2);
2186 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2187 ref4 = get_refcount((IUnknown *)d3drm3);
2188 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2189 IDirectDrawClipper_Release(clipper);
2191 IDirect3DRM3_Release(d3drm3);
2192 IDirect3DRM2_Release(d3drm2);
2193 IDirect3DRM_Release(d3drm1);
2194 DestroyWindow(window);
2197 static void test_Light(void)
2199 IDirect3DRMObject *object;
2200 HRESULT hr;
2201 IDirect3DRM *d3drm;
2202 IDirect3DRMLight *light;
2203 D3DRMLIGHTTYPE type;
2204 D3DCOLOR color;
2206 hr = Direct3DRMCreate(&d3drm);
2207 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2209 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.5, 0.5, 0.5, &light);
2210 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
2212 hr = IDirect3DRMLight_QueryInterface(light, &IID_IDirect3DRMObject, (void **)&object);
2213 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, hr %#x.\n", hr);
2214 IDirect3DRMObject_Release(object);
2216 test_class_name((IDirect3DRMObject *)light, "Light");
2217 test_object_name((IDirect3DRMObject *)light);
2219 type = IDirect3DRMLight_GetType(light);
2220 ok(type == D3DRMLIGHT_SPOT, "wrong type (%u)\n", type);
2222 color = IDirect3DRMLight_GetColor(light);
2223 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
2225 hr = IDirect3DRMLight_SetType(light, D3DRMLIGHT_POINT);
2226 ok(hr == D3DRM_OK, "Cannot set type (hr = %x)\n", hr);
2227 type = IDirect3DRMLight_GetType(light);
2228 ok(type == D3DRMLIGHT_POINT, "wrong type (%u)\n", type);
2230 hr = IDirect3DRMLight_SetColor(light, 0xff180587);
2231 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
2232 color = IDirect3DRMLight_GetColor(light);
2233 ok(color == 0xff180587, "wrong color (%x)\n", color);
2235 hr = IDirect3DRMLight_SetColorRGB(light, 0.5, 0.5, 0.5);
2236 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
2237 color = IDirect3DRMLight_GetColor(light);
2238 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
2240 IDirect3DRMLight_Release(light);
2242 IDirect3DRM_Release(d3drm);
2245 static void test_Material2(void)
2247 HRESULT hr;
2248 IDirect3DRM *d3drm;
2249 IDirect3DRM3 *d3drm3;
2250 IDirect3DRMMaterial2 *material2;
2251 D3DVALUE r, g, b;
2253 hr = Direct3DRMCreate(&d3drm);
2254 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2256 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
2258 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
2259 IDirect3DRM_Release(d3drm);
2260 return;
2263 hr = IDirect3DRM3_CreateMaterial(d3drm3, 18.5f, &material2);
2264 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMaterial2 interface (hr = %x)\n", hr);
2266 test_class_name((IDirect3DRMObject *)material2, "Material");
2267 test_object_name((IDirect3DRMObject *)material2);
2269 r = IDirect3DRMMaterial2_GetPower(material2);
2270 ok(r == 18.5f, "wrong power (%f)\n", r);
2272 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
2273 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2274 ok(r == 0.0f && g == 0.0f && b == 0.0f, "wrong emissive r=%f g=%f b=%f, expected r=0.0 g=0.0 b=0.0\n", r, g, b);
2276 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
2277 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2278 ok(r == 1.0f && g == 1.0f && b == 1.0f, "wrong specular r=%f g=%f b=%f, expected r=1.0 g=1.0 b=1.0\n", r, g, b);
2280 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
2281 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2282 ok(r == 0.0f && g == 0.0f && b == 0.0f, "wrong ambient r=%f g=%f b=%f, expected r=0.0 g=0.0 b=0.0\n", r, g, b);
2284 hr = IDirect3DRMMaterial2_SetPower(material2, 5.87f);
2285 ok(hr == D3DRM_OK, "Cannot set power (hr = %x)\n", hr);
2286 r = IDirect3DRMMaterial2_GetPower(material2);
2287 ok(r == 5.87f, "wrong power (%f)\n", r);
2289 hr = IDirect3DRMMaterial2_SetEmissive(material2, 0.5f, 0.5f, 0.5f);
2290 ok(hr == D3DRM_OK, "Cannot set emissive (hr = %x)\n", hr);
2291 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
2292 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2293 ok(r == 0.5f && g == 0.5f && b == 0.5f, "wrong emissive r=%f g=%f b=%f, expected r=0.5 g=0.5 b=0.5\n", r, g, b);
2295 hr = IDirect3DRMMaterial2_SetSpecular(material2, 0.6f, 0.6f, 0.6f);
2296 ok(hr == D3DRM_OK, "Cannot set specular (hr = %x)\n", hr);
2297 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
2298 ok(hr == D3DRM_OK, "Cannot get specular (hr = %x)\n", hr);
2299 ok(r == 0.6f && g == 0.6f && b == 0.6f, "wrong specular r=%f g=%f b=%f, expected r=0.6 g=0.6 b=0.6\n", r, g, b);
2301 hr = IDirect3DRMMaterial2_SetAmbient(material2, 0.7f, 0.7f, 0.7f);
2302 ok(hr == D3DRM_OK, "Cannot set ambient (hr = %x)\n", hr);
2303 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
2304 ok(hr == D3DRM_OK, "Cannot get ambient (hr = %x)\n", hr);
2305 ok(r == 0.7f && g == 0.7f && b == 0.7f, "wrong ambient r=%f g=%f b=%f, expected r=0.7 g=0.7 b=0.7\n", r, g, b);
2307 IDirect3DRMMaterial2_Release(material2);
2309 IDirect3DRM3_Release(d3drm3);
2310 IDirect3DRM_Release(d3drm);
2313 static void test_Texture(void)
2315 HRESULT hr;
2316 IDirect3DRM *d3drm1;
2317 IDirect3DRM2 *d3drm2;
2318 IDirect3DRM3 *d3drm3;
2319 IDirect3DRMTexture *texture1;
2320 IDirect3DRMTexture2 *texture2;
2321 IDirect3DRMTexture3 *texture3;
2322 IDirectDrawSurface *surface;
2324 D3DRMIMAGE initimg =
2326 2, 2, 1, 1, 32,
2327 TRUE, 2 * sizeof(DWORD), NULL, NULL,
2328 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0, NULL
2330 testimg =
2332 0, 0, 0, 0, 0,
2333 TRUE, 0, (void *)0xcafebabe, NULL,
2334 0x000000ff, 0x0000ff00, 0x00ff0000, 0, 0, NULL
2336 *d3drm_img = NULL;
2338 DWORD pixel[4] = { 20000, 30000, 10000, 0 };
2339 ULONG ref1, ref2, ref3, ref4;
2341 hr = Direct3DRMCreate(&d3drm1);
2342 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2343 ref1 = get_refcount((IUnknown *)d3drm1);
2345 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2346 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2348 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2349 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2351 /* Test NULL params */
2352 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
2353 hr = IDirect3DRM_CreateTexture(d3drm1, NULL, &texture1);
2354 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2355 ok(!texture1, "Expected texture returned == NULL, got %p.\n", texture1);
2356 hr = IDirect3DRM_CreateTexture(d3drm1, NULL, NULL);
2357 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2359 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
2360 hr = IDirect3DRM2_CreateTexture(d3drm2, NULL, &texture2);
2361 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2362 ok(!texture2, "Expected texture returned == NULL, got %p.\n", texture2);
2363 hr = IDirect3DRM2_CreateTexture(d3drm2, NULL, NULL);
2364 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2366 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
2367 hr = IDirect3DRM3_CreateTexture(d3drm3, NULL, &texture3);
2368 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2369 ok(!texture3, "Expected texture returned == NULL, got %p.\n", texture3);
2370 hr = IDirect3DRM3_CreateTexture(d3drm3, NULL, NULL);
2371 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2373 /* Tests for validation of D3DRMIMAGE struct */
2374 hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
2375 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2376 hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
2377 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2378 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
2379 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2380 IDirect3DRMTexture_Release(texture1);
2381 IDirect3DRMTexture2_Release(texture2);
2382 IDirect3DRMTexture3_Release(texture3);
2384 testimg.rgb = 0;
2385 testimg.palette = (void *)0xdeadbeef;
2386 testimg.palette_size = 0x39;
2387 hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
2388 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2389 hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
2390 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2391 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
2392 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2393 IDirect3DRMTexture_Release(texture1);
2394 IDirect3DRMTexture2_Release(texture2);
2395 IDirect3DRMTexture3_Release(texture3);
2397 initimg.rgb = 0;
2398 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
2399 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2400 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2401 ok(!texture1, "Expected texture == NULL, got %p.\n", texture1);
2402 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
2403 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2404 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2405 ok(!texture2, "Expected texture == NULL, got %p.\n", texture2);
2406 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
2407 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2408 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2409 ok(!texture3, "Expected texture == NULL, got %p.\n", texture3);
2410 initimg.rgb = 1;
2411 initimg.red_mask = 0;
2412 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2413 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2414 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2415 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2416 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2417 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2418 initimg.red_mask = 0x000000ff;
2419 initimg.green_mask = 0;
2420 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2421 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2422 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2423 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2424 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2425 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2426 initimg.green_mask = 0x0000ff00;
2427 initimg.blue_mask = 0;
2428 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2429 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2430 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2431 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2432 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2433 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2434 initimg.blue_mask = 0x00ff0000;
2435 initimg.buffer1 = NULL;
2436 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2437 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2438 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2439 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2440 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2441 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2443 initimg.buffer1 = &pixel;
2444 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2445 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2446 ref2 = get_refcount((IUnknown *)d3drm1);
2447 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2448 ref3 = get_refcount((IUnknown *)d3drm2);
2449 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2450 ref4 = get_refcount((IUnknown *)d3drm3);
2451 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2452 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2453 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2454 ref2 = get_refcount((IUnknown *)d3drm1);
2455 ok(ref2 > ref1 + 1, "expected ref2 > (ref1 + 1), got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2456 ref3 = get_refcount((IUnknown *)d3drm2);
2457 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2458 ref4 = get_refcount((IUnknown *)d3drm3);
2459 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2460 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2461 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2462 ref2 = get_refcount((IUnknown *)d3drm1);
2463 ok(ref2 > ref1 + 2, "expected ref2 > (ref1 + 2), got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2464 ref3 = get_refcount((IUnknown *)d3drm2);
2465 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2466 ref4 = get_refcount((IUnknown *)d3drm3);
2467 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2469 /* Created from image, GetSurface() does not work. */
2470 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, NULL);
2471 ok(hr == D3DRMERR_BADVALUE, "GetSurface() expected to fail, %#x\n", hr);
2473 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &surface);
2474 ok(hr == D3DRMERR_NOTCREATEDFROMDDS, "GetSurface() expected to fail, %#x\n", hr);
2476 /* Test all failures together */
2477 test_class_name((IDirect3DRMObject *)texture1, "Texture");
2478 test_class_name((IDirect3DRMObject *)texture2, "Texture");
2479 test_class_name((IDirect3DRMObject *)texture3, "Texture");
2480 test_object_name((IDirect3DRMObject *)texture1);
2481 test_object_name((IDirect3DRMObject *)texture2);
2482 test_object_name((IDirect3DRMObject *)texture3);
2484 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
2485 ok(!!d3drm_img, "Failed to get image.\n");
2486 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2488 IDirect3DRMTexture_Release(texture1);
2489 ref2 = get_refcount((IUnknown *)d3drm1);
2490 ok(ref2 - 2 == ref1, "expected (ref2 - 2) == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2491 ref3 = get_refcount((IUnknown *)d3drm2);
2492 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2493 ref4 = get_refcount((IUnknown *)d3drm3);
2494 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2496 d3drm_img = NULL;
2497 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
2498 ok(!!d3drm_img, "Failed to get image.\n");
2499 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2501 IDirect3DRMTexture2_Release(texture2);
2502 ref2 = get_refcount((IUnknown *)d3drm1);
2503 ok(ref2 - 1 == ref1, "expected (ref2 - 1) == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2504 ref3 = get_refcount((IUnknown *)d3drm2);
2505 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2506 ref4 = get_refcount((IUnknown *)d3drm3);
2507 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2509 d3drm_img = NULL;
2510 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
2511 ok(!!d3drm_img, "Failed to get image.\n");
2512 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2514 IDirect3DRMTexture3_Release(texture3);
2515 ref2 = get_refcount((IUnknown *)d3drm1);
2516 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2517 ref3 = get_refcount((IUnknown *)d3drm2);
2518 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2519 ref4 = get_refcount((IUnknown *)d3drm3);
2520 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2522 /* InitFromImage tests */
2523 /* Tests for validation of D3DRMIMAGE struct */
2524 testimg.rgb = 1;
2525 testimg.palette = NULL;
2526 testimg.palette_size = 0;
2527 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2528 (void **)&texture2);
2529 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2530 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2531 (void **)&texture3);
2532 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2533 hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
2534 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2535 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
2536 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2537 IDirect3DRMTexture2_Release(texture2);
2538 IDirect3DRMTexture3_Release(texture3);
2540 testimg.rgb = 0;
2541 testimg.palette = (void *)0xdeadbeef;
2542 testimg.palette_size = 0x39;
2543 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2544 (void **)&texture2);
2545 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2546 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2547 (void **)&texture3);
2548 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2549 hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
2550 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2551 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
2552 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2553 IDirect3DRMTexture2_Release(texture2);
2554 IDirect3DRMTexture3_Release(texture3);
2556 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2557 (void **)&texture2);
2558 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2559 ref2 = get_refcount((IUnknown *)texture2);
2560 hr = IDirect3DRMTexture2_InitFromImage(texture2, NULL);
2561 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2562 ref3 = get_refcount((IUnknown *)texture2);
2563 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2565 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2566 (void **)&texture3);
2567 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2568 ref2 = get_refcount((IUnknown *)texture3);
2569 hr = IDirect3DRMTexture3_InitFromImage(texture3, NULL);
2570 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2571 ref3 = get_refcount((IUnknown *)texture3);
2572 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2574 initimg.rgb = 0;
2575 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2576 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2577 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2578 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2579 initimg.rgb = 1;
2580 initimg.red_mask = 0;
2581 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2582 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2583 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2584 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2585 initimg.red_mask = 0x000000ff;
2586 initimg.green_mask = 0;
2587 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2588 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2589 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2590 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2591 initimg.green_mask = 0x0000ff00;
2592 initimg.blue_mask = 0;
2593 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2594 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2595 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2596 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2597 initimg.blue_mask = 0x00ff0000;
2598 initimg.buffer1 = NULL;
2599 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2600 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2601 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2602 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2603 initimg.buffer1 = &pixel;
2605 d3drm_img = NULL;
2606 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2607 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 from image (hr = %#x).\n", hr);
2608 ref2 = get_refcount((IUnknown *)d3drm1);
2609 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2610 ref3 = get_refcount((IUnknown *)d3drm2);
2611 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2612 ref4 = get_refcount((IUnknown *)d3drm3);
2613 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2615 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2616 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2617 /* Release leaked reference to d3drm1 */
2618 IDirect3DRM_Release(d3drm1);
2620 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
2621 ok(!!d3drm_img, "Failed to get image.\n");
2622 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2623 IDirect3DRMTexture2_Release(texture2);
2624 ref2 = get_refcount((IUnknown *)d3drm1);
2625 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2626 ref3 = get_refcount((IUnknown *)d3drm2);
2627 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2628 ref4 = get_refcount((IUnknown *)d3drm3);
2629 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2631 d3drm_img = NULL;
2632 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2633 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 from image (hr = %#x).\n", hr);
2634 ref2 = get_refcount((IUnknown *)d3drm1);
2635 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2636 ref3 = get_refcount((IUnknown *)d3drm2);
2637 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2638 ref4 = get_refcount((IUnknown *)d3drm3);
2639 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2641 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2642 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2643 IDirect3DRM_Release(d3drm1);
2645 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
2646 ok(!!d3drm_img, "Failed to get image.\n");
2647 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2648 IDirect3DRMTexture3_Release(texture3);
2649 ref2 = get_refcount((IUnknown *)d3drm1);
2650 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2651 ref3 = get_refcount((IUnknown *)d3drm2);
2652 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2653 ref4 = get_refcount((IUnknown *)d3drm3);
2654 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2656 IDirect3DRM3_Release(d3drm3);
2657 IDirect3DRM2_Release(d3drm2);
2658 IDirect3DRM_Release(d3drm1);
2661 static void test_Device(void)
2663 IDirectDrawClipper *pClipper;
2664 HRESULT hr;
2665 IDirect3DRM *d3drm;
2666 IDirect3DRMDevice *device;
2667 IDirect3DRMWinDevice *win_device;
2668 GUID driver;
2669 HWND window;
2670 RECT rc;
2672 window = create_window();
2673 GetClientRect(window, &rc);
2675 hr = Direct3DRMCreate(&d3drm);
2676 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2678 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
2679 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
2681 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
2682 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
2684 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
2685 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
2686 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
2688 test_class_name((IDirect3DRMObject *)device, "Device");
2689 test_object_name((IDirect3DRMObject *)device);
2691 /* WinDevice */
2692 if (FAILED(hr = IDirect3DRMDevice_QueryInterface(device, &IID_IDirect3DRMWinDevice, (void **)&win_device)))
2694 win_skip("Cannot get IDirect3DRMWinDevice interface (hr = %x), skipping tests\n", hr);
2695 goto cleanup;
2698 test_class_name((IDirect3DRMObject *)win_device, "Device");
2699 test_object_name((IDirect3DRMObject *)win_device);
2700 IDirect3DRMWinDevice_Release(win_device);
2702 cleanup:
2703 IDirect3DRMDevice_Release(device);
2704 IDirectDrawClipper_Release(pClipper);
2706 IDirect3DRM_Release(d3drm);
2707 DestroyWindow(window);
2710 static void test_frame_transform(void)
2712 HRESULT hr;
2713 IDirect3DRM *d3drm;
2714 IDirect3DRMFrame *frame;
2715 D3DRMMATRIX4D matrix;
2717 hr = Direct3DRMCreate(&d3drm);
2718 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2720 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
2721 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
2723 hr = IDirect3DRMFrame_GetTransform(frame, matrix);
2724 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetTransform returned hr = %x\n", hr);
2725 ok(!memcmp(matrix, identity, sizeof(D3DRMMATRIX4D)), "Returned matrix is not identity\n");
2727 IDirect3DRMFrame_Release(frame);
2728 IDirect3DRM_Release(d3drm);
2731 static int nb_objects = 0;
2732 static const GUID* refiids[] =
2734 &IID_IDirect3DRMMeshBuilder,
2735 &IID_IDirect3DRMMeshBuilder,
2736 &IID_IDirect3DRMFrame,
2737 &IID_IDirect3DRMMaterial /* Not taken into account and not notified */
2740 static void __cdecl object_load_callback(IDirect3DRMObject *object, REFIID objectguid, void *arg)
2742 ok(object != NULL, "Arg 1 should not be null\n");
2743 ok(IsEqualGUID(objectguid, refiids[nb_objects]), "Arg 2 is incorrect\n");
2744 ok(arg == (void *)0xdeadbeef, "Arg 3 should be 0xdeadbeef (got %p)\n", arg);
2745 nb_objects++;
2748 static void test_d3drm_load(void)
2750 HRESULT hr;
2751 IDirect3DRM *d3drm;
2752 D3DRMLOADMEMORY info;
2753 const GUID* req_refiids[] = { &IID_IDirect3DRMMeshBuilder, &IID_IDirect3DRMFrame, &IID_IDirect3DRMMaterial };
2755 hr = Direct3DRMCreate(&d3drm);
2756 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2758 info.lpMemory = data_d3drm_load;
2759 info.dSize = strlen(data_d3drm_load);
2760 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID **)req_refiids, 3, D3DRMLOAD_FROMMEMORY,
2761 object_load_callback, (void *)0xdeadbeef, NULL, NULL, NULL);
2762 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
2763 ok(nb_objects == 3, "Should have loaded 3 objects (got %d)\n", nb_objects);
2765 IDirect3DRM_Release(d3drm);
2768 IDirect3DRMMeshBuilder *mesh_builder = NULL;
2770 static void __cdecl object_load_callback_frame(IDirect3DRMObject *object, REFIID object_guid, void *arg)
2772 HRESULT hr;
2773 IDirect3DRMFrame *frame;
2774 IDirect3DRMVisualArray *array;
2775 IDirect3DRMVisual *visual;
2776 ULONG size;
2777 char name[128];
2779 hr = IDirect3DRMObject_QueryInterface(object, &IID_IDirect3DRMFrame, (void**)&frame);
2780 ok(hr == D3DRM_OK, "IDirect3DRMObject_QueryInterface returned %x\n", hr);
2782 hr = IDirect3DRMFrame_GetVisuals(frame, &array);
2783 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetVisuals returned %x\n", hr);
2785 size = IDirect3DRMVisualArray_GetSize(array);
2786 ok(size == 1, "Wrong size %u returned, expected 1\n", size);
2788 hr = IDirect3DRMVisualArray_GetElement(array, 0, &visual);
2789 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetElement returned %x\n", hr);
2791 hr = IDirect3DRMVisual_QueryInterface(visual, &IID_IDirect3DRMMeshBuilder, (void**)&mesh_builder);
2792 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetSize returned %x\n", hr);
2794 size = sizeof(name);
2795 hr = IDirect3DRMMeshBuilder_GetName(mesh_builder, &size, name);
2796 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned %x\n", hr);
2797 ok(!strcmp(name, "mesh1"), "Wrong name %s, expected mesh1\n", name);
2799 IDirect3DRMVisual_Release(visual);
2800 IDirect3DRMVisualArray_Release(array);
2801 IDirect3DRMFrame_Release(frame);
2804 struct {
2805 int vertex_count;
2806 int face_count;
2807 int vertex_per_face;
2808 int face_data_size;
2809 DWORD color;
2810 float power;
2811 float specular[3];
2812 float emissive[3];
2813 } groups[3] = {
2814 { 4, 3, 3, 9, 0x4c0000ff, 30.0f, { 0.31f, 0.32f, 0.33f }, { 0.34f, 0.35f, 0.36f } },
2815 { 4, 2, 3, 6, 0x3300ff00, 20.0f, { 0.21f, 0.22f, 0.23f }, { 0.24f, 0.25f, 0.26f } },
2816 { 3, 1, 3, 3, 0x19ff0000, 10.0f, { 0.11f, 0.12f, 0.13f }, { 0.14f, 0.15f, 0.16f } }
2819 static void test_frame_mesh_materials(void)
2821 HRESULT hr;
2822 IDirect3DRM *d3drm;
2823 D3DRMLOADMEMORY info;
2824 const GUID *req_refiids[] = { &IID_IDirect3DRMFrame };
2825 IDirect3DRMMesh *mesh;
2826 ULONG size;
2827 IDirect3DRMMaterial *material;
2828 IDirect3DRMTexture *texture;
2829 int i;
2831 hr = Direct3DRMCreate(&d3drm);
2832 ok(hr == D3DRM_OK, "Direct3DRMCreate returned %x\n", hr);
2834 info.lpMemory = data_frame_mesh_materials;
2835 info.dSize = strlen(data_frame_mesh_materials);
2836 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID**)req_refiids, 1, D3DRMLOAD_FROMMEMORY, object_load_callback_frame, (void*)0xdeadbeef, NULL, NULL, NULL);
2837 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
2839 hr = IDirect3DRMMeshBuilder_CreateMesh(mesh_builder, &mesh);
2840 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_CreateMesh returned %x\n", hr);
2842 size = IDirect3DRMMesh_GetGroupCount(mesh);
2843 ok(size == 3, "Wrong size %u returned, expected 3\n", size);
2845 for (i = 0; i < size; i++)
2847 D3DVALUE red, green, blue, power;
2848 D3DCOLOR color;
2849 unsigned vertex_count, face_count, vertex_per_face;
2850 DWORD face_data_size;
2852 hr = IDirect3DRMMesh_GetGroup(mesh, i, &vertex_count, &face_count, &vertex_per_face, &face_data_size, NULL);
2853 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroup returned %x\n", i, hr);
2854 ok(vertex_count == groups[i].vertex_count, "Group %d: Wrong vertex count %d, expected %d\n", i, vertex_count, groups[i].vertex_count);
2855 ok(face_count == groups[i].face_count, "Group %d: Wrong face count %d; expected %d\n", i, face_count, groups[i].face_count);
2856 ok(vertex_per_face == groups[i].vertex_per_face, "Group %d: Wrong vertex per face %d, expected %d\n", i, vertex_per_face, groups[i].vertex_per_face);
2857 ok(face_data_size == groups[i].face_data_size, "Group %d: Wrong face data size %d, expected %d\n", i, face_data_size, groups[i].face_data_size);
2859 color = IDirect3DRMMesh_GetGroupColor(mesh, i);
2860 ok(color == groups[i].color, "Group %d: Wrong color %x, expected %x\n", i, color, groups[i].color);
2862 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, i, &material);
2863 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupMaterial returned %x\n", i, hr);
2864 ok(material != NULL, "Group %d: No material\n", i);
2865 power = IDirect3DRMMaterial_GetPower(material);
2866 ok(power == groups[i].power, "Group %d: Wrong power %f, expected %f\n", i, power, groups[i].power);
2867 hr = IDirect3DRMMaterial_GetSpecular(material, &red, &green, &blue);
2868 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetSpecular returned %x\n", i, hr);
2869 ok(red == groups[i].specular[0], "Group %d: Wrong specular red %f, expected %f\n", i, red, groups[i].specular[0]);
2870 ok(green == groups[i].specular[1], "Group %d: Wrong specular green %f, pD3DRMexpected %f\n", i, green, groups[i].specular[1]);
2871 ok(blue == groups[i].specular[2], "Group %d: Wrong specular blue %f, expected %f\n", i, blue, groups[i].specular[2]);
2872 hr = IDirect3DRMMaterial_GetEmissive(material, &red, &green, &blue);
2873 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetEmissive returned %x\n", i, hr);
2874 ok(red == groups[i].emissive[0], "Group %d: Wrong emissive red %f, expected %f\n", i, red, groups[i].emissive[0]);
2875 ok(green == groups[i].emissive[1], "Group %d: Wrong emissive green %f, expected %f\n", i, green, groups[i].emissive[1]);
2876 ok(blue == groups[i].emissive[2], "Group %d: Wrong emissive blue %f, expected %f\n", i, blue, groups[i].emissive[2]);
2878 hr = IDirect3DRMMesh_GetGroupTexture(mesh, i, &texture);
2879 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupTexture returned %x\n", i, hr);
2880 ok(!texture, "Group %d: Unexpected texture\n", i);
2882 if (material)
2883 IDirect3DRMMaterial_Release(material);
2884 if (texture)
2885 IDirect3DRMTexture_Release(texture);
2888 IDirect3DRMMesh_Release(mesh);
2889 IDirect3DRMMeshBuilder_Release(mesh_builder);
2890 IDirect3DRM_Release(d3drm);
2893 struct qi_test
2895 REFIID iid;
2896 REFIID refcount_iid;
2897 REFIID vtable_iid;
2898 HRESULT hr;
2901 static void test_qi(const char *test_name, IUnknown *base_iface,
2902 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
2904 ULONG refcount, expected_refcount;
2905 IUnknown *iface1, *iface2;
2906 HRESULT hr;
2907 UINT i, j;
2909 for (i = 0; i < entry_count; ++i)
2911 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
2912 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
2913 if (SUCCEEDED(hr))
2915 for (j = 0; j < entry_count; ++j)
2917 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
2918 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
2919 if (SUCCEEDED(hr))
2921 expected_refcount = 0;
2922 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
2923 ++expected_refcount;
2924 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
2925 ++expected_refcount;
2926 refcount = IUnknown_Release(iface2);
2927 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2928 refcount, test_name, i, j, expected_refcount);
2929 if (tests[i].vtable_iid && tests[j].vtable_iid && IsEqualGUID(tests[i].vtable_iid, tests[j].vtable_iid))
2930 ok(iface1 == iface2,
2931 "Expected iface1 == iface2 for test \"%s\" %u, %u. Got iface1 = %p, iface 2 = %p.\n",
2932 test_name, i, j, iface1, iface2);
2933 else if (tests[i].vtable_iid && tests[j].vtable_iid)
2934 ok(iface1 != iface2,
2935 "Expected iface1 != iface2 for test \"%s\" %u, %u. Got iface1 == iface2 == %p.\n",
2936 test_name, i, j, iface1);
2940 expected_refcount = 0;
2941 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
2942 ++expected_refcount;
2943 refcount = IUnknown_Release(iface1);
2944 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2945 refcount, test_name, i, expected_refcount);
2950 static void test_d3drm_qi(void)
2952 static const struct qi_test tests[] =
2954 { &IID_IDirect3DRM3, &IID_IDirect3DRM3, &IID_IDirect3DRM3, S_OK },
2955 { &IID_IDirect3DRM2, &IID_IDirect3DRM2, &IID_IDirect3DRM2, S_OK },
2956 { &IID_IDirect3DRM, &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK },
2957 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2958 { &IID_IDirect3DRMObject, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2959 { &IID_IDirect3DRMObject2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2960 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2961 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2962 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2963 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2964 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2965 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2966 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2967 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2968 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2969 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2970 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2971 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2972 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2973 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2974 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2975 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2976 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2977 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2978 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2979 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2980 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2981 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2982 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2983 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2984 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2985 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2986 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2987 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2988 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2989 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2990 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2991 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2992 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2993 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2994 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2995 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2996 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2997 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2998 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2999 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3000 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3001 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3002 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3003 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3004 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3005 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3006 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3007 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3008 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3009 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3010 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3011 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3012 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3013 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3014 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3015 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3016 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3017 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3018 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3019 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3020 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3021 { &IID_IUnknown, &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK },
3023 HRESULT hr;
3024 IDirect3DRM *d3drm;
3026 hr = Direct3DRMCreate(&d3drm);
3027 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
3029 test_qi("d3drm_qi", (IUnknown *)d3drm, &IID_IDirect3DRM, tests, sizeof(tests) / sizeof(*tests));
3031 IDirect3DRM_Release(d3drm);
3034 static void test_frame_qi(void)
3036 static const struct qi_test tests[] =
3038 { &IID_IDirect3DRMFrame3, &IID_IUnknown, &IID_IDirect3DRMFrame3, S_OK },
3039 { &IID_IDirect3DRMFrame2, &IID_IUnknown, &IID_IDirect3DRMFrame2, S_OK },
3040 { &IID_IDirect3DRMFrame, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
3041 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3042 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3043 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
3044 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3045 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3046 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3047 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3048 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3049 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3050 { &IID_IDirect3DRMVisual, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
3051 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3052 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3053 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3054 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3055 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3056 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3057 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3058 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3059 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3060 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3061 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3062 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3063 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3064 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3065 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3066 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3067 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3068 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3069 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3070 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3071 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3072 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3073 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3074 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3075 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3076 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3077 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3078 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3079 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3080 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3081 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3082 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3083 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3084 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3085 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3086 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3087 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3088 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3089 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3090 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3091 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3092 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3093 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3094 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3095 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3096 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3097 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3098 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3099 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3100 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3101 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3102 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3103 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3104 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK },
3106 HRESULT hr;
3107 IDirect3DRM *d3drm1;
3108 IDirect3DRM2 *d3drm2;
3109 IDirect3DRM3 *d3drm3;
3110 IDirect3DRMFrame *frame1;
3111 IDirect3DRMFrame2 *frame2;
3112 IDirect3DRMFrame3 *frame3;
3113 IUnknown *unknown;
3115 hr = Direct3DRMCreate(&d3drm1);
3116 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
3118 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
3119 ok(hr == D3DRM_OK, "Failed to create frame1 (hr = %x)\n", hr);
3120 hr = IDirect3DRMFrame_QueryInterface(frame1, &IID_IUnknown, (void **)&unknown);
3121 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame1 (hr = %x)\n", hr);
3122 IDirect3DRMFrame_Release(frame1);
3123 test_qi("frame1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3124 IUnknown_Release(unknown);
3126 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3127 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3128 hr = IDirect3DRM2_CreateFrame(d3drm2, NULL, &frame2);
3129 ok(hr == D3DRM_OK, "Failed to create frame2 (hr = %x)\n", hr);
3130 hr = IDirect3DRMFrame2_QueryInterface(frame2, &IID_IUnknown, (void **)&unknown);
3131 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame2 (hr = %x)\n", hr);
3132 IDirect3DRMFrame2_Release(frame2);
3133 test_qi("frame2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3134 IUnknown_Release(unknown);
3136 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3137 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3138 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
3139 ok(hr == D3DRM_OK, "Failed to create frame3 (hr = %x)\n", hr);
3140 hr = IDirect3DRMFrame3_QueryInterface(frame3, &IID_IUnknown, (void **)&unknown);
3141 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame3 (hr = %x)\n", hr);
3142 IDirect3DRMFrame3_Release(frame3);
3143 test_qi("frame3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3144 IUnknown_Release(unknown);
3146 IDirect3DRM3_Release(d3drm3);
3147 IDirect3DRM2_Release(d3drm2);
3148 IDirect3DRM_Release(d3drm1);
3151 static void test_device_qi(void)
3153 static const struct qi_test tests[] =
3155 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3156 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3157 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3158 { &IID_IDirect3DRMDevice, &IID_IUnknown, &IID_IDirect3DRMDevice, S_OK, },
3159 { &IID_IDirect3DRMDevice2, &IID_IUnknown, &IID_IDirect3DRMDevice2, S_OK, },
3160 { &IID_IDirect3DRMDevice3, &IID_IUnknown, &IID_IDirect3DRMDevice3, S_OK, },
3161 { &IID_IDirect3DRMWinDevice, &IID_IUnknown, &IID_IDirect3DRMWinDevice, S_OK, },
3162 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMDevice, S_OK, },
3163 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3164 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3165 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3166 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3167 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3168 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3169 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3170 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3171 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3172 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3173 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3174 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3175 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3176 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3177 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3178 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3179 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3180 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3181 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3182 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3183 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3184 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3185 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3186 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3187 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3188 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3189 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3190 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3191 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3192 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3193 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3194 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3195 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3196 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3197 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3198 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3199 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3200 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3201 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3202 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3203 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3204 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3205 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3206 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3207 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3208 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3209 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3210 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3211 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3212 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3213 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3214 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3215 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3216 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3217 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3218 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3219 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3220 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3221 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3222 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
3224 HRESULT hr;
3225 IDirect3DRM *d3drm1;
3226 IDirect3DRM2 *d3drm2;
3227 IDirect3DRM3 *d3drm3;
3228 IDirectDrawClipper *clipper;
3229 IDirect3DRMDevice *device1;
3230 IDirect3DRMDevice2 *device2;
3231 IDirect3DRMDevice3 *device3;
3232 IUnknown *unknown;
3233 HWND window;
3234 GUID driver;
3235 RECT rc;
3237 window = create_window();
3238 GetClientRect(window, &rc);
3239 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3240 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
3241 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3242 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
3244 hr = Direct3DRMCreate(&d3drm1);
3245 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
3246 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
3247 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
3248 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
3249 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IUnknown, (void **)&unknown);
3250 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice (hr = %x)\n", hr);
3251 IDirect3DRMDevice_Release(device1);
3252 test_qi("device1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3253 IUnknown_Release(unknown);
3255 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3256 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3257 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
3258 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %x)\n", hr);
3259 hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IUnknown, (void **)&unknown);
3260 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice2 (hr = %x)\n", hr);
3261 IDirect3DRMDevice2_Release(device2);
3262 test_qi("device2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3263 IUnknown_Release(unknown);
3265 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3266 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3267 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
3268 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
3269 IDirect3DRMDevice3_QueryInterface(device3, &IID_IUnknown, (void **)&unknown);
3270 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice3 (hr = %x)\n", hr);
3271 IDirect3DRMDevice3_Release(device3);
3272 test_qi("device3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3273 IUnknown_Release(unknown);
3275 IDirectDrawClipper_Release(clipper);
3276 IDirect3DRM3_Release(d3drm3);
3277 IDirect3DRM2_Release(d3drm2);
3278 IDirect3DRM_Release(d3drm1);
3279 DestroyWindow(window);
3283 static HRESULT CALLBACK surface_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
3285 IDirectDrawSurface **primary = context;
3287 if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
3289 *primary = surface;
3290 return DDENUMRET_CANCEL;
3292 IDirectDrawSurface_Release(surface);
3294 return DDENUMRET_OK;
3297 static void test_create_device_from_clipper1(void)
3299 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3300 IDirect3DRM *d3drm1 = NULL;
3301 IDirectDraw *ddraw = NULL;
3302 IUnknown *unknown = NULL;
3303 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3304 IDirect3DDevice *d3ddevice1 = NULL;
3305 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3306 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3307 IDirectDrawSurface7 *surface7 = NULL;
3308 DDSURFACEDESC desc, surface_desc;
3309 DWORD expected_flags, ret_val;
3310 HWND window;
3311 GUID driver = IID_IDirect3DRGBDevice;
3312 HRESULT hr;
3313 ULONG ref1, ref2, cref1, cref2;
3314 RECT rc;
3316 window = create_window();
3317 GetClientRect(window, &rc);
3318 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3319 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3320 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3321 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3323 hr = Direct3DRMCreate(&d3drm1);
3324 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3325 ref1 = get_refcount((IUnknown *)d3drm1);
3326 cref1 = get_refcount((IUnknown *)clipper);
3328 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 0, 0, &device1);
3329 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3330 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3332 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3333 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, NULL, &driver, 300, 200, &device1);
3334 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3336 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, NULL);
3337 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3339 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, &device1);
3340 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3341 ref2 = get_refcount((IUnknown *)d3drm1);
3342 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3343 cref2 = get_refcount((IUnknown *)clipper);
3344 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3345 ret_val = IDirect3DRMDevice_GetWidth(device1);
3346 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3347 ret_val = IDirect3DRMDevice_GetHeight(device1);
3348 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3350 /* Fetch immediate mode device in order to access render target */
3351 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3352 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3354 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
3355 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3357 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3358 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3360 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3361 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3362 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3363 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3364 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3365 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3366 IUnknown_Release(unknown);
3367 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3368 NULL, &d3drm_primary, surface_callback);
3369 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3370 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3371 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3372 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3373 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3375 IDirectDrawClipper_Release(d3drm_clipper);
3376 IDirectDrawSurface_Release(d3drm_primary);
3377 IDirectDrawSurface7_Release(surface7);
3378 IDirectDraw_Release(ddraw);
3380 /* Check properties of render target and depth surface */
3381 surface_desc.dwSize = sizeof(surface_desc);
3382 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3383 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3385 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3386 surface_desc.dwWidth, surface_desc.dwHeight);
3387 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3388 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3389 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3390 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3392 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3393 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3394 desc.dwSize = sizeof(desc);
3395 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3396 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3397 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3398 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3400 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3401 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3403 desc.dwSize = sizeof(desc);
3404 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3405 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3407 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3408 desc.dwWidth, desc.dwHeight);
3409 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3410 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3411 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3412 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3413 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3415 /* Release old objects and check refcount of device and clipper */
3416 IDirectDrawSurface_Release(ds);
3417 ds = NULL;
3418 IDirectDrawSurface_Release(surface);
3419 surface = NULL;
3420 IDirect3DDevice_Release(d3ddevice1);
3421 d3ddevice1 = NULL;
3422 IDirect3DRMDevice_Release(device1);
3423 ref2 = get_refcount((IUnknown *)d3drm1);
3424 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
3425 cref2 = get_refcount((IUnknown *)clipper);
3426 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3428 /* Test if render target format follows the screen format */
3429 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3430 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3431 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3432 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3434 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3435 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3436 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3438 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
3439 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3441 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3442 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3444 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
3445 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3447 surface_desc.dwSize = sizeof(surface_desc);
3448 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3449 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3450 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3451 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3453 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3454 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3456 if (ds)
3457 IDirectDrawSurface_Release(ds);
3458 IDirectDrawSurface_Release(surface);
3459 IDirect3DDevice_Release(d3ddevice1);
3460 IDirect3DRMDevice_Release(device1);
3461 IDirect3DRM_Release(d3drm1);
3462 IDirectDrawClipper_Release(clipper);
3463 IDirectDraw_Release(ddraw);
3464 DestroyWindow(window);
3467 static void test_create_device_from_clipper2(void)
3469 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3470 IDirect3DRM *d3drm1 = NULL;
3471 IDirect3DRM2 *d3drm2 = NULL;
3472 IDirectDraw *ddraw = NULL;
3473 IUnknown *unknown = NULL;
3474 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
3475 IDirect3DDevice2 *d3ddevice2 = NULL;
3476 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3477 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3478 IDirectDrawSurface7 *surface7 = NULL;
3479 DDSURFACEDESC desc, surface_desc;
3480 DWORD expected_flags, ret_val;
3481 HWND window;
3482 GUID driver = IID_IDirect3DRGBDevice;
3483 HRESULT hr;
3484 ULONG ref1, ref2, ref3, cref1, cref2;
3485 RECT rc;
3487 window = create_window();
3488 GetClientRect(window, &rc);
3489 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3490 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3491 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3492 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3494 hr = Direct3DRMCreate(&d3drm1);
3495 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3496 ref1 = get_refcount((IUnknown *)d3drm1);
3497 cref1 = get_refcount((IUnknown *)clipper);
3499 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3500 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3501 ref2 = get_refcount((IUnknown *)d3drm2);
3503 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 0, 0, &device2);
3504 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3505 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
3507 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3508 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, NULL, &driver, 300, 200, &device2);
3509 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3511 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, NULL);
3512 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3514 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, &device2);
3515 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3516 ref3 = get_refcount((IUnknown *)d3drm1);
3517 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3518 ref3 = get_refcount((IUnknown *)d3drm2);
3519 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3520 cref2 = get_refcount((IUnknown *)clipper);
3521 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3522 ret_val = IDirect3DRMDevice2_GetWidth(device2);
3523 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3524 ret_val = IDirect3DRMDevice2_GetHeight(device2);
3525 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3527 /* Fetch immediate mode device in order to access render target */
3528 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3529 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3531 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3532 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3534 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3535 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3537 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3538 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3539 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3540 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3541 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3542 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3543 IUnknown_Release(unknown);
3544 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3545 NULL, &d3drm_primary, surface_callback);
3546 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3547 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3548 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3549 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3550 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3552 IDirectDrawClipper_Release(d3drm_clipper);
3553 IDirectDrawSurface_Release(d3drm_primary);
3554 IDirectDrawSurface7_Release(surface7);
3555 IDirectDraw_Release(ddraw);
3557 /* Check properties of render target and depth surface */
3558 surface_desc.dwSize = sizeof(surface_desc);
3559 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3560 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3562 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3563 surface_desc.dwWidth, surface_desc.dwHeight);
3564 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3565 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3566 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3567 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3569 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3570 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3571 desc.dwSize = sizeof(desc);
3572 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3573 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3574 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3575 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3577 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3578 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3580 desc.dwSize = sizeof(desc);
3581 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3582 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3584 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3585 desc.dwWidth, desc.dwHeight);
3586 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3587 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3588 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3589 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3590 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3592 /* Release old objects and check refcount of device and clipper */
3593 IDirectDrawSurface_Release(ds);
3594 ds = NULL;
3595 IDirectDrawSurface_Release(surface);
3596 surface = NULL;
3597 IDirect3DDevice2_Release(d3ddevice2);
3598 d3ddevice2 = NULL;
3599 IDirect3DRMDevice2_Release(device2);
3600 ref3 = get_refcount((IUnknown *)d3drm1);
3601 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3602 ref3 = get_refcount((IUnknown *)d3drm2);
3603 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3604 cref2 = get_refcount((IUnknown *)clipper);
3605 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3607 /* Test if render target format follows the screen format */
3608 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3609 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3610 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3611 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3613 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3614 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3615 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3617 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
3618 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3620 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3621 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3623 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3624 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3626 surface_desc.dwSize = sizeof(surface_desc);
3627 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3628 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3629 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3630 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3632 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3633 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3635 IDirectDrawSurface_Release(surface);
3636 IDirect3DDevice2_Release(d3ddevice2);
3637 IDirect3DRMDevice2_Release(device2);
3638 IDirect3DRM2_Release(d3drm2);
3639 IDirect3DRM_Release(d3drm1);
3640 IDirectDrawClipper_Release(clipper);
3641 IDirectDraw_Release(ddraw);
3642 DestroyWindow(window);
3645 static void test_create_device_from_clipper3(void)
3647 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3648 IDirect3DRM *d3drm1 = NULL;
3649 IDirect3DRM3 *d3drm3 = NULL;
3650 IDirectDraw *ddraw = NULL;
3651 IUnknown *unknown = NULL;
3652 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
3653 IDirect3DDevice2 *d3ddevice2 = NULL;
3654 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3655 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3656 IDirectDrawSurface7 *surface7 = NULL;
3657 DDSURFACEDESC desc, surface_desc;
3658 DWORD expected_flags, ret_val;
3659 HWND window;
3660 GUID driver = IID_IDirect3DRGBDevice;
3661 HRESULT hr;
3662 ULONG ref1, ref2, ref3, cref1, cref2;
3663 RECT rc;
3665 window = create_window();
3666 GetClientRect(window, &rc);
3667 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3668 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3669 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3670 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3672 hr = Direct3DRMCreate(&d3drm1);
3673 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3674 ref1 = get_refcount((IUnknown *)d3drm1);
3675 cref1 = get_refcount((IUnknown *)clipper);
3677 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3678 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3679 ref2 = get_refcount((IUnknown *)d3drm3);
3681 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 0, 0, &device3);
3682 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3683 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
3685 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3686 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, NULL, &driver, 300, 200, &device3);
3687 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3689 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, NULL);
3690 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3692 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, &device3);
3693 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3694 ref3 = get_refcount((IUnknown *)d3drm1);
3695 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3696 ref3 = get_refcount((IUnknown *)d3drm3);
3697 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3698 cref2 = get_refcount((IUnknown *)clipper);
3699 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3700 ret_val = IDirect3DRMDevice3_GetWidth(device3);
3701 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3702 ret_val = IDirect3DRMDevice3_GetHeight(device3);
3703 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3705 /* Fetch immediate mode device in order to access render target */
3706 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3707 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3709 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3710 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3712 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3713 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3715 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3716 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3717 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3718 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3719 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3720 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3721 IUnknown_Release(unknown);
3722 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3723 NULL, &d3drm_primary, surface_callback);
3724 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3725 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3726 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3727 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3728 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3730 IDirectDrawClipper_Release(d3drm_clipper);
3731 IDirectDrawSurface_Release(d3drm_primary);
3732 IDirectDrawSurface7_Release(surface7);
3733 IDirectDraw_Release(ddraw);
3735 /* Check properties of render target and depth surface */
3736 surface_desc.dwSize = sizeof(surface_desc);
3737 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3738 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3740 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3741 surface_desc.dwWidth, surface_desc.dwHeight);
3742 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3743 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3744 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3745 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3747 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3748 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3749 desc.dwSize = sizeof(desc);
3750 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3751 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3752 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3753 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3755 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3756 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3758 desc.dwSize = sizeof(desc);
3759 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3760 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3762 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3763 desc.dwWidth, desc.dwHeight);
3764 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3765 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3766 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3767 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3768 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3770 /* Release old objects and check refcount of device and clipper */
3771 IDirectDrawSurface_Release(ds);
3772 ds = NULL;
3773 IDirectDrawSurface_Release(surface);
3774 surface = NULL;
3775 IDirect3DDevice2_Release(d3ddevice2);
3776 d3ddevice2 = NULL;
3777 IDirect3DRMDevice3_Release(device3);
3778 ref3 = get_refcount((IUnknown *)d3drm1);
3779 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3780 ref3 = get_refcount((IUnknown *)d3drm3);
3781 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3782 cref2 = get_refcount((IUnknown *)clipper);
3783 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3785 /* Test if render target format follows the screen format */
3786 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3787 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3788 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3789 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3791 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3792 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3793 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3795 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
3796 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3798 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3799 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3801 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3802 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3804 surface_desc.dwSize = sizeof(surface_desc);
3805 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3806 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3807 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3808 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3810 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3811 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3813 IDirectDrawSurface_Release(surface);
3814 IDirect3DDevice2_Release(d3ddevice2);
3815 IDirect3DRMDevice3_Release(device3);
3816 IDirect3DRM3_Release(d3drm3);
3817 IDirect3DRM_Release(d3drm1);
3818 IDirectDrawClipper_Release(clipper);
3819 IDirectDraw_Release(ddraw);
3820 DestroyWindow(window);
3823 static void test_create_device_from_surface1(void)
3825 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3826 DDSURFACEDESC desc;
3827 IDirectDraw *ddraw = NULL;
3828 IDirect3DRM *d3drm1 = NULL;
3829 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3830 IDirect3DDevice *d3ddevice1 = NULL;
3831 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
3832 DWORD expected_flags, ret_val;
3833 HWND window;
3834 GUID driver = IID_IDirect3DRGBDevice;
3835 ULONG ref1, ref2, surface_ref1, surface_ref2;
3836 RECT rc;
3837 BOOL use_sysmem_zbuffer = FALSE;
3838 HRESULT hr;
3840 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3841 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3843 window = create_window();
3844 GetClientRect(window, &rc);
3846 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3847 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3849 hr = Direct3DRMCreate(&d3drm1);
3850 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3851 ref1 = get_refcount((IUnknown *)d3drm1);
3853 /* Create a surface and use it to create the retained mode device. */
3854 memset(&desc, 0, sizeof(desc));
3855 desc.dwSize = sizeof(desc);
3856 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3857 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3858 desc.dwWidth = rc.right;
3859 desc.dwHeight = rc.bottom;
3861 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3862 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3864 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3865 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
3866 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3867 IDirectDrawSurface_Release(surface);
3869 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
3870 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3871 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3872 surface_ref1 = get_refcount((IUnknown *)surface);
3874 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, NULL);
3875 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
3876 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, NULL, &device1);
3877 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3878 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, NULL, surface, &device1);
3879 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3881 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3882 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3883 ref2 = get_refcount((IUnknown *)d3drm1);
3884 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3885 surface_ref2 = get_refcount((IUnknown *)surface);
3886 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
3887 ret_val = IDirect3DRMDevice_GetWidth(device1);
3888 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
3889 ret_val = IDirect3DRMDevice_GetHeight(device1);
3890 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
3892 /* Check if CreateDeviceFromSurface creates a primary surface */
3893 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3894 NULL, &d3drm_surface, surface_callback);
3895 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3896 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
3898 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3899 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3901 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
3902 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3903 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3905 /* Check properties of attached depth surface */
3906 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
3907 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3909 memset(&desc, 0, sizeof(desc));
3910 desc.dwSize = sizeof(desc);
3911 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3912 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3914 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
3915 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3916 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3917 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3918 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3919 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3921 IDirectDrawSurface_Release(ds);
3922 IDirect3DDevice_Release(d3ddevice1);
3923 IDirectDrawSurface_Release(d3drm_surface);
3925 IDirect3DRMDevice_Release(device1);
3926 ref2 = get_refcount((IUnknown *)d3drm1);
3927 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
3928 surface_ref2 = get_refcount((IUnknown *)surface);
3929 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
3930 surface_ref1, surface_ref2);
3931 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3932 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3933 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3934 ref1 = IDirectDrawSurface_Release(ds);
3935 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3936 ref1 = IDirectDrawSurface_Release(surface);
3937 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3939 memset(&desc, 0, sizeof(desc));
3940 desc.dwSize = sizeof(desc);
3941 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3942 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3943 desc.dwWidth = rc.right;
3944 desc.dwHeight = rc.bottom;
3946 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3947 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3949 memset(&desc, 0, sizeof(desc));
3950 desc.dwSize = sizeof(desc);
3951 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3952 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
3953 desc.dwZBufferBitDepth = 16;
3954 desc.dwWidth = rc.right;
3955 desc.dwHeight = rc.bottom;
3956 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
3957 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
3958 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
3959 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3961 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3962 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3964 hr = IDirect3DRMDevice2_GetDirect3DDevice(device1, &d3ddevice1);
3965 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3967 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
3968 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3969 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3971 /* Check if depth surface matches the one we created */
3972 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3973 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3974 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3976 IDirectDrawSurface_Release(d3drm_ds);
3977 IDirectDrawSurface_Release(d3drm_surface);
3978 IDirectDrawSurface_Release(ds);
3980 IDirect3DDevice_Release(d3ddevice1);
3981 IDirect3DRMDevice_Release(device1);
3982 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3983 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3984 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3985 ref1 = IDirectDrawSurface_Release(ds);
3986 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3987 ref1 = IDirectDrawSurface_Release(surface);
3988 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3989 IDirect3DRM_Release(d3drm1);
3990 IDirectDraw_Release(ddraw);
3991 DestroyWindow(window);
3994 static void test_create_device_from_surface2(void)
3996 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3997 DDSURFACEDESC desc;
3998 IDirectDraw *ddraw = NULL;
3999 IDirect3DRM *d3drm1 = NULL;
4000 IDirect3DRM2 *d3drm2 = NULL;
4001 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
4002 IDirect3DDevice2 *d3ddevice2 = NULL;
4003 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
4004 DWORD expected_flags, ret_val;
4005 HWND window;
4006 GUID driver = IID_IDirect3DRGBDevice;
4007 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
4008 RECT rc;
4009 BOOL use_sysmem_zbuffer = FALSE;
4010 HRESULT hr;
4012 hr = DirectDrawCreate(NULL, &ddraw, NULL);
4013 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4015 window = create_window();
4016 GetClientRect(window, &rc);
4018 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4019 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4021 hr = Direct3DRMCreate(&d3drm1);
4022 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4023 ref1 = get_refcount((IUnknown *)d3drm1);
4025 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
4026 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
4027 ref2 = get_refcount((IUnknown *)d3drm2);
4029 /* Create a surface and use it to create the retained mode device. */
4030 memset(&desc, 0, sizeof(desc));
4031 desc.dwSize = sizeof(desc);
4032 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4033 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4034 desc.dwWidth = rc.right;
4035 desc.dwHeight = rc.bottom;
4037 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4038 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4040 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
4041 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
4042 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
4043 IDirectDrawSurface_Release(surface);
4045 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
4046 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4047 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4048 surface_ref1 = get_refcount((IUnknown *)surface);
4050 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, NULL);
4051 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
4052 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, NULL, &device2);
4053 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4054 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, NULL, surface, &device2);
4055 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4057 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
4058 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
4059 ref3 = get_refcount((IUnknown *)d3drm1);
4060 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4061 ref3 = get_refcount((IUnknown *)d3drm2);
4062 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4063 surface_ref2 = get_refcount((IUnknown *)surface);
4064 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
4065 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4066 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4067 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4068 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4070 /* Check if CreateDeviceFromSurface creates a primary surface */
4071 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4072 NULL, &d3drm_surface, surface_callback);
4073 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4074 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
4076 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4077 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4079 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4080 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4081 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4083 /* Check properties of attached depth surface */
4084 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
4085 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4087 memset(&desc, 0, sizeof(desc));
4088 desc.dwSize = sizeof(desc);
4089 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4090 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4092 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4093 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4094 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4095 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4096 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4097 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4099 IDirectDrawSurface_Release(ds);
4100 IDirect3DDevice2_Release(d3ddevice2);
4101 IDirectDrawSurface_Release(d3drm_surface);
4103 IDirect3DRMDevice2_Release(device2);
4104 ref3 = get_refcount((IUnknown *)d3drm1);
4105 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4106 ref3 = get_refcount((IUnknown *)d3drm2);
4107 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4108 surface_ref2 = get_refcount((IUnknown *)surface);
4109 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
4110 surface_ref1, surface_ref2);
4111 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4112 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4113 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4114 ref1 = IDirectDrawSurface_Release(ds);
4115 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4117 ref1 = IDirectDrawSurface_Release(surface);
4118 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4120 memset(&desc, 0, sizeof(desc));
4121 desc.dwSize = sizeof(desc);
4122 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4123 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4124 desc.dwWidth = rc.right;
4125 desc.dwHeight = rc.bottom;
4127 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4128 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4130 memset(&desc, 0, sizeof(desc));
4131 desc.dwSize = sizeof(desc);
4132 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4133 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
4134 desc.dwZBufferBitDepth = 16;
4135 desc.dwWidth = rc.right;
4136 desc.dwHeight = rc.bottom;
4137 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
4138 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
4139 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
4140 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4142 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
4143 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
4145 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4146 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4148 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4149 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4150 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4152 /* Check if depth surface matches the one we created */
4153 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4154 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4155 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4157 IDirectDrawSurface_Release(d3drm_ds);
4158 IDirectDrawSurface_Release(d3drm_surface);
4159 IDirectDrawSurface_Release(ds);
4161 IDirect3DDevice2_Release(d3ddevice2);
4162 IDirect3DRMDevice2_Release(device2);
4163 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4164 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4165 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4166 ref1 = IDirectDrawSurface_Release(ds);
4167 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4168 ref1 = IDirectDrawSurface_Release(surface);
4169 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4170 IDirect3DRM2_Release(d3drm2);
4171 IDirect3DRM_Release(d3drm1);
4172 IDirectDraw_Release(ddraw);
4173 DestroyWindow(window);
4176 static void test_create_device_from_surface3(void)
4178 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4179 DDSURFACEDESC desc;
4180 IDirectDraw *ddraw = NULL;
4181 IDirect3DRM *d3drm1 = NULL;
4182 IDirect3DRM3 *d3drm3 = NULL;
4183 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
4184 IDirect3DDevice2 *d3ddevice2 = NULL;
4185 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
4186 DWORD expected_flags, ret_val;
4187 HWND window;
4188 GUID driver = IID_IDirect3DRGBDevice;
4189 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
4190 RECT rc;
4191 BOOL use_sysmem_zbuffer = FALSE;
4192 HRESULT hr;
4194 hr = DirectDrawCreate(NULL, &ddraw, NULL);
4195 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4197 window = create_window();
4198 GetClientRect(window, &rc);
4200 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4201 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4203 hr = Direct3DRMCreate(&d3drm1);
4204 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4205 ref1 = get_refcount((IUnknown *)d3drm1);
4207 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
4208 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
4209 ref2 = get_refcount((IUnknown *)d3drm3);
4211 /* Create a surface and use it to create the retained mode device. */
4212 memset(&desc, 0, sizeof(desc));
4213 desc.dwSize = sizeof(desc);
4214 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4215 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4216 desc.dwWidth = rc.right;
4217 desc.dwHeight = rc.bottom;
4219 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4220 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4222 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4223 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
4224 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
4225 IDirectDrawSurface_Release(surface);
4227 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
4228 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4229 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4230 surface_ref1 = get_refcount((IUnknown *)surface);
4232 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, NULL);
4233 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
4234 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, NULL, 0, &device3);
4235 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4236 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, NULL, surface, 0, &device3);
4237 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4239 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4240 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4241 ref3 = get_refcount((IUnknown *)d3drm1);
4242 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4243 ref3 = get_refcount((IUnknown *)d3drm3);
4244 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4245 surface_ref2 = get_refcount((IUnknown *)surface);
4246 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
4247 ret_val = IDirect3DRMDevice3_GetWidth(device3);
4248 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4249 ret_val = IDirect3DRMDevice3_GetHeight(device3);
4250 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4252 /* Check if CreateDeviceFromSurface creates a primary surface */
4253 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4254 NULL, &d3drm_surface, surface_callback);
4255 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4256 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
4258 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4259 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4261 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4262 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4263 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4265 /* Check properties of attached depth surface */
4266 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
4267 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4269 memset(&desc, 0, sizeof(desc));
4270 desc.dwSize = sizeof(desc);
4271 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4272 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4274 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4275 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4276 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4277 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4278 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4279 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4281 IDirectDrawSurface_Release(ds);
4282 IDirect3DDevice2_Release(d3ddevice2);
4283 IDirectDrawSurface_Release(d3drm_surface);
4284 IDirect3DRMDevice3_Release(device3);
4286 ref3 = get_refcount((IUnknown *)d3drm1);
4287 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4288 ref3 = get_refcount((IUnknown *)d3drm3);
4289 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4290 surface_ref2 = get_refcount((IUnknown *)surface);
4291 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
4292 surface_ref1, surface_ref2);
4293 /* In version 3, d3drm will destroy all references of the depth surface it created internally. */
4294 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4295 todo_wine ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x.\n", hr);
4296 if (SUCCEEDED(hr))
4297 IDirectDrawSurface_Release(ds);
4298 ref1 = IDirectDrawSurface_Release(surface);
4299 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4301 memset(&desc, 0, sizeof(desc));
4302 desc.dwSize = sizeof(desc);
4303 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4304 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4305 desc.dwWidth = rc.right;
4306 desc.dwHeight = rc.bottom;
4308 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4309 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4311 memset(&desc, 0, sizeof(desc));
4312 desc.dwSize = sizeof(desc);
4313 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4314 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
4315 desc.dwZBufferBitDepth = 16;
4316 desc.dwWidth = rc.right;
4317 desc.dwHeight = rc.bottom;
4318 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
4319 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
4320 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
4321 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4323 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
4324 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4326 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4327 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4329 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4330 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4331 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4333 /* Check if depth surface matches the one we created */
4334 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4335 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4336 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4338 IDirectDrawSurface_Release(d3drm_ds);
4339 IDirectDrawSurface_Release(d3drm_surface);
4340 IDirectDrawSurface_Release(ds);
4341 IDirect3DDevice2_Release(d3ddevice2);
4342 IDirect3DRMDevice3_Release(device3);
4343 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4344 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4345 /* The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4346 ref1 = IDirectDrawSurface_Release(ds);
4347 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4349 /* What happens if we pass no flags and still attach our own depth surface? */
4350 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4351 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4353 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4354 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4356 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4357 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4358 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4360 /* Check if depth surface matches the one we created */
4361 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4362 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4363 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4365 IDirectDrawSurface_Release(d3drm_ds);
4366 IDirectDrawSurface_Release(d3drm_surface);
4367 IDirect3DDevice2_Release(d3ddevice2);
4368 IDirect3DRMDevice3_Release(device3);
4369 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4370 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4371 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4372 ref1 = IDirectDrawSurface_Release(ds);
4373 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4374 ref1 = IDirectDrawSurface_Release(surface);
4375 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4377 memset(&desc, 0, sizeof(desc));
4378 desc.dwSize = sizeof(desc);
4379 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4380 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4381 desc.dwWidth = rc.right;
4382 desc.dwHeight = rc.bottom;
4384 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4385 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4387 /* What happens if we don't pass D3DRMDEVICE_NOZBUFFER and still not attach our own depth surface? */
4388 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
4389 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4391 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4392 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4394 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4395 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4396 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4398 /* Check if depth surface matches the one we created */
4399 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4400 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x).\n", hr);
4401 IDirectDrawSurface_Release(d3drm_surface);
4403 IDirect3DDevice2_Release(d3ddevice2);
4404 IDirect3DRMDevice3_Release(device3);
4405 ref1 = IDirectDrawSurface_Release(surface);
4406 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4407 IDirect3DRM3_Release(d3drm3);
4408 IDirect3DRM_Release(d3drm1);
4409 IDirectDraw_Release(ddraw);
4410 DestroyWindow(window);
4413 static IDirect3DDevice *create_device1(IDirectDraw *ddraw, HWND window, IDirectDrawSurface **ds)
4415 static const DWORD z_depths[] = { 32, 24, 16 };
4416 IDirectDrawSurface *surface;
4417 IDirect3DDevice *device = NULL;
4418 DDSURFACEDESC surface_desc;
4419 unsigned int i;
4420 HRESULT hr;
4421 RECT rc;
4423 GetClientRect(window, &rc);
4424 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4425 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4427 memset(&surface_desc, 0, sizeof(surface_desc));
4428 surface_desc.dwSize = sizeof(surface_desc);
4429 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4430 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4431 surface_desc.dwWidth = rc.right;
4432 surface_desc.dwHeight = rc.bottom;
4434 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4435 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4437 /* We used to use EnumDevices() for this, but it seems
4438 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
4439 * relationship with reality. */
4440 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
4442 memset(&surface_desc, 0, sizeof(surface_desc));
4443 surface_desc.dwSize = sizeof(surface_desc);
4444 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4445 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4446 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
4447 surface_desc.dwWidth = rc.right;
4448 surface_desc.dwHeight = rc.bottom;
4449 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, ds, NULL)))
4450 continue;
4452 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
4453 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4454 if (FAILED(hr))
4456 IDirectDrawSurface_Release(*ds);
4457 continue;
4460 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device)))
4461 break;
4463 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
4464 IDirectDrawSurface_Release(*ds);
4465 *ds = NULL;
4468 IDirectDrawSurface_Release(surface);
4469 return device;
4472 static void test_create_device_from_d3d1(void)
4474 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
4475 IDirect3D *d3d1 = NULL, *temp_d3d1;
4476 IDirect3DRM *d3drm1 = NULL;
4477 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
4478 IDirect3DRMDevice2 *device2;
4479 IDirect3DRMDevice3 *device3;
4480 IDirect3DDevice *d3ddevice1 = NULL, *d3drm_d3ddevice1 = NULL, *temp_d3ddevice1;
4481 IDirect3DDevice2 *d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4482 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
4483 DWORD expected_flags, ret_val;
4484 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4485 DDSURFACEDESC desc;
4486 RECT rc;
4487 HWND window;
4488 ULONG ref1, ref2, ref3, ref4, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
4489 HRESULT hr;
4491 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
4492 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4494 window = create_window();
4495 GetClientRect(window, &rc);
4497 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
4498 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
4499 d3d_ref1 = get_refcount((IUnknown *)d3d1);
4501 /* Create the immediate mode device */
4502 d3ddevice1 = create_device1(ddraw1, window, &ds);
4503 if (d3ddevice1 == NULL)
4505 win_skip("Cannot create IM device, skipping tests.\n");
4506 IDirect3D_Release(d3d1);
4507 IDirectDraw_Release(ddraw1);
4508 return;
4510 device_ref1 = get_refcount((IUnknown *)d3ddevice1);
4512 hr = Direct3DRMCreate(&d3drm1);
4513 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4514 ref1 = get_refcount((IUnknown *)d3drm1);
4516 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, NULL, d3ddevice1, &device1);
4517 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4518 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
4519 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, NULL, &device1);
4520 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4521 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, NULL);
4522 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4524 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, &device1);
4525 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice interface (hr = %x)\n", hr);
4526 ref2 = get_refcount((IUnknown *)d3drm1);
4527 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
4528 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4529 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4530 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4531 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4532 ret_val = IDirect3DRMDevice_GetWidth(device1);
4533 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4534 ret_val = IDirect3DRMDevice_GetHeight(device1);
4535 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4537 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
4538 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
4539 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4540 ok(SUCCEEDED(hr), "Expected hr == D3DRM_OK, got %#x.\n", hr);
4541 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4542 IDirect3DRMDevice2_Release(device2);
4544 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4545 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)&device3);
4546 ok(hr == DD_OK, "Cannot get IDirect3DRMDevice3 Interface (hr = %x).\n", hr);
4547 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4548 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4549 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4550 IDirect3DRMDevice3_Release(device3);
4552 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4553 NULL, &surface, surface_callback);
4554 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4555 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4557 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
4558 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
4559 ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice1, d3drm_d3ddevice1);
4561 /* Check properties of render target and depth surfaces */
4562 hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
4563 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4565 memset(&desc, 0, sizeof(desc));
4566 desc.dwSize = sizeof(desc);
4567 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4568 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
4570 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4571 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4572 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4573 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4574 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4575 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4577 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4578 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4579 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4581 desc.dwSize = sizeof(desc);
4582 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4583 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4585 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4586 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4587 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4588 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4589 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4591 IDirectDrawSurface_Release(d3drm_ds);
4592 IDirectDrawSurface_Release(ds);
4593 IDirectDrawSurface_Release(surface);
4594 IDirect3DDevice_Release(d3drm_d3ddevice1);
4595 IDirect3DRMDevice_Release(device1);
4596 ref2 = get_refcount((IUnknown *)d3drm1);
4597 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
4598 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4599 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4601 /* InitFromD3D tests */
4602 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice, (void **)&device1);
4603 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
4605 hr = IDirect3DRMDevice_InitFromD3D(device1, NULL, d3ddevice1);
4606 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4607 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, NULL);
4608 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4610 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4611 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice interface (hr = %#x)\n", hr);
4612 ref2 = get_refcount((IUnknown *)d3drm1);
4613 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
4614 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4615 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4616 device_ref1, device_ref2);
4617 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4618 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4619 ret_val = IDirect3DRMDevice_GetWidth(device1);
4620 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4621 ret_val = IDirect3DRMDevice_GetHeight(device1);
4622 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4624 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4625 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4626 ref3 = get_refcount((IUnknown *)d3drm1);
4627 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4628 ref3 = get_refcount((IUnknown *)d3ddevice1);
4629 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4630 ref3 = get_refcount((IUnknown *)d3d1);
4631 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4632 /* Release leaked references */
4633 while (IDirect3DRM_Release(d3drm1) > ref2);
4634 while (IDirect3DDevice_Release(d3ddevice1) > device_ref2);
4635 while (IDirect3D_Release(d3d1) > d3d_ref2);
4637 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
4638 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
4639 ref4 = get_refcount((IUnknown *)temp_ddraw1);
4641 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D, (void **)&temp_d3d1);
4642 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
4643 temp_d3ddevice1 = create_device1(temp_ddraw1, window, &surface);
4644 hr = IDirect3DRMDevice_InitFromD3D(device1, temp_d3d1, temp_d3ddevice1);
4645 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4646 ref3 = get_refcount((IUnknown *)d3drm1);
4647 ok(ref3 > ref2, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4648 ref3 = get_refcount((IUnknown *)temp_d3ddevice1);
4649 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4650 ref3 = get_refcount((IUnknown *)temp_d3d1);
4651 todo_wine ok(ref3 < d3d_ref2, "Expected ref3 < d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4652 /* Release leaked references */
4653 while (IDirect3DRM_Release(d3drm1) > ref2);
4654 while (IDirect3DDevice_Release(temp_d3ddevice1) > 0);
4655 while (IDirect3D_Release(temp_d3d1) > ref4);
4656 IDirectDrawSurface_Release(surface);
4657 IDirectDraw_Release(temp_ddraw1);
4659 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4660 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
4661 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
4662 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4663 ok(SUCCEEDED(hr), "Expected hr == D3DRM_OK, got %#x.\n", hr);
4664 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4665 IDirect3DRMDevice2_Release(device2);
4667 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4668 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)&device3);
4669 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 Interface (hr = %#x).\n", hr);
4670 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4671 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4672 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4673 IDirect3DRMDevice3_Release(device3);
4675 surface = NULL;
4676 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4677 NULL, &surface, surface_callback);
4678 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
4679 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4681 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
4682 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice interface (hr = %#x).\n", hr);
4683 ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode device created == %p, got %p.\n",
4684 d3ddevice1, d3drm_d3ddevice1);
4686 /* Check properties of render target and depth surfaces */
4687 hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
4688 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
4690 memset(&desc, 0, sizeof(desc));
4691 desc.dwSize = sizeof(desc);
4692 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4693 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %#x).\n", hr);
4695 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4696 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4697 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
4698 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4699 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4700 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4702 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4703 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
4704 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4706 desc.dwSize = sizeof(desc);
4707 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4708 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %#x).\n", hr);
4710 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4711 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4712 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %#x, got %#x.\n",
4713 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4714 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4715 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
4717 IDirectDrawSurface_Release(d3drm_ds);
4718 IDirectDrawSurface_Release(ds);
4719 IDirectDrawSurface_Release(surface);
4720 IDirect3DDevice_Release(d3drm_d3ddevice1);
4721 IDirect3DRMDevice_Release(device1);
4722 ref2 = get_refcount((IUnknown *)d3drm1);
4723 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
4724 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4725 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4726 device_ref1, device_ref2);
4727 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4728 todo_wine ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1,
4729 d3d_ref2);
4731 IDirect3DRM_Release(d3drm1);
4732 IDirect3DDevice_Release(d3ddevice1);
4733 IDirect3D_Release(d3d1);
4734 IDirectDraw_Release(ddraw1);
4735 DestroyWindow(window);
4738 static IDirect3DDevice2 *create_device2(IDirectDraw2 *ddraw, HWND window, IDirectDrawSurface **ds)
4740 static const DWORD z_depths[] = { 32, 24, 16 };
4741 IDirectDrawSurface *surface;
4742 IDirect3DDevice2 *device = NULL;
4743 DDSURFACEDESC surface_desc;
4744 IDirect3D2 *d3d;
4745 unsigned int i;
4746 HRESULT hr;
4747 RECT rc;
4749 GetClientRect(window, &rc);
4750 hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4751 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4753 memset(&surface_desc, 0, sizeof(surface_desc));
4754 surface_desc.dwSize = sizeof(surface_desc);
4755 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4756 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4757 surface_desc.dwWidth = rc.right;
4758 surface_desc.dwHeight = rc.bottom;
4760 hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4761 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4763 hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
4764 if (FAILED(hr))
4766 IDirectDrawSurface_Release(surface);
4767 *ds = NULL;
4768 return NULL;
4771 /* We used to use EnumDevices() for this, but it seems
4772 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
4773 * relationship with reality. */
4774 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
4776 memset(&surface_desc, 0, sizeof(surface_desc));
4777 surface_desc.dwSize = sizeof(surface_desc);
4778 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4779 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4780 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
4781 surface_desc.dwWidth = rc.right;
4782 surface_desc.dwHeight = rc.bottom;
4783 if (FAILED(IDirectDraw2_CreateSurface(ddraw, &surface_desc, ds, NULL)))
4784 continue;
4786 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
4787 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4788 if (FAILED(hr))
4790 IDirectDrawSurface_Release(*ds);
4791 continue;
4794 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device)))
4795 break;
4797 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
4798 IDirectDrawSurface_Release(*ds);
4799 *ds = NULL;
4802 IDirect3D2_Release(d3d);
4803 IDirectDrawSurface_Release(surface);
4804 return device;
4807 static void test_create_device_from_d3d2(void)
4809 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
4810 IDirectDraw2 *ddraw2 = NULL, *temp_ddraw2;
4811 IDirect3D* d3d1;
4812 IDirect3D2 *d3d2 = NULL, *temp_d3d2;
4813 IDirect3DRM *d3drm1 = NULL;
4814 IDirect3DRM2 *d3drm2 = NULL;
4815 IDirect3DRMDevice *device1;
4816 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
4817 IDirect3DDevice *d3ddevice1;
4818 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL, *temp_d3ddevice2;
4819 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
4820 DWORD expected_flags, ret_val;
4821 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4822 DDSURFACEDESC desc;
4823 RECT rc;
4824 HWND window;
4825 ULONG ref1, ref2, ref3, ref4, ref5, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
4826 HRESULT hr;
4828 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
4829 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4831 window = create_window();
4832 GetClientRect(window, &rc);
4834 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
4835 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
4836 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
4837 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
4838 d3d_ref1 = get_refcount((IUnknown *)d3d2);
4840 /* Create the immediate mode device */
4841 d3ddevice2 = create_device2(ddraw2, window, &ds);
4842 if (d3ddevice2 == NULL)
4844 win_skip("Cannot create IM device, skipping tests.\n");
4845 IDirect3D2_Release(d3d2);
4846 IDirectDraw2_Release(ddraw2);
4847 IDirectDraw_Release(ddraw1);
4848 return;
4850 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
4852 hr = Direct3DRMCreate(&d3drm1);
4853 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4854 ref1 = get_refcount((IUnknown *)d3drm1);
4856 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
4857 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
4858 ref2 = get_refcount((IUnknown *)d3drm2);
4860 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, NULL, d3ddevice2, &device2);
4861 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4862 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
4863 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, NULL, &device2);
4864 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4865 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, NULL);
4866 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4868 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, &device2);
4869 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice2 interface (hr = %x)\n", hr);
4870 ref3 = get_refcount((IUnknown *)d3drm1);
4871 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4872 ref3 = get_refcount((IUnknown *)d3drm2);
4873 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4874 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4875 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4876 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4877 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4878 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4879 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4880 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4881 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4883 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4884 NULL, &surface, surface_callback);
4885 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4886 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4888 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3drm_d3ddevice2);
4889 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4890 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
4892 /* Check properties of render target and depth surfaces */
4893 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
4894 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4896 memset(&desc, 0, sizeof(desc));
4897 desc.dwSize = sizeof(desc);
4898 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4899 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
4901 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4902 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4903 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4904 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4905 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4906 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4908 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4909 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4910 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4912 desc.dwSize = sizeof(desc);
4913 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4914 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4916 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4917 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4918 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4919 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4920 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4922 IDirectDrawSurface_Release(d3drm_ds);
4923 IDirectDrawSurface_Release(ds);
4924 IDirectDrawSurface_Release(surface);
4925 IDirect3DDevice2_Release(d3drm_d3ddevice2);
4926 IDirect3DRMDevice2_Release(device2);
4927 ref3 = get_refcount((IUnknown *)d3drm1);
4928 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4929 ref3 = get_refcount((IUnknown *)d3drm2);
4930 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4931 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4932 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4933 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4934 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4936 /* InitFromD3D tests */
4937 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice2, (void **)&device2);
4938 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %#x).\n", hr);
4940 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
4941 ok(SUCCEEDED(hr), "Cannot get IDirect3D interface (hr = %x).\n", hr);
4942 if (SUCCEEDED(hr = IDirect3DDevice2_QueryInterface(d3ddevice2, &IID_IDirect3DDevice, (void **)&d3ddevice1)))
4944 hr = IDirect3DRMDevice2_InitFromD3D(device2, d3d1, d3ddevice1);
4945 ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
4946 hr = IDirect3DRMDevice2_InitFromD3D(device2, NULL, d3ddevice1);
4947 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4948 hr = IDirect3DRMDevice2_InitFromD3D(device2, d3d1, NULL);
4949 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4950 hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IDirect3DRMDevice, (void **)&device1);
4951 ok(SUCCEEDED(hr), "Cannot obtain IDirect3DRMDevice interface (hr = %#x).\n", hr);
4952 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4953 todo_wine ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
4954 IDirect3DRMDevice_Release(device1);
4955 if (SUCCEEDED(hr))
4957 IDirect3DRMDevice_Release(device1);
4958 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice2,
4959 (void **)&device2);
4960 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %#x).\n", hr);
4963 IDirect3D_Release(d3d1);
4964 IDirect3DDevice_Release(d3ddevice1);
4966 hr = IDirect3DRMDevice2_InitFromD3D2(device2, NULL, d3ddevice2);
4967 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4968 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, NULL);
4969 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4971 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, d3ddevice2);
4972 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice2 interface (hr = %#x)\n", hr);
4973 ref4 = get_refcount((IUnknown *)d3drm1);
4974 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
4975 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4976 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4977 device_ref1, device_ref2);
4978 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4979 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4980 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4981 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4982 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4983 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4985 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, d3ddevice2);
4986 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4987 ref3 = get_refcount((IUnknown *)d3drm1);
4988 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4989 ref3 = get_refcount((IUnknown *)d3ddevice2);
4990 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4991 ref3 = get_refcount((IUnknown *)d3d2);
4992 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4993 /* Release leaked references */
4994 while (IDirect3DRM_Release(d3drm1) > ref4);
4995 while (IDirect3DDevice2_Release(d3ddevice2) > device_ref2);
4996 while (IDirect3D2_Release(d3d2) > d3d_ref2);
4998 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
4999 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
5000 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D2, (void **)&temp_d3d2);
5001 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
5002 ref5 = get_refcount((IUnknown *)temp_d3d2);
5004 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirectDraw2, (void **)&temp_ddraw2);
5005 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
5007 temp_d3ddevice2 = create_device2(temp_ddraw2, window, &surface);
5008 hr = IDirect3DRMDevice2_InitFromD3D2(device2, temp_d3d2, temp_d3ddevice2);
5009 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
5010 ref3 = get_refcount((IUnknown *)d3drm1);
5011 ok(ref3 > ref4, "expected ref3 > ref4, got ref3 = %u , ref4 = %u.\n", ref3, ref4);
5012 ref3 = get_refcount((IUnknown *)temp_d3ddevice2);
5013 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
5014 ref3 = get_refcount((IUnknown *)temp_d3d2);
5015 ok(ref3 == d3d_ref2, "Expected ref3 == d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
5016 /* Release leaked references */
5017 while (IDirect3DRM_Release(d3drm1) > ref4);
5018 while (IDirect3DDevice2_Release(temp_d3ddevice2) > 0);
5019 while (IDirect3D2_Release(temp_d3d2) >= ref5);
5020 IDirectDrawSurface_Release(surface);
5021 IDirectDraw2_Release(temp_ddraw2);
5022 IDirectDraw_Release(temp_ddraw1);
5024 surface = NULL;
5025 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
5026 NULL, &surface, surface_callback);
5027 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
5028 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
5030 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3drm_d3ddevice2);
5031 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
5032 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2,
5033 d3drm_d3ddevice2);
5035 /* Check properties of render target and depth surfaces */
5036 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
5037 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
5039 memset(&desc, 0, sizeof(desc));
5040 desc.dwSize = sizeof(desc);
5041 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
5042 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %#x).\n", hr);
5044 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5045 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5046 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
5047 "Expected caps containing %#x, got %#x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
5048 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5049 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5051 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5052 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
5053 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5055 desc.dwSize = sizeof(desc);
5056 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5057 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %x).\n", hr);
5059 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5060 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5061 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %#x, got %#x.\n",
5062 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5063 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5064 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5066 IDirectDrawSurface_Release(d3drm_ds);
5067 IDirectDrawSurface_Release(ds);
5068 IDirectDrawSurface_Release(surface);
5069 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5070 IDirect3DRMDevice2_Release(device2);
5071 ref3 = get_refcount((IUnknown *)d3drm1);
5072 ok(ref1 == ref3, "Expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5073 ref3 = get_refcount((IUnknown *)d3drm2);
5074 ok(ref3 == ref2, "Expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5075 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5076 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5077 device_ref1, device_ref2);
5078 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5079 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5081 IDirect3DRM2_Release(d3drm2);
5082 IDirect3DRM_Release(d3drm1);
5083 IDirect3DDevice2_Release(d3ddevice2);
5084 IDirect3D2_Release(d3d2);
5085 IDirectDraw2_Release(ddraw2);
5086 IDirectDraw_Release(ddraw1);
5087 DestroyWindow(window);
5090 static void test_create_device_from_d3d3(void)
5092 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
5093 IDirectDraw2 *ddraw2 = NULL, *temp_ddraw2;
5094 IDirect3D *d3d1;
5095 IDirect3D2 *d3d2 = NULL, *temp_d3d2;
5096 IDirect3DRM *d3drm1 = NULL;
5097 IDirect3DRM3 *d3drm3 = NULL;
5098 IDirect3DRMDevice *device1;
5099 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
5100 IDirect3DDevice *d3ddevice1;
5101 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL, *temp_d3ddevice2;
5102 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
5103 DWORD expected_flags, ret_val;
5104 DDSCAPS caps = { DDSCAPS_ZBUFFER };
5105 DDSURFACEDESC desc;
5106 RECT rc;
5107 HWND window;
5108 ULONG ref1, ref2, ref3, ref4, ref5, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
5109 HRESULT hr;
5111 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
5112 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
5114 window = create_window();
5115 GetClientRect(window, &rc);
5117 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
5118 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
5119 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
5120 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
5121 d3d_ref1 = get_refcount((IUnknown *)d3d2);
5123 /* Create the immediate mode device */
5124 d3ddevice2 = create_device2(ddraw2, window, &ds);
5125 if (d3ddevice2 == NULL)
5127 win_skip("Cannot create IM device, skipping tests.\n");
5128 IDirect3D2_Release(d3d2);
5129 IDirectDraw2_Release(ddraw2);
5130 IDirectDraw_Release(ddraw1);
5131 return;
5133 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
5135 hr = Direct3DRMCreate(&d3drm1);
5136 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
5137 ref1 = get_refcount((IUnknown *)d3drm1);
5139 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5140 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
5141 ref2 = get_refcount((IUnknown *)d3drm3);
5143 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, NULL, d3ddevice2, &device3);
5144 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5145 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
5146 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, NULL, &device3);
5147 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5148 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, NULL);
5149 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5151 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, &device3);
5152 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice3 interface (hr = %x)\n", hr);
5153 ref3 = get_refcount((IUnknown *)d3drm1);
5154 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
5155 ref3 = get_refcount((IUnknown *)d3drm3);
5156 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5157 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5158 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
5159 ret_val = IDirect3DRMDevice3_GetWidth(device3);
5160 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
5161 ret_val = IDirect3DRMDevice3_GetHeight(device3);
5162 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
5164 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
5165 NULL, &surface, surface_callback);
5166 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
5167 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
5169 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3drm_d3ddevice2);
5170 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
5171 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
5173 /* Check properties of render target and depth surfaces */
5174 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
5175 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
5177 memset(&desc, 0, sizeof(desc));
5178 desc.dwSize = sizeof(desc);
5179 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
5180 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
5182 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5183 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5184 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
5185 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
5186 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5187 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
5189 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5190 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
5191 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5193 desc.dwSize = sizeof(desc);
5194 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5195 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
5197 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5198 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5199 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5200 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5201 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
5203 IDirectDrawSurface_Release(d3drm_ds);
5204 IDirectDrawSurface_Release(ds);
5205 IDirectDrawSurface_Release(surface);
5206 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5207 IDirect3DRMDevice3_Release(device3);
5208 ref3 = get_refcount((IUnknown *)d3drm1);
5209 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5210 ref3 = get_refcount((IUnknown *)d3drm3);
5211 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5212 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5213 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
5214 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5215 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5217 /* InitFromD3D tests */
5218 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice3, (void **)&device3);
5219 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5221 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
5222 ok(SUCCEEDED(hr), "Cannot get IDirect3D interface (hr = %#x).\n", hr);
5223 if (SUCCEEDED(hr = IDirect3DDevice2_QueryInterface(d3ddevice2, &IID_IDirect3DDevice, (void **)&d3ddevice1)))
5225 hr = IDirect3DRMDevice3_InitFromD3D(device3, d3d1, d3ddevice1);
5226 ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
5227 hr = IDirect3DRMDevice3_InitFromD3D(device3, NULL, d3ddevice1);
5228 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5229 hr = IDirect3DRMDevice3_InitFromD3D(device3, d3d1, NULL);
5230 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5231 hr = IDirect3DRMDevice3_QueryInterface(device3, &IID_IDirect3DRMDevice, (void **)&device1);
5232 ok(SUCCEEDED(hr), "Cannot obtain IDirect3DRMDevice interface (hr = %#x).\n", hr);
5233 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
5234 todo_wine ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
5235 IDirect3DRMDevice_Release(device1);
5236 if (SUCCEEDED(hr))
5238 IDirect3DRMDevice_Release(device1);
5239 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice3,
5240 (void **)&device3);
5241 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5244 IDirect3D_Release(d3d1);
5245 IDirect3DDevice_Release(d3ddevice1);
5247 hr = IDirect3DRMDevice3_InitFromD3D2(device3, NULL, d3ddevice2);
5248 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5249 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, NULL);
5250 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5252 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, d3ddevice2);
5253 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice2 interface (hr = %#x)\n", hr);
5254 ref4 = get_refcount((IUnknown *)d3drm1);
5255 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
5256 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5257 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5258 device_ref1, device_ref2);
5259 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5260 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5261 ret_val = IDirect3DRMDevice3_GetWidth(device3);
5262 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
5263 ret_val = IDirect3DRMDevice3_GetHeight(device3);
5264 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
5266 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, d3ddevice2);
5267 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
5268 ref3 = get_refcount((IUnknown *)d3drm1);
5269 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
5270 ref3 = get_refcount((IUnknown *)d3ddevice2);
5271 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
5272 ref3 = get_refcount((IUnknown *)d3d2);
5273 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
5274 /* Release leaked references */
5275 while (IDirect3DRM_Release(d3drm1) > ref4);
5276 while (IDirect3DDevice2_Release(d3ddevice2) > device_ref2);
5277 while (IDirect3D2_Release(d3d2) > d3d_ref2);
5279 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
5280 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
5281 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D2, (void **)&temp_d3d2);
5282 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
5283 ref5 = get_refcount((IUnknown *)temp_d3d2);
5285 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirectDraw2, (void **)&temp_ddraw2);
5286 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
5288 temp_d3ddevice2 = create_device2(temp_ddraw2, window, &surface);
5289 hr = IDirect3DRMDevice3_InitFromD3D2(device3, temp_d3d2, temp_d3ddevice2);
5290 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
5291 ref3 = get_refcount((IUnknown *)d3drm1);
5292 ok(ref3 > ref4, "expected ref3 > ref4, got ref3 = %u , ref4 = %u.\n", ref3, ref4);
5293 ref3 = get_refcount((IUnknown *)temp_d3ddevice2);
5294 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
5295 ref3 = get_refcount((IUnknown *)temp_d3d2);
5296 ok(ref3 == d3d_ref2, "Expected ref3 == d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
5297 /* Release leaked references */
5298 while (IDirect3DRM_Release(d3drm1) > ref4);
5299 while (IDirect3DDevice2_Release(temp_d3ddevice2) > 0);
5300 while (IDirect3D2_Release(temp_d3d2) >= ref5);
5301 IDirectDrawSurface_Release(surface);
5302 IDirectDraw2_Release(temp_ddraw2);
5303 IDirectDraw_Release(temp_ddraw1);
5305 surface = NULL;
5306 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
5307 NULL, &surface, surface_callback);
5308 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
5309 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
5311 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3drm_d3ddevice2);
5312 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
5313 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2,
5314 d3drm_d3ddevice2);
5316 /* Check properties of render target and depth surfaces */
5317 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
5318 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
5320 memset(&desc, 0, sizeof(desc));
5321 desc.dwSize = sizeof(desc);
5322 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
5323 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %x).\n", hr);
5325 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5326 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5327 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
5328 "Expected caps containing %#x, got %#x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
5329 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5330 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5332 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5333 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
5334 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5336 desc.dwSize = sizeof(desc);
5337 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5338 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %x).\n", hr);
5340 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5341 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5342 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %#x.\n",
5343 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5344 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5345 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5347 IDirectDrawSurface_Release(d3drm_ds);
5348 IDirectDrawSurface_Release(ds);
5349 IDirectDrawSurface_Release(surface);
5350 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5351 IDirect3DRMDevice3_Release(device3);
5352 ref3 = get_refcount((IUnknown *)d3drm1);
5353 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5354 ref3 = get_refcount((IUnknown *)d3drm3);
5355 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5356 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5357 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5358 device_ref1, device_ref2);
5359 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5360 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5362 IDirect3DRM3_Release(d3drm3);
5363 IDirect3DRM_Release(d3drm1);
5364 IDirect3DDevice2_Release(d3ddevice2);
5365 IDirect3D2_Release(d3d2);
5366 IDirectDraw2_Release(ddraw2);
5367 IDirectDraw_Release(ddraw1);
5368 DestroyWindow(window);
5371 static char *create_bitmap(unsigned int w, unsigned int h, BOOL palettized)
5373 unsigned int bpp = palettized ? 8 : 24;
5374 BITMAPFILEHEADER file_header;
5375 DWORD written, size, ret;
5376 unsigned char *buffer;
5377 char path[MAX_PATH];
5378 unsigned int i, j;
5379 BITMAPINFO *info;
5380 char *filename;
5381 HANDLE file;
5383 ret = GetTempPathA(MAX_PATH, path);
5384 ok(ret, "Failed to get temporary file path.\n");
5385 filename = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
5386 ret = GetTempFileNameA(path, "d3d", 0, filename);
5387 ok(ret, "Failed to get filename.\n");
5388 file = CreateFileA(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
5389 ok(file != INVALID_HANDLE_VALUE, "Failed to open temporary file \"%s\".\n", filename);
5391 size = FIELD_OFFSET(BITMAPINFO, bmiColors[palettized ? 256 : 0]);
5393 memset(&file_header, 0, sizeof(file_header));
5394 file_header.bfType = 0x4d42; /* BM */
5395 file_header.bfOffBits = sizeof(file_header) + size;
5396 file_header.bfSize = file_header.bfOffBits + w * h * (bpp / 8);
5397 ret = WriteFile(file, &file_header, sizeof(file_header), &written, NULL);
5398 ok(ret && written == sizeof(file_header), "Failed to write file header.\n");
5400 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
5401 info->bmiHeader.biSize = sizeof(info->bmiHeader);
5402 info->bmiHeader.biBitCount = bpp;
5403 info->bmiHeader.biPlanes = 1;
5404 info->bmiHeader.biWidth = w;
5405 info->bmiHeader.biHeight = h;
5406 info->bmiHeader.biCompression = BI_RGB;
5407 if (palettized)
5409 for (i = 0; i < 256; ++i)
5411 info->bmiColors[i].rgbBlue = i;
5412 info->bmiColors[i].rgbGreen = i;
5413 info->bmiColors[i].rgbRed = i;
5416 ret = WriteFile(file, info, size, &written, NULL);
5417 ok(ret && written == size, "Failed to write bitmap info.\n");
5418 HeapFree(GetProcessHeap(), 0, info);
5420 size = w * h * (bpp / 8);
5421 buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
5422 for (i = 0, j = 0; i < size;)
5424 if (palettized)
5426 buffer[i++] = j++;
5427 j %= 256;
5429 else
5431 buffer[i++] = j % 251;
5432 buffer[i++] = j % 239;
5433 buffer[i++] = j++ % 247;
5436 ret = WriteFile(file, buffer, size, &written, NULL);
5437 ok(ret && written == size, "Failed to write bitmap data.\n");
5438 HeapFree(GetProcessHeap(), 0, buffer);
5440 CloseHandle(file);
5442 return filename;
5445 static void test_bitmap_data(unsigned int test_idx, const D3DRMIMAGE *img,
5446 BOOL upside_down, unsigned int w, unsigned int h, BOOL palettized)
5448 const unsigned char *data = img->buffer1;
5449 unsigned int i, j;
5451 ok(img->width == w, "Test %u: Got unexpected image width %u, expected %u.\n", test_idx, img->width, w);
5452 ok(img->height == h, "Test %u: Got unexpected image height %u, expected %u.\n", test_idx, img->height, h);
5453 ok(img->aspectx == 1, "Test %u: Got unexpected image aspectx %u.\n", test_idx, img->aspectx);
5454 ok(img->aspecty == 1, "Test %u: Got unexpected image aspecty %u.\n", test_idx, img->aspecty);
5455 ok(!img->buffer2, "Test %u: Got unexpected image buffer2 %p.\n", test_idx, img->buffer2);
5457 /* The image is palettized if the total number of colors used is <= 256. */
5458 if (w * h > 256 && !palettized)
5460 /* D3drm aligns the 24bpp texture to 4 bytes in the buffer, with one
5461 * byte padding from 24bpp texture. */
5462 ok(img->depth == 32, "Test %u: Got unexpected image depth %u.\n", test_idx, img->depth);
5463 ok(img->rgb == TRUE, "Test %u: Got unexpected image rgb %#x.\n", test_idx, img->rgb);
5464 ok(img->bytes_per_line == w * 4, "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5465 test_idx, img->bytes_per_line, w * 4);
5466 ok(img->red_mask == 0xff0000, "Test %u: Got unexpected image red mask %#x.\n", test_idx, img->red_mask);
5467 ok(img->green_mask == 0x00ff00, "Test %u: Got unexpected image green mask %#x.\n", test_idx, img->green_mask);
5468 ok(img->blue_mask == 0x0000ff, "Test %u: Got unexpected image blue mask %#x.\n", test_idx, img->blue_mask);
5469 ok(!img->alpha_mask, "Test %u: Got unexpected image alpha mask %#x.\n", test_idx, img->alpha_mask);
5470 ok(!img->palette_size, "Test %u: Got unexpected palette size %u.\n", test_idx, img->palette_size);
5471 ok(!img->palette, "Test %u: Got unexpected image palette %p.\n", test_idx, img->palette);
5472 for (i = 0; i < h; ++i)
5474 for (j = 0; j < w; ++j)
5476 const unsigned char *ptr = &data[i * img->bytes_per_line + j * 4];
5477 unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
5479 if (ptr[0] != idx % 251 || ptr[1] != idx % 239 || ptr[2] != idx % 247 || ptr[3] != 0xff)
5481 ok(0, "Test %u: Got unexpected color 0x%02x%02x%02x%02x at position %u, %u, "
5482 "expected 0x%02x%02x%02x%02x.\n", test_idx, ptr[0], ptr[1], ptr[2], ptr[3],
5483 j, i, idx % 251, idx % 239, idx % 247, 0xff);
5484 return;
5488 return;
5491 ok(img->depth == 8, "Test %u: Got unexpected image depth %u.\n", test_idx, img->depth);
5492 ok(!img->rgb, "Test %u: Got unexpected image rgb %#x.\n", test_idx, img->rgb);
5493 ok(img->red_mask == 0xff, "Test %u: Got unexpected image red mask %#x.\n", test_idx, img->red_mask);
5494 ok(img->green_mask == 0xff, "Test %u: Got unexpected image green mask %#x.\n", test_idx, img->green_mask);
5495 ok(img->blue_mask == 0xff, "Test %u: Got unexpected image blue mask %#x.\n", test_idx, img->blue_mask);
5496 ok(!img->alpha_mask, "Test %u: Got unexpected image alpha mask %#x.\n", test_idx, img->alpha_mask);
5497 ok(!!img->palette, "Test %u: Got unexpected image palette %p.\n", test_idx, img->palette);
5498 if (!palettized)
5500 /* In this case, bytes_per_line is aligned to the next multiple of
5501 * 4 from width. */
5502 ok(img->bytes_per_line == ((w + 3) & ~3), "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5503 test_idx, img->bytes_per_line, (w + 3) & ~3);
5504 ok(img->palette_size == w * h, "Test %u: Got unexpected palette size %u, expected %u.\n",
5505 test_idx, img->palette_size, w * h);
5506 for (i = 0; i < img->palette_size; ++i)
5508 unsigned int idx = upside_down ? (h - 1) * w - i + (i % w) * 2 : i;
5509 ok(img->palette[i].red == idx % 251
5510 && img->palette[i].green == idx % 239 && img->palette[i].blue == idx % 247,
5511 "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n",
5512 test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue);
5513 ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
5514 "Test %u: Got unexpected palette entry (%u) flags %#x.\n",
5515 test_idx, i, img->palette[i].flags);
5517 for (i = 0; i < h; ++i)
5519 for (j = 0; j < w; ++j)
5521 if (data[i * img->bytes_per_line + j] != i * w + j)
5523 ok(0, "Test %u: Got unexpected color 0x%02x at position %u, %u, expected 0x%02x.\n",
5524 test_idx, data[i * img->bytes_per_line + j], j, i, i * w + j);
5525 return;
5529 return;
5532 /* bytes_per_line is not always aligned by d3drm depending on the
5533 * format. */
5534 ok(img->bytes_per_line == w, "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5535 test_idx, img->bytes_per_line, w);
5536 ok(img->palette_size == 256, "Test %u: Got unexpected palette size %u.\n", test_idx, img->palette_size);
5537 for (i = 0; i < 256; ++i)
5539 ok(img->palette[i].red == i && img->palette[i].green == i && img->palette[i].blue == i,
5540 "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n",
5541 test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue);
5542 ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
5543 "Test %u: Got unexpected palette entry (%u) flags %#x.\n",
5544 test_idx, i, img->palette[i].flags);
5546 for (i = 0; i < h; ++i)
5548 for (j = 0; j < w; ++j)
5550 unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
5551 if (data[i * img->bytes_per_line + j] != idx % 256)
5553 ok(0, "Test %u: Got unexpected color 0x%02x at position %u, %u, expected 0x%02x.\n",
5554 test_idx, data[i * img->bytes_per_line + j], j, i, idx % 256);
5555 return;
5561 static void test_load_texture(void)
5563 IDirect3DRMTexture3 *texture3;
5564 IDirect3DRMTexture2 *texture2;
5565 IDirect3DRMTexture *texture1;
5566 D3DRMIMAGE *d3drm_img;
5567 IDirect3DRM3 *d3drm3;
5568 IDirect3DRM2 *d3drm2;
5569 IDirect3DRM *d3drm1;
5570 char *filename;
5571 HRESULT hr;
5572 BOOL ret;
5573 int i;
5575 static const struct
5577 unsigned int w;
5578 unsigned int h;
5579 BOOL palettized;
5581 tests[] =
5583 {100, 100, TRUE },
5584 {99, 100, TRUE },
5585 {100, 100, FALSE},
5586 {99, 100, FALSE},
5587 {3, 39, FALSE},
5590 hr = Direct3DRMCreate(&d3drm1);
5591 ok(hr == D3DRM_OK, "Failed to create IDirect3DRM object, hr %#x.\n", hr);
5592 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5593 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM2 interface, hr %#x.\n", hr);
5594 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5595 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM3 interface, hr %#x.\n", hr);
5597 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
5599 filename = create_bitmap(tests[i].w, tests[i].h, tests[i].palettized);
5601 hr = IDirect3DRM_LoadTexture(d3drm1, filename, &texture1);
5602 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5603 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
5604 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5605 if (d3drm_img)
5606 test_bitmap_data(i * 4, d3drm_img, FALSE, tests[i].w, tests[i].h, tests[i].palettized);
5607 IDirect3DRMTexture_Release(texture1);
5609 hr = IDirect3DRM2_LoadTexture(d3drm2, filename, &texture2);
5610 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5611 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
5612 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5613 if (d3drm_img)
5614 test_bitmap_data(i * 4 + 1, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5615 IDirect3DRMTexture2_Release(texture2);
5617 hr = IDirect3DRM3_LoadTexture(d3drm3, filename, &texture3);
5618 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5619 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
5620 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5621 if (d3drm_img)
5622 test_bitmap_data(i * 4 + 2, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5623 /* Test whether querying a version 1 texture from version 3 causes a
5624 * change in the loading behavior. */
5625 hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IDirect3DRMTexture, (void **)&texture1);
5626 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMTexture interface, hr %#x.\n", hr);
5627 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
5628 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5629 if (d3drm_img)
5630 test_bitmap_data(i * 4 + 3, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5631 IDirect3DRMTexture_Release(texture1);
5632 IDirect3DRMTexture3_Release(texture3);
5634 ret = DeleteFileA(filename);
5635 ok(ret, "Test %u: Failed to delete bitmap \"%s\".\n", i, filename);
5636 HeapFree(GetProcessHeap(), 0, filename);
5639 IDirect3DRM3_Release(d3drm3);
5640 IDirect3DRM2_Release(d3drm2);
5641 IDirect3DRM_Release(d3drm1);
5644 static void test_texture_qi(void)
5646 static const struct qi_test tests[] =
5648 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5649 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5650 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5651 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5652 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5653 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5654 { &IID_IDirect3DRMWinDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5655 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5656 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5657 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5658 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5659 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5660 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5661 { &IID_IDirect3DRMVisual, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5662 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5663 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5664 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5665 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5666 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5667 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5668 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5669 { &IID_IDirect3DRMTexture, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5670 { &IID_IDirect3DRMTexture2, &IID_IUnknown, &IID_IDirect3DRMTexture2, S_OK },
5671 { &IID_IDirect3DRMTexture3, &IID_IUnknown, &IID_IDirect3DRMTexture3, S_OK },
5672 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5673 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5674 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5675 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5676 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5677 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5678 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5679 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5680 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5681 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5682 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5683 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5684 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5685 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5686 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5687 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5688 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5689 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5690 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5691 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5692 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5693 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5694 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5695 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5696 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5697 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5698 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5699 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5700 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5701 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5702 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5703 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5704 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5705 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5706 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5707 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5708 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5709 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5710 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5711 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5712 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5713 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5714 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5715 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
5717 HRESULT hr;
5718 IDirect3DRM *d3drm1;
5719 IDirect3DRM2 *d3drm2;
5720 IDirect3DRM3 *d3drm3;
5721 IDirect3DRMTexture *texture1;
5722 IDirect3DRMTexture2 *texture2;
5723 IDirect3DRMTexture3 *texture3;
5724 IUnknown *unknown;
5725 char *filename;
5726 BOOL check;
5728 hr = Direct3DRMCreate(&d3drm1);
5729 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x)\n", hr);
5730 filename = create_bitmap(1, 1, TRUE);
5731 hr = IDirect3DRM_LoadTexture(d3drm1, filename, &texture1);
5732 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5733 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
5734 hr = IDirect3DRMTexture_QueryInterface(texture1, &IID_IUnknown, (void **)&unknown);
5735 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture (hr = %#x)\n", hr);
5736 IDirect3DRMTexture_Release(texture1);
5737 test_qi("texture1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5738 IUnknown_Release(unknown);
5740 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5741 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
5742 hr = IDirect3DRM2_LoadTexture(d3drm2, filename, &texture2);
5743 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5744 hr = IDirect3DRMTexture2_QueryInterface(texture2, &IID_IUnknown, (void **)&unknown);
5745 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture2 (hr = %#x)\n", hr);
5746 IDirect3DRMTexture2_Release(texture2);
5747 test_qi("texture2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5748 IUnknown_Release(unknown);
5750 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5751 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
5752 hr = IDirect3DRM3_LoadTexture(d3drm3, filename, &texture3);
5753 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5754 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
5755 hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IUnknown, (void **)&unknown);
5756 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture3 (hr = %#x)\n", hr);
5757 IDirect3DRMTexture3_Release(texture3);
5758 test_qi("texture3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5759 IUnknown_Release(unknown);
5761 IDirect3DRM3_Release(d3drm3);
5762 IDirect3DRM2_Release(d3drm2);
5763 IDirect3DRM_Release(d3drm1);
5764 check = DeleteFileA(filename);
5765 ok(check, "Cannot delete image stored in %s (error = %d).\n", filename, GetLastError());
5766 HeapFree(GetProcessHeap(), 0, filename);
5769 static void test_viewport_qi(void)
5771 IDirect3DRM *d3drm1;
5772 IDirect3DRM2 *d3drm2;
5773 IDirect3DRM3 *d3drm3;
5774 IDirect3DRMFrame *frame1, *camera1;
5775 IDirect3DRMFrame3 *frame3, *camera3;
5776 IDirect3DRMDevice *device1;
5777 IDirect3DRMDevice3 *device3;
5778 IDirectDrawClipper *clipper;
5779 IDirect3DRMViewport *viewport1;
5780 IDirect3DRMViewport2 *viewport2;
5781 IUnknown *unknown;
5782 GUID driver = IID_IDirect3DRGBDevice;
5783 HRESULT hr;
5785 static const struct qi_test tests[] =
5787 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5788 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5789 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5790 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5791 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5792 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5793 { &IID_IDirect3DRMWinDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5794 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMViewport, S_OK },
5795 { &IID_IDirect3DRMViewport, &IID_IUnknown, &IID_IDirect3DRMViewport, S_OK },
5796 { &IID_IDirect3DRMViewport2, &IID_IUnknown, &IID_IDirect3DRMViewport2, S_OK },
5797 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5798 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5799 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5800 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5801 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5802 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5803 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5804 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5805 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5806 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5807 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5808 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5809 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5810 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5811 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5812 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5813 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5814 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5815 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5816 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5817 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5818 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5819 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5820 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5821 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5822 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5823 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5824 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5825 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5826 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5827 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5828 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5829 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5830 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5831 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5832 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5833 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5834 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5835 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5836 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5837 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5838 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5839 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5840 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5841 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5842 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5843 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5844 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5845 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5846 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5847 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5848 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5849 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5850 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5851 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5852 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5853 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5854 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
5857 hr = DirectDrawCreateClipper(0, &clipper, NULL);
5858 ok(SUCCEEDED(hr), "Cannot get IDirectDrawClipper interface (hr = %#x).\n", hr);
5860 hr = Direct3DRMCreate(&d3drm1);
5861 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
5863 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 640, 480, &device1);
5864 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
5865 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
5866 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
5867 hr = IDirect3DRM_CreateFrame(d3drm1, frame1, &camera1);
5868 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
5869 hr = IDirect3DRM_CreateViewport(d3drm1, device1, camera1, 0, 0, 640, 480, &viewport1);
5870 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
5871 hr = IDirect3DRMViewport_QueryInterface(viewport1, &IID_IUnknown, (void **)&unknown);
5872 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5873 IDirect3DRMViewport_Release(viewport1);
5874 test_qi("viewport1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5875 IUnknown_Release(unknown);
5877 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5878 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
5879 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, camera1, 0, 0, 640, 480, &viewport1);
5880 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
5881 hr = IDirect3DRMViewport_QueryInterface(viewport1, &IID_IUnknown, (void **)&unknown);
5882 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5883 IDirect3DRMViewport_Release(viewport1);
5884 test_qi("viewport1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5885 IUnknown_Release(unknown);
5886 IDirect3DRMDevice_Release(device1);
5887 IDirect3DRMFrame_Release(camera1);
5888 IDirect3DRMFrame_Release(frame1);
5890 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5891 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
5892 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 640, 480, &device3);
5893 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5894 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
5895 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
5896 hr = IDirect3DRM3_CreateFrame(d3drm3, frame3, &camera3);
5897 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
5898 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, 640, 480, &viewport2);
5899 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
5900 hr = IDirect3DRMViewport2_QueryInterface(viewport2, &IID_IUnknown, (void **)&unknown);
5901 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5902 IDirect3DRMViewport_Release(viewport2);
5903 test_qi("viewport2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5904 IUnknown_Release(unknown);
5905 IDirect3DRMDevice3_Release(device3);
5906 IDirect3DRMFrame3_Release(camera3);
5907 IDirect3DRMFrame3_Release(frame3);
5909 IDirectDrawClipper_Release(clipper);
5910 IDirect3DRM3_Release(d3drm3);
5911 IDirect3DRM2_Release(d3drm2);
5912 IDirect3DRM_Release(d3drm1);
5915 static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y)
5917 RECT rect = { x, y, x + 1, y + 1 };
5918 DDSURFACEDESC surface_desc;
5919 D3DCOLOR color;
5920 HRESULT hr;
5922 memset(&surface_desc, 0, sizeof(surface_desc));
5923 surface_desc.dwSize = sizeof(surface_desc);
5925 hr = IDirectDrawSurface_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
5926 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5927 if (FAILED(hr))
5928 return 0xdeadbeef;
5930 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
5932 hr = IDirectDrawSurface_Unlock(surface, NULL);
5933 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5935 return color;
5938 static IDirect3DDevice2 *create_device2_without_ds(IDirectDraw2 *ddraw, HWND window)
5940 IDirectDrawSurface *surface;
5941 IDirect3DDevice2 *device = NULL;
5942 DDSURFACEDESC surface_desc;
5943 IDirect3D2 *d3d;
5944 HRESULT hr;
5945 RECT rc;
5947 GetClientRect(window, &rc);
5948 hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5949 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5951 memset(&surface_desc, 0, sizeof(surface_desc));
5952 surface_desc.dwSize = sizeof(surface_desc);
5953 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5954 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5955 surface_desc.dwWidth = rc.right;
5956 surface_desc.dwHeight = rc.bottom;
5958 hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5959 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5961 hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
5962 if (FAILED(hr))
5964 IDirectDrawSurface_Release(surface);
5965 return NULL;
5968 IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device);
5970 IDirect3D2_Release(d3d);
5971 IDirectDrawSurface_Release(surface);
5972 return device;
5975 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
5977 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5978 c1 >>= 8; c2 >>= 8;
5979 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5980 c1 >>= 8; c2 >>= 8;
5981 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5982 c1 >>= 8; c2 >>= 8;
5983 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5984 return TRUE;
5987 static void clear_depth_surface(IDirectDrawSurface *surface, DWORD value)
5989 HRESULT hr;
5990 DDBLTFX fx;
5992 memset(&fx, 0, sizeof(fx));
5993 fx.dwSize = sizeof(fx);
5994 U5(fx).dwFillDepth = value;
5996 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
5997 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
6000 static void set_execute_data(IDirect3DExecuteBuffer *execute_buffer, UINT vertex_count, UINT offset, UINT len)
6002 D3DEXECUTEDATA exec_data;
6003 HRESULT hr;
6005 memset(&exec_data, 0, sizeof(exec_data));
6006 exec_data.dwSize = sizeof(exec_data);
6007 exec_data.dwVertexCount = vertex_count;
6008 exec_data.dwInstructionOffset = offset;
6009 exec_data.dwInstructionLength = len;
6010 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
6011 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
6014 static void emit_set_ts(void **ptr, D3DTRANSFORMSTATETYPE state, DWORD value)
6016 D3DINSTRUCTION *inst = *ptr;
6017 D3DSTATE *ts = (D3DSTATE *)(inst + 1);
6019 inst->bOpcode = D3DOP_STATETRANSFORM;
6020 inst->bSize = sizeof(*ts);
6021 inst->wCount = 1;
6023 U1(*ts).dtstTransformStateType = state;
6024 U2(*ts).dwArg[0] = value;
6026 *ptr = ts + 1;
6029 static void emit_set_rs(void **ptr, D3DRENDERSTATETYPE state, DWORD value)
6031 D3DINSTRUCTION *inst = *ptr;
6032 D3DSTATE *rs = (D3DSTATE *)(inst + 1);
6034 inst->bOpcode = D3DOP_STATERENDER;
6035 inst->bSize = sizeof(*rs);
6036 inst->wCount = 1;
6038 U1(*rs).drstRenderStateType = state;
6039 U2(*rs).dwArg[0] = value;
6041 *ptr = rs + 1;
6044 static void emit_process_vertices(void **ptr, DWORD flags, WORD base_idx, DWORD vertex_count)
6046 D3DINSTRUCTION *inst = *ptr;
6047 D3DPROCESSVERTICES *pv = (D3DPROCESSVERTICES *)(inst + 1);
6049 inst->bOpcode = D3DOP_PROCESSVERTICES;
6050 inst->bSize = sizeof(*pv);
6051 inst->wCount = 1;
6053 pv->dwFlags = flags;
6054 pv->wStart = base_idx;
6055 pv->wDest = 0;
6056 pv->dwCount = vertex_count;
6057 pv->dwReserved = 0;
6059 *ptr = pv + 1;
6062 static void emit_tquad(void **ptr, WORD base_idx)
6064 D3DINSTRUCTION *inst = *ptr;
6065 D3DTRIANGLE *tri = (D3DTRIANGLE *)(inst + 1);
6067 inst->bOpcode = D3DOP_TRIANGLE;
6068 inst->bSize = sizeof(*tri);
6069 inst->wCount = 2;
6071 U1(*tri).v1 = base_idx;
6072 U2(*tri).v2 = base_idx + 1;
6073 U3(*tri).v3 = base_idx + 2;
6074 tri->wFlags = D3DTRIFLAG_START;
6075 ++tri;
6077 U1(*tri).v1 = base_idx + 2;
6078 U2(*tri).v2 = base_idx + 1;
6079 U3(*tri).v3 = base_idx + 3;
6080 tri->wFlags = D3DTRIFLAG_ODD;
6081 ++tri;
6083 *ptr = tri;
6086 static void emit_end(void **ptr)
6088 D3DINSTRUCTION *inst = *ptr;
6090 inst->bOpcode = D3DOP_EXIT;
6091 inst->bSize = 0;
6092 inst->wCount = 0;
6094 *ptr = inst + 1;
6097 static void d3d_draw_quad1(IDirect3DDevice *device, IDirect3DViewport *viewport)
6099 IDirect3DExecuteBuffer *execute_buffer;
6100 D3DEXECUTEBUFFERDESC exec_desc;
6101 HRESULT hr;
6102 void *ptr;
6103 UINT inst_length;
6104 D3DMATRIXHANDLE world_handle, view_handle, proj_handle;
6105 static D3DMATRIX mat =
6107 1.0f, 0.0f, 0.0f, 0.0f,
6108 0.0f, 1.0f, 0.0f, 0.0f,
6109 0.0f, 0.0f, 1.0f, 0.0f,
6110 0.0f, 0.0f, 0.0f, 1.0f,
6112 static const D3DLVERTEX quad_strip[] =
6114 {{-1.0f}, {-1.0f}, {0.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6115 {{-1.0f}, { 1.0f}, {0.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6116 {{ 1.0f}, {-1.0f}, {1.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6117 {{ 1.0f}, { 1.0f}, {1.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6120 hr = IDirect3DDevice_CreateMatrix(device, &world_handle);
6121 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6122 hr = IDirect3DDevice_SetMatrix(device, world_handle, &mat);
6123 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6124 hr = IDirect3DDevice_CreateMatrix(device, &view_handle);
6125 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6126 hr = IDirect3DDevice_SetMatrix(device, view_handle, &mat);
6127 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6128 hr = IDirect3DDevice_CreateMatrix(device, &proj_handle);
6129 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6130 hr = IDirect3DDevice_SetMatrix(device, proj_handle, &mat);
6131 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6133 memset(&exec_desc, 0, sizeof(exec_desc));
6134 exec_desc.dwSize = sizeof(exec_desc);
6135 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
6136 exec_desc.dwBufferSize = 1024;
6137 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
6139 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
6140 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
6142 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6143 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6145 memcpy(exec_desc.lpData, quad_strip, sizeof(quad_strip));
6146 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad_strip);
6147 emit_set_ts(&ptr, D3DTRANSFORMSTATE_WORLD, world_handle);
6148 emit_set_ts(&ptr, D3DTRANSFORMSTATE_VIEW, view_handle);
6149 emit_set_ts(&ptr, D3DTRANSFORMSTATE_PROJECTION, proj_handle);
6150 emit_set_rs(&ptr, D3DRENDERSTATE_CLIPPING, FALSE);
6151 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, TRUE);
6152 emit_set_rs(&ptr, D3DRENDERSTATE_FOGENABLE, FALSE);
6153 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
6154 emit_set_rs(&ptr, D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT);
6156 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
6157 emit_tquad(&ptr, 0);
6159 emit_end(&ptr);
6160 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6161 inst_length -= sizeof(quad_strip);
6163 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6164 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6166 hr = IDirect3DDevice_BeginScene(device);
6167 set_execute_data(execute_buffer, 4, sizeof(quad_strip), inst_length);
6168 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
6169 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6170 hr = IDirect3DDevice_EndScene(device);
6171 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6173 IDirect3DExecuteBuffer_Release(execute_buffer);
6176 static void test_viewport_clear1(void)
6178 DDSCAPS caps = { DDSCAPS_ZBUFFER };
6179 IDirectDraw *ddraw;
6180 IDirectDrawClipper *clipper;
6181 IDirect3DRM *d3drm1;
6182 IDirect3DRMFrame *frame1, *camera1;
6183 IDirect3DRMDevice *device1;
6184 IDirect3DViewport *d3d_viewport;
6185 IDirect3DRMViewport *viewport1;
6186 IDirect3DDevice *d3d_device1;
6187 IDirectDrawSurface *surface, *ds, *d3drm_ds;
6188 HWND window;
6189 GUID driver = IID_IDirect3DRGBDevice;
6190 HRESULT hr;
6191 D3DCOLOR ret_color;
6192 RECT rc;
6194 window = create_window();
6195 GetClientRect(window, &rc);
6197 hr = DirectDrawCreate(NULL, &ddraw, NULL);
6198 ok(SUCCEEDED(hr), "Cannot create IDirectDraw interface (hr = %#x).\n", hr);
6200 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6201 ok(SUCCEEDED(hr), "Failed to set cooperative level (hr = %#x).\n", hr);
6203 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
6204 ok(SUCCEEDED(hr), "Cannot create clipper (hr = %#x).\n", hr);
6206 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
6207 ok(SUCCEEDED(hr), "Cannot set HWnd to Clipper (hr = %#x)\n", hr);
6209 hr = Direct3DRMCreate(&d3drm1);
6210 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
6212 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
6213 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %#x)\n", hr);
6215 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
6216 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
6217 hr = IDirect3DRM_CreateFrame(d3drm1, frame1, &camera1);
6218 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
6220 hr = IDirect3DRM_CreateViewport(d3drm1, device1, camera1, 0, 0, rc.right,
6221 rc.bottom, &viewport1);
6222 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6224 /* Fetch immediate mode device and viewport */
6225 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3d_device1);
6226 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice interface (hr = %#x).\n", hr);
6227 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport1, &d3d_viewport);
6228 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
6230 hr = IDirect3DDevice_QueryInterface(d3d_device1, &IID_IDirectDrawSurface, (void **)&surface);
6231 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6233 ret_color = get_surface_color(surface, 320, 240);
6234 ok(compare_color(ret_color, 0, 1), "Got unexpected color 0x%08x.\n", ret_color);
6236 /* Clear uses the scene frame's background color. */
6237 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(frame1, 1.0f, 1.0f, 1.0f);
6238 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6239 ret_color = IDirect3DRMFrame_GetSceneBackground(frame1);
6240 ok(ret_color == 0xffffffff, "Expected scene color returned == 0xffffffff, got %#x.\n", ret_color);
6241 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(camera1, 0.0f, 1.0f, 0.0f);
6242 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6243 ret_color = IDirect3DRMFrame_GetSceneBackground(camera1);
6244 ok(ret_color == 0xff00ff00, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6246 hr = IDirect3DRMViewport_Clear(viewport1);
6247 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6248 ret_color = get_surface_color(surface, 320, 240);
6249 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6251 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(frame1, 0.0f, 0.0f, 1.0f);
6252 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6253 ret_color = IDirect3DRMFrame_GetSceneBackground(frame1);
6254 ok(ret_color == 0xff0000ff, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6256 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6257 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6258 hr = IDirect3DRMViewport_Clear(viewport1);
6259 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6260 ret_color = get_surface_color(surface, 100, 200);
6261 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6263 d3d_draw_quad1(d3d_device1, d3d_viewport);
6265 ret_color = get_surface_color(surface, 100, 200);
6266 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6268 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
6269 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
6271 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6272 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6273 hr = IDirect3DRMViewport_Clear(viewport1);
6274 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6275 ret_color = get_surface_color(surface, 100, 200);
6276 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6278 /* Fill the depth surface with a value lower than the quad's depth value. */
6279 clear_depth_surface(ds, 0x7fff);
6281 /* Depth test passes here */
6282 d3d_draw_quad1(d3d_device1, d3d_viewport);
6283 ret_color = get_surface_color(surface, 100, 200);
6284 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6285 /* Depth test fails here */
6286 ret_color = get_surface_color(surface, 500, 400);
6287 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6289 /* Check what happens if we release the depth surface that d3drm created, and clear the viewport */
6290 hr = IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
6291 ok(SUCCEEDED(hr), "Cannot delete attached surface (hr = %#x).\n", hr);
6292 d3drm_ds = (IDirectDrawSurface *)0xdeadbeef;
6293 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
6294 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %#x.\n", hr);
6295 ok(d3drm_ds == NULL, "Expected NULL z-surface, got %p.\n", d3drm_ds);
6297 clear_depth_surface(ds, 0x7fff);
6298 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6299 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6300 hr = IDirect3DRMViewport_Clear(viewport1);
6301 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6303 ret_color = get_surface_color(surface, 100, 200);
6304 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6306 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
6307 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
6308 IDirectDrawSurface_Release(ds);
6310 d3d_draw_quad1(d3d_device1, d3d_viewport);
6312 ret_color = get_surface_color(surface, 100, 200);
6313 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6314 ret_color = get_surface_color(surface, 500, 400);
6315 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6317 IDirect3DViewport_Release(d3d_viewport);
6318 IDirectDrawSurface_Release(surface);
6319 IDirect3DDevice_Release(d3d_device1);
6320 IDirect3DRMViewport_Release(viewport1);
6321 IDirect3DRMFrame_Release(frame1);
6322 IDirect3DRMFrame_Release(camera1);
6323 IDirect3DRMDevice_Release(device1);
6324 IDirect3DRM_Release(d3drm1);
6325 IDirectDrawClipper_Release(clipper);
6326 IDirectDraw_Release(ddraw);
6327 DestroyWindow(window);
6330 static void draw_quad2(IDirect3DDevice2 *device, IDirect3DViewport *viewport)
6332 static D3DLVERTEX tquad[] =
6334 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6335 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffbada55}, {0}, {0.0f}, {1.0f}},
6336 {{ 1.0f}, {-1.0f}, {1.0f}, 0, {0xffbada55}, {0}, {1.0f}, {0.0f}},
6337 {{ 1.0f}, { 1.0f}, {1.0f}, 0, {0xffbada55}, {0}, {1.0f}, {1.0f}},
6339 static D3DMATRIX mat =
6341 1.0f, 0.0f, 0.0f, 0.0f,
6342 0.0f, 1.0f, 0.0f, 0.0f,
6343 0.0f, 0.0f, 1.0f, 0.0f,
6344 0.0f, 0.0f, 0.0f, 1.0f,
6346 IDirect3DViewport2 *viewport2;
6347 HRESULT hr;
6349 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
6350 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
6351 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
6352 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
6353 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
6354 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
6356 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport2, (void **)&viewport2);
6357 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport2 interface (hr = %#x).\n", hr);
6358 hr = IDirect3DDevice2_SetCurrentViewport(device, viewport2);
6359 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
6360 IDirect3DViewport2_Release(viewport2);
6362 hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
6363 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
6364 hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
6365 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
6367 hr = IDirect3DDevice2_BeginScene(device);
6368 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6369 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DVT_LVERTEX, tquad, 4, 0);
6370 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6371 hr = IDirect3DDevice2_EndScene(device);
6372 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6375 static void test_viewport_clear2(void)
6377 DDSCAPS caps = { DDSCAPS_ZBUFFER };
6378 IDirect3D2 *d3d2;
6379 IDirectDraw *ddraw1;
6380 IDirectDraw2 *ddraw2;
6381 IDirectDrawClipper *clipper;
6382 IDirect3DRM *d3drm1;
6383 IDirect3DRM3 *d3drm3;
6384 IDirect3DRMFrame3 *frame3, *camera3;
6385 IDirect3DRMDevice3 *device3;
6386 IDirect3DViewport *d3d_viewport;
6387 IDirect3DRMViewport2 *viewport2;
6388 IDirect3DDevice2 *d3d_device2;
6389 IDirectDrawSurface *surface, *ds, *d3drm_ds;
6390 HWND window;
6391 GUID driver = IID_IDirect3DRGBDevice;
6392 HRESULT hr;
6393 D3DCOLOR ret_color;
6394 RECT rc;
6396 window = create_window();
6397 GetClientRect(window, &rc);
6399 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
6400 ok(SUCCEEDED(hr), "Cannot create IDirectDraw interface (hr = %#x).\n", hr);
6402 hr = IDirectDraw_SetCooperativeLevel(ddraw1, window, DDSCL_NORMAL);
6403 ok(SUCCEEDED(hr), "Failed to set cooperative level (hr = %#x).\n", hr);
6405 hr = IDirectDraw_CreateClipper(ddraw1, 0, &clipper, NULL);
6406 ok(SUCCEEDED(hr), "Cannot create clipper (hr = %#x).\n", hr);
6408 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
6409 ok(SUCCEEDED(hr), "Cannot set HWnd to Clipper (hr = %#x)\n", hr);
6411 hr = Direct3DRMCreate(&d3drm1);
6412 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
6414 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
6415 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
6417 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
6418 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice3 interface (hr = %#x)\n", hr);
6420 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
6421 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
6422 hr = IDirect3DRM3_CreateFrame(d3drm3, frame3, &camera3);
6423 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
6425 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, rc.right,
6426 rc.bottom, &viewport2);
6427 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6429 /* Fetch immediate mode device in order to access render target and test its color. */
6430 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3d_device2);
6431 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
6433 hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
6434 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6436 ret_color = get_surface_color(surface, 320, 240);
6437 ok(compare_color(ret_color, 0, 1), "Got unexpected color 0x%08x.\n", ret_color);
6439 /* Clear uses the scene frame's background color. */
6440 hr = IDirect3DRMFrame3_SetSceneBackgroundRGB(frame3, 1.0f, 1.0f, 1.0f);
6441 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6442 ret_color = IDirect3DRMFrame3_GetSceneBackground(frame3);
6443 ok(ret_color == 0xffffffff, "Expected scene color returned == 0xffffffff, got %#x.\n", ret_color);
6444 hr = IDirect3DRMFrame3_SetSceneBackgroundRGB(camera3, 0.0f, 1.0f, 0.0f);
6445 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6446 ret_color = IDirect3DRMFrame3_GetSceneBackground(camera3);
6447 ok(ret_color == 0xff00ff00, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6449 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6450 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6451 ret_color = get_surface_color(surface, 320, 240);
6452 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6454 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
6455 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
6457 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6458 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6460 /* d3drm seems to be calling BeginScene when Clear is called. */
6461 hr = IDirect3DDevice2_BeginScene(d3d_device2);
6462 todo_wine ok(hr == D3DERR_SCENE_IN_SCENE, "Expected hr == D3DERR_SCENE_IN_SCENE, got %#x.\n", hr);
6463 hr = IDirect3DDevice2_EndScene(d3d_device2);
6464 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6466 ret_color = get_surface_color(surface, 320, 240);
6467 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6469 /* We're using d3d to draw using IDirect3DDevice2 created from d3drm. */
6470 draw_quad2(d3d_device2, d3d_viewport);
6471 ret_color = get_surface_color(surface, 320, 240);
6472 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6474 /* Without calling Configure, Clear doesn't work. */
6475 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6476 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6477 ret_color = get_surface_color(surface, 320, 240);
6478 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6480 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6481 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6482 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6483 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6485 ret_color = get_surface_color(surface, 320, 240);
6486 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6488 /* Fetch attached depth surface and see if viewport clears it if it's detached from the render target. */
6489 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
6490 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
6492 clear_depth_surface(ds, 0x39);
6493 draw_quad2(d3d_device2, d3d_viewport);
6495 ret_color = get_surface_color(surface, 320, 240);
6496 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6498 hr = IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
6499 ok(SUCCEEDED(hr), "Cannot delete attached surface (hr = %#x).\n", hr);
6500 d3drm_ds = (IDirectDrawSurface *)0xdeadbeef;
6501 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
6502 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %#x.\n", hr);
6503 ok(d3drm_ds == NULL, "Expected NULL z-surface, got %p.\n", d3drm_ds);
6505 clear_depth_surface(ds, 0x7fff);
6507 /* This version of Clear still clears the depth surface even if it's deleted from the render target. */
6508 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6509 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6510 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6511 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6513 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
6514 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
6515 ret_color = get_surface_color(surface, 320, 240);
6516 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6518 draw_quad2(d3d_device2, d3d_viewport);
6519 ret_color = get_surface_color(surface, 100, 200);
6520 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6521 ret_color = get_surface_color(surface, 500, 400);
6522 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6524 /* Clear with no flags */
6525 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6526 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6527 hr = IDirect3DRMViewport2_Clear(viewport2, 0);
6528 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6529 ret_color = get_surface_color(surface, 320, 240);
6530 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6532 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6533 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6534 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6535 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6536 ret_color = get_surface_color(surface, 320, 240);
6537 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6539 IDirect3DViewport_Release(d3d_viewport);
6540 IDirectDrawSurface_Release(surface);
6541 IDirectDrawSurface_Release(ds);
6542 IDirect3DDevice2_Release(d3d_device2);
6543 IDirect3DRMViewport2_Release(viewport2);
6544 IDirect3DRMDevice3_Release(device3);
6546 /* Create device without depth surface attached */
6547 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
6548 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
6549 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
6550 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
6551 d3d_device2 = create_device2_without_ds(ddraw2, window);
6552 if (!d3d_device2)
6553 goto cleanup;
6555 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3d_device2, &device3);
6556 ok(SUCCEEDED(hr), "Failed to create IDirect3DRMDevice interface (hr = %#x)\n", hr);
6557 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, rc.right,
6558 rc.bottom, &viewport2);
6559 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6560 hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
6561 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6563 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6564 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6565 ret_color = get_surface_color(surface, 320, 240);
6566 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6568 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ZBUFFER);
6569 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6571 IDirectDrawSurface_Release(surface);
6572 IDirect3DRMViewport2_Release(viewport2);
6573 IDirect3DRMDevice3_Release(device3);
6574 IDirect3DDevice2_Release(d3d_device2);
6576 cleanup:
6577 IDirect3DRMFrame3_Release(camera3);
6578 IDirect3DRMFrame3_Release(frame3);
6579 IDirect3DRM3_Release(d3drm3);
6580 IDirect3DRM_Release(d3drm1);
6581 IDirectDrawClipper_Release(clipper);
6582 IDirect3D2_Release(d3d2);
6583 IDirectDraw2_Release(ddraw2);
6584 IDirectDraw_Release(ddraw1);
6585 DestroyWindow(window);
6588 static void test_create_texture_from_surface(void)
6590 D3DRMIMAGE testimg =
6592 0, 0, 0, 0, 0,
6593 TRUE, 0, (void *)0xcafebabe, NULL,
6594 0x000000ff, 0x0000ff00, 0x00ff0000, 0, 0, NULL
6596 IDirectDrawSurface *surface = NULL, *surface2 = NULL, *ds = NULL;
6597 IDirect3DRMTexture *texture1;
6598 IDirect3DRMTexture2 *texture2;
6599 IDirect3DRMTexture3 *texture3;
6600 IDirectDraw *ddraw = NULL;
6601 IDirect3DRM *d3drm1 = NULL;
6602 IDirect3DRM2 *d3drm2 = NULL;
6603 IDirect3DRM3 *d3drm3 = NULL;
6604 ULONG ref1, ref2, ref3;
6605 D3DRMIMAGE *image;
6606 DDSURFACEDESC desc;
6607 HWND window;
6608 HRESULT hr;
6609 RECT rc;
6611 hr = DirectDrawCreate(NULL, &ddraw, NULL);
6612 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
6614 window = create_window();
6615 GetClientRect(window, &rc);
6617 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6618 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6620 hr = Direct3DRMCreate(&d3drm1);
6621 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
6623 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
6624 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
6626 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
6627 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
6629 /* Create a surface and use it to create a texture. */
6630 memset(&desc, 0, sizeof(desc));
6631 desc.dwSize = sizeof(desc);
6632 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6633 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6634 desc.dwWidth = rc.right;
6635 desc.dwHeight = rc.bottom;
6637 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
6638 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6640 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface2, NULL);
6641 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6643 /* Test NULL params */
6644 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
6645 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, NULL, &texture1);
6646 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6647 ok(!texture1, "Expected texture returned == NULL, got %p.\n", texture1);
6649 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, NULL, NULL);
6650 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6652 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
6653 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, NULL, &texture2);
6654 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6655 ok(!texture2, "Expected texture returned == NULL, got %p.\n", texture2);
6657 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, NULL, NULL);
6658 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6660 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
6661 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, NULL, &texture3);
6662 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6663 ok(!texture3, "Expected texture returned == NULL, got %p.\n", texture3);
6665 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, NULL, NULL);
6666 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6668 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6669 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, surface, &texture1);
6670 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6672 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6673 image = IDirect3DRMTexture_GetImage(texture1);
6674 ok(image == NULL, "Unexpected image, %p.\n", image);
6675 hr = IDirect3DRMTexture_InitFromSurface(texture1, NULL);
6676 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6677 IDirect3DRMTexture_Release(texture1);
6679 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6680 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, surface, &texture2);
6681 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6682 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6683 image = IDirect3DRMTexture2_GetImage(texture2);
6684 ok(image == NULL, "Unexpected image, %p.\n", image);
6685 hr = IDirect3DRMTexture2_InitFromSurface(texture2, NULL);
6686 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6687 IDirect3DRMTexture_Release(texture2);
6689 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6690 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, surface, &texture3);
6691 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6692 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6693 image = IDirect3DRMTexture3_GetImage(texture3);
6694 ok(image == NULL, "Unexpected image, %p.\n", image);
6695 hr = IDirect3DRMTexture3_InitFromSurface(texture3, NULL);
6696 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6697 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, NULL);
6698 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6699 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &ds);
6700 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
6701 ok(ds == surface, "Expected same surface back.\n");
6702 IDirectDrawSurface_Release(ds);
6704 /* Init already initialized texture with same surface. */
6705 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface);
6706 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6708 /* Init already initialized texture with different surface. */
6709 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface2);
6710 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6712 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &ds);
6713 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
6714 ok(ds == surface, "Expected same surface back.\n");
6715 IDirectDrawSurface_Release(ds);
6717 ref1 = get_refcount((IUnknown *)d3drm1);
6718 ref2 = get_refcount((IUnknown *)d3drm2);
6719 ref3 = get_refcount((IUnknown *)d3drm3);
6720 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
6721 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6722 ok(ref1 < get_refcount((IUnknown *)d3drm1), "Expected d3drm1 reference taken.\n");
6723 ok(ref2 == get_refcount((IUnknown *)d3drm2), "Expected d3drm2 reference unchanged.\n");
6724 ok(ref3 == get_refcount((IUnknown *)d3drm3), "Expected d3drm3 reference unchanged.\n");
6725 /* Release leaked reference to d3drm1 */
6726 IDirect3DRM_Release(d3drm1);
6728 IDirect3DRMTexture_Release(texture3);
6730 /* Create from image, initialize from surface. */
6731 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
6732 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
6734 ref1 = get_refcount((IUnknown *)d3drm1);
6735 ref2 = get_refcount((IUnknown *)d3drm2);
6736 ref3 = get_refcount((IUnknown *)d3drm3);
6737 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface);
6738 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6739 ok(ref1 < get_refcount((IUnknown *)d3drm1), "Expected d3drm1 reference taken.\n");
6740 ok(ref2 == get_refcount((IUnknown *)d3drm2), "Expected d3drm2 reference unchanged.\n");
6741 ok(ref3 == get_refcount((IUnknown *)d3drm3), "Expected d3drm3 reference unchanged.\n");
6742 /* Release leaked reference to d3drm1 */
6743 IDirect3DRM_Release(d3drm1);
6744 IDirect3DRMTexture3_Release(texture3);
6746 IDirectDrawSurface_Release(surface2);
6747 IDirectDrawSurface_Release(surface);
6748 IDirect3DRM3_Release(d3drm3);
6749 IDirect3DRM2_Release(d3drm2);
6750 IDirect3DRM_Release(d3drm1);
6751 IDirectDraw_Release(ddraw);
6754 static void test_animation(void)
6756 IDirect3DRMAnimation2 *animation2;
6757 IDirect3DRMAnimation *animation;
6758 D3DRMANIMATIONOPTIONS options;
6759 IDirect3DRMObject *obj, *obj2;
6760 D3DRMANIMATIONKEY keys[10];
6761 IDirect3DRMFrame3 *frame3;
6762 IDirect3DRMFrame *frame;
6763 D3DRMANIMATIONKEY key;
6764 IDirect3DRM *d3drm1;
6765 D3DRMQUATERNION q;
6766 DWORD count, i;
6767 HRESULT hr;
6768 D3DVECTOR v;
6770 hr = Direct3DRMCreate(&d3drm1);
6771 ok(SUCCEEDED(hr), "Failed to create IDirect3DRM instance, hr 0x%08x.\n", hr);
6773 hr = IDirect3DRM_CreateAnimation(d3drm1, NULL);
6774 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr 0x%08x.\n", hr);
6776 CHECK_REFCOUNT(d3drm1, 1);
6777 hr = IDirect3DRM_CreateAnimation(d3drm1, &animation);
6778 ok(SUCCEEDED(hr), "Failed to create animation hr 0x%08x.\n", hr);
6779 CHECK_REFCOUNT(d3drm1, 2);
6781 test_class_name((IDirect3DRMObject *)animation, "Animation");
6783 hr = IDirect3DRMAnimation_QueryInterface(animation, &IID_IDirect3DRMAnimation2, (void **)&animation2);
6784 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMAnimation2, hr 0x%08x.\n", hr);
6785 ok(animation != (void *)animation2, "Expected different interface pointer.\n");
6787 hr = IDirect3DRMAnimation_QueryInterface(animation, &IID_IDirect3DRMObject, (void **)&obj);
6788 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, hr 0x%08x.\n", hr);
6790 hr = IDirect3DRMAnimation2_QueryInterface(animation2, &IID_IDirect3DRMObject, (void **)&obj2);
6791 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, hr 0x%08x.\n", hr);
6793 ok(obj == obj2 && obj == (IDirect3DRMObject *)animation, "Unexpected object pointer.\n");
6795 IDirect3DRMObject_Release(obj);
6796 IDirect3DRMObject_Release(obj2);
6798 /* Set animated frame, get it back. */
6799 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame);
6800 ok(SUCCEEDED(hr), "Failed to create a frame, hr %#x.\n", hr);
6802 hr = IDirect3DRMAnimation_SetFrame(animation, NULL);
6803 ok(SUCCEEDED(hr), "Failed to reset frame, hr %#x.\n", hr);
6805 CHECK_REFCOUNT(frame, 1);
6806 hr = IDirect3DRMAnimation_SetFrame(animation, frame);
6807 ok(SUCCEEDED(hr), "Failed to set a frame, hr %#x.\n", hr);
6808 CHECK_REFCOUNT(frame, 1);
6810 hr = IDirect3DRMAnimation2_GetFrame(animation2, NULL);
6811 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6813 hr = IDirect3DRMAnimation2_GetFrame(animation2, &frame3);
6814 ok(SUCCEEDED(hr), "Failed to get the frame, %#x.\n", hr);
6815 ok(frame3 != (void *)frame, "Unexpected interface pointer.\n");
6816 CHECK_REFCOUNT(frame, 2);
6818 IDirect3DRMFrame3_Release(frame3);
6820 hr = IDirect3DRMAnimation_SetFrame(animation, NULL);
6821 ok(SUCCEEDED(hr), "Failed to reset frame, hr %#x.\n", hr);
6823 hr = IDirect3DRMFrame_QueryInterface(frame, &IID_IDirect3DRMFrame3, (void **)&frame3);
6824 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMFrame3, hr %#x.\n", hr);
6826 CHECK_REFCOUNT(frame3, 2);
6827 hr = IDirect3DRMAnimation2_SetFrame(animation2, frame3);
6828 ok(SUCCEEDED(hr), "Failed to set a frame, hr %#x.\n", hr);
6829 CHECK_REFCOUNT(frame3, 2);
6831 IDirect3DRMFrame3_Release(frame3);
6832 IDirect3DRMFrame_Release(frame);
6834 /* Animation options. */
6835 options = IDirect3DRMAnimation_GetOptions(animation);
6836 ok(options == (D3DRMANIMATION_CLOSED | D3DRMANIMATION_LINEARPOSITION),
6837 "Unexpected default options %#x.\n", options);
6839 /* Undefined mask value */
6840 hr = IDirect3DRMAnimation_SetOptions(animation, 0xf0000000);
6841 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6843 options = IDirect3DRMAnimation_GetOptions(animation);
6844 ok(options == (D3DRMANIMATION_CLOSED | D3DRMANIMATION_LINEARPOSITION),
6845 "Unexpected default options %#x.\n", options);
6847 /* Ambiguous mask */
6848 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_OPEN | D3DRMANIMATION_CLOSED);
6849 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6851 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_LINEARPOSITION | D3DRMANIMATION_SPLINEPOSITION);
6852 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6854 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_SCALEANDROTATION | D3DRMANIMATION_POSITION);
6855 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6857 options = IDirect3DRMAnimation_GetOptions(animation);
6858 ok(options == (D3DRMANIMATION_CLOSED | D3DRMANIMATION_LINEARPOSITION),
6859 "Unexpected default options %#x.\n", options);
6861 /* Mask contains undefined bits together with valid one. */
6862 hr = IDirect3DRMAnimation_SetOptions(animation, 0xf0000000 | D3DRMANIMATION_OPEN);
6863 ok(SUCCEEDED(hr), "Failed to set animation options, hr %#x.\n", hr);
6865 options = IDirect3DRMAnimation_GetOptions(animation);
6866 ok(options == (0xf0000000 | D3DRMANIMATION_OPEN), "Unexpected animation options %#x.\n", options);
6868 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_SCALEANDROTATION);
6869 ok(SUCCEEDED(hr), "Failed to set animation options, hr %#x.\n", hr);
6871 options = IDirect3DRMAnimation_GetOptions(animation);
6872 ok(options == D3DRMANIMATION_SCALEANDROTATION, "Unexpected options %#x.\n", options);
6874 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_OPEN);
6875 ok(SUCCEEDED(hr), "Failed to set animation options, hr %#x.\n", hr);
6877 options = IDirect3DRMAnimation_GetOptions(animation);
6878 ok(options == D3DRMANIMATION_OPEN, "Unexpected options %#x.\n", options);
6880 hr = IDirect3DRMAnimation_SetOptions(animation, 0);
6881 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6883 options = IDirect3DRMAnimation_GetOptions(animation);
6884 ok(options == D3DRMANIMATION_OPEN, "Unexpected options %#x.\n", options);
6886 /* Key management. */
6887 hr = IDirect3DRMAnimation_AddPositionKey(animation, 0.0f, 1.0f, 0.0f, 0.0f);
6888 ok(SUCCEEDED(hr), "Failed to add position key, hr %#x.\n", hr);
6890 hr = IDirect3DRMAnimation_AddScaleKey(animation, 0.0f, 1.0f, 2.0f, 1.0f);
6891 ok(SUCCEEDED(hr), "Failed to add scale key, hr %#x.\n", hr);
6893 hr = IDirect3DRMAnimation_AddPositionKey(animation, 0.0f, 2.0f, 0.0f, 0.0f);
6894 ok(SUCCEEDED(hr), "Failed to add position key, hr %#x.\n", hr);
6896 hr = IDirect3DRMAnimation_AddPositionKey(animation, 99.0f, 3.0f, 1.0f, 0.0f);
6897 ok(SUCCEEDED(hr), "Failed to add position key, hr %#x.\n", hr);
6899 hr = IDirect3DRMAnimation_AddPositionKey(animation, 80.0f, 4.0f, 1.0f, 0.0f);
6900 ok(SUCCEEDED(hr), "Failed to add position key, hr %#x.\n", hr);
6902 v.x = 1.0f;
6903 v.y = 0.0f;
6904 v.z = 0.0f;
6905 D3DRMQuaternionFromRotation(&q, &v, 1.0f);
6907 /* NULL quaternion pointer leads to a crash on Windows. */
6908 hr = IDirect3DRMAnimation_AddRotateKey(animation, 0.0f, &q);
6909 ok(SUCCEEDED(hr), "Failed to add rotation key, hr %#.x\n", hr);
6911 count = 0;
6912 memset(keys, 0, sizeof(keys));
6913 hr = IDirect3DRMAnimation2_GetKeys(animation2, 0.0f, 99.0f, &count, keys);
6914 ok(SUCCEEDED(hr), "Failed to get animation keys, hr %#x.\n", hr);
6915 ok(count == 6, "Unexpected key count %u.\n", count);
6917 ok(keys[0].dwKeyType == D3DRMANIMATION_ROTATEKEY, "Unexpected key type %u.\n", keys[0].dwKeyType);
6918 ok(keys[1].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[1].dwKeyType);
6919 ok(keys[2].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[2].dwKeyType);
6920 ok(keys[3].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[3].dwKeyType);
6921 ok(keys[4].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[4].dwKeyType);
6922 ok(keys[5].dwKeyType == D3DRMANIMATION_SCALEKEY, "Unexpected key type %u.\n", keys[5].dwKeyType);
6924 /* Relative order, keys are returned sorted by time. */
6925 ok(keys[1].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[1].dvTime);
6926 ok(keys[2].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[2].dvTime);
6927 ok(keys[3].dvTime == 80.0f, "Unexpected key time %.8e.\n", keys[3].dvTime);
6928 ok(keys[4].dvTime == 99.0f, "Unexpected key time %.8e.\n", keys[4].dvTime);
6930 /* For keys with same time, order they were added in is kept. */
6931 ok(keys[1].dvPositionKey.x == 1.0f, "Unexpected key position x %.8e.\n", keys[1].dvPositionKey.x);
6932 ok(keys[2].dvPositionKey.x == 2.0f, "Unexpected key position x %.8e.\n", keys[2].dvPositionKey.x);
6933 ok(keys[3].dvPositionKey.x == 4.0f, "Unexpected key position x %.8e.\n", keys[3].dvPositionKey.x);
6934 ok(keys[4].dvPositionKey.x == 3.0f, "Unexpected key position x %.8e.\n", keys[4].dvPositionKey.x);
6936 for (i = 0; i < count; i++)
6938 ok(keys[i].dwSize == sizeof(*keys), "%u: unexpected dwSize value %u.\n", i, keys[i].dwSize);
6940 todo_wine
6942 switch (keys[i].dwKeyType)
6944 case D3DRMANIMATION_ROTATEKEY:
6945 ok((keys[i].dwID & 0xf0000000) == 0x40000000, "%u: unexpected id mask %#x.\n", i, keys[i].dwID);
6946 break;
6947 case D3DRMANIMATION_POSITIONKEY:
6948 ok((keys[i].dwID & 0xf0000000) == 0x80000000, "%u: unexpected id mask %#x.\n", i, keys[i].dwID);
6949 break;
6950 case D3DRMANIMATION_SCALEKEY:
6951 ok((keys[i].dwID & 0xf0000000) == 0xc0000000, "%u: unexpected id mask %#x.\n", i, keys[i].dwID);
6952 break;
6953 default:
6954 ok(0, "%u: unknown key type %d.\n", i, keys[i].dwKeyType);
6959 /* No keys in this range. */
6960 count = 10;
6961 hr = IDirect3DRMAnimation2_GetKeys(animation2, 100.0f, 200.0f, &count, NULL);
6962 ok(hr == D3DRMERR_NOSUCHKEY, "Unexpected hr %#x.\n", hr);
6963 ok(count == 0, "Unexpected key count %u.\n", count);
6965 count = 10;
6966 hr = IDirect3DRMAnimation2_GetKeys(animation2, 100.0f, 200.0f, &count, keys);
6967 ok(hr == D3DRMERR_NOSUCHKEY, "Unexpected hr %#x.\n", hr);
6968 ok(count == 0, "Unexpected key count %u.\n", count);
6970 count = 10;
6971 hr = IDirect3DRMAnimation2_GetKeys(animation2, 0.0f, 0.0f, &count, NULL);
6972 ok(SUCCEEDED(hr), "Failed to get animation keys, hr %#x.\n", hr);
6973 ok(count == 4, "Unexpected key count %u.\n", count);
6975 hr = IDirect3DRMAnimation2_GetKeys(animation2, 0.0f, 100.0f, NULL, NULL);
6976 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6978 /* Time is 0-based. */
6979 hr = IDirect3DRMAnimation2_GetKeys(animation2, -100.0f, -50.0f, NULL, NULL);
6980 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6982 count = 10;
6983 hr = IDirect3DRMAnimation2_GetKeys(animation2, -100.0f, -50.0f, &count, NULL);
6984 ok(hr == D3DRMERR_NOSUCHKEY, "Unexpected hr %#x.\n", hr);
6985 ok(count == 0, "Unexpected key count %u.\n", count);
6987 count = 10;
6988 hr = IDirect3DRMAnimation2_GetKeys(animation2, -100.0f, 100.0f, &count, NULL);
6989 ok(SUCCEEDED(hr), "Failed to get animation keys, hr %#x.\n", hr);
6990 ok(count == 6, "Unexpected key count %u.\n", count);
6992 /* AddKey() tests. */
6993 hr = IDirect3DRMAnimation2_AddKey(animation2, NULL);
6994 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
6996 memset(&key, 0, sizeof(key));
6997 key.dwKeyType = D3DRMANIMATION_POSITIONKEY;
6998 hr = IDirect3DRMAnimation2_AddKey(animation2, &key);
6999 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
7001 memset(&key, 0, sizeof(key));
7002 key.dwSize = sizeof(key) - 1;
7003 key.dwKeyType = D3DRMANIMATION_POSITIONKEY;
7004 hr = IDirect3DRMAnimation2_AddKey(animation2, &key);
7005 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
7007 memset(&key, 0, sizeof(key));
7008 key.dwSize = sizeof(key) + 1;
7009 key.dwKeyType = D3DRMANIMATION_POSITIONKEY;
7010 hr = IDirect3DRMAnimation2_AddKey(animation2, &key);
7011 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
7013 memset(&key, 0, sizeof(key));
7014 key.dwSize = sizeof(key);
7015 key.dwKeyType = D3DRMANIMATION_POSITIONKEY;
7016 key.dvPositionKey.x = 8.0f;
7017 hr = IDirect3DRMAnimation2_AddKey(animation2, &key);
7018 ok(SUCCEEDED(hr), "Failed to add key, hr %#x.\n", hr);
7020 /* Delete tests. */
7021 hr = IDirect3DRMAnimation_AddRotateKey(animation, 0.0f, &q);
7022 ok(SUCCEEDED(hr), "Failed to add rotation key, hr %#.x\n", hr);
7024 hr = IDirect3DRMAnimation_AddScaleKey(animation, 0.0f, 1.0f, 2.0f, 1.0f);
7025 ok(SUCCEEDED(hr), "Failed to add scale key, hr %#x.\n", hr);
7027 count = 0;
7028 memset(keys, 0, sizeof(keys));
7029 hr = IDirect3DRMAnimation2_GetKeys(animation2, -1000.0f, 1000.0f, &count, keys);
7030 ok(SUCCEEDED(hr), "Failed to get key count, hr %#x.\n", hr);
7031 ok(count == 9, "Unexpected key count %u.\n", count);
7033 ok(keys[0].dwKeyType == D3DRMANIMATION_ROTATEKEY, "Unexpected key type %u.\n", keys[0].dwKeyType);
7034 ok(keys[1].dwKeyType == D3DRMANIMATION_ROTATEKEY, "Unexpected key type %u.\n", keys[1].dwKeyType);
7035 ok(keys[2].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[2].dwKeyType);
7036 ok(keys[3].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[3].dwKeyType);
7037 ok(keys[4].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[4].dwKeyType);
7038 ok(keys[5].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[5].dwKeyType);
7039 ok(keys[6].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[6].dwKeyType);
7040 ok(keys[7].dwKeyType == D3DRMANIMATION_SCALEKEY, "Unexpected key type %u.\n", keys[7].dwKeyType);
7041 ok(keys[8].dwKeyType == D3DRMANIMATION_SCALEKEY, "Unexpected key type %u.\n", keys[8].dwKeyType);
7043 ok(keys[0].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[0].dvTime);
7044 ok(keys[1].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[1].dvTime);
7045 ok(keys[2].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[2].dvTime);
7046 ok(keys[3].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[3].dvTime);
7047 ok(keys[4].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[4].dvTime);
7048 ok(keys[5].dvTime == 80.0f, "Unexpected key time %.8e.\n", keys[5].dvTime);
7049 ok(keys[6].dvTime == 99.0f, "Unexpected key time %.8e.\n", keys[6].dvTime);
7050 ok(keys[7].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[7].dvTime);
7051 ok(keys[8].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[8].dvTime);
7053 hr = IDirect3DRMAnimation_DeleteKey(animation, -100.0f);
7054 ok(SUCCEEDED(hr), "Failed to delete keys, hr %#x.\n", hr);
7056 hr = IDirect3DRMAnimation_DeleteKey(animation, 100.0f);
7057 ok(SUCCEEDED(hr), "Failed to delete keys, hr %#x.\n", hr);
7059 /* Only first Position keys are not removed. */
7060 hr = IDirect3DRMAnimation_DeleteKey(animation, 0.0f);
7061 ok(SUCCEEDED(hr), "Failed to delete keys, hr %#x.\n", hr);
7063 count = 0;
7064 memset(keys, 0, sizeof(keys));
7065 hr = IDirect3DRMAnimation2_GetKeys(animation2, 0.0f, 100.0f, &count, keys);
7066 ok(SUCCEEDED(hr), "Failed to get key count, hr %#x.\n", hr);
7067 ok(count == 6, "Unexpected key count %u.\n", count);
7069 ok(keys[0].dwKeyType == D3DRMANIMATION_ROTATEKEY, "Unexpected key type %u.\n", keys[0].dwKeyType);
7070 ok(keys[1].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[1].dwKeyType);
7071 ok(keys[2].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[2].dwKeyType);
7072 ok(keys[3].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[3].dwKeyType);
7073 ok(keys[4].dwKeyType == D3DRMANIMATION_POSITIONKEY, "Unexpected key type %u.\n", keys[4].dwKeyType);
7074 ok(keys[5].dwKeyType == D3DRMANIMATION_SCALEKEY, "Unexpected key type %u.\n", keys[5].dwKeyType);
7076 ok(keys[0].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[0].dvTime);
7077 ok(keys[1].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[1].dvTime);
7078 ok(keys[2].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[2].dvTime);
7079 ok(keys[3].dvTime == 80.0f, "Unexpected key time %.8e.\n", keys[3].dvTime);
7080 ok(keys[4].dvTime == 99.0f, "Unexpected key time %.8e.\n", keys[4].dvTime);
7081 ok(keys[5].dvTime == 0.0f, "Unexpected key time %.8e.\n", keys[5].dvTime);
7083 hr = IDirect3DRMAnimation_DeleteKey(animation, 0.0f);
7084 ok(SUCCEEDED(hr), "Failed to delete keys, hr %#x.\n", hr);
7086 count = 0;
7087 hr = IDirect3DRMAnimation2_GetKeys(animation2, 0.0f, 100.0f, &count, NULL);
7088 ok(SUCCEEDED(hr), "Failed to get key count, hr %#x.\n", hr);
7089 ok(count == 3, "Unexpected key count %u.\n", count);
7091 IDirect3DRMAnimation2_Release(animation2);
7092 IDirect3DRMAnimation_Release(animation);
7094 IDirect3DRM_Release(d3drm1);
7097 static void test_animation_qi(void)
7099 static const struct qi_test tests[] =
7101 { &IID_IDirect3DRMAnimation2, &IID_IUnknown, &IID_IDirect3DRMAnimation2, S_OK },
7102 { &IID_IDirect3DRMAnimation, &IID_IUnknown, &IID_IDirect3DRMAnimation, S_OK },
7103 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7104 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7105 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMAnimation, S_OK },
7106 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7107 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7108 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7109 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7110 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7111 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7112 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7113 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7114 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7115 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7116 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7117 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7118 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7119 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7120 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7121 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7122 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7123 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7124 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7125 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7126 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7127 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7128 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7129 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7130 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7131 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7132 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7133 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7134 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7135 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7136 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7137 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7138 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7139 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7140 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7141 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7142 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7143 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7144 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7145 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7146 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7147 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7148 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7149 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7150 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7151 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7152 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7153 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7154 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7155 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7156 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7157 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7158 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7159 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7160 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7161 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7162 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7163 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK },
7165 IDirect3DRMAnimation2 *animation2;
7166 IDirect3DRMAnimation *animation;
7167 IDirect3DRM3 *d3drm3;
7168 IDirect3DRM *d3drm1;
7169 IUnknown *unknown;
7170 HRESULT hr;
7172 hr = Direct3DRMCreate(&d3drm1);
7173 ok(SUCCEEDED(hr), "Failed to create d3drm instance, hr %#x.\n", hr);
7175 hr = IDirect3DRM_CreateAnimation(d3drm1, &animation);
7176 ok(SUCCEEDED(hr), "Failed to create animation hr %#x.\n", hr);
7178 hr = IDirect3DRMAnimation_QueryInterface(animation, &IID_IUnknown, (void **)&unknown);
7179 ok(SUCCEEDED(hr), "Failed to get IUnknown from animation, hr %#x.\n", hr);
7180 IDirect3DRMAnimation_Release(animation);
7182 test_qi("animation_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
7183 IUnknown_Release(unknown);
7185 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
7186 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM3, hr %#x.\n", hr);
7188 hr = IDirect3DRM3_CreateAnimation(d3drm3, &animation2);
7189 ok(SUCCEEDED(hr), "Failed to create animation hr %#x.\n", hr);
7191 hr = IDirect3DRMAnimation2_QueryInterface(animation2, &IID_IUnknown, (void **)&unknown);
7192 ok(SUCCEEDED(hr), "Failed to get IUnknown from animation, hr %#x.\n", hr);
7193 IDirect3DRMAnimation2_Release(animation2);
7195 test_qi("animation2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
7196 IUnknown_Release(unknown);
7198 IDirect3DRM3_Release(d3drm3);
7199 IDirect3DRM_Release(d3drm1);
7202 static void test_wrap(void)
7204 IDirect3DRMWrap *wrap;
7205 IDirect3DRM *d3drm1;
7206 HRESULT hr;
7208 hr = Direct3DRMCreate(&d3drm1);
7209 ok(SUCCEEDED(hr), "Failed to create IDirect3DRM instance, hr %#x.\n", hr);
7211 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMWrap, NULL, &IID_IDirect3DRMWrap, (void **)&wrap);
7212 ok(SUCCEEDED(hr), "Failed to create wrap instance, hr %#x.\n", hr);
7214 test_class_name((IDirect3DRMObject *)wrap, "");
7216 IDirect3DRMWrap_Release(wrap);
7217 IDirect3DRM_Release(d3drm1);
7220 static void test_wrap_qi(void)
7222 static const struct qi_test tests[] =
7224 { &IID_IDirect3DRMWrap, &IID_IUnknown, &IID_IDirect3DRMWrap, S_OK },
7225 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7226 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7227 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMWrap, S_OK },
7228 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7229 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7230 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7231 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7232 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7233 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7234 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7235 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7236 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7237 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7238 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7239 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7240 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7241 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7242 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7243 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7244 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7245 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7246 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7247 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7248 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7249 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7250 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7251 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7252 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7253 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7254 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7255 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7256 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7257 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7258 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7259 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7260 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7261 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7262 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7263 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7264 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7265 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7266 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7267 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7268 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7269 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7270 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7271 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7272 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7273 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7274 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7275 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7276 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7277 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7278 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7279 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7280 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7281 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7282 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7283 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7284 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7285 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7286 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7287 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK },
7289 IDirect3DRMWrap *wrap;
7290 IDirect3DRM *d3drm1;
7291 IUnknown *unknown;
7292 HRESULT hr;
7294 hr = Direct3DRMCreate(&d3drm1);
7295 ok(SUCCEEDED(hr), "Failed to create d3drm instance, hr %#x.\n", hr);
7297 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMWrap, NULL, &IID_IDirect3DRMWrap, (void **)&wrap);
7298 ok(SUCCEEDED(hr), "Failed to create wrap instance, hr %#x.\n", hr);
7300 hr = IDirect3DRMWrap_QueryInterface(wrap, &IID_IUnknown, (void **)&unknown);
7301 ok(SUCCEEDED(hr), "Failed to get IUnknown from wrap (hr = %#x)\n", hr);
7302 IDirect3DRMWrap_Release(wrap);
7303 test_qi("wrap_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
7304 IUnknown_Release(unknown);
7306 IDirect3DRM_Release(d3drm1);
7308 START_TEST(d3drm)
7310 test_MeshBuilder();
7311 test_MeshBuilder3();
7312 test_Mesh();
7313 test_Face();
7314 test_Frame();
7315 test_Device();
7316 test_object();
7317 test_Viewport();
7318 test_Light();
7319 test_Material2();
7320 test_Texture();
7321 test_frame_transform();
7322 test_d3drm_load();
7323 test_frame_mesh_materials();
7324 test_d3drm_qi();
7325 test_frame_qi();
7326 test_device_qi();
7327 test_create_device_from_clipper1();
7328 test_create_device_from_clipper2();
7329 test_create_device_from_clipper3();
7330 test_create_device_from_surface1();
7331 test_create_device_from_surface2();
7332 test_create_device_from_surface3();
7333 test_create_device_from_d3d1();
7334 test_create_device_from_d3d2();
7335 test_create_device_from_d3d3();
7336 test_load_texture();
7337 test_texture_qi();
7338 test_viewport_qi();
7339 test_viewport_clear1();
7340 test_viewport_clear2();
7341 test_create_texture_from_surface();
7342 test_animation();
7343 test_animation_qi();
7344 test_wrap();
7345 test_wrap_qi();