d3drm/tests: Additional test for SetOptions().
[wine.git] / dlls / d3drm / tests / d3drm.c
blob950edb17972a1801a88e62b7bb6de5671d522cd5
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 ? 1 : 0;
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 DWORD count;
785 int icount;
787 hr = Direct3DRMCreate(&d3drm);
788 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
790 hr = IDirect3DRM_CreateFace(d3drm, &face1);
791 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
792 if (FAILED(hr))
794 skip("Cannot get IDirect3DRMFace interface (hr = %x), skipping tests\n", hr);
795 IDirect3DRM_Release(d3drm);
796 return;
799 hr = IDirect3DRMFace_QueryInterface(face1, &IID_IDirect3DRMObject, (void **)&obj);
800 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
801 ok(obj == (IDirect3DRMObject *)face1, "Unexpected interface pointer.\n");
802 IDirect3DRMObject_Release(obj);
804 test_class_name((IDirect3DRMObject *)face1, "Face");
805 test_object_name((IDirect3DRMObject *)face1);
807 icount = IDirect3DRMFace_GetVertexCount(face1);
808 ok(!icount, "wrong VertexCount: %i\n", icount);
810 IDirect3DRMFace_Release(face1);
812 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM2, (void **)&d3drm2)))
814 win_skip("Cannot get IDirect3DRM2 interface (hr = %x), skipping tests\n", hr);
815 IDirect3DRM_Release(d3drm);
816 return;
819 hr = IDirect3DRM2_CreateMeshBuilder(d3drm2, &MeshBuilder2);
820 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder2 interface (hr = %x)\n", hr);
822 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
823 ok(!icount, "wrong FaceCount: %i\n", icount);
825 array1 = NULL;
826 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
827 todo_wine
828 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
830 hr = IDirect3DRMMeshBuilder2_CreateFace(MeshBuilder2, &face1);
831 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
833 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
834 todo_wine
835 ok(icount == 1, "wrong FaceCount: %i\n", icount);
837 array1 = NULL;
838 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
839 todo_wine
840 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
841 todo_wine
842 ok(array1 != NULL, "pArray = %p\n", array1);
843 if (array1)
845 IDirect3DRMFace *face;
846 count = IDirect3DRMFaceArray_GetSize(array1);
847 ok(count == 1, "count = %u\n", count);
848 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
849 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
850 IDirect3DRMFace_Release(face);
851 IDirect3DRMFaceArray_Release(array1);
854 icount = IDirect3DRMFace_GetVertexCount(face1);
855 ok(!icount, "wrong VertexCount: %i\n", icount);
857 IDirect3DRMFace_Release(face1);
858 IDirect3DRMMeshBuilder2_Release(MeshBuilder2);
860 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
862 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
863 IDirect3DRM_Release(d3drm);
864 return;
867 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &MeshBuilder3);
868 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
870 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
871 ok(!icount, "wrong FaceCount: %i\n", icount);
873 hr = IDirect3DRMMeshBuilder3_CreateFace(MeshBuilder3, &face2);
874 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace2 interface (hr = %x)\n", hr);
876 hr = IDirect3DRMFace2_QueryInterface(face2, &IID_IDirect3DRMObject, (void **)&obj);
877 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
879 hr = IDirect3DRMFace2_QueryInterface(face2, &IID_IDirect3DRMFace, (void **)&face1);
880 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, %#x.\n", hr);
881 ok(obj == (IDirect3DRMObject *)face1, "Unexpected interface pointer.\n");
883 IDirect3DRMFace_Release(face1);
884 IDirect3DRMObject_Release(obj);
886 test_class_name((IDirect3DRMObject *)face2, "Face");
887 test_object_name((IDirect3DRMObject *)face2);
889 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
890 todo_wine
891 ok(icount == 1, "wrong FaceCount: %i\n", icount);
893 array1 = NULL;
894 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
895 todo_wine
896 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
897 todo_wine
898 ok(array1 != NULL, "pArray = %p\n", array1);
899 if (array1)
901 IDirect3DRMFace *face;
902 count = IDirect3DRMFaceArray_GetSize(array1);
903 ok(count == 1, "count = %u\n", count);
904 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
905 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
906 IDirect3DRMFace_Release(face);
907 IDirect3DRMFaceArray_Release(array1);
910 icount = IDirect3DRMFace2_GetVertexCount(face2);
911 ok(!icount, "wrong VertexCount: %i\n", icount);
913 info.lpMemory = data_ok;
914 info.dSize = strlen(data_ok);
915 hr = IDirect3DRMMeshBuilder3_Load(MeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
916 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
918 icount = IDirect3DRMMeshBuilder3_GetVertexCount(MeshBuilder3);
919 ok(icount == 4, "Wrong number of vertices %d (must be 4)\n", icount);
921 icount = IDirect3DRMMeshBuilder3_GetNormalCount(MeshBuilder3);
922 ok(icount == 4, "Wrong number of normals %d (must be 4)\n", icount);
924 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
925 todo_wine
926 ok(icount == 4, "Wrong number of faces %d (must be 4)\n", icount);
928 count = 4;
929 hr = IDirect3DRMMeshBuilder3_GetVertices(MeshBuilder3, 0, &count, v1);
930 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
931 ok(count == 4, "Wrong number of vertices %d (must be 4)\n", count);
933 hr = IDirect3DRMMeshBuilder3_GetNormals(MeshBuilder3, 0, &count, n1);
934 ok(hr == D3DRM_OK, "Cannot get normals information (hr = %x)\n", hr);
935 ok(count == 4, "Wrong number of normals %d (must be 4)\n", count);
937 array1 = NULL;
938 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
939 todo_wine
940 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
941 todo_wine
942 ok(array1 != NULL, "pArray = %p\n", array1);
943 if (array1)
945 IDirect3DRMFace *face;
946 count = IDirect3DRMFaceArray_GetSize(array1);
947 ok(count == 4, "count = %u\n", count);
948 hr = IDirect3DRMFaceArray_GetElement(array1, 1, &face);
949 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
950 hr = IDirect3DRMFace_GetVertices(face, &count, v2, n2);
951 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
952 ok(count == 3, "Wrong number of vertices %d (must be 3)\n", count);
954 vector_eq(&v1[0], &v2[0]);
955 vector_eq(&v1[1], &v2[1]);
956 vector_eq(&v1[2], &v2[2]);
958 vector_eq(&n1[0], &n2[0]);
959 vector_eq(&n1[1], &n2[1]);
960 vector_eq(&n1[2], &n2[2]);
962 IDirect3DRMFace_Release(face);
963 IDirect3DRMFaceArray_Release(array1);
966 IDirect3DRMFace2_Release(face2);
967 IDirect3DRMMeshBuilder3_Release(MeshBuilder3);
968 IDirect3DRM3_Release(d3drm3);
969 IDirect3DRM2_Release(d3drm2);
970 IDirect3DRM_Release(d3drm);
973 static void test_Frame(void)
975 HRESULT hr;
976 IDirect3DRM *d3drm;
977 IDirect3DRMFrame *pFrameC;
978 IDirect3DRMFrame *pFrameP1;
979 IDirect3DRMFrame *pFrameP2;
980 IDirect3DRMFrame *pFrameTmp;
981 IDirect3DRMFrame *scene_frame;
982 IDirect3DRMFrameArray *frame_array;
983 IDirect3DRMMeshBuilder *mesh_builder;
984 IDirect3DRMVisual *visual1;
985 IDirect3DRMVisual *visual_tmp;
986 IDirect3DRMVisualArray *visual_array;
987 IDirect3DRMLight *light1;
988 IDirect3DRMLight *light_tmp;
989 IDirect3DRMLightArray *light_array;
990 ULONG ref, ref2;
991 D3DCOLOR color;
992 DWORD count;
994 hr = Direct3DRMCreate(&d3drm);
995 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
997 ref = get_refcount((IUnknown *)d3drm);
998 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameC);
999 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1000 CHECK_REFCOUNT(pFrameC, 1);
1001 ref2 = get_refcount((IUnknown *)d3drm);
1002 ok(ref2 > ref, "Expected d3drm object to be referenced.\n");
1004 test_class_name((IDirect3DRMObject *)pFrameC, "Frame");
1005 test_object_name((IDirect3DRMObject *)pFrameC);
1007 hr = IDirect3DRMFrame_GetParent(pFrameC, NULL);
1008 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
1009 pFrameTmp = (void*)0xdeadbeef;
1010 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1011 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1012 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1013 CHECK_REFCOUNT(pFrameC, 1);
1015 frame_array = NULL;
1016 hr = IDirect3DRMFrame_GetChildren(pFrameC, &frame_array);
1017 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1018 ok(!!frame_array, "frame_array = %p\n", frame_array);
1019 if (frame_array)
1021 count = IDirect3DRMFrameArray_GetSize(frame_array);
1022 ok(count == 0, "count = %u\n", count);
1023 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1024 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1025 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1026 IDirect3DRMFrameArray_Release(frame_array);
1029 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP1);
1030 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1032 /* GetParent with NULL pointer */
1033 hr = IDirect3DRMFrame_GetParent(pFrameP1, NULL);
1034 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1035 CHECK_REFCOUNT(pFrameP1, 1);
1037 /* [Add/Delete]Child with NULL pointer */
1038 hr = IDirect3DRMFrame_AddChild(pFrameP1, NULL);
1039 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1040 CHECK_REFCOUNT(pFrameP1, 1);
1042 hr = IDirect3DRMFrame_DeleteChild(pFrameP1, NULL);
1043 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1044 CHECK_REFCOUNT(pFrameP1, 1);
1046 /* Add child to first parent */
1047 pFrameTmp = (void*)0xdeadbeef;
1048 hr = IDirect3DRMFrame_GetParent(pFrameP1, &pFrameTmp);
1049 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1050 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1052 hr = IDirect3DRMFrame_AddChild(pFrameP1, pFrameC);
1053 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1054 CHECK_REFCOUNT(pFrameP1, 1);
1055 CHECK_REFCOUNT(pFrameC, 2);
1057 hr = IDirect3DRMFrame_GetScene(pFrameC, NULL);
1058 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1059 hr = IDirect3DRMFrame_GetScene(pFrameC, &scene_frame);
1060 ok(SUCCEEDED(hr), "Cannot get scene (hr == %#x).\n", hr);
1061 ok(scene_frame == pFrameP1, "Expected scene frame == %p, got %p.\n", pFrameP1, scene_frame);
1062 CHECK_REFCOUNT(pFrameP1, 2);
1063 IDirect3DRMFrame_Release(scene_frame);
1064 hr = IDirect3DRMFrame_GetScene(pFrameP1, &scene_frame);
1065 ok(SUCCEEDED(hr), "Cannot get scene (hr == %#x).\n", hr);
1066 ok(scene_frame == pFrameP1, "Expected scene frame == %p, got %p.\n", pFrameP1, scene_frame);
1067 CHECK_REFCOUNT(pFrameP1, 2);
1068 IDirect3DRMFrame_Release(scene_frame);
1070 frame_array = NULL;
1071 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
1072 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1073 /* In some older version of d3drm, creating IDirect3DRMFrameArray object with GetChildren does not increment refcount of children frames */
1074 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
1075 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
1076 if (frame_array)
1078 count = IDirect3DRMFrameArray_GetSize(frame_array);
1079 ok(count == 1, "count = %u\n", count);
1080 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1081 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1082 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1083 ok((get_refcount((IUnknown*)pFrameC) == 4) || broken(get_refcount((IUnknown*)pFrameC) == 3),
1084 "Invalid refcount. Expected 4 (or 3) got %d\n", get_refcount((IUnknown*)pFrameC));
1085 IDirect3DRMFrame_Release(pFrameTmp);
1086 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
1087 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
1088 IDirect3DRMFrameArray_Release(frame_array);
1089 CHECK_REFCOUNT(pFrameC, 2);
1092 pFrameTmp = (void*)0xdeadbeef;
1093 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1094 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1095 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
1096 CHECK_REFCOUNT(pFrameP1, 2);
1097 IDirect3DRMFrame_Release(pFrameTmp);
1098 CHECK_REFCOUNT(pFrameP1, 1);
1100 /* Add child to second parent */
1101 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP2);
1102 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1104 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1105 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1106 CHECK_REFCOUNT(pFrameC, 2);
1108 frame_array = NULL;
1109 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1110 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1111 if (frame_array)
1113 count = IDirect3DRMFrameArray_GetSize(frame_array);
1114 ok(count == 1, "count = %u\n", count);
1115 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1116 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1117 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1118 IDirect3DRMFrame_Release(pFrameTmp);
1119 IDirect3DRMFrameArray_Release(frame_array);
1122 frame_array = NULL;
1123 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
1124 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1125 if (frame_array)
1127 count = IDirect3DRMFrameArray_GetSize(frame_array);
1128 ok(count == 0, "count = %u\n", count);
1129 pFrameTmp = (void*)0xdeadbeef;
1130 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1131 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1132 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1133 IDirect3DRMFrameArray_Release(frame_array);
1135 hr = IDirect3DRMFrame_GetScene(pFrameC, &scene_frame);
1136 ok(SUCCEEDED(hr), "Cannot get scene (hr == %#x).\n", hr);
1137 ok(scene_frame == pFrameP2, "Expected scene frame == %p, got %p.\n", pFrameP2, scene_frame);
1138 CHECK_REFCOUNT(pFrameP2, 2);
1139 IDirect3DRMFrame_Release(scene_frame);
1140 hr = IDirect3DRMFrame_GetScene(pFrameP2, &scene_frame);
1141 ok(SUCCEEDED(hr), "Cannot get scene (hr == %#x).\n", hr);
1142 ok(scene_frame == pFrameP2, "Expected scene frame == %p, got %p.\n", pFrameP2, scene_frame);
1143 CHECK_REFCOUNT(pFrameP2, 2);
1144 IDirect3DRMFrame_Release(scene_frame);
1146 pFrameTmp = (void*)0xdeadbeef;
1147 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1148 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1149 ok(pFrameTmp == pFrameP2, "pFrameTmp = %p\n", pFrameTmp);
1150 CHECK_REFCOUNT(pFrameP2, 2);
1151 CHECK_REFCOUNT(pFrameC, 2);
1152 IDirect3DRMFrame_Release(pFrameTmp);
1153 CHECK_REFCOUNT(pFrameP2, 1);
1155 /* Add child again */
1156 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1157 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1158 CHECK_REFCOUNT(pFrameC, 2);
1160 frame_array = NULL;
1161 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1162 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1163 if (frame_array)
1165 count = IDirect3DRMFrameArray_GetSize(frame_array);
1166 ok(count == 1, "count = %u\n", count);
1167 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1168 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1169 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1170 IDirect3DRMFrame_Release(pFrameTmp);
1171 IDirect3DRMFrameArray_Release(frame_array);
1174 /* Delete child */
1175 hr = IDirect3DRMFrame_DeleteChild(pFrameP2, pFrameC);
1176 ok(hr == D3DRM_OK, "Cannot delete child frame (hr = %x)\n", hr);
1177 CHECK_REFCOUNT(pFrameC, 1);
1179 frame_array = NULL;
1180 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1181 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1182 if (frame_array)
1184 count = IDirect3DRMFrameArray_GetSize(frame_array);
1185 ok(count == 0, "count = %u\n", count);
1186 pFrameTmp = (void*)0xdeadbeef;
1187 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1188 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1189 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1190 IDirect3DRMFrameArray_Release(frame_array);
1193 pFrameTmp = (void*)0xdeadbeef;
1194 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1195 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1196 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1198 /* Add two children */
1199 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1200 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1201 CHECK_REFCOUNT(pFrameC, 2);
1203 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameP1);
1204 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1205 CHECK_REFCOUNT(pFrameP1, 2);
1207 frame_array = NULL;
1208 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1209 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1210 if (frame_array)
1212 count = IDirect3DRMFrameArray_GetSize(frame_array);
1213 ok(count == 2, "count = %u\n", count);
1214 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1215 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1216 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1217 IDirect3DRMFrame_Release(pFrameTmp);
1218 hr = IDirect3DRMFrameArray_GetElement(frame_array, 1, &pFrameTmp);
1219 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1220 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
1221 IDirect3DRMFrame_Release(pFrameTmp);
1222 IDirect3DRMFrameArray_Release(frame_array);
1225 /* [Add/Delete]Visual with NULL pointer */
1226 hr = IDirect3DRMFrame_AddVisual(pFrameP1, NULL);
1227 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1228 CHECK_REFCOUNT(pFrameP1, 2);
1230 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, NULL);
1231 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1232 CHECK_REFCOUNT(pFrameP1, 2);
1234 /* Create Visual */
1235 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &mesh_builder);
1236 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
1237 visual1 = (IDirect3DRMVisual *)mesh_builder;
1239 /* Add Visual to first parent */
1240 hr = IDirect3DRMFrame_AddVisual(pFrameP1, visual1);
1241 ok(hr == D3DRM_OK, "Cannot add visual (hr = %x)\n", hr);
1242 CHECK_REFCOUNT(pFrameP1, 2);
1243 CHECK_REFCOUNT(visual1, 2);
1245 visual_array = NULL;
1246 hr = IDirect3DRMFrame_GetVisuals(pFrameP1, &visual_array);
1247 ok(hr == D3DRM_OK, "Cannot get visuals (hr = %x)\n", hr);
1248 if (visual_array)
1250 count = IDirect3DRMVisualArray_GetSize(visual_array);
1251 ok(count == 1, "count = %u\n", count);
1252 hr = IDirect3DRMVisualArray_GetElement(visual_array, 0, &visual_tmp);
1253 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1254 ok(visual_tmp == visual1, "visual_tmp = %p\n", visual_tmp);
1255 IDirect3DRMVisual_Release(visual_tmp);
1256 IDirect3DRMVisualArray_Release(visual_array);
1259 /* Delete Visual */
1260 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, visual1);
1261 ok(hr == D3DRM_OK, "Cannot delete visual (hr = %x)\n", hr);
1262 CHECK_REFCOUNT(pFrameP1, 2);
1263 IDirect3DRMMeshBuilder_Release(mesh_builder);
1265 /* [Add/Delete]Light with NULL pointer */
1266 hr = IDirect3DRMFrame_AddLight(pFrameP1, NULL);
1267 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1268 CHECK_REFCOUNT(pFrameP1, 2);
1270 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, NULL);
1271 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1272 CHECK_REFCOUNT(pFrameP1, 2);
1274 /* Create Light */
1275 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.1, 0.2, 0.3, &light1);
1276 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
1278 /* Add Light to first parent */
1279 hr = IDirect3DRMFrame_AddLight(pFrameP1, light1);
1280 ok(hr == D3DRM_OK, "Cannot add light (hr = %x)\n", hr);
1281 CHECK_REFCOUNT(pFrameP1, 2);
1282 CHECK_REFCOUNT(light1, 2);
1284 light_array = NULL;
1285 hr = IDirect3DRMFrame_GetLights(pFrameP1, &light_array);
1286 ok(hr == D3DRM_OK, "Cannot get lights (hr = %x)\n", hr);
1287 if (light_array)
1289 count = IDirect3DRMLightArray_GetSize(light_array);
1290 ok(count == 1, "count = %u\n", count);
1291 hr = IDirect3DRMLightArray_GetElement(light_array, 0, &light_tmp);
1292 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1293 ok(light_tmp == light1, "light_tmp = %p\n", light_tmp);
1294 IDirect3DRMLight_Release(light_tmp);
1295 IDirect3DRMLightArray_Release(light_array);
1298 /* Delete Light */
1299 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, light1);
1300 ok(hr == D3DRM_OK, "Cannot delete light (hr = %x)\n", hr);
1301 CHECK_REFCOUNT(pFrameP1, 2);
1302 IDirect3DRMLight_Release(light1);
1304 /* Test SceneBackground on first parent */
1305 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1306 ok(color == 0xff000000, "wrong color (%x)\n", color);
1308 hr = IDirect3DRMFrame_SetSceneBackground(pFrameP1, 0xff180587);
1309 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1310 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1311 ok(color == 0xff180587, "wrong color (%x)\n", color);
1313 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(pFrameP1, 0.5, 0.5, 0.5);
1314 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1315 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1316 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1318 /* Cleanup */
1319 IDirect3DRMFrame_Release(pFrameP2);
1320 CHECK_REFCOUNT(pFrameC, 1);
1321 CHECK_REFCOUNT(pFrameP1, 1);
1323 IDirect3DRMFrame_Release(pFrameC);
1324 IDirect3DRMFrame_Release(pFrameP1);
1326 IDirect3DRM_Release(d3drm);
1329 struct destroy_context
1331 IDirect3DRMObject *obj;
1332 unsigned int test_idx;
1333 int called;
1336 struct callback_order
1338 void *callback;
1339 void *context;
1340 } corder[3], d3drm_corder[3];
1342 static void CDECL destroy_callback(IDirect3DRMObject *obj, void *arg)
1344 struct destroy_context *ctxt = arg;
1345 ok(ctxt->called == 1 || ctxt->called == 2, "got called counter %d\n", ctxt->called);
1346 ok(obj == ctxt->obj, "called with %p, expected %p\n", obj, ctxt->obj);
1347 d3drm_corder[ctxt->called].callback = &destroy_callback;
1348 d3drm_corder[ctxt->called++].context = ctxt;
1351 static void CDECL destroy_callback1(IDirect3DRMObject *obj, void *arg)
1353 struct destroy_context *ctxt = (struct destroy_context*)arg;
1354 ok(ctxt->called == 0, "got called counter %d\n", ctxt->called);
1355 ok(obj == ctxt->obj, "called with %p, expected %p\n", obj, ctxt->obj);
1356 d3drm_corder[ctxt->called].callback = &destroy_callback1;
1357 d3drm_corder[ctxt->called++].context = ctxt;
1360 static void test_destroy_callback(unsigned int test_idx, REFCLSID clsid, REFIID iid)
1362 struct destroy_context context;
1363 IDirect3DRMObject *obj;
1364 IUnknown *unknown;
1365 IDirect3DRM *d3drm;
1366 HRESULT hr;
1367 int i;
1369 hr = Direct3DRMCreate(&d3drm);
1370 ok(SUCCEEDED(hr), "Test %u: Cannot get IDirect3DRM interface (hr = %x).\n", test_idx, hr);
1372 hr = IDirect3DRM_CreateObject(d3drm, clsid, NULL, iid, (void **)&unknown);
1373 ok(hr == D3DRM_OK, "Test %u: Cannot get IDirect3DRMObject interface (hr = %x).\n", test_idx, hr);
1374 hr = IUnknown_QueryInterface(unknown, &IID_IDirect3DRMObject, (void**)&obj);
1375 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1376 IUnknown_Release(unknown);
1378 context.called = 0;
1379 context.test_idx = test_idx;
1380 context.obj = obj;
1382 hr = IDirect3DRMObject_AddDestroyCallback(obj, NULL, &context);
1383 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected D3DRMERR_BADVALUE (hr = %x).\n", test_idx, hr);
1385 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1386 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1387 corder[2].callback = &destroy_callback;
1388 corder[2].context = &context;
1390 /* same callback added twice */
1391 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1392 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1393 corder[1].callback = &destroy_callback;
1394 corder[1].context = &context;
1396 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback1, NULL);
1397 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1399 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback1, &context);
1400 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1402 /* add one more */
1403 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback1, &context);
1404 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1405 corder[0].callback = &destroy_callback1;
1406 corder[0].context = &context;
1408 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, NULL, NULL);
1409 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected D3DRM_BADVALUE (hr = %x).\n", test_idx, hr);
1411 context.called = 0;
1412 IDirect3DRMObject_Release(obj);
1413 ok(context.called == 3, "Test %u: got %d, expected 3.\n", test_idx, context.called);
1414 for (i = 0; i < context.called; i++)
1416 ok(corder[i].callback == d3drm_corder[i].callback
1417 && corder[i].context == d3drm_corder[i].context,
1418 "Expected callback = %p, context = %p. Got callback = %p, context = %p.\n", d3drm_corder[i].callback,
1419 d3drm_corder[i].context, corder[i].callback, corder[i].context);
1422 /* test this pattern - add cb1, add cb2, add cb1, delete cb1 */
1423 hr = IDirect3DRM_CreateObject(d3drm, clsid, NULL, iid, (void **)&unknown);
1424 ok(hr == D3DRM_OK, "Test %u: Cannot get IDirect3DRMObject interface (hr = %x).\n", test_idx, hr);
1425 hr = IUnknown_QueryInterface(unknown, &IID_IDirect3DRMObject, (void**)&obj);
1426 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1427 IUnknown_Release(unknown);
1429 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1430 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1431 corder[1].callback = &destroy_callback;
1432 corder[1].context = &context;
1434 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback1, &context);
1435 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1436 corder[0].callback = &destroy_callback1;
1437 corder[0].context = &context;
1439 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1440 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1442 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback, &context);
1443 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1445 context.called = 0;
1446 hr = IDirect3DRMObject_QueryInterface(obj, &IID_IDirect3DRMObject, (void**)&context.obj);
1447 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1448 IDirect3DRMObject_Release(context.obj);
1449 IUnknown_Release(unknown);
1450 ok(context.called == 2, "Test %u: got %d, expected 2.\n", test_idx, context.called);
1451 for (i = 0; i < context.called; i++)
1453 ok(corder[i].callback == d3drm_corder[i].callback
1454 && corder[i].context == d3drm_corder[i].context,
1455 "Expected callback = %p, context = %p. Got callback = %p, context = %p.\n", d3drm_corder[i].callback,
1456 d3drm_corder[i].context, corder[i].callback, corder[i].context);
1460 static void test_object(void)
1462 static const struct
1464 REFCLSID clsid;
1465 REFIID iid;
1466 BOOL takes_d3drm_ref;
1468 tests[] =
1470 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice },
1471 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice2 },
1472 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice3 },
1473 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMWinDevice },
1474 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture },
1475 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture2 },
1476 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture3 },
1477 { &CLSID_CDirect3DRMViewport, &IID_IDirect3DRMViewport },
1478 { &CLSID_CDirect3DRMViewport, &IID_IDirect3DRMViewport2 },
1479 { &CLSID_CDirect3DRMFace, &IID_IDirect3DRMFace },
1480 { &CLSID_CDirect3DRMFace, &IID_IDirect3DRMFace2 },
1481 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder, TRUE },
1482 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder2, TRUE },
1483 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder3, TRUE },
1484 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame, TRUE },
1485 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame2, TRUE },
1486 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame3, TRUE },
1487 { &CLSID_CDirect3DRMLight, &IID_IDirect3DRMLight, TRUE },
1488 { &CLSID_CDirect3DRMMaterial, &IID_IDirect3DRMMaterial, TRUE },
1489 { &CLSID_CDirect3DRMMaterial, &IID_IDirect3DRMMaterial2, TRUE },
1490 { &CLSID_CDirect3DRMMesh, &IID_IDirect3DRMMesh, TRUE },
1491 { &CLSID_CDirect3DRMAnimation, &IID_IDirect3DRMAnimation, TRUE },
1492 { &CLSID_CDirect3DRMAnimation, &IID_IDirect3DRMAnimation2, TRUE },
1493 { &CLSID_CDirect3DRMWrap, &IID_IDirect3DRMWrap },
1495 IDirect3DRM *d3drm1;
1496 IDirect3DRM2 *d3drm2;
1497 IDirect3DRM3 *d3drm3;
1498 IUnknown *unknown = (IUnknown *)0xdeadbeef;
1499 HRESULT hr;
1500 ULONG ref1, ref2, ref3, ref4;
1501 int i;
1503 hr = Direct3DRMCreate(&d3drm1);
1504 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
1505 ref1 = get_refcount((IUnknown *)d3drm1);
1506 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1507 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
1508 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1509 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
1511 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_DirectDraw, NULL, &IID_IDirectDraw, (void **)&unknown);
1512 ok(hr == CLASSFACTORY_E_FIRST, "Expected hr == CLASSFACTORY_E_FIRST, got %#x.\n", hr);
1513 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1515 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1517 unknown = (IUnknown *)0xdeadbeef;
1518 hr = IDirect3DRM_CreateObject(d3drm1, NULL, NULL, tests[i].iid, (void **)&unknown);
1519 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1520 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1521 unknown = (IUnknown *)0xdeadbeef;
1522 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, NULL, (void **)&unknown);
1523 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1524 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1525 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, NULL, NULL);
1526 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1528 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1529 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1530 if (SUCCEEDED(hr))
1532 ref2 = get_refcount((IUnknown *)d3drm1);
1533 if (tests[i].takes_d3drm_ref)
1534 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1535 else
1536 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1538 ref3 = get_refcount((IUnknown *)d3drm2);
1539 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1540 ref4 = get_refcount((IUnknown *)d3drm3);
1541 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1542 IUnknown_Release(unknown);
1543 ref2 = get_refcount((IUnknown *)d3drm1);
1544 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1545 ref3 = get_refcount((IUnknown *)d3drm2);
1546 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1547 ref4 = get_refcount((IUnknown *)d3drm3);
1548 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1550 /* test Add/Destroy callbacks */
1551 test_destroy_callback(i, tests[i].clsid, tests[i].iid);
1553 hr = IDirect3DRM2_CreateObject(d3drm2, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1554 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1555 ref2 = get_refcount((IUnknown *)d3drm1);
1556 if (tests[i].takes_d3drm_ref)
1557 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1558 else
1559 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1560 ref3 = get_refcount((IUnknown *)d3drm2);
1561 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1562 ref4 = get_refcount((IUnknown *)d3drm3);
1563 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1564 IUnknown_Release(unknown);
1565 ref2 = get_refcount((IUnknown *)d3drm1);
1566 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1567 ref3 = get_refcount((IUnknown *)d3drm2);
1568 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1569 ref4 = get_refcount((IUnknown *)d3drm3);
1570 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1572 hr = IDirect3DRM3_CreateObject(d3drm3, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1573 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1574 ref2 = get_refcount((IUnknown *)d3drm1);
1575 if (tests[i].takes_d3drm_ref)
1576 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1577 else
1578 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1579 ref3 = get_refcount((IUnknown *)d3drm2);
1580 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1581 ref4 = get_refcount((IUnknown *)d3drm3);
1582 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1583 IUnknown_Release(unknown);
1584 ref2 = get_refcount((IUnknown *)d3drm1);
1585 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1586 ref3 = get_refcount((IUnknown *)d3drm2);
1587 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1588 ref4 = get_refcount((IUnknown *)d3drm3);
1589 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1593 IDirect3DRM_Release(d3drm1);
1594 IDirect3DRM2_Release(d3drm2);
1595 IDirect3DRM3_Release(d3drm3);
1598 static void test_Viewport(void)
1600 IDirectDrawClipper *clipper;
1601 HRESULT hr;
1602 IDirect3DRM *d3drm1;
1603 IDirect3DRM2 *d3drm2;
1604 IDirect3DRM3 *d3drm3;
1605 IDirect3DRMDevice *device1, *d3drm_device1;
1606 IDirect3DRMDevice3 *device3, *d3drm_device3;
1607 IDirect3DRMFrame *frame;
1608 IDirect3DRMFrame3 *frame3;
1609 IDirect3DRMViewport *viewport;
1610 IDirect3DRMViewport2 *viewport2;
1611 IDirect3DViewport *d3d_viewport;
1612 D3DVIEWPORT vp;
1613 D3DVALUE expected_val;
1614 IDirect3DRMObject *obj, *obj2;
1615 GUID driver;
1616 HWND window;
1617 RECT rc;
1618 DWORD data, ref1, ref2, ref3, ref4;
1619 DWORD initial_ref1, initial_ref2, initial_ref3, device_ref, frame_ref, frame_ref2, viewport_ref;
1621 window = create_window();
1622 GetClientRect(window, &rc);
1624 hr = Direct3DRMCreate(&d3drm1);
1625 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1626 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1627 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
1628 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1629 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
1630 initial_ref1 = get_refcount((IUnknown *)d3drm1);
1631 initial_ref2 = get_refcount((IUnknown *)d3drm2);
1632 initial_ref3 = get_refcount((IUnknown *)d3drm3);
1634 hr = DirectDrawCreateClipper(0, &clipper, NULL);
1635 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1637 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
1638 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
1640 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
1641 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
1642 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1643 hr = IDirect3DRMDevice3_QueryInterface(device3, &IID_IDirect3DRMDevice, (void **)&device1);
1644 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
1646 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame);
1647 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1648 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
1649 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %x).\n", hr);
1651 ref1 = get_refcount((IUnknown *)d3drm1);
1652 ref2 = get_refcount((IUnknown *)d3drm2);
1653 ref3 = get_refcount((IUnknown *)d3drm3);
1654 device_ref = get_refcount((IUnknown *)device1);
1655 frame_ref = get_refcount((IUnknown *)frame);
1657 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, 0, 0, 0, 0, &viewport);
1658 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1659 ref4 = get_refcount((IUnknown *)d3drm1);
1660 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1661 ref4 = get_refcount((IUnknown *)d3drm2);
1662 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1663 ref4 = get_refcount((IUnknown *)d3drm3);
1664 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1665 ref4 = get_refcount((IUnknown *)device1);
1666 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1667 ref4 = get_refcount((IUnknown *)frame);
1668 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1670 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1671 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1672 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device1, d3drm_device1);
1673 IDirect3DRMDevice_Release(d3drm_device1);
1675 IDirect3DRMViewport_Release(viewport);
1676 ref4 = get_refcount((IUnknown *)d3drm1);
1677 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1678 ref4 = get_refcount((IUnknown *)d3drm2);
1679 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1680 ref4 = get_refcount((IUnknown *)d3drm3);
1681 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1682 ref4 = get_refcount((IUnknown *)device1);
1683 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1684 ref4 = get_refcount((IUnknown *)frame);
1685 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1687 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, 0, 0, 0, 0, &viewport);
1688 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1689 ref4 = get_refcount((IUnknown *)d3drm1);
1690 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1691 ref4 = get_refcount((IUnknown *)d3drm2);
1692 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1693 ref4 = get_refcount((IUnknown *)d3drm3);
1694 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1695 ref4 = get_refcount((IUnknown *)device1);
1696 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1697 ref4 = get_refcount((IUnknown *)frame);
1698 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1700 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1701 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1702 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device1, d3drm_device1);
1703 IDirect3DRMDevice_Release(d3drm_device1);
1705 IDirect3DRMViewport_Release(viewport);
1706 ref4 = get_refcount((IUnknown *)d3drm1);
1707 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1708 ref4 = get_refcount((IUnknown *)d3drm2);
1709 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1710 ref4 = get_refcount((IUnknown *)d3drm3);
1711 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1712 ref4 = get_refcount((IUnknown *)device1);
1713 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1714 ref4 = get_refcount((IUnknown *)frame);
1715 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1717 device_ref = get_refcount((IUnknown *)device3);
1718 frame_ref2 = get_refcount((IUnknown *)frame3);
1720 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, 0, 0, 0, 0, &viewport2);
1721 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
1722 ref4 = get_refcount((IUnknown *)d3drm1);
1723 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1724 ref4 = get_refcount((IUnknown *)d3drm2);
1725 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1726 ref4 = get_refcount((IUnknown *)d3drm3);
1727 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1728 ref4 = get_refcount((IUnknown *)device3);
1729 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1730 ref4 = get_refcount((IUnknown *)frame3);
1731 ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
1733 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
1734 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
1735 ok(device3 == d3drm_device3, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
1736 IDirect3DRMDevice3_Release(d3drm_device3);
1738 IDirect3DRMViewport2_Release(viewport2);
1739 ref4 = get_refcount((IUnknown *)d3drm1);
1740 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1741 ref4 = get_refcount((IUnknown *)d3drm2);
1742 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1743 ref4 = get_refcount((IUnknown *)d3drm3);
1744 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1745 ref4 = get_refcount((IUnknown *)device3);
1746 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1747 ref4 = get_refcount((IUnknown *)frame3);
1748 ok(ref4 == frame_ref2, "Expected ref4 == frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
1750 /* Test all failures together */
1751 hr = IDirect3DRM_CreateViewport(d3drm1, NULL, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1752 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1753 hr = IDirect3DRM_CreateViewport(d3drm1, device1, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1754 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1755 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &viewport);
1756 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1757 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom, &viewport);
1758 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1759 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right, rc.bottom + 1, &viewport);
1760 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1761 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right, rc.bottom, NULL);
1762 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1764 hr = IDirect3DRM2_CreateViewport(d3drm2, NULL, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1765 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1766 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1767 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1768 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &viewport);
1769 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1770 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom, &viewport);
1771 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1772 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right, rc.bottom + 1, &viewport);
1773 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1774 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right, rc.bottom, NULL);
1775 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1777 hr = IDirect3DRM3_CreateViewport(d3drm3, NULL, frame3, rc.left, rc.top, rc.right, rc.bottom, &viewport2);
1778 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1779 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport2);
1780 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1781 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &viewport2);
1782 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1783 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom, &viewport2);
1784 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1785 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right, rc.bottom + 1, &viewport2);
1786 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1787 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right, rc.bottom, NULL);
1788 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1790 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1791 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1792 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1793 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1794 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1795 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1796 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1797 ref4 = get_refcount((IUnknown *)d3d_viewport);
1798 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1799 IDirect3DViewport_Release(d3d_viewport);
1800 ref4 = get_refcount((IUnknown *)d3d_viewport);
1801 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1802 IDirect3DViewport_Release(d3d_viewport);
1804 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1805 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1806 vp.dwSize = sizeof(vp);
1807 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1808 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1809 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1810 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1811 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1812 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1813 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1814 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1815 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1816 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1817 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1818 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1819 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1820 IDirect3DViewport_Release(d3d_viewport);
1821 IDirect3DRMViewport_Release(viewport);
1823 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right, rc.bottom, &viewport2);
1824 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
1825 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1826 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1827 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1828 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1829 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1830 ref4 = get_refcount((IUnknown *)d3d_viewport);
1831 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1832 IDirect3DViewport_Release(d3d_viewport);
1833 ref4 = get_refcount((IUnknown *)d3d_viewport);
1834 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1835 IDirect3DViewport_Release(d3d_viewport);
1837 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1838 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1839 vp.dwSize = sizeof(vp);
1840 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1841 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1842 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1843 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1844 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1845 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1846 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1847 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1848 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1849 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1850 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1851 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1852 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1853 IDirect3DViewport_Release(d3d_viewport);
1854 IDirect3DRMViewport2_Release(viewport2);
1856 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1857 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %x)\n", hr);
1858 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1859 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1860 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1861 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1862 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1863 ref4 = get_refcount((IUnknown *)d3d_viewport);
1864 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1865 IDirect3DViewport_Release(d3d_viewport);
1866 ref4 = get_refcount((IUnknown *)d3d_viewport);
1867 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1868 IDirect3DViewport_Release(d3d_viewport);
1870 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1871 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1872 vp.dwSize = sizeof(vp);
1873 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1874 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1875 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1876 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1877 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1878 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1879 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1880 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1881 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1882 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1883 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1884 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1885 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1886 IDirect3DViewport_Release(d3d_viewport);
1888 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMObject, (void**)&obj);
1889 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1890 ok((IDirect3DRMObject*)viewport == obj, "got object pointer %p, expected %p\n", obj, viewport);
1892 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMViewport2, (void**)&viewport2);
1893 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1895 hr = IDirect3DRMViewport2_QueryInterface(viewport2, &IID_IDirect3DRMObject, (void**)&obj2);
1896 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1897 ok(obj == obj2, "got object pointer %p, expected %p\n", obj2, obj);
1898 ok((IUnknown*)viewport != (IUnknown*)viewport2, "got viewport1 %p, viewport2 %p\n", viewport, viewport2);
1900 IDirect3DRMViewport2_Release(viewport2);
1901 IDirect3DRMObject_Release(obj);
1902 IDirect3DRMObject_Release(obj2);
1904 test_class_name((IDirect3DRMObject *)viewport, "Viewport");
1905 test_object_name((IDirect3DRMObject *)viewport);
1907 /* AppData */
1908 hr = IDirect3DRMViewport_SetAppData(viewport, 0);
1909 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1911 hr = IDirect3DRMViewport_SetAppData(viewport, 0);
1912 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1914 hr = IDirect3DRMViewport_SetAppData(viewport, 1);
1915 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1917 hr = IDirect3DRMViewport_SetAppData(viewport, 1);
1918 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1920 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMViewport2, (void**)&viewport2);
1921 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1923 data = IDirect3DRMViewport2_GetAppData(viewport2);
1924 ok(data == 1, "got %x\n", data);
1925 IDirect3DRMViewport2_Release(viewport2);
1926 IDirect3DRMViewport_Release(viewport);
1928 /* IDirect3DRMViewport*::Init tests */
1929 ref1 = get_refcount((IUnknown *)d3drm1);
1930 ref2 = get_refcount((IUnknown *)d3drm2);
1931 ref3 = get_refcount((IUnknown *)d3drm3);
1932 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMViewport, NULL, &IID_IDirect3DRMViewport,
1933 (void **)&viewport);
1934 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x).\n", hr);
1935 ref4 = get_refcount((IUnknown *)d3drm1);
1936 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1937 ref4 = get_refcount((IUnknown *)d3drm2);
1938 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1939 ref4 = get_refcount((IUnknown *)d3drm3);
1940 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1942 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1943 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1944 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1945 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1947 /* Test all failures together */
1948 hr = IDirect3DRMViewport_Init(viewport, NULL, frame, rc.left, rc.top, rc.right, rc.bottom);
1949 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1950 hr = IDirect3DRMViewport_Init(viewport, device1, NULL, rc.left, rc.top, rc.right, rc.bottom);
1951 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1952 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
1953 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1954 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom);
1955 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1956 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom + 1);
1957 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1959 device_ref = get_refcount((IUnknown *)device1);
1960 frame_ref = get_refcount((IUnknown *)frame);
1961 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom);
1962 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMViewport interface (hr = %#x).\n", hr);
1963 ref4 = get_refcount((IUnknown *)d3drm1);
1964 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1965 ref4 = get_refcount((IUnknown *)d3drm2);
1966 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1967 ref4 = get_refcount((IUnknown *)d3drm3);
1968 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1969 ref4 = get_refcount((IUnknown *)device1);
1970 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1971 ref4 = get_refcount((IUnknown *)frame);
1972 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1974 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1975 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
1976 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
1977 IDirect3DRMDevice_Release(d3drm_device1);
1979 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1980 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1981 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1982 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1983 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1984 ref4 = get_refcount((IUnknown *)d3d_viewport);
1985 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1986 IDirect3DViewport_Release(d3d_viewport);
1987 ref4 = get_refcount((IUnknown *)d3d_viewport);
1988 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1989 IDirect3DViewport_Release(d3d_viewport);
1991 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1992 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1993 vp.dwSize = sizeof(vp);
1994 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1995 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1996 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1997 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1998 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1999 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
2000 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
2001 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
2002 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
2003 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
2004 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
2005 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
2006 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
2007 IDirect3DViewport_Release(d3d_viewport);
2009 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom);
2010 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2012 IDirect3DRMViewport_Release(viewport);
2013 ref4 = get_refcount((IUnknown *)d3drm1);
2014 todo_wine ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2015 ref4 = get_refcount((IUnknown *)d3drm2);
2016 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2017 ref4 = get_refcount((IUnknown *)d3drm3);
2018 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2019 ref4 = get_refcount((IUnknown *)device1);
2020 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2021 ref4 = get_refcount((IUnknown *)frame);
2022 todo_wine ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
2024 ref1 = get_refcount((IUnknown *)d3drm1);
2025 ref2 = get_refcount((IUnknown *)d3drm2);
2026 ref3 = get_refcount((IUnknown *)d3drm3);
2027 hr = IDirect3DRM3_CreateObject(d3drm2, &CLSID_CDirect3DRMViewport, NULL, &IID_IDirect3DRMViewport2,
2028 (void **)&viewport2);
2029 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x).\n", hr);
2030 ref4 = get_refcount((IUnknown *)d3drm1);
2031 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2032 ref4 = get_refcount((IUnknown *)d3drm2);
2033 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2034 ref4 = get_refcount((IUnknown *)d3drm3);
2035 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2037 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2038 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2039 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
2040 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2042 hr = IDirect3DRMViewport2_Init(viewport2, NULL, frame3, rc.left, rc.top, rc.right, rc.bottom);
2043 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2044 hr = IDirect3DRMViewport2_Init(viewport2, device3, NULL, rc.left, rc.top, rc.right, rc.bottom);
2045 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2046 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom + 1);
2047 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2048 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom);
2049 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2050 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom + 1);
2051 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2053 device_ref = get_refcount((IUnknown *)device3);
2054 frame_ref2 = get_refcount((IUnknown *)frame3);
2055 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom);
2056 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMViewport2 interface (hr = %#x).\n", hr);
2057 ref4 = get_refcount((IUnknown *)device3);
2058 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2059 ref4 = get_refcount((IUnknown *)frame3);
2060 ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2062 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
2063 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
2064 ok(device3 == d3drm_device3, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
2065 IDirect3DRMDevice3_Release(d3drm_device3);
2067 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2068 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2069 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
2070 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2071 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2072 ref4 = get_refcount((IUnknown *)d3d_viewport);
2073 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
2074 IDirect3DViewport_Release(d3d_viewport);
2075 ref4 = get_refcount((IUnknown *)d3d_viewport);
2076 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
2077 IDirect3DViewport_Release(d3d_viewport);
2079 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2080 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2081 vp.dwSize = sizeof(vp);
2082 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
2083 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
2084 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
2085 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
2086 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
2087 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
2088 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
2089 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
2090 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
2091 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
2092 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
2093 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
2094 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
2095 IDirect3DViewport_Release(d3d_viewport);
2097 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom);
2098 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2100 IDirect3DRMViewport2_Release(viewport2);
2101 ref4 = get_refcount((IUnknown *)d3drm1);
2102 todo_wine ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2103 ref4 = get_refcount((IUnknown *)d3drm2);
2104 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2105 ref4 = get_refcount((IUnknown *)d3drm3);
2106 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2107 ref4 = get_refcount((IUnknown *)device3);
2108 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2109 ref4 = get_refcount((IUnknown *)frame3);
2110 todo_wine ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2112 IDirect3DRMDevice3_Release(device3);
2113 IDirect3DRMDevice_Release(device1);
2114 ref4 = get_refcount((IUnknown *)d3drm1);
2115 ok(ref4 > initial_ref1, "Expected ref4 > initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2116 ref4 = get_refcount((IUnknown *)d3drm2);
2117 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2118 ref4 = get_refcount((IUnknown *)d3drm3);
2119 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2120 ref4 = get_refcount((IUnknown *)frame);
2121 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
2122 ref4 = get_refcount((IUnknown *)frame3);
2123 ok(ref4 == frame_ref2, "Expected ref4 == frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2125 IDirect3DRMFrame3_Release(frame3);
2126 ref4 = get_refcount((IUnknown *)d3drm1);
2127 ok(ref4 > initial_ref1, "Expected ref4 > initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2128 ref4 = get_refcount((IUnknown *)d3drm2);
2129 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2130 ref4 = get_refcount((IUnknown *)d3drm3);
2131 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2133 IDirect3DRMFrame_Release(frame);
2134 ref4 = get_refcount((IUnknown *)d3drm1);
2135 ok(ref4 == initial_ref1, "Expected ref4 == initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2136 ref4 = get_refcount((IUnknown *)d3drm2);
2137 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2138 ref4 = get_refcount((IUnknown *)d3drm3);
2139 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2140 IDirectDrawClipper_Release(clipper);
2142 IDirect3DRM3_Release(d3drm3);
2143 IDirect3DRM2_Release(d3drm2);
2144 IDirect3DRM_Release(d3drm1);
2145 DestroyWindow(window);
2148 static void test_Light(void)
2150 IDirect3DRMObject *object;
2151 HRESULT hr;
2152 IDirect3DRM *d3drm;
2153 IDirect3DRMLight *light;
2154 D3DRMLIGHTTYPE type;
2155 D3DCOLOR color;
2157 hr = Direct3DRMCreate(&d3drm);
2158 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2160 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.5, 0.5, 0.5, &light);
2161 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
2163 hr = IDirect3DRMLight_QueryInterface(light, &IID_IDirect3DRMObject, (void **)&object);
2164 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, hr %#x.\n", hr);
2165 IDirect3DRMObject_Release(object);
2167 test_class_name((IDirect3DRMObject *)light, "Light");
2168 test_object_name((IDirect3DRMObject *)light);
2170 type = IDirect3DRMLight_GetType(light);
2171 ok(type == D3DRMLIGHT_SPOT, "wrong type (%u)\n", type);
2173 color = IDirect3DRMLight_GetColor(light);
2174 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
2176 hr = IDirect3DRMLight_SetType(light, D3DRMLIGHT_POINT);
2177 ok(hr == D3DRM_OK, "Cannot set type (hr = %x)\n", hr);
2178 type = IDirect3DRMLight_GetType(light);
2179 ok(type == D3DRMLIGHT_POINT, "wrong type (%u)\n", type);
2181 hr = IDirect3DRMLight_SetColor(light, 0xff180587);
2182 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
2183 color = IDirect3DRMLight_GetColor(light);
2184 ok(color == 0xff180587, "wrong color (%x)\n", color);
2186 hr = IDirect3DRMLight_SetColorRGB(light, 0.5, 0.5, 0.5);
2187 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
2188 color = IDirect3DRMLight_GetColor(light);
2189 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
2191 IDirect3DRMLight_Release(light);
2193 IDirect3DRM_Release(d3drm);
2196 static void test_Material2(void)
2198 HRESULT hr;
2199 IDirect3DRM *d3drm;
2200 IDirect3DRM3 *d3drm3;
2201 IDirect3DRMMaterial2 *material2;
2202 D3DVALUE r, g, b;
2204 hr = Direct3DRMCreate(&d3drm);
2205 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2207 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
2209 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
2210 IDirect3DRM_Release(d3drm);
2211 return;
2214 hr = IDirect3DRM3_CreateMaterial(d3drm3, 18.5f, &material2);
2215 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMaterial2 interface (hr = %x)\n", hr);
2217 test_class_name((IDirect3DRMObject *)material2, "Material");
2218 test_object_name((IDirect3DRMObject *)material2);
2220 r = IDirect3DRMMaterial2_GetPower(material2);
2221 ok(r == 18.5f, "wrong power (%f)\n", r);
2223 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
2224 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2225 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);
2227 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
2228 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2229 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);
2231 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
2232 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2233 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);
2235 hr = IDirect3DRMMaterial2_SetPower(material2, 5.87f);
2236 ok(hr == D3DRM_OK, "Cannot set power (hr = %x)\n", hr);
2237 r = IDirect3DRMMaterial2_GetPower(material2);
2238 ok(r == 5.87f, "wrong power (%f)\n", r);
2240 hr = IDirect3DRMMaterial2_SetEmissive(material2, 0.5f, 0.5f, 0.5f);
2241 ok(hr == D3DRM_OK, "Cannot set emissive (hr = %x)\n", hr);
2242 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
2243 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2244 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);
2246 hr = IDirect3DRMMaterial2_SetSpecular(material2, 0.6f, 0.6f, 0.6f);
2247 ok(hr == D3DRM_OK, "Cannot set specular (hr = %x)\n", hr);
2248 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
2249 ok(hr == D3DRM_OK, "Cannot get specular (hr = %x)\n", hr);
2250 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);
2252 hr = IDirect3DRMMaterial2_SetAmbient(material2, 0.7f, 0.7f, 0.7f);
2253 ok(hr == D3DRM_OK, "Cannot set ambient (hr = %x)\n", hr);
2254 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
2255 ok(hr == D3DRM_OK, "Cannot get ambient (hr = %x)\n", hr);
2256 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);
2258 IDirect3DRMMaterial2_Release(material2);
2260 IDirect3DRM3_Release(d3drm3);
2261 IDirect3DRM_Release(d3drm);
2264 static void test_Texture(void)
2266 HRESULT hr;
2267 IDirect3DRM *d3drm1;
2268 IDirect3DRM2 *d3drm2;
2269 IDirect3DRM3 *d3drm3;
2270 IDirect3DRMTexture *texture1;
2271 IDirect3DRMTexture2 *texture2;
2272 IDirect3DRMTexture3 *texture3;
2273 IDirectDrawSurface *surface;
2275 D3DRMIMAGE initimg =
2277 2, 2, 1, 1, 32,
2278 TRUE, 2 * sizeof(DWORD), NULL, NULL,
2279 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0, NULL
2281 testimg =
2283 0, 0, 0, 0, 0,
2284 TRUE, 0, (void *)0xcafebabe, NULL,
2285 0x000000ff, 0x0000ff00, 0x00ff0000, 0, 0, NULL
2287 *d3drm_img = NULL;
2289 DWORD pixel[4] = { 20000, 30000, 10000, 0 };
2290 ULONG ref1, ref2, ref3, ref4;
2292 hr = Direct3DRMCreate(&d3drm1);
2293 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2294 ref1 = get_refcount((IUnknown *)d3drm1);
2296 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2297 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2299 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2300 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2302 /* Test NULL params */
2303 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
2304 hr = IDirect3DRM_CreateTexture(d3drm1, NULL, &texture1);
2305 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2306 ok(!texture1, "Expected texture returned == NULL, got %p.\n", texture1);
2307 hr = IDirect3DRM_CreateTexture(d3drm1, NULL, NULL);
2308 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2310 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
2311 hr = IDirect3DRM2_CreateTexture(d3drm2, NULL, &texture2);
2312 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2313 ok(!texture2, "Expected texture returned == NULL, got %p.\n", texture2);
2314 hr = IDirect3DRM2_CreateTexture(d3drm2, NULL, NULL);
2315 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2317 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
2318 hr = IDirect3DRM3_CreateTexture(d3drm3, NULL, &texture3);
2319 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2320 ok(!texture3, "Expected texture returned == NULL, got %p.\n", texture3);
2321 hr = IDirect3DRM3_CreateTexture(d3drm3, NULL, NULL);
2322 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2324 /* Tests for validation of D3DRMIMAGE struct */
2325 hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
2326 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2327 hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
2328 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2329 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
2330 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2331 IDirect3DRMTexture_Release(texture1);
2332 IDirect3DRMTexture2_Release(texture2);
2333 IDirect3DRMTexture3_Release(texture3);
2335 testimg.rgb = 0;
2336 testimg.palette = (void *)0xdeadbeef;
2337 testimg.palette_size = 0x39;
2338 hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
2339 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2340 hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
2341 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2342 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
2343 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2344 IDirect3DRMTexture_Release(texture1);
2345 IDirect3DRMTexture2_Release(texture2);
2346 IDirect3DRMTexture3_Release(texture3);
2348 initimg.rgb = 0;
2349 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
2350 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2351 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2352 ok(!texture1, "Expected texture == NULL, got %p.\n", texture1);
2353 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
2354 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2355 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2356 ok(!texture2, "Expected texture == NULL, got %p.\n", texture2);
2357 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
2358 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2359 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2360 ok(!texture3, "Expected texture == NULL, got %p.\n", texture3);
2361 initimg.rgb = 1;
2362 initimg.red_mask = 0;
2363 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2364 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2365 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2366 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2367 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2368 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2369 initimg.red_mask = 0x000000ff;
2370 initimg.green_mask = 0;
2371 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2372 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2373 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2374 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2375 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2376 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2377 initimg.green_mask = 0x0000ff00;
2378 initimg.blue_mask = 0;
2379 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2380 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2381 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2382 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2383 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2384 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2385 initimg.blue_mask = 0x00ff0000;
2386 initimg.buffer1 = NULL;
2387 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2388 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2389 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2390 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2391 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2392 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2394 initimg.buffer1 = &pixel;
2395 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2396 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2397 ref2 = get_refcount((IUnknown *)d3drm1);
2398 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2399 ref3 = get_refcount((IUnknown *)d3drm2);
2400 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2401 ref4 = get_refcount((IUnknown *)d3drm3);
2402 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2403 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2404 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2405 ref2 = get_refcount((IUnknown *)d3drm1);
2406 ok(ref2 > ref1 + 1, "expected ref2 > (ref1 + 1), got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2407 ref3 = get_refcount((IUnknown *)d3drm2);
2408 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2409 ref4 = get_refcount((IUnknown *)d3drm3);
2410 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2411 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2412 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2413 ref2 = get_refcount((IUnknown *)d3drm1);
2414 ok(ref2 > ref1 + 2, "expected ref2 > (ref1 + 2), got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2415 ref3 = get_refcount((IUnknown *)d3drm2);
2416 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2417 ref4 = get_refcount((IUnknown *)d3drm3);
2418 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2420 /* Created from image, GetSurface() does not work. */
2421 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, NULL);
2422 ok(hr == D3DRMERR_BADVALUE, "GetSurface() expected to fail, %#x\n", hr);
2424 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &surface);
2425 ok(hr == D3DRMERR_NOTCREATEDFROMDDS, "GetSurface() expected to fail, %#x\n", hr);
2427 /* Test all failures together */
2428 test_class_name((IDirect3DRMObject *)texture1, "Texture");
2429 test_class_name((IDirect3DRMObject *)texture2, "Texture");
2430 test_class_name((IDirect3DRMObject *)texture3, "Texture");
2431 test_object_name((IDirect3DRMObject *)texture1);
2432 test_object_name((IDirect3DRMObject *)texture2);
2433 test_object_name((IDirect3DRMObject *)texture3);
2435 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
2436 ok(!!d3drm_img, "Failed to get image.\n");
2437 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2439 IDirect3DRMTexture_Release(texture1);
2440 ref2 = get_refcount((IUnknown *)d3drm1);
2441 ok(ref2 - 2 == ref1, "expected (ref2 - 2) == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2442 ref3 = get_refcount((IUnknown *)d3drm2);
2443 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2444 ref4 = get_refcount((IUnknown *)d3drm3);
2445 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2447 d3drm_img = NULL;
2448 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
2449 ok(!!d3drm_img, "Failed to get image.\n");
2450 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2452 IDirect3DRMTexture2_Release(texture2);
2453 ref2 = get_refcount((IUnknown *)d3drm1);
2454 ok(ref2 - 1 == ref1, "expected (ref2 - 1) == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2455 ref3 = get_refcount((IUnknown *)d3drm2);
2456 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2457 ref4 = get_refcount((IUnknown *)d3drm3);
2458 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2460 d3drm_img = NULL;
2461 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
2462 ok(!!d3drm_img, "Failed to get image.\n");
2463 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2465 IDirect3DRMTexture3_Release(texture3);
2466 ref2 = get_refcount((IUnknown *)d3drm1);
2467 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2468 ref3 = get_refcount((IUnknown *)d3drm2);
2469 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2470 ref4 = get_refcount((IUnknown *)d3drm3);
2471 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2473 /* InitFromImage tests */
2474 /* Tests for validation of D3DRMIMAGE struct */
2475 testimg.rgb = 1;
2476 testimg.palette = NULL;
2477 testimg.palette_size = 0;
2478 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2479 (void **)&texture2);
2480 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2481 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2482 (void **)&texture3);
2483 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2484 hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
2485 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2486 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
2487 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2488 IDirect3DRMTexture2_Release(texture2);
2489 IDirect3DRMTexture3_Release(texture3);
2491 testimg.rgb = 0;
2492 testimg.palette = (void *)0xdeadbeef;
2493 testimg.palette_size = 0x39;
2494 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2495 (void **)&texture2);
2496 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2497 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2498 (void **)&texture3);
2499 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2500 hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
2501 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2502 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
2503 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2504 IDirect3DRMTexture2_Release(texture2);
2505 IDirect3DRMTexture3_Release(texture3);
2507 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2508 (void **)&texture2);
2509 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2510 ref2 = get_refcount((IUnknown *)texture2);
2511 hr = IDirect3DRMTexture2_InitFromImage(texture2, NULL);
2512 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2513 ref3 = get_refcount((IUnknown *)texture2);
2514 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2516 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2517 (void **)&texture3);
2518 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2519 ref2 = get_refcount((IUnknown *)texture3);
2520 hr = IDirect3DRMTexture3_InitFromImage(texture3, NULL);
2521 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2522 ref3 = get_refcount((IUnknown *)texture3);
2523 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2525 initimg.rgb = 0;
2526 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2527 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2528 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2529 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2530 initimg.rgb = 1;
2531 initimg.red_mask = 0;
2532 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2533 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2534 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2535 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2536 initimg.red_mask = 0x000000ff;
2537 initimg.green_mask = 0;
2538 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2539 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2540 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2541 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2542 initimg.green_mask = 0x0000ff00;
2543 initimg.blue_mask = 0;
2544 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2545 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2546 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2547 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2548 initimg.blue_mask = 0x00ff0000;
2549 initimg.buffer1 = NULL;
2550 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2551 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2552 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2553 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2554 initimg.buffer1 = &pixel;
2556 d3drm_img = NULL;
2557 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2558 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 from image (hr = %#x).\n", hr);
2559 ref2 = get_refcount((IUnknown *)d3drm1);
2560 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2561 ref3 = get_refcount((IUnknown *)d3drm2);
2562 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2563 ref4 = get_refcount((IUnknown *)d3drm3);
2564 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2566 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2567 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2568 /* Release leaked reference to d3drm1 */
2569 IDirect3DRM_Release(d3drm1);
2571 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
2572 ok(!!d3drm_img, "Failed to get image.\n");
2573 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2574 IDirect3DRMTexture2_Release(texture2);
2575 ref2 = get_refcount((IUnknown *)d3drm1);
2576 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2577 ref3 = get_refcount((IUnknown *)d3drm2);
2578 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2579 ref4 = get_refcount((IUnknown *)d3drm3);
2580 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2582 d3drm_img = NULL;
2583 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2584 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 from image (hr = %#x).\n", hr);
2585 ref2 = get_refcount((IUnknown *)d3drm1);
2586 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2587 ref3 = get_refcount((IUnknown *)d3drm2);
2588 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2589 ref4 = get_refcount((IUnknown *)d3drm3);
2590 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2592 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2593 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2594 IDirect3DRM_Release(d3drm1);
2596 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
2597 ok(!!d3drm_img, "Failed to get image.\n");
2598 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2599 IDirect3DRMTexture3_Release(texture3);
2600 ref2 = get_refcount((IUnknown *)d3drm1);
2601 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2602 ref3 = get_refcount((IUnknown *)d3drm2);
2603 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2604 ref4 = get_refcount((IUnknown *)d3drm3);
2605 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2607 IDirect3DRM3_Release(d3drm3);
2608 IDirect3DRM2_Release(d3drm2);
2609 IDirect3DRM_Release(d3drm1);
2612 static void test_Device(void)
2614 IDirectDrawClipper *pClipper;
2615 HRESULT hr;
2616 IDirect3DRM *d3drm;
2617 IDirect3DRMDevice *device;
2618 IDirect3DRMWinDevice *win_device;
2619 GUID driver;
2620 HWND window;
2621 RECT rc;
2623 window = create_window();
2624 GetClientRect(window, &rc);
2626 hr = Direct3DRMCreate(&d3drm);
2627 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2629 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
2630 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
2632 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
2633 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
2635 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
2636 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
2637 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
2639 test_class_name((IDirect3DRMObject *)device, "Device");
2640 test_object_name((IDirect3DRMObject *)device);
2642 /* WinDevice */
2643 if (FAILED(hr = IDirect3DRMDevice_QueryInterface(device, &IID_IDirect3DRMWinDevice, (void **)&win_device)))
2645 win_skip("Cannot get IDirect3DRMWinDevice interface (hr = %x), skipping tests\n", hr);
2646 goto cleanup;
2649 test_class_name((IDirect3DRMObject *)win_device, "Device");
2650 test_object_name((IDirect3DRMObject *)win_device);
2651 IDirect3DRMWinDevice_Release(win_device);
2653 cleanup:
2654 IDirect3DRMDevice_Release(device);
2655 IDirectDrawClipper_Release(pClipper);
2657 IDirect3DRM_Release(d3drm);
2658 DestroyWindow(window);
2661 static void test_frame_transform(void)
2663 HRESULT hr;
2664 IDirect3DRM *d3drm;
2665 IDirect3DRMFrame *frame;
2666 D3DRMMATRIX4D matrix;
2668 hr = Direct3DRMCreate(&d3drm);
2669 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2671 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
2672 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
2674 hr = IDirect3DRMFrame_GetTransform(frame, matrix);
2675 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetTransform returned hr = %x\n", hr);
2676 ok(!memcmp(matrix, identity, sizeof(D3DRMMATRIX4D)), "Returned matrix is not identity\n");
2678 IDirect3DRMFrame_Release(frame);
2679 IDirect3DRM_Release(d3drm);
2682 static int nb_objects = 0;
2683 static const GUID* refiids[] =
2685 &IID_IDirect3DRMMeshBuilder,
2686 &IID_IDirect3DRMMeshBuilder,
2687 &IID_IDirect3DRMFrame,
2688 &IID_IDirect3DRMMaterial /* Not taken into account and not notified */
2691 static void __cdecl object_load_callback(IDirect3DRMObject *object, REFIID objectguid, void *arg)
2693 ok(object != NULL, "Arg 1 should not be null\n");
2694 ok(IsEqualGUID(objectguid, refiids[nb_objects]), "Arg 2 is incorrect\n");
2695 ok(arg == (void *)0xdeadbeef, "Arg 3 should be 0xdeadbeef (got %p)\n", arg);
2696 nb_objects++;
2699 static void test_d3drm_load(void)
2701 HRESULT hr;
2702 IDirect3DRM *d3drm;
2703 D3DRMLOADMEMORY info;
2704 const GUID* req_refiids[] = { &IID_IDirect3DRMMeshBuilder, &IID_IDirect3DRMFrame, &IID_IDirect3DRMMaterial };
2706 hr = Direct3DRMCreate(&d3drm);
2707 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2709 info.lpMemory = data_d3drm_load;
2710 info.dSize = strlen(data_d3drm_load);
2711 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID **)req_refiids, 3, D3DRMLOAD_FROMMEMORY,
2712 object_load_callback, (void *)0xdeadbeef, NULL, NULL, NULL);
2713 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
2714 ok(nb_objects == 3, "Should have loaded 3 objects (got %d)\n", nb_objects);
2716 IDirect3DRM_Release(d3drm);
2719 IDirect3DRMMeshBuilder *mesh_builder = NULL;
2721 static void __cdecl object_load_callback_frame(IDirect3DRMObject *object, REFIID object_guid, void *arg)
2723 HRESULT hr;
2724 IDirect3DRMFrame *frame;
2725 IDirect3DRMVisualArray *array;
2726 IDirect3DRMVisual *visual;
2727 ULONG size;
2728 char name[128];
2730 hr = IDirect3DRMObject_QueryInterface(object, &IID_IDirect3DRMFrame, (void**)&frame);
2731 ok(hr == D3DRM_OK, "IDirect3DRMObject_QueryInterface returned %x\n", hr);
2733 hr = IDirect3DRMFrame_GetVisuals(frame, &array);
2734 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetVisuals returned %x\n", hr);
2736 size = IDirect3DRMVisualArray_GetSize(array);
2737 ok(size == 1, "Wrong size %u returned, expected 1\n", size);
2739 hr = IDirect3DRMVisualArray_GetElement(array, 0, &visual);
2740 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetElement returned %x\n", hr);
2742 hr = IDirect3DRMVisual_QueryInterface(visual, &IID_IDirect3DRMMeshBuilder, (void**)&mesh_builder);
2743 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetSize returned %x\n", hr);
2745 size = sizeof(name);
2746 hr = IDirect3DRMMeshBuilder_GetName(mesh_builder, &size, name);
2747 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned %x\n", hr);
2748 ok(!strcmp(name, "mesh1"), "Wrong name %s, expected mesh1\n", name);
2750 IDirect3DRMVisual_Release(visual);
2751 IDirect3DRMVisualArray_Release(array);
2752 IDirect3DRMFrame_Release(frame);
2755 struct {
2756 int vertex_count;
2757 int face_count;
2758 int vertex_per_face;
2759 int face_data_size;
2760 DWORD color;
2761 float power;
2762 float specular[3];
2763 float emissive[3];
2764 } groups[3] = {
2765 { 4, 3, 3, 9, 0x4c0000ff, 30.0f, { 0.31f, 0.32f, 0.33f }, { 0.34f, 0.35f, 0.36f } },
2766 { 4, 2, 3, 6, 0x3300ff00, 20.0f, { 0.21f, 0.22f, 0.23f }, { 0.24f, 0.25f, 0.26f } },
2767 { 3, 1, 3, 3, 0x19ff0000, 10.0f, { 0.11f, 0.12f, 0.13f }, { 0.14f, 0.15f, 0.16f } }
2770 static void test_frame_mesh_materials(void)
2772 HRESULT hr;
2773 IDirect3DRM *d3drm;
2774 D3DRMLOADMEMORY info;
2775 const GUID *req_refiids[] = { &IID_IDirect3DRMFrame };
2776 IDirect3DRMMesh *mesh;
2777 ULONG size;
2778 IDirect3DRMMaterial *material;
2779 IDirect3DRMTexture *texture;
2780 int i;
2782 hr = Direct3DRMCreate(&d3drm);
2783 ok(hr == D3DRM_OK, "Direct3DRMCreate returned %x\n", hr);
2785 info.lpMemory = data_frame_mesh_materials;
2786 info.dSize = strlen(data_frame_mesh_materials);
2787 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID**)req_refiids, 1, D3DRMLOAD_FROMMEMORY, object_load_callback_frame, (void*)0xdeadbeef, NULL, NULL, NULL);
2788 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
2790 hr = IDirect3DRMMeshBuilder_CreateMesh(mesh_builder, &mesh);
2791 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_CreateMesh returned %x\n", hr);
2793 size = IDirect3DRMMesh_GetGroupCount(mesh);
2794 ok(size == 3, "Wrong size %u returned, expected 3\n", size);
2796 for (i = 0; i < size; i++)
2798 D3DVALUE red, green, blue, power;
2799 D3DCOLOR color;
2800 unsigned vertex_count, face_count, vertex_per_face;
2801 DWORD face_data_size;
2803 hr = IDirect3DRMMesh_GetGroup(mesh, i, &vertex_count, &face_count, &vertex_per_face, &face_data_size, NULL);
2804 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroup returned %x\n", i, hr);
2805 ok(vertex_count == groups[i].vertex_count, "Group %d: Wrong vertex count %d, expected %d\n", i, vertex_count, groups[i].vertex_count);
2806 ok(face_count == groups[i].face_count, "Group %d: Wrong face count %d; expected %d\n", i, face_count, groups[i].face_count);
2807 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);
2808 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);
2810 color = IDirect3DRMMesh_GetGroupColor(mesh, i);
2811 ok(color == groups[i].color, "Group %d: Wrong color %x, expected %x\n", i, color, groups[i].color);
2813 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, i, &material);
2814 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupMaterial returned %x\n", i, hr);
2815 ok(material != NULL, "Group %d: No material\n", i);
2816 power = IDirect3DRMMaterial_GetPower(material);
2817 ok(power == groups[i].power, "Group %d: Wrong power %f, expected %f\n", i, power, groups[i].power);
2818 hr = IDirect3DRMMaterial_GetSpecular(material, &red, &green, &blue);
2819 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetSpecular returned %x\n", i, hr);
2820 ok(red == groups[i].specular[0], "Group %d: Wrong specular red %f, expected %f\n", i, red, groups[i].specular[0]);
2821 ok(green == groups[i].specular[1], "Group %d: Wrong specular green %f, pD3DRMexpected %f\n", i, green, groups[i].specular[1]);
2822 ok(blue == groups[i].specular[2], "Group %d: Wrong specular blue %f, expected %f\n", i, blue, groups[i].specular[2]);
2823 hr = IDirect3DRMMaterial_GetEmissive(material, &red, &green, &blue);
2824 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetEmissive returned %x\n", i, hr);
2825 ok(red == groups[i].emissive[0], "Group %d: Wrong emissive red %f, expected %f\n", i, red, groups[i].emissive[0]);
2826 ok(green == groups[i].emissive[1], "Group %d: Wrong emissive green %f, expected %f\n", i, green, groups[i].emissive[1]);
2827 ok(blue == groups[i].emissive[2], "Group %d: Wrong emissive blue %f, expected %f\n", i, blue, groups[i].emissive[2]);
2829 hr = IDirect3DRMMesh_GetGroupTexture(mesh, i, &texture);
2830 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupTexture returned %x\n", i, hr);
2831 ok(!texture, "Group %d: Unexpected texture\n", i);
2833 if (material)
2834 IDirect3DRMMaterial_Release(material);
2835 if (texture)
2836 IDirect3DRMTexture_Release(texture);
2839 IDirect3DRMMesh_Release(mesh);
2840 IDirect3DRMMeshBuilder_Release(mesh_builder);
2841 IDirect3DRM_Release(d3drm);
2844 struct qi_test
2846 REFIID iid;
2847 REFIID refcount_iid;
2848 REFIID vtable_iid;
2849 HRESULT hr;
2852 static void test_qi(const char *test_name, IUnknown *base_iface,
2853 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
2855 ULONG refcount, expected_refcount;
2856 IUnknown *iface1, *iface2;
2857 HRESULT hr;
2858 UINT i, j;
2860 for (i = 0; i < entry_count; ++i)
2862 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
2863 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
2864 if (SUCCEEDED(hr))
2866 for (j = 0; j < entry_count; ++j)
2868 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
2869 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
2870 if (SUCCEEDED(hr))
2872 expected_refcount = 0;
2873 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
2874 ++expected_refcount;
2875 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
2876 ++expected_refcount;
2877 refcount = IUnknown_Release(iface2);
2878 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2879 refcount, test_name, i, j, expected_refcount);
2880 if (tests[i].vtable_iid && tests[j].vtable_iid && IsEqualGUID(tests[i].vtable_iid, tests[j].vtable_iid))
2881 ok(iface1 == iface2,
2882 "Expected iface1 == iface2 for test \"%s\" %u, %u. Got iface1 = %p, iface 2 = %p.\n",
2883 test_name, i, j, iface1, iface2);
2884 else if (tests[i].vtable_iid && tests[j].vtable_iid)
2885 ok(iface1 != iface2,
2886 "Expected iface1 != iface2 for test \"%s\" %u, %u. Got iface1 == iface2 == %p.\n",
2887 test_name, i, j, iface1);
2891 expected_refcount = 0;
2892 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
2893 ++expected_refcount;
2894 refcount = IUnknown_Release(iface1);
2895 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2896 refcount, test_name, i, expected_refcount);
2901 static void test_d3drm_qi(void)
2903 static const struct qi_test tests[] =
2905 { &IID_IDirect3DRM3, &IID_IDirect3DRM3, &IID_IDirect3DRM3, S_OK },
2906 { &IID_IDirect3DRM2, &IID_IDirect3DRM2, &IID_IDirect3DRM2, S_OK },
2907 { &IID_IDirect3DRM, &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK },
2908 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2909 { &IID_IDirect3DRMObject, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2910 { &IID_IDirect3DRMObject2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2911 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2912 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2913 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2914 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2915 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2916 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2917 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2918 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2919 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2920 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2921 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2922 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2923 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2924 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2925 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2926 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2927 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2928 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2929 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2930 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2931 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2932 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2933 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2934 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2935 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2936 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2937 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2938 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2939 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2940 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2941 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2942 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2943 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2944 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2945 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2946 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2947 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2948 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2949 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2950 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2951 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2952 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2953 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2954 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2955 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2956 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2957 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2958 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2959 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2960 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2961 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2962 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2963 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2964 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2965 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2966 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2967 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2968 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2969 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2970 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2971 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2972 { &IID_IUnknown, &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK },
2974 HRESULT hr;
2975 IDirect3DRM *d3drm;
2977 hr = Direct3DRMCreate(&d3drm);
2978 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2980 test_qi("d3drm_qi", (IUnknown *)d3drm, &IID_IDirect3DRM, tests, sizeof(tests) / sizeof(*tests));
2982 IDirect3DRM_Release(d3drm);
2985 static void test_frame_qi(void)
2987 static const struct qi_test tests[] =
2989 { &IID_IDirect3DRMFrame3, &IID_IUnknown, &IID_IDirect3DRMFrame3, S_OK },
2990 { &IID_IDirect3DRMFrame2, &IID_IUnknown, &IID_IDirect3DRMFrame2, S_OK },
2991 { &IID_IDirect3DRMFrame, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
2992 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2993 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2994 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
2995 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2996 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2997 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2998 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2999 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3000 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3001 { &IID_IDirect3DRMVisual, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
3002 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3003 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3004 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3005 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3006 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3007 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3008 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3009 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3010 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3011 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3012 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3013 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3014 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3015 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3016 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3017 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3018 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3019 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3020 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3021 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3022 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3023 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3024 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3025 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3026 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3027 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3028 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3029 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3030 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3031 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3032 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3033 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3034 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3035 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3036 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3037 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3038 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3039 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3040 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3041 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3042 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3043 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3044 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3045 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3046 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3047 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3048 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3049 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3050 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3051 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3052 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3053 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3054 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3055 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK },
3057 HRESULT hr;
3058 IDirect3DRM *d3drm1;
3059 IDirect3DRM2 *d3drm2;
3060 IDirect3DRM3 *d3drm3;
3061 IDirect3DRMFrame *frame1;
3062 IDirect3DRMFrame2 *frame2;
3063 IDirect3DRMFrame3 *frame3;
3064 IUnknown *unknown;
3066 hr = Direct3DRMCreate(&d3drm1);
3067 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
3069 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
3070 ok(hr == D3DRM_OK, "Failed to create frame1 (hr = %x)\n", hr);
3071 hr = IDirect3DRMFrame_QueryInterface(frame1, &IID_IUnknown, (void **)&unknown);
3072 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame1 (hr = %x)\n", hr);
3073 IDirect3DRMFrame_Release(frame1);
3074 test_qi("frame1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3075 IUnknown_Release(unknown);
3077 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3078 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3079 hr = IDirect3DRM2_CreateFrame(d3drm2, NULL, &frame2);
3080 ok(hr == D3DRM_OK, "Failed to create frame2 (hr = %x)\n", hr);
3081 hr = IDirect3DRMFrame2_QueryInterface(frame2, &IID_IUnknown, (void **)&unknown);
3082 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame2 (hr = %x)\n", hr);
3083 IDirect3DRMFrame2_Release(frame2);
3084 test_qi("frame2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3085 IUnknown_Release(unknown);
3087 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3088 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3089 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
3090 ok(hr == D3DRM_OK, "Failed to create frame3 (hr = %x)\n", hr);
3091 hr = IDirect3DRMFrame3_QueryInterface(frame3, &IID_IUnknown, (void **)&unknown);
3092 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame3 (hr = %x)\n", hr);
3093 IDirect3DRMFrame3_Release(frame3);
3094 test_qi("frame3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3095 IUnknown_Release(unknown);
3097 IDirect3DRM3_Release(d3drm3);
3098 IDirect3DRM2_Release(d3drm2);
3099 IDirect3DRM_Release(d3drm1);
3102 static void test_device_qi(void)
3104 static const struct qi_test tests[] =
3106 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3107 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3108 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3109 { &IID_IDirect3DRMDevice, &IID_IUnknown, &IID_IDirect3DRMDevice, S_OK, },
3110 { &IID_IDirect3DRMDevice2, &IID_IUnknown, &IID_IDirect3DRMDevice2, S_OK, },
3111 { &IID_IDirect3DRMDevice3, &IID_IUnknown, &IID_IDirect3DRMDevice3, S_OK, },
3112 { &IID_IDirect3DRMWinDevice, &IID_IUnknown, &IID_IDirect3DRMWinDevice, S_OK, },
3113 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMDevice, S_OK, },
3114 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3115 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3116 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3117 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3118 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3119 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3120 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3121 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3122 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3123 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3124 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3125 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3126 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3127 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3128 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3129 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3130 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3131 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3132 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3133 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3134 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3135 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3136 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3137 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3138 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3139 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3140 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3141 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3142 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3143 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3144 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3145 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3146 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3147 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3148 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3149 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3150 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3151 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3152 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3153 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3154 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3155 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3156 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3157 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3158 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3159 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3160 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3161 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3162 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3163 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3164 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3165 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3166 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3167 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3168 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3169 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3170 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3171 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3172 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3173 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
3175 HRESULT hr;
3176 IDirect3DRM *d3drm1;
3177 IDirect3DRM2 *d3drm2;
3178 IDirect3DRM3 *d3drm3;
3179 IDirectDrawClipper *clipper;
3180 IDirect3DRMDevice *device1;
3181 IDirect3DRMDevice2 *device2;
3182 IDirect3DRMDevice3 *device3;
3183 IUnknown *unknown;
3184 HWND window;
3185 GUID driver;
3186 RECT rc;
3188 window = create_window();
3189 GetClientRect(window, &rc);
3190 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3191 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
3192 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3193 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
3195 hr = Direct3DRMCreate(&d3drm1);
3196 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
3197 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
3198 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
3199 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
3200 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IUnknown, (void **)&unknown);
3201 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice (hr = %x)\n", hr);
3202 IDirect3DRMDevice_Release(device1);
3203 test_qi("device1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3204 IUnknown_Release(unknown);
3206 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3207 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3208 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
3209 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %x)\n", hr);
3210 hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IUnknown, (void **)&unknown);
3211 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice2 (hr = %x)\n", hr);
3212 IDirect3DRMDevice2_Release(device2);
3213 test_qi("device2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3214 IUnknown_Release(unknown);
3216 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3217 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3218 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
3219 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
3220 IDirect3DRMDevice3_QueryInterface(device3, &IID_IUnknown, (void **)&unknown);
3221 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice3 (hr = %x)\n", hr);
3222 IDirect3DRMDevice3_Release(device3);
3223 test_qi("device3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3224 IUnknown_Release(unknown);
3226 IDirectDrawClipper_Release(clipper);
3227 IDirect3DRM3_Release(d3drm3);
3228 IDirect3DRM2_Release(d3drm2);
3229 IDirect3DRM_Release(d3drm1);
3230 DestroyWindow(window);
3234 static HRESULT CALLBACK surface_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
3236 IDirectDrawSurface **primary = context;
3238 if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
3240 *primary = surface;
3241 return DDENUMRET_CANCEL;
3243 IDirectDrawSurface_Release(surface);
3245 return DDENUMRET_OK;
3248 static void test_create_device_from_clipper1(void)
3250 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3251 IDirect3DRM *d3drm1 = NULL;
3252 IDirectDraw *ddraw = NULL;
3253 IUnknown *unknown = NULL;
3254 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3255 IDirect3DDevice *d3ddevice1 = NULL;
3256 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3257 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3258 IDirectDrawSurface7 *surface7 = NULL;
3259 DDSURFACEDESC desc, surface_desc;
3260 DWORD expected_flags, ret_val;
3261 HWND window;
3262 GUID driver = IID_IDirect3DRGBDevice;
3263 HRESULT hr;
3264 ULONG ref1, ref2, cref1, cref2;
3265 RECT rc;
3267 window = create_window();
3268 GetClientRect(window, &rc);
3269 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3270 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3271 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3272 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3274 hr = Direct3DRMCreate(&d3drm1);
3275 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3276 ref1 = get_refcount((IUnknown *)d3drm1);
3277 cref1 = get_refcount((IUnknown *)clipper);
3279 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 0, 0, &device1);
3280 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3281 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3283 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3284 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, NULL, &driver, 300, 200, &device1);
3285 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3287 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, NULL);
3288 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3290 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, &device1);
3291 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3292 ref2 = get_refcount((IUnknown *)d3drm1);
3293 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3294 cref2 = get_refcount((IUnknown *)clipper);
3295 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3296 ret_val = IDirect3DRMDevice_GetWidth(device1);
3297 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3298 ret_val = IDirect3DRMDevice_GetHeight(device1);
3299 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3301 /* Fetch immediate mode device in order to access render target */
3302 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3303 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3305 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
3306 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3308 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3309 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3311 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3312 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3313 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3314 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3315 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3316 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3317 IUnknown_Release(unknown);
3318 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3319 NULL, &d3drm_primary, surface_callback);
3320 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3321 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3322 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3323 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3324 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3326 IDirectDrawClipper_Release(d3drm_clipper);
3327 IDirectDrawSurface_Release(d3drm_primary);
3328 IDirectDrawSurface7_Release(surface7);
3329 IDirectDraw_Release(ddraw);
3331 /* Check properties of render target and depth surface */
3332 surface_desc.dwSize = sizeof(surface_desc);
3333 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3334 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3336 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3337 surface_desc.dwWidth, surface_desc.dwHeight);
3338 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3339 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3340 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3341 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3343 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3344 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3345 desc.dwSize = sizeof(desc);
3346 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3347 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3348 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3349 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3351 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3352 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3354 desc.dwSize = sizeof(desc);
3355 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3356 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3358 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3359 desc.dwWidth, desc.dwHeight);
3360 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3361 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3362 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3363 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3364 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3366 /* Release old objects and check refcount of device and clipper */
3367 IDirectDrawSurface_Release(ds);
3368 ds = NULL;
3369 IDirectDrawSurface_Release(surface);
3370 surface = NULL;
3371 IDirect3DDevice_Release(d3ddevice1);
3372 d3ddevice1 = NULL;
3373 IDirect3DRMDevice_Release(device1);
3374 ref2 = get_refcount((IUnknown *)d3drm1);
3375 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
3376 cref2 = get_refcount((IUnknown *)clipper);
3377 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3379 /* Test if render target format follows the screen format */
3380 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3381 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3382 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3383 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3385 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3386 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3387 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3389 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
3390 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3392 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3393 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3395 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
3396 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3398 surface_desc.dwSize = sizeof(surface_desc);
3399 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3400 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3401 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3402 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3404 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3405 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3407 if (ds)
3408 IDirectDrawSurface_Release(ds);
3409 IDirectDrawSurface_Release(surface);
3410 IDirect3DDevice_Release(d3ddevice1);
3411 IDirect3DRMDevice_Release(device1);
3412 IDirect3DRM_Release(d3drm1);
3413 IDirectDrawClipper_Release(clipper);
3414 IDirectDraw_Release(ddraw);
3415 DestroyWindow(window);
3418 static void test_create_device_from_clipper2(void)
3420 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3421 IDirect3DRM *d3drm1 = NULL;
3422 IDirect3DRM2 *d3drm2 = NULL;
3423 IDirectDraw *ddraw = NULL;
3424 IUnknown *unknown = NULL;
3425 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
3426 IDirect3DDevice2 *d3ddevice2 = NULL;
3427 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3428 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3429 IDirectDrawSurface7 *surface7 = NULL;
3430 DDSURFACEDESC desc, surface_desc;
3431 DWORD expected_flags, ret_val;
3432 HWND window;
3433 GUID driver = IID_IDirect3DRGBDevice;
3434 HRESULT hr;
3435 ULONG ref1, ref2, ref3, cref1, cref2;
3436 RECT rc;
3438 window = create_window();
3439 GetClientRect(window, &rc);
3440 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3441 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3442 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3443 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3445 hr = Direct3DRMCreate(&d3drm1);
3446 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3447 ref1 = get_refcount((IUnknown *)d3drm1);
3448 cref1 = get_refcount((IUnknown *)clipper);
3450 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3451 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3452 ref2 = get_refcount((IUnknown *)d3drm2);
3454 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 0, 0, &device2);
3455 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3456 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
3458 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3459 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, NULL, &driver, 300, 200, &device2);
3460 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3462 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, NULL);
3463 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3465 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, &device2);
3466 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3467 ref3 = get_refcount((IUnknown *)d3drm1);
3468 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3469 ref3 = get_refcount((IUnknown *)d3drm2);
3470 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3471 cref2 = get_refcount((IUnknown *)clipper);
3472 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3473 ret_val = IDirect3DRMDevice2_GetWidth(device2);
3474 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3475 ret_val = IDirect3DRMDevice2_GetHeight(device2);
3476 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3478 /* Fetch immediate mode device in order to access render target */
3479 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3480 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3482 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3483 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3485 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3486 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3488 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3489 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3490 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3491 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3492 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3493 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3494 IUnknown_Release(unknown);
3495 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3496 NULL, &d3drm_primary, surface_callback);
3497 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3498 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3499 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3500 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3501 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3503 IDirectDrawClipper_Release(d3drm_clipper);
3504 IDirectDrawSurface_Release(d3drm_primary);
3505 IDirectDrawSurface7_Release(surface7);
3506 IDirectDraw_Release(ddraw);
3508 /* Check properties of render target and depth surface */
3509 surface_desc.dwSize = sizeof(surface_desc);
3510 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3511 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3513 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3514 surface_desc.dwWidth, surface_desc.dwHeight);
3515 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3516 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3517 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3518 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3520 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3521 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3522 desc.dwSize = sizeof(desc);
3523 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3524 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3525 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3526 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3528 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3529 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3531 desc.dwSize = sizeof(desc);
3532 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3533 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3535 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3536 desc.dwWidth, desc.dwHeight);
3537 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3538 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3539 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3540 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3541 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3543 /* Release old objects and check refcount of device and clipper */
3544 IDirectDrawSurface_Release(ds);
3545 ds = NULL;
3546 IDirectDrawSurface_Release(surface);
3547 surface = NULL;
3548 IDirect3DDevice2_Release(d3ddevice2);
3549 d3ddevice2 = NULL;
3550 IDirect3DRMDevice2_Release(device2);
3551 ref3 = get_refcount((IUnknown *)d3drm1);
3552 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3553 ref3 = get_refcount((IUnknown *)d3drm2);
3554 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3555 cref2 = get_refcount((IUnknown *)clipper);
3556 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3558 /* Test if render target format follows the screen format */
3559 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3560 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3561 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3562 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3564 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3565 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3566 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3568 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
3569 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3571 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3572 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3574 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3575 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3577 surface_desc.dwSize = sizeof(surface_desc);
3578 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3579 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3580 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3581 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3583 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3584 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3586 IDirectDrawSurface_Release(surface);
3587 IDirect3DDevice2_Release(d3ddevice2);
3588 IDirect3DRMDevice2_Release(device2);
3589 IDirect3DRM2_Release(d3drm2);
3590 IDirect3DRM_Release(d3drm1);
3591 IDirectDrawClipper_Release(clipper);
3592 IDirectDraw_Release(ddraw);
3593 DestroyWindow(window);
3596 static void test_create_device_from_clipper3(void)
3598 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3599 IDirect3DRM *d3drm1 = NULL;
3600 IDirect3DRM3 *d3drm3 = NULL;
3601 IDirectDraw *ddraw = NULL;
3602 IUnknown *unknown = NULL;
3603 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
3604 IDirect3DDevice2 *d3ddevice2 = NULL;
3605 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3606 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3607 IDirectDrawSurface7 *surface7 = NULL;
3608 DDSURFACEDESC desc, surface_desc;
3609 DWORD expected_flags, ret_val;
3610 HWND window;
3611 GUID driver = IID_IDirect3DRGBDevice;
3612 HRESULT hr;
3613 ULONG ref1, ref2, ref3, cref1, cref2;
3614 RECT rc;
3616 window = create_window();
3617 GetClientRect(window, &rc);
3618 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3619 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3620 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3621 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3623 hr = Direct3DRMCreate(&d3drm1);
3624 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3625 ref1 = get_refcount((IUnknown *)d3drm1);
3626 cref1 = get_refcount((IUnknown *)clipper);
3628 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3629 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3630 ref2 = get_refcount((IUnknown *)d3drm3);
3632 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 0, 0, &device3);
3633 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3634 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
3636 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3637 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, NULL, &driver, 300, 200, &device3);
3638 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3640 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, NULL);
3641 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3643 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, &device3);
3644 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3645 ref3 = get_refcount((IUnknown *)d3drm1);
3646 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3647 ref3 = get_refcount((IUnknown *)d3drm3);
3648 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3649 cref2 = get_refcount((IUnknown *)clipper);
3650 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3651 ret_val = IDirect3DRMDevice3_GetWidth(device3);
3652 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3653 ret_val = IDirect3DRMDevice3_GetHeight(device3);
3654 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3656 /* Fetch immediate mode device in order to access render target */
3657 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3658 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3660 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3661 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3663 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3664 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3666 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3667 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3668 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3669 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3670 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3671 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3672 IUnknown_Release(unknown);
3673 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3674 NULL, &d3drm_primary, surface_callback);
3675 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3676 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3677 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3678 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3679 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3681 IDirectDrawClipper_Release(d3drm_clipper);
3682 IDirectDrawSurface_Release(d3drm_primary);
3683 IDirectDrawSurface7_Release(surface7);
3684 IDirectDraw_Release(ddraw);
3686 /* Check properties of render target and depth surface */
3687 surface_desc.dwSize = sizeof(surface_desc);
3688 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3689 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3691 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3692 surface_desc.dwWidth, surface_desc.dwHeight);
3693 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3694 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3695 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3696 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3698 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3699 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3700 desc.dwSize = sizeof(desc);
3701 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3702 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3703 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3704 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3706 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3707 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3709 desc.dwSize = sizeof(desc);
3710 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3711 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3713 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3714 desc.dwWidth, desc.dwHeight);
3715 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3716 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3717 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3718 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3719 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3721 /* Release old objects and check refcount of device and clipper */
3722 IDirectDrawSurface_Release(ds);
3723 ds = NULL;
3724 IDirectDrawSurface_Release(surface);
3725 surface = NULL;
3726 IDirect3DDevice2_Release(d3ddevice2);
3727 d3ddevice2 = NULL;
3728 IDirect3DRMDevice3_Release(device3);
3729 ref3 = get_refcount((IUnknown *)d3drm1);
3730 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3731 ref3 = get_refcount((IUnknown *)d3drm3);
3732 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3733 cref2 = get_refcount((IUnknown *)clipper);
3734 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3736 /* Test if render target format follows the screen format */
3737 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3738 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3739 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3740 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3742 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3743 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3744 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3746 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
3747 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3749 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3750 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3752 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3753 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3755 surface_desc.dwSize = sizeof(surface_desc);
3756 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3757 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3758 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3759 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3761 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3762 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3764 IDirectDrawSurface_Release(surface);
3765 IDirect3DDevice2_Release(d3ddevice2);
3766 IDirect3DRMDevice3_Release(device3);
3767 IDirect3DRM3_Release(d3drm3);
3768 IDirect3DRM_Release(d3drm1);
3769 IDirectDrawClipper_Release(clipper);
3770 IDirectDraw_Release(ddraw);
3771 DestroyWindow(window);
3774 static void test_create_device_from_surface1(void)
3776 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3777 DDSURFACEDESC desc;
3778 IDirectDraw *ddraw = NULL;
3779 IDirect3DRM *d3drm1 = NULL;
3780 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3781 IDirect3DDevice *d3ddevice1 = NULL;
3782 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
3783 DWORD expected_flags, ret_val;
3784 HWND window;
3785 GUID driver = IID_IDirect3DRGBDevice;
3786 ULONG ref1, ref2, surface_ref1, surface_ref2;
3787 RECT rc;
3788 BOOL use_sysmem_zbuffer = FALSE;
3789 HRESULT hr;
3791 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3792 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3794 window = create_window();
3795 GetClientRect(window, &rc);
3797 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3798 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3800 hr = Direct3DRMCreate(&d3drm1);
3801 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3802 ref1 = get_refcount((IUnknown *)d3drm1);
3804 /* Create a surface and use it to create the retained mode device. */
3805 memset(&desc, 0, sizeof(desc));
3806 desc.dwSize = sizeof(desc);
3807 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3808 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3809 desc.dwWidth = rc.right;
3810 desc.dwHeight = rc.bottom;
3812 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3813 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3815 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3816 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
3817 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3818 IDirectDrawSurface_Release(surface);
3820 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
3821 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3822 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3823 surface_ref1 = get_refcount((IUnknown *)surface);
3825 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, NULL);
3826 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
3827 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, NULL, &device1);
3828 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3829 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, NULL, surface, &device1);
3830 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3832 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3833 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3834 ref2 = get_refcount((IUnknown *)d3drm1);
3835 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3836 surface_ref2 = get_refcount((IUnknown *)surface);
3837 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
3838 ret_val = IDirect3DRMDevice_GetWidth(device1);
3839 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
3840 ret_val = IDirect3DRMDevice_GetHeight(device1);
3841 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
3843 /* Check if CreateDeviceFromSurface creates a primary surface */
3844 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3845 NULL, &d3drm_surface, surface_callback);
3846 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3847 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
3849 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3850 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3852 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
3853 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3854 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3856 /* Check properties of attached depth surface */
3857 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
3858 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3860 memset(&desc, 0, sizeof(desc));
3861 desc.dwSize = sizeof(desc);
3862 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3863 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3865 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
3866 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3867 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3868 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3869 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3870 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3872 IDirectDrawSurface_Release(ds);
3873 IDirect3DDevice_Release(d3ddevice1);
3874 IDirectDrawSurface_Release(d3drm_surface);
3876 IDirect3DRMDevice_Release(device1);
3877 ref2 = get_refcount((IUnknown *)d3drm1);
3878 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
3879 surface_ref2 = get_refcount((IUnknown *)surface);
3880 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
3881 surface_ref1, surface_ref2);
3882 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3883 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3884 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3885 ref1 = IDirectDrawSurface_Release(ds);
3886 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3887 ref1 = IDirectDrawSurface_Release(surface);
3888 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3890 memset(&desc, 0, sizeof(desc));
3891 desc.dwSize = sizeof(desc);
3892 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3893 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3894 desc.dwWidth = rc.right;
3895 desc.dwHeight = rc.bottom;
3897 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3898 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3900 memset(&desc, 0, sizeof(desc));
3901 desc.dwSize = sizeof(desc);
3902 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3903 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
3904 desc.dwZBufferBitDepth = 16;
3905 desc.dwWidth = rc.right;
3906 desc.dwHeight = rc.bottom;
3907 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
3908 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
3909 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
3910 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3912 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3913 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3915 hr = IDirect3DRMDevice2_GetDirect3DDevice(device1, &d3ddevice1);
3916 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3918 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
3919 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3920 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3922 /* Check if depth surface matches the one we created */
3923 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3924 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3925 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3927 IDirectDrawSurface_Release(d3drm_ds);
3928 IDirectDrawSurface_Release(d3drm_surface);
3929 IDirectDrawSurface_Release(ds);
3931 IDirect3DDevice_Release(d3ddevice1);
3932 IDirect3DRMDevice_Release(device1);
3933 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3934 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3935 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3936 ref1 = IDirectDrawSurface_Release(ds);
3937 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3938 ref1 = IDirectDrawSurface_Release(surface);
3939 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3940 IDirect3DRM_Release(d3drm1);
3941 IDirectDraw_Release(ddraw);
3942 DestroyWindow(window);
3945 static void test_create_device_from_surface2(void)
3947 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3948 DDSURFACEDESC desc;
3949 IDirectDraw *ddraw = NULL;
3950 IDirect3DRM *d3drm1 = NULL;
3951 IDirect3DRM2 *d3drm2 = NULL;
3952 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
3953 IDirect3DDevice2 *d3ddevice2 = NULL;
3954 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
3955 DWORD expected_flags, ret_val;
3956 HWND window;
3957 GUID driver = IID_IDirect3DRGBDevice;
3958 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
3959 RECT rc;
3960 BOOL use_sysmem_zbuffer = FALSE;
3961 HRESULT hr;
3963 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3964 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3966 window = create_window();
3967 GetClientRect(window, &rc);
3969 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3970 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3972 hr = Direct3DRMCreate(&d3drm1);
3973 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3974 ref1 = get_refcount((IUnknown *)d3drm1);
3976 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3977 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3978 ref2 = get_refcount((IUnknown *)d3drm2);
3980 /* Create a surface and use it to create the retained mode device. */
3981 memset(&desc, 0, sizeof(desc));
3982 desc.dwSize = sizeof(desc);
3983 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3984 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3985 desc.dwWidth = rc.right;
3986 desc.dwHeight = rc.bottom;
3988 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3989 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3991 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
3992 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
3993 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
3994 IDirectDrawSurface_Release(surface);
3996 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
3997 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3998 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3999 surface_ref1 = get_refcount((IUnknown *)surface);
4001 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, NULL);
4002 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
4003 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, NULL, &device2);
4004 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4005 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, NULL, surface, &device2);
4006 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4008 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
4009 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
4010 ref3 = get_refcount((IUnknown *)d3drm1);
4011 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4012 ref3 = get_refcount((IUnknown *)d3drm2);
4013 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4014 surface_ref2 = get_refcount((IUnknown *)surface);
4015 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
4016 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4017 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4018 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4019 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4021 /* Check if CreateDeviceFromSurface creates a primary surface */
4022 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4023 NULL, &d3drm_surface, surface_callback);
4024 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4025 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
4027 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4028 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4030 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4031 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4032 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4034 /* Check properties of attached depth surface */
4035 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
4036 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4038 memset(&desc, 0, sizeof(desc));
4039 desc.dwSize = sizeof(desc);
4040 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4041 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4043 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4044 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4045 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4046 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4047 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4048 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4050 IDirectDrawSurface_Release(ds);
4051 IDirect3DDevice2_Release(d3ddevice2);
4052 IDirectDrawSurface_Release(d3drm_surface);
4054 IDirect3DRMDevice2_Release(device2);
4055 ref3 = get_refcount((IUnknown *)d3drm1);
4056 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4057 ref3 = get_refcount((IUnknown *)d3drm2);
4058 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4059 surface_ref2 = get_refcount((IUnknown *)surface);
4060 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
4061 surface_ref1, surface_ref2);
4062 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4063 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4064 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4065 ref1 = IDirectDrawSurface_Release(ds);
4066 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4068 ref1 = IDirectDrawSurface_Release(surface);
4069 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4071 memset(&desc, 0, sizeof(desc));
4072 desc.dwSize = sizeof(desc);
4073 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4074 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4075 desc.dwWidth = rc.right;
4076 desc.dwHeight = rc.bottom;
4078 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4079 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4081 memset(&desc, 0, sizeof(desc));
4082 desc.dwSize = sizeof(desc);
4083 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4084 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
4085 desc.dwZBufferBitDepth = 16;
4086 desc.dwWidth = rc.right;
4087 desc.dwHeight = rc.bottom;
4088 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
4089 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
4090 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
4091 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4093 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
4094 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
4096 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4097 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4099 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4100 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4101 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4103 /* Check if depth surface matches the one we created */
4104 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4105 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4106 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4108 IDirectDrawSurface_Release(d3drm_ds);
4109 IDirectDrawSurface_Release(d3drm_surface);
4110 IDirectDrawSurface_Release(ds);
4112 IDirect3DDevice2_Release(d3ddevice2);
4113 IDirect3DRMDevice2_Release(device2);
4114 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4115 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4116 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4117 ref1 = IDirectDrawSurface_Release(ds);
4118 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4119 ref1 = IDirectDrawSurface_Release(surface);
4120 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4121 IDirect3DRM2_Release(d3drm2);
4122 IDirect3DRM_Release(d3drm1);
4123 IDirectDraw_Release(ddraw);
4124 DestroyWindow(window);
4127 static void test_create_device_from_surface3(void)
4129 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4130 DDSURFACEDESC desc;
4131 IDirectDraw *ddraw = NULL;
4132 IDirect3DRM *d3drm1 = NULL;
4133 IDirect3DRM3 *d3drm3 = NULL;
4134 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
4135 IDirect3DDevice2 *d3ddevice2 = NULL;
4136 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
4137 DWORD expected_flags, ret_val;
4138 HWND window;
4139 GUID driver = IID_IDirect3DRGBDevice;
4140 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
4141 RECT rc;
4142 BOOL use_sysmem_zbuffer = FALSE;
4143 HRESULT hr;
4145 hr = DirectDrawCreate(NULL, &ddraw, NULL);
4146 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4148 window = create_window();
4149 GetClientRect(window, &rc);
4151 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4152 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4154 hr = Direct3DRMCreate(&d3drm1);
4155 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4156 ref1 = get_refcount((IUnknown *)d3drm1);
4158 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
4159 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
4160 ref2 = get_refcount((IUnknown *)d3drm3);
4162 /* Create a surface and use it to create the retained mode device. */
4163 memset(&desc, 0, sizeof(desc));
4164 desc.dwSize = sizeof(desc);
4165 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4166 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4167 desc.dwWidth = rc.right;
4168 desc.dwHeight = rc.bottom;
4170 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4171 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4173 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4174 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
4175 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
4176 IDirectDrawSurface_Release(surface);
4178 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
4179 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4180 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4181 surface_ref1 = get_refcount((IUnknown *)surface);
4183 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, NULL);
4184 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
4185 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, NULL, 0, &device3);
4186 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4187 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, NULL, surface, 0, &device3);
4188 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4190 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4191 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4192 ref3 = get_refcount((IUnknown *)d3drm1);
4193 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4194 ref3 = get_refcount((IUnknown *)d3drm3);
4195 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4196 surface_ref2 = get_refcount((IUnknown *)surface);
4197 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
4198 ret_val = IDirect3DRMDevice3_GetWidth(device3);
4199 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4200 ret_val = IDirect3DRMDevice3_GetHeight(device3);
4201 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4203 /* Check if CreateDeviceFromSurface creates a primary surface */
4204 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4205 NULL, &d3drm_surface, surface_callback);
4206 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4207 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
4209 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4210 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4212 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4213 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4214 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4216 /* Check properties of attached depth surface */
4217 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
4218 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4220 memset(&desc, 0, sizeof(desc));
4221 desc.dwSize = sizeof(desc);
4222 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4223 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4225 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4226 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4227 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4228 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4229 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4230 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4232 IDirectDrawSurface_Release(ds);
4233 IDirect3DDevice2_Release(d3ddevice2);
4234 IDirectDrawSurface_Release(d3drm_surface);
4235 IDirect3DRMDevice3_Release(device3);
4237 ref3 = get_refcount((IUnknown *)d3drm1);
4238 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4239 ref3 = get_refcount((IUnknown *)d3drm3);
4240 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4241 surface_ref2 = get_refcount((IUnknown *)surface);
4242 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
4243 surface_ref1, surface_ref2);
4244 /* In version 3, d3drm will destroy all references of the depth surface it created internally. */
4245 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4246 todo_wine ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x.\n", hr);
4247 if (SUCCEEDED(hr))
4248 IDirectDrawSurface_Release(ds);
4249 ref1 = IDirectDrawSurface_Release(surface);
4250 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4252 memset(&desc, 0, sizeof(desc));
4253 desc.dwSize = sizeof(desc);
4254 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4255 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4256 desc.dwWidth = rc.right;
4257 desc.dwHeight = rc.bottom;
4259 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4260 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4262 memset(&desc, 0, sizeof(desc));
4263 desc.dwSize = sizeof(desc);
4264 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4265 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
4266 desc.dwZBufferBitDepth = 16;
4267 desc.dwWidth = rc.right;
4268 desc.dwHeight = rc.bottom;
4269 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
4270 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
4271 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
4272 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4274 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
4275 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4277 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4278 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4280 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4281 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4282 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4284 /* Check if depth surface matches the one we created */
4285 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4286 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4287 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4289 IDirectDrawSurface_Release(d3drm_ds);
4290 IDirectDrawSurface_Release(d3drm_surface);
4291 IDirectDrawSurface_Release(ds);
4292 IDirect3DDevice2_Release(d3ddevice2);
4293 IDirect3DRMDevice3_Release(device3);
4294 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4295 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4296 /* The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4297 ref1 = IDirectDrawSurface_Release(ds);
4298 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4300 /* What happens if we pass no flags and still attach our own depth surface? */
4301 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4302 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4304 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4305 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4307 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4308 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4309 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4311 /* Check if depth surface matches the one we created */
4312 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4313 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4314 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4316 IDirectDrawSurface_Release(d3drm_ds);
4317 IDirectDrawSurface_Release(d3drm_surface);
4318 IDirect3DDevice2_Release(d3ddevice2);
4319 IDirect3DRMDevice3_Release(device3);
4320 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4321 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4322 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4323 ref1 = IDirectDrawSurface_Release(ds);
4324 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4325 ref1 = IDirectDrawSurface_Release(surface);
4326 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4328 memset(&desc, 0, sizeof(desc));
4329 desc.dwSize = sizeof(desc);
4330 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4331 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4332 desc.dwWidth = rc.right;
4333 desc.dwHeight = rc.bottom;
4335 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4336 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4338 /* What happens if we don't pass D3DRMDEVICE_NOZBUFFER and still not attach our own depth surface? */
4339 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
4340 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4342 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4343 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4345 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4346 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4347 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4349 /* Check if depth surface matches the one we created */
4350 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4351 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x).\n", hr);
4352 IDirectDrawSurface_Release(d3drm_surface);
4354 IDirect3DDevice2_Release(d3ddevice2);
4355 IDirect3DRMDevice3_Release(device3);
4356 ref1 = IDirectDrawSurface_Release(surface);
4357 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4358 IDirect3DRM3_Release(d3drm3);
4359 IDirect3DRM_Release(d3drm1);
4360 IDirectDraw_Release(ddraw);
4361 DestroyWindow(window);
4364 static IDirect3DDevice *create_device1(IDirectDraw *ddraw, HWND window, IDirectDrawSurface **ds)
4366 static const DWORD z_depths[] = { 32, 24, 16 };
4367 IDirectDrawSurface *surface;
4368 IDirect3DDevice *device = NULL;
4369 DDSURFACEDESC surface_desc;
4370 unsigned int i;
4371 HRESULT hr;
4372 RECT rc;
4374 GetClientRect(window, &rc);
4375 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4376 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4378 memset(&surface_desc, 0, sizeof(surface_desc));
4379 surface_desc.dwSize = sizeof(surface_desc);
4380 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4381 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4382 surface_desc.dwWidth = rc.right;
4383 surface_desc.dwHeight = rc.bottom;
4385 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4386 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4388 /* We used to use EnumDevices() for this, but it seems
4389 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
4390 * relationship with reality. */
4391 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
4393 memset(&surface_desc, 0, sizeof(surface_desc));
4394 surface_desc.dwSize = sizeof(surface_desc);
4395 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4396 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4397 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
4398 surface_desc.dwWidth = rc.right;
4399 surface_desc.dwHeight = rc.bottom;
4400 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, ds, NULL)))
4401 continue;
4403 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
4404 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4405 if (FAILED(hr))
4407 IDirectDrawSurface_Release(*ds);
4408 continue;
4411 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device)))
4412 break;
4414 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
4415 IDirectDrawSurface_Release(*ds);
4416 *ds = NULL;
4419 IDirectDrawSurface_Release(surface);
4420 return device;
4423 static void test_create_device_from_d3d1(void)
4425 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
4426 IDirect3D *d3d1 = NULL, *temp_d3d1;
4427 IDirect3DRM *d3drm1 = NULL;
4428 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
4429 IDirect3DRMDevice2 *device2;
4430 IDirect3DRMDevice3 *device3;
4431 IDirect3DDevice *d3ddevice1 = NULL, *d3drm_d3ddevice1 = NULL, *temp_d3ddevice1;
4432 IDirect3DDevice2 *d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4433 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
4434 DWORD expected_flags, ret_val;
4435 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4436 DDSURFACEDESC desc;
4437 RECT rc;
4438 HWND window;
4439 ULONG ref1, ref2, ref3, ref4, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
4440 HRESULT hr;
4442 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
4443 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4445 window = create_window();
4446 GetClientRect(window, &rc);
4448 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
4449 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
4450 d3d_ref1 = get_refcount((IUnknown *)d3d1);
4452 /* Create the immediate mode device */
4453 d3ddevice1 = create_device1(ddraw1, window, &ds);
4454 if (d3ddevice1 == NULL)
4456 win_skip("Cannot create IM device, skipping tests.\n");
4457 IDirect3D_Release(d3d1);
4458 IDirectDraw_Release(ddraw1);
4459 return;
4461 device_ref1 = get_refcount((IUnknown *)d3ddevice1);
4463 hr = Direct3DRMCreate(&d3drm1);
4464 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4465 ref1 = get_refcount((IUnknown *)d3drm1);
4467 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, NULL, d3ddevice1, &device1);
4468 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4469 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
4470 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, NULL, &device1);
4471 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4472 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, NULL);
4473 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4475 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, &device1);
4476 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice interface (hr = %x)\n", hr);
4477 ref2 = get_refcount((IUnknown *)d3drm1);
4478 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
4479 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4480 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4481 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4482 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4483 ret_val = IDirect3DRMDevice_GetWidth(device1);
4484 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4485 ret_val = IDirect3DRMDevice_GetHeight(device1);
4486 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4488 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
4489 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
4490 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4491 ok(SUCCEEDED(hr), "Expected hr == D3DRM_OK, got %#x.\n", hr);
4492 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4493 IDirect3DRMDevice2_Release(device2);
4495 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4496 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)&device3);
4497 ok(hr == DD_OK, "Cannot get IDirect3DRMDevice3 Interface (hr = %x).\n", hr);
4498 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4499 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4500 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4501 IDirect3DRMDevice3_Release(device3);
4503 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4504 NULL, &surface, surface_callback);
4505 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4506 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4508 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
4509 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
4510 ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice1, d3drm_d3ddevice1);
4512 /* Check properties of render target and depth surfaces */
4513 hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
4514 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4516 memset(&desc, 0, sizeof(desc));
4517 desc.dwSize = sizeof(desc);
4518 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4519 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
4521 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4522 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4523 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4524 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4525 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4526 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4528 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4529 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4530 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4532 desc.dwSize = sizeof(desc);
4533 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4534 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4536 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4537 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4538 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4539 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4540 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4542 IDirectDrawSurface_Release(d3drm_ds);
4543 IDirectDrawSurface_Release(ds);
4544 IDirectDrawSurface_Release(surface);
4545 IDirect3DDevice_Release(d3drm_d3ddevice1);
4546 IDirect3DRMDevice_Release(device1);
4547 ref2 = get_refcount((IUnknown *)d3drm1);
4548 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
4549 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4550 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4552 /* InitFromD3D tests */
4553 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice, (void **)&device1);
4554 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
4556 hr = IDirect3DRMDevice_InitFromD3D(device1, NULL, d3ddevice1);
4557 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4558 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, NULL);
4559 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4561 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4562 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice interface (hr = %#x)\n", hr);
4563 ref2 = get_refcount((IUnknown *)d3drm1);
4564 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
4565 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4566 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4567 device_ref1, device_ref2);
4568 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4569 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4570 ret_val = IDirect3DRMDevice_GetWidth(device1);
4571 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4572 ret_val = IDirect3DRMDevice_GetHeight(device1);
4573 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4575 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4576 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4577 ref3 = get_refcount((IUnknown *)d3drm1);
4578 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4579 ref3 = get_refcount((IUnknown *)d3ddevice1);
4580 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4581 ref3 = get_refcount((IUnknown *)d3d1);
4582 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4583 /* Release leaked references */
4584 while (IDirect3DRM_Release(d3drm1) > ref2);
4585 while (IDirect3DDevice_Release(d3ddevice1) > device_ref2);
4586 while (IDirect3D_Release(d3d1) > d3d_ref2);
4588 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
4589 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
4590 ref4 = get_refcount((IUnknown *)temp_ddraw1);
4592 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D, (void **)&temp_d3d1);
4593 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
4594 temp_d3ddevice1 = create_device1(temp_ddraw1, window, &surface);
4595 hr = IDirect3DRMDevice_InitFromD3D(device1, temp_d3d1, temp_d3ddevice1);
4596 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4597 ref3 = get_refcount((IUnknown *)d3drm1);
4598 ok(ref3 > ref2, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4599 ref3 = get_refcount((IUnknown *)temp_d3ddevice1);
4600 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4601 ref3 = get_refcount((IUnknown *)temp_d3d1);
4602 todo_wine ok(ref3 < d3d_ref2, "Expected ref3 < d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4603 /* Release leaked references */
4604 while (IDirect3DRM_Release(d3drm1) > ref2);
4605 while (IDirect3DDevice_Release(temp_d3ddevice1) > 0);
4606 while (IDirect3D_Release(temp_d3d1) > ref4);
4607 IDirectDrawSurface_Release(surface);
4608 IDirectDraw_Release(temp_ddraw1);
4610 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4611 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
4612 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
4613 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4614 ok(SUCCEEDED(hr), "Expected hr == D3DRM_OK, got %#x.\n", hr);
4615 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4616 IDirect3DRMDevice2_Release(device2);
4618 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4619 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)&device3);
4620 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 Interface (hr = %#x).\n", hr);
4621 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4622 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4623 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4624 IDirect3DRMDevice3_Release(device3);
4626 surface = NULL;
4627 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4628 NULL, &surface, surface_callback);
4629 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
4630 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4632 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
4633 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice interface (hr = %#x).\n", hr);
4634 ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode device created == %p, got %p.\n",
4635 d3ddevice1, d3drm_d3ddevice1);
4637 /* Check properties of render target and depth surfaces */
4638 hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
4639 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
4641 memset(&desc, 0, sizeof(desc));
4642 desc.dwSize = sizeof(desc);
4643 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4644 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %#x).\n", hr);
4646 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4647 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4648 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
4649 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4650 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4651 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4653 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4654 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
4655 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4657 desc.dwSize = sizeof(desc);
4658 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4659 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %#x).\n", hr);
4661 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4662 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4663 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %#x, got %#x.\n",
4664 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4665 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4666 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
4668 IDirectDrawSurface_Release(d3drm_ds);
4669 IDirectDrawSurface_Release(ds);
4670 IDirectDrawSurface_Release(surface);
4671 IDirect3DDevice_Release(d3drm_d3ddevice1);
4672 IDirect3DRMDevice_Release(device1);
4673 ref2 = get_refcount((IUnknown *)d3drm1);
4674 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
4675 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4676 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4677 device_ref1, device_ref2);
4678 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4679 todo_wine ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1,
4680 d3d_ref2);
4682 IDirect3DRM_Release(d3drm1);
4683 IDirect3DDevice_Release(d3ddevice1);
4684 IDirect3D_Release(d3d1);
4685 IDirectDraw_Release(ddraw1);
4686 DestroyWindow(window);
4689 static IDirect3DDevice2 *create_device2(IDirectDraw2 *ddraw, HWND window, IDirectDrawSurface **ds)
4691 static const DWORD z_depths[] = { 32, 24, 16 };
4692 IDirectDrawSurface *surface;
4693 IDirect3DDevice2 *device = NULL;
4694 DDSURFACEDESC surface_desc;
4695 IDirect3D2 *d3d;
4696 unsigned int i;
4697 HRESULT hr;
4698 RECT rc;
4700 GetClientRect(window, &rc);
4701 hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4702 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4704 memset(&surface_desc, 0, sizeof(surface_desc));
4705 surface_desc.dwSize = sizeof(surface_desc);
4706 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4707 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4708 surface_desc.dwWidth = rc.right;
4709 surface_desc.dwHeight = rc.bottom;
4711 hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4712 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4714 hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
4715 if (FAILED(hr))
4717 IDirectDrawSurface_Release(surface);
4718 *ds = NULL;
4719 return NULL;
4722 /* We used to use EnumDevices() for this, but it seems
4723 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
4724 * relationship with reality. */
4725 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
4727 memset(&surface_desc, 0, sizeof(surface_desc));
4728 surface_desc.dwSize = sizeof(surface_desc);
4729 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4730 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4731 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
4732 surface_desc.dwWidth = rc.right;
4733 surface_desc.dwHeight = rc.bottom;
4734 if (FAILED(IDirectDraw2_CreateSurface(ddraw, &surface_desc, ds, NULL)))
4735 continue;
4737 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
4738 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4739 if (FAILED(hr))
4741 IDirectDrawSurface_Release(*ds);
4742 continue;
4745 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device)))
4746 break;
4748 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
4749 IDirectDrawSurface_Release(*ds);
4750 *ds = NULL;
4753 IDirect3D2_Release(d3d);
4754 IDirectDrawSurface_Release(surface);
4755 return device;
4758 static void test_create_device_from_d3d2(void)
4760 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
4761 IDirectDraw2 *ddraw2 = NULL, *temp_ddraw2;
4762 IDirect3D* d3d1;
4763 IDirect3D2 *d3d2 = NULL, *temp_d3d2;
4764 IDirect3DRM *d3drm1 = NULL;
4765 IDirect3DRM2 *d3drm2 = NULL;
4766 IDirect3DRMDevice *device1;
4767 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
4768 IDirect3DDevice *d3ddevice1;
4769 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL, *temp_d3ddevice2;
4770 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
4771 DWORD expected_flags, ret_val;
4772 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4773 DDSURFACEDESC desc;
4774 RECT rc;
4775 HWND window;
4776 ULONG ref1, ref2, ref3, ref4, ref5, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
4777 HRESULT hr;
4779 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
4780 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4782 window = create_window();
4783 GetClientRect(window, &rc);
4785 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
4786 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
4787 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
4788 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
4789 d3d_ref1 = get_refcount((IUnknown *)d3d2);
4791 /* Create the immediate mode device */
4792 d3ddevice2 = create_device2(ddraw2, window, &ds);
4793 if (d3ddevice2 == NULL)
4795 win_skip("Cannot create IM device, skipping tests.\n");
4796 IDirect3D2_Release(d3d2);
4797 IDirectDraw2_Release(ddraw2);
4798 IDirectDraw_Release(ddraw1);
4799 return;
4801 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
4803 hr = Direct3DRMCreate(&d3drm1);
4804 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4805 ref1 = get_refcount((IUnknown *)d3drm1);
4807 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
4808 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
4809 ref2 = get_refcount((IUnknown *)d3drm2);
4811 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, NULL, d3ddevice2, &device2);
4812 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4813 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
4814 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, NULL, &device2);
4815 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4816 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, NULL);
4817 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4819 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, &device2);
4820 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice2 interface (hr = %x)\n", hr);
4821 ref3 = get_refcount((IUnknown *)d3drm1);
4822 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4823 ref3 = get_refcount((IUnknown *)d3drm2);
4824 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4825 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4826 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4827 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4828 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4829 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4830 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4831 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4832 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4834 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4835 NULL, &surface, surface_callback);
4836 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4837 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4839 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3drm_d3ddevice2);
4840 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4841 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
4843 /* Check properties of render target and depth surfaces */
4844 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
4845 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4847 memset(&desc, 0, sizeof(desc));
4848 desc.dwSize = sizeof(desc);
4849 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4850 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
4852 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4853 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4854 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4855 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4856 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4857 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4859 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4860 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4861 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4863 desc.dwSize = sizeof(desc);
4864 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4865 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4867 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4868 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4869 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4870 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4871 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4873 IDirectDrawSurface_Release(d3drm_ds);
4874 IDirectDrawSurface_Release(ds);
4875 IDirectDrawSurface_Release(surface);
4876 IDirect3DDevice2_Release(d3drm_d3ddevice2);
4877 IDirect3DRMDevice2_Release(device2);
4878 ref3 = get_refcount((IUnknown *)d3drm1);
4879 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4880 ref3 = get_refcount((IUnknown *)d3drm2);
4881 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4882 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4883 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4884 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4885 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4887 /* InitFromD3D tests */
4888 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice2, (void **)&device2);
4889 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %#x).\n", hr);
4891 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
4892 ok(SUCCEEDED(hr), "Cannot get IDirect3D interface (hr = %x).\n", hr);
4893 if (SUCCEEDED(hr = IDirect3DDevice2_QueryInterface(d3ddevice2, &IID_IDirect3DDevice, (void **)&d3ddevice1)))
4895 hr = IDirect3DRMDevice2_InitFromD3D(device2, d3d1, d3ddevice1);
4896 ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
4897 hr = IDirect3DRMDevice2_InitFromD3D(device2, NULL, d3ddevice1);
4898 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4899 hr = IDirect3DRMDevice2_InitFromD3D(device2, d3d1, NULL);
4900 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4901 hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IDirect3DRMDevice, (void **)&device1);
4902 ok(SUCCEEDED(hr), "Cannot obtain IDirect3DRMDevice interface (hr = %#x).\n", hr);
4903 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4904 todo_wine ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
4905 IDirect3DRMDevice_Release(device1);
4906 if (SUCCEEDED(hr))
4908 IDirect3DRMDevice_Release(device1);
4909 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice2,
4910 (void **)&device2);
4911 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %#x).\n", hr);
4914 IDirect3D_Release(d3d1);
4915 IDirect3DDevice_Release(d3ddevice1);
4917 hr = IDirect3DRMDevice2_InitFromD3D2(device2, NULL, d3ddevice2);
4918 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4919 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, NULL);
4920 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4922 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, d3ddevice2);
4923 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice2 interface (hr = %#x)\n", hr);
4924 ref4 = get_refcount((IUnknown *)d3drm1);
4925 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
4926 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4927 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4928 device_ref1, device_ref2);
4929 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4930 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4931 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4932 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4933 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4934 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4936 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, d3ddevice2);
4937 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4938 ref3 = get_refcount((IUnknown *)d3drm1);
4939 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4940 ref3 = get_refcount((IUnknown *)d3ddevice2);
4941 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4942 ref3 = get_refcount((IUnknown *)d3d2);
4943 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4944 /* Release leaked references */
4945 while (IDirect3DRM_Release(d3drm1) > ref4);
4946 while (IDirect3DDevice2_Release(d3ddevice2) > device_ref2);
4947 while (IDirect3D2_Release(d3d2) > d3d_ref2);
4949 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
4950 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
4951 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D2, (void **)&temp_d3d2);
4952 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
4953 ref5 = get_refcount((IUnknown *)temp_d3d2);
4955 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirectDraw2, (void **)&temp_ddraw2);
4956 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
4958 temp_d3ddevice2 = create_device2(temp_ddraw2, window, &surface);
4959 hr = IDirect3DRMDevice2_InitFromD3D2(device2, temp_d3d2, temp_d3ddevice2);
4960 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4961 ref3 = get_refcount((IUnknown *)d3drm1);
4962 ok(ref3 > ref4, "expected ref3 > ref4, got ref3 = %u , ref4 = %u.\n", ref3, ref4);
4963 ref3 = get_refcount((IUnknown *)temp_d3ddevice2);
4964 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4965 ref3 = get_refcount((IUnknown *)temp_d3d2);
4966 ok(ref3 == d3d_ref2, "Expected ref3 == d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4967 /* Release leaked references */
4968 while (IDirect3DRM_Release(d3drm1) > ref4);
4969 while (IDirect3DDevice2_Release(temp_d3ddevice2) > 0);
4970 while (IDirect3D2_Release(temp_d3d2) >= ref5);
4971 IDirectDrawSurface_Release(surface);
4972 IDirectDraw2_Release(temp_ddraw2);
4973 IDirectDraw_Release(temp_ddraw1);
4975 surface = NULL;
4976 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4977 NULL, &surface, surface_callback);
4978 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
4979 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4981 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3drm_d3ddevice2);
4982 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
4983 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2,
4984 d3drm_d3ddevice2);
4986 /* Check properties of render target and depth surfaces */
4987 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
4988 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
4990 memset(&desc, 0, sizeof(desc));
4991 desc.dwSize = sizeof(desc);
4992 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4993 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %#x).\n", hr);
4995 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4996 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4997 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
4998 "Expected caps containing %#x, got %#x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4999 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5000 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5002 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5003 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
5004 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5006 desc.dwSize = sizeof(desc);
5007 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5008 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %x).\n", hr);
5010 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5011 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5012 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %#x, got %#x.\n",
5013 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5014 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5015 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5017 IDirectDrawSurface_Release(d3drm_ds);
5018 IDirectDrawSurface_Release(ds);
5019 IDirectDrawSurface_Release(surface);
5020 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5021 IDirect3DRMDevice2_Release(device2);
5022 ref3 = get_refcount((IUnknown *)d3drm1);
5023 ok(ref1 == ref3, "Expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5024 ref3 = get_refcount((IUnknown *)d3drm2);
5025 ok(ref3 == ref2, "Expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5026 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5027 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5028 device_ref1, device_ref2);
5029 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5030 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5032 IDirect3DRM2_Release(d3drm2);
5033 IDirect3DRM_Release(d3drm1);
5034 IDirect3DDevice2_Release(d3ddevice2);
5035 IDirect3D2_Release(d3d2);
5036 IDirectDraw2_Release(ddraw2);
5037 IDirectDraw_Release(ddraw1);
5038 DestroyWindow(window);
5041 static void test_create_device_from_d3d3(void)
5043 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
5044 IDirectDraw2 *ddraw2 = NULL, *temp_ddraw2;
5045 IDirect3D *d3d1;
5046 IDirect3D2 *d3d2 = NULL, *temp_d3d2;
5047 IDirect3DRM *d3drm1 = NULL;
5048 IDirect3DRM3 *d3drm3 = NULL;
5049 IDirect3DRMDevice *device1;
5050 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
5051 IDirect3DDevice *d3ddevice1;
5052 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL, *temp_d3ddevice2;
5053 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
5054 DWORD expected_flags, ret_val;
5055 DDSCAPS caps = { DDSCAPS_ZBUFFER };
5056 DDSURFACEDESC desc;
5057 RECT rc;
5058 HWND window;
5059 ULONG ref1, ref2, ref3, ref4, ref5, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
5060 HRESULT hr;
5062 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
5063 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
5065 window = create_window();
5066 GetClientRect(window, &rc);
5068 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
5069 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
5070 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
5071 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
5072 d3d_ref1 = get_refcount((IUnknown *)d3d2);
5074 /* Create the immediate mode device */
5075 d3ddevice2 = create_device2(ddraw2, window, &ds);
5076 if (d3ddevice2 == NULL)
5078 win_skip("Cannot create IM device, skipping tests.\n");
5079 IDirect3D2_Release(d3d2);
5080 IDirectDraw2_Release(ddraw2);
5081 IDirectDraw_Release(ddraw1);
5082 return;
5084 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
5086 hr = Direct3DRMCreate(&d3drm1);
5087 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
5088 ref1 = get_refcount((IUnknown *)d3drm1);
5090 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5091 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
5092 ref2 = get_refcount((IUnknown *)d3drm3);
5094 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, NULL, d3ddevice2, &device3);
5095 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5096 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
5097 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, NULL, &device3);
5098 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5099 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, NULL);
5100 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5102 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, &device3);
5103 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice3 interface (hr = %x)\n", hr);
5104 ref3 = get_refcount((IUnknown *)d3drm1);
5105 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
5106 ref3 = get_refcount((IUnknown *)d3drm3);
5107 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5108 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5109 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
5110 ret_val = IDirect3DRMDevice3_GetWidth(device3);
5111 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
5112 ret_val = IDirect3DRMDevice3_GetHeight(device3);
5113 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
5115 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
5116 NULL, &surface, surface_callback);
5117 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
5118 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
5120 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3drm_d3ddevice2);
5121 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
5122 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
5124 /* Check properties of render target and depth surfaces */
5125 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
5126 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
5128 memset(&desc, 0, sizeof(desc));
5129 desc.dwSize = sizeof(desc);
5130 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
5131 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
5133 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5134 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5135 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
5136 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
5137 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5138 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
5140 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5141 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
5142 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5144 desc.dwSize = sizeof(desc);
5145 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5146 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
5148 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5149 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5150 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5151 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5152 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
5154 IDirectDrawSurface_Release(d3drm_ds);
5155 IDirectDrawSurface_Release(ds);
5156 IDirectDrawSurface_Release(surface);
5157 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5158 IDirect3DRMDevice3_Release(device3);
5159 ref3 = get_refcount((IUnknown *)d3drm1);
5160 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5161 ref3 = get_refcount((IUnknown *)d3drm3);
5162 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5163 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5164 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
5165 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5166 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5168 /* InitFromD3D tests */
5169 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice3, (void **)&device3);
5170 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5172 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
5173 ok(SUCCEEDED(hr), "Cannot get IDirect3D interface (hr = %#x).\n", hr);
5174 if (SUCCEEDED(hr = IDirect3DDevice2_QueryInterface(d3ddevice2, &IID_IDirect3DDevice, (void **)&d3ddevice1)))
5176 hr = IDirect3DRMDevice3_InitFromD3D(device3, d3d1, d3ddevice1);
5177 ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
5178 hr = IDirect3DRMDevice3_InitFromD3D(device3, NULL, d3ddevice1);
5179 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5180 hr = IDirect3DRMDevice3_InitFromD3D(device3, d3d1, NULL);
5181 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5182 hr = IDirect3DRMDevice3_QueryInterface(device3, &IID_IDirect3DRMDevice, (void **)&device1);
5183 ok(SUCCEEDED(hr), "Cannot obtain IDirect3DRMDevice interface (hr = %#x).\n", hr);
5184 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
5185 todo_wine ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
5186 IDirect3DRMDevice_Release(device1);
5187 if (SUCCEEDED(hr))
5189 IDirect3DRMDevice_Release(device1);
5190 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice3,
5191 (void **)&device3);
5192 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5195 IDirect3D_Release(d3d1);
5196 IDirect3DDevice_Release(d3ddevice1);
5198 hr = IDirect3DRMDevice3_InitFromD3D2(device3, NULL, d3ddevice2);
5199 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5200 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, NULL);
5201 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5203 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, d3ddevice2);
5204 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice2 interface (hr = %#x)\n", hr);
5205 ref4 = get_refcount((IUnknown *)d3drm1);
5206 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
5207 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5208 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5209 device_ref1, device_ref2);
5210 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5211 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5212 ret_val = IDirect3DRMDevice3_GetWidth(device3);
5213 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
5214 ret_val = IDirect3DRMDevice3_GetHeight(device3);
5215 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
5217 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, d3ddevice2);
5218 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
5219 ref3 = get_refcount((IUnknown *)d3drm1);
5220 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
5221 ref3 = get_refcount((IUnknown *)d3ddevice2);
5222 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
5223 ref3 = get_refcount((IUnknown *)d3d2);
5224 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
5225 /* Release leaked references */
5226 while (IDirect3DRM_Release(d3drm1) > ref4);
5227 while (IDirect3DDevice2_Release(d3ddevice2) > device_ref2);
5228 while (IDirect3D2_Release(d3d2) > d3d_ref2);
5230 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
5231 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
5232 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D2, (void **)&temp_d3d2);
5233 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
5234 ref5 = get_refcount((IUnknown *)temp_d3d2);
5236 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirectDraw2, (void **)&temp_ddraw2);
5237 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
5239 temp_d3ddevice2 = create_device2(temp_ddraw2, window, &surface);
5240 hr = IDirect3DRMDevice3_InitFromD3D2(device3, temp_d3d2, temp_d3ddevice2);
5241 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
5242 ref3 = get_refcount((IUnknown *)d3drm1);
5243 ok(ref3 > ref4, "expected ref3 > ref4, got ref3 = %u , ref4 = %u.\n", ref3, ref4);
5244 ref3 = get_refcount((IUnknown *)temp_d3ddevice2);
5245 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
5246 ref3 = get_refcount((IUnknown *)temp_d3d2);
5247 ok(ref3 == d3d_ref2, "Expected ref3 == d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
5248 /* Release leaked references */
5249 while (IDirect3DRM_Release(d3drm1) > ref4);
5250 while (IDirect3DDevice2_Release(temp_d3ddevice2) > 0);
5251 while (IDirect3D2_Release(temp_d3d2) >= ref5);
5252 IDirectDrawSurface_Release(surface);
5253 IDirectDraw2_Release(temp_ddraw2);
5254 IDirectDraw_Release(temp_ddraw1);
5256 surface = NULL;
5257 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
5258 NULL, &surface, surface_callback);
5259 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
5260 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
5262 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3drm_d3ddevice2);
5263 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
5264 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2,
5265 d3drm_d3ddevice2);
5267 /* Check properties of render target and depth surfaces */
5268 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
5269 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
5271 memset(&desc, 0, sizeof(desc));
5272 desc.dwSize = sizeof(desc);
5273 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
5274 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %x).\n", hr);
5276 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5277 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5278 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
5279 "Expected caps containing %#x, got %#x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
5280 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5281 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5283 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5284 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
5285 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5287 desc.dwSize = sizeof(desc);
5288 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5289 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %x).\n", hr);
5291 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5292 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5293 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %#x.\n",
5294 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5295 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5296 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5298 IDirectDrawSurface_Release(d3drm_ds);
5299 IDirectDrawSurface_Release(ds);
5300 IDirectDrawSurface_Release(surface);
5301 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5302 IDirect3DRMDevice3_Release(device3);
5303 ref3 = get_refcount((IUnknown *)d3drm1);
5304 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5305 ref3 = get_refcount((IUnknown *)d3drm3);
5306 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5307 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5308 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5309 device_ref1, device_ref2);
5310 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5311 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5313 IDirect3DRM3_Release(d3drm3);
5314 IDirect3DRM_Release(d3drm1);
5315 IDirect3DDevice2_Release(d3ddevice2);
5316 IDirect3D2_Release(d3d2);
5317 IDirectDraw2_Release(ddraw2);
5318 IDirectDraw_Release(ddraw1);
5319 DestroyWindow(window);
5322 static char *create_bitmap(unsigned int w, unsigned int h, BOOL palettized)
5324 unsigned int bpp = palettized ? 8 : 24;
5325 BITMAPFILEHEADER file_header;
5326 DWORD written, size, ret;
5327 unsigned char *buffer;
5328 char path[MAX_PATH];
5329 unsigned int i, j;
5330 BITMAPINFO *info;
5331 char *filename;
5332 HANDLE file;
5334 ret = GetTempPathA(MAX_PATH, path);
5335 ok(ret, "Failed to get temporary file path.\n");
5336 filename = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
5337 ret = GetTempFileNameA(path, "d3d", 0, filename);
5338 ok(ret, "Failed to get filename.\n");
5339 file = CreateFileA(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
5340 ok(file != INVALID_HANDLE_VALUE, "Failed to open temporary file \"%s\".\n", filename);
5342 size = FIELD_OFFSET(BITMAPINFO, bmiColors[palettized ? 256 : 0]);
5344 memset(&file_header, 0, sizeof(file_header));
5345 file_header.bfType = 0x4d42; /* BM */
5346 file_header.bfOffBits = sizeof(file_header) + size;
5347 file_header.bfSize = file_header.bfOffBits + w * h * (bpp / 8);
5348 ret = WriteFile(file, &file_header, sizeof(file_header), &written, NULL);
5349 ok(ret && written == sizeof(file_header), "Failed to write file header.\n");
5351 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
5352 info->bmiHeader.biSize = sizeof(info->bmiHeader);
5353 info->bmiHeader.biBitCount = bpp;
5354 info->bmiHeader.biPlanes = 1;
5355 info->bmiHeader.biWidth = w;
5356 info->bmiHeader.biHeight = h;
5357 info->bmiHeader.biCompression = BI_RGB;
5358 if (palettized)
5360 for (i = 0; i < 256; ++i)
5362 info->bmiColors[i].rgbBlue = i;
5363 info->bmiColors[i].rgbGreen = i;
5364 info->bmiColors[i].rgbRed = i;
5367 ret = WriteFile(file, info, size, &written, NULL);
5368 ok(ret && written == size, "Failed to write bitmap info.\n");
5369 HeapFree(GetProcessHeap(), 0, info);
5371 size = w * h * (bpp / 8);
5372 buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
5373 for (i = 0, j = 0; i < size;)
5375 if (palettized)
5377 buffer[i++] = j++;
5378 j %= 256;
5380 else
5382 buffer[i++] = j % 251;
5383 buffer[i++] = j % 239;
5384 buffer[i++] = j++ % 247;
5387 ret = WriteFile(file, buffer, size, &written, NULL);
5388 ok(ret && written == size, "Failed to write bitmap data.\n");
5389 HeapFree(GetProcessHeap(), 0, buffer);
5391 CloseHandle(file);
5393 return filename;
5396 static void test_bitmap_data(unsigned int test_idx, const D3DRMIMAGE *img,
5397 BOOL upside_down, unsigned int w, unsigned int h, BOOL palettized)
5399 const unsigned char *data = img->buffer1;
5400 unsigned int i, j;
5402 ok(img->width == w, "Test %u: Got unexpected image width %u, expected %u.\n", test_idx, img->width, w);
5403 ok(img->height == h, "Test %u: Got unexpected image height %u, expected %u.\n", test_idx, img->height, h);
5404 ok(img->aspectx == 1, "Test %u: Got unexpected image aspectx %u.\n", test_idx, img->aspectx);
5405 ok(img->aspecty == 1, "Test %u: Got unexpected image aspecty %u.\n", test_idx, img->aspecty);
5406 ok(!img->buffer2, "Test %u: Got unexpected image buffer2 %p.\n", test_idx, img->buffer2);
5408 /* The image is palettized if the total number of colors used is <= 256. */
5409 if (w * h > 256 && !palettized)
5411 /* D3drm aligns the 24bpp texture to 4 bytes in the buffer, with one
5412 * byte padding from 24bpp texture. */
5413 ok(img->depth == 32, "Test %u: Got unexpected image depth %u.\n", test_idx, img->depth);
5414 ok(img->rgb == TRUE, "Test %u: Got unexpected image rgb %#x.\n", test_idx, img->rgb);
5415 ok(img->bytes_per_line == w * 4, "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5416 test_idx, img->bytes_per_line, w * 4);
5417 ok(img->red_mask == 0xff0000, "Test %u: Got unexpected image red mask %#x.\n", test_idx, img->red_mask);
5418 ok(img->green_mask == 0x00ff00, "Test %u: Got unexpected image green mask %#x.\n", test_idx, img->green_mask);
5419 ok(img->blue_mask == 0x0000ff, "Test %u: Got unexpected image blue mask %#x.\n", test_idx, img->blue_mask);
5420 ok(!img->alpha_mask, "Test %u: Got unexpected image alpha mask %#x.\n", test_idx, img->alpha_mask);
5421 ok(!img->palette_size, "Test %u: Got unexpected palette size %u.\n", test_idx, img->palette_size);
5422 ok(!img->palette, "Test %u: Got unexpected image palette %p.\n", test_idx, img->palette);
5423 for (i = 0; i < h; ++i)
5425 for (j = 0; j < w; ++j)
5427 const unsigned char *ptr = &data[i * img->bytes_per_line + j * 4];
5428 unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
5430 if (ptr[0] != idx % 251 || ptr[1] != idx % 239 || ptr[2] != idx % 247 || ptr[3] != 0xff)
5432 ok(0, "Test %u: Got unexpected color 0x%02x%02x%02x%02x at position %u, %u, "
5433 "expected 0x%02x%02x%02x%02x.\n", test_idx, ptr[0], ptr[1], ptr[2], ptr[3],
5434 j, i, idx % 251, idx % 239, idx % 247, 0xff);
5435 return;
5439 return;
5442 ok(img->depth == 8, "Test %u: Got unexpected image depth %u.\n", test_idx, img->depth);
5443 ok(!img->rgb, "Test %u: Got unexpected image rgb %#x.\n", test_idx, img->rgb);
5444 ok(img->red_mask == 0xff, "Test %u: Got unexpected image red mask %#x.\n", test_idx, img->red_mask);
5445 ok(img->green_mask == 0xff, "Test %u: Got unexpected image green mask %#x.\n", test_idx, img->green_mask);
5446 ok(img->blue_mask == 0xff, "Test %u: Got unexpected image blue mask %#x.\n", test_idx, img->blue_mask);
5447 ok(!img->alpha_mask, "Test %u: Got unexpected image alpha mask %#x.\n", test_idx, img->alpha_mask);
5448 ok(!!img->palette, "Test %u: Got unexpected image palette %p.\n", test_idx, img->palette);
5449 if (!palettized)
5451 /* In this case, bytes_per_line is aligned to the next multiple of
5452 * 4 from width. */
5453 ok(img->bytes_per_line == ((w + 3) & ~3), "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5454 test_idx, img->bytes_per_line, (w + 3) & ~3);
5455 ok(img->palette_size == w * h, "Test %u: Got unexpected palette size %u, expected %u.\n",
5456 test_idx, img->palette_size, w * h);
5457 for (i = 0; i < img->palette_size; ++i)
5459 unsigned int idx = upside_down ? (h - 1) * w - i + (i % w) * 2 : i;
5460 ok(img->palette[i].red == idx % 251
5461 && img->palette[i].green == idx % 239 && img->palette[i].blue == idx % 247,
5462 "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n",
5463 test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue);
5464 ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
5465 "Test %u: Got unexpected palette entry (%u) flags %#x.\n",
5466 test_idx, i, img->palette[i].flags);
5468 for (i = 0; i < h; ++i)
5470 for (j = 0; j < w; ++j)
5472 if (data[i * img->bytes_per_line + j] != i * w + j)
5474 ok(0, "Test %u: Got unexpected color 0x%02x at position %u, %u, expected 0x%02x.\n",
5475 test_idx, data[i * img->bytes_per_line + j], j, i, i * w + j);
5476 return;
5480 return;
5483 /* bytes_per_line is not always aligned by d3drm depending on the
5484 * format. */
5485 ok(img->bytes_per_line == w, "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5486 test_idx, img->bytes_per_line, w);
5487 ok(img->palette_size == 256, "Test %u: Got unexpected palette size %u.\n", test_idx, img->palette_size);
5488 for (i = 0; i < 256; ++i)
5490 ok(img->palette[i].red == i && img->palette[i].green == i && img->palette[i].blue == i,
5491 "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n",
5492 test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue);
5493 ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
5494 "Test %u: Got unexpected palette entry (%u) flags %#x.\n",
5495 test_idx, i, img->palette[i].flags);
5497 for (i = 0; i < h; ++i)
5499 for (j = 0; j < w; ++j)
5501 unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
5502 if (data[i * img->bytes_per_line + j] != idx % 256)
5504 ok(0, "Test %u: Got unexpected color 0x%02x at position %u, %u, expected 0x%02x.\n",
5505 test_idx, data[i * img->bytes_per_line + j], j, i, idx % 256);
5506 return;
5512 static void test_load_texture(void)
5514 IDirect3DRMTexture3 *texture3;
5515 IDirect3DRMTexture2 *texture2;
5516 IDirect3DRMTexture *texture1;
5517 D3DRMIMAGE *d3drm_img;
5518 IDirect3DRM3 *d3drm3;
5519 IDirect3DRM2 *d3drm2;
5520 IDirect3DRM *d3drm1;
5521 char *filename;
5522 HRESULT hr;
5523 BOOL ret;
5524 int i;
5526 static const struct
5528 unsigned int w;
5529 unsigned int h;
5530 BOOL palettized;
5532 tests[] =
5534 {100, 100, TRUE },
5535 {99, 100, TRUE },
5536 {100, 100, FALSE},
5537 {99, 100, FALSE},
5538 {3, 39, FALSE},
5541 hr = Direct3DRMCreate(&d3drm1);
5542 ok(hr == D3DRM_OK, "Failed to create IDirect3DRM object, hr %#x.\n", hr);
5543 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5544 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM2 interface, hr %#x.\n", hr);
5545 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5546 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM3 interface, hr %#x.\n", hr);
5548 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
5550 filename = create_bitmap(tests[i].w, tests[i].h, tests[i].palettized);
5552 hr = IDirect3DRM_LoadTexture(d3drm1, filename, &texture1);
5553 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5554 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
5555 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5556 if (d3drm_img)
5557 test_bitmap_data(i * 4, d3drm_img, FALSE, tests[i].w, tests[i].h, tests[i].palettized);
5558 IDirect3DRMTexture_Release(texture1);
5560 hr = IDirect3DRM2_LoadTexture(d3drm2, filename, &texture2);
5561 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5562 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
5563 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5564 if (d3drm_img)
5565 test_bitmap_data(i * 4 + 1, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5566 IDirect3DRMTexture2_Release(texture2);
5568 hr = IDirect3DRM3_LoadTexture(d3drm3, filename, &texture3);
5569 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5570 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
5571 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5572 if (d3drm_img)
5573 test_bitmap_data(i * 4 + 2, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5574 /* Test whether querying a version 1 texture from version 3 causes a
5575 * change in the loading behavior. */
5576 hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IDirect3DRMTexture, (void **)&texture1);
5577 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMTexture interface, hr %#x.\n", hr);
5578 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
5579 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5580 if (d3drm_img)
5581 test_bitmap_data(i * 4 + 3, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5582 IDirect3DRMTexture_Release(texture1);
5583 IDirect3DRMTexture3_Release(texture3);
5585 ret = DeleteFileA(filename);
5586 ok(ret, "Test %u: Failed to delete bitmap \"%s\".\n", i, filename);
5587 HeapFree(GetProcessHeap(), 0, filename);
5590 IDirect3DRM3_Release(d3drm3);
5591 IDirect3DRM2_Release(d3drm2);
5592 IDirect3DRM_Release(d3drm1);
5595 static void test_texture_qi(void)
5597 static const struct qi_test tests[] =
5599 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5600 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5601 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5602 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5603 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5604 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5605 { &IID_IDirect3DRMWinDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5606 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5607 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5608 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5609 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5610 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5611 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5612 { &IID_IDirect3DRMVisual, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5613 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5614 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5615 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5616 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5617 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5618 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5619 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5620 { &IID_IDirect3DRMTexture, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5621 { &IID_IDirect3DRMTexture2, &IID_IUnknown, &IID_IDirect3DRMTexture2, S_OK },
5622 { &IID_IDirect3DRMTexture3, &IID_IUnknown, &IID_IDirect3DRMTexture3, S_OK },
5623 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5624 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5625 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5626 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5627 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5628 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5629 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5630 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5631 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5632 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5633 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5634 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5635 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5636 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5637 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5638 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5639 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5640 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5641 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5642 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5643 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5644 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5645 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5646 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5647 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5648 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5649 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5650 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5651 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5652 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5653 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5654 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5655 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5656 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5657 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5658 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5659 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5660 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5661 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5662 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5663 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5664 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5665 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5666 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
5668 HRESULT hr;
5669 IDirect3DRM *d3drm1;
5670 IDirect3DRM2 *d3drm2;
5671 IDirect3DRM3 *d3drm3;
5672 IDirect3DRMTexture *texture1;
5673 IDirect3DRMTexture2 *texture2;
5674 IDirect3DRMTexture3 *texture3;
5675 IUnknown *unknown;
5676 char *filename;
5677 BOOL check;
5679 hr = Direct3DRMCreate(&d3drm1);
5680 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x)\n", hr);
5681 filename = create_bitmap(1, 1, TRUE);
5682 hr = IDirect3DRM_LoadTexture(d3drm1, filename, &texture1);
5683 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5684 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
5685 hr = IDirect3DRMTexture_QueryInterface(texture1, &IID_IUnknown, (void **)&unknown);
5686 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture (hr = %#x)\n", hr);
5687 IDirect3DRMTexture_Release(texture1);
5688 test_qi("texture1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5689 IUnknown_Release(unknown);
5691 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5692 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
5693 hr = IDirect3DRM2_LoadTexture(d3drm2, filename, &texture2);
5694 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5695 hr = IDirect3DRMTexture2_QueryInterface(texture2, &IID_IUnknown, (void **)&unknown);
5696 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture2 (hr = %#x)\n", hr);
5697 IDirect3DRMTexture2_Release(texture2);
5698 test_qi("texture2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5699 IUnknown_Release(unknown);
5701 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5702 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
5703 hr = IDirect3DRM3_LoadTexture(d3drm3, filename, &texture3);
5704 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5705 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
5706 hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IUnknown, (void **)&unknown);
5707 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture3 (hr = %#x)\n", hr);
5708 IDirect3DRMTexture3_Release(texture3);
5709 test_qi("texture3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5710 IUnknown_Release(unknown);
5712 IDirect3DRM3_Release(d3drm3);
5713 IDirect3DRM2_Release(d3drm2);
5714 IDirect3DRM_Release(d3drm1);
5715 check = DeleteFileA(filename);
5716 ok(check, "Cannot delete image stored in %s (error = %d).\n", filename, GetLastError());
5717 HeapFree(GetProcessHeap(), 0, filename);
5720 static void test_viewport_qi(void)
5722 IDirect3DRM *d3drm1;
5723 IDirect3DRM2 *d3drm2;
5724 IDirect3DRM3 *d3drm3;
5725 IDirect3DRMFrame *frame1, *camera1;
5726 IDirect3DRMFrame3 *frame3, *camera3;
5727 IDirect3DRMDevice *device1;
5728 IDirect3DRMDevice3 *device3;
5729 IDirectDrawClipper *clipper;
5730 IDirect3DRMViewport *viewport1;
5731 IDirect3DRMViewport2 *viewport2;
5732 IUnknown *unknown;
5733 GUID driver = IID_IDirect3DRGBDevice;
5734 HRESULT hr;
5736 static const struct qi_test tests[] =
5738 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5739 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5740 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5741 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5742 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5743 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5744 { &IID_IDirect3DRMWinDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5745 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMViewport, S_OK },
5746 { &IID_IDirect3DRMViewport, &IID_IUnknown, &IID_IDirect3DRMViewport, S_OK },
5747 { &IID_IDirect3DRMViewport2, &IID_IUnknown, &IID_IDirect3DRMViewport2, S_OK },
5748 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5749 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5750 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5751 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5752 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5753 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5754 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5755 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5756 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5757 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5758 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5759 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5760 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5761 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5762 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5763 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5764 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5765 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5766 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5767 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5768 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5769 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5770 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5771 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5772 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5773 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5774 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5775 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5776 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5777 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5778 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5779 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5780 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5781 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5782 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5783 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5784 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5785 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5786 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5787 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5788 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5789 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5790 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5791 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5792 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5793 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5794 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5795 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5796 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5797 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5798 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5799 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5800 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5801 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5802 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5803 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5804 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5805 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
5808 hr = DirectDrawCreateClipper(0, &clipper, NULL);
5809 ok(SUCCEEDED(hr), "Cannot get IDirectDrawClipper interface (hr = %#x).\n", hr);
5811 hr = Direct3DRMCreate(&d3drm1);
5812 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
5814 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 640, 480, &device1);
5815 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
5816 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
5817 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
5818 hr = IDirect3DRM_CreateFrame(d3drm1, frame1, &camera1);
5819 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
5820 hr = IDirect3DRM_CreateViewport(d3drm1, device1, camera1, 0, 0, 640, 480, &viewport1);
5821 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
5822 hr = IDirect3DRMViewport_QueryInterface(viewport1, &IID_IUnknown, (void **)&unknown);
5823 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5824 IDirect3DRMViewport_Release(viewport1);
5825 test_qi("viewport1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5826 IUnknown_Release(unknown);
5828 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5829 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
5830 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, camera1, 0, 0, 640, 480, &viewport1);
5831 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
5832 hr = IDirect3DRMViewport_QueryInterface(viewport1, &IID_IUnknown, (void **)&unknown);
5833 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5834 IDirect3DRMViewport_Release(viewport1);
5835 test_qi("viewport1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5836 IUnknown_Release(unknown);
5837 IDirect3DRMDevice_Release(device1);
5838 IDirect3DRMFrame_Release(camera1);
5839 IDirect3DRMFrame_Release(frame1);
5841 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5842 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
5843 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 640, 480, &device3);
5844 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5845 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
5846 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
5847 hr = IDirect3DRM3_CreateFrame(d3drm3, frame3, &camera3);
5848 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
5849 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, 640, 480, &viewport2);
5850 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
5851 hr = IDirect3DRMViewport2_QueryInterface(viewport2, &IID_IUnknown, (void **)&unknown);
5852 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5853 IDirect3DRMViewport_Release(viewport2);
5854 test_qi("viewport2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5855 IUnknown_Release(unknown);
5856 IDirect3DRMDevice3_Release(device3);
5857 IDirect3DRMFrame3_Release(camera3);
5858 IDirect3DRMFrame3_Release(frame3);
5860 IDirectDrawClipper_Release(clipper);
5861 IDirect3DRM3_Release(d3drm3);
5862 IDirect3DRM2_Release(d3drm2);
5863 IDirect3DRM_Release(d3drm1);
5866 static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y)
5868 RECT rect = { x, y, x + 1, y + 1 };
5869 DDSURFACEDESC surface_desc;
5870 D3DCOLOR color;
5871 HRESULT hr;
5873 memset(&surface_desc, 0, sizeof(surface_desc));
5874 surface_desc.dwSize = sizeof(surface_desc);
5876 hr = IDirectDrawSurface_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
5877 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5878 if (FAILED(hr))
5879 return 0xdeadbeef;
5881 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
5883 hr = IDirectDrawSurface_Unlock(surface, NULL);
5884 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5886 return color;
5889 static IDirect3DDevice2 *create_device2_without_ds(IDirectDraw2 *ddraw, HWND window)
5891 IDirectDrawSurface *surface;
5892 IDirect3DDevice2 *device = NULL;
5893 DDSURFACEDESC surface_desc;
5894 IDirect3D2 *d3d;
5895 HRESULT hr;
5896 RECT rc;
5898 GetClientRect(window, &rc);
5899 hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5900 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5902 memset(&surface_desc, 0, sizeof(surface_desc));
5903 surface_desc.dwSize = sizeof(surface_desc);
5904 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5905 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5906 surface_desc.dwWidth = rc.right;
5907 surface_desc.dwHeight = rc.bottom;
5909 hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5910 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5912 hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
5913 if (FAILED(hr))
5915 IDirectDrawSurface_Release(surface);
5916 return NULL;
5919 IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device);
5921 IDirect3D2_Release(d3d);
5922 IDirectDrawSurface_Release(surface);
5923 return device;
5926 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
5928 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5929 c1 >>= 8; c2 >>= 8;
5930 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5931 c1 >>= 8; c2 >>= 8;
5932 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5933 c1 >>= 8; c2 >>= 8;
5934 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5935 return TRUE;
5938 static void clear_depth_surface(IDirectDrawSurface *surface, DWORD value)
5940 HRESULT hr;
5941 DDBLTFX fx;
5943 memset(&fx, 0, sizeof(fx));
5944 fx.dwSize = sizeof(fx);
5945 U5(fx).dwFillDepth = value;
5947 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
5948 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5951 static void set_execute_data(IDirect3DExecuteBuffer *execute_buffer, UINT vertex_count, UINT offset, UINT len)
5953 D3DEXECUTEDATA exec_data;
5954 HRESULT hr;
5956 memset(&exec_data, 0, sizeof(exec_data));
5957 exec_data.dwSize = sizeof(exec_data);
5958 exec_data.dwVertexCount = vertex_count;
5959 exec_data.dwInstructionOffset = offset;
5960 exec_data.dwInstructionLength = len;
5961 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
5962 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
5965 static void emit_set_ts(void **ptr, D3DTRANSFORMSTATETYPE state, DWORD value)
5967 D3DINSTRUCTION *inst = *ptr;
5968 D3DSTATE *ts = (D3DSTATE *)(inst + 1);
5970 inst->bOpcode = D3DOP_STATETRANSFORM;
5971 inst->bSize = sizeof(*ts);
5972 inst->wCount = 1;
5974 U1(*ts).dtstTransformStateType = state;
5975 U2(*ts).dwArg[0] = value;
5977 *ptr = ts + 1;
5980 static void emit_set_rs(void **ptr, D3DRENDERSTATETYPE state, DWORD value)
5982 D3DINSTRUCTION *inst = *ptr;
5983 D3DSTATE *rs = (D3DSTATE *)(inst + 1);
5985 inst->bOpcode = D3DOP_STATERENDER;
5986 inst->bSize = sizeof(*rs);
5987 inst->wCount = 1;
5989 U1(*rs).drstRenderStateType = state;
5990 U2(*rs).dwArg[0] = value;
5992 *ptr = rs + 1;
5995 static void emit_process_vertices(void **ptr, DWORD flags, WORD base_idx, DWORD vertex_count)
5997 D3DINSTRUCTION *inst = *ptr;
5998 D3DPROCESSVERTICES *pv = (D3DPROCESSVERTICES *)(inst + 1);
6000 inst->bOpcode = D3DOP_PROCESSVERTICES;
6001 inst->bSize = sizeof(*pv);
6002 inst->wCount = 1;
6004 pv->dwFlags = flags;
6005 pv->wStart = base_idx;
6006 pv->wDest = 0;
6007 pv->dwCount = vertex_count;
6008 pv->dwReserved = 0;
6010 *ptr = pv + 1;
6013 static void emit_tquad(void **ptr, WORD base_idx)
6015 D3DINSTRUCTION *inst = *ptr;
6016 D3DTRIANGLE *tri = (D3DTRIANGLE *)(inst + 1);
6018 inst->bOpcode = D3DOP_TRIANGLE;
6019 inst->bSize = sizeof(*tri);
6020 inst->wCount = 2;
6022 U1(*tri).v1 = base_idx;
6023 U2(*tri).v2 = base_idx + 1;
6024 U3(*tri).v3 = base_idx + 2;
6025 tri->wFlags = D3DTRIFLAG_START;
6026 ++tri;
6028 U1(*tri).v1 = base_idx + 2;
6029 U2(*tri).v2 = base_idx + 1;
6030 U3(*tri).v3 = base_idx + 3;
6031 tri->wFlags = D3DTRIFLAG_ODD;
6032 ++tri;
6034 *ptr = tri;
6037 static void emit_end(void **ptr)
6039 D3DINSTRUCTION *inst = *ptr;
6041 inst->bOpcode = D3DOP_EXIT;
6042 inst->bSize = 0;
6043 inst->wCount = 0;
6045 *ptr = inst + 1;
6048 static void d3d_draw_quad1(IDirect3DDevice *device, IDirect3DViewport *viewport)
6050 IDirect3DExecuteBuffer *execute_buffer;
6051 D3DEXECUTEBUFFERDESC exec_desc;
6052 HRESULT hr;
6053 void *ptr;
6054 UINT inst_length;
6055 D3DMATRIXHANDLE world_handle, view_handle, proj_handle;
6056 static D3DMATRIX mat =
6058 1.0f, 0.0f, 0.0f, 0.0f,
6059 0.0f, 1.0f, 0.0f, 0.0f,
6060 0.0f, 0.0f, 1.0f, 0.0f,
6061 0.0f, 0.0f, 0.0f, 1.0f,
6063 static const D3DLVERTEX quad_strip[] =
6065 {{-1.0f}, {-1.0f}, {0.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6066 {{-1.0f}, { 1.0f}, {0.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6067 {{ 1.0f}, {-1.0f}, {1.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6068 {{ 1.0f}, { 1.0f}, {1.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6071 hr = IDirect3DDevice_CreateMatrix(device, &world_handle);
6072 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6073 hr = IDirect3DDevice_SetMatrix(device, world_handle, &mat);
6074 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6075 hr = IDirect3DDevice_CreateMatrix(device, &view_handle);
6076 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6077 hr = IDirect3DDevice_SetMatrix(device, view_handle, &mat);
6078 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6079 hr = IDirect3DDevice_CreateMatrix(device, &proj_handle);
6080 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6081 hr = IDirect3DDevice_SetMatrix(device, proj_handle, &mat);
6082 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6084 memset(&exec_desc, 0, sizeof(exec_desc));
6085 exec_desc.dwSize = sizeof(exec_desc);
6086 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
6087 exec_desc.dwBufferSize = 1024;
6088 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
6090 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
6091 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
6093 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6094 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6096 memcpy(exec_desc.lpData, quad_strip, sizeof(quad_strip));
6097 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad_strip);
6098 emit_set_ts(&ptr, D3DTRANSFORMSTATE_WORLD, world_handle);
6099 emit_set_ts(&ptr, D3DTRANSFORMSTATE_VIEW, view_handle);
6100 emit_set_ts(&ptr, D3DTRANSFORMSTATE_PROJECTION, proj_handle);
6101 emit_set_rs(&ptr, D3DRENDERSTATE_CLIPPING, FALSE);
6102 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, TRUE);
6103 emit_set_rs(&ptr, D3DRENDERSTATE_FOGENABLE, FALSE);
6104 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
6105 emit_set_rs(&ptr, D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT);
6107 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
6108 emit_tquad(&ptr, 0);
6110 emit_end(&ptr);
6111 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6112 inst_length -= sizeof(quad_strip);
6114 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6115 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6117 hr = IDirect3DDevice_BeginScene(device);
6118 set_execute_data(execute_buffer, 4, sizeof(quad_strip), inst_length);
6119 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
6120 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6121 hr = IDirect3DDevice_EndScene(device);
6122 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6124 IDirect3DExecuteBuffer_Release(execute_buffer);
6127 static void test_viewport_clear1(void)
6129 DDSCAPS caps = { DDSCAPS_ZBUFFER };
6130 IDirectDraw *ddraw;
6131 IDirectDrawClipper *clipper;
6132 IDirect3DRM *d3drm1;
6133 IDirect3DRMFrame *frame1, *camera1;
6134 IDirect3DRMDevice *device1;
6135 IDirect3DViewport *d3d_viewport;
6136 IDirect3DRMViewport *viewport1;
6137 IDirect3DDevice *d3d_device1;
6138 IDirectDrawSurface *surface, *ds, *d3drm_ds;
6139 HWND window;
6140 GUID driver = IID_IDirect3DRGBDevice;
6141 HRESULT hr;
6142 D3DCOLOR ret_color;
6143 RECT rc;
6145 window = create_window();
6146 GetClientRect(window, &rc);
6148 hr = DirectDrawCreate(NULL, &ddraw, NULL);
6149 ok(SUCCEEDED(hr), "Cannot create IDirectDraw interface (hr = %#x).\n", hr);
6151 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6152 ok(SUCCEEDED(hr), "Failed to set cooperative level (hr = %#x).\n", hr);
6154 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
6155 ok(SUCCEEDED(hr), "Cannot create clipper (hr = %#x).\n", hr);
6157 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
6158 ok(SUCCEEDED(hr), "Cannot set HWnd to Clipper (hr = %#x)\n", hr);
6160 hr = Direct3DRMCreate(&d3drm1);
6161 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
6163 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
6164 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %#x)\n", hr);
6166 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
6167 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
6168 hr = IDirect3DRM_CreateFrame(d3drm1, frame1, &camera1);
6169 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
6171 hr = IDirect3DRM_CreateViewport(d3drm1, device1, camera1, 0, 0, rc.right,
6172 rc.bottom, &viewport1);
6173 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6175 /* Fetch immediate mode device and viewport */
6176 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3d_device1);
6177 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice interface (hr = %#x).\n", hr);
6178 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport1, &d3d_viewport);
6179 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
6181 hr = IDirect3DDevice_QueryInterface(d3d_device1, &IID_IDirectDrawSurface, (void **)&surface);
6182 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6184 ret_color = get_surface_color(surface, 320, 240);
6185 ok(compare_color(ret_color, 0, 1), "Got unexpected color 0x%08x.\n", ret_color);
6187 /* Clear uses the scene frame's background color. */
6188 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(frame1, 1.0f, 1.0f, 1.0f);
6189 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6190 ret_color = IDirect3DRMFrame_GetSceneBackground(frame1);
6191 ok(ret_color == 0xffffffff, "Expected scene color returned == 0xffffffff, got %#x.\n", ret_color);
6192 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(camera1, 0.0f, 1.0f, 0.0f);
6193 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6194 ret_color = IDirect3DRMFrame_GetSceneBackground(camera1);
6195 ok(ret_color == 0xff00ff00, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6197 hr = IDirect3DRMViewport_Clear(viewport1);
6198 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6199 ret_color = get_surface_color(surface, 320, 240);
6200 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6202 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(frame1, 0.0f, 0.0f, 1.0f);
6203 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6204 ret_color = IDirect3DRMFrame_GetSceneBackground(frame1);
6205 ok(ret_color == 0xff0000ff, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6207 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6208 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6209 hr = IDirect3DRMViewport_Clear(viewport1);
6210 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6211 ret_color = get_surface_color(surface, 100, 200);
6212 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6214 d3d_draw_quad1(d3d_device1, d3d_viewport);
6216 ret_color = get_surface_color(surface, 100, 200);
6217 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6219 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
6220 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
6222 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6223 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6224 hr = IDirect3DRMViewport_Clear(viewport1);
6225 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6226 ret_color = get_surface_color(surface, 100, 200);
6227 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6229 /* Fill the depth surface with a value lower than the quad's depth value. */
6230 clear_depth_surface(ds, 0x7fff);
6232 /* Depth test passes here */
6233 d3d_draw_quad1(d3d_device1, d3d_viewport);
6234 ret_color = get_surface_color(surface, 100, 200);
6235 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6236 /* Depth test fails here */
6237 ret_color = get_surface_color(surface, 500, 400);
6238 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6240 /* Check what happens if we release the depth surface that d3drm created, and clear the viewport */
6241 hr = IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
6242 ok(SUCCEEDED(hr), "Cannot delete attached surface (hr = %#x).\n", hr);
6243 d3drm_ds = (IDirectDrawSurface *)0xdeadbeef;
6244 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
6245 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %#x.\n", hr);
6246 ok(d3drm_ds == NULL, "Expected NULL z-surface, got %p.\n", d3drm_ds);
6248 clear_depth_surface(ds, 0x7fff);
6249 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6250 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6251 hr = IDirect3DRMViewport_Clear(viewport1);
6252 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6254 ret_color = get_surface_color(surface, 100, 200);
6255 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6257 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
6258 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
6259 IDirectDrawSurface_Release(ds);
6261 d3d_draw_quad1(d3d_device1, d3d_viewport);
6263 ret_color = get_surface_color(surface, 100, 200);
6264 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6265 ret_color = get_surface_color(surface, 500, 400);
6266 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6268 IDirect3DViewport_Release(d3d_viewport);
6269 IDirectDrawSurface_Release(surface);
6270 IDirect3DDevice_Release(d3d_device1);
6271 IDirect3DRMViewport_Release(viewport1);
6272 IDirect3DRMFrame_Release(frame1);
6273 IDirect3DRMFrame_Release(camera1);
6274 IDirect3DRMDevice_Release(device1);
6275 IDirect3DRM_Release(d3drm1);
6276 IDirectDrawClipper_Release(clipper);
6277 IDirectDraw_Release(ddraw);
6278 DestroyWindow(window);
6281 static void draw_quad2(IDirect3DDevice2 *device, IDirect3DViewport *viewport)
6283 static D3DLVERTEX tquad[] =
6285 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6286 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffbada55}, {0}, {0.0f}, {1.0f}},
6287 {{ 1.0f}, {-1.0f}, {1.0f}, 0, {0xffbada55}, {0}, {1.0f}, {0.0f}},
6288 {{ 1.0f}, { 1.0f}, {1.0f}, 0, {0xffbada55}, {0}, {1.0f}, {1.0f}},
6290 static D3DMATRIX mat =
6292 1.0f, 0.0f, 0.0f, 0.0f,
6293 0.0f, 1.0f, 0.0f, 0.0f,
6294 0.0f, 0.0f, 1.0f, 0.0f,
6295 0.0f, 0.0f, 0.0f, 1.0f,
6297 IDirect3DViewport2 *viewport2;
6298 HRESULT hr;
6300 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
6301 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
6302 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
6303 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
6304 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
6305 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
6307 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport2, (void **)&viewport2);
6308 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport2 interface (hr = %#x).\n", hr);
6309 hr = IDirect3DDevice2_SetCurrentViewport(device, viewport2);
6310 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
6311 IDirect3DViewport2_Release(viewport2);
6313 hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
6314 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
6315 hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
6316 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
6318 hr = IDirect3DDevice2_BeginScene(device);
6319 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6320 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DVT_LVERTEX, tquad, 4, 0);
6321 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6322 hr = IDirect3DDevice2_EndScene(device);
6323 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6326 static void test_viewport_clear2(void)
6328 DDSCAPS caps = { DDSCAPS_ZBUFFER };
6329 IDirect3D2 *d3d2;
6330 IDirectDraw *ddraw1;
6331 IDirectDraw2 *ddraw2;
6332 IDirectDrawClipper *clipper;
6333 IDirect3DRM *d3drm1;
6334 IDirect3DRM3 *d3drm3;
6335 IDirect3DRMFrame3 *frame3, *camera3;
6336 IDirect3DRMDevice3 *device3;
6337 IDirect3DViewport *d3d_viewport;
6338 IDirect3DRMViewport2 *viewport2;
6339 IDirect3DDevice2 *d3d_device2;
6340 IDirectDrawSurface *surface, *ds, *d3drm_ds;
6341 HWND window;
6342 GUID driver = IID_IDirect3DRGBDevice;
6343 HRESULT hr;
6344 D3DCOLOR ret_color;
6345 RECT rc;
6347 window = create_window();
6348 GetClientRect(window, &rc);
6350 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
6351 ok(SUCCEEDED(hr), "Cannot create IDirectDraw interface (hr = %#x).\n", hr);
6353 hr = IDirectDraw_SetCooperativeLevel(ddraw1, window, DDSCL_NORMAL);
6354 ok(SUCCEEDED(hr), "Failed to set cooperative level (hr = %#x).\n", hr);
6356 hr = IDirectDraw_CreateClipper(ddraw1, 0, &clipper, NULL);
6357 ok(SUCCEEDED(hr), "Cannot create clipper (hr = %#x).\n", hr);
6359 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
6360 ok(SUCCEEDED(hr), "Cannot set HWnd to Clipper (hr = %#x)\n", hr);
6362 hr = Direct3DRMCreate(&d3drm1);
6363 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
6365 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
6366 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
6368 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
6369 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice3 interface (hr = %#x)\n", hr);
6371 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
6372 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
6373 hr = IDirect3DRM3_CreateFrame(d3drm3, frame3, &camera3);
6374 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
6376 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, rc.right,
6377 rc.bottom, &viewport2);
6378 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6380 /* Fetch immediate mode device in order to access render target and test its color. */
6381 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3d_device2);
6382 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
6384 hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
6385 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6387 ret_color = get_surface_color(surface, 320, 240);
6388 ok(compare_color(ret_color, 0, 1), "Got unexpected color 0x%08x.\n", ret_color);
6390 /* Clear uses the scene frame's background color. */
6391 hr = IDirect3DRMFrame3_SetSceneBackgroundRGB(frame3, 1.0f, 1.0f, 1.0f);
6392 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6393 ret_color = IDirect3DRMFrame3_GetSceneBackground(frame3);
6394 ok(ret_color == 0xffffffff, "Expected scene color returned == 0xffffffff, got %#x.\n", ret_color);
6395 hr = IDirect3DRMFrame3_SetSceneBackgroundRGB(camera3, 0.0f, 1.0f, 0.0f);
6396 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6397 ret_color = IDirect3DRMFrame3_GetSceneBackground(camera3);
6398 ok(ret_color == 0xff00ff00, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6400 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6401 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6402 ret_color = get_surface_color(surface, 320, 240);
6403 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6405 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
6406 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
6408 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6409 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6411 /* d3drm seems to be calling BeginScene when Clear is called. */
6412 hr = IDirect3DDevice2_BeginScene(d3d_device2);
6413 todo_wine ok(hr == D3DERR_SCENE_IN_SCENE, "Expected hr == D3DERR_SCENE_IN_SCENE, got %#x.\n", hr);
6414 hr = IDirect3DDevice2_EndScene(d3d_device2);
6415 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6417 ret_color = get_surface_color(surface, 320, 240);
6418 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6420 /* We're using d3d to draw using IDirect3DDevice2 created from d3drm. */
6421 draw_quad2(d3d_device2, d3d_viewport);
6422 ret_color = get_surface_color(surface, 320, 240);
6423 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6425 /* Without calling Configure, Clear doesn't work. */
6426 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6427 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6428 ret_color = get_surface_color(surface, 320, 240);
6429 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6431 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6432 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6433 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6434 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6436 ret_color = get_surface_color(surface, 320, 240);
6437 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6439 /* Fetch attached depth surface and see if viewport clears it if it's detached from the render target. */
6440 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
6441 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
6443 clear_depth_surface(ds, 0x39);
6444 draw_quad2(d3d_device2, d3d_viewport);
6446 ret_color = get_surface_color(surface, 320, 240);
6447 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6449 hr = IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
6450 ok(SUCCEEDED(hr), "Cannot delete attached surface (hr = %#x).\n", hr);
6451 d3drm_ds = (IDirectDrawSurface *)0xdeadbeef;
6452 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
6453 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %#x.\n", hr);
6454 ok(d3drm_ds == NULL, "Expected NULL z-surface, got %p.\n", d3drm_ds);
6456 clear_depth_surface(ds, 0x7fff);
6458 /* This version of Clear still clears the depth surface even if it's deleted from the render target. */
6459 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6460 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6461 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6462 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6464 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
6465 ok(SUCCEEDED(hr), "Failed to attach depth buffer, 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 draw_quad2(d3d_device2, d3d_viewport);
6470 ret_color = get_surface_color(surface, 100, 200);
6471 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6472 ret_color = get_surface_color(surface, 500, 400);
6473 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6475 /* Clear with no flags */
6476 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6477 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6478 hr = IDirect3DRMViewport2_Clear(viewport2, 0);
6479 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6480 ret_color = get_surface_color(surface, 320, 240);
6481 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6483 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6484 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6485 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6486 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6487 ret_color = get_surface_color(surface, 320, 240);
6488 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6490 IDirect3DViewport_Release(d3d_viewport);
6491 IDirectDrawSurface_Release(surface);
6492 IDirectDrawSurface_Release(ds);
6493 IDirect3DDevice2_Release(d3d_device2);
6494 IDirect3DRMViewport2_Release(viewport2);
6495 IDirect3DRMDevice3_Release(device3);
6497 /* Create device without depth surface attached */
6498 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
6499 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
6500 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
6501 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
6502 d3d_device2 = create_device2_without_ds(ddraw2, window);
6503 if (!d3d_device2)
6504 goto cleanup;
6506 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3d_device2, &device3);
6507 ok(SUCCEEDED(hr), "Failed to create IDirect3DRMDevice interface (hr = %#x)\n", hr);
6508 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, rc.right,
6509 rc.bottom, &viewport2);
6510 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6511 hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
6512 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6514 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6515 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6516 ret_color = get_surface_color(surface, 320, 240);
6517 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6519 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ZBUFFER);
6520 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6522 IDirectDrawSurface_Release(surface);
6523 IDirect3DRMViewport2_Release(viewport2);
6524 IDirect3DRMDevice3_Release(device3);
6525 IDirect3DDevice2_Release(d3d_device2);
6527 cleanup:
6528 IDirect3DRMFrame3_Release(camera3);
6529 IDirect3DRMFrame3_Release(frame3);
6530 IDirect3DRM3_Release(d3drm3);
6531 IDirect3DRM_Release(d3drm1);
6532 IDirectDrawClipper_Release(clipper);
6533 IDirect3D2_Release(d3d2);
6534 IDirectDraw2_Release(ddraw2);
6535 IDirectDraw_Release(ddraw1);
6536 DestroyWindow(window);
6539 static void test_create_texture_from_surface(void)
6541 D3DRMIMAGE testimg =
6543 0, 0, 0, 0, 0,
6544 TRUE, 0, (void *)0xcafebabe, NULL,
6545 0x000000ff, 0x0000ff00, 0x00ff0000, 0, 0, NULL
6547 IDirectDrawSurface *surface = NULL, *surface2 = NULL, *ds = NULL;
6548 IDirect3DRMTexture *texture1;
6549 IDirect3DRMTexture2 *texture2;
6550 IDirect3DRMTexture3 *texture3;
6551 IDirectDraw *ddraw = NULL;
6552 IDirect3DRM *d3drm1 = NULL;
6553 IDirect3DRM2 *d3drm2 = NULL;
6554 IDirect3DRM3 *d3drm3 = NULL;
6555 ULONG ref1, ref2, ref3;
6556 D3DRMIMAGE *image;
6557 DDSURFACEDESC desc;
6558 HWND window;
6559 HRESULT hr;
6560 RECT rc;
6562 hr = DirectDrawCreate(NULL, &ddraw, NULL);
6563 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
6565 window = create_window();
6566 GetClientRect(window, &rc);
6568 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6569 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6571 hr = Direct3DRMCreate(&d3drm1);
6572 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
6574 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
6575 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
6577 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
6578 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
6580 /* Create a surface and use it to create a texture. */
6581 memset(&desc, 0, sizeof(desc));
6582 desc.dwSize = sizeof(desc);
6583 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6584 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6585 desc.dwWidth = rc.right;
6586 desc.dwHeight = rc.bottom;
6588 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
6589 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6591 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface2, NULL);
6592 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6594 /* Test NULL params */
6595 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
6596 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, NULL, &texture1);
6597 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6598 ok(!texture1, "Expected texture returned == NULL, got %p.\n", texture1);
6600 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, NULL, NULL);
6601 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6603 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
6604 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, NULL, &texture2);
6605 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6606 ok(!texture2, "Expected texture returned == NULL, got %p.\n", texture2);
6608 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, NULL, NULL);
6609 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6611 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
6612 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, NULL, &texture3);
6613 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6614 ok(!texture3, "Expected texture returned == NULL, got %p.\n", texture3);
6616 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, NULL, NULL);
6617 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6619 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6620 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, surface, &texture1);
6621 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6623 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6624 image = IDirect3DRMTexture_GetImage(texture1);
6625 ok(image == NULL, "Unexpected image, %p.\n", image);
6626 hr = IDirect3DRMTexture_InitFromSurface(texture1, NULL);
6627 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6628 IDirect3DRMTexture_Release(texture1);
6630 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6631 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, surface, &texture2);
6632 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6633 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6634 image = IDirect3DRMTexture2_GetImage(texture2);
6635 ok(image == NULL, "Unexpected image, %p.\n", image);
6636 hr = IDirect3DRMTexture2_InitFromSurface(texture2, NULL);
6637 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6638 IDirect3DRMTexture_Release(texture2);
6640 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6641 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, surface, &texture3);
6642 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6643 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6644 image = IDirect3DRMTexture3_GetImage(texture3);
6645 ok(image == NULL, "Unexpected image, %p.\n", image);
6646 hr = IDirect3DRMTexture3_InitFromSurface(texture3, NULL);
6647 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6648 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, NULL);
6649 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6650 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &ds);
6651 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
6652 ok(ds == surface, "Expected same surface back.\n");
6653 IDirectDrawSurface_Release(ds);
6655 /* Init already initialized texture with same surface. */
6656 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface);
6657 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6659 /* Init already initialized texture with different surface. */
6660 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface2);
6661 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6663 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &ds);
6664 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
6665 ok(ds == surface, "Expected same surface back.\n");
6666 IDirectDrawSurface_Release(ds);
6668 ref1 = get_refcount((IUnknown *)d3drm1);
6669 ref2 = get_refcount((IUnknown *)d3drm2);
6670 ref3 = get_refcount((IUnknown *)d3drm3);
6671 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
6672 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6673 ok(ref1 < get_refcount((IUnknown *)d3drm1), "Expected d3drm1 reference taken.\n");
6674 ok(ref2 == get_refcount((IUnknown *)d3drm2), "Expected d3drm2 reference unchanged.\n");
6675 ok(ref3 == get_refcount((IUnknown *)d3drm3), "Expected d3drm3 reference unchanged.\n");
6676 /* Release leaked reference to d3drm1 */
6677 IDirect3DRM_Release(d3drm1);
6679 IDirect3DRMTexture_Release(texture3);
6681 /* Create from image, initialize from surface. */
6682 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
6683 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
6685 ref1 = get_refcount((IUnknown *)d3drm1);
6686 ref2 = get_refcount((IUnknown *)d3drm2);
6687 ref3 = get_refcount((IUnknown *)d3drm3);
6688 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface);
6689 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6690 ok(ref1 < get_refcount((IUnknown *)d3drm1), "Expected d3drm1 reference taken.\n");
6691 ok(ref2 == get_refcount((IUnknown *)d3drm2), "Expected d3drm2 reference unchanged.\n");
6692 ok(ref3 == get_refcount((IUnknown *)d3drm3), "Expected d3drm3 reference unchanged.\n");
6693 /* Release leaked reference to d3drm1 */
6694 IDirect3DRM_Release(d3drm1);
6695 IDirect3DRMTexture3_Release(texture3);
6697 IDirectDrawSurface_Release(surface2);
6698 IDirectDrawSurface_Release(surface);
6699 IDirect3DRM3_Release(d3drm3);
6700 IDirect3DRM2_Release(d3drm2);
6701 IDirect3DRM_Release(d3drm1);
6702 IDirectDraw_Release(ddraw);
6705 static void test_animation(void)
6707 IDirect3DRMAnimation2 *animation2;
6708 IDirect3DRMAnimation *animation;
6709 D3DRMANIMATIONOPTIONS options;
6710 IDirect3DRMObject *obj, *obj2;
6711 IDirect3DRMFrame3 *frame3;
6712 IDirect3DRMFrame *frame;
6713 IDirect3DRM *d3drm1;
6714 HRESULT hr;
6716 hr = Direct3DRMCreate(&d3drm1);
6717 ok(SUCCEEDED(hr), "Failed to create IDirect3DRM instance, hr 0x%08x.\n", hr);
6719 hr = IDirect3DRM_CreateAnimation(d3drm1, NULL);
6720 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr 0x%08x.\n", hr);
6722 CHECK_REFCOUNT(d3drm1, 1);
6723 hr = IDirect3DRM_CreateAnimation(d3drm1, &animation);
6724 ok(SUCCEEDED(hr), "Failed to create animation hr 0x%08x.\n", hr);
6725 CHECK_REFCOUNT(d3drm1, 2);
6727 test_class_name((IDirect3DRMObject *)animation, "Animation");
6729 hr = IDirect3DRMAnimation_QueryInterface(animation, &IID_IDirect3DRMAnimation2, (void **)&animation2);
6730 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMAnimation2, hr 0x%08x.\n", hr);
6731 ok(animation != (void *)animation2, "Expected different interface pointer.\n");
6733 hr = IDirect3DRMAnimation_QueryInterface(animation, &IID_IDirect3DRMObject, (void **)&obj);
6734 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, hr 0x%08x.\n", hr);
6736 hr = IDirect3DRMAnimation2_QueryInterface(animation2, &IID_IDirect3DRMObject, (void **)&obj2);
6737 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, hr 0x%08x.\n", hr);
6739 ok(obj == obj2 && obj == (IDirect3DRMObject *)animation, "Unexpected object pointer.\n");
6741 IDirect3DRMObject_Release(obj);
6742 IDirect3DRMObject_Release(obj2);
6744 /* Set animated frame, get it back. */
6745 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame);
6746 ok(SUCCEEDED(hr), "Failed to create a frame, hr %#x.\n", hr);
6748 hr = IDirect3DRMAnimation_SetFrame(animation, NULL);
6749 ok(SUCCEEDED(hr), "Failed to reset frame, hr %#x.\n", hr);
6751 CHECK_REFCOUNT(frame, 1);
6752 hr = IDirect3DRMAnimation_SetFrame(animation, frame);
6753 ok(SUCCEEDED(hr), "Failed to set a frame, hr %#x.\n", hr);
6754 CHECK_REFCOUNT(frame, 1);
6756 hr = IDirect3DRMAnimation2_GetFrame(animation2, NULL);
6757 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6759 hr = IDirect3DRMAnimation2_GetFrame(animation2, &frame3);
6760 ok(SUCCEEDED(hr), "Failed to get the frame, %#x.\n", hr);
6761 ok(frame3 != (void *)frame, "Unexpected interface pointer.\n");
6762 CHECK_REFCOUNT(frame, 2);
6764 IDirect3DRMFrame3_Release(frame3);
6766 hr = IDirect3DRMAnimation_SetFrame(animation, NULL);
6767 ok(SUCCEEDED(hr), "Failed to reset frame, hr %#x.\n", hr);
6769 hr = IDirect3DRMFrame_QueryInterface(frame, &IID_IDirect3DRMFrame3, (void **)&frame3);
6770 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMFrame3, hr %#x.\n", hr);
6772 CHECK_REFCOUNT(frame3, 2);
6773 hr = IDirect3DRMAnimation2_SetFrame(animation2, frame3);
6774 ok(SUCCEEDED(hr), "Failed to set a frame, hr %#x.\n", hr);
6775 CHECK_REFCOUNT(frame3, 2);
6777 IDirect3DRMFrame3_Release(frame3);
6778 IDirect3DRMFrame_Release(frame);
6780 /* Animation options. */
6781 options = IDirect3DRMAnimation_GetOptions(animation);
6782 ok(options == (D3DRMANIMATION_CLOSED | D3DRMANIMATION_LINEARPOSITION),
6783 "Unexpected default options %#x.\n", options);
6785 /* Undefined mask value */
6786 hr = IDirect3DRMAnimation_SetOptions(animation, 0xf0000000);
6787 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6789 options = IDirect3DRMAnimation_GetOptions(animation);
6790 ok(options == (D3DRMANIMATION_CLOSED | D3DRMANIMATION_LINEARPOSITION),
6791 "Unexpected default options %#x.\n", options);
6793 /* Ambiguous mask */
6794 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_OPEN | D3DRMANIMATION_CLOSED);
6795 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6797 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_LINEARPOSITION | D3DRMANIMATION_SPLINEPOSITION);
6798 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6800 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_SCALEANDROTATION | D3DRMANIMATION_POSITION);
6801 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6803 options = IDirect3DRMAnimation_GetOptions(animation);
6804 ok(options == (D3DRMANIMATION_CLOSED | D3DRMANIMATION_LINEARPOSITION),
6805 "Unexpected default options %#x.\n", options);
6807 /* Mask contains undefined bits together with valid one. */
6808 hr = IDirect3DRMAnimation_SetOptions(animation, 0xf0000000 | D3DRMANIMATION_OPEN);
6809 ok(SUCCEEDED(hr), "Failed to set animation options, hr %#x.\n", hr);
6811 options = IDirect3DRMAnimation_GetOptions(animation);
6812 ok(options == (0xf0000000 | D3DRMANIMATION_OPEN), "Unexpected animation options %#x.\n", options);
6814 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_SCALEANDROTATION);
6815 ok(SUCCEEDED(hr), "Failed to set animation options, hr %#x.\n", hr);
6817 options = IDirect3DRMAnimation_GetOptions(animation);
6818 ok(options == D3DRMANIMATION_SCALEANDROTATION, "Unexpected options %#x.\n", options);
6820 hr = IDirect3DRMAnimation_SetOptions(animation, D3DRMANIMATION_OPEN);
6821 ok(SUCCEEDED(hr), "Failed to set animation options, hr %#x.\n", hr);
6823 options = IDirect3DRMAnimation_GetOptions(animation);
6824 ok(options == D3DRMANIMATION_OPEN, "Unexpected options %#x.\n", options);
6826 hr = IDirect3DRMAnimation_SetOptions(animation, 0);
6827 ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr);
6829 options = IDirect3DRMAnimation_GetOptions(animation);
6830 ok(options == D3DRMANIMATION_OPEN, "Unexpected options %#x.\n", options);
6832 IDirect3DRMAnimation2_Release(animation2);
6833 IDirect3DRMAnimation_Release(animation);
6835 IDirect3DRM_Release(d3drm1);
6838 static void test_animation_qi(void)
6840 static const struct qi_test tests[] =
6842 { &IID_IDirect3DRMAnimation2, &IID_IUnknown, &IID_IDirect3DRMAnimation2, S_OK },
6843 { &IID_IDirect3DRMAnimation, &IID_IUnknown, &IID_IDirect3DRMAnimation, S_OK },
6844 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6845 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6846 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMAnimation, S_OK },
6847 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6848 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6849 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6850 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6851 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6852 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6853 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6854 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6855 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6856 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6857 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6858 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6859 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6860 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6861 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6862 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6863 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6864 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6865 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6866 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6867 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6868 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6869 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6870 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6871 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6872 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6873 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6874 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6875 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6876 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6877 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6878 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6879 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6880 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6881 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6882 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6883 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6884 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6885 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6886 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6887 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6888 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6889 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6890 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6891 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6892 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6893 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6894 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6895 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6896 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6897 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6898 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6899 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6900 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6901 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6902 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6903 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6904 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK },
6906 IDirect3DRMAnimation2 *animation2;
6907 IDirect3DRMAnimation *animation;
6908 IDirect3DRM3 *d3drm3;
6909 IDirect3DRM *d3drm1;
6910 IUnknown *unknown;
6911 HRESULT hr;
6913 hr = Direct3DRMCreate(&d3drm1);
6914 ok(SUCCEEDED(hr), "Failed to create d3drm instance, hr %#x.\n", hr);
6916 hr = IDirect3DRM_CreateAnimation(d3drm1, &animation);
6917 ok(SUCCEEDED(hr), "Failed to create animation hr %#x.\n", hr);
6919 hr = IDirect3DRMAnimation_QueryInterface(animation, &IID_IUnknown, (void **)&unknown);
6920 ok(SUCCEEDED(hr), "Failed to get IUnknown from animation, hr %#x.\n", hr);
6921 IDirect3DRMAnimation_Release(animation);
6923 test_qi("animation_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
6924 IUnknown_Release(unknown);
6926 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
6927 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM3, hr %#x.\n", hr);
6929 hr = IDirect3DRM3_CreateAnimation(d3drm3, &animation2);
6930 ok(SUCCEEDED(hr), "Failed to create animation hr %#x.\n", hr);
6932 hr = IDirect3DRMAnimation2_QueryInterface(animation2, &IID_IUnknown, (void **)&unknown);
6933 ok(SUCCEEDED(hr), "Failed to get IUnknown from animation, hr %#x.\n", hr);
6934 IDirect3DRMAnimation2_Release(animation2);
6936 test_qi("animation2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
6937 IUnknown_Release(unknown);
6939 IDirect3DRM3_Release(d3drm3);
6940 IDirect3DRM_Release(d3drm1);
6943 static void test_wrap(void)
6945 IDirect3DRMWrap *wrap;
6946 IDirect3DRM *d3drm1;
6947 HRESULT hr;
6949 hr = Direct3DRMCreate(&d3drm1);
6950 ok(SUCCEEDED(hr), "Failed to create IDirect3DRM instance, hr %#x.\n", hr);
6952 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMWrap, NULL, &IID_IDirect3DRMWrap, (void **)&wrap);
6953 ok(SUCCEEDED(hr), "Failed to create wrap instance, hr %#x.\n", hr);
6955 test_class_name((IDirect3DRMObject *)wrap, "");
6957 IDirect3DRMWrap_Release(wrap);
6958 IDirect3DRM_Release(d3drm1);
6961 static void test_wrap_qi(void)
6963 static const struct qi_test tests[] =
6965 { &IID_IDirect3DRMWrap, &IID_IUnknown, &IID_IDirect3DRMWrap, S_OK },
6966 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6967 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6968 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMWrap, S_OK },
6969 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6970 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6971 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6972 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6973 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6974 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6975 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6976 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6977 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6978 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6979 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6980 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6981 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6982 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6983 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6984 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6985 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6986 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6987 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6988 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6989 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6990 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6991 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6992 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6993 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6994 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6995 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6996 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6997 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6998 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
6999 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7000 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7001 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7002 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7003 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7004 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7005 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7006 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7007 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7008 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7009 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7010 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7011 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7012 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7013 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7014 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7015 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7016 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7017 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7018 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7019 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7020 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7021 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7022 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7023 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7024 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7025 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7026 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7027 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
7028 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK },
7030 IDirect3DRMWrap *wrap;
7031 IDirect3DRM *d3drm1;
7032 IUnknown *unknown;
7033 HRESULT hr;
7035 hr = Direct3DRMCreate(&d3drm1);
7036 ok(SUCCEEDED(hr), "Failed to create d3drm instance, hr %#x.\n", hr);
7038 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMWrap, NULL, &IID_IDirect3DRMWrap, (void **)&wrap);
7039 ok(SUCCEEDED(hr), "Failed to create wrap instance, hr %#x.\n", hr);
7041 hr = IDirect3DRMWrap_QueryInterface(wrap, &IID_IUnknown, (void **)&unknown);
7042 ok(SUCCEEDED(hr), "Failed to get IUnknown from wrap (hr = %#x)\n", hr);
7043 IDirect3DRMWrap_Release(wrap);
7044 test_qi("wrap_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
7045 IUnknown_Release(unknown);
7047 IDirect3DRM_Release(d3drm1);
7049 START_TEST(d3drm)
7051 test_MeshBuilder();
7052 test_MeshBuilder3();
7053 test_Mesh();
7054 test_Face();
7055 test_Frame();
7056 test_Device();
7057 test_object();
7058 test_Viewport();
7059 test_Light();
7060 test_Material2();
7061 test_Texture();
7062 test_frame_transform();
7063 test_d3drm_load();
7064 test_frame_mesh_materials();
7065 test_d3drm_qi();
7066 test_frame_qi();
7067 test_device_qi();
7068 test_create_device_from_clipper1();
7069 test_create_device_from_clipper2();
7070 test_create_device_from_clipper3();
7071 test_create_device_from_surface1();
7072 test_create_device_from_surface2();
7073 test_create_device_from_surface3();
7074 test_create_device_from_d3d1();
7075 test_create_device_from_d3d2();
7076 test_create_device_from_d3d3();
7077 test_load_texture();
7078 test_texture_qi();
7079 test_viewport_qi();
7080 test_viewport_clear1();
7081 test_viewport_clear2();
7082 test_create_texture_from_surface();
7083 test_animation();
7084 test_animation_qi();
7085 test_wrap();
7086 test_wrap_qi();